forked from lug/matterbridge
Compare commits
21 Commits
v0.5.0-bet
...
v0.6.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2c135bca2 | ||
|
|
eb20cb237d | ||
|
|
106404d32f | ||
|
|
e06efbad9f | ||
|
|
3311c7f923 | ||
|
|
3a6c655dfb | ||
|
|
e11d786775 | ||
|
|
889b6debc4 | ||
|
|
9cb3413d9c | ||
|
|
131826e1d1 | ||
|
|
96e21dd051 | ||
|
|
32e5f396e7 | ||
|
|
6c6000dbbd | ||
|
|
24defcb970 | ||
|
|
a1a11a88b3 | ||
|
|
a997ae29ad | ||
|
|
ff94796700 | ||
|
|
1f72ca4c4e | ||
|
|
46faad8b57 | ||
|
|
30f30364d5 | ||
|
|
073d90da88 |
@@ -2,10 +2,10 @@ FROM alpine:edge
|
|||||||
ENTRYPOINT ["/bin/matterbridge"]
|
ENTRYPOINT ["/bin/matterbridge"]
|
||||||
|
|
||||||
COPY . /go/src/github.com/42wim/matterbridge
|
COPY . /go/src/github.com/42wim/matterbridge
|
||||||
RUN apk update && apk add go git \
|
RUN apk update && apk add go git gcc musl-dev ca-certificates \
|
||||||
&& cd /go/src/github.com/42wim/matterbridge \
|
&& cd /go/src/github.com/42wim/matterbridge \
|
||||||
&& export GOPATH=/go \
|
&& export GOPATH=/go \
|
||||||
&& go get \
|
&& go get \
|
||||||
&& go build -o /bin/matterbridge \
|
&& go build -o /bin/matterbridge \
|
||||||
&& rm -rf /go \
|
&& rm -rf /go \
|
||||||
&& apk del --purge git go
|
&& apk del --purge git go gcc musl-dev
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -8,9 +8,16 @@ Simple bridge between mattermost and IRC.
|
|||||||
|
|
||||||
This project has now [matterbridge-plus](https://github.com/42wim/matterbridge-plus/) merged in.
|
This project has now [matterbridge-plus](https://github.com/42wim/matterbridge-plus/) merged in.
|
||||||
Breaking changes for matterbridge can be found in [migration](https://github.com/42wim/matterbridge/blob/master/migration.md)
|
Breaking changes for matterbridge can be found in [migration](https://github.com/42wim/matterbridge/blob/master/migration.md)
|
||||||
|
Look at [matterbridge.conf.sample] (https://github.com/42wim/matterbridge/blob/master/matterbridge.conf.sample) for an example.
|
||||||
|
|
||||||
|
Configuration changes since v0.5.0 can be found in [changelog.md] (https://github.com/42wim/matterbridge/blob/master/changelog.md)
|
||||||
|
|
||||||
## Requirements:
|
## Requirements:
|
||||||
* [Mattermost] (https://github.com/mattermost/platform/) 3.x (stable, not a dev build)
|
* [Mattermost] (https://github.com/mattermost/platform/)
|
||||||
|
### Compatibility
|
||||||
|
* Matterbridge v0.6.0 works with mattermost 3.3.0 and higher [3.3.0 release](https://github.com/mattermost/platform/releases/tag/v3.3.0)
|
||||||
|
* Matterbridge v0.5.0 works with mattermost 3.0.0 - 3.2.0 [3.2.0 release](https://github.com/mattermost/platform/releases/tag/v3.2.0)
|
||||||
|
|
||||||
|
|
||||||
### Webhooks version
|
### Webhooks version
|
||||||
* Configured incoming/outgoing [webhooks](https://www.mattermost.org/webhooks/) on your mattermost instance.
|
* Configured incoming/outgoing [webhooks](https://www.mattermost.org/webhooks/) on your mattermost instance.
|
||||||
@@ -19,7 +26,9 @@ Breaking changes for matterbridge can be found in [migration](https://github.com
|
|||||||
* A dedicated user(bot) on your mattermost instance.
|
* A dedicated user(bot) on your mattermost instance.
|
||||||
|
|
||||||
## binaries
|
## binaries
|
||||||
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/tag/v0.5-beta2)
|
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/)
|
||||||
|
* For use with mattermost 3.3.0 [v0.6.0-beta1](https://github.com/42wim/matterircd/releases/tag/v0.6.0-beta1)
|
||||||
|
* For use with mattermost 3.0.0-3.2.0 [v0.5.0](https://github.com/42wim/matterircd/releases/tag/v0.5.0)
|
||||||
|
|
||||||
## building
|
## building
|
||||||
Go 1.6+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
Go 1.6+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
||||||
@@ -48,7 +57,7 @@ Usage of ./matterbridge:
|
|||||||
-debug
|
-debug
|
||||||
enable debug
|
enable debug
|
||||||
-plus
|
-plus
|
||||||
running using API instead of webhooks
|
running using API instead of webhooks (deprecated, set Plus flag in [general] config)
|
||||||
-version
|
-version
|
||||||
show version
|
show version
|
||||||
```
|
```
|
||||||
|
|||||||
459
bridge/bridge.go
459
bridge/bridge.go
@@ -1,407 +1,134 @@
|
|||||||
package bridge
|
package bridge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
//"fmt"
|
||||||
"github.com/42wim/matterbridge/matterclient"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"github.com/42wim/matterbridge/bridge/irc"
|
||||||
|
"github.com/42wim/matterbridge/bridge/mattermost"
|
||||||
|
"github.com/42wim/matterbridge/bridge/xmpp"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/peterhellberg/giphy"
|
|
||||||
ircm "github.com/sorcix/irc"
|
|
||||||
"github.com/thoj/go-ircevent"
|
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//type Bridge struct {
|
|
||||||
type MMhook struct {
|
|
||||||
mh *matterhook.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
type MMapi struct {
|
|
||||||
mc *matterclient.MMClient
|
|
||||||
mmMap map[string]string
|
|
||||||
mmIgnoreNicks []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type MMirc struct {
|
|
||||||
i *irc.Connection
|
|
||||||
ircNick string
|
|
||||||
ircMap map[string]string
|
|
||||||
names map[string][]string
|
|
||||||
ircIgnoreNicks []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type MMMessage struct {
|
|
||||||
Text string
|
|
||||||
Channel string
|
|
||||||
Username string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
MMhook
|
*config.Config
|
||||||
MMapi
|
Source string
|
||||||
MMirc
|
Bridges []Bridger
|
||||||
*Config
|
Channels []map[string]string
|
||||||
kind string
|
ignoreNicks map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type FancyLog struct {
|
type Bridger interface {
|
||||||
irc *log.Entry
|
Send(msg config.Message) error
|
||||||
mm *log.Entry
|
Name() string
|
||||||
|
Connect() error
|
||||||
|
//Command(cmd string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
var flog FancyLog
|
func NewBridge(cfg *config.Config) error {
|
||||||
|
c := make(chan config.Message)
|
||||||
const Legacy = "legacy"
|
|
||||||
|
|
||||||
func initFLog() {
|
|
||||||
flog.irc = log.WithFields(log.Fields{"module": "irc"})
|
|
||||||
flog.mm = log.WithFields(log.Fields{"module": "mattermost"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBridge(name string, config *Config, kind string) *Bridge {
|
|
||||||
initFLog()
|
|
||||||
b := &Bridge{}
|
b := &Bridge{}
|
||||||
b.Config = config
|
b.Config = cfg
|
||||||
b.kind = kind
|
if cfg.IRC.Enable {
|
||||||
b.ircNick = b.Config.IRC.Nick
|
b.Bridges = append(b.Bridges, birc.New(cfg, c))
|
||||||
b.ircMap = make(map[string]string)
|
|
||||||
b.mmMap = make(map[string]string)
|
|
||||||
b.MMirc.names = make(map[string][]string)
|
|
||||||
b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
|
|
||||||
b.mmIgnoreNicks = strings.Fields(b.Config.Mattermost.IgnoreNicks)
|
|
||||||
for _, val := range b.Config.Channel {
|
|
||||||
b.ircMap[val.IRC] = val.Mattermost
|
|
||||||
b.mmMap[val.Mattermost] = val.IRC
|
|
||||||
}
|
}
|
||||||
if kind == Legacy {
|
if cfg.Mattermost.Enable {
|
||||||
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
b.Bridges = append(b.Bridges, bmattermost.New(cfg, c))
|
||||||
matterhook.Config{InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
|
||||||
BindAddress: b.Config.Mattermost.BindAddress})
|
|
||||||
} else {
|
|
||||||
b.mc = matterclient.New(b.Config.Mattermost.Login, b.Config.Mattermost.Password,
|
|
||||||
b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
|
||||||
b.mc.SkipTLSVerify = b.Config.Mattermost.SkipTLSVerify
|
|
||||||
b.mc.NoTLS = b.Config.Mattermost.NoTLS
|
|
||||||
flog.mm.Infof("Trying login %s (team: %s) on %s", b.Config.Mattermost.Login, b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
|
||||||
err := b.mc.Login()
|
|
||||||
if err != nil {
|
|
||||||
flog.mm.Fatal("Can not connect", err)
|
|
||||||
}
|
}
|
||||||
flog.mm.Info("Login ok")
|
if cfg.Xmpp.Enable {
|
||||||
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
b.Bridges = append(b.Bridges, bxmpp.New(cfg, c))
|
||||||
for _, val := range b.Config.Channel {
|
|
||||||
b.mc.JoinChannel(val.Mattermost)
|
|
||||||
}
|
}
|
||||||
go b.mc.WsReceiver()
|
if len(b.Bridges) < 2 {
|
||||||
|
log.Fatalf("only %d sections enabled. Need at least 2 sections enabled (eg [IRC] and [mattermost]", len(b.Bridges))
|
||||||
}
|
}
|
||||||
flog.irc.Info("Trying IRC connection")
|
for _, br := range b.Bridges {
|
||||||
b.i = b.createIRC(name)
|
br.Connect()
|
||||||
flog.irc.Info("Connection succeeded")
|
|
||||||
go b.handleMatter()
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) createIRC(name string) *irc.Connection {
|
|
||||||
i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick)
|
|
||||||
i.UseTLS = b.Config.IRC.UseTLS
|
|
||||||
i.UseSASL = b.Config.IRC.UseSASL
|
|
||||||
i.SASLLogin = b.Config.IRC.NickServNick
|
|
||||||
i.SASLPassword = b.Config.IRC.NickServPassword
|
|
||||||
i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify}
|
|
||||||
if b.Config.IRC.Password != "" {
|
|
||||||
i.Password = b.Config.IRC.Password
|
|
||||||
}
|
}
|
||||||
i.AddCallback(ircm.RPL_WELCOME, b.handleNewConnection)
|
b.mapChannels()
|
||||||
err := i.Connect(b.Config.IRC.Server)
|
b.mapIgnores()
|
||||||
if err != nil {
|
b.handleReceive(c)
|
||||||
flog.irc.Fatal(err)
|
|
||||||
}
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleNewConnection(event *irc.Event) {
|
|
||||||
flog.irc.Info("Registering callbacks")
|
|
||||||
i := b.i
|
|
||||||
b.ircNick = event.Arguments[0]
|
|
||||||
i.AddCallback("PRIVMSG", b.handlePrivMsg)
|
|
||||||
i.AddCallback("CTCP_ACTION", b.handlePrivMsg)
|
|
||||||
i.AddCallback(ircm.RPL_ENDOFNAMES, b.endNames)
|
|
||||||
i.AddCallback(ircm.RPL_NAMREPLY, b.storeNames)
|
|
||||||
i.AddCallback(ircm.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
|
|
||||||
i.AddCallback(ircm.NOTICE, b.handleNotice)
|
|
||||||
i.AddCallback(ircm.RPL_MYINFO, func(e *irc.Event) { flog.irc.Infof("%s: %s", e.Code, strings.Join(e.Arguments[1:], " ")) })
|
|
||||||
i.AddCallback("PING", func(e *irc.Event) {
|
|
||||||
i.SendRaw("PONG :" + e.Message())
|
|
||||||
flog.irc.Debugf("PING/PONG")
|
|
||||||
})
|
|
||||||
if b.Config.Mattermost.ShowJoinPart {
|
|
||||||
i.AddCallback("JOIN", b.handleJoinPart)
|
|
||||||
i.AddCallback("PART", b.handleJoinPart)
|
|
||||||
}
|
|
||||||
i.AddCallback("*", b.handleOther)
|
|
||||||
b.setupChannels()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) setupChannels() {
|
|
||||||
i := b.i
|
|
||||||
for _, val := range b.Config.Channel {
|
|
||||||
flog.irc.Infof("Joining %s as %s", val.IRC, b.ircNick)
|
|
||||||
i.Join(val.IRC)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleIrcBotCommand(event *irc.Event) bool {
|
|
||||||
parts := strings.Fields(event.Message())
|
|
||||||
exp, _ := regexp.Compile("[:,]+$")
|
|
||||||
channel := event.Arguments[0]
|
|
||||||
command := ""
|
|
||||||
if len(parts) == 2 {
|
|
||||||
command = parts[1]
|
|
||||||
}
|
|
||||||
if exp.ReplaceAllString(parts[0], "") == b.ircNick {
|
|
||||||
switch command {
|
|
||||||
case "users":
|
|
||||||
usernames := b.mc.UsernamesInChannel(b.getMMChannel(channel))
|
|
||||||
sort.Strings(usernames)
|
|
||||||
b.i.Privmsg(channel, "Users on Mattermost: "+strings.Join(usernames, ", "))
|
|
||||||
default:
|
|
||||||
b.i.Privmsg(channel, "Valid commands are: [users, help]")
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) ircNickFormat(nick string) string {
|
|
||||||
if nick == b.ircNick {
|
|
||||||
return nick
|
|
||||||
}
|
|
||||||
if b.Config.Mattermost.RemoteNickFormat == nil {
|
|
||||||
return "irc-" + nick
|
|
||||||
}
|
|
||||||
return strings.Replace(*b.Config.Mattermost.RemoteNickFormat, "{NICK}", nick, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handlePrivMsg(event *irc.Event) {
|
|
||||||
flog.irc.Debugf("handlePrivMsg() %s %s", event.Nick, event.Message())
|
|
||||||
if b.ignoreMessage(event.Nick, event.Message(), "irc") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if b.handleIrcBotCommand(event) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
msg := ""
|
|
||||||
if event.Code == "CTCP_ACTION" {
|
|
||||||
msg = event.Nick + " "
|
|
||||||
}
|
|
||||||
msg += event.Message()
|
|
||||||
b.Send(b.ircNickFormat(event.Nick), msg, b.getMMChannel(event.Arguments[0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleJoinPart(event *irc.Event) {
|
|
||||||
b.Send(b.ircNick, b.ircNickFormat(event.Nick)+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleNotice(event *irc.Event) {
|
|
||||||
if strings.Contains(event.Message(), "This nickname is registered") {
|
|
||||||
b.i.Privmsg(b.Config.IRC.NickServNick, "IDENTIFY "+b.Config.IRC.NickServPassword)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) nicksPerRow() int {
|
|
||||||
if b.Config.Mattermost.NicksPerRow < 1 {
|
|
||||||
return 4
|
|
||||||
}
|
|
||||||
return b.Config.Mattermost.NicksPerRow
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) formatnicks(nicks []string, continued bool) string {
|
|
||||||
switch b.Config.Mattermost.NickFormatter {
|
|
||||||
case "table":
|
|
||||||
return tableformatter(nicks, b.nicksPerRow(), continued)
|
|
||||||
default:
|
|
||||||
return plainformatter(nicks, b.nicksPerRow())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) storeNames(event *irc.Event) {
|
|
||||||
channel := event.Arguments[2]
|
|
||||||
b.MMirc.names[channel] = append(
|
|
||||||
b.MMirc.names[channel],
|
|
||||||
strings.Split(strings.TrimSpace(event.Message()), " ")...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) endNames(event *irc.Event) {
|
|
||||||
channel := event.Arguments[1]
|
|
||||||
sort.Strings(b.MMirc.names[channel])
|
|
||||||
maxNamesPerPost := (300 / b.nicksPerRow()) * b.nicksPerRow()
|
|
||||||
continued := false
|
|
||||||
for len(b.MMirc.names[channel]) > maxNamesPerPost {
|
|
||||||
b.Send(
|
|
||||||
b.ircNick,
|
|
||||||
b.formatnicks(b.MMirc.names[channel][0:maxNamesPerPost], continued),
|
|
||||||
b.getMMChannel(channel))
|
|
||||||
b.MMirc.names[channel] = b.MMirc.names[channel][maxNamesPerPost:]
|
|
||||||
continued = true
|
|
||||||
}
|
|
||||||
b.Send(b.ircNick, b.formatnicks(b.MMirc.names[channel], continued), b.getMMChannel(channel))
|
|
||||||
b.MMirc.names[channel] = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleTopicWhoTime(event *irc.Event) {
|
|
||||||
parts := strings.Split(event.Arguments[2], "!")
|
|
||||||
t, err := strconv.ParseInt(event.Arguments[3], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
flog.irc.Errorf("Invalid time stamp: %s", event.Arguments[3])
|
|
||||||
}
|
|
||||||
user := parts[0]
|
|
||||||
if len(parts) > 1 {
|
|
||||||
user += " [" + parts[1] + "]"
|
|
||||||
}
|
|
||||||
flog.irc.Infof("%s: Topic set by %s [%s]", event.Code, user, time.Unix(t, 0))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleOther(event *irc.Event) {
|
|
||||||
flog.irc.Debugf("%#v", event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) Send(nick string, message string, channel string) error {
|
|
||||||
return b.SendType(nick, message, channel, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) SendType(nick string, message string, channel string, mtype string) error {
|
|
||||||
if b.Config.Mattermost.PrefixMessagesWithNick {
|
|
||||||
if IsMarkup(message) {
|
|
||||||
message = nick + "\n\n" + message
|
|
||||||
} else {
|
|
||||||
message = nick + " " + message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if b.kind == Legacy {
|
|
||||||
matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL}
|
|
||||||
matterMessage.Channel = channel
|
|
||||||
matterMessage.UserName = nick
|
|
||||||
matterMessage.Type = mtype
|
|
||||||
matterMessage.Text = message
|
|
||||||
err := b.mh.Send(matterMessage)
|
|
||||||
if err != nil {
|
|
||||||
flog.mm.Info(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
|
||||||
b.mc.PostMessage(channel, message)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handleMatterHook(mchan chan *MMMessage) {
|
func (b *Bridge) handleReceive(c chan config.Message) {
|
||||||
for {
|
for {
|
||||||
message := b.mh.Receive()
|
select {
|
||||||
flog.mm.Debugf("receiving from matterhook %#v", message)
|
case msg := <-c:
|
||||||
m := &MMMessage{}
|
for _, br := range b.Bridges {
|
||||||
m.Username = message.UserName
|
b.handleMessage(msg, br)
|
||||||
m.Text = message.Text
|
|
||||||
m.Channel = message.ChannelName
|
|
||||||
mchan <- m
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) handleMatterClient(mchan chan *MMMessage) {
|
|
||||||
for message := range b.mc.MessageChan {
|
|
||||||
// do not post our own messages back to irc
|
|
||||||
if message.Raw.Action == "posted" && b.mc.User.Username != message.Username {
|
|
||||||
flog.mm.Debugf("receiving from matterclient %#v", message)
|
|
||||||
m := &MMMessage{}
|
|
||||||
m.Username = message.Username
|
|
||||||
m.Channel = message.Channel
|
|
||||||
m.Text = message.Text
|
|
||||||
mchan <- m
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handleMatter() {
|
func (b *Bridge) mapChannels() error {
|
||||||
flog.mm.Infof("Choosing Mattermost connection type %s", b.kind)
|
for _, val := range b.Config.Channel {
|
||||||
mchan := make(chan *MMMessage)
|
m := make(map[string]string)
|
||||||
if b.kind == Legacy {
|
m["irc"] = val.IRC
|
||||||
go b.handleMatterHook(mchan)
|
m["mattermost"] = val.Mattermost
|
||||||
} else {
|
m["xmpp"] = val.Xmpp
|
||||||
go b.handleMatterClient(mchan)
|
b.Channels = append(b.Channels, m)
|
||||||
}
|
}
|
||||||
flog.mm.Info("Start listening for Mattermost messages")
|
return nil
|
||||||
for message := range mchan {
|
}
|
||||||
var username string
|
|
||||||
if b.ignoreMessage(message.Username, message.Text, "mattermost") {
|
func (b *Bridge) mapIgnores() {
|
||||||
continue
|
m := make(map[string][]string)
|
||||||
|
m["irc"] = strings.Fields(b.Config.IRC.IgnoreNicks)
|
||||||
|
m["mattermost"] = strings.Fields(b.Config.Mattermost.IgnoreNicks)
|
||||||
|
m["xmpp"] = strings.Fields(b.Config.Mattermost.IgnoreNicks)
|
||||||
|
b.ignoreNicks = m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bridge) getDestChannel(msg *config.Message, dest string) string {
|
||||||
|
for _, v := range b.Channels {
|
||||||
|
if v[msg.Origin] == msg.Channel {
|
||||||
|
return v[dest]
|
||||||
}
|
}
|
||||||
username = message.Username + ": "
|
|
||||||
if b.Config.IRC.RemoteNickFormat != "" {
|
|
||||||
username = strings.Replace(b.Config.IRC.RemoteNickFormat, "{NICK}", message.Username, -1)
|
|
||||||
}
|
}
|
||||||
cmds := strings.Fields(message.Text)
|
return ""
|
||||||
// empty message
|
}
|
||||||
if len(cmds) == 0 {
|
|
||||||
continue
|
func (b *Bridge) handleMessage(msg config.Message, dest Bridger) {
|
||||||
|
if b.ignoreMessage(&msg) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
cmd := cmds[0]
|
if dest.Name() != msg.Origin {
|
||||||
switch cmd {
|
msg.Channel = b.getDestChannel(&msg, dest.Name())
|
||||||
case "!users":
|
if msg.Channel == "" {
|
||||||
flog.mm.Info("Received !users from ", message.Username)
|
return
|
||||||
b.i.SendRaw("NAMES " + b.getIRCChannel(message.Channel))
|
|
||||||
continue
|
|
||||||
case "!gif":
|
|
||||||
message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1)))
|
|
||||||
b.Send(b.ircNick, message.Text, b.getIRCChannel(message.Channel))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
texts := strings.Split(message.Text, "\n")
|
|
||||||
for _, text := range texts {
|
|
||||||
flog.mm.Debug("Sending message from " + message.Username + " to " + message.Channel)
|
|
||||||
b.i.Privmsg(b.getIRCChannel(message.Channel), username+text)
|
|
||||||
}
|
}
|
||||||
|
b.modifyMessage(&msg, dest.Name())
|
||||||
|
dest.Send(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) giphyRandom(query []string) string {
|
func (b *Bridge) ignoreMessage(msg *config.Message) bool {
|
||||||
g := giphy.DefaultClient
|
|
||||||
if b.Config.General.GiphyAPIKey != "" {
|
|
||||||
g.APIKey = b.Config.General.GiphyAPIKey
|
|
||||||
}
|
|
||||||
res, err := g.Random(query)
|
|
||||||
if err != nil {
|
|
||||||
return "error"
|
|
||||||
}
|
|
||||||
return res.Data.FixedHeightDownsampledURL
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) getMMChannel(ircChannel string) string {
|
|
||||||
mmChannel := b.ircMap[ircChannel]
|
|
||||||
if b.kind == Legacy {
|
|
||||||
return mmChannel
|
|
||||||
}
|
|
||||||
return b.mc.GetChannelId(mmChannel, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) getIRCChannel(mmChannel string) string {
|
|
||||||
return b.mmMap[mmChannel]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bridge) ignoreMessage(nick string, message string, protocol string) bool {
|
|
||||||
var ignoreNicks = b.mmIgnoreNicks
|
|
||||||
if protocol == "irc" {
|
|
||||||
ignoreNicks = b.ircIgnoreNicks
|
|
||||||
}
|
|
||||||
// should we discard messages ?
|
// should we discard messages ?
|
||||||
for _, entry := range ignoreNicks {
|
for _, entry := range b.ignoreNicks[msg.Origin] {
|
||||||
if nick == entry {
|
if msg.Username == entry {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setNickFormat(msg *config.Message, format string) {
|
||||||
|
if format == "" {
|
||||||
|
msg.Username = msg.Origin + "-" + msg.Username + ": "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg.Username = strings.Replace(format, "{NICK}", msg.Username, -1)
|
||||||
|
msg.Username = strings.Replace(msg.Username, "{BRIDGE}", msg.Origin, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bridge) modifyMessage(msg *config.Message, dest string) {
|
||||||
|
switch dest {
|
||||||
|
case "irc":
|
||||||
|
setNickFormat(msg, b.Config.IRC.RemoteNickFormat)
|
||||||
|
case "xmpp":
|
||||||
|
setNickFormat(msg, b.Config.Xmpp.RemoteNickFormat)
|
||||||
|
case "mattermost":
|
||||||
|
setNickFormat(msg, b.Config.Mattermost.RemoteNickFormat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package bridge
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/gcfg.v1"
|
"gopkg.in/gcfg.v1"
|
||||||
@@ -6,6 +6,13 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Text string
|
||||||
|
Channel string
|
||||||
|
Username string
|
||||||
|
Origin string
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
IRC struct {
|
IRC struct {
|
||||||
UseTLS bool
|
UseTLS bool
|
||||||
@@ -19,6 +26,7 @@ type Config struct {
|
|||||||
NickServPassword string
|
NickServPassword string
|
||||||
RemoteNickFormat string
|
RemoteNickFormat string
|
||||||
IgnoreNicks string
|
IgnoreNicks string
|
||||||
|
Enable bool
|
||||||
}
|
}
|
||||||
Mattermost struct {
|
Mattermost struct {
|
||||||
URL string
|
URL string
|
||||||
@@ -34,16 +42,31 @@ type Config struct {
|
|||||||
Team string
|
Team string
|
||||||
Login string
|
Login string
|
||||||
Password string
|
Password string
|
||||||
RemoteNickFormat *string
|
RemoteNickFormat string
|
||||||
IgnoreNicks string
|
IgnoreNicks string
|
||||||
NoTLS bool
|
NoTLS bool
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
Xmpp struct {
|
||||||
|
Jid string
|
||||||
|
Password string
|
||||||
|
Server string
|
||||||
|
Muc string
|
||||||
|
Nick string
|
||||||
|
RemoteNickFormat string
|
||||||
|
Enable bool
|
||||||
}
|
}
|
||||||
Channel map[string]*struct {
|
Channel map[string]*struct {
|
||||||
IRC string
|
IRC string
|
||||||
Mattermost string
|
Mattermost string
|
||||||
|
Xmpp string
|
||||||
}
|
}
|
||||||
General struct {
|
General struct {
|
||||||
GiphyAPIKey string
|
GiphyAPIKey string
|
||||||
|
Xmpp bool
|
||||||
|
Irc bool
|
||||||
|
Mattermost bool
|
||||||
|
Plus bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package bridge
|
package birc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
194
bridge/irc/irc.go
Normal file
194
bridge/irc/irc.go
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
package birc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
ircm "github.com/sorcix/irc"
|
||||||
|
"github.com/thoj/go-ircevent"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
//type Bridge struct {
|
||||||
|
type Birc struct {
|
||||||
|
i *irc.Connection
|
||||||
|
ircNick string
|
||||||
|
ircMap map[string]string
|
||||||
|
names map[string][]string
|
||||||
|
ircIgnoreNicks []string
|
||||||
|
*config.Config
|
||||||
|
Remote chan config.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
type FancyLog struct {
|
||||||
|
irc *log.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
var flog FancyLog
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flog.irc = log.WithFields(log.Fields{"module": "irc"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(config *config.Config, c chan config.Message) *Birc {
|
||||||
|
b := &Birc{}
|
||||||
|
b.Config = config
|
||||||
|
b.Remote = c
|
||||||
|
b.ircNick = b.Config.IRC.Nick
|
||||||
|
b.ircMap = make(map[string]string)
|
||||||
|
b.names = make(map[string][]string)
|
||||||
|
b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) Command(msg *config.Message) string {
|
||||||
|
switch msg.Text {
|
||||||
|
case "!users":
|
||||||
|
b.i.SendRaw("NAMES " + msg.Channel)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) Connect() error {
|
||||||
|
flog.irc.Info("Trying IRC connection")
|
||||||
|
i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick)
|
||||||
|
i.UseTLS = b.Config.IRC.UseTLS
|
||||||
|
i.UseSASL = b.Config.IRC.UseSASL
|
||||||
|
i.SASLLogin = b.Config.IRC.NickServNick
|
||||||
|
i.SASLPassword = b.Config.IRC.NickServPassword
|
||||||
|
i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify}
|
||||||
|
if b.Config.IRC.Password != "" {
|
||||||
|
i.Password = b.Config.IRC.Password
|
||||||
|
}
|
||||||
|
i.AddCallback(ircm.RPL_WELCOME, b.handleNewConnection)
|
||||||
|
err := i.Connect(b.Config.IRC.Server)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
flog.irc.Info("Connection succeeded")
|
||||||
|
b.i = i
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) Name() string {
|
||||||
|
return "irc"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) Send(msg config.Message) error {
|
||||||
|
if msg.Origin == "irc" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(msg.Text, "!") {
|
||||||
|
b.Command(&msg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) endNames(event *irc.Event) {
|
||||||
|
channel := event.Arguments[1]
|
||||||
|
sort.Strings(b.names[channel])
|
||||||
|
maxNamesPerPost := (300 / b.nicksPerRow()) * b.nicksPerRow()
|
||||||
|
continued := false
|
||||||
|
for len(b.names[channel]) > maxNamesPerPost {
|
||||||
|
b.Remote <- config.Message{Username: b.ircNick, Text: b.formatnicks(b.names[channel][0:maxNamesPerPost], continued), Channel: channel, Origin: "irc"}
|
||||||
|
b.names[channel] = b.names[channel][maxNamesPerPost:]
|
||||||
|
continued = true
|
||||||
|
}
|
||||||
|
b.Remote <- config.Message{Username: b.ircNick, Text: b.formatnicks(b.names[channel], continued), Channel: channel, Origin: "irc"}
|
||||||
|
b.names[channel] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleNewConnection(event *irc.Event) {
|
||||||
|
flog.irc.Info("Registering callbacks")
|
||||||
|
i := b.i
|
||||||
|
b.ircNick = event.Arguments[0]
|
||||||
|
i.AddCallback("PRIVMSG", b.handlePrivMsg)
|
||||||
|
i.AddCallback("CTCP_ACTION", b.handlePrivMsg)
|
||||||
|
i.AddCallback(ircm.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
|
||||||
|
i.AddCallback(ircm.RPL_ENDOFNAMES, b.endNames)
|
||||||
|
i.AddCallback(ircm.RPL_NAMREPLY, b.storeNames)
|
||||||
|
i.AddCallback(ircm.NOTICE, b.handleNotice)
|
||||||
|
i.AddCallback(ircm.RPL_MYINFO, func(e *irc.Event) { flog.irc.Infof("%s: %s", e.Code, strings.Join(e.Arguments[1:], " ")) })
|
||||||
|
i.AddCallback("PING", func(e *irc.Event) {
|
||||||
|
i.SendRaw("PONG :" + e.Message())
|
||||||
|
flog.irc.Debugf("PING/PONG")
|
||||||
|
})
|
||||||
|
if b.Config.Mattermost.ShowJoinPart {
|
||||||
|
i.AddCallback("JOIN", b.handleJoinPart)
|
||||||
|
i.AddCallback("PART", b.handleJoinPart)
|
||||||
|
}
|
||||||
|
i.AddCallback("*", b.handleOther)
|
||||||
|
b.setupChannels()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleJoinPart(event *irc.Event) {
|
||||||
|
//b.Send(b.ircNick, b.ircNickFormat(event.Nick)+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleNotice(event *irc.Event) {
|
||||||
|
if strings.Contains(event.Message(), "This nickname is registered") {
|
||||||
|
b.i.Privmsg(b.Config.IRC.NickServNick, "IDENTIFY "+b.Config.IRC.NickServPassword)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleOther(event *irc.Event) {
|
||||||
|
flog.irc.Debugf("%#v", event)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handlePrivMsg(event *irc.Event) {
|
||||||
|
flog.irc.Debugf("handlePrivMsg() %s %s", event.Nick, event.Message())
|
||||||
|
msg := ""
|
||||||
|
if event.Code == "CTCP_ACTION" {
|
||||||
|
msg = event.Nick + " "
|
||||||
|
}
|
||||||
|
msg += event.Message()
|
||||||
|
b.Remote <- config.Message{Username: event.Nick, Text: msg, Channel: event.Arguments[0], Origin: "irc"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleTopicWhoTime(event *irc.Event) {
|
||||||
|
parts := strings.Split(event.Arguments[2], "!")
|
||||||
|
t, err := strconv.ParseInt(event.Arguments[3], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
flog.irc.Errorf("Invalid time stamp: %s", event.Arguments[3])
|
||||||
|
}
|
||||||
|
user := parts[0]
|
||||||
|
if len(parts) > 1 {
|
||||||
|
user += " [" + parts[1] + "]"
|
||||||
|
}
|
||||||
|
flog.irc.Infof("%s: Topic set by %s [%s]", event.Code, user, time.Unix(t, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) nicksPerRow() int {
|
||||||
|
if b.Config.Mattermost.NicksPerRow < 1 {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
return b.Config.Mattermost.NicksPerRow
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) setupChannels() {
|
||||||
|
for _, val := range b.Config.Channel {
|
||||||
|
flog.irc.Infof("Joining %s as %s", val.IRC, b.ircNick)
|
||||||
|
b.i.Join(val.IRC)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) storeNames(event *irc.Event) {
|
||||||
|
channel := event.Arguments[2]
|
||||||
|
b.names[channel] = append(
|
||||||
|
b.names[channel],
|
||||||
|
strings.Split(strings.TrimSpace(event.Message()), " ")...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Birc) formatnicks(nicks []string, continued bool) string {
|
||||||
|
switch b.Config.Mattermost.NickFormatter {
|
||||||
|
case "table":
|
||||||
|
return tableformatter(nicks, b.nicksPerRow(), continued)
|
||||||
|
default:
|
||||||
|
return plainformatter(nicks, b.nicksPerRow())
|
||||||
|
}
|
||||||
|
}
|
||||||
174
bridge/mattermost/mattermost.go
Normal file
174
bridge/mattermost/mattermost.go
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
package bmattermost
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"github.com/42wim/matterbridge/matterclient"
|
||||||
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//type Bridge struct {
|
||||||
|
type MMhook struct {
|
||||||
|
mh *matterhook.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type MMapi struct {
|
||||||
|
mc *matterclient.MMClient
|
||||||
|
mmMap map[string]string
|
||||||
|
mmIgnoreNicks []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type MMMessage struct {
|
||||||
|
Text string
|
||||||
|
Channel string
|
||||||
|
Username string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Bmattermost struct {
|
||||||
|
MMhook
|
||||||
|
MMapi
|
||||||
|
*config.Config
|
||||||
|
Plus bool
|
||||||
|
Remote chan config.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
type FancyLog struct {
|
||||||
|
irc *log.Entry
|
||||||
|
mm *log.Entry
|
||||||
|
xmpp *log.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
var flog FancyLog
|
||||||
|
|
||||||
|
const Legacy = "legacy"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flog.irc = log.WithFields(log.Fields{"module": "irc"})
|
||||||
|
flog.mm = log.WithFields(log.Fields{"module": "mattermost"})
|
||||||
|
flog.xmpp = log.WithFields(log.Fields{"module": "xmpp"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(cfg *config.Config, c chan config.Message) *Bmattermost {
|
||||||
|
b := &Bmattermost{}
|
||||||
|
b.Config = cfg
|
||||||
|
b.Remote = c
|
||||||
|
b.Plus = cfg.General.Plus
|
||||||
|
b.mmMap = make(map[string]string)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Command(cmd string) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Connect() error {
|
||||||
|
if !b.Plus {
|
||||||
|
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
||||||
|
matterhook.Config{InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.Mattermost.BindAddress})
|
||||||
|
} else {
|
||||||
|
b.mc = matterclient.New(b.Config.Mattermost.Login, b.Config.Mattermost.Password,
|
||||||
|
b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
||||||
|
b.mc.SkipTLSVerify = b.Config.Mattermost.SkipTLSVerify
|
||||||
|
b.mc.NoTLS = b.Config.Mattermost.NoTLS
|
||||||
|
flog.mm.Infof("Trying login %s (team: %s) on %s", b.Config.Mattermost.Login, b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
||||||
|
err := b.mc.Login()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
flog.mm.Info("Login ok")
|
||||||
|
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
||||||
|
for _, val := range b.Config.Channel {
|
||||||
|
b.mc.JoinChannel(val.Mattermost)
|
||||||
|
}
|
||||||
|
go b.mc.WsReceiver()
|
||||||
|
}
|
||||||
|
go b.handleMatter()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Name() string {
|
||||||
|
return "mattermost"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) Send(msg config.Message) error {
|
||||||
|
flog.mm.Infof("mattermost send %#v", msg)
|
||||||
|
if msg.Origin != "mattermost" {
|
||||||
|
return b.SendType(msg.Username, msg.Text, msg.Channel, "")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) SendType(nick string, message string, channel string, mtype string) error {
|
||||||
|
if b.Config.Mattermost.PrefixMessagesWithNick {
|
||||||
|
/*if IsMarkup(message) {
|
||||||
|
message = nick + "\n\n" + message
|
||||||
|
} else {
|
||||||
|
*/
|
||||||
|
message = nick + " " + message
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
if !b.Plus {
|
||||||
|
matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL}
|
||||||
|
matterMessage.Channel = channel
|
||||||
|
matterMessage.UserName = nick
|
||||||
|
matterMessage.Type = mtype
|
||||||
|
matterMessage.Text = message
|
||||||
|
err := b.mh.Send(matterMessage)
|
||||||
|
if err != nil {
|
||||||
|
flog.mm.Info(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
flog.mm.Debug("->mattermost channel plus: ", channel, " ", message)
|
||||||
|
b.mc.PostMessage(b.mc.GetChannelId(channel, ""), message)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) handleMatter() {
|
||||||
|
flog.mm.Infof("Choosing API based Mattermost connection: %t", b.Plus)
|
||||||
|
mchan := make(chan *MMMessage)
|
||||||
|
if b.Plus {
|
||||||
|
go b.handleMatterClient(mchan)
|
||||||
|
} else {
|
||||||
|
go b.handleMatterHook(mchan)
|
||||||
|
}
|
||||||
|
flog.mm.Info("Start listening for Mattermost messages")
|
||||||
|
for message := range mchan {
|
||||||
|
texts := strings.Split(message.Text, "\n")
|
||||||
|
for _, text := range texts {
|
||||||
|
flog.mm.Debug("Sending message from " + message.Username + " to " + message.Channel)
|
||||||
|
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: "mattermost"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) {
|
||||||
|
for message := range b.mc.MessageChan {
|
||||||
|
// do not post our own messages back to irc
|
||||||
|
if message.Raw.Event == "posted" && b.mc.User.Username != message.Username {
|
||||||
|
flog.mm.Debugf("receiving from matterclient %#v", message)
|
||||||
|
flog.mm.Debugf("receiving from matterclient %#v", message.Raw)
|
||||||
|
m := &MMMessage{}
|
||||||
|
m.Username = message.Username
|
||||||
|
m.Channel = message.Channel
|
||||||
|
m.Text = message.Text
|
||||||
|
mchan <- m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) handleMatterHook(mchan chan *MMMessage) {
|
||||||
|
for {
|
||||||
|
message := b.mh.Receive()
|
||||||
|
flog.mm.Debugf("receiving from matterhook %#v", message)
|
||||||
|
m := &MMMessage{}
|
||||||
|
m.Username = message.UserName
|
||||||
|
m.Text = message.Text
|
||||||
|
m.Channel = message.ChannelName
|
||||||
|
mchan <- m
|
||||||
|
}
|
||||||
|
}
|
||||||
133
bridge/xmpp/xmpp.go
Normal file
133
bridge/xmpp/xmpp.go
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
package bxmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/mattn/go-xmpp"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Bxmpp struct {
|
||||||
|
xc *xmpp.Client
|
||||||
|
xmppMap map[string]string
|
||||||
|
*config.Config
|
||||||
|
Remote chan config.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
type FancyLog struct {
|
||||||
|
xmpp *log.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Text string
|
||||||
|
Channel string
|
||||||
|
Username string
|
||||||
|
}
|
||||||
|
|
||||||
|
var flog FancyLog
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flog.xmpp = log.WithFields(log.Fields{"module": "xmpp"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(config *config.Config, c chan config.Message) *Bxmpp {
|
||||||
|
b := &Bxmpp{}
|
||||||
|
b.xmppMap = make(map[string]string)
|
||||||
|
b.Config = config
|
||||||
|
b.Remote = c
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) Connect() error {
|
||||||
|
var err error
|
||||||
|
flog.xmpp.Info("Trying XMPP connection")
|
||||||
|
b.xc, err = b.createXMPP()
|
||||||
|
if err != nil {
|
||||||
|
flog.xmpp.Debugf("%#v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
flog.xmpp.Info("Connection succeeded")
|
||||||
|
b.setupChannels()
|
||||||
|
go b.handleXmpp()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) Name() string {
|
||||||
|
return "xmpp"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) Send(msg config.Message) error {
|
||||||
|
b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Xmpp.Muc, Text: msg.Username + msg.Text})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) createXMPP() (*xmpp.Client, error) {
|
||||||
|
options := xmpp.Options{
|
||||||
|
Host: b.Config.Xmpp.Server,
|
||||||
|
User: b.Config.Xmpp.Jid,
|
||||||
|
Password: b.Config.Xmpp.Password,
|
||||||
|
NoTLS: true,
|
||||||
|
StartTLS: true,
|
||||||
|
//StartTLS: false,
|
||||||
|
Debug: true,
|
||||||
|
Session: true,
|
||||||
|
Status: "",
|
||||||
|
StatusMessage: "",
|
||||||
|
Resource: "",
|
||||||
|
InsecureAllowUnencryptedAuth: false,
|
||||||
|
//InsecureAllowUnencryptedAuth: true,
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
b.xc, err = options.NewClient()
|
||||||
|
return b.xc, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) setupChannels() {
|
||||||
|
for _, val := range b.Config.Channel {
|
||||||
|
flog.xmpp.Infof("Joining %s as %s", val.Xmpp, b.Xmpp.Nick)
|
||||||
|
b.xc.JoinMUCNoHistory(val.Xmpp+"@"+b.Xmpp.Muc, b.Xmpp.Nick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) xmppKeepAlive() {
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(90 * time.Second)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
b.xc.Send(xmpp.Chat{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bxmpp) handleXmpp() error {
|
||||||
|
for {
|
||||||
|
m, err := b.xc.Recv()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch v := m.(type) {
|
||||||
|
case xmpp.Chat:
|
||||||
|
var channel, nick string
|
||||||
|
if v.Type == "groupchat" {
|
||||||
|
s := strings.Split(v.Remote, "@")
|
||||||
|
if len(s) == 2 {
|
||||||
|
channel = s[0]
|
||||||
|
}
|
||||||
|
s = strings.Split(s[1], "/")
|
||||||
|
if len(s) == 2 {
|
||||||
|
nick = s[1]
|
||||||
|
}
|
||||||
|
if nick != b.Xmpp.Nick {
|
||||||
|
flog.xmpp.Infof("sending message to remote %s %s %s", nick, v.Text, channel)
|
||||||
|
b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Origin: "xmpp"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case xmpp.Presence:
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
changelog.md
Normal file
19
changelog.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# v0.6.0
|
||||||
|
## Breaking changes from 0.5 to 0.6
|
||||||
|
### commandline
|
||||||
|
* -plus switch deprecated. Use ```Plus=true``` or ```Plus``` in ```[general]``` section
|
||||||
|
### IRC section
|
||||||
|
* ```Enabled``` added (default false)
|
||||||
|
Add ```Enabled=true``` or ```Enabled``` to the ```[IRC]``` section if you want to enable the IRC bridge
|
||||||
|
### Mattermost section
|
||||||
|
* ```Enabled``` added (default false)
|
||||||
|
Add ```Enabled=true``` or ```Enabled``` to the ```[mattermost]``` section if you want to enable the mattermostbridge
|
||||||
|
### General section
|
||||||
|
* Use ```Plus=true``` or ```Plus``` in ```[general]``` section to enable the API version of matterbridge
|
||||||
|
|
||||||
|
## New features
|
||||||
|
* Matterbridge now bridges between any specified protocol (not only mattermost anymore)
|
||||||
|
* XMPP support added. See matterbridge.conf.sample for more information
|
||||||
|
* RemoteNickFormat {BRIDGE} variable added
|
||||||
|
You can now add the originating bridge to ```RemoteNickFormat```
|
||||||
|
eg ```RemoteNickFormat="[{BRIDGE}] <{NICK}> "```
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
#IRC section
|
#IRC section
|
||||||
###################################################################
|
###################################################################
|
||||||
[IRC]
|
[IRC]
|
||||||
|
#Enable enables this bridge
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
Enable=true
|
||||||
#irc server to connect to.
|
#irc server to connect to.
|
||||||
#REQUIRED
|
#REQUIRED
|
||||||
Server="irc.freenode.net:6667"
|
Server="irc.freenode.net:6667"
|
||||||
@@ -13,7 +16,7 @@ UseTLS=false
|
|||||||
|
|
||||||
#Enable SASL (PLAIN) authentication. (freenode requires this from eg AWS hosts)
|
#Enable SASL (PLAIN) authentication. (freenode requires this from eg AWS hosts)
|
||||||
#It uses NickServNick and NickServPassword as login and password
|
#It uses NickServNick and NickServPassword as login and password
|
||||||
#OPTIONAL (deefault false)
|
#OPTIONAL (default false)
|
||||||
UseSASL=false
|
UseSASL=false
|
||||||
|
|
||||||
#Enable to not verify the certificate on your irc server. i
|
#Enable to not verify the certificate on your irc server. i
|
||||||
@@ -41,11 +44,44 @@ RemoteNickFormat="{NICK}: "
|
|||||||
#OPTIONAL
|
#OPTIONAL
|
||||||
IgnoreNicks="ircspammer1 ircspammer2"
|
IgnoreNicks="ircspammer1 ircspammer2"
|
||||||
|
|
||||||
|
###################################################################
|
||||||
|
#XMPP section
|
||||||
|
###################################################################
|
||||||
|
[XMPP]
|
||||||
|
#Enable enables this bridge
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
Enable=true
|
||||||
|
|
||||||
|
#xmpp server to connect to.
|
||||||
|
#REQUIRED
|
||||||
|
Server="jabber.example.com:5222"
|
||||||
|
|
||||||
|
#Jid
|
||||||
|
#REQUIRED
|
||||||
|
Jid="user@example.com"
|
||||||
|
|
||||||
|
#Password
|
||||||
|
#REQUIRED
|
||||||
|
Password="yourpass"
|
||||||
|
|
||||||
|
#MUC
|
||||||
|
#REQUIRED
|
||||||
|
Muc="conference.jabber.example.com"
|
||||||
|
|
||||||
|
#Your nick in the rooms
|
||||||
|
#REQUIRED
|
||||||
|
Nick="xmppbot"
|
||||||
|
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
#mattermost section
|
#mattermost section
|
||||||
###################################################################
|
###################################################################
|
||||||
|
|
||||||
[mattermost]
|
[mattermost]
|
||||||
|
#Enable enables this bridge
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
Enable=true
|
||||||
|
|
||||||
#### Settings for webhook matterbridge.
|
#### Settings for webhook matterbridge.
|
||||||
#### These settings will not be used when using -plus switch which doesn't use
|
#### These settings will not be used when using -plus switch which doesn't use
|
||||||
#### webhooks.
|
#### webhooks.
|
||||||
@@ -83,7 +119,7 @@ Team="yourteam"
|
|||||||
Login="yourlogin"
|
Login="yourlogin"
|
||||||
Password="yourpass"
|
Password="yourpass"
|
||||||
|
|
||||||
#Disable to make a http connection to your mattermost.
|
#Enable this to make a http connection (instead of https) to your mattermost.
|
||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
NoTLS=false
|
NoTLS=false
|
||||||
|
|
||||||
@@ -134,10 +170,13 @@ IgnoreNicks="mmbot spammer2"
|
|||||||
IRC="#off-topic"
|
IRC="#off-topic"
|
||||||
#Choose the mattermost channel to send IRC messages to.
|
#Choose the mattermost channel to send IRC messages to.
|
||||||
mattermost="off-topic"
|
mattermost="off-topic"
|
||||||
|
#Choose the mattermost channel to send IRC messages to.
|
||||||
|
xmpp="off-topic"
|
||||||
|
|
||||||
[Channel "testchannel"]
|
[Channel "testchannel"]
|
||||||
IRC="#testing"
|
IRC="#testing"
|
||||||
mattermost="testing"
|
mattermost="testing"
|
||||||
|
xmpp="testing"
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
#general
|
#general
|
||||||
@@ -146,3 +185,6 @@ mattermost="testing"
|
|||||||
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key.
|
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key.
|
||||||
#OPTIONAL
|
#OPTIONAL
|
||||||
GiphyApiKey="dc6zaTOxFJmzC"
|
GiphyApiKey="dc6zaTOxFJmzC"
|
||||||
|
|
||||||
|
#Enabling plus means you'll use the API version instead of the webhooks one
|
||||||
|
Plus=false
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "0.5.0-beta2"
|
var version = "0.6.0-beta1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
||||||
@@ -17,7 +18,7 @@ func main() {
|
|||||||
flagConfig := flag.String("conf", "matterbridge.conf", "config file")
|
flagConfig := flag.String("conf", "matterbridge.conf", "config file")
|
||||||
flagDebug := flag.Bool("debug", false, "enable debug")
|
flagDebug := flag.Bool("debug", false, "enable debug")
|
||||||
flagVersion := flag.Bool("version", false, "show version")
|
flagVersion := flag.Bool("version", false, "show version")
|
||||||
flagPlus := flag.Bool("plus", false, "running using API instead of webhooks")
|
flagPlus := flag.Bool("plus", false, "running using API instead of webhooks (deprecated, set Plus flag in [general] config)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *flagVersion {
|
if *flagVersion {
|
||||||
fmt.Println("version:", version)
|
fmt.Println("version:", version)
|
||||||
@@ -29,10 +30,12 @@ func main() {
|
|||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
fmt.Println("running version", version)
|
fmt.Println("running version", version)
|
||||||
|
cfg := config.NewConfig(*flagConfig)
|
||||||
if *flagPlus {
|
if *flagPlus {
|
||||||
bridge.NewBridge("matterbot", bridge.NewConfig(*flagConfig), "")
|
cfg.General.Plus = true
|
||||||
} else {
|
}
|
||||||
bridge.NewBridge("matterbot", bridge.NewConfig(*flagConfig), "legacy")
|
err := bridge.NewBridge(cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("starting bridge failed %#v", err)
|
||||||
}
|
}
|
||||||
select {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package matterclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
@@ -27,7 +28,7 @@ type Credentials struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Raw *model.Message
|
Raw *model.WebSocketEvent
|
||||||
Post *model.Post
|
Post *model.Post
|
||||||
Team string
|
Team string
|
||||||
Channel string
|
Channel string
|
||||||
@@ -49,14 +50,16 @@ type MMClient struct {
|
|||||||
Team *Team
|
Team *Team
|
||||||
OtherTeams []*Team
|
OtherTeams []*Team
|
||||||
Client *model.Client
|
Client *model.Client
|
||||||
WsClient *websocket.Conn
|
|
||||||
WsQuit bool
|
|
||||||
WsAway bool
|
|
||||||
WsConnected bool
|
|
||||||
User *model.User
|
User *model.User
|
||||||
Users map[string]*model.User
|
Users map[string]*model.User
|
||||||
MessageChan chan *Message
|
MessageChan chan *Message
|
||||||
log *log.Entry
|
log *log.Entry
|
||||||
|
WsClient *websocket.Conn
|
||||||
|
WsQuit bool
|
||||||
|
WsAway bool
|
||||||
|
WsConnected bool
|
||||||
|
WsSequence int64
|
||||||
|
WsPingChan chan *model.WebSocketResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(login, pass, team, server string) *MMClient {
|
func New(login, pass, team, server string) *MMClient {
|
||||||
@@ -151,7 +154,7 @@ func (m *MMClient) Login() error {
|
|||||||
m.Client.SetTeamId(m.Team.Id)
|
m.Client.SetTeamId(m.Team.Id)
|
||||||
|
|
||||||
// setup websocket connection
|
// setup websocket connection
|
||||||
wsurl := wsScheme + m.Credentials.Server + "/api/v3/users/websocket"
|
wsurl := wsScheme + m.Credentials.Server + model.API_URL_SUFFIX + "/users/websocket"
|
||||||
header := http.Header{}
|
header := http.Header{}
|
||||||
header.Set(model.HEADER_AUTH, "BEARER "+m.Client.AuthToken)
|
header.Set(model.HEADER_AUTH, "BEARER "+m.Client.AuthToken)
|
||||||
|
|
||||||
@@ -169,6 +172,8 @@ func (m *MMClient) Login() error {
|
|||||||
}
|
}
|
||||||
b.Reset()
|
b.Reset()
|
||||||
|
|
||||||
|
m.WsSequence = 1
|
||||||
|
m.WsPingChan = make(chan *model.WebSocketResponse)
|
||||||
// only start to parse WS messages when login is completely done
|
// only start to parse WS messages when login is completely done
|
||||||
m.WsConnected = true
|
m.WsConnected = true
|
||||||
|
|
||||||
@@ -190,42 +195,44 @@ func (m *MMClient) Logout() error {
|
|||||||
|
|
||||||
func (m *MMClient) WsReceiver() {
|
func (m *MMClient) WsReceiver() {
|
||||||
for {
|
for {
|
||||||
var rmsg model.Message
|
var rawMsg json.RawMessage
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if !m.WsConnected {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if m.WsQuit {
|
if m.WsQuit {
|
||||||
m.log.Debug("exiting WsReceiver")
|
m.log.Debug("exiting WsReceiver")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := m.WsClient.ReadJSON(&rmsg); err != nil {
|
|
||||||
|
if _, rawMsg, err = m.WsClient.ReadMessage(); err != nil {
|
||||||
m.log.Error("error:", err)
|
m.log.Error("error:", err)
|
||||||
// reconnect
|
// reconnect
|
||||||
m.Login()
|
m.Login()
|
||||||
}
|
}
|
||||||
// we're not fully logged in yet.
|
|
||||||
if !m.WsConnected {
|
var event model.WebSocketEvent
|
||||||
continue
|
if err := json.Unmarshal(rawMsg, &event); err == nil && event.IsValid() {
|
||||||
}
|
m.log.Debugf("WsReceiver: %#v", event)
|
||||||
if rmsg.Action == "ping" {
|
msg := &Message{Raw: &event, Team: m.Credentials.Team}
|
||||||
m.handleWsPing()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
msg := &Message{Raw: &rmsg, Team: m.Credentials.Team}
|
|
||||||
m.parseMessage(msg)
|
m.parseMessage(msg)
|
||||||
m.MessageChan <- msg
|
m.MessageChan <- msg
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
var response model.WebSocketResponse
|
||||||
|
if err := json.Unmarshal(rawMsg, &response); err == nil && response.IsValid() {
|
||||||
func (m *MMClient) handleWsPing() {
|
m.log.Debugf("WsReceiver: %#v", response)
|
||||||
m.log.Debug("Ws PING")
|
m.parseResponse(response)
|
||||||
if !m.WsQuit && !m.WsAway {
|
continue
|
||||||
m.log.Debug("Ws PONG")
|
}
|
||||||
m.WsClient.WriteMessage(websocket.PongMessage, []byte{})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) parseMessage(rmsg *Message) {
|
func (m *MMClient) parseMessage(rmsg *Message) {
|
||||||
switch rmsg.Raw.Action {
|
switch rmsg.Raw.Event {
|
||||||
case model.ACTION_POSTED:
|
case model.WEBSOCKET_EVENT_POSTED:
|
||||||
m.parseActionPost(rmsg)
|
m.parseActionPost(rmsg)
|
||||||
/*
|
/*
|
||||||
case model.ACTION_USER_REMOVED:
|
case model.ACTION_USER_REMOVED:
|
||||||
@@ -236,8 +243,17 @@ func (m *MMClient) parseMessage(rmsg *Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MMClient) parseResponse(rmsg model.WebSocketResponse) {
|
||||||
|
if rmsg.Data != nil {
|
||||||
|
// ping reply
|
||||||
|
if rmsg.Data["text"].(string) == "pong" {
|
||||||
|
m.WsPingChan <- &rmsg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MMClient) parseActionPost(rmsg *Message) {
|
func (m *MMClient) parseActionPost(rmsg *Message) {
|
||||||
data := model.PostFromJson(strings.NewReader(rmsg.Raw.Props["post"]))
|
data := model.PostFromJson(strings.NewReader(rmsg.Raw.Data["post"].(string)))
|
||||||
// we don't have the user, refresh the userlist
|
// we don't have the user, refresh the userlist
|
||||||
if m.GetUser(data.UserId) == nil {
|
if m.GetUser(data.UserId) == nil {
|
||||||
m.UpdateUsers()
|
m.UpdateUsers()
|
||||||
@@ -246,7 +262,7 @@ func (m *MMClient) parseActionPost(rmsg *Message) {
|
|||||||
rmsg.Channel = m.GetChannelName(data.ChannelId)
|
rmsg.Channel = m.GetChannelName(data.ChannelId)
|
||||||
rmsg.Team = m.GetTeamName(rmsg.Raw.TeamId)
|
rmsg.Team = m.GetTeamName(rmsg.Raw.TeamId)
|
||||||
// direct message
|
// direct message
|
||||||
if data.Type == "D" {
|
if rmsg.Raw.Data["channel_type"] == "D" {
|
||||||
rmsg.Channel = m.GetUser(data.UserId).Username
|
rmsg.Channel = m.GetUser(data.UserId).Username
|
||||||
}
|
}
|
||||||
rmsg.Text = data.Message
|
rmsg.Text = data.Message
|
||||||
@@ -255,7 +271,10 @@ func (m *MMClient) parseActionPost(rmsg *Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateUsers() error {
|
func (m *MMClient) UpdateUsers() error {
|
||||||
mmusers, _ := m.Client.GetProfilesForDirectMessageList(m.Team.Id)
|
mmusers, err := m.Client.GetProfilesForDirectMessageList(m.Team.Id)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New(err.DetailedError)
|
||||||
|
}
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.Users = mmusers.Data.(map[string]*model.User)
|
m.Users = mmusers.Data.(map[string]*model.User)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
@@ -263,8 +282,14 @@ func (m *MMClient) UpdateUsers() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateChannels() error {
|
func (m *MMClient) UpdateChannels() error {
|
||||||
mmchannels, _ := m.Client.GetChannels("")
|
mmchannels, err := m.Client.GetChannels("")
|
||||||
mmchannels2, _ := m.Client.GetMoreChannels("")
|
if err != nil {
|
||||||
|
return errors.New(err.DetailedError)
|
||||||
|
}
|
||||||
|
mmchannels2, err := m.Client.GetMoreChannels("")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New(err.DetailedError)
|
||||||
|
}
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.Team.Channels = mmchannels.Data.(*model.ChannelList)
|
m.Team.Channels = mmchannels.Data.(*model.ChannelList)
|
||||||
m.Team.MoreChannels = mmchannels2.Data.(*model.ChannelList)
|
m.Team.MoreChannels = mmchannels2.Data.(*model.ChannelList)
|
||||||
@@ -534,6 +559,42 @@ func (m *MMClient) GetUser(userId string) *model.User {
|
|||||||
return m.Users[userId]
|
return m.Users[userId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MMClient) GetStatus(userId string) string {
|
||||||
|
res, err := m.Client.GetStatuses()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
status := res.Data.(map[string]string)
|
||||||
|
if status[userId] == model.STATUS_AWAY {
|
||||||
|
return "away"
|
||||||
|
}
|
||||||
|
if status[userId] == model.STATUS_ONLINE {
|
||||||
|
return "online"
|
||||||
|
}
|
||||||
|
return "offline"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MMClient) StatusLoop() {
|
||||||
|
for {
|
||||||
|
if m.WsQuit {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if m.WsConnected {
|
||||||
|
m.log.Debug("WS PING")
|
||||||
|
m.sendWSRequest("ping", nil)
|
||||||
|
select {
|
||||||
|
case <-m.WsPingChan:
|
||||||
|
m.log.Debug("WS PONG received")
|
||||||
|
case <-time.After(time.Second * 5):
|
||||||
|
m.Logout()
|
||||||
|
m.WsQuit = false
|
||||||
|
m.Login()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second * 60)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initialize user and teams
|
// initialize user and teams
|
||||||
func (m *MMClient) initUser() error {
|
func (m *MMClient) initUser() error {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
@@ -568,3 +629,14 @@ func (m *MMClient) initUser() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MMClient) sendWSRequest(action string, data map[string]interface{}) error {
|
||||||
|
req := &model.WebSocketRequest{}
|
||||||
|
req.Seq = m.WsSequence
|
||||||
|
req.Action = action
|
||||||
|
req.Data = data
|
||||||
|
m.WsSequence++
|
||||||
|
m.log.Debugf("sendWsRequest %#v", req)
|
||||||
|
m.WsClient.WriteJSON(req)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
20
vendor/github.com/mattermost/platform/einterfaces/account_migration.go
generated
vendored
Normal file
20
vendor/github.com/mattermost/platform/einterfaces/account_migration.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package einterfaces
|
||||||
|
|
||||||
|
import "github.com/mattermost/platform/model"
|
||||||
|
|
||||||
|
type AccountMigrationInterface interface {
|
||||||
|
MigrateToLdap(fromAuthService string, forignUserFieldNameToMatch string) *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
var theAccountMigrationInterface AccountMigrationInterface
|
||||||
|
|
||||||
|
func RegisterAccountMigrationInterface(newInterface AccountMigrationInterface) {
|
||||||
|
theAccountMigrationInterface = newInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAccountMigrationInterface() AccountMigrationInterface {
|
||||||
|
return theAccountMigrationInterface
|
||||||
|
}
|
||||||
32
vendor/github.com/mattermost/platform/einterfaces/cluster.go
generated
vendored
Normal file
32
vendor/github.com/mattermost/platform/einterfaces/cluster.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package einterfaces
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClusterInterface interface {
|
||||||
|
StartInterNodeCommunication()
|
||||||
|
StopInterNodeCommunication()
|
||||||
|
GetClusterInfos() []*model.ClusterInfo
|
||||||
|
RemoveAllSessionsForUserId(userId string)
|
||||||
|
InvalidateCacheForUser(userId string)
|
||||||
|
InvalidateCacheForChannel(channelId string)
|
||||||
|
Publish(event *model.WebSocketEvent)
|
||||||
|
UpdateStatus(status *model.Status)
|
||||||
|
GetLogs() ([]string, *model.AppError)
|
||||||
|
GetClusterId() string
|
||||||
|
ConfigChanged(previousConfig *model.Config, newConfig *model.Config, sendToOtherServer bool) *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
var theClusterInterface ClusterInterface
|
||||||
|
|
||||||
|
func RegisterClusterInterface(newInterface ClusterInterface) {
|
||||||
|
theClusterInterface = newInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetClusterInterface() ClusterInterface {
|
||||||
|
return theClusterInterface
|
||||||
|
}
|
||||||
2
vendor/github.com/mattermost/platform/einterfaces/ldap.go
generated
vendored
2
vendor/github.com/mattermost/platform/einterfaces/ldap.go
generated
vendored
@@ -15,6 +15,8 @@ type LdapInterface interface {
|
|||||||
ValidateFilter(filter string) *model.AppError
|
ValidateFilter(filter string) *model.AppError
|
||||||
Syncronize() *model.AppError
|
Syncronize() *model.AppError
|
||||||
StartLdapSyncJob()
|
StartLdapSyncJob()
|
||||||
|
SyncNow()
|
||||||
|
GetAllLdapUsers() ([]*model.User, *model.AppError)
|
||||||
}
|
}
|
||||||
|
|
||||||
var theLdapInterface LdapInterface
|
var theLdapInterface LdapInterface
|
||||||
|
|||||||
25
vendor/github.com/mattermost/platform/model/access.go
generated
vendored
25
vendor/github.com/mattermost/platform/model/access.go
generated
vendored
@@ -15,10 +15,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AccessData struct {
|
type AccessData struct {
|
||||||
AuthCode string `json:"auth_code"`
|
ClientId string `json:"client_id"`
|
||||||
|
UserId string `json:"user_id"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
RedirectUri string `json:"redirect_uri"`
|
RedirectUri string `json:"redirect_uri"`
|
||||||
|
ExpiresAt int64 `json:"expires_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessResponse struct {
|
type AccessResponse struct {
|
||||||
@@ -33,8 +35,12 @@ type AccessResponse struct {
|
|||||||
// correctly.
|
// correctly.
|
||||||
func (ad *AccessData) IsValid() *AppError {
|
func (ad *AccessData) IsValid() *AppError {
|
||||||
|
|
||||||
if len(ad.AuthCode) == 0 || len(ad.AuthCode) > 128 {
|
if len(ad.ClientId) == 0 || len(ad.ClientId) > 26 {
|
||||||
return NewLocAppError("AccessData.IsValid", "model.access.is_valid.auth_code.app_error", nil, "")
|
return NewLocAppError("AccessData.IsValid", "model.access.is_valid.client_id.app_error", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ad.UserId) == 0 || len(ad.UserId) > 26 {
|
||||||
|
return NewLocAppError("AccessData.IsValid", "model.access.is_valid.user_id.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ad.Token) != 26 {
|
if len(ad.Token) != 26 {
|
||||||
@@ -52,6 +58,19 @@ func (ad *AccessData) IsValid() *AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *AccessData) IsExpired() bool {
|
||||||
|
|
||||||
|
if me.ExpiresAt <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if GetMillis() > me.ExpiresAt {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (ad *AccessData) ToJson() string {
|
func (ad *AccessData) ToJson() string {
|
||||||
b, err := json.Marshal(ad)
|
b, err := json.Marshal(ad)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
5
vendor/github.com/mattermost/platform/model/authorize.go
generated
vendored
5
vendor/github.com/mattermost/platform/model/authorize.go
generated
vendored
@@ -11,6 +11,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
AUTHCODE_EXPIRE_TIME = 60 * 10 // 10 minutes
|
AUTHCODE_EXPIRE_TIME = 60 * 10 // 10 minutes
|
||||||
AUTHCODE_RESPONSE_TYPE = "code"
|
AUTHCODE_RESPONSE_TYPE = "code"
|
||||||
|
DEFAULT_SCOPE = "user"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthData struct {
|
type AuthData struct {
|
||||||
@@ -71,6 +72,10 @@ func (ad *AuthData) PreSave() {
|
|||||||
if ad.CreateAt == 0 {
|
if ad.CreateAt == 0 {
|
||||||
ad.CreateAt = GetMillis()
|
ad.CreateAt = GetMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(ad.Scope) == 0 {
|
||||||
|
ad.Scope = DEFAULT_SCOPE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ad *AuthData) ToJson() string {
|
func (ad *AuthData) ToJson() string {
|
||||||
|
|||||||
3
vendor/github.com/mattermost/platform/model/channel.go
generated
vendored
3
vendor/github.com/mattermost/platform/model/channel.go
generated
vendored
@@ -124,9 +124,6 @@ func (o *Channel) ExtraUpdated() {
|
|||||||
o.ExtraUpdateAt = GetMillis()
|
o.ExtraUpdateAt = GetMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Channel) PreExport() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDMNameFromIds(userId1, userId2 string) string {
|
func GetDMNameFromIds(userId1, userId2 string) string {
|
||||||
if userId1 > userId2 {
|
if userId1 > userId2 {
|
||||||
return userId2 + "__" + userId1
|
return userId2 + "__" + userId1
|
||||||
|
|||||||
174
vendor/github.com/mattermost/platform/model/client.go
generated
vendored
174
vendor/github.com/mattermost/platform/model/client.go
generated
vendored
@@ -20,6 +20,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
HEADER_REQUEST_ID = "X-Request-ID"
|
HEADER_REQUEST_ID = "X-Request-ID"
|
||||||
HEADER_VERSION_ID = "X-Version-ID"
|
HEADER_VERSION_ID = "X-Version-ID"
|
||||||
|
HEADER_CLUSTER_ID = "X-Cluster-ID"
|
||||||
HEADER_ETAG_SERVER = "ETag"
|
HEADER_ETAG_SERVER = "ETag"
|
||||||
HEADER_ETAG_CLIENT = "If-None-Match"
|
HEADER_ETAG_CLIENT = "If-None-Match"
|
||||||
HEADER_FORWARDED = "X-Forwarded-For"
|
HEADER_FORWARDED = "X-Forwarded-For"
|
||||||
@@ -32,6 +33,7 @@ const (
|
|||||||
HEADER_REQUESTED_WITH_XML = "XMLHttpRequest"
|
HEADER_REQUESTED_WITH_XML = "XMLHttpRequest"
|
||||||
STATUS = "status"
|
STATUS = "status"
|
||||||
STATUS_OK = "OK"
|
STATUS_OK = "OK"
|
||||||
|
STATUS_FAIL = "FAIL"
|
||||||
|
|
||||||
API_URL_SUFFIX_V1 = "/api/v1"
|
API_URL_SUFFIX_V1 = "/api/v1"
|
||||||
API_URL_SUFFIX_V3 = "/api/v3"
|
API_URL_SUFFIX_V3 = "/api/v3"
|
||||||
@@ -276,6 +278,9 @@ func (c *Client) GetPing() (map[string]string, *AppError) {
|
|||||||
|
|
||||||
// Team Routes Section
|
// Team Routes Section
|
||||||
|
|
||||||
|
// SignupTeam sends an email with a team sign-up link to the provided address if email
|
||||||
|
// verification is enabled, otherwise it returns a map with a "follow_link" entry
|
||||||
|
// containing the team sign-up link.
|
||||||
func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppError) {
|
func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["email"] = email
|
m["email"] = email
|
||||||
@@ -289,6 +294,8 @@ func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppErro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTeamFromSignup creates a team based on the provided TeamSignup struct. On success
|
||||||
|
// it returns the TeamSignup struct.
|
||||||
func (c *Client) CreateTeamFromSignup(teamSignup *TeamSignup) (*Result, *AppError) {
|
func (c *Client) CreateTeamFromSignup(teamSignup *TeamSignup) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/teams/create_from_signup", teamSignup.ToJson()); err != nil {
|
if r, err := c.DoApiPost("/teams/create_from_signup", teamSignup.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -299,6 +306,8 @@ func (c *Client) CreateTeamFromSignup(teamSignup *TeamSignup) (*Result, *AppErro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTeam creates a team based on the provided Team struct. On success it returns
|
||||||
|
// the Team struct with the Id, CreateAt and other server-decided fields populated.
|
||||||
func (c *Client) CreateTeam(team *Team) (*Result, *AppError) {
|
func (c *Client) CreateTeam(team *Team) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/teams/create", team.ToJson()); err != nil {
|
if r, err := c.DoApiPost("/teams/create", team.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -309,6 +318,7 @@ func (c *Client) CreateTeam(team *Team) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllTeams returns a map of all teams using team ids as the key.
|
||||||
func (c *Client) GetAllTeams() (*Result, *AppError) {
|
func (c *Client) GetAllTeams() (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/teams/all", "", ""); err != nil {
|
if r, err := c.DoApiGet("/teams/all", "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -319,6 +329,8 @@ func (c *Client) GetAllTeams() (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllTeamListings returns a map of all teams that are available to join
|
||||||
|
// using team ids as the key. Must be authenticated.
|
||||||
func (c *Client) GetAllTeamListings() (*Result, *AppError) {
|
func (c *Client) GetAllTeamListings() (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/teams/all_team_listings", "", ""); err != nil {
|
if r, err := c.DoApiGet("/teams/all_team_listings", "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -329,6 +341,8 @@ func (c *Client) GetAllTeamListings() (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindTeamByName returns the strings "true" or "false" depending on if a team
|
||||||
|
// with the provided name was found.
|
||||||
func (c *Client) FindTeamByName(name string) (*Result, *AppError) {
|
func (c *Client) FindTeamByName(name string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["name"] = name
|
m["name"] = name
|
||||||
@@ -365,6 +379,8 @@ func (c *Client) AddUserToTeam(teamId string, userId string) (*Result, *AppError
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddUserToTeamFromInvite adds a user to a team based off data provided in an invite link.
|
||||||
|
// Either hash and dataToHash are required or inviteId is required.
|
||||||
func (c *Client) AddUserToTeamFromInvite(hash, dataToHash, inviteId string) (*Result, *AppError) {
|
func (c *Client) AddUserToTeamFromInvite(hash, dataToHash, inviteId string) (*Result, *AppError) {
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
data["hash"] = hash
|
data["hash"] = hash
|
||||||
@@ -409,6 +425,9 @@ func (c *Client) InviteMembers(invites *Invites) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateTeam updates a team based on the changes in the provided team struct. On success
|
||||||
|
// it returns a sanitized version of the updated team. Must be authenticated as a team admin
|
||||||
|
// for that team or a system admin.
|
||||||
func (c *Client) UpdateTeam(team *Team) (*Result, *AppError) {
|
func (c *Client) UpdateTeam(team *Team) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost(c.GetTeamRoute()+"/update", team.ToJson()); err != nil {
|
if r, err := c.DoApiPost(c.GetTeamRoute()+"/update", team.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -419,6 +438,9 @@ func (c *Client) UpdateTeam(team *Team) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// User Routes Section
|
||||||
|
|
||||||
|
// CreateUser creates a user in the system based on the provided user struct.
|
||||||
func (c *Client) CreateUser(user *User, hash string) (*Result, *AppError) {
|
func (c *Client) CreateUser(user *User, hash string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/users/create", user.ToJson()); err != nil {
|
if r, err := c.DoApiPost("/users/create", user.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -429,6 +451,8 @@ func (c *Client) CreateUser(user *User, hash string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateUserWithInvite creates a user based on the provided user struct. Either the hash and
|
||||||
|
// data strings or the inviteId is required from the invite.
|
||||||
func (c *Client) CreateUserWithInvite(user *User, hash string, data string, inviteId string) (*Result, *AppError) {
|
func (c *Client) CreateUserWithInvite(user *User, hash string, data string, inviteId string) (*Result, *AppError) {
|
||||||
|
|
||||||
url := "/users/create?d=" + url.QueryEscape(data) + "&h=" + url.QueryEscape(hash) + "&iid=" + url.QueryEscape(inviteId)
|
url := "/users/create?d=" + url.QueryEscape(data) + "&h=" + url.QueryEscape(hash) + "&iid=" + url.QueryEscape(inviteId)
|
||||||
@@ -452,6 +476,7 @@ func (c *Client) CreateUserFromSignup(user *User, data string, hash string) (*Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUser returns a user based on a provided user id string. Must be authenticated.
|
||||||
func (c *Client) GetUser(id string, etag string) (*Result, *AppError) {
|
func (c *Client) GetUser(id string, etag string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/"+id+"/get", "", etag); err != nil {
|
if r, err := c.DoApiGet("/users/"+id+"/get", "", etag); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -462,6 +487,7 @@ func (c *Client) GetUser(id string, etag string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMe returns the current user.
|
||||||
func (c *Client) GetMe(etag string) (*Result, *AppError) {
|
func (c *Client) GetMe(etag string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/me", "", etag); err != nil {
|
if r, err := c.DoApiGet("/users/me", "", etag); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -472,6 +498,8 @@ func (c *Client) GetMe(etag string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProfilesForDirectMessageList returns a map of users for a team that can be direct
|
||||||
|
// messaged, using user id as the key. Must be authenticated.
|
||||||
func (c *Client) GetProfilesForDirectMessageList(teamId string) (*Result, *AppError) {
|
func (c *Client) GetProfilesForDirectMessageList(teamId string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/profiles_for_dm_list/"+teamId, "", ""); err != nil {
|
if r, err := c.DoApiGet("/users/profiles_for_dm_list/"+teamId, "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -482,6 +510,8 @@ func (c *Client) GetProfilesForDirectMessageList(teamId string) (*Result, *AppEr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProfiles returns a map of users for a team using user id as the key. Must
|
||||||
|
// be authenticated.
|
||||||
func (c *Client) GetProfiles(teamId string, etag string) (*Result, *AppError) {
|
func (c *Client) GetProfiles(teamId string, etag string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/profiles/"+teamId, "", etag); err != nil {
|
if r, err := c.DoApiGet("/users/profiles/"+teamId, "", etag); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -492,6 +522,8 @@ func (c *Client) GetProfiles(teamId string, etag string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDirectProfiles gets a map of users that are currently shown in the sidebar,
|
||||||
|
// using user id as the key. Must be authenticated.
|
||||||
func (c *Client) GetDirectProfiles(etag string) (*Result, *AppError) {
|
func (c *Client) GetDirectProfiles(etag string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/direct_profiles", "", etag); err != nil {
|
if r, err := c.DoApiGet("/users/direct_profiles", "", etag); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -502,6 +534,7 @@ func (c *Client) GetDirectProfiles(etag string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginById authenticates a user by user id and password.
|
||||||
func (c *Client) LoginById(id string, password string) (*Result, *AppError) {
|
func (c *Client) LoginById(id string, password string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["id"] = id
|
m["id"] = id
|
||||||
@@ -509,6 +542,8 @@ func (c *Client) LoginById(id string, password string) (*Result, *AppError) {
|
|||||||
return c.login(m)
|
return c.login(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Login authenticates a user by login id, which can be username, email or some sort
|
||||||
|
// of SSO identifier based on configuration, and a password.
|
||||||
func (c *Client) Login(loginId string, password string) (*Result, *AppError) {
|
func (c *Client) Login(loginId string, password string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["login_id"] = loginId
|
m["login_id"] = loginId
|
||||||
@@ -516,6 +551,7 @@ func (c *Client) Login(loginId string, password string) (*Result, *AppError) {
|
|||||||
return c.login(m)
|
return c.login(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginByLdap authenticates a user by LDAP id and password.
|
||||||
func (c *Client) LoginByLdap(loginId string, password string) (*Result, *AppError) {
|
func (c *Client) LoginByLdap(loginId string, password string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["login_id"] = loginId
|
m["login_id"] = loginId
|
||||||
@@ -524,6 +560,9 @@ func (c *Client) LoginByLdap(loginId string, password string) (*Result, *AppErro
|
|||||||
return c.login(m)
|
return c.login(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginWithDevice authenticates a user by login id (username, email or some sort
|
||||||
|
// of SSO identifier based on configuration), password and attaches a device id to
|
||||||
|
// the session.
|
||||||
func (c *Client) LoginWithDevice(loginId string, password string, deviceId string) (*Result, *AppError) {
|
func (c *Client) LoginWithDevice(loginId string, password string, deviceId string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["login_id"] = loginId
|
m["login_id"] = loginId
|
||||||
@@ -550,6 +589,7 @@ func (c *Client) login(m map[string]string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logout terminates the current user's session.
|
||||||
func (c *Client) Logout() (*Result, *AppError) {
|
func (c *Client) Logout() (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/users/logout", ""); err != nil {
|
if r, err := c.DoApiPost("/users/logout", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -564,6 +604,9 @@ func (c *Client) Logout() (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckMfa returns a map with key "mfa_required" with the string value "true" or "false",
|
||||||
|
// indicating whether MFA is required to log the user in, based on a provided login id
|
||||||
|
// (username, email or some sort of SSO identifier based on configuration).
|
||||||
func (c *Client) CheckMfa(loginId string) (*Result, *AppError) {
|
func (c *Client) CheckMfa(loginId string) (*Result, *AppError) {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
m["login_id"] = loginId
|
m["login_id"] = loginId
|
||||||
@@ -577,6 +620,8 @@ func (c *Client) CheckMfa(loginId string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateMfaQrCode returns a QR code imagem containing the secret, to be scanned
|
||||||
|
// by a multi-factor authentication mobile application. Must be authenticated.
|
||||||
func (c *Client) GenerateMfaQrCode() (*Result, *AppError) {
|
func (c *Client) GenerateMfaQrCode() (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/users/generate_mfa_qr", "", ""); err != nil {
|
if r, err := c.DoApiGet("/users/generate_mfa_qr", "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -587,6 +632,9 @@ func (c *Client) GenerateMfaQrCode() (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateMfa activates multi-factor authenticates for the current user if activate
|
||||||
|
// is true and a valid token is provided. If activate is false, then token is not
|
||||||
|
// required and multi-factor authentication is disabled for the current user.
|
||||||
func (c *Client) UpdateMfa(activate bool, token string) (*Result, *AppError) {
|
func (c *Client) UpdateMfa(activate bool, token string) (*Result, *AppError) {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["activate"] = activate
|
m["activate"] = activate
|
||||||
@@ -761,6 +809,15 @@ func (c *Client) GetLogs() (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetClusterStatus() ([]*ClusterInfo, *AppError) {
|
||||||
|
if r, err := c.DoApiGet("/admin/cluster_status", "", ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return ClusterInfosFromJson(r.Body), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) GetAllAudits() (*Result, *AppError) {
|
func (c *Client) GetAllAudits() (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/admin/audits", "", ""); err != nil {
|
if r, err := c.DoApiGet("/admin/audits", "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1181,6 +1238,18 @@ func (c *Client) SearchPosts(terms string, isOrSearch bool) (*Result, *AppError)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFlaggedPosts will return a post list of posts that have been flagged by the user.
|
||||||
|
// The page is set by the integer parameters offset and limit.
|
||||||
|
func (c *Client) GetFlaggedPosts(offset int, limit int) (*Result, *AppError) {
|
||||||
|
if r, err := c.DoApiGet(c.GetTeamRoute()+fmt.Sprintf("/posts/flagged/%v/%v", offset, limit), "", ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||||
|
r.Header.Get(HEADER_ETAG_SERVER), PostListFromJson(r.Body)}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) UploadProfileFile(data []byte, contentType string) (*Result, *AppError) {
|
func (c *Client) UploadProfileFile(data []byte, contentType string) (*Result, *AppError) {
|
||||||
return c.uploadFile(c.ApiUrl+"/users/newimage", data, contentType)
|
return c.uploadFile(c.ApiUrl+"/users/newimage", data, contentType)
|
||||||
}
|
}
|
||||||
@@ -1368,8 +1437,9 @@ func (c *Client) AdminResetPassword(userId, newPassword string) (*Result, *AppEr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetStatuses(data []string) (*Result, *AppError) {
|
// GetStatuses returns a map of string statuses using user id as the key
|
||||||
if r, err := c.DoApiPost("/users/status", ArrayToJson(data)); err != nil {
|
func (c *Client) GetStatuses() (*Result, *AppError) {
|
||||||
|
if r, err := c.DoApiGet("/users/status", "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
@@ -1398,6 +1468,8 @@ func (c *Client) GetTeamMembers(teamId string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterApp creates a new OAuth2 app to be used with the OAuth2 Provider. On success
|
||||||
|
// it returns the created app. Must be authenticated as a user.
|
||||||
func (c *Client) RegisterApp(app *OAuthApp) (*Result, *AppError) {
|
func (c *Client) RegisterApp(app *OAuthApp) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/oauth/register", app.ToJson()); err != nil {
|
if r, err := c.DoApiPost("/oauth/register", app.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1408,6 +1480,9 @@ func (c *Client) RegisterApp(app *OAuthApp) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowOAuth allows a new session by an OAuth2 App. On success
|
||||||
|
// it returns the url to be redirected back to the app which initiated the oauth2 flow.
|
||||||
|
// Must be authenticated as a user.
|
||||||
func (c *Client) AllowOAuth(rspType, clientId, redirect, scope, state string) (*Result, *AppError) {
|
func (c *Client) AllowOAuth(rspType, clientId, redirect, scope, state string) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet("/oauth/allow?response_type="+rspType+"&client_id="+clientId+"&redirect_uri="+url.QueryEscape(redirect)+"&scope="+scope+"&state="+url.QueryEscape(state), "", ""); err != nil {
|
if r, err := c.DoApiGet("/oauth/allow?response_type="+rspType+"&client_id="+clientId+"&redirect_uri="+url.QueryEscape(redirect)+"&scope="+scope+"&state="+url.QueryEscape(state), "", ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1418,8 +1493,47 @@ func (c *Client) AllowOAuth(rspType, clientId, redirect, scope, state string) (*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOAuthAppsByUser returns the OAuth2 Apps registered by the user. On success
|
||||||
|
// it returns a list of OAuth2 Apps from the same user or all the registered apps if the user
|
||||||
|
// is a System Administrator. Must be authenticated as a user.
|
||||||
|
func (c *Client) GetOAuthAppsByUser() (*Result, *AppError) {
|
||||||
|
if r, err := c.DoApiGet("/oauth/list", "", ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||||
|
r.Header.Get(HEADER_ETAG_SERVER), OAuthAppListFromJson(r.Body)}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOAuthAppInfo lookup an OAuth2 App using the client_id. On success
|
||||||
|
// it returns a Sanitized OAuth2 App. Must be authenticated as a user.
|
||||||
|
func (c *Client) GetOAuthAppInfo(clientId string) (*Result, *AppError) {
|
||||||
|
if r, err := c.DoApiGet("/oauth/app/"+clientId, "", ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||||
|
r.Header.Get(HEADER_ETAG_SERVER), OAuthAppFromJson(r.Body)}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOAuthApp deletes an OAuth2 app, the app must be deleted by the same user who created it or
|
||||||
|
// a System Administrator. On success returs Status OK. Must be authenticated as a user.
|
||||||
|
func (c *Client) DeleteOAuthApp(id string) (*Result, *AppError) {
|
||||||
|
data := make(map[string]string)
|
||||||
|
data["id"] = id
|
||||||
|
if r, err := c.DoApiPost("/oauth/delete", MapToJson(data)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||||
|
r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) GetAccessToken(data url.Values) (*Result, *AppError) {
|
func (c *Client) GetAccessToken(data url.Values) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost("/oauth/access_token", data.Encode()); err != nil {
|
if r, err := c.DoPost("/oauth/access_token", data.Encode(), "application/x-www-form-urlencoded"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
@@ -1509,6 +1623,16 @@ func (c *Client) GetPreferenceCategory(category string) (*Result, *AppError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeletePreferences deletes a list of preferences owned by the current user. If successful,
|
||||||
|
// it will return status=ok. Otherwise, an error will be returned.
|
||||||
|
func (c *Client) DeletePreferences(preferences *Preferences) (bool, *AppError) {
|
||||||
|
if r, err := c.DoApiPost("/preferences/delete", preferences.ToJson()); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else {
|
||||||
|
return c.CheckStatusOK(r), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) CreateOutgoingWebhook(hook *OutgoingWebhook) (*Result, *AppError) {
|
func (c *Client) CreateOutgoingWebhook(hook *OutgoingWebhook) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiPost(c.GetTeamRoute()+"/hooks/outgoing/create", hook.ToJson()); err != nil {
|
if r, err := c.DoApiPost(c.GetTeamRoute()+"/hooks/outgoing/create", hook.ToJson()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1648,3 +1772,47 @@ func (c *Client) DeleteEmoji(id string) (bool, *AppError) {
|
|||||||
func (c *Client) GetCustomEmojiImageUrl(id string) string {
|
func (c *Client) GetCustomEmojiImageUrl(id string) string {
|
||||||
return c.GetEmojiRoute() + "/" + id
|
return c.GetEmojiRoute() + "/" + id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uploads a x509 base64 Certificate or Private Key file to be used with SAML.
|
||||||
|
// data byte array is required and needs to be a Multi-Part with 'certificate' as the field name
|
||||||
|
// contentType is also required. Returns nil if succesful, otherwise returns an AppError
|
||||||
|
func (c *Client) UploadCertificateFile(data []byte, contentType string) *AppError {
|
||||||
|
url := c.ApiUrl + "/admin/add_certificate"
|
||||||
|
rq, _ := http.NewRequest("POST", url, bytes.NewReader(data))
|
||||||
|
rq.Header.Set("Content-Type", contentType)
|
||||||
|
|
||||||
|
if len(c.AuthToken) > 0 {
|
||||||
|
rq.Header.Set(HEADER_AUTH, "BEARER "+c.AuthToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rp, err := c.HttpClient.Do(rq); err != nil {
|
||||||
|
return NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
|
||||||
|
} else if rp.StatusCode >= 300 {
|
||||||
|
return AppErrorFromJson(rp.Body)
|
||||||
|
} else {
|
||||||
|
defer closeBody(rp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removes a x509 base64 Certificate or Private Key file used with SAML.
|
||||||
|
// filename is required. Returns nil if successful, otherwise returns an AppError
|
||||||
|
func (c *Client) RemoveCertificateFile(filename string) *AppError {
|
||||||
|
if r, err := c.DoApiPost("/admin/remove_certificate", MapToJson(map[string]string{"filename": filename})); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the x509 base64 Certificates and Private Key files used with SAML exists on the file system.
|
||||||
|
// Returns a map[string]interface{} if successful, otherwise returns an AppError. Must be System Admin authenticated.
|
||||||
|
func (c *Client) SamlCertificateStatus(filename string) (map[string]interface{}, *AppError) {
|
||||||
|
if r, err := c.DoApiGet("/admin/remove_certificate", "", ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return StringInterfaceFromJson(r.Body), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
66
vendor/github.com/mattermost/platform/model/cluster_info.go
generated
vendored
Normal file
66
vendor/github.com/mattermost/platform/model/cluster_info.go
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClusterInfo struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
ConfigHash string `json:"config_hash"`
|
||||||
|
InterNodeUrl string `json:"internode_url"`
|
||||||
|
Hostname string `json:"hostname"`
|
||||||
|
LastSuccessfulPing int64 `json:"last_ping"`
|
||||||
|
IsAlive bool `json:"is_alive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me *ClusterInfo) ToJson() string {
|
||||||
|
b, err := json.Marshal(me)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClusterInfoFromJson(data io.Reader) *ClusterInfo {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var me ClusterInfo
|
||||||
|
err := decoder.Decode(&me)
|
||||||
|
if err == nil {
|
||||||
|
return &me
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me *ClusterInfo) HaveEstablishedInitialContact() bool {
|
||||||
|
if me.Id != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClusterInfosToJson(objmap []*ClusterInfo) string {
|
||||||
|
if b, err := json.Marshal(objmap); err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClusterInfosFromJson(data io.Reader) []*ClusterInfo {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
|
||||||
|
var objmap []*ClusterInfo
|
||||||
|
if err := decoder.Decode(&objmap); err != nil {
|
||||||
|
return make([]*ClusterInfo, 0)
|
||||||
|
} else {
|
||||||
|
return objmap
|
||||||
|
}
|
||||||
|
}
|
||||||
126
vendor/github.com/mattermost/platform/model/config.go
generated
vendored
126
vendor/github.com/mattermost/platform/model/config.go
generated
vendored
@@ -6,6 +6,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -24,6 +25,7 @@ const (
|
|||||||
|
|
||||||
SERVICE_GITLAB = "gitlab"
|
SERVICE_GITLAB = "gitlab"
|
||||||
SERVICE_GOOGLE = "google"
|
SERVICE_GOOGLE = "google"
|
||||||
|
SERVICE_OFFICE365 = "office365"
|
||||||
|
|
||||||
WEBSERVER_MODE_REGULAR = "regular"
|
WEBSERVER_MODE_REGULAR = "regular"
|
||||||
WEBSERVER_MODE_GZIP = "gzip"
|
WEBSERVER_MODE_GZIP = "gzip"
|
||||||
@@ -44,9 +46,12 @@ const (
|
|||||||
RESTRICT_EMOJI_CREATION_ALL = "all"
|
RESTRICT_EMOJI_CREATION_ALL = "all"
|
||||||
RESTRICT_EMOJI_CREATION_ADMIN = "admin"
|
RESTRICT_EMOJI_CREATION_ADMIN = "admin"
|
||||||
RESTRICT_EMOJI_CREATION_SYSTEM_ADMIN = "system_admin"
|
RESTRICT_EMOJI_CREATION_SYSTEM_ADMIN = "system_admin"
|
||||||
|
|
||||||
|
SITENAME_MAX_LENGTH = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceSettings struct {
|
type ServiceSettings struct {
|
||||||
|
SiteURL *string
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
MaximumLoginAttempts int
|
MaximumLoginAttempts int
|
||||||
SegmentDeveloperKey string
|
SegmentDeveloperKey string
|
||||||
@@ -75,6 +80,12 @@ type ServiceSettings struct {
|
|||||||
RestrictCustomEmojiCreation *string
|
RestrictCustomEmojiCreation *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClusterSettings struct {
|
||||||
|
Enable *bool
|
||||||
|
InterNodeListenAddress *string
|
||||||
|
InterNodeUrls []string
|
||||||
|
}
|
||||||
|
|
||||||
type SSOSettings struct {
|
type SSOSettings struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
Secret string
|
Secret string
|
||||||
@@ -189,10 +200,12 @@ type TeamSettings struct {
|
|||||||
RestrictTeamNames *bool
|
RestrictTeamNames *bool
|
||||||
EnableCustomBrand *bool
|
EnableCustomBrand *bool
|
||||||
CustomBrandText *string
|
CustomBrandText *string
|
||||||
|
CustomDescriptionText *string
|
||||||
RestrictDirectMessage *string
|
RestrictDirectMessage *string
|
||||||
RestrictTeamInvite *string
|
RestrictTeamInvite *string
|
||||||
RestrictPublicChannelManagement *string
|
RestrictPublicChannelManagement *string
|
||||||
RestrictPrivateChannelManagement *string
|
RestrictPrivateChannelManagement *string
|
||||||
|
UserStatusAwayTimeout *int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type LdapSettings struct {
|
type LdapSettings struct {
|
||||||
@@ -265,6 +278,12 @@ type SamlSettings struct {
|
|||||||
LoginButtonText *string
|
LoginButtonText *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NativeAppSettings struct {
|
||||||
|
AppDownloadLink *string
|
||||||
|
AndroidAppDownloadLink *string
|
||||||
|
IosAppDownloadLink *string
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ServiceSettings ServiceSettings
|
ServiceSettings ServiceSettings
|
||||||
TeamSettings TeamSettings
|
TeamSettings TeamSettings
|
||||||
@@ -278,10 +297,13 @@ type Config struct {
|
|||||||
SupportSettings SupportSettings
|
SupportSettings SupportSettings
|
||||||
GitLabSettings SSOSettings
|
GitLabSettings SSOSettings
|
||||||
GoogleSettings SSOSettings
|
GoogleSettings SSOSettings
|
||||||
|
Office365Settings SSOSettings
|
||||||
LdapSettings LdapSettings
|
LdapSettings LdapSettings
|
||||||
ComplianceSettings ComplianceSettings
|
ComplianceSettings ComplianceSettings
|
||||||
LocalizationSettings LocalizationSettings
|
LocalizationSettings LocalizationSettings
|
||||||
SamlSettings SamlSettings
|
SamlSettings SamlSettings
|
||||||
|
NativeAppSettings NativeAppSettings
|
||||||
|
ClusterSettings ClusterSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) ToJson() string {
|
func (o *Config) ToJson() string {
|
||||||
@@ -299,6 +321,8 @@ func (o *Config) GetSSOService(service string) *SSOSettings {
|
|||||||
return &o.GitLabSettings
|
return &o.GitLabSettings
|
||||||
case SERVICE_GOOGLE:
|
case SERVICE_GOOGLE:
|
||||||
return &o.GoogleSettings
|
return &o.GoogleSettings
|
||||||
|
case SERVICE_OFFICE365:
|
||||||
|
return &o.Office365Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -348,6 +372,11 @@ func (o *Config) SetDefaults() {
|
|||||||
o.EmailSettings.PasswordResetSalt = NewRandomString(32)
|
o.EmailSettings.PasswordResetSalt = NewRandomString(32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.ServiceSettings.SiteURL == nil {
|
||||||
|
o.ServiceSettings.SiteURL = new(string)
|
||||||
|
*o.ServiceSettings.SiteURL = ""
|
||||||
|
}
|
||||||
|
|
||||||
if o.ServiceSettings.EnableDeveloper == nil {
|
if o.ServiceSettings.EnableDeveloper == nil {
|
||||||
o.ServiceSettings.EnableDeveloper = new(bool)
|
o.ServiceSettings.EnableDeveloper = new(bool)
|
||||||
*o.ServiceSettings.EnableDeveloper = false
|
*o.ServiceSettings.EnableDeveloper = false
|
||||||
@@ -408,6 +437,11 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.TeamSettings.CustomBrandText = ""
|
*o.TeamSettings.CustomBrandText = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.TeamSettings.CustomDescriptionText == nil {
|
||||||
|
o.TeamSettings.CustomDescriptionText = new(string)
|
||||||
|
*o.TeamSettings.CustomDescriptionText = ""
|
||||||
|
}
|
||||||
|
|
||||||
if o.TeamSettings.EnableOpenServer == nil {
|
if o.TeamSettings.EnableOpenServer == nil {
|
||||||
o.TeamSettings.EnableOpenServer = new(bool)
|
o.TeamSettings.EnableOpenServer = new(bool)
|
||||||
*o.TeamSettings.EnableOpenServer = false
|
*o.TeamSettings.EnableOpenServer = false
|
||||||
@@ -433,6 +467,11 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.TeamSettings.RestrictPrivateChannelManagement = PERMISSIONS_ALL
|
*o.TeamSettings.RestrictPrivateChannelManagement = PERMISSIONS_ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.TeamSettings.UserStatusAwayTimeout == nil {
|
||||||
|
o.TeamSettings.UserStatusAwayTimeout = new(int64)
|
||||||
|
*o.TeamSettings.UserStatusAwayTimeout = 300
|
||||||
|
}
|
||||||
|
|
||||||
if o.EmailSettings.EnableSignInWithEmail == nil {
|
if o.EmailSettings.EnableSignInWithEmail == nil {
|
||||||
o.EmailSettings.EnableSignInWithEmail = new(bool)
|
o.EmailSettings.EnableSignInWithEmail = new(bool)
|
||||||
|
|
||||||
@@ -474,7 +513,7 @@ func (o *Config) SetDefaults() {
|
|||||||
|
|
||||||
if o.SupportSettings.TermsOfServiceLink == nil {
|
if o.SupportSettings.TermsOfServiceLink == nil {
|
||||||
o.SupportSettings.TermsOfServiceLink = new(string)
|
o.SupportSettings.TermsOfServiceLink = new(string)
|
||||||
*o.SupportSettings.TermsOfServiceLink = "/static/help/terms.html"
|
*o.SupportSettings.TermsOfServiceLink = "https://about.mattermost.com/default-terms/"
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsSafeLink(o.SupportSettings.PrivacyPolicyLink) {
|
if !IsSafeLink(o.SupportSettings.PrivacyPolicyLink) {
|
||||||
@@ -483,7 +522,7 @@ func (o *Config) SetDefaults() {
|
|||||||
|
|
||||||
if o.SupportSettings.PrivacyPolicyLink == nil {
|
if o.SupportSettings.PrivacyPolicyLink == nil {
|
||||||
o.SupportSettings.PrivacyPolicyLink = new(string)
|
o.SupportSettings.PrivacyPolicyLink = new(string)
|
||||||
*o.SupportSettings.PrivacyPolicyLink = "/static/help/privacy.html"
|
*o.SupportSettings.PrivacyPolicyLink = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsSafeLink(o.SupportSettings.AboutLink) {
|
if !IsSafeLink(o.SupportSettings.AboutLink) {
|
||||||
@@ -492,7 +531,7 @@ func (o *Config) SetDefaults() {
|
|||||||
|
|
||||||
if o.SupportSettings.AboutLink == nil {
|
if o.SupportSettings.AboutLink == nil {
|
||||||
o.SupportSettings.AboutLink = new(string)
|
o.SupportSettings.AboutLink = new(string)
|
||||||
*o.SupportSettings.AboutLink = "/static/help/about.html"
|
*o.SupportSettings.AboutLink = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsSafeLink(o.SupportSettings.HelpLink) {
|
if !IsSafeLink(o.SupportSettings.HelpLink) {
|
||||||
@@ -501,7 +540,7 @@ func (o *Config) SetDefaults() {
|
|||||||
|
|
||||||
if o.SupportSettings.HelpLink == nil {
|
if o.SupportSettings.HelpLink == nil {
|
||||||
o.SupportSettings.HelpLink = new(string)
|
o.SupportSettings.HelpLink = new(string)
|
||||||
*o.SupportSettings.HelpLink = "/static/help/help.html"
|
*o.SupportSettings.HelpLink = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsSafeLink(o.SupportSettings.ReportAProblemLink) {
|
if !IsSafeLink(o.SupportSettings.ReportAProblemLink) {
|
||||||
@@ -510,7 +549,7 @@ func (o *Config) SetDefaults() {
|
|||||||
|
|
||||||
if o.SupportSettings.ReportAProblemLink == nil {
|
if o.SupportSettings.ReportAProblemLink == nil {
|
||||||
o.SupportSettings.ReportAProblemLink = new(string)
|
o.SupportSettings.ReportAProblemLink = new(string)
|
||||||
*o.SupportSettings.ReportAProblemLink = "/static/help/report_problem.html"
|
*o.SupportSettings.ReportAProblemLink = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.SupportSettings.SupportEmail == nil {
|
if o.SupportSettings.SupportEmail == nil {
|
||||||
@@ -675,6 +714,20 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.ServiceSettings.RestrictCustomEmojiCreation = RESTRICT_EMOJI_CREATION_ALL
|
*o.ServiceSettings.RestrictCustomEmojiCreation = RESTRICT_EMOJI_CREATION_ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.ClusterSettings.InterNodeListenAddress == nil {
|
||||||
|
o.ClusterSettings.InterNodeListenAddress = new(string)
|
||||||
|
*o.ClusterSettings.InterNodeListenAddress = ":8075"
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.ClusterSettings.Enable == nil {
|
||||||
|
o.ClusterSettings.Enable = new(bool)
|
||||||
|
*o.ClusterSettings.Enable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.ClusterSettings.InterNodeUrls == nil {
|
||||||
|
o.ClusterSettings.InterNodeUrls = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
if o.ComplianceSettings.Enable == nil {
|
if o.ComplianceSettings.Enable == nil {
|
||||||
o.ComplianceSettings.Enable = new(bool)
|
o.ComplianceSettings.Enable = new(bool)
|
||||||
*o.ComplianceSettings.Enable = false
|
*o.ComplianceSettings.Enable = false
|
||||||
@@ -784,6 +837,21 @@ func (o *Config) SetDefaults() {
|
|||||||
o.SamlSettings.LocaleAttribute = new(string)
|
o.SamlSettings.LocaleAttribute = new(string)
|
||||||
*o.SamlSettings.LocaleAttribute = ""
|
*o.SamlSettings.LocaleAttribute = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.NativeAppSettings.AppDownloadLink == nil {
|
||||||
|
o.NativeAppSettings.AppDownloadLink = new(string)
|
||||||
|
*o.NativeAppSettings.AppDownloadLink = "https://about.mattermost.com/downloads/"
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.NativeAppSettings.AndroidAppDownloadLink == nil {
|
||||||
|
o.NativeAppSettings.AndroidAppDownloadLink = new(string)
|
||||||
|
*o.NativeAppSettings.AndroidAppDownloadLink = "https://about.mattermost.com/mattermost-android-app/"
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.NativeAppSettings.IosAppDownloadLink == nil {
|
||||||
|
o.NativeAppSettings.IosAppDownloadLink = new(string)
|
||||||
|
*o.NativeAppSettings.IosAppDownloadLink = "https://about.mattermost.com/mattermost-ios-app/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) IsValid() *AppError {
|
func (o *Config) IsValid() *AppError {
|
||||||
@@ -792,6 +860,12 @@ func (o *Config) IsValid() *AppError {
|
|||||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "")
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(*o.ServiceSettings.SiteURL) != 0 {
|
||||||
|
if _, err := url.ParseRequestURI(*o.ServiceSettings.SiteURL); err != nil {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(o.ServiceSettings.ListenAddress) == 0 {
|
if len(o.ServiceSettings.ListenAddress) == 0 {
|
||||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
|
||||||
}
|
}
|
||||||
@@ -893,21 +967,37 @@ func (o *Config) IsValid() *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *o.LdapSettings.Enable {
|
if *o.LdapSettings.Enable {
|
||||||
if *o.LdapSettings.LdapServer == "" ||
|
if *o.LdapSettings.LdapServer == "" {
|
||||||
*o.LdapSettings.BaseDN == "" ||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_server", nil, "")
|
||||||
*o.LdapSettings.BindUsername == "" ||
|
}
|
||||||
*o.LdapSettings.BindPassword == "" ||
|
|
||||||
*o.LdapSettings.FirstNameAttribute == "" ||
|
if *o.LdapSettings.BaseDN == "" {
|
||||||
*o.LdapSettings.LastNameAttribute == "" ||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_basedn", nil, "")
|
||||||
*o.LdapSettings.EmailAttribute == "" ||
|
}
|
||||||
*o.LdapSettings.UsernameAttribute == "" ||
|
|
||||||
*o.LdapSettings.IdAttribute == "" {
|
if *o.LdapSettings.FirstNameAttribute == "" {
|
||||||
return NewLocAppError("Config.IsValid", "Required LDAP field missing", nil, "")
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_firstname", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *o.LdapSettings.LastNameAttribute == "" {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_lastname", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *o.LdapSettings.EmailAttribute == "" {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_email", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *o.LdapSettings.UsernameAttribute == "" {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_username", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if *o.LdapSettings.IdAttribute == "" {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_id", nil, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *o.SamlSettings.Enable {
|
if *o.SamlSettings.Enable {
|
||||||
if len(*o.SamlSettings.IdpUrl) == 0 {
|
if len(*o.SamlSettings.IdpUrl) == 0 || !IsValidHttpUrl(*o.SamlSettings.IdpUrl) {
|
||||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "")
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.saml_idp_url.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -960,6 +1050,10 @@ func (o *Config) IsValid() *AppError {
|
|||||||
return NewLocAppError("Config.IsValid", "model.config.is_valid.password_length.app_error", map[string]interface{}{"MinLength": PASSWORD_MINIMUM_LENGTH, "MaxLength": PASSWORD_MAXIMUM_LENGTH}, "")
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.password_length.app_error", map[string]interface{}{"MinLength": PASSWORD_MINIMUM_LENGTH, "MaxLength": PASSWORD_MAXIMUM_LENGTH}, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(o.TeamSettings.SiteName) > SITENAME_MAX_LENGTH {
|
||||||
|
return NewLocAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
vendor/github.com/mattermost/platform/model/job.go
generated
vendored
6
vendor/github.com/mattermost/platform/model/job.go
generated
vendored
@@ -84,6 +84,12 @@ func (task *ScheduledTask) Cancel() {
|
|||||||
removeTaskByName(task.Name)
|
removeTaskByName(task.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Executes the task immediatly. A recurring task will be run regularally after interval.
|
||||||
|
func (task *ScheduledTask) Execute() {
|
||||||
|
task.function()
|
||||||
|
task.timer.Reset(task.Interval)
|
||||||
|
}
|
||||||
|
|
||||||
func (task *ScheduledTask) String() string {
|
func (task *ScheduledTask) String() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s\nInterval: %s\nRecurring: %t\n",
|
"%s\nInterval: %s\nRecurring: %t\n",
|
||||||
|
|||||||
20
vendor/github.com/mattermost/platform/model/license.go
generated
vendored
20
vendor/github.com/mattermost/platform/model/license.go
generated
vendored
@@ -35,8 +35,10 @@ type Features struct {
|
|||||||
Users *int `json:"users"`
|
Users *int `json:"users"`
|
||||||
LDAP *bool `json:"ldap"`
|
LDAP *bool `json:"ldap"`
|
||||||
MFA *bool `json:"mfa"`
|
MFA *bool `json:"mfa"`
|
||||||
GoogleSSO *bool `json:"google_sso"`
|
GoogleOAuth *bool `json:"google_oauth"`
|
||||||
|
Office365OAuth *bool `json:"office365_oauth"`
|
||||||
Compliance *bool `json:"compliance"`
|
Compliance *bool `json:"compliance"`
|
||||||
|
Cluster *bool `json:"cluster"`
|
||||||
CustomBrand *bool `json:"custom_brand"`
|
CustomBrand *bool `json:"custom_brand"`
|
||||||
MHPNS *bool `json:"mhpns"`
|
MHPNS *bool `json:"mhpns"`
|
||||||
SAML *bool `json:"saml"`
|
SAML *bool `json:"saml"`
|
||||||
@@ -65,9 +67,14 @@ func (f *Features) SetDefaults() {
|
|||||||
*f.MFA = *f.FutureFeatures
|
*f.MFA = *f.FutureFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.GoogleSSO == nil {
|
if f.GoogleOAuth == nil {
|
||||||
f.GoogleSSO = new(bool)
|
f.GoogleOAuth = new(bool)
|
||||||
*f.GoogleSSO = *f.FutureFeatures
|
*f.GoogleOAuth = *f.FutureFeatures
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.Office365OAuth == nil {
|
||||||
|
f.Office365OAuth = new(bool)
|
||||||
|
*f.Office365OAuth = *f.FutureFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Compliance == nil {
|
if f.Compliance == nil {
|
||||||
@@ -75,6 +82,11 @@ func (f *Features) SetDefaults() {
|
|||||||
*f.Compliance = *f.FutureFeatures
|
*f.Compliance = *f.FutureFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f.Cluster == nil {
|
||||||
|
f.Cluster = new(bool)
|
||||||
|
*f.Cluster = *f.FutureFeatures
|
||||||
|
}
|
||||||
|
|
||||||
if f.CustomBrand == nil {
|
if f.CustomBrand == nil {
|
||||||
f.CustomBrand = new(bool)
|
f.CustomBrand = new(bool)
|
||||||
*f.CustomBrand = *f.FutureFeatures
|
*f.CustomBrand = *f.FutureFeatures
|
||||||
|
|||||||
61
vendor/github.com/mattermost/platform/model/message.go
generated
vendored
61
vendor/github.com/mattermost/platform/model/message.go
generated
vendored
@@ -1,61 +0,0 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
ACTION_TYPING = "typing"
|
|
||||||
ACTION_POSTED = "posted"
|
|
||||||
ACTION_POST_EDITED = "post_edited"
|
|
||||||
ACTION_POST_DELETED = "post_deleted"
|
|
||||||
ACTION_CHANNEL_DELETED = "channel_deleted"
|
|
||||||
ACTION_CHANNEL_VIEWED = "channel_viewed"
|
|
||||||
ACTION_DIRECT_ADDED = "direct_added"
|
|
||||||
ACTION_NEW_USER = "new_user"
|
|
||||||
ACTION_LEAVE_TEAM = "leave_team"
|
|
||||||
ACTION_USER_ADDED = "user_added"
|
|
||||||
ACTION_USER_REMOVED = "user_removed"
|
|
||||||
ACTION_PREFERENCE_CHANGED = "preference_changed"
|
|
||||||
ACTION_EPHEMERAL_MESSAGE = "ephemeral_message"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
TeamId string `json:"team_id"`
|
|
||||||
ChannelId string `json:"channel_id"`
|
|
||||||
UserId string `json:"user_id"`
|
|
||||||
Action string `json:"action"`
|
|
||||||
Props map[string]string `json:"props"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Message) Add(key string, value string) {
|
|
||||||
m.Props[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMessage(teamId string, channelId string, userId string, action string) *Message {
|
|
||||||
return &Message{TeamId: teamId, ChannelId: channelId, UserId: userId, Action: action, Props: make(map[string]string)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Message) ToJson() string {
|
|
||||||
b, err := json.Marshal(o)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
} else {
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MessageFromJson(data io.Reader) *Message {
|
|
||||||
decoder := json.NewDecoder(data)
|
|
||||||
var o Message
|
|
||||||
err := decoder.Decode(&o)
|
|
||||||
if err == nil {
|
|
||||||
return &o
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
40
vendor/github.com/mattermost/platform/model/oauth.go
generated
vendored
40
vendor/github.com/mattermost/platform/model/oauth.go
generated
vendored
@@ -25,8 +25,10 @@ type OAuthApp struct {
|
|||||||
ClientSecret string `json:"client_secret"`
|
ClientSecret string `json:"client_secret"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
IconURL string `json:"icon_url"`
|
||||||
CallbackUrls StringArray `json:"callback_urls"`
|
CallbackUrls StringArray `json:"callback_urls"`
|
||||||
Homepage string `json:"homepage"`
|
Homepage string `json:"homepage"`
|
||||||
|
IsTrusted bool `json:"is_trusted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid validates the app and returns an error if it isn't configured
|
// IsValid validates the app and returns an error if it isn't configured
|
||||||
@@ -61,7 +63,13 @@ func (a *OAuthApp) IsValid() *AppError {
|
|||||||
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "app_id="+a.Id)
|
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "app_id="+a.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(a.Homepage) == 0 || len(a.Homepage) > 256 {
|
for _, callback := range a.CallbackUrls {
|
||||||
|
if !IsValidHttpUrl(callback) {
|
||||||
|
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(a.Homepage) == 0 || len(a.Homepage) > 256 || !IsValidHttpUrl(a.Homepage) {
|
||||||
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.homepage.app_error", nil, "app_id="+a.Id)
|
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.homepage.app_error", nil, "app_id="+a.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +77,12 @@ func (a *OAuthApp) IsValid() *AppError {
|
|||||||
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.description.app_error", nil, "app_id="+a.Id)
|
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.description.app_error", nil, "app_id="+a.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(a.IconURL) > 0 {
|
||||||
|
if len(a.IconURL) > 512 || !IsValidHttpUrl(a.IconURL) {
|
||||||
|
return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.icon_url.app_error", nil, "app_id="+a.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +99,6 @@ func (a *OAuthApp) PreSave() {
|
|||||||
|
|
||||||
a.CreateAt = GetMillis()
|
a.CreateAt = GetMillis()
|
||||||
a.UpdateAt = a.CreateAt
|
a.UpdateAt = a.CreateAt
|
||||||
|
|
||||||
if len(a.ClientSecret) > 0 {
|
|
||||||
a.ClientSecret = HashPassword(a.ClientSecret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreUpdate should be run before updating the app in the db.
|
// PreUpdate should be run before updating the app in the db.
|
||||||
@@ -157,3 +167,23 @@ func OAuthAppMapFromJson(data io.Reader) map[string]*OAuthApp {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OAuthAppListToJson(l []*OAuthApp) string {
|
||||||
|
b, err := json.Marshal(l)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OAuthAppListFromJson(data io.Reader) []*OAuthApp {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var o []*OAuthApp
|
||||||
|
err := decoder.Decode(&o)
|
||||||
|
if err == nil {
|
||||||
|
return o
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
20
vendor/github.com/mattermost/platform/model/outgoing_webhook.go
generated
vendored
20
vendor/github.com/mattermost/platform/model/outgoing_webhook.go
generated
vendored
@@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OutgoingWebhook struct {
|
type OutgoingWebhook struct {
|
||||||
@@ -21,6 +22,7 @@ type OutgoingWebhook struct {
|
|||||||
ChannelId string `json:"channel_id"`
|
ChannelId string `json:"channel_id"`
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
TriggerWords StringArray `json:"trigger_words"`
|
TriggerWords StringArray `json:"trigger_words"`
|
||||||
|
TriggerWhen int `json:"trigger_when"`
|
||||||
CallbackURLs StringArray `json:"callback_urls"`
|
CallbackURLs StringArray `json:"callback_urls"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@@ -171,6 +173,10 @@ func (o *OutgoingWebhook) IsValid() *AppError {
|
|||||||
return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.content_type.app_error", nil, "")
|
return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.content_type.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.TriggerWhen > 1 {
|
||||||
|
return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.content_type.app_error", nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,3 +210,17 @@ func (o *OutgoingWebhook) HasTriggerWord(word string) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *OutgoingWebhook) TriggerWordStartsWith(word string) bool {
|
||||||
|
if len(o.TriggerWords) == 0 || len(word) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, trigger := range o.TriggerWords {
|
||||||
|
if strings.HasPrefix(word, trigger) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
3
vendor/github.com/mattermost/platform/model/post.go
generated
vendored
3
vendor/github.com/mattermost/platform/model/post.go
generated
vendored
@@ -162,9 +162,6 @@ func (o *Post) AddProp(key string, value interface{}) {
|
|||||||
o.Props[key] = value
|
o.Props[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Post) PreExport() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Post) IsSystemMessage() bool {
|
func (o *Post) IsSystemMessage() bool {
|
||||||
return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX
|
return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX
|
||||||
}
|
}
|
||||||
|
|||||||
48
vendor/github.com/mattermost/platform/model/preference.go
generated
vendored
48
vendor/github.com/mattermost/platform/model/preference.go
generated
vendored
@@ -6,6 +6,8 @@ package model
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,10 +15,17 @@ const (
|
|||||||
PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW = "direct_channel_show"
|
PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW = "direct_channel_show"
|
||||||
PREFERENCE_CATEGORY_TUTORIAL_STEPS = "tutorial_step"
|
PREFERENCE_CATEGORY_TUTORIAL_STEPS = "tutorial_step"
|
||||||
PREFERENCE_CATEGORY_ADVANCED_SETTINGS = "advanced_settings"
|
PREFERENCE_CATEGORY_ADVANCED_SETTINGS = "advanced_settings"
|
||||||
|
PREFERENCE_CATEGORY_FLAGGED_POST = "flagged_post"
|
||||||
|
|
||||||
PREFERENCE_CATEGORY_DISPLAY_SETTINGS = "display_settings"
|
PREFERENCE_CATEGORY_DISPLAY_SETTINGS = "display_settings"
|
||||||
PREFERENCE_NAME_COLLAPSE_SETTING = "collapse_previews"
|
PREFERENCE_NAME_COLLAPSE_SETTING = "collapse_previews"
|
||||||
|
|
||||||
|
PREFERENCE_CATEGORY_THEME = "theme"
|
||||||
|
// the name for theme props is the team id
|
||||||
|
|
||||||
|
PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP = "oauth_app"
|
||||||
|
// the name for oauth_app is the client_id and value is the current scope
|
||||||
|
|
||||||
PREFERENCE_CATEGORY_LAST = "last"
|
PREFERENCE_CATEGORY_LAST = "last"
|
||||||
PREFERENCE_NAME_LAST_CHANNEL = "channel"
|
PREFERENCE_NAME_LAST_CHANNEL = "channel"
|
||||||
)
|
)
|
||||||
@@ -57,13 +66,48 @@ func (o *Preference) IsValid() *AppError {
|
|||||||
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.category.app_error", nil, "category="+o.Category)
|
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.category.app_error", nil, "category="+o.Category)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(o.Name) == 0 || len(o.Name) > 32 {
|
if len(o.Name) > 32 {
|
||||||
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.name.app_error", nil, "name="+o.Name)
|
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.name.app_error", nil, "name="+o.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if utf8.RuneCountInString(o.Value) > 128 {
|
if utf8.RuneCountInString(o.Value) > 2000 {
|
||||||
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.value.app_error", nil, "value="+o.Value)
|
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.value.app_error", nil, "value="+o.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.Category == PREFERENCE_CATEGORY_THEME {
|
||||||
|
var unused map[string]string
|
||||||
|
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&unused); err != nil {
|
||||||
|
return NewLocAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Preference) PreUpdate() {
|
||||||
|
if o.Category == PREFERENCE_CATEGORY_THEME {
|
||||||
|
// decode the value of theme (a map of strings to string) and eliminate any invalid values
|
||||||
|
var props map[string]string
|
||||||
|
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&props); err != nil {
|
||||||
|
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
colorPattern := regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||||
|
|
||||||
|
// blank out any invalid theme values
|
||||||
|
for name, value := range props {
|
||||||
|
if name == "image" || name == "type" || name == "codeTheme" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !colorPattern.MatchString(value) {
|
||||||
|
props[name] = "#ffffff"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if b, err := json.Marshal(props); err == nil {
|
||||||
|
o.Value = string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
4
vendor/github.com/mattermost/platform/model/session.go
generated
vendored
4
vendor/github.com/mattermost/platform/model/session.go
generated
vendored
@@ -83,7 +83,11 @@ func (me *Session) IsExpired() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *Session) SetExpireInDays(days int) {
|
func (me *Session) SetExpireInDays(days int) {
|
||||||
|
if me.CreateAt == 0 {
|
||||||
me.ExpiresAt = GetMillis() + (1000 * 60 * 60 * 24 * int64(days))
|
me.ExpiresAt = GetMillis() + (1000 * 60 * 60 * 24 * int64(days))
|
||||||
|
} else {
|
||||||
|
me.ExpiresAt = me.CreateAt + (1000 * 60 * 60 * 24 * int64(days))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *Session) AddProp(key string, value string) {
|
func (me *Session) AddProp(key string, value string) {
|
||||||
|
|||||||
42
vendor/github.com/mattermost/platform/model/status.go
generated
vendored
Normal file
42
vendor/github.com/mattermost/platform/model/status.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
STATUS_OFFLINE = "offline"
|
||||||
|
STATUS_AWAY = "away"
|
||||||
|
STATUS_ONLINE = "online"
|
||||||
|
STATUS_CACHE_SIZE = 10000
|
||||||
|
)
|
||||||
|
|
||||||
|
type Status struct {
|
||||||
|
UserId string `json:"user_id"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
LastActivityAt int64 `json:"last_activity_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Status) ToJson() string {
|
||||||
|
b, err := json.Marshal(o)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StatusFromJson(data io.Reader) *Status {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var o Status
|
||||||
|
err := decoder.Decode(&o)
|
||||||
|
if err == nil {
|
||||||
|
return &o
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
3
vendor/github.com/mattermost/platform/model/team.go
generated
vendored
3
vendor/github.com/mattermost/platform/model/team.go
generated
vendored
@@ -224,9 +224,6 @@ func CleanTeamName(s string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Team) PreExport() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Team) Sanitize() {
|
func (o *Team) Sanitize() {
|
||||||
o.Email = ""
|
o.Email = ""
|
||||||
o.AllowedDomains = ""
|
o.AllowedDomains = ""
|
||||||
|
|||||||
49
vendor/github.com/mattermost/platform/model/user.go
generated
vendored
49
vendor/github.com/mattermost/platform/model/user.go
generated
vendored
@@ -16,11 +16,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ROLE_SYSTEM_ADMIN = "system_admin"
|
ROLE_SYSTEM_ADMIN = "system_admin"
|
||||||
USER_AWAY_TIMEOUT = 5 * 60 * 1000 // 5 minutes
|
|
||||||
USER_OFFLINE_TIMEOUT = 1 * 60 * 1000 // 1 minute
|
|
||||||
USER_OFFLINE = "offline"
|
|
||||||
USER_AWAY = "away"
|
|
||||||
USER_ONLINE = "online"
|
|
||||||
USER_NOTIFY_ALL = "all"
|
USER_NOTIFY_ALL = "all"
|
||||||
USER_NOTIFY_MENTION = "mention"
|
USER_NOTIFY_MENTION = "mention"
|
||||||
USER_NOTIFY_NONE = "none"
|
USER_NOTIFY_NONE = "none"
|
||||||
@@ -44,12 +39,9 @@ type User struct {
|
|||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
Roles string `json:"roles"`
|
Roles string `json:"roles"`
|
||||||
LastActivityAt int64 `json:"last_activity_at,omitempty"`
|
|
||||||
LastPingAt int64 `json:"last_ping_at,omitempty"`
|
|
||||||
AllowMarketing bool `json:"allow_marketing,omitempty"`
|
AllowMarketing bool `json:"allow_marketing,omitempty"`
|
||||||
Props StringMap `json:"props,omitempty"`
|
Props StringMap `json:"props,omitempty"`
|
||||||
NotifyProps StringMap `json:"notify_props,omitempty"`
|
NotifyProps StringMap `json:"notify_props,omitempty"`
|
||||||
ThemeProps StringMap `json:"theme_props,omitempty"`
|
|
||||||
LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
|
LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
|
||||||
LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
|
LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
|
||||||
FailedAttempts int `json:"failed_attempts,omitempty"`
|
FailedAttempts int `json:"failed_attempts,omitempty"`
|
||||||
@@ -106,10 +98,6 @@ func (u *User) IsValid() *AppError {
|
|||||||
return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_pwd.app_error", nil, "user_id="+u.Id)
|
return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_pwd.app_error", nil, "user_id="+u.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(u.ThemeProps) > 2000 {
|
|
||||||
return NewLocAppError("User.IsValid", "model.user.is_valid.theme.app_error", nil, "user_id="+u.Id)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,21 +167,6 @@ func (u *User) PreUpdate() {
|
|||||||
}
|
}
|
||||||
u.NotifyProps["mention_keys"] = strings.Join(goodKeys, ",")
|
u.NotifyProps["mention_keys"] = strings.Join(goodKeys, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.ThemeProps != nil {
|
|
||||||
colorPattern := regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
|
||||||
|
|
||||||
// blank out any invalid theme values
|
|
||||||
for name, value := range u.ThemeProps {
|
|
||||||
if name == "image" || name == "type" || name == "codeTheme" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !colorPattern.MatchString(value) {
|
|
||||||
u.ThemeProps[name] = "#ffffff"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) SetDefaultNotifications() {
|
func (u *User) SetDefaultNotifications() {
|
||||||
@@ -242,14 +215,6 @@ func (u *User) Etag(showFullName, showEmail bool) string {
|
|||||||
return Etag(u.Id, u.UpdateAt, showFullName, showEmail)
|
return Etag(u.Id, u.UpdateAt, showFullName, showEmail)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) IsOffline() bool {
|
|
||||||
return (GetMillis()-u.LastPingAt) > USER_OFFLINE_TIMEOUT && (GetMillis()-u.LastActivityAt) > USER_OFFLINE_TIMEOUT
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *User) IsAway() bool {
|
|
||||||
return (GetMillis() - u.LastActivityAt) > USER_AWAY_TIMEOUT
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove any private data from the user object
|
// Remove any private data from the user object
|
||||||
func (u *User) Sanitize(options map[string]bool) {
|
func (u *User) Sanitize(options map[string]bool) {
|
||||||
u.Password = ""
|
u.Password = ""
|
||||||
@@ -278,11 +243,9 @@ func (u *User) ClearNonProfileFields() {
|
|||||||
u.MfaActive = false
|
u.MfaActive = false
|
||||||
u.MfaSecret = ""
|
u.MfaSecret = ""
|
||||||
u.EmailVerified = false
|
u.EmailVerified = false
|
||||||
u.LastPingAt = 0
|
|
||||||
u.AllowMarketing = false
|
u.AllowMarketing = false
|
||||||
u.Props = StringMap{}
|
u.Props = StringMap{}
|
||||||
u.NotifyProps = StringMap{}
|
u.NotifyProps = StringMap{}
|
||||||
u.ThemeProps = StringMap{}
|
|
||||||
u.LastPasswordUpdate = 0
|
u.LastPasswordUpdate = 0
|
||||||
u.LastPictureUpdate = 0
|
u.LastPictureUpdate = 0
|
||||||
u.FailedAttempts = 0
|
u.FailedAttempts = 0
|
||||||
@@ -392,17 +355,6 @@ func (u *User) IsLDAPUser() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) PreExport() {
|
|
||||||
u.Password = ""
|
|
||||||
u.AuthData = new(string)
|
|
||||||
*u.AuthData = ""
|
|
||||||
u.LastActivityAt = 0
|
|
||||||
u.LastPingAt = 0
|
|
||||||
u.LastPasswordUpdate = 0
|
|
||||||
u.LastPictureUpdate = 0
|
|
||||||
u.FailedAttempts = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserFromJson will decode the input and return a User
|
// UserFromJson will decode the input and return a User
|
||||||
func UserFromJson(data io.Reader) *User {
|
func UserFromJson(data io.Reader) *User {
|
||||||
decoder := json.NewDecoder(data)
|
decoder := json.NewDecoder(data)
|
||||||
@@ -461,6 +413,7 @@ var validUsernameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
|
|||||||
var restrictedUsernames = []string{
|
var restrictedUsernames = []string{
|
||||||
"all",
|
"all",
|
||||||
"channel",
|
"channel",
|
||||||
|
"matterbot",
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsValidUsername(s string) bool {
|
func IsValidUsername(s string) bool {
|
||||||
|
|||||||
6
vendor/github.com/mattermost/platform/model/utils.go
generated
vendored
6
vendor/github.com/mattermost/platform/model/utils.go
generated
vendored
@@ -36,10 +36,10 @@ type AppError struct {
|
|||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Message string `json:"message"` // Message to be display to the end user without debugging information
|
Message string `json:"message"` // Message to be display to the end user without debugging information
|
||||||
DetailedError string `json:"detailed_error"` // Internal error string to help the developer
|
DetailedError string `json:"detailed_error"` // Internal error string to help the developer
|
||||||
RequestId string `json:"request_id"` // The RequestId that's also set in the header
|
RequestId string `json:"request_id,omitempty"` // The RequestId that's also set in the header
|
||||||
StatusCode int `json:"status_code"` // The http status code
|
StatusCode int `json:"status_code,omitempty"` // The http status code
|
||||||
Where string `json:"-"` // The function where it happened in the form of Struct.Func
|
Where string `json:"-"` // The function where it happened in the form of Struct.Func
|
||||||
IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific
|
IsOAuth bool `json:"is_oauth,omitempty"` // Whether the error is OAuth specific
|
||||||
params map[string]interface{} `json:"-"`
|
params map[string]interface{} `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
vendor/github.com/mattermost/platform/model/version.go
generated
vendored
1
vendor/github.com/mattermost/platform/model/version.go
generated
vendored
@@ -13,6 +13,7 @@ import (
|
|||||||
// It should be maitained in chronological order with most current
|
// It should be maitained in chronological order with most current
|
||||||
// release at the front of the list.
|
// release at the front of the list.
|
||||||
var versions = []string{
|
var versions = []string{
|
||||||
|
"3.3.0",
|
||||||
"3.2.0",
|
"3.2.0",
|
||||||
"3.1.0",
|
"3.1.0",
|
||||||
"3.0.0",
|
"3.0.0",
|
||||||
|
|||||||
109
vendor/github.com/mattermost/platform/model/websocket_client.go
generated
vendored
Normal file
109
vendor/github.com/mattermost/platform/model/websocket_client.go
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebSocketClient struct {
|
||||||
|
Url string // The location of the server like "ws://localhost:8065"
|
||||||
|
ApiUrl string // The api location of the server like "ws://localhost:8065/api/v3"
|
||||||
|
Conn *websocket.Conn // The WebSocket connection
|
||||||
|
AuthToken string // The token used to open the WebSocket
|
||||||
|
Sequence int64 // The ever-incrementing sequence attached to each WebSocket action
|
||||||
|
EventChannel chan *WebSocketEvent
|
||||||
|
ResponseChannel chan *WebSocketResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWebSocketClient constructs a new WebSocket client with convienence
|
||||||
|
// methods for talking to the server.
|
||||||
|
func NewWebSocketClient(url, authToken string) (*WebSocketClient, *AppError) {
|
||||||
|
header := http.Header{}
|
||||||
|
header.Set(HEADER_AUTH, "BEARER "+authToken)
|
||||||
|
conn, _, err := websocket.DefaultDialer.Dial(url+API_URL_SUFFIX+"/users/websocket", header)
|
||||||
|
if err != nil {
|
||||||
|
return nil, NewLocAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &WebSocketClient{
|
||||||
|
url,
|
||||||
|
url + API_URL_SUFFIX,
|
||||||
|
conn,
|
||||||
|
authToken,
|
||||||
|
1,
|
||||||
|
make(chan *WebSocketEvent, 100),
|
||||||
|
make(chan *WebSocketResponse, 100),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wsc *WebSocketClient) Connect() *AppError {
|
||||||
|
header := http.Header{}
|
||||||
|
header.Set(HEADER_AUTH, "BEARER "+wsc.AuthToken)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
wsc.Conn, _, err = websocket.DefaultDialer.Dial(wsc.ApiUrl+"/users/websocket", header)
|
||||||
|
if err != nil {
|
||||||
|
return NewLocAppError("NewWebSocketClient", "model.websocket_client.connect_fail.app_error", nil, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wsc *WebSocketClient) Close() {
|
||||||
|
wsc.Conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wsc *WebSocketClient) Listen() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
var rawMsg json.RawMessage
|
||||||
|
var err error
|
||||||
|
if _, rawMsg, err = wsc.Conn.ReadMessage(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var event WebSocketEvent
|
||||||
|
if err := json.Unmarshal(rawMsg, &event); err == nil && event.IsValid() {
|
||||||
|
wsc.EventChannel <- &event
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var response WebSocketResponse
|
||||||
|
if err := json.Unmarshal(rawMsg, &response); err == nil && response.IsValid() {
|
||||||
|
wsc.ResponseChannel <- &response
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wsc *WebSocketClient) SendMessage(action string, data map[string]interface{}) {
|
||||||
|
req := &WebSocketRequest{}
|
||||||
|
req.Seq = wsc.Sequence
|
||||||
|
req.Action = action
|
||||||
|
req.Data = data
|
||||||
|
|
||||||
|
wsc.Sequence++
|
||||||
|
|
||||||
|
wsc.Conn.WriteJSON(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserTyping will push a user_typing event out to all connected users
|
||||||
|
// who are in the specified channel
|
||||||
|
func (wsc *WebSocketClient) UserTyping(channelId, parentId string) {
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"channel_id": channelId,
|
||||||
|
"parent_id": parentId,
|
||||||
|
}
|
||||||
|
|
||||||
|
wsc.SendMessage("user_typing", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStatuses will return a map of string statuses using user id as the key
|
||||||
|
func (wsc *WebSocketClient) GetStatuses() {
|
||||||
|
wsc.SendMessage("get_statuses", nil)
|
||||||
|
}
|
||||||
114
vendor/github.com/mattermost/platform/model/websocket_message.go
generated
vendored
Normal file
114
vendor/github.com/mattermost/platform/model/websocket_message.go
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
WEBSOCKET_EVENT_TYPING = "typing"
|
||||||
|
WEBSOCKET_EVENT_POSTED = "posted"
|
||||||
|
WEBSOCKET_EVENT_POST_EDITED = "post_edited"
|
||||||
|
WEBSOCKET_EVENT_POST_DELETED = "post_deleted"
|
||||||
|
WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted"
|
||||||
|
WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
|
||||||
|
WEBSOCKET_EVENT_DIRECT_ADDED = "direct_added"
|
||||||
|
WEBSOCKET_EVENT_NEW_USER = "new_user"
|
||||||
|
WEBSOCKET_EVENT_LEAVE_TEAM = "leave_team"
|
||||||
|
WEBSOCKET_EVENT_USER_ADDED = "user_added"
|
||||||
|
WEBSOCKET_EVENT_USER_REMOVED = "user_removed"
|
||||||
|
WEBSOCKET_EVENT_PREFERENCE_CHANGED = "preference_changed"
|
||||||
|
WEBSOCKET_EVENT_EPHEMERAL_MESSAGE = "ephemeral_message"
|
||||||
|
WEBSOCKET_EVENT_STATUS_CHANGE = "status_change"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebSocketMessage interface {
|
||||||
|
ToJson() string
|
||||||
|
IsValid() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebSocketEvent struct {
|
||||||
|
TeamId string `json:"team_id"`
|
||||||
|
ChannelId string `json:"channel_id"`
|
||||||
|
UserId string `json:"user_id"`
|
||||||
|
Event string `json:"event"`
|
||||||
|
Data map[string]interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WebSocketEvent) Add(key string, value interface{}) {
|
||||||
|
m.Data[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebSocketEvent(teamId string, channelId string, userId string, event string) *WebSocketEvent {
|
||||||
|
return &WebSocketEvent{TeamId: teamId, ChannelId: channelId, UserId: userId, Event: event, Data: make(map[string]interface{})}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *WebSocketEvent) IsValid() bool {
|
||||||
|
return o.Event != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *WebSocketEvent) ToJson() string {
|
||||||
|
b, err := json.Marshal(o)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WebSocketEventFromJson(data io.Reader) *WebSocketEvent {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var o WebSocketEvent
|
||||||
|
err := decoder.Decode(&o)
|
||||||
|
if err == nil {
|
||||||
|
return &o
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebSocketResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
SeqReply int64 `json:"seq_reply,omitempty"`
|
||||||
|
Data map[string]interface{} `json:"data,omitempty"`
|
||||||
|
Error *AppError `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WebSocketResponse) Add(key string, value interface{}) {
|
||||||
|
m.Data[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebSocketResponse(status string, seqReply int64, data map[string]interface{}) *WebSocketResponse {
|
||||||
|
return &WebSocketResponse{Status: status, SeqReply: seqReply, Data: data}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebSocketError(seqReply int64, err *AppError) *WebSocketResponse {
|
||||||
|
return &WebSocketResponse{Status: STATUS_FAIL, SeqReply: seqReply, Error: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *WebSocketResponse) IsValid() bool {
|
||||||
|
return o.Status != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *WebSocketResponse) ToJson() string {
|
||||||
|
b, err := json.Marshal(o)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WebSocketResponseFromJson(data io.Reader) *WebSocketResponse {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var o WebSocketResponse
|
||||||
|
err := decoder.Decode(&o)
|
||||||
|
if err == nil {
|
||||||
|
return &o
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
43
vendor/github.com/mattermost/platform/model/websocket_request.go
generated
vendored
Normal file
43
vendor/github.com/mattermost/platform/model/websocket_request.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebSocketRequest struct {
|
||||||
|
// Client-provided fields
|
||||||
|
Seq int64 `json:"seq"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Data map[string]interface{} `json:"data"`
|
||||||
|
|
||||||
|
// Server-provided fields
|
||||||
|
Session Session `json:"-"`
|
||||||
|
T goi18n.TranslateFunc `json:"-"`
|
||||||
|
Locale string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *WebSocketRequest) ToJson() string {
|
||||||
|
b, err := json.Marshal(o)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WebSocketRequestFromJson(data io.Reader) *WebSocketRequest {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
var o WebSocketRequest
|
||||||
|
err := decoder.Decode(&o)
|
||||||
|
if err == nil {
|
||||||
|
return &o
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
27
vendor/github.com/mattn/go-xmpp/LICENSE
generated
vendored
Normal file
27
vendor/github.com/mattn/go-xmpp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
881
vendor/github.com/mattn/go-xmpp/xmpp.go
generated
vendored
Normal file
881
vendor/github.com/mattn/go-xmpp/xmpp.go
generated
vendored
Normal file
@@ -0,0 +1,881 @@
|
|||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// TODO(rsc):
|
||||||
|
// More precise error handling.
|
||||||
|
// Presence functionality.
|
||||||
|
// TODO(mattn):
|
||||||
|
// Add proxy authentication.
|
||||||
|
|
||||||
|
// Package xmpp implements a simple Google Talk client
|
||||||
|
// using the XMPP protocol described in RFC 3920 and RFC 3921.
|
||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/tls"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/xml"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math/big"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nsStream = "http://etherx.jabber.org/streams"
|
||||||
|
nsTLS = "urn:ietf:params:xml:ns:xmpp-tls"
|
||||||
|
nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl"
|
||||||
|
nsBind = "urn:ietf:params:xml:ns:xmpp-bind"
|
||||||
|
nsClient = "jabber:client"
|
||||||
|
nsSession = "urn:ietf:params:xml:ns:xmpp-session"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Default TLS configuration options
|
||||||
|
var DefaultConfig tls.Config
|
||||||
|
|
||||||
|
// Cookie is a unique XMPP session identifier
|
||||||
|
type Cookie uint64
|
||||||
|
|
||||||
|
func getCookie() Cookie {
|
||||||
|
var buf [8]byte
|
||||||
|
if _, err := rand.Reader.Read(buf[:]); err != nil {
|
||||||
|
panic("Failed to read random bytes: " + err.Error())
|
||||||
|
}
|
||||||
|
return Cookie(binary.LittleEndian.Uint64(buf[:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client holds XMPP connection opitons
|
||||||
|
type Client struct {
|
||||||
|
conn net.Conn // connection to server
|
||||||
|
jid string // Jabber ID for our connection
|
||||||
|
domain string
|
||||||
|
p *xml.Decoder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) JID() string {
|
||||||
|
return c.jid
|
||||||
|
}
|
||||||
|
|
||||||
|
func connect(host, user, passwd string) (net.Conn, error) {
|
||||||
|
addr := host
|
||||||
|
|
||||||
|
if strings.TrimSpace(host) == "" {
|
||||||
|
a := strings.SplitN(user, "@", 2)
|
||||||
|
if len(a) == 2 {
|
||||||
|
addr = a[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a := strings.SplitN(host, ":", 2)
|
||||||
|
if len(a) == 1 {
|
||||||
|
addr += ":5222"
|
||||||
|
}
|
||||||
|
proxy := os.Getenv("HTTP_PROXY")
|
||||||
|
if proxy == "" {
|
||||||
|
proxy = os.Getenv("http_proxy")
|
||||||
|
}
|
||||||
|
if proxy != "" {
|
||||||
|
url, err := url.Parse(proxy)
|
||||||
|
if err == nil {
|
||||||
|
addr = url.Host
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c, err := net.Dial("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if proxy != "" {
|
||||||
|
fmt.Fprintf(c, "CONNECT %s HTTP/1.1\r\n", host)
|
||||||
|
fmt.Fprintf(c, "Host: %s\r\n", host)
|
||||||
|
fmt.Fprintf(c, "\r\n")
|
||||||
|
br := bufio.NewReader(c)
|
||||||
|
req, _ := http.NewRequest("CONNECT", host, nil)
|
||||||
|
resp, err := http.ReadResponse(br, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
f := strings.SplitN(resp.Status, " ", 2)
|
||||||
|
return nil, errors.New(f[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Options are used to specify additional options for new clients, such as a Resource.
|
||||||
|
type Options struct {
|
||||||
|
// Host specifies what host to connect to, as either "hostname" or "hostname:port"
|
||||||
|
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
||||||
|
// Default the port to 5222.
|
||||||
|
Host string
|
||||||
|
|
||||||
|
// User specifies what user to authenticate to the remote server.
|
||||||
|
User string
|
||||||
|
|
||||||
|
// Password supplies the password to use for authentication with the remote server.
|
||||||
|
Password string
|
||||||
|
|
||||||
|
// Resource specifies an XMPP client resource, like "bot", instead of accepting one
|
||||||
|
// from the server. Use "" to let the server generate one for your client.
|
||||||
|
Resource string
|
||||||
|
|
||||||
|
// OAuthScope provides go-xmpp the required scope for OAuth2 authentication.
|
||||||
|
OAuthScope string
|
||||||
|
|
||||||
|
// OAuthToken provides go-xmpp with the required OAuth2 token used to authenticate
|
||||||
|
OAuthToken string
|
||||||
|
|
||||||
|
// OAuthXmlNs provides go-xmpp with the required namespaced used for OAuth2 authentication. This is
|
||||||
|
// provided to the server as the xmlns:auth attribute of the OAuth2 authentication request.
|
||||||
|
OAuthXmlNs string
|
||||||
|
|
||||||
|
// TLS Config
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
// InsecureAllowUnencryptedAuth permits authentication over a TCP connection that has not been promoted to
|
||||||
|
// TLS by STARTTLS; this could leak authentication information over the network, or permit man in the middle
|
||||||
|
// attacks.
|
||||||
|
InsecureAllowUnencryptedAuth bool
|
||||||
|
|
||||||
|
// NoTLS directs go-xmpp to not use TLS initially to contact the server; instead, a plain old unencrypted
|
||||||
|
// TCP connection should be used. (Can be combined with StartTLS to support STARTTLS-based servers.)
|
||||||
|
NoTLS bool
|
||||||
|
|
||||||
|
// StartTLS directs go-xmpp to STARTTLS if the server supports it; go-xmpp will automatically STARTTLS
|
||||||
|
// if the server requires it regardless of this option.
|
||||||
|
StartTLS bool
|
||||||
|
|
||||||
|
// Debug output
|
||||||
|
Debug bool
|
||||||
|
|
||||||
|
// Use server sessions
|
||||||
|
Session bool
|
||||||
|
|
||||||
|
// Presence Status
|
||||||
|
Status string
|
||||||
|
|
||||||
|
// Status message
|
||||||
|
StatusMessage string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient establishes a new Client connection based on a set of Options.
|
||||||
|
func (o Options) NewClient() (*Client, error) {
|
||||||
|
host := o.Host
|
||||||
|
c, err := connect(host, o.User, o.Password)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.LastIndex(o.Host, ":") > 0 {
|
||||||
|
host = host[:strings.LastIndex(o.Host, ":")]
|
||||||
|
}
|
||||||
|
|
||||||
|
client := new(Client)
|
||||||
|
if o.NoTLS {
|
||||||
|
client.conn = c
|
||||||
|
} else {
|
||||||
|
var tlsconn *tls.Conn
|
||||||
|
if o.TLSConfig != nil {
|
||||||
|
tlsconn = tls.Client(c, o.TLSConfig)
|
||||||
|
} else {
|
||||||
|
DefaultConfig.ServerName = host
|
||||||
|
tlsconn = tls.Client(c, &DefaultConfig)
|
||||||
|
}
|
||||||
|
if err = tlsconn.Handshake(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
insecureSkipVerify := DefaultConfig.InsecureSkipVerify
|
||||||
|
if o.TLSConfig != nil {
|
||||||
|
insecureSkipVerify = o.TLSConfig.InsecureSkipVerify
|
||||||
|
}
|
||||||
|
if !insecureSkipVerify {
|
||||||
|
if err = tlsconn.VerifyHostname(host); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.conn = tlsconn
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := client.init(&o); err != nil {
|
||||||
|
client.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new connection to a host given as "hostname" or "hostname:port".
|
||||||
|
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
||||||
|
// Default the port to 5222.
|
||||||
|
func NewClient(host, user, passwd string, debug bool) (*Client, error) {
|
||||||
|
opts := Options{
|
||||||
|
Host: host,
|
||||||
|
User: user,
|
||||||
|
Password: passwd,
|
||||||
|
Debug: debug,
|
||||||
|
Session: false,
|
||||||
|
}
|
||||||
|
return opts.NewClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientNoTLS creates a new client without TLS
|
||||||
|
func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error) {
|
||||||
|
opts := Options{
|
||||||
|
Host: host,
|
||||||
|
User: user,
|
||||||
|
Password: passwd,
|
||||||
|
NoTLS: true,
|
||||||
|
Debug: debug,
|
||||||
|
Session: false,
|
||||||
|
}
|
||||||
|
return opts.NewClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the XMPP connection
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
if c.conn != (*tls.Conn)(nil) {
|
||||||
|
return c.conn.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func saslDigestResponse(username, realm, passwd, nonce, cnonceStr, authenticate, digestURI, nonceCountStr string) string {
|
||||||
|
h := func(text string) []byte {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(text))
|
||||||
|
return h.Sum(nil)
|
||||||
|
}
|
||||||
|
hex := func(bytes []byte) string {
|
||||||
|
return fmt.Sprintf("%x", bytes)
|
||||||
|
}
|
||||||
|
kd := func(secret, data string) []byte {
|
||||||
|
return h(secret + ":" + data)
|
||||||
|
}
|
||||||
|
|
||||||
|
a1 := string(h(username+":"+realm+":"+passwd)) + ":" + nonce + ":" + cnonceStr
|
||||||
|
a2 := authenticate + ":" + digestURI
|
||||||
|
response := hex(kd(hex(h(a1)), nonce+":"+nonceCountStr+":"+cnonceStr+":auth:"+hex(h(a2))))
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
func cnonce() string {
|
||||||
|
randSize := big.NewInt(0)
|
||||||
|
randSize.Lsh(big.NewInt(1), 64)
|
||||||
|
cn, err := rand.Int(rand.Reader, randSize)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%016x", cn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init(o *Options) error {
|
||||||
|
|
||||||
|
var domain string
|
||||||
|
var user string
|
||||||
|
a := strings.SplitN(o.User, "@", 2)
|
||||||
|
if len(o.User) > 0 {
|
||||||
|
if len(a) != 2 {
|
||||||
|
return errors.New("xmpp: invalid username (want user@domain): " + o.User)
|
||||||
|
}
|
||||||
|
user = a[0]
|
||||||
|
domain = a[1]
|
||||||
|
} // Otherwise, we'll be attempting ANONYMOUS
|
||||||
|
|
||||||
|
// Declare intent to be a jabber client and gather stream features.
|
||||||
|
f, err := c.startStream(o, domain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the server requires we STARTTLS, attempt to do so.
|
||||||
|
if f, err = c.startTLSIfRequired(f, o, domain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.User == "" && o.Password == "" {
|
||||||
|
foundAnonymous := false
|
||||||
|
for _, m := range f.Mechanisms.Mechanism {
|
||||||
|
if m == "ANONYMOUS" {
|
||||||
|
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='ANONYMOUS' />\n", nsSASL)
|
||||||
|
foundAnonymous = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundAnonymous {
|
||||||
|
return fmt.Errorf("ANONYMOUS authentication is not an option and username and password were not specified")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Even digest forms of authentication are unsafe if we do not know that the host
|
||||||
|
// we are talking to is the actual server, and not a man in the middle playing
|
||||||
|
// proxy.
|
||||||
|
if !c.IsEncrypted() && !o.InsecureAllowUnencryptedAuth {
|
||||||
|
return errors.New("refusing to authenticate over unencrypted TCP connection")
|
||||||
|
}
|
||||||
|
|
||||||
|
mechanism := ""
|
||||||
|
for _, m := range f.Mechanisms.Mechanism {
|
||||||
|
if m == "X-OAUTH2" && o.OAuthToken != "" && o.OAuthScope != "" {
|
||||||
|
mechanism = m
|
||||||
|
// Oauth authentication: send base64-encoded \x00 user \x00 token.
|
||||||
|
raw := "\x00" + user + "\x00" + o.OAuthToken
|
||||||
|
enc := make([]byte, base64.StdEncoding.EncodedLen(len(raw)))
|
||||||
|
base64.StdEncoding.Encode(enc, []byte(raw))
|
||||||
|
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='X-OAUTH2' auth:service='oauth2' "+
|
||||||
|
"xmlns:auth='%s'>%s</auth>\n", nsSASL, o.OAuthXmlNs, enc)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if m == "PLAIN" {
|
||||||
|
mechanism = m
|
||||||
|
// Plain authentication: send base64-encoded \x00 user \x00 password.
|
||||||
|
raw := "\x00" + user + "\x00" + o.Password
|
||||||
|
enc := make([]byte, base64.StdEncoding.EncodedLen(len(raw)))
|
||||||
|
base64.StdEncoding.Encode(enc, []byte(raw))
|
||||||
|
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='PLAIN'>%s</auth>\n", nsSASL, enc)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if m == "DIGEST-MD5" {
|
||||||
|
mechanism = m
|
||||||
|
// Digest-MD5 authentication
|
||||||
|
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='DIGEST-MD5'/>\n", nsSASL)
|
||||||
|
var ch saslChallenge
|
||||||
|
if err = c.p.DecodeElement(&ch, nil); err != nil {
|
||||||
|
return errors.New("unmarshal <challenge>: " + err.Error())
|
||||||
|
}
|
||||||
|
b, err := base64.StdEncoding.DecodeString(string(ch))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tokens := map[string]string{}
|
||||||
|
for _, token := range strings.Split(string(b), ",") {
|
||||||
|
kv := strings.SplitN(strings.TrimSpace(token), "=", 2)
|
||||||
|
if len(kv) == 2 {
|
||||||
|
if kv[1][0] == '"' && kv[1][len(kv[1])-1] == '"' {
|
||||||
|
kv[1] = kv[1][1 : len(kv[1])-1]
|
||||||
|
}
|
||||||
|
tokens[kv[0]] = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
realm, _ := tokens["realm"]
|
||||||
|
nonce, _ := tokens["nonce"]
|
||||||
|
qop, _ := tokens["qop"]
|
||||||
|
charset, _ := tokens["charset"]
|
||||||
|
cnonceStr := cnonce()
|
||||||
|
digestURI := "xmpp/" + domain
|
||||||
|
nonceCount := fmt.Sprintf("%08x", 1)
|
||||||
|
digest := saslDigestResponse(user, realm, o.Password, nonce, cnonceStr, "AUTHENTICATE", digestURI, nonceCount)
|
||||||
|
message := "username=\"" + user + "\", realm=\"" + realm + "\", nonce=\"" + nonce + "\", cnonce=\"" + cnonceStr +
|
||||||
|
"\", nc=" + nonceCount + ", qop=" + qop + ", digest-uri=\"" + digestURI + "\", response=" + digest + ", charset=" + charset
|
||||||
|
|
||||||
|
fmt.Fprintf(c.conn, "<response xmlns='%s'>%s</response>\n", nsSASL, base64.StdEncoding.EncodeToString([]byte(message)))
|
||||||
|
|
||||||
|
var rspauth saslRspAuth
|
||||||
|
if err = c.p.DecodeElement(&rspauth, nil); err != nil {
|
||||||
|
return errors.New("unmarshal <challenge>: " + err.Error())
|
||||||
|
}
|
||||||
|
b, err = base64.StdEncoding.DecodeString(string(rspauth))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(c.conn, "<response xmlns='%s'/>\n", nsSASL)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mechanism == "" {
|
||||||
|
return fmt.Errorf("PLAIN authentication is not an option: %v", f.Mechanisms.Mechanism)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Next message should be either success or failure.
|
||||||
|
name, val, err := next(c.p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch v := val.(type) {
|
||||||
|
case *saslSuccess:
|
||||||
|
case *saslFailure:
|
||||||
|
// v.Any is type of sub-element in failure,
|
||||||
|
// which gives a description of what failed.
|
||||||
|
return errors.New("auth failure: " + v.Any.Local)
|
||||||
|
default:
|
||||||
|
return errors.New("expected <success> or <failure>, got <" + name.Local + "> in " + name.Space)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now that we're authenticated, we're supposed to start the stream over again.
|
||||||
|
// Declare intent to be a jabber client.
|
||||||
|
if f, err = c.startStream(o, domain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a unique cookie
|
||||||
|
cookie := getCookie()
|
||||||
|
|
||||||
|
// Send IQ message asking to bind to the local user name.
|
||||||
|
if o.Resource == "" {
|
||||||
|
fmt.Fprintf(c.conn, "<iq type='set' id='%x'><bind xmlns='%s'></bind></iq>\n", cookie, nsBind)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(c.conn, "<iq type='set' id='%x'><bind xmlns='%s'><resource>%s</resource></bind></iq>\n", cookie, nsBind, o.Resource)
|
||||||
|
}
|
||||||
|
var iq clientIQ
|
||||||
|
if err = c.p.DecodeElement(&iq, nil); err != nil {
|
||||||
|
return errors.New("unmarshal <iq>: " + err.Error())
|
||||||
|
}
|
||||||
|
if &iq.Bind == nil {
|
||||||
|
return errors.New("<iq> result missing <bind>")
|
||||||
|
}
|
||||||
|
c.jid = iq.Bind.Jid // our local id
|
||||||
|
c.domain = domain
|
||||||
|
|
||||||
|
if o.Session {
|
||||||
|
//if server support session, open it
|
||||||
|
fmt.Fprintf(c.conn, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>", xmlEscape(domain), cookie, nsSession)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're connected and can now receive and send messages.
|
||||||
|
fmt.Fprintf(c.conn, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", o.Status, o.StatusMessage)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// startTlsIfRequired examines the server's stream features and, if STARTTLS is required or supported, performs the TLS handshake.
|
||||||
|
// f will be updated if the handshake completes, as the new stream's features are typically different from the original.
|
||||||
|
func (c *Client) startTLSIfRequired(f *streamFeatures, o *Options, domain string) (*streamFeatures, error) {
|
||||||
|
// whether we start tls is a matter of opinion: the server's and the user's.
|
||||||
|
switch {
|
||||||
|
case f.StartTLS == nil:
|
||||||
|
// the server does not support STARTTLS
|
||||||
|
return f, nil
|
||||||
|
case f.StartTLS.Required != nil:
|
||||||
|
// the server requires STARTTLS.
|
||||||
|
case !o.StartTLS:
|
||||||
|
// the user wants STARTTLS and the server supports it.
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
fmt.Fprintf(c.conn, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>\n")
|
||||||
|
var k tlsProceed
|
||||||
|
if err = c.p.DecodeElement(&k, nil); err != nil {
|
||||||
|
return f, errors.New("unmarshal <proceed>: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
tc := o.TLSConfig
|
||||||
|
if tc == nil {
|
||||||
|
tc = new(tls.Config)
|
||||||
|
*tc = DefaultConfig
|
||||||
|
//TODO(scott): we should consider using the server's address or reverse lookup
|
||||||
|
tc.ServerName = domain
|
||||||
|
}
|
||||||
|
t := tls.Client(c.conn, tc)
|
||||||
|
|
||||||
|
if err = t.Handshake(); err != nil {
|
||||||
|
return f, errors.New("starttls handshake: " + err.Error())
|
||||||
|
}
|
||||||
|
c.conn = t
|
||||||
|
|
||||||
|
// restart our declaration of XMPP stream intentions.
|
||||||
|
tf, err := c.startStream(o, domain)
|
||||||
|
if err != nil {
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
|
return tf, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// startStream will start a new XML decoder for the connection, signal the start of a stream to the server and verify that the server has
|
||||||
|
// also started the stream; if o.Debug is true, startStream will tee decoded XML data to stderr. The features advertised by the server
|
||||||
|
// will be returned.
|
||||||
|
func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) {
|
||||||
|
if o.Debug {
|
||||||
|
c.p = xml.NewDecoder(tee{c.conn, os.Stderr})
|
||||||
|
} else {
|
||||||
|
c.p = xml.NewDecoder(c.conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := fmt.Fprintf(c.conn, "<?xml version='1.0'?>\n"+
|
||||||
|
"<stream:stream to='%s' xmlns='%s'\n"+
|
||||||
|
" xmlns:stream='%s' version='1.0'>\n",
|
||||||
|
xmlEscape(domain), nsClient, nsStream)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// We expect the server to start a <stream>.
|
||||||
|
se, err := nextStart(c.p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if se.Name.Space != nsStream || se.Name.Local != "stream" {
|
||||||
|
return nil, fmt.Errorf("expected <stream> but got <%v> in %v", se.Name.Local, se.Name.Space)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we're in the stream and can use Unmarshal.
|
||||||
|
// Next message should be <features> to tell us authentication options.
|
||||||
|
// See section 4.6 in RFC 3920.
|
||||||
|
f := new(streamFeatures)
|
||||||
|
if err = c.p.DecodeElement(f, nil); err != nil {
|
||||||
|
return f, errors.New("unmarshal <features>: " + err.Error())
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEncrypted will return true if the client is connected using a TLS transport, either because it used.
|
||||||
|
// TLS to connect from the outset, or because it successfully used STARTTLS to promote a TCP connection to TLS.
|
||||||
|
func (c *Client) IsEncrypted() bool {
|
||||||
|
_, ok := c.conn.(*tls.Conn)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chat is an incoming or outgoing XMPP chat message.
|
||||||
|
type Chat struct {
|
||||||
|
Remote string
|
||||||
|
Type string
|
||||||
|
Text string
|
||||||
|
Roster Roster
|
||||||
|
Other []string
|
||||||
|
Stamp time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type Roster []Contact
|
||||||
|
|
||||||
|
type Contact struct {
|
||||||
|
Remote string
|
||||||
|
Name string
|
||||||
|
Group []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Presence is an XMPP presence notification.
|
||||||
|
type Presence struct {
|
||||||
|
From string
|
||||||
|
To string
|
||||||
|
Type string
|
||||||
|
Show string
|
||||||
|
Status string
|
||||||
|
}
|
||||||
|
|
||||||
|
type IQ struct {
|
||||||
|
ID string
|
||||||
|
From string
|
||||||
|
To string
|
||||||
|
Type string
|
||||||
|
Query []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recv waits to receive the next XMPP stanza.
|
||||||
|
// Return type is either a presence notification or a chat message.
|
||||||
|
func (c *Client) Recv() (stanza interface{}, err error) {
|
||||||
|
for {
|
||||||
|
_, val, err := next(c.p)
|
||||||
|
if err != nil {
|
||||||
|
return Chat{}, err
|
||||||
|
}
|
||||||
|
switch v := val.(type) {
|
||||||
|
case *clientMessage:
|
||||||
|
stamp, _ := time.Parse(
|
||||||
|
"2006-01-02T15:04:05Z",
|
||||||
|
v.Delay.Stamp,
|
||||||
|
)
|
||||||
|
chat := Chat{
|
||||||
|
Remote: v.From,
|
||||||
|
Type: v.Type,
|
||||||
|
Text: v.Body,
|
||||||
|
Other: v.Other,
|
||||||
|
Stamp: stamp,
|
||||||
|
}
|
||||||
|
return chat, nil
|
||||||
|
case *clientQuery:
|
||||||
|
var r Roster
|
||||||
|
for _, item := range v.Item {
|
||||||
|
r = append(r, Contact{item.Jid, item.Name, item.Group})
|
||||||
|
}
|
||||||
|
return Chat{Type: "roster", Roster: r}, nil
|
||||||
|
case *clientPresence:
|
||||||
|
return Presence{v.From, v.To, v.Type, v.Show, v.Status}, nil
|
||||||
|
case *clientIQ:
|
||||||
|
return IQ{ID: v.ID, From: v.From, To: v.To, Type: v.Type, Query: v.Query}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send sends the message wrapped inside an XMPP message stanza body.
|
||||||
|
func (c *Client) Send(chat Chat) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+"<body>%s</body></message>",
|
||||||
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
|
||||||
|
func (c *Client) SendOrg(org string) (n int, err error) {
|
||||||
|
return fmt.Fprint(c.conn, org)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) SendPresence(presence Presence) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence from='%s' to='%s'/>", xmlEscape(presence.From), xmlEscape(presence.To))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendHtml sends the message as HTML as defined by XEP-0071
|
||||||
|
func (c *Client) SendHtml(chat Chat) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+
|
||||||
|
"<body>%s</body>"+
|
||||||
|
"<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html></message>",
|
||||||
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text), chat.Text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Roster asks for the chat roster.
|
||||||
|
func (c *Client) Roster() error {
|
||||||
|
fmt.Fprintf(c.conn, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 3920 C.1 Streams name space
|
||||||
|
type streamFeatures struct {
|
||||||
|
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
|
||||||
|
StartTLS *tlsStartTLS
|
||||||
|
Mechanisms saslMechanisms
|
||||||
|
Bind bindBind
|
||||||
|
Session bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type streamError struct {
|
||||||
|
XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"`
|
||||||
|
Any xml.Name
|
||||||
|
Text string
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 3920 C.3 TLS name space
|
||||||
|
type tlsStartTLS struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
|
||||||
|
Required *string `xml:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type tlsProceed struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls proceed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type tlsFailure struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 3920 C.4 SASL name space
|
||||||
|
type saslMechanisms struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
|
||||||
|
Mechanism []string `xml:"mechanism"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type saslAuth struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl auth"`
|
||||||
|
Mechanism string `xml:",attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type saslChallenge string
|
||||||
|
|
||||||
|
type saslRspAuth string
|
||||||
|
|
||||||
|
type saslResponse string
|
||||||
|
|
||||||
|
type saslAbort struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl abort"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type saslSuccess struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type saslFailure struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
|
||||||
|
Any xml.Name `xml:",any"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 3920 C.5 Resource binding name space
|
||||||
|
type bindBind struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
|
||||||
|
Resource string
|
||||||
|
Jid string `xml:"jid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 3921 B.1 jabber:client
|
||||||
|
type clientMessage struct {
|
||||||
|
XMLName xml.Name `xml:"jabber:client message"`
|
||||||
|
From string `xml:"from,attr"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
To string `xml:"to,attr"`
|
||||||
|
Type string `xml:"type,attr"` // chat, error, groupchat, headline, or normal
|
||||||
|
|
||||||
|
// These should technically be []clientText, but string is much more convenient.
|
||||||
|
Subject string `xml:"subject"`
|
||||||
|
Body string `xml:"body"`
|
||||||
|
Thread string `xml:"thread"`
|
||||||
|
|
||||||
|
// Any hasn't matched element
|
||||||
|
Other []string `xml:",any"`
|
||||||
|
|
||||||
|
Delay Delay `xml:"delay"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Delay struct {
|
||||||
|
Stamp string `xml:"stamp,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientText struct {
|
||||||
|
Lang string `xml:",attr"`
|
||||||
|
Body string `xml:"chardata"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientPresence struct {
|
||||||
|
XMLName xml.Name `xml:"jabber:client presence"`
|
||||||
|
From string `xml:"from,attr"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
To string `xml:"to,attr"`
|
||||||
|
Type string `xml:"type,attr"` // error, probe, subscribe, subscribed, unavailable, unsubscribe, unsubscribed
|
||||||
|
Lang string `xml:"lang,attr"`
|
||||||
|
|
||||||
|
Show string `xml:"show"` // away, chat, dnd, xa
|
||||||
|
Status string `xml:"status"` // sb []clientText
|
||||||
|
Priority string `xml:"priority,attr"`
|
||||||
|
Error *clientError
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientIQ struct { // info/query
|
||||||
|
XMLName xml.Name `xml:"jabber:client iq"`
|
||||||
|
From string `xml:"from,attr"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
To string `xml:"to,attr"`
|
||||||
|
Type string `xml:"type,attr"` // error, get, result, set
|
||||||
|
Query []byte `xml:",innerxml"`
|
||||||
|
Error clientError
|
||||||
|
Bind bindBind
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientError struct {
|
||||||
|
XMLName xml.Name `xml:"jabber:client error"`
|
||||||
|
Code string `xml:",attr"`
|
||||||
|
Type string `xml:",attr"`
|
||||||
|
Any xml.Name
|
||||||
|
Text string
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientQuery struct {
|
||||||
|
Item []rosterItem
|
||||||
|
}
|
||||||
|
|
||||||
|
type rosterItem struct {
|
||||||
|
XMLName xml.Name `xml:"jabber:iq:roster item"`
|
||||||
|
Jid string `xml:",attr"`
|
||||||
|
Name string `xml:",attr"`
|
||||||
|
Subscription string `xml:",attr"`
|
||||||
|
Group []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan XML token stream to find next StartElement.
|
||||||
|
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
||||||
|
for {
|
||||||
|
t, err := p.Token()
|
||||||
|
if err != nil && err != io.EOF || t == nil {
|
||||||
|
return xml.StartElement{}, err
|
||||||
|
}
|
||||||
|
switch t := t.(type) {
|
||||||
|
case xml.StartElement:
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan XML token stream for next element and save into val.
|
||||||
|
// If val == nil, allocate new element based on proto map.
|
||||||
|
// Either way, return val.
|
||||||
|
func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
||||||
|
// Read start element to find out what type we want.
|
||||||
|
se, err := nextStart(p)
|
||||||
|
if err != nil {
|
||||||
|
return xml.Name{}, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put it in an interface and allocate one.
|
||||||
|
var nv interface{}
|
||||||
|
switch se.Name.Space + " " + se.Name.Local {
|
||||||
|
case nsStream + " features":
|
||||||
|
nv = &streamFeatures{}
|
||||||
|
case nsStream + " error":
|
||||||
|
nv = &streamError{}
|
||||||
|
case nsTLS + " starttls":
|
||||||
|
nv = &tlsStartTLS{}
|
||||||
|
case nsTLS + " proceed":
|
||||||
|
nv = &tlsProceed{}
|
||||||
|
case nsTLS + " failure":
|
||||||
|
nv = &tlsFailure{}
|
||||||
|
case nsSASL + " mechanisms":
|
||||||
|
nv = &saslMechanisms{}
|
||||||
|
case nsSASL + " challenge":
|
||||||
|
nv = ""
|
||||||
|
case nsSASL + " response":
|
||||||
|
nv = ""
|
||||||
|
case nsSASL + " abort":
|
||||||
|
nv = &saslAbort{}
|
||||||
|
case nsSASL + " success":
|
||||||
|
nv = &saslSuccess{}
|
||||||
|
case nsSASL + " failure":
|
||||||
|
nv = &saslFailure{}
|
||||||
|
case nsBind + " bind":
|
||||||
|
nv = &bindBind{}
|
||||||
|
case nsClient + " message":
|
||||||
|
nv = &clientMessage{}
|
||||||
|
case nsClient + " presence":
|
||||||
|
nv = &clientPresence{}
|
||||||
|
case nsClient + " iq":
|
||||||
|
nv = &clientIQ{}
|
||||||
|
case nsClient + " error":
|
||||||
|
nv = &clientError{}
|
||||||
|
default:
|
||||||
|
return xml.Name{}, nil, errors.New("unexpected XMPP message " +
|
||||||
|
se.Name.Space + " <" + se.Name.Local + "/>")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal into that storage.
|
||||||
|
if err = p.DecodeElement(nv, &se); err != nil {
|
||||||
|
return xml.Name{}, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return se.Name, nv, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var xmlSpecial = map[byte]string{
|
||||||
|
'<': "<",
|
||||||
|
'>': ">",
|
||||||
|
'"': """,
|
||||||
|
'\'': "'",
|
||||||
|
'&': "&",
|
||||||
|
}
|
||||||
|
|
||||||
|
func xmlEscape(s string) string {
|
||||||
|
var b bytes.Buffer
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
c := s[i]
|
||||||
|
if s, ok := xmlSpecial[c]; ok {
|
||||||
|
b.WriteString(s)
|
||||||
|
} else {
|
||||||
|
b.WriteByte(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
type tee struct {
|
||||||
|
r io.Reader
|
||||||
|
w io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t tee) Read(p []byte) (n int, err error) {
|
||||||
|
n, err = t.r.Read(p)
|
||||||
|
if n > 0 {
|
||||||
|
t.w.Write(p[0:n])
|
||||||
|
t.w.Write([]byte("\n"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
24
vendor/github.com/mattn/go-xmpp/xmpp_information_query.go
generated
vendored
Normal file
24
vendor/github.com/mattn/go-xmpp/xmpp_information_query.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const IQTypeGet = "get"
|
||||||
|
const IQTypeSet = "set"
|
||||||
|
const IQTypeResult = "result"
|
||||||
|
|
||||||
|
func (c *Client) Discovery() (string, error) {
|
||||||
|
const namespace = "http://jabber.org/protocol/disco#items"
|
||||||
|
// use getCookie for a pseudo random id.
|
||||||
|
reqID := strconv.FormatUint(uint64(getCookie()), 10)
|
||||||
|
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, namespace, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// RawInformationQuery sends an information query request to the server.
|
||||||
|
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
|
||||||
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>"
|
||||||
|
_, err := fmt.Fprintf(c.conn, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
||||||
|
return id, err
|
||||||
|
}
|
||||||
134
vendor/github.com/mattn/go-xmpp/xmpp_muc.go
generated
vendored
Normal file
134
vendor/github.com/mattn/go-xmpp/xmpp_muc.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// Copyright 2013 Flo Lauber <dev@qatfy.at>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// TODO(flo):
|
||||||
|
// - support password protected MUC rooms
|
||||||
|
// - cleanup signatures of join/leave functions
|
||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nsMUC = "http://jabber.org/protocol/muc"
|
||||||
|
nsMUCUser = "http://jabber.org/protocol/muc#user"
|
||||||
|
NoHistory = 0
|
||||||
|
CharHistory = 1
|
||||||
|
StanzaHistory = 2
|
||||||
|
SecondsHistory = 3
|
||||||
|
SinceHistory = 4
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send sends room topic wrapped inside an XMPP message stanza body.
|
||||||
|
func (c *Client) SendTopic(chat Chat) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>",
|
||||||
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) JoinMUCNoHistory(jid, nick string) (n int, err error) {
|
||||||
|
if nick == "" {
|
||||||
|
nick = c.jid
|
||||||
|
}
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
|
||||||
|
"<x xmlns='%s'>"+
|
||||||
|
"<history maxchars='0'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||||
|
}
|
||||||
|
|
||||||
|
// xep-0045 7.2
|
||||||
|
func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||||
|
if nick == "" {
|
||||||
|
nick = c.jid
|
||||||
|
}
|
||||||
|
switch history_type {
|
||||||
|
case NoHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s' />\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||||
|
case CharHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history maxchars='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case StanzaHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history maxstanzas='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case SecondsHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history seconds='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case SinceHistory:
|
||||||
|
if history_date != nil {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history since='%s'/></x>\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("Unknown history option")
|
||||||
|
}
|
||||||
|
|
||||||
|
// xep-0045 7.2.6
|
||||||
|
func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||||
|
if nick == "" {
|
||||||
|
nick = c.jid
|
||||||
|
}
|
||||||
|
switch history_type {
|
||||||
|
case NoHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
||||||
|
case CharHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history maxchars='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case StanzaHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history maxstanzas='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case SecondsHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history seconds='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case SinceHistory:
|
||||||
|
if history_date != nil {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history since='%s'/></x>\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("Unknown history option")
|
||||||
|
}
|
||||||
|
|
||||||
|
// xep-0045 7.14
|
||||||
|
func (c *Client) LeaveMUC(jid string) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence from='%s' to='%s' type='unavailable' />",
|
||||||
|
c.jid, xmlEscape(jid))
|
||||||
|
}
|
||||||
27
vendor/github.com/mattn/go-xmpp/xmpp_ping.go
generated
vendored
Normal file
27
vendor/github.com/mattn/go-xmpp/xmpp_ping.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) PingC2S(jid, server string) error {
|
||||||
|
if jid == "" {
|
||||||
|
jid = c.jid
|
||||||
|
}
|
||||||
|
if server == "" {
|
||||||
|
server = c.domain
|
||||||
|
}
|
||||||
|
_, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+
|
||||||
|
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
||||||
|
"</iq>",
|
||||||
|
xmlEscape(jid), xmlEscape(server))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) PingS2S(fromServer, toServer string) error {
|
||||||
|
_, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='s2s1' type='get'>\n"+
|
||||||
|
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
||||||
|
"</iq>",
|
||||||
|
xmlEscape(fromServer), xmlEscape(toServer))
|
||||||
|
return err
|
||||||
|
}
|
||||||
20
vendor/github.com/mattn/go-xmpp/xmpp_subscription.go
generated
vendored
Normal file
20
vendor/github.com/mattn/go-xmpp/xmpp_subscription.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package xmpp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) ApproveSubscription(jid string) {
|
||||||
|
fmt.Fprintf(c.conn, "<presence to='%s' type='subscribed'/>",
|
||||||
|
xmlEscape(jid))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RevokeSubscription(jid string) {
|
||||||
|
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribed'/>",
|
||||||
|
xmlEscape(jid))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RequestSubscription(jid string) {
|
||||||
|
fmt.Fprintf(c.conn, "<presence to='%s' type='subscribe'/>",
|
||||||
|
xmlEscape(jid))
|
||||||
|
}
|
||||||
1
vendor/github.com/thoj/go-ircevent/irc.go
generated
vendored
1
vendor/github.com/thoj/go-ircevent/irc.go
generated
vendored
@@ -152,7 +152,6 @@ func (irc *Connection) writeLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pings the server if we have not received any messages for 5 minutes
|
// Pings the server if we have not received any messages for 5 minutes
|
||||||
|
|||||||
4
vendor/github.com/thoj/go-ircevent/irc_callback.go
generated
vendored
4
vendor/github.com/thoj/go-ircevent/irc_callback.go
generated
vendored
@@ -33,7 +33,7 @@ func (irc *Connection) RemoveCallback(eventcode string, i int) bool {
|
|||||||
delete(irc.events[eventcode], i)
|
delete(irc.events[eventcode], i)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
irc.Log.Printf("Event found, but no callback found at id %s\n", i)
|
irc.Log.Printf("Event found, but no callback found at id %d\n", i)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ func (irc *Connection) ReplaceCallback(eventcode string, i int, callback func(*E
|
|||||||
event[i] = callback
|
event[i] = callback
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
irc.Log.Printf("Event found, but no callback found at id %s\n", i)
|
irc.Log.Printf("Event found, but no callback found at id %d\n", i)
|
||||||
}
|
}
|
||||||
irc.Log.Printf("Event not found. Use AddCallBack\n")
|
irc.Log.Printf("Event not found. Use AddCallBack\n")
|
||||||
}
|
}
|
||||||
|
|||||||
16
vendor/manifest
vendored
16
vendor/manifest
vendored
@@ -63,8 +63,8 @@
|
|||||||
"importpath": "github.com/mattermost/platform/einterfaces",
|
"importpath": "github.com/mattermost/platform/einterfaces",
|
||||||
"repository": "https://github.com/mattermost/platform",
|
"repository": "https://github.com/mattermost/platform",
|
||||||
"vcs": "git",
|
"vcs": "git",
|
||||||
"revision": "ab52700aaa76a5623de23cd0156f5dbd9a24e264",
|
"revision": "20735470185e0b0ac1d15b975041ed9a2e0e43bc",
|
||||||
"branch": "release-3.2",
|
"branch": "release-3.3",
|
||||||
"path": "/einterfaces",
|
"path": "/einterfaces",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
@@ -72,11 +72,19 @@
|
|||||||
"importpath": "github.com/mattermost/platform/model",
|
"importpath": "github.com/mattermost/platform/model",
|
||||||
"repository": "https://github.com/mattermost/platform",
|
"repository": "https://github.com/mattermost/platform",
|
||||||
"vcs": "git",
|
"vcs": "git",
|
||||||
"revision": "ab52700aaa76a5623de23cd0156f5dbd9a24e264",
|
"revision": "20735470185e0b0ac1d15b975041ed9a2e0e43bc",
|
||||||
"branch": "release-3.2",
|
"branch": "release-3.3",
|
||||||
"path": "/model",
|
"path": "/model",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"importpath": "github.com/mattn/go-xmpp",
|
||||||
|
"repository": "https://github.com/mattn/go-xmpp",
|
||||||
|
"vcs": "git",
|
||||||
|
"revision": "e44d1877bb457f5c3991903e9934a31e55c3a2ad",
|
||||||
|
"branch": "master",
|
||||||
|
"notests": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"importpath": "github.com/nicksnyder/go-i18n/i18n",
|
"importpath": "github.com/nicksnyder/go-i18n/i18n",
|
||||||
"repository": "https://github.com/nicksnyder/go-i18n",
|
"repository": "https://github.com/nicksnyder/go-i18n",
|
||||||
|
|||||||
Reference in New Issue
Block a user