mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-24 03:29:28 +01:00
automode: switch from irc.checkAuthenticated to new-style permissions
This commit is contained in:
parent
91e39b7df9
commit
104c0cef4b
@ -8,6 +8,7 @@ import json
|
|||||||
|
|
||||||
from pylinkirc import utils, conf, world
|
from pylinkirc import utils, conf, world
|
||||||
from pylinkirc.log import log
|
from pylinkirc.log import log
|
||||||
|
from pylinkirc.coremods import permissions
|
||||||
|
|
||||||
mydesc = ("The \x02Automode\x02 plugin provides simple channel ACL management by giving prefix modes "
|
mydesc = ("The \x02Automode\x02 plugin provides simple channel ACL management by giving prefix modes "
|
||||||
"to users matching hostmasks or exttargets.")
|
"to users matching hostmasks or exttargets.")
|
||||||
@ -95,6 +96,35 @@ def die(sourceirc):
|
|||||||
|
|
||||||
utils.unregisterService('automode')
|
utils.unregisterService('automode')
|
||||||
|
|
||||||
|
def checkAccess(irc, uid, channel, command):
|
||||||
|
"""Checks the caller's access to Automode."""
|
||||||
|
# Automode defines the following permissions, where <command> is either "manage", "list",
|
||||||
|
# "sync", or "clear":
|
||||||
|
# - automode.<command> OR automode.<command>.*: ability to <command> automode on all channels.
|
||||||
|
# - automode.<command>.relay_owned: ability to <command> automode on channels owned via Relay.
|
||||||
|
# If Relay isn't loaded, this permission check FAILS.
|
||||||
|
# - automode.<command>.#channel: ability to <command> automode on the given channel.
|
||||||
|
# - automode.savedb: ability to save the automode DB.
|
||||||
|
log.debug('(%s) Automode: checking access for %s/%s for %s capability on %s', irc.name, uid,
|
||||||
|
irc.getHostmask(uid), command, channel)
|
||||||
|
|
||||||
|
baseperm = 'automode.%s' % command
|
||||||
|
try:
|
||||||
|
# First, check the catch all and channel permissions.
|
||||||
|
return permissions.checkPermissions(irc, uid, [baseperm, baseperm+'.*', '%s.%s' % (command, channel)])
|
||||||
|
except utils.NotAuthorizedError:
|
||||||
|
log.debug('(%s) Automode: falling back to automode.%s.relay_owned', irc.name, command)
|
||||||
|
permissions.checkPermissions(irc, uid, [baseperm+'.relay_owned'])
|
||||||
|
|
||||||
|
relay = world.plugins.get('relay')
|
||||||
|
if relay is None:
|
||||||
|
raise utils.NotAuthorizedError("You are not authorized to use Automode when Relay is "
|
||||||
|
"disabled. You are missing one of the following "
|
||||||
|
"permissions: %s or %s.%s" % (baseperm, baseperm, channel))
|
||||||
|
elif (irc.name, channel) not in relay.db:
|
||||||
|
raise utils.NotAuthorizedError("The network you are on does not own the relay channel %s." % channel)
|
||||||
|
return True
|
||||||
|
|
||||||
def setacc(irc, source, args):
|
def setacc(irc, source, args):
|
||||||
"""<channel> <mask> <mode list>
|
"""<channel> <mask> <mode list>
|
||||||
|
|
||||||
@ -106,7 +136,7 @@ def setacc(irc, source, args):
|
|||||||
SET #channel $oper:Network?Administrator qo
|
SET #channel $oper:Network?Administrator qo
|
||||||
SET #staffchan $channel:#mainchan:op o
|
SET #staffchan $channel:#mainchan:op o
|
||||||
"""
|
"""
|
||||||
irc.checkAuthenticated(source, allowOper=False)
|
|
||||||
try:
|
try:
|
||||||
channel, mask, modes = args
|
channel, mask, modes = args
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -120,6 +150,8 @@ def setacc(irc, source, args):
|
|||||||
# Store channels case insensitively
|
# Store channels case insensitively
|
||||||
channel = irc.toLower(channel)
|
channel = irc.toLower(channel)
|
||||||
|
|
||||||
|
checkAccess(irc, source, channel, 'manage')
|
||||||
|
|
||||||
# Database entries for any network+channel pair are automatically created using
|
# Database entries for any network+channel pair are automatically created using
|
||||||
# defaultdict. Note: string keys are used here instead of tuples so they can be
|
# defaultdict. Note: string keys are used here instead of tuples so they can be
|
||||||
# exported easily as JSON.
|
# exported easily as JSON.
|
||||||
@ -138,8 +170,6 @@ def delacc(irc, source, args):
|
|||||||
|
|
||||||
Removes the Automode entry for the given mask on the given channel, if one exists.
|
Removes the Automode entry for the given mask on the given channel, if one exists.
|
||||||
"""
|
"""
|
||||||
irc.checkAuthenticated(source, allowOper=False)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
channel, mask = args
|
channel, mask = args
|
||||||
channel = irc.toLower(channel)
|
channel = irc.toLower(channel)
|
||||||
@ -147,6 +177,8 @@ def delacc(irc, source, args):
|
|||||||
reply(irc, "Error: Invalid arguments given. Needs 2: channel, mask")
|
reply(irc, "Error: Invalid arguments given. Needs 2: channel, mask")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
checkAccess(irc, source, channel, 'manage')
|
||||||
|
|
||||||
dbentry = db.get(irc.name+channel)
|
dbentry = db.get(irc.name+channel)
|
||||||
|
|
||||||
if dbentry is None:
|
if dbentry is None:
|
||||||
@ -173,12 +205,14 @@ def listacc(irc, source, args):
|
|||||||
"""<channel>
|
"""<channel>
|
||||||
|
|
||||||
Lists all Automode entries for the given channel."""
|
Lists all Automode entries for the given channel."""
|
||||||
irc.checkAuthenticated(source)
|
|
||||||
try:
|
try:
|
||||||
channel = irc.toLower(args[0])
|
channel = irc.toLower(args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
checkAccess(irc, source, channel, 'list')
|
||||||
|
|
||||||
dbentry = db.get(irc.name+channel)
|
dbentry = db.get(irc.name+channel)
|
||||||
if not dbentry:
|
if not dbentry:
|
||||||
reply(irc, "Error: No Automode access entries exist for \x02%s\x02." % channel)
|
reply(irc, "Error: No Automode access entries exist for \x02%s\x02." % channel)
|
||||||
@ -199,7 +233,7 @@ def save(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Saves the Automode database to disk."""
|
Saves the Automode database to disk."""
|
||||||
irc.checkAuthenticated(source)
|
permissions.checkPermissions(irc, source, ['automode.savedb'])
|
||||||
exportDB()
|
exportDB()
|
||||||
reply(irc, 'Done.')
|
reply(irc, 'Done.')
|
||||||
modebot.add_cmd(save)
|
modebot.add_cmd(save)
|
||||||
@ -247,13 +281,13 @@ def syncacc(irc, source, args):
|
|||||||
|
|
||||||
Syncs Automode access lists to the channel.
|
Syncs Automode access lists to the channel.
|
||||||
"""
|
"""
|
||||||
irc.checkAuthenticated(source, allowOper=False)
|
|
||||||
try:
|
try:
|
||||||
channel = irc.toLower(args[0])
|
channel = irc.toLower(args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
checkAccess(irc, source, channel, 'sync')
|
||||||
match(irc, channel)
|
match(irc, channel)
|
||||||
|
|
||||||
reply(irc, 'Done.')
|
reply(irc, 'Done.')
|
||||||
@ -267,7 +301,6 @@ def clearacc(irc, source, args):
|
|||||||
|
|
||||||
Removes all Automode entries for the given channel.
|
Removes all Automode entries for the given channel.
|
||||||
"""
|
"""
|
||||||
irc.checkAuthenticated(source, allowOper=False)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
channel = irc.toLower(args[0])
|
channel = irc.toLower(args[0])
|
||||||
@ -275,6 +308,8 @@ def clearacc(irc, source, args):
|
|||||||
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
reply(irc, "Error: Invalid arguments given. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
checkAccess(irc, source, channel, 'clear')
|
||||||
|
|
||||||
if db.get(irc.name+channel):
|
if db.get(irc.name+channel):
|
||||||
log.debug("Automode: purging channel pair %s/%s", irc.name, channel)
|
log.debug("Automode: purging channel pair %s/%s", irc.name, channel)
|
||||||
del db[irc.name+channel]
|
del db[irc.name+channel]
|
||||||
|
Loading…
Reference in New Issue
Block a user