mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-22 00:10:55 +01:00
Migrate coremods.permissions to snake case
This commit is contained in:
parent
f15f27168a
commit
4379ef68ef
@ -106,7 +106,7 @@ def rehash():
|
|||||||
|
|
||||||
# Reset permissions.
|
# Reset permissions.
|
||||||
log.debug('rehash: resetting permissions')
|
log.debug('rehash: resetting permissions')
|
||||||
permissions.resetPermissions()
|
permissions.reset_permissions()
|
||||||
|
|
||||||
for network, ircobj in world.networkobjects.copy().items():
|
for network, ircobj in world.networkobjects.copy().items():
|
||||||
# Server was removed from the config file, disconnect them.
|
# Server was removed from the config file, disconnect them.
|
||||||
|
@ -59,7 +59,7 @@ def shutdown(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Exits PyLink by disconnecting all networks."""
|
Exits PyLink by disconnecting all networks."""
|
||||||
permissions.checkPermissions(irc, source, ['core.shutdown'])
|
permissions.check_permissions(irc, source, ['core.shutdown'])
|
||||||
log.info('(%s) SHUTDOWN requested by %s, exiting...', irc.name, irc.get_hostmask(source))
|
log.info('(%s) SHUTDOWN requested by %s, exiting...', irc.name, irc.get_hostmask(source))
|
||||||
control.shutdown(irc=irc)
|
control.shutdown(irc=irc)
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ def load(irc, source, args):
|
|||||||
Loads a plugin from the plugin folder."""
|
Loads a plugin from the plugin folder."""
|
||||||
# Note: reload capability is acceptable here, because all it actually does is call
|
# Note: reload capability is acceptable here, because all it actually does is call
|
||||||
# load after unload.
|
# load after unload.
|
||||||
permissions.checkPermissions(irc, source, ['core.load', 'core.reload'])
|
permissions.check_permissions(irc, source, ['core.load', 'core.reload'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
@ -100,7 +100,7 @@ def unload(irc, source, args):
|
|||||||
"""<plugin name>.
|
"""<plugin name>.
|
||||||
|
|
||||||
Unloads a currently loaded plugin."""
|
Unloads a currently loaded plugin."""
|
||||||
permissions.checkPermissions(irc, source, ['core.unload', 'core.reload'])
|
permissions.check_permissions(irc, source, ['core.unload', 'core.reload'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
@ -186,7 +186,7 @@ def rehash(irc, source, args):
|
|||||||
Reloads the configuration file for PyLink, (dis)connecting added/removed networks.
|
Reloads the configuration file for PyLink, (dis)connecting added/removed networks.
|
||||||
|
|
||||||
Note: plugins must be manually reloaded."""
|
Note: plugins must be manually reloaded."""
|
||||||
permissions.checkPermissions(irc, source, ['core.rehash'])
|
permissions.check_permissions(irc, source, ['core.rehash'])
|
||||||
try:
|
try:
|
||||||
control.rehash()
|
control.rehash()
|
||||||
except Exception as e: # Something went wrong, abort.
|
except Exception as e: # Something went wrong, abort.
|
||||||
@ -200,5 +200,5 @@ def clearqueue(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Clears the outgoing text queue for the current connection."""
|
Clears the outgoing text queue for the current connection."""
|
||||||
permissions.checkPermissions(irc, source, ['core.clearqueue'])
|
permissions.check_permissions(irc, source, ['core.clearqueue'])
|
||||||
irc._queue.queue.clear()
|
irc._queue.queue.clear()
|
||||||
|
@ -15,45 +15,48 @@ permissions_lock = threading.Lock()
|
|||||||
from pylinkirc import conf, utils
|
from pylinkirc import conf, utils
|
||||||
from pylinkirc.log import log
|
from pylinkirc.log import log
|
||||||
|
|
||||||
def resetPermissions():
|
def reset_permissions():
|
||||||
"""
|
"""
|
||||||
Loads the permissions specified in the permissions: block of the PyLink configuration,
|
Loads the permissions specified in the permissions: block of the PyLink configuration,
|
||||||
if such a block exists. Otherwise, fallback to the default permissions specified by plugins.
|
if such a block exists. Otherwise, fallback to the default permissions specified by plugins.
|
||||||
"""
|
"""
|
||||||
with permissions_lock:
|
with permissions_lock:
|
||||||
global permissions
|
global permissions
|
||||||
log.debug('permissions.resetPermissions: old perm list: %s', permissions)
|
log.debug('permissions.reset_permissions: old perm list: %s', permissions)
|
||||||
|
|
||||||
new_permissions = default_permissions.copy()
|
new_permissions = default_permissions.copy()
|
||||||
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
|
log.debug('permissions.reset_permissions: new_permissions %s', new_permissions)
|
||||||
if not conf.conf.get('permissions_merge_defaults', True):
|
if not conf.conf.get('permissions_merge_defaults', True):
|
||||||
log.debug('permissions.resetPermissions: clearing perm list due to permissions_merge_defaults set False.')
|
log.debug('permissions.reset_permissions: clearing perm list due to permissions_merge_defaults set False.')
|
||||||
new_permissions.clear()
|
new_permissions.clear()
|
||||||
|
|
||||||
# Convert all perm lists to sets.
|
# Convert all perm lists to sets.
|
||||||
for k, v in conf.conf.get('permissions', {}).items():
|
for k, v in conf.conf.get('permissions', {}).items():
|
||||||
new_permissions[k] |= set(v)
|
new_permissions[k] |= set(v)
|
||||||
|
|
||||||
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
|
log.debug('permissions.reset_permissions: new_permissions %s', new_permissions)
|
||||||
permissions.clear()
|
permissions.clear()
|
||||||
permissions.update(new_permissions)
|
permissions.update(new_permissions)
|
||||||
log.debug('permissions.resetPermissions: new perm list: %s', permissions)
|
log.debug('permissions.reset_permissions: new perm list: %s', permissions)
|
||||||
|
resetPermissions = reset_permissions
|
||||||
|
|
||||||
def addDefaultPermissions(perms):
|
def add_default_permissions(perms):
|
||||||
"""Adds default permissions to the index."""
|
"""Adds default permissions to the index."""
|
||||||
with permissions_lock:
|
with permissions_lock:
|
||||||
global default_permissions
|
global default_permissions
|
||||||
for target, permlist in perms.items():
|
for target, permlist in perms.items():
|
||||||
default_permissions[target] |= set(permlist)
|
default_permissions[target] |= set(permlist)
|
||||||
|
addDefaultPermissions = add_default_permissions
|
||||||
|
|
||||||
def removeDefaultPermissions(perms):
|
def remove_default_permissions(perms):
|
||||||
"""Remove default permissions from the index."""
|
"""Remove default permissions from the index."""
|
||||||
with permissions_lock:
|
with permissions_lock:
|
||||||
global default_permissions
|
global default_permissions
|
||||||
for target, permlist in perms.items():
|
for target, permlist in perms.items():
|
||||||
default_permissions[target] -= set(permlist)
|
default_permissions[target] -= set(permlist)
|
||||||
|
removeDefaultPermissions = remove_default_permissions
|
||||||
|
|
||||||
def checkPermissions(irc, uid, perms, also_show=[]):
|
def check_permissions(irc, uid, perms, also_show=[]):
|
||||||
"""
|
"""
|
||||||
Checks permissions of the caller. If the caller has any of the permissions listed in perms,
|
Checks permissions of the caller. If the caller has any of the permissions listed in perms,
|
||||||
this function returns True. Otherwise, NotAuthorizedError is raised.
|
this function returns True. Otherwise, NotAuthorizedError is raised.
|
||||||
@ -79,3 +82,4 @@ def checkPermissions(irc, uid, perms, also_show=[]):
|
|||||||
return True
|
return True
|
||||||
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
|
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
|
||||||
(', '.join(perms+also_show)))
|
(', '.join(perms+also_show)))
|
||||||
|
checkPermissions = check_permissions
|
||||||
|
@ -84,4 +84,4 @@ def main():
|
|||||||
world.started.set()
|
world.started.set()
|
||||||
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
|
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
|
||||||
|
|
||||||
coremods.permissions.resetPermissions() # XXX we should probably move this to run on import
|
coremods.permissions.reset_permissions() # XXX we should probably move this to run on import
|
||||||
|
@ -33,7 +33,7 @@ def main(irc=None):
|
|||||||
datastore.load()
|
datastore.load()
|
||||||
|
|
||||||
# Register our permissions.
|
# Register our permissions.
|
||||||
permissions.addDefaultPermissions(default_permissions)
|
permissions.add_default_permissions(default_permissions)
|
||||||
|
|
||||||
# Queue joins to all channels where Automode has entries.
|
# Queue joins to all channels where Automode has entries.
|
||||||
for entry in db:
|
for entry in db:
|
||||||
@ -45,7 +45,7 @@ def main(irc=None):
|
|||||||
def die(irc=None):
|
def die(irc=None):
|
||||||
"""Saves the Automode database and quit."""
|
"""Saves the Automode database and quit."""
|
||||||
datastore.die()
|
datastore.die()
|
||||||
permissions.removeDefaultPermissions(default_permissions)
|
permissions.remove_default_permissions(default_permissions)
|
||||||
utils.unregisterService('automode')
|
utils.unregisterService('automode')
|
||||||
|
|
||||||
def _check_automode_access(irc, uid, channel, command):
|
def _check_automode_access(irc, uid, channel, command):
|
||||||
@ -64,12 +64,12 @@ def _check_automode_access(irc, uid, channel, command):
|
|||||||
try:
|
try:
|
||||||
# First, check the catch all and channel permissions.
|
# First, check the catch all and channel permissions.
|
||||||
perms = [baseperm, baseperm+'.*', '%s.%s' % (baseperm, channel)]
|
perms = [baseperm, baseperm+'.*', '%s.%s' % (baseperm, channel)]
|
||||||
return permissions.checkPermissions(irc, uid, perms)
|
return permissions.check_permissions(irc, uid, perms)
|
||||||
except utils.NotAuthorizedError:
|
except utils.NotAuthorizedError:
|
||||||
if not command.startswith('remote'):
|
if not command.startswith('remote'):
|
||||||
# Relay-based ACL checking only works with local calls.
|
# Relay-based ACL checking only works with local calls.
|
||||||
log.debug('(%s) Automode: falling back to automode.%s.relay_owned', irc.name, command)
|
log.debug('(%s) Automode: falling back to automode.%s.relay_owned', irc.name, command)
|
||||||
permissions.checkPermissions(irc, uid, [baseperm+'.relay_owned'], also_show=perms)
|
permissions.check_permissions(irc, uid, [baseperm+'.relay_owned'], also_show=perms)
|
||||||
|
|
||||||
relay = world.plugins.get('relay')
|
relay = world.plugins.get('relay')
|
||||||
if relay is None:
|
if relay is None:
|
||||||
@ -280,7 +280,7 @@ def save(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Saves the Automode database to disk."""
|
Saves the Automode database to disk."""
|
||||||
permissions.checkPermissions(irc, source, ['automode.savedb'])
|
permissions.check_permissions(irc, source, ['automode.savedb'])
|
||||||
datastore.save()
|
datastore.save()
|
||||||
reply(irc, 'Done.')
|
reply(irc, 'Done.')
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ def spawnclient(irc, source, args):
|
|||||||
|
|
||||||
Spawns the specified client on the PyLink server.
|
Spawns the specified client on the PyLink server.
|
||||||
Note: this doesn't check the validity of any fields you give it!"""
|
Note: this doesn't check the validity of any fields you give it!"""
|
||||||
permissions.checkPermissions(irc, source, ['bots.spawnclient'])
|
permissions.check_permissions(irc, source, ['bots.spawnclient'])
|
||||||
try:
|
try:
|
||||||
nick, ident, host = args[:3]
|
nick, ident, host = args[:3]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -26,7 +26,7 @@ def quit(irc, source, args):
|
|||||||
"""<target> [<reason>]
|
"""<target> [<reason>]
|
||||||
|
|
||||||
Quits the PyLink client with nick <target>, if one exists."""
|
Quits the PyLink client with nick <target>, if one exists."""
|
||||||
permissions.checkPermissions(irc, source, ['bots.quit'])
|
permissions.check_permissions(irc, source, ['bots.quit'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nick = args[0]
|
nick = args[0]
|
||||||
@ -59,7 +59,7 @@ def joinclient(irc, source, args):
|
|||||||
For the channel arguments, prefixes can also be specified to join the given client with
|
For the channel arguments, prefixes can also be specified to join the given client with
|
||||||
(e.g. @#channel will join the client with op, while ~@#channel will join it with +qo.
|
(e.g. @#channel will join the client with op, while ~@#channel will join it with +qo.
|
||||||
"""
|
"""
|
||||||
permissions.checkPermissions(irc, source, ['bots.joinclient'])
|
permissions.check_permissions(irc, source, ['bots.joinclient'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Check if the first argument is an existing PyLink client. If it is not,
|
# Check if the first argument is an existing PyLink client. If it is not,
|
||||||
@ -117,7 +117,7 @@ def nick(irc, source, args):
|
|||||||
|
|
||||||
Changes the nick of <target>, a PyLink client, to <newnick>. If <target> is not given, it defaults to the main PyLink client."""
|
Changes the nick of <target>, a PyLink client, to <newnick>. If <target> is not given, it defaults to the main PyLink client."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['bots.nick'])
|
permissions.check_permissions(irc, source, ['bots.nick'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nick = args[0]
|
nick = args[0]
|
||||||
@ -152,7 +152,7 @@ def part(irc, source, args):
|
|||||||
"""[<target>] <channel1>,[<channel2>],... [<reason>]
|
"""[<target>] <channel1>,[<channel2>],... [<reason>]
|
||||||
|
|
||||||
Parts <target>, the nick of a PyLink client, from a comma-separated list of channels. If <target> is not given, it defaults to the main PyLink client."""
|
Parts <target>, the nick of a PyLink client, from a comma-separated list of channels. If <target> is not given, it defaults to the main PyLink client."""
|
||||||
permissions.checkPermissions(irc, source, ['bots.part'])
|
permissions.check_permissions(irc, source, ['bots.part'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nick = args[0]
|
nick = args[0]
|
||||||
@ -198,7 +198,7 @@ def msg(irc, source, args):
|
|||||||
"""[<source>] <target> <text>
|
"""[<source>] <target> <text>
|
||||||
|
|
||||||
Sends message <text> from <source>, where <source> is the nick of a PyLink client. If <source> is not given, it defaults to the main PyLink client."""
|
Sends message <text> from <source>, where <source> is the nick of a PyLink client. If <source> is not given, it defaults to the main PyLink client."""
|
||||||
permissions.checkPermissions(irc, source, ['bots.msg'])
|
permissions.check_permissions(irc, source, ['bots.msg'])
|
||||||
|
|
||||||
# Because we want the source nick to be optional, this argument parsing gets a bit tricky.
|
# Because we want the source nick to be optional, this argument parsing gets a bit tricky.
|
||||||
try:
|
try:
|
||||||
|
@ -126,7 +126,7 @@ def applyhosts(irc, sender, args):
|
|||||||
|
|
||||||
Applies all configured hosts for users on the given network, or the current network if none is specified."""
|
Applies all configured hosts for users on the given network, or the current network if none is specified."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, sender, ['changehost.applyhosts'])
|
permissions.check_permissions(irc, sender, ['changehost.applyhosts'])
|
||||||
|
|
||||||
try: # Try to get network from the command line.
|
try: # Try to get network from the command line.
|
||||||
network = world.networkobjects[args[0]]
|
network = world.networkobjects[args[0]]
|
||||||
|
@ -12,18 +12,18 @@ default_permissions = {"*!*@*": ['commands.status', 'commands.showuser', 'comman
|
|||||||
def main(irc=None):
|
def main(irc=None):
|
||||||
"""Commands plugin main function, called on plugin load."""
|
"""Commands plugin main function, called on plugin load."""
|
||||||
# Register our permissions.
|
# Register our permissions.
|
||||||
permissions.addDefaultPermissions(default_permissions)
|
permissions.add_default_permissions(default_permissions)
|
||||||
|
|
||||||
def die(irc=None):
|
def die(irc=None):
|
||||||
"""Commands plugin die function, called on plugin unload."""
|
"""Commands plugin die function, called on plugin unload."""
|
||||||
permissions.removeDefaultPermissions(default_permissions)
|
permissions.remove_default_permissions(default_permissions)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def status(irc, source, args):
|
def status(irc, source, args):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Returns your current PyLink login status."""
|
Returns your current PyLink login status."""
|
||||||
permissions.checkPermissions(irc, source, ['commands.status'])
|
permissions.check_permissions(irc, source, ['commands.status'])
|
||||||
identified = irc.users[source].account
|
identified = irc.users[source].account
|
||||||
if identified:
|
if identified:
|
||||||
irc.reply('You are identified as \x02%s\x02.' % identified)
|
irc.reply('You are identified as \x02%s\x02.' % identified)
|
||||||
@ -37,7 +37,7 @@ def showuser(irc, source, args):
|
|||||||
"""<user>
|
"""<user>
|
||||||
|
|
||||||
Shows information about <user>."""
|
Shows information about <user>."""
|
||||||
permissions.checkPermissions(irc, source, ['commands.showuser'])
|
permissions.check_permissions(irc, source, ['commands.showuser'])
|
||||||
try:
|
try:
|
||||||
target = args[0]
|
target = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -81,7 +81,7 @@ def showchan(irc, source, args):
|
|||||||
"""<channel>
|
"""<channel>
|
||||||
|
|
||||||
Shows information about <channel>."""
|
Shows information about <channel>."""
|
||||||
permissions.checkPermissions(irc, source, ['commands.showchan'])
|
permissions.check_permissions(irc, source, ['commands.showchan'])
|
||||||
try:
|
try:
|
||||||
channel = irc.to_lower(args[0])
|
channel = irc.to_lower(args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -142,7 +142,7 @@ def echo(irc, source, args):
|
|||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Echoes the text given."""
|
Echoes the text given."""
|
||||||
permissions.checkPermissions(irc, source, ['commands.echo'])
|
permissions.check_permissions(irc, source, ['commands.echo'])
|
||||||
irc.reply(' '.join(args))
|
irc.reply(' '.join(args))
|
||||||
|
|
||||||
def _check_logout_access(irc, source, target, perms):
|
def _check_logout_access(irc, source, target, perms):
|
||||||
@ -154,7 +154,7 @@ def _check_logout_access(irc, source, target, perms):
|
|||||||
assert source in irc.users, "Unknown source user"
|
assert source in irc.users, "Unknown source user"
|
||||||
assert target in irc.users, "Unknown target user"
|
assert target in irc.users, "Unknown target user"
|
||||||
try:
|
try:
|
||||||
permissions.checkPermissions(irc, source, perms)
|
permissions.check_permissions(irc, source, perms)
|
||||||
except utils.NotAuthorizedError:
|
except utils.NotAuthorizedError:
|
||||||
if irc.users[source].account and (irc.users[source].account == irc.users[target].account):
|
if irc.users[source].account and (irc.users[source].account == irc.users[target].account):
|
||||||
return True
|
return True
|
||||||
@ -200,7 +200,7 @@ def loglevel(irc, source, args):
|
|||||||
|
|
||||||
Sets the log level to the given <level>. <level> must be either DEBUG, INFO, WARNING, ERROR, or CRITICAL.
|
Sets the log level to the given <level>. <level> must be either DEBUG, INFO, WARNING, ERROR, or CRITICAL.
|
||||||
If no log level is given, shows the current one."""
|
If no log level is given, shows the current one."""
|
||||||
permissions.checkPermissions(irc, source, ['commands.loglevel'])
|
permissions.check_permissions(irc, source, ['commands.loglevel'])
|
||||||
try:
|
try:
|
||||||
level = args[0].upper()
|
level = args[0].upper()
|
||||||
try:
|
try:
|
||||||
|
@ -25,7 +25,7 @@ def _exec(irc, source, args, locals_dict=None):
|
|||||||
Admin-only. Executes <code> in the current PyLink instance. This command performs backslash escaping of characters, so things like \\n and \\ will work.
|
Admin-only. Executes <code> in the current PyLink instance. This command performs backslash escaping of characters, so things like \\n and \\ will work.
|
||||||
|
|
||||||
\x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02"""
|
\x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02"""
|
||||||
permissions.checkPermissions(irc, source, ['exec.exec'])
|
permissions.check_permissions(irc, source, ['exec.exec'])
|
||||||
|
|
||||||
# Allow using \n in the code, while escaping backslashes correctly otherwise.
|
# Allow using \n in the code, while escaping backslashes correctly otherwise.
|
||||||
args = bytes(' '.join(args), 'utf-8').decode("unicode_escape")
|
args = bytes(' '.join(args), 'utf-8').decode("unicode_escape")
|
||||||
@ -69,7 +69,7 @@ def _eval(irc, source, args, locals_dict=None, pretty_print=False):
|
|||||||
Admin-only. Evaluates the given Python expression and returns the result.
|
Admin-only. Evaluates the given Python expression and returns the result.
|
||||||
|
|
||||||
\x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02"""
|
\x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02"""
|
||||||
permissions.checkPermissions(irc, source, ['exec.eval'])
|
permissions.check_permissions(irc, source, ['exec.eval'])
|
||||||
|
|
||||||
args = ' '.join(args)
|
args = ' '.join(args)
|
||||||
if not args.strip():
|
if not args.strip():
|
||||||
@ -142,7 +142,7 @@ def raw(irc, source, args):
|
|||||||
Admin-only. Sends raw text to the uplink IRC server.
|
Admin-only. Sends raw text to the uplink IRC server.
|
||||||
|
|
||||||
\x02**WARNING: THIS CAN BREAK YOUR NETWORK IF USED IMPROPERLY!**\x02"""
|
\x02**WARNING: THIS CAN BREAK YOUR NETWORK IF USED IMPROPERLY!**\x02"""
|
||||||
permissions.checkPermissions(irc, source, ['exec.raw'])
|
permissions.check_permissions(irc, source, ['exec.raw'])
|
||||||
|
|
||||||
args = ' '.join(args)
|
args = ' '.join(args)
|
||||||
if not args.strip():
|
if not args.strip():
|
||||||
@ -162,7 +162,7 @@ def inject(irc, source, args):
|
|||||||
Admin-only. Injects raw text into the running PyLink protocol module, replying with the hook data returned.
|
Admin-only. Injects raw text into the running PyLink protocol module, replying with the hook data returned.
|
||||||
|
|
||||||
\x02**WARNING: THIS CAN BREAK YOUR NETWORK IF USED IMPROPERLY!**\x02"""
|
\x02**WARNING: THIS CAN BREAK YOUR NETWORK IF USED IMPROPERLY!**\x02"""
|
||||||
permissions.checkPermissions(irc, source, ['exec.inject'])
|
permissions.check_permissions(irc, source, ['exec.inject'])
|
||||||
|
|
||||||
args = ' '.join(args)
|
args = ' '.join(args)
|
||||||
if not args.strip():
|
if not args.strip():
|
||||||
|
@ -13,7 +13,7 @@ def g(irc, source, args):
|
|||||||
|
|
||||||
Sends out a Instance-wide notice.
|
Sends out a Instance-wide notice.
|
||||||
"""
|
"""
|
||||||
permissions.checkPermissions(irc, source, ["global.global"])
|
permissions.check_permissions(irc, source, ["global.global"])
|
||||||
message = " ".join(args)
|
message = " ".join(args)
|
||||||
template = string.Template(conf.conf.get('global', {}).get("format", DEFAULT_FORMAT))
|
template = string.Template(conf.conf.get('global', {}).get("format", DEFAULT_FORMAT))
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ def disconnect(irc, source, args):
|
|||||||
Disconnects the network <network>. When all networks are disconnected, PyLink will automatically exit.
|
Disconnects the network <network>. When all networks are disconnected, PyLink will automatically exit.
|
||||||
|
|
||||||
To reconnect a network disconnected using this command, use REHASH to reload the networks list."""
|
To reconnect a network disconnected using this command, use REHASH to reload the networks list."""
|
||||||
permissions.checkPermissions(irc, source, ['networks.disconnect'])
|
permissions.check_permissions(irc, source, ['networks.disconnect'])
|
||||||
try:
|
try:
|
||||||
netname = args[0]
|
netname = args[0]
|
||||||
network = world.networkobjects[netname]
|
network = world.networkobjects[netname]
|
||||||
@ -37,7 +37,7 @@ def autoconnect(irc, source, args):
|
|||||||
|
|
||||||
Sets the autoconnect time for <network> to <seconds>.
|
Sets the autoconnect time for <network> to <seconds>.
|
||||||
You can disable autoconnect for a network by setting <seconds> to a negative value."""
|
You can disable autoconnect for a network by setting <seconds> to a negative value."""
|
||||||
permissions.checkPermissions(irc, source, ['networks.autoconnect'])
|
permissions.check_permissions(irc, source, ['networks.autoconnect'])
|
||||||
try:
|
try:
|
||||||
netname = args[0]
|
netname = args[0]
|
||||||
seconds = float(args[1])
|
seconds = float(args[1])
|
||||||
@ -64,7 +64,7 @@ def remote(irc, source, args):
|
|||||||
|
|
||||||
Runs <command> on the remote network <network>. Plugin responses sent using irc.reply() are
|
Runs <command> on the remote network <network>. Plugin responses sent using irc.reply() are
|
||||||
supported and returned here, but others are dropped due to protocol limitations."""
|
supported and returned here, but others are dropped due to protocol limitations."""
|
||||||
permissions.checkPermissions(irc, source, ['networks.remote'])
|
permissions.check_permissions(irc, source, ['networks.remote'])
|
||||||
|
|
||||||
args = remote_parser.parse_args(args)
|
args = remote_parser.parse_args(args)
|
||||||
netname = args.network
|
netname = args.network
|
||||||
@ -151,7 +151,7 @@ def reloadproto(irc, source, args):
|
|||||||
"""<protocol module name>
|
"""<protocol module name>
|
||||||
|
|
||||||
Reloads the given protocol module without restart. You will have to manually disconnect and reconnect any network using the module for changes to apply."""
|
Reloads the given protocol module without restart. You will have to manually disconnect and reconnect any network using the module for changes to apply."""
|
||||||
permissions.checkPermissions(irc, source, ['networks.reloadproto'])
|
permissions.check_permissions(irc, source, ['networks.reloadproto'])
|
||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -36,7 +36,7 @@ def checkban(irc, source, args):
|
|||||||
include users in the given channel.
|
include users in the given channel.
|
||||||
|
|
||||||
The --maxresults option configures how many responses will be shown."""
|
The --maxresults option configures how many responses will be shown."""
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.checkban'])
|
permissions.check_permissions(irc, source, ['opercmds.checkban'])
|
||||||
|
|
||||||
args = checkban_parser.parse_args(args)
|
args = checkban_parser.parse_args(args)
|
||||||
if not args.target:
|
if not args.target:
|
||||||
@ -79,7 +79,7 @@ def jupe(irc, source, args):
|
|||||||
|
|
||||||
Jupes the given server."""
|
Jupes the given server."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.jupe'])
|
permissions.check_permissions(irc, source, ['opercmds.jupe'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
servername = args[0]
|
servername = args[0]
|
||||||
@ -106,7 +106,7 @@ def kick(irc, source, args):
|
|||||||
"""<channel> <user> [<reason>]
|
"""<channel> <user> [<reason>]
|
||||||
|
|
||||||
Kicks <user> from the specified channel."""
|
Kicks <user> from the specified channel."""
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.kick'])
|
permissions.check_permissions(irc, source, ['opercmds.kick'])
|
||||||
try:
|
try:
|
||||||
channel = irc.to_lower(args[0])
|
channel = irc.to_lower(args[0])
|
||||||
target = args[1]
|
target = args[1]
|
||||||
@ -137,7 +137,7 @@ def kill(irc, source, args):
|
|||||||
"""<target> [<reason>]
|
"""<target> [<reason>]
|
||||||
|
|
||||||
Kills the given target."""
|
Kills the given target."""
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.kill'])
|
permissions.check_permissions(irc, source, ['opercmds.kill'])
|
||||||
try:
|
try:
|
||||||
target = args[0]
|
target = args[0]
|
||||||
reason = ' '.join(args[1:])
|
reason = ' '.join(args[1:])
|
||||||
@ -170,7 +170,7 @@ def mode(irc, source, args):
|
|||||||
|
|
||||||
Sets the given modes on the target channel."""
|
Sets the given modes on the target channel."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.mode'])
|
permissions.check_permissions(irc, source, ['opercmds.mode'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
target, modes = args[0], args[1:]
|
target, modes = args[0], args[1:]
|
||||||
@ -208,7 +208,7 @@ def topic(irc, source, args):
|
|||||||
"""<channel> <topic>
|
"""<channel> <topic>
|
||||||
|
|
||||||
Changes the topic in a channel."""
|
Changes the topic in a channel."""
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.topic'])
|
permissions.check_permissions(irc, source, ['opercmds.topic'])
|
||||||
try:
|
try:
|
||||||
channel = args[0]
|
channel = args[0]
|
||||||
topic = ' '.join(args[1:])
|
topic = ' '.join(args[1:])
|
||||||
@ -249,7 +249,7 @@ def chgname(irc, source, args):
|
|||||||
chgfield(irc, source, args, 'name', 'GECOS')
|
chgfield(irc, source, args, 'name', 'GECOS')
|
||||||
|
|
||||||
def chgfield(irc, source, args, human_field, internal_field=None):
|
def chgfield(irc, source, args, human_field, internal_field=None):
|
||||||
permissions.checkPermissions(irc, source, ['opercmds.chg' + human_field])
|
permissions.check_permissions(irc, source, ['opercmds.chg' + human_field])
|
||||||
try:
|
try:
|
||||||
target = args[0]
|
target = args[0]
|
||||||
new = args[1]
|
new = args[1]
|
||||||
|
@ -52,7 +52,7 @@ def main(irc=None):
|
|||||||
log.debug('relay.main: loading links database')
|
log.debug('relay.main: loading links database')
|
||||||
datastore.load()
|
datastore.load()
|
||||||
|
|
||||||
permissions.addDefaultPermissions(default_permissions)
|
permissions.add_default_permissions(default_permissions)
|
||||||
|
|
||||||
if irc is not None:
|
if irc is not None:
|
||||||
# irc is defined when the plugin is reloaded. Otherwise, it means that we've just started the
|
# irc is defined when the plugin is reloaded. Otherwise, it means that we've just started the
|
||||||
@ -79,7 +79,7 @@ def die(irc=None):
|
|||||||
relayusers.clear()
|
relayusers.clear()
|
||||||
|
|
||||||
# 3) Unload our permissions.
|
# 3) Unload our permissions.
|
||||||
permissions.removeDefaultPermissions(default_permissions)
|
permissions.remove_default_permissions(default_permissions)
|
||||||
|
|
||||||
# 4) Save the database and quit.
|
# 4) Save the database and quit.
|
||||||
datastore.die()
|
datastore.die()
|
||||||
@ -1626,7 +1626,7 @@ def create(irc, source, args):
|
|||||||
irc.error('You must be in %r to complete this operation.' % channel)
|
irc.error('You must be in %r to complete this operation.' % channel)
|
||||||
return
|
return
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.create'])
|
permissions.check_permissions(irc, source, ['relay.create'])
|
||||||
|
|
||||||
# Check to see whether the channel requested is already part of a different
|
# Check to see whether the channel requested is already part of a different
|
||||||
# relay.
|
# relay.
|
||||||
@ -1676,9 +1676,9 @@ def destroy(irc, source, args):
|
|||||||
# Check for different permissions based on whether we're destroying a local channel or
|
# Check for different permissions based on whether we're destroying a local channel or
|
||||||
# a remote one.
|
# a remote one.
|
||||||
if network == irc.name:
|
if network == irc.name:
|
||||||
permissions.checkPermissions(irc, source, ['relay.destroy'])
|
permissions.check_permissions(irc, source, ['relay.destroy'])
|
||||||
else:
|
else:
|
||||||
permissions.checkPermissions(irc, source, ['relay.destroy.remote'])
|
permissions.check_permissions(irc, source, ['relay.destroy.remote'])
|
||||||
|
|
||||||
entry = (network, channel)
|
entry = (network, channel)
|
||||||
if entry in db:
|
if entry in db:
|
||||||
@ -1699,7 +1699,7 @@ def purge(irc, source, args):
|
|||||||
"""<network>
|
"""<network>
|
||||||
|
|
||||||
Destroys all links relating to the target network."""
|
Destroys all links relating to the target network."""
|
||||||
permissions.checkPermissions(irc, source, ['relay.purge'])
|
permissions.check_permissions(irc, source, ['relay.purge'])
|
||||||
try:
|
try:
|
||||||
network = args[0]
|
network = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -1771,7 +1771,7 @@ def link(irc, source, args):
|
|||||||
irc.error('You must be in %r to complete this operation.' % localchan)
|
irc.error('You must be in %r to complete this operation.' % localchan)
|
||||||
return
|
return
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.link'])
|
permissions.check_permissions(irc, source, ['relay.link'])
|
||||||
|
|
||||||
if remotenet not in world.networkobjects:
|
if remotenet not in world.networkobjects:
|
||||||
irc.error('No network named %r exists.' % remotenet)
|
irc.error('No network named %r exists.' % remotenet)
|
||||||
@ -1798,7 +1798,7 @@ def link(irc, source, args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if args.force:
|
if args.force:
|
||||||
permissions.checkPermissions(irc, source, ['relay.link.force'])
|
permissions.check_permissions(irc, source, ['relay.link.force'])
|
||||||
log.info("(%s) relay: Forcing link %s%s -> %s%s", irc.name, irc.name, localchan, remotenet,
|
log.info("(%s) relay: Forcing link %s%s -> %s%s", irc.name, irc.name, localchan, remotenet,
|
||||||
args.channel)
|
args.channel)
|
||||||
else:
|
else:
|
||||||
@ -1842,7 +1842,7 @@ def delink(irc, source, args):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
remotenet = None
|
remotenet = None
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.delink'])
|
permissions.check_permissions(irc, source, ['relay.delink'])
|
||||||
|
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.error('Invalid channel %r.' % channel)
|
irc.error('Invalid channel %r.' % channel)
|
||||||
@ -1876,7 +1876,7 @@ def linked(irc, source, args):
|
|||||||
|
|
||||||
Returns a list of channels shared across PyLink Relay. If \x02network\x02 is given, filters output to channels linked to the given network."""
|
Returns a list of channels shared across PyLink Relay. If \x02network\x02 is given, filters output to channels linked to the given network."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.linked'])
|
permissions.check_permissions(irc, source, ['relay.linked'])
|
||||||
|
|
||||||
# Only show remote networks that are marked as connected.
|
# Only show remote networks that are marked as connected.
|
||||||
remote_networks = [netname for netname, ircobj in world.networkobjects.copy().items()
|
remote_networks = [netname for netname, ircobj in world.networkobjects.copy().items()
|
||||||
@ -1976,12 +1976,12 @@ def linkacl(irc, source, args):
|
|||||||
irc.error('No such relay %r exists.' % channel)
|
irc.error('No such relay %r exists.' % channel)
|
||||||
return
|
return
|
||||||
if cmd == 'list':
|
if cmd == 'list':
|
||||||
permissions.checkPermissions(irc, source, ['relay.linkacl.view'])
|
permissions.check_permissions(irc, source, ['relay.linkacl.view'])
|
||||||
s = 'Blocked networks for \x02%s\x02: \x02%s\x02' % (channel, ', '.join(db[relay]['blocked_nets']) or '(empty)')
|
s = 'Blocked networks for \x02%s\x02: \x02%s\x02' % (channel, ', '.join(db[relay]['blocked_nets']) or '(empty)')
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
return
|
return
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.linkacl'])
|
permissions.check_permissions(irc, source, ['relay.linkacl'])
|
||||||
try:
|
try:
|
||||||
remotenet = args[2]
|
remotenet = args[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -2072,7 +2072,7 @@ def save(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Saves the relay database to disk."""
|
Saves the relay database to disk."""
|
||||||
permissions.checkPermissions(irc, source, ['relay.savedb'])
|
permissions.check_permissions(irc, source, ['relay.savedb'])
|
||||||
datastore.save()
|
datastore.save()
|
||||||
irc.reply('Done.')
|
irc.reply('Done.')
|
||||||
|
|
||||||
@ -2097,7 +2097,7 @@ def claim(irc, source, args):
|
|||||||
irc.error("Not enough arguments. Needs 1-2: channel, list of networks (optional).")
|
irc.error("Not enough arguments. Needs 1-2: channel, list of networks (optional).")
|
||||||
return
|
return
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['relay.claim'])
|
permissions.check_permissions(irc, source, ['relay.claim'])
|
||||||
|
|
||||||
# We override get_relay() here to limit the search to the current network.
|
# We override get_relay() here to limit the search to the current network.
|
||||||
relay = (irc.name, channel)
|
relay = (irc.name, channel)
|
||||||
|
@ -14,7 +14,7 @@ def _map(irc, source, args, show_relay=True):
|
|||||||
|
|
||||||
Shows the network map for the given network, or the current network if not specified."""
|
Shows the network map for the given network, or the current network if not specified."""
|
||||||
|
|
||||||
permissions.checkPermissions(irc, source, ['servermaps.map'])
|
permissions.check_permissions(irc, source, ['servermaps.map'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
netname = args[0]
|
netname = args[0]
|
||||||
|
@ -32,7 +32,7 @@ def uptime(irc, source, args):
|
|||||||
|
|
||||||
Returns the uptime for PyLink and the given network's connection (or the current network if not specified).
|
Returns the uptime for PyLink and the given network's connection (or the current network if not specified).
|
||||||
The --all argument can also be given to show the uptime for all networks."""
|
The --all argument can also be given to show the uptime for all networks."""
|
||||||
permissions.checkPermissions(irc, source, ['stats.uptime'])
|
permissions.check_permissions(irc, source, ['stats.uptime'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
network = args[0]
|
network = args[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user