diff --git a/README.md b/README.md index c3f66e7..bf434c6 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,6 @@ completes. There are no runtime dependencies or configuration needed. Pull requests welcome. Keep it simple. ## changelog +* 12-Aug-2019: 0.2.1 hipchat support removed and fix ssh connection! [HostKeyCallback non-permissive by default](https://github.com/golang/go/issues/19767) * 4-Sep-2015: 0.2 - Slack support added * 11-Aug-2015: 0.1 - first public release diff --git a/main.go b/main.go index a7f80ad..db5e8bc 100644 --- a/main.go +++ b/main.go @@ -33,18 +33,14 @@ import ( "os/user" "path/filepath" "strings" - "time" - - "github.com/daneharrigan/hipchat" "github.com/nlopes/slack" ) const ( - VERSION = "0.2" + VERSION = "0.2.1" ) var sshUsername, idRsaPath string -var hcFlag = flag.Bool("h", false, "create HipChat bot") var slackFlag = flag.Bool("s", false, "create Slack bot") var currentUser *user.User @@ -71,10 +67,9 @@ func main() { flag.Parse() - if (!*hcFlag && !*slackFlag) || (*hcFlag && *slackFlag) || - (*hcFlag && len(os.Args) != 4) || (*slackFlag && len(os.Args) != 3) { - usage() - } + if (*slackFlag && len(os.Args) != 3) { + usage() + } log.SetPrefix("rtop-bot: ") log.SetFlags(0) @@ -99,11 +94,8 @@ func main() { parseSshConfig(sshConfig) } - if *hcFlag { - doHipChat(os.Args[2], os.Args[3]) - } else { - doSlack(os.Args[2]) - } + doSlack(os.Args[2]) + } func doSlack(apiToken string) { @@ -137,57 +129,6 @@ func doSlack(apiToken string) { } } -func doHipChat(username, roomjid string) { - if strings.HasSuffix(username, "@chat.hipchat.com") { - username = strings.Replace(username, "@chat.hipchat.com", "", 1) - } - if !strings.HasSuffix(roomjid, "@conf.hipchat.com") { - roomjid += "@conf.hipchat.com" - } - pass, err := getpass("Password for user \"" + username + "\": ") - if err != nil { - log.Print(err) - } - - client, err := hipchat.NewClient(username, pass, "bot") - if err != nil { - log.Print(err) - os.Exit(1) - } - - nick, mname := getUserInfo(client, username) - - client.Status("chat") - client.Join(roomjid, nick) - log.Printf("[%s] now serving room [%s]", nick, roomjid) - log.Print("hit ^C to exit") - - go client.KeepAlive() - for message := range client.Messages() { - if strings.HasPrefix(message.Body, "@"+mname) { - go client.Say(roomjid, nick, process(message.Body)) - } - } -} - -func getUserInfo(client *hipchat.Client, id string) (string, string) { - id = id + "@chat.hipchat.com" - client.RequestUsers() - select { - case users := <-client.Users(): - for _, user := range users { - if user.Id == id { - log.Printf("using username [%s] and mention name [%s]", - user.Name, user.MentionName) - return user.Name, user.MentionName - } - } - case <-time.After(10 * time.Second): - log.Print("timed out waiting for user list") - os.Exit(1) - } - return "rtop-bot", "rtop-bot" -} func process(request string) string { diff --git a/sshhelper.go b/sshhelper.go index 39b5f86..aa9da72 100644 --- a/sshhelper.go +++ b/sshhelper.go @@ -157,6 +157,7 @@ func tryAgentConnect(user, addr string) (client *ssh.Client) { config := &ssh.ClientConfig{ User: user, Auth: []ssh.AuthMethod{auth}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } client, _ = ssh.Dial("tcp", addr, config) } @@ -177,6 +178,7 @@ func sshConnect(user, addr, keypath string) (client *ssh.Client, err error) { config := &ssh.ClientConfig{ User: user, Auth: auths, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } client, err = ssh.Dial("tcp", addr, config) if err != nil {