2005-01-19 14:14:38 +01:00
|
|
|
###
|
2005-01-19 14:33:05 +01:00
|
|
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2009, James McCoy
|
2005-01-19 14:14:38 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
|
|
|
|
import supybot.log as log
|
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.world as world
|
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
from supybot.commands import *
|
2005-01-31 16:22:48 +01:00
|
|
|
from supybot.utils.iter import all
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-16 13:51:27 +02:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('Config')
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
###
|
|
|
|
# Now, to setup the registry.
|
|
|
|
###
|
|
|
|
|
|
|
|
def getWrapper(name):
|
|
|
|
parts = registry.split(name)
|
|
|
|
if not parts or parts[0] not in ('supybot', 'users'):
|
2014-03-05 14:14:36 +01:00
|
|
|
raise registry.InvalidRegistryName(name)
|
2005-01-19 14:14:38 +01:00
|
|
|
group = getattr(conf, parts.pop(0))
|
|
|
|
while parts:
|
2014-05-31 20:44:56 +02:00
|
|
|
part = parts.pop(0)
|
|
|
|
if group.__hasattr__(part):
|
|
|
|
group = group.get(part)
|
|
|
|
else:
|
|
|
|
# We'll raise registry.InvalidRegistryName here so
|
|
|
|
# that we have a useful error message for the user.
|
2014-01-20 15:43:55 +01:00
|
|
|
raise registry.InvalidRegistryName(name)
|
2005-01-19 14:14:38 +01:00
|
|
|
return group
|
|
|
|
|
2019-08-04 18:11:28 +02:00
|
|
|
def getCapability(irc, name):
|
2005-01-19 14:14:38 +01:00
|
|
|
capability = 'owner' # Default to requiring the owner capability.
|
2018-02-06 14:20:37 +01:00
|
|
|
if not name.startswith('supybot') and not name.startswith('users'):
|
|
|
|
name = 'supybot.' + name
|
2005-01-19 14:14:38 +01:00
|
|
|
parts = registry.split(name)
|
2018-02-06 14:20:37 +01:00
|
|
|
group = getattr(conf, parts.pop(0))
|
2005-01-19 14:14:38 +01:00
|
|
|
while parts:
|
2018-02-06 14:20:37 +01:00
|
|
|
part = parts.pop(0)
|
|
|
|
group = group.get(part)
|
|
|
|
if not getattr(group, '_opSettable', True):
|
|
|
|
return 'owner'
|
2019-08-04 18:11:28 +02:00
|
|
|
if irc.isChannel(part):
|
2009-08-16 23:17:05 +02:00
|
|
|
# If a registry value has a channel in it, it requires a
|
|
|
|
# 'channel,op' capability, or so we assume. We'll see if we're
|
|
|
|
# proven wrong.
|
2005-01-19 14:14:38 +01:00
|
|
|
capability = ircdb.makeChannelCapability(part, 'op')
|
|
|
|
### Do more later, for specific capabilities/sections.
|
|
|
|
return capability
|
|
|
|
|
2017-09-24 21:11:21 +02:00
|
|
|
def isReadOnly(name):
|
|
|
|
"""Prevents changing certain config variables to gain shell access via
|
|
|
|
a vulnerable IRC network."""
|
|
|
|
parts = registry.split(name.lower())
|
|
|
|
if parts[0] != 'supybot':
|
|
|
|
parts.insert(0, 'supybot')
|
|
|
|
if parts == ['supybot', 'commands', 'allowshell'] and \
|
|
|
|
not conf.supybot.commands.allowShell():
|
|
|
|
# allow setting supybot.commands.allowShell from True to False,
|
|
|
|
# but not from False to True.
|
|
|
|
# Otherwise an IRC network could overwrite it.
|
|
|
|
return True
|
|
|
|
elif parts[0:2] == ['supybot', 'directories'] and \
|
|
|
|
not conf.supybot.commands.allowShell():
|
|
|
|
# Setting plugins directory allows for arbitrary code execution if
|
|
|
|
# an attacker can both use the IRC network to MITM and upload files
|
|
|
|
# on the server (eg. with a web CMS).
|
|
|
|
# Setting other directories allows writing data at arbitrary
|
|
|
|
# locations.
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
def _reload():
|
|
|
|
ircdb.users.reload()
|
2005-08-10 13:40:24 +02:00
|
|
|
ircdb.ignores.reload()
|
2005-01-19 14:14:38 +01:00
|
|
|
ircdb.channels.reload()
|
2012-09-07 19:20:09 +02:00
|
|
|
registry.open_registry(world.registryFilename)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def _hupHandler(sig, frame):
|
|
|
|
log.info('Received SIGHUP, reloading configuration.')
|
|
|
|
_reload()
|
|
|
|
|
|
|
|
if os.name == 'posix':
|
|
|
|
signal.signal(signal.SIGHUP, _hupHandler)
|
|
|
|
|
|
|
|
def getConfigVar(irc, msg, args, state):
|
|
|
|
name = args[0]
|
|
|
|
if name.startswith('conf.'):
|
|
|
|
name = name[5:]
|
|
|
|
if not name.startswith('supybot') and not name.startswith('users'):
|
|
|
|
name = 'supybot.' + name
|
|
|
|
try:
|
|
|
|
group = getWrapper(name)
|
|
|
|
state.args.append(group)
|
|
|
|
del args[0]
|
2014-01-20 15:49:15 +01:00
|
|
|
except registry.InvalidRegistryName as e:
|
2010-12-12 15:03:13 +01:00
|
|
|
state.errorInvalid(_('configuration variable'), str(e))
|
2005-01-19 14:14:38 +01:00
|
|
|
addConverter('configVar', getConfigVar)
|
|
|
|
|
2009-01-28 06:31:36 +01:00
|
|
|
def getSettableConfigVar(irc, msg, args, state):
|
|
|
|
getConfigVar(irc, msg, args, state)
|
|
|
|
if not hasattr(state.args[-1], 'set'):
|
2010-12-12 15:03:13 +01:00
|
|
|
state.errorInvalid(_('settable configuration variable'),
|
2009-01-28 06:31:36 +01:00
|
|
|
state.args[-1]._name)
|
|
|
|
addConverter('settableConfigVar', getSettableConfigVar)
|
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class Config(callbacks.Plugin):
|
2014-11-30 08:18:44 +01:00
|
|
|
"""Provides access to the Supybot configuration. This is
|
|
|
|
a core Supybot plugin that should not be removed!"""
|
2005-02-17 23:39:44 +01:00
|
|
|
def callCommand(self, command, irc, msg, *args, **kwargs):
|
2005-01-19 14:14:38 +01:00
|
|
|
try:
|
2005-02-17 23:39:44 +01:00
|
|
|
super(Config, self).callCommand(command, irc, msg, *args, **kwargs)
|
2014-01-20 15:49:15 +01:00
|
|
|
except registry.InvalidRegistryValue as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.error(str(e))
|
|
|
|
|
2019-08-04 18:11:28 +02:00
|
|
|
def _list(self, irc, group):
|
2005-01-19 14:14:38 +01:00
|
|
|
L = []
|
2015-08-08 22:20:14 +02:00
|
|
|
for (vname, v) in group._children.items():
|
2019-11-02 18:47:45 +01:00
|
|
|
if getattr(group, '_networkValue', False) and \
|
|
|
|
vname.startswith(':'):
|
|
|
|
# Skip pseudo-children that are network names
|
|
|
|
continue
|
|
|
|
if getattr(group, '_channelValue', False) and \
|
|
|
|
irc.isChannel(vname):
|
|
|
|
# Skip pseudo-children that are channel names
|
2005-01-19 14:14:38 +01:00
|
|
|
continue
|
2019-08-15 12:22:43 +02:00
|
|
|
if hasattr(v, '_channelValue') and v._channelValue:
|
2005-01-19 14:14:38 +01:00
|
|
|
vname = '#' + vname
|
2019-08-04 18:11:28 +02:00
|
|
|
if v._added and not all(irc.isChannel, v._added):
|
2005-01-19 14:14:38 +01:00
|
|
|
vname = '@' + vname
|
|
|
|
L.append(vname)
|
2005-02-15 14:57:57 +01:00
|
|
|
utils.sortBy(str.lower, L)
|
2005-01-19 14:14:38 +01:00
|
|
|
return L
|
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def list(self, irc, msg, args, group):
|
|
|
|
"""<group>
|
|
|
|
|
|
|
|
Returns the configuration variables available under the given
|
|
|
|
configuration <group>. If a variable has values under it, it is
|
|
|
|
preceded by an '@' sign. If a variable is a 'ChannelValue', that is,
|
|
|
|
it can be separately configured for each channel using the 'channel'
|
|
|
|
command in this plugin, it is preceded by an '#' sign.
|
|
|
|
"""
|
2019-08-04 18:11:28 +02:00
|
|
|
L = self._list(irc, group)
|
2005-01-19 14:14:38 +01:00
|
|
|
if L:
|
2005-01-31 15:52:27 +01:00
|
|
|
irc.reply(format('%L', L))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.error(_('There don\'t seem to be any values in %s.') %
|
|
|
|
group._name)
|
2005-01-19 14:14:38 +01:00
|
|
|
list = wrap(list, ['configVar'])
|
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def search(self, irc, msg, args, word):
|
|
|
|
"""<word>
|
|
|
|
|
|
|
|
Searches for <word> in the current configuration variables.
|
|
|
|
"""
|
|
|
|
L = []
|
2010-11-26 23:19:05 +01:00
|
|
|
for (name, x) in conf.supybot.getValues(getChildren=True):
|
2005-01-19 14:14:38 +01:00
|
|
|
if word in name.lower():
|
|
|
|
possibleChannel = registry.split(name)[-1]
|
2019-08-04 18:11:28 +02:00
|
|
|
if not irc.isChannel(possibleChannel):
|
2005-01-19 14:14:38 +01:00
|
|
|
L.append(name)
|
|
|
|
if L:
|
2005-01-31 15:52:27 +01:00
|
|
|
irc.reply(format('%L', L))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.reply(_('There were no matching configuration variables.'))
|
2005-01-19 14:14:38 +01:00
|
|
|
search = wrap(search, ['lowered']) # XXX compose with withoutSpaces?
|
|
|
|
|
2019-08-15 12:22:43 +02:00
|
|
|
def _getValue(self, irc, msg, group, network=None, channel=None, addGlobal=False):
|
2019-08-24 17:50:05 +02:00
|
|
|
global_group = group
|
2019-08-15 12:22:43 +02:00
|
|
|
global_value = str(group) or ' '
|
|
|
|
group = group.getSpecific(
|
2019-08-24 17:50:05 +02:00
|
|
|
network=network.network, channel=channel, check=False)
|
2005-01-19 14:14:38 +01:00
|
|
|
value = str(group) or ' '
|
2019-08-15 12:22:43 +02:00
|
|
|
if addGlobal and not irc.nested:
|
2019-08-25 14:00:11 +02:00
|
|
|
if global_group._channelValue and channel:
|
|
|
|
# TODO: also show the network value when relevant
|
|
|
|
value = _(
|
|
|
|
'Global: %(global_value)s; '
|
|
|
|
'%(channel_name)s @ %(network_name)s: %(channel_value)s') % {
|
|
|
|
'global_value': global_value,
|
|
|
|
'channel_name': msg.channel,
|
|
|
|
'network_name': irc.network,
|
|
|
|
'channel_value': value,
|
|
|
|
}
|
|
|
|
elif global_group._networkValue and network:
|
|
|
|
value = _(
|
|
|
|
'Global: %(global_value)s; '
|
|
|
|
'%(network_name)s: %(network_value)s') % {
|
|
|
|
'global_value': global_value,
|
|
|
|
'network_name': irc.network,
|
|
|
|
'network_value': value,
|
|
|
|
}
|
2019-08-24 17:50:05 +02:00
|
|
|
if hasattr(global_group, 'value'):
|
|
|
|
if not global_group._private:
|
2018-05-29 22:17:19 +02:00
|
|
|
return (value, None)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2019-08-04 18:11:28 +02:00
|
|
|
capability = getCapability(irc, group._name)
|
2005-01-19 14:14:38 +01:00
|
|
|
if ircdb.checkCapability(msg.prefix, capability):
|
2018-05-29 22:17:19 +02:00
|
|
|
return (value, True)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2018-05-29 22:17:19 +02:00
|
|
|
irc.errorNoCapability(capability, Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.error(_('That registry variable has no value. Use the list '
|
2005-01-19 14:14:38 +01:00
|
|
|
'command in this plugin to see what variables are '
|
2019-08-24 17:50:05 +02:00
|
|
|
'available in this group.'), Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def _setValue(self, irc, msg, group, value):
|
2017-09-24 21:11:21 +02:00
|
|
|
if isReadOnly(group._name):
|
2017-10-25 12:21:50 +02:00
|
|
|
irc.error(_("This configuration variable is not writeable "
|
|
|
|
"via IRC. To change it you have to: 1) use the 'flush' command 2) edit "
|
|
|
|
"the config file 3) use the 'config reload' command."), Raise=True)
|
2019-08-04 18:11:28 +02:00
|
|
|
capability = getCapability(irc, group._name)
|
2005-01-19 14:14:38 +01:00
|
|
|
if ircdb.checkCapability(msg.prefix, capability):
|
|
|
|
# I think callCommand catches exceptions here. Should it?
|
|
|
|
group.set(value)
|
|
|
|
else:
|
2018-05-29 22:17:19 +02:00
|
|
|
irc.errorNoCapability(capability, Raise=True)
|
2005-08-10 13:40:24 +02:00
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2019-08-15 12:22:43 +02:00
|
|
|
def channel(self, irc, msg, args, network, channels, group, value):
|
|
|
|
"""[<network>] [<channel>] <name> [<value>]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
If <value> is given, sets the channel configuration variable for <name>
|
2019-08-15 12:22:43 +02:00
|
|
|
to <value> for <channel> on the <network>.
|
|
|
|
Otherwise, returns the current channel
|
2005-01-19 14:14:38 +01:00
|
|
|
configuration value of <name>. <channel> is only necessary if the
|
2018-05-29 22:17:19 +02:00
|
|
|
message isn't sent in the channel itself. More than one channel may
|
2019-08-15 12:22:43 +02:00
|
|
|
be given at once by separating them with commas.
|
|
|
|
<network> defaults to the current network."""
|
|
|
|
if not group._channelValue:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.error(_('That configuration variable is not a channel-specific '
|
|
|
|
'configuration variable.'))
|
2005-01-19 14:14:38 +01:00
|
|
|
return
|
|
|
|
if value is not None:
|
2018-05-29 22:17:19 +02:00
|
|
|
for channel in channels:
|
|
|
|
assert irc.isChannel(channel)
|
2019-08-15 12:22:43 +02:00
|
|
|
|
|
|
|
# Sets the non-network-specific value, for forward
|
|
|
|
# compatibility, ie. this will work even if the owner rolls
|
|
|
|
# back Limnoria to an older version.
|
|
|
|
# It's also an easy way to support plugins which are not
|
|
|
|
# network-aware.
|
2018-05-29 22:17:19 +02:00
|
|
|
self._setValue(irc, msg, group.get(channel), value)
|
2019-08-15 12:22:43 +02:00
|
|
|
|
|
|
|
if network != '*':
|
|
|
|
# Set the network-specific value
|
|
|
|
self._setValue(irc, msg, group.get(':' + network.network).get(channel), value)
|
|
|
|
|
2018-05-29 22:17:19 +02:00
|
|
|
irc.replySuccess()
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2019-08-15 12:22:43 +02:00
|
|
|
if network == '*':
|
|
|
|
network = None
|
2018-05-29 22:17:19 +02:00
|
|
|
values = []
|
|
|
|
private = None
|
|
|
|
for channel in channels:
|
2019-08-15 12:22:43 +02:00
|
|
|
(value, private_value) = \
|
|
|
|
self._getValue(irc, msg, group, network, channel)
|
2018-05-29 22:46:56 +02:00
|
|
|
values.append((channel, value))
|
2018-05-29 22:17:19 +02:00
|
|
|
if private_value:
|
|
|
|
private = True
|
|
|
|
if len(channels) > 1:
|
2019-08-25 10:24:57 +02:00
|
|
|
irc.reply('; '.join(['%s: %s' % (channel, value)
|
|
|
|
for (channel, value) in values]),
|
|
|
|
private=private)
|
2018-05-29 22:17:19 +02:00
|
|
|
else:
|
2019-08-25 10:24:57 +02:00
|
|
|
irc.reply(values[0][1], private=private)
|
2019-08-15 12:22:43 +02:00
|
|
|
channel = wrap(channel, [optional(first(('literal', '*'), 'networkIrc')),
|
|
|
|
'channels', 'settableConfigVar',
|
2019-08-25 10:25:14 +02:00
|
|
|
additional('text')])
|
|
|
|
|
|
|
|
def network(self, irc, msg, args, network, group, value):
|
|
|
|
"""[<network>] <name> [<value>]
|
|
|
|
|
|
|
|
If <value> is given, sets the network configuration variable for <name>
|
|
|
|
to <value> for <network>.
|
|
|
|
Otherwise, returns the current network configuration value of <name>.
|
|
|
|
<network> defaults to the current network."""
|
|
|
|
if not group._networkValue:
|
|
|
|
irc.error(_('That configuration variable is not a network-specific '
|
|
|
|
'configuration variable.'))
|
|
|
|
return
|
|
|
|
if value is not None:
|
|
|
|
self._setValue(irc, msg, group.get(':' + network.network), value)
|
|
|
|
|
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
|
|
|
values = []
|
|
|
|
private = None
|
|
|
|
(value, private) = \
|
|
|
|
self._getValue(irc, msg, group, network)
|
|
|
|
irc.reply(value, private=private)
|
|
|
|
network = wrap(network, ['networkIrc', 'settableConfigVar',
|
2009-01-28 06:31:36 +01:00
|
|
|
additional('text')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def config(self, irc, msg, args, group, value):
|
|
|
|
"""<name> [<value>]
|
|
|
|
|
|
|
|
If <value> is given, sets the value of <name> to <value>. Otherwise,
|
|
|
|
returns the current value of <name>. You may omit the leading
|
|
|
|
"supybot." in the name if you so choose.
|
|
|
|
"""
|
|
|
|
if value is not None:
|
|
|
|
self._setValue(irc, msg, group, value)
|
2018-05-29 22:17:19 +02:00
|
|
|
irc.replySuccess()
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2019-08-15 12:22:43 +02:00
|
|
|
(value, private) = self._getValue(
|
|
|
|
irc, msg, group, network=irc,
|
2019-08-24 17:50:05 +02:00
|
|
|
channel=msg.channel,
|
2019-08-25 14:00:11 +02:00
|
|
|
addGlobal=group._channelValue or group._networkValue)
|
2018-05-29 22:17:19 +02:00
|
|
|
irc.reply(value, private=private)
|
2009-01-28 06:31:36 +01:00
|
|
|
config = wrap(config, ['settableConfigVar', additional('text')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def help(self, irc, msg, args, group):
|
|
|
|
"""<name>
|
|
|
|
|
|
|
|
Returns the description of the configuration variable <name>.
|
|
|
|
"""
|
|
|
|
if hasattr(group, '_help'):
|
|
|
|
s = group.help()
|
|
|
|
if s:
|
|
|
|
if hasattr(group, 'value') and not group._private:
|
2019-08-24 17:50:05 +02:00
|
|
|
if msg.channel and \
|
|
|
|
msg.channel in group._children:
|
2014-04-03 13:47:24 +02:00
|
|
|
globvalue = str(group)
|
2019-08-24 17:50:05 +02:00
|
|
|
chanvalue = str(group.get(msg.channel))
|
2014-04-03 13:47:24 +02:00
|
|
|
if chanvalue != globvalue:
|
|
|
|
s += _(' (Current global value: %s; '
|
|
|
|
'current channel value: %s)') % \
|
|
|
|
(globvalue, chanvalue)
|
|
|
|
else:
|
|
|
|
s += _(' (Current value: %s)') % group
|
|
|
|
else:
|
|
|
|
s += _(' (Current value: %s)') % group
|
2005-01-19 14:14:38 +01:00
|
|
|
irc.reply(s)
|
|
|
|
else:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.reply(_('That configuration group exists, but seems to '
|
|
|
|
'have no help. Try "config list %s" to see if it '
|
|
|
|
'has any children values.') % group._name)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2010-10-16 13:51:27 +02:00
|
|
|
irc.error(_('%s has no help.') % group._name)
|
2005-01-19 14:14:38 +01:00
|
|
|
help = wrap(help, ['configVar'])
|
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def default(self, irc, msg, args, group):
|
|
|
|
"""<name>
|
|
|
|
|
|
|
|
Returns the default value of the configuration variable <name>.
|
|
|
|
"""
|
|
|
|
v = group.__class__(group._default, '')
|
|
|
|
irc.reply(str(v))
|
2009-01-28 06:31:36 +01:00
|
|
|
default = wrap(default, ['settableConfigVar'])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def reload(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Reloads the various configuration files (user database, channel
|
|
|
|
database, registry, etc.).
|
|
|
|
"""
|
|
|
|
_reload() # This was factored out for SIGHUP handling.
|
|
|
|
irc.replySuccess()
|
|
|
|
reload = wrap(reload, [('checkCapability', 'owner')])
|
|
|
|
|
2010-10-16 13:51:27 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def export(self, irc, msg, args, filename):
|
|
|
|
"""<filename>
|
|
|
|
|
|
|
|
Exports the public variables of your configuration to <filename>.
|
|
|
|
If you want to show someone your configuration file, but you don't
|
|
|
|
want that person to be able to see things like passwords, etc., this
|
|
|
|
command will export a "sanitized" configuration file suitable for
|
|
|
|
showing publicly.
|
|
|
|
"""
|
2017-09-24 21:11:21 +02:00
|
|
|
if not conf.supybot.commands.allowShell():
|
|
|
|
# Disallow writing arbitrary files
|
|
|
|
irc.error('This command is not available, because '
|
|
|
|
'supybot.commands.allowShell is False.', Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
registry.close(conf.supybot, filename, private=False)
|
|
|
|
irc.replySuccess()
|
|
|
|
export = wrap(export, [('checkCapability', 'owner'), 'filename'])
|
|
|
|
|
2012-11-07 05:20:03 +01:00
|
|
|
@internationalizeDocstring
|
2012-11-09 23:32:01 +01:00
|
|
|
def setdefault(self, irc, msg, args, group):
|
2012-11-07 05:20:03 +01:00
|
|
|
"""<name>
|
|
|
|
|
|
|
|
Resets the configuration variable <name> to its default value.
|
|
|
|
"""
|
|
|
|
v = str(group.__class__(group._default, ''))
|
|
|
|
self._setValue(irc, msg, group, v)
|
2019-10-06 17:21:12 +02:00
|
|
|
irc.replySuccess()
|
2012-11-09 23:40:10 +01:00
|
|
|
setdefault = wrap(setdefault, ['settableConfigVar'])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
Class = Config
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|