summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2015-10-24 18:01:15 +0200
committerWim <wim@42.be>2015-10-24 18:05:10 +0200
commit6feccd4c6cae08c7c6a4f283822565785428b2e0 (patch)
treef5d4b8f2fda0e16065eb07ac5f300d7dc0e9e1c4
parent25d72a7e31a0d077546639f3de25d75ebb4efa14 (diff)
downloadmatterbridge-msglm-6feccd4c6cae08c7c6a4f283822565785428b2e0.tar.gz
matterbridge-msglm-6feccd4c6cae08c7c6a4f283822565785428b2e0.tar.bz2
matterbridge-msglm-6feccd4c6cae08c7c6a4f283822565785428b2e0.zip
Add support for outgoing webhook token
-rw-r--r--README.md3
-rw-r--r--config.go1
-rw-r--r--matterbridge.conf.sample1
-rw-r--r--matterbridge.go3
-rw-r--r--matterhook/matterhook.go11
5 files changed, 17 insertions, 2 deletions
diff --git a/README.md b/README.md
index 7f347995..655d4619 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,9 @@ 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 07da3732..62d0ee17 100644
--- a/config.go
+++ b/config.go
@@ -19,6 +19,7 @@ type Config struct {
URL string
Port int
ShowJoinPart bool
+ Token string
}
}
diff --git a/matterbridge.conf.sample b/matterbridge.conf.sample
index bea46e91..7cbdce1f 100644
--- a/matterbridge.conf.sample
+++ b/matterbridge.conf.sample
@@ -10,3 +10,4 @@ channel="#matterbridge"
url="http://yourdomain/hooks/yourhookkey"
port=9999
showjoinpart=true
+#token=yourtokenfrommattermost
diff --git a/matterbridge.go b/matterbridge.go
index afad75af..219f062e 100644
--- a/matterbridge.go
+++ b/matterbridge.go
@@ -19,7 +19,8 @@ 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 8e87cc7b..ed062499 100644
--- a/matterhook/matterhook.go
+++ b/matterhook/matterhook.go
@@ -45,8 +45,10 @@ 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.
@@ -96,6 +98,13 @@ 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
}