mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-13 07:29:30 +01:00
opers: Enforce oper class permissions
This commit is contained in:
parent
f3459830e7
commit
8e2a8cb1b3
@ -247,6 +247,21 @@ func (client *Client) HasUsername() bool {
|
|||||||
return client.username != "" && client.username != "*"
|
return client.username != "" && client.username != "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCapabs returns true if client has the given (role) capabilities.
|
||||||
|
func (client *Client) HasCapabs(capabs ...string) bool {
|
||||||
|
if client.class == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, capab := range capabs {
|
||||||
|
if !client.class.Capabilities[capab] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// <mode>
|
// <mode>
|
||||||
func (c *Client) ModeString() (str string) {
|
func (c *Client) ModeString() (str string) {
|
||||||
str = "+"
|
str = "+"
|
||||||
|
@ -15,6 +15,7 @@ type Command struct {
|
|||||||
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
|
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
|
||||||
leaveClientIdle bool
|
leaveClientIdle bool
|
||||||
minParams int
|
minParams int
|
||||||
|
capabs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs this command with the given client/message.
|
// Run runs this command with the given client/message.
|
||||||
@ -27,6 +28,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
|
|||||||
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
|
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if len(cmd.capabs) > 0 && !client.HasCapabs(cmd.capabs...) {
|
||||||
|
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied")
|
||||||
|
return false
|
||||||
|
}
|
||||||
if len(msg.Params) < cmd.minParams {
|
if len(msg.Params) < cmd.minParams {
|
||||||
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
|
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
|
||||||
return false
|
return false
|
||||||
@ -91,6 +96,7 @@ var Commands = map[string]Command{
|
|||||||
handler: killHandler,
|
handler: killHandler,
|
||||||
minParams: 1,
|
minParams: 1,
|
||||||
oper: true,
|
oper: true,
|
||||||
|
capabs: []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself
|
||||||
},
|
},
|
||||||
"LIST": {
|
"LIST": {
|
||||||
handler: listHandler,
|
handler: listHandler,
|
||||||
@ -168,6 +174,7 @@ var Commands = map[string]Command{
|
|||||||
handler: rehashHandler,
|
handler: rehashHandler,
|
||||||
minParams: 0,
|
minParams: 0,
|
||||||
oper: true,
|
oper: true,
|
||||||
|
capabs: []string{"oper:rehash"},
|
||||||
},
|
},
|
||||||
"TIME": {
|
"TIME": {
|
||||||
handler: timeHandler,
|
handler: timeHandler,
|
||||||
|
Loading…
Reference in New Issue
Block a user