Skip to content

Commit

Permalink
use the EnvVar for user:pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdulelah Alfuntukh committed Jul 29, 2016
1 parent 9f1b60c commit 851f83a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions transmission-telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
VERSION = "1.0"
VERSION = "1.1"

HELP = `
*list* or *li*
Expand Down Expand Up @@ -68,13 +68,13 @@ const (
Takes one or more torrent's IDs to list more info about them.
*stop* or *sp*
Takes one or more torrent's IDs to stop them.
Takes one or more torrent's IDs to stop them, or _all_ to stop all torrents.
*start* or *st*
Takes one or more torrent's IDs to start them.
Takes one or more torrent's IDs to start them, or _all_ to start all torrents.
*check* or *ck*
Takes one or more torrent's IDs to verify them.
Takes one or more torrent's IDs to verify them, or _all_ to verify all torrents.
*del*
Takes one or more torrent's IDs to delete them.
Expand All @@ -98,6 +98,7 @@ const (
Shows version numbers.
- Prefix commands with '/' if you want to talk to your bot in a group.
- report any issues [here](https://github.com/pyed/transmission-telegram)
`
)

Expand All @@ -106,7 +107,7 @@ var (
// flags
BotToken string
Master string
RpcUrl string
RPCURL string
Username string
Password string
LogFile string
Expand Down Expand Up @@ -137,7 +138,7 @@ func init() {
// define arguments and parse them.
flag.StringVar(&BotToken, "token", "", "Telegram bot token")
flag.StringVar(&Master, "master", "", "Your telegram handler, So the bot will only respond to you")
flag.StringVar(&RpcUrl, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
flag.StringVar(&RPCURL, "url", "http://localhost:9091/transmission/rpc", "Transmission RPC URL")
flag.StringVar(&Username, "username", "", "Transmission username")
flag.StringVar(&Password, "password", "", "Transmission password")
flag.StringVar(&LogFile, "logfile", "", "Send logs to a file")
Expand Down Expand Up @@ -169,12 +170,23 @@ func init() {
}
log.SetOutput(logf)
}

// if the `-username` flag isn't set, look into the environment variable 'TR_AUTH'
if Username == "" {
if values := strings.Split(os.Getenv("TR_AUTH"), ":"); len(values) > 1 {
Username, Password = values[0], values[1]
}
}

// log the flags
log.Printf("[INFO] Token=%s\nMaster=%s\nURL=%s\nUSER=%s\nPASS=%s",
BotToken, Master, RPCURL, Username, Password)
}

// init transmission
func init() {
var err error
Client, err = transmission.New(RpcUrl, Username, Password)
Client, err = transmission.New(RPCURL, Username, Password)
if err != nil {
fmt.Fprintf(os.Stderr, "[ERROR] Transmission: Make sure you have the right URL, Username and Password")
os.Exit(1)
Expand Down

0 comments on commit 851f83a

Please sign in to comment.