mirror of https://github.com/fluffle/goirc
Make authentication based on ident and host
This commit is contained in:
parent
e24293df24
commit
e0cf7e3917
|
@ -4,4 +4,4 @@ owner: f.o.o.r
|
||||||
[Rizon #raylu]
|
[Rizon #raylu]
|
||||||
|
|
||||||
[Rizon #vn-meta]
|
[Rizon #vn-meta]
|
||||||
chauc.er: at
|
vermi@chauc.er: at
|
||||||
|
|
34
auth.go
34
auth.go
|
@ -19,6 +19,13 @@ func readAuth() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func user(nick *irc.Nick) string {
|
||||||
|
if nick.Ident[0] == '~' {
|
||||||
|
return nick.Ident[1:] + "@" + nick.Host
|
||||||
|
}
|
||||||
|
return nick.Ident + "@" + nick.Host
|
||||||
|
}
|
||||||
|
|
||||||
func addAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
func addAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
||||||
n := conn.GetNick(nick)
|
n := conn.GetNick(nick)
|
||||||
if n == nil {
|
if n == nil {
|
||||||
|
@ -26,7 +33,8 @@ func addAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
section := conn.Network + " " + channel
|
section := conn.Network + " " + channel
|
||||||
cflags, _ := auth.String(section, n.Host)
|
user := user(n)
|
||||||
|
cflags, _ := auth.String(section, user)
|
||||||
|
|
||||||
nflags := cflags
|
nflags := cflags
|
||||||
for _, flag := range flags {
|
for _, flag := range flags {
|
||||||
|
@ -37,12 +45,12 @@ func addAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
||||||
nflags += string(flag)
|
nflags += string(flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.AddOption(section, n.Host, nflags)
|
auth.AddOption(section, user, nflags)
|
||||||
if updateAuth() != nil {
|
if updateAuth() != nil {
|
||||||
say(conn, channel, "Error while writing to %s", authFile)
|
say(conn, channel, "Error while writing to %s", authFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.Host, nflags
|
return user, nflags
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
func removeAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
||||||
|
@ -52,7 +60,8 @@ func removeAccess(conn *irc.Conn, channel, nick, flags string) (string, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
section := conn.Network + " " + channel
|
section := conn.Network + " " + channel
|
||||||
cflags, _ := auth.String(section, n.Host)
|
user := user(n)
|
||||||
|
cflags, _ := auth.String(section, user)
|
||||||
|
|
||||||
nflags := ""
|
nflags := ""
|
||||||
for _, flag := range cflags {
|
for _, flag := range cflags {
|
||||||
|
@ -62,12 +71,12 @@ func removeAccess(conn *irc.Conn, channel, nick, flags string) (string, string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.AddOption(section, n.Host, nflags)
|
auth.AddOption(section, user, nflags)
|
||||||
if updateAuth() != nil {
|
if updateAuth() != nil {
|
||||||
say(conn, channel, "Error while writing to %s", authFile)
|
say(conn, channel, "Error while writing to %s", authFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.Host, nflags
|
return user, nflags
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeUser(conn *irc.Conn, channel, nick string) (string, bool) {
|
func removeUser(conn *irc.Conn, channel, nick string) (string, bool) {
|
||||||
|
@ -77,15 +86,16 @@ func removeUser(conn *irc.Conn, channel, nick string) (string, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
section := conn.Network + " " + channel
|
section := conn.Network + " " + channel
|
||||||
|
user := user(n)
|
||||||
|
|
||||||
if !auth.RemoveOption(section, n.Host) {
|
if !auth.RemoveOption(section, user) {
|
||||||
return n.Host, false
|
return user, false
|
||||||
}
|
}
|
||||||
if updateAuth() != nil {
|
if updateAuth() != nil {
|
||||||
say(conn, channel, "Error while writing to %s", authFile)
|
say(conn, channel, "Error while writing to %s", authFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.Host, true
|
return user, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// this allows target to be a channel or a privmsg in which the channel is the first argument
|
// this allows target to be a channel or a privmsg in which the channel is the first argument
|
||||||
|
@ -117,12 +127,12 @@ func hasAccess(conn *irc.Conn, nick, target, args, flag string) (string, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// actually check access
|
// actually check access
|
||||||
if owner, _ := auth.String(conn.Network, "owner"); owner == n.Host {
|
user := user(n)
|
||||||
|
if owner, _ := auth.String(conn.Network, "owner"); owner == user {
|
||||||
return channel, args
|
return channel, args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags, err := auth.String(conn.Network + " " + channel, user)
|
||||||
flags, err := auth.String(conn.Network + " " + channel, n.Host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", args
|
return "", args
|
||||||
}
|
}
|
||||||
|
|
11
handler.go
11
handler.go
|
@ -261,16 +261,17 @@ func flags(conn *irc.Conn, nick, args, target string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner, _ := auth.String(conn.Network, "owner"); owner == n.Host {
|
user := user(n)
|
||||||
say(conn, target, "%s is the owner", query)
|
if owner, _ := auth.String(conn.Network, "owner"); owner == user {
|
||||||
|
say(conn, target, "%s is the owner", user)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
flags, _ := auth.String(conn.Network + " " + channel, n.Host)
|
flags, _ := auth.String(conn.Network + " " + channel, user)
|
||||||
if flags == "" {
|
if flags == "" {
|
||||||
say(conn, target, "%s has no flags", n.Host)
|
say(conn, target, "%s has no flags", user)
|
||||||
} else {
|
} else {
|
||||||
say(conn, target, "%s: %s", n.Host, flags)
|
say(conn, target, "%s: %s", user, flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue