Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 6feccd4c6cae08c7c6a4f283822565785428b2e0 Author: Wim <wim@42.be> Date: Sat Oct 24 18:01:15 2015 +0000 Add support for outgoing webhook token diff --git a/README.md b/README.md index 7f34799..655d461 100644 --- a/README.md +++ b/README.md @@ -576 +579 @@ url="http://mattermost.yourdomain.com/hooks/incomingwebhookkey"  #port the bridge webserver will listen on  port=9999  showjoinpart=true #show irc users joining and parting +#the token you get from the outgoing webhook in mattermost. If empty no token check will be done. +token=yourtokenfrommattermost +  ```    ### mattermost diff --git a/config.go b/config.go index 07da373..62d0ee1 100644 --- a/config.go +++ b/config.go @@ -196 +197 @@ type Config struct {   URL string   Port int   ShowJoinPart bool + Token string   }  }   diff --git a/matterbridge.conf.sample b/matterbridge.conf.sample index bea46e9..7cbdce1 100644 --- a/matterbridge.conf.sample +++ b/matterbridge.conf.sample @@ -103 +104 @@ channel="#matterbridge"  url="http://yourdomain/hooks/yourhookkey"  port=9999  showjoinpart=true +#token=yourtokenfrommattermost diff --git a/matterbridge.go b/matterbridge.go index afad75a..219f062 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -197 +198 @@ type Bridge struct {  func NewBridge(name string, config *Config) *Bridge {   b := &Bridge{}   b.Config = config - b.m = matterhook.New(b.Config.Mattermost.URL, matterhook.Config{Port: b.Config.Mattermost.Port}) + b.m = matterhook.New(b.Config.Mattermost.URL, + matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token})   b.i = b.createIRC(name)   go b.handleMatter()   return b diff --git a/matterhook/matterhook.go b/matterhook/matterhook.go index 8e87cc7..ed06249 100644 --- a/matterhook/matterhook.go +++ b/matterhook/matterhook.go @@ -458 +4510 @@ type Client struct {   Config  }   +// Config for client.  type Config struct { - Port int + Port int // Port to listen on. + Token string // Only allow this token from Mattermost. (Allow everything when empty)  }    // New Mattermost client. @@ -966 +9813 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) {   http.NotFound(w, r)   return   } + if c.Token != "" { + if msg.Token != c.Token { + log.Println("invalid token " + msg.Token + " from " + r.RemoteAddr) + http.NotFound(w, r) + return + } + }   c.In <- msg  }