Add SASL auth and CAP negotiation

This commit is contained in:
Ken-Håvard Lieng 2020-05-23 08:05:37 +02:00
parent be8b785813
commit 2f8dad2529
18 changed files with 563 additions and 127 deletions

View file

@ -12,7 +12,7 @@ import (
type connectDefaults struct {
*config.Defaults
Password bool
ServerPassword bool
}
type dispatchVersion struct {
@ -51,7 +51,7 @@ func (d *Dispatch) getIndexData(r *http.Request, state *State) *indexData {
},
}
data.Defaults.Password = cfg.Defaults.Password != ""
data.Defaults.ServerPassword = cfg.Defaults.ServerPassword != ""
if state == nil {
data.Settings = storage.DefaultClientSettings()

View file

@ -553,8 +553,8 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer2(in *jlexer.Lexer, out
continue
}
switch key {
case "password":
out.Password = bool(in.Bool())
case "serverPassword":
out.ServerPassword = bool(in.Bool())
case "name":
out.Name = string(in.String())
case "host":
@ -604,11 +604,11 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer2(out *jwriter.Writer,
out.RawByte('{')
first := true
_ = first
if in.Password {
const prefix string = ",\"password\":"
if in.ServerPassword {
const prefix string = ",\"serverPassword\":"
first = false
out.RawString(prefix[1:])
out.Bool(bool(in.Password))
out.Bool(bool(in.ServerPassword))
}
if in.Name != "" {
const prefix string = ",\"name\":"

View file

@ -55,12 +55,19 @@ func connectIRC(server *storage.Server, state *State, srcIP []byte) *irc.Client
i.Realname = server.Nick
}
if server.Password == "" &&
cfg.Defaults.Password != "" &&
if server.ServerPassword == "" &&
cfg.Defaults.ServerPassword != "" &&
address == cfg.Defaults.Host {
i.Password = cfg.Defaults.Password
i.Password = cfg.Defaults.ServerPassword
} else {
i.Password = server.Password
i.Password = server.ServerPassword
}
if server.Account != "" && server.Password != "" {
i.SASL = &irc.SASLPlain{
Username: server.Account,
Password: server.Password,
}
}
if i.TLS {

View file

@ -866,14 +866,18 @@ func easyjson42239ddeDecodeGithubComKhliengDispatchServer8(in *jlexer.Lexer, out
out.Port = string(in.String())
case "tls":
out.TLS = bool(in.Bool())
case "password":
out.Password = string(in.String())
case "serverPassword":
out.ServerPassword = string(in.String())
case "nick":
out.Nick = string(in.String())
case "username":
out.Username = string(in.String())
case "realname":
out.Realname = string(in.String())
case "account":
out.Account = string(in.String())
case "password":
out.Password = string(in.String())
default:
in.SkipRecursive()
}
@ -964,15 +968,15 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer8(out *jwriter.Writer,
}
out.Bool(bool(in.TLS))
}
if in.Password != "" {
const prefix string = ",\"password\":"
if in.ServerPassword != "" {
const prefix string = ",\"serverPassword\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Password))
out.String(string(in.ServerPassword))
}
if in.Nick != "" {
const prefix string = ",\"nick\":"
@ -1004,6 +1008,26 @@ func easyjson42239ddeEncodeGithubComKhliengDispatchServer8(out *jwriter.Writer,
}
out.String(string(in.Realname))
}
if in.Account != "" {
const prefix string = ",\"account\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Account))
}
if in.Password != "" {
const prefix string = ",\"password\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Password))
}
out.RawByte('}')
}