3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-23 19:19:31 +01:00

commands: add a 'shownet' command

Basic info available to everyone include network name, protocol module, and encoding.

For those with the commands.shownet.extended permission, this also allows looking up disconnected networks defined in the config, and shows configured IP:port, PyLink hostname, SID, and SID range.

Closes #578.
This commit is contained in:
James Lu 2019-06-26 13:46:04 -07:00
parent 37822fda42
commit 19c7dce931
2 changed files with 73 additions and 2 deletions

View File

@ -52,6 +52,8 @@ Remote versions of the `manage`, `list`, `sync`, and `clear` commands also exist
- `commands.loglevel` - Grants access to the `loglevel` command.
- `commands.logout.force` - Allows forcing logouts on other users via the `logout` command.
- `commands.showchan` - Grants access to the `showchan` command. **With the default permissions set, this is granted to all users.**
- `commands.shownet` - Grants access to the `shownet` command (basic info including netname, protocol module, and encoding). **With the default permissions set, this is granted to all users.**
- `commands.shownet.extended` - Grants access to extended info in `shownet`, including connected status, target IP:port, and configured PyLink hostname / SID.
- `commands.showuser` - Grants access to the `showuser` command. **With the default permissions set, this is granted to all users.**
- `commands.status` - Grants access to the `status` command. **With the default permissions set, this is granted to all users.**

View File

@ -1,13 +1,13 @@
# commands.py: base PyLink commands
import time
from pylinkirc import utils, __version__, world, real_version
from pylinkirc import conf, utils, __version__, world, real_version
from pylinkirc.log import log
from pylinkirc.coremods import permissions
from pylinkirc.coremods.login import pwd_context
default_permissions = {"*!*@*": ['commands.status', 'commands.showuser', 'commands.showchan']}
default_permissions = {"*!*@*": ['commands.status', 'commands.showuser', 'commands.showchan', 'commands.shownet']}
def main(irc=None):
"""Commands plugin main function, called on plugin load."""
@ -123,6 +123,75 @@ def showuser(irc, source, args):
for user in users:
_do_showuser(irc, source, user)
@utils.add_cmd
def shownet(irc, source, args):
"""[<network name>]
Shows information about <network name>, or the current network if no argument is given."""
permissions.check_permissions(irc, source, ['commands.shownet'])
try:
extended = permissions.check_permissions(irc, source, ['commands.shownet.extended'])
except utils.NotAuthorizedError:
extended = False
try:
target = args[0]
except IndexError:
target = irc.name
try:
netobj = world.networkobjects[target]
serverdata = netobj.serverdata
except KeyError:
netobj = None
# If we have extended access, also look for disconnected networks
if extended and target in conf.conf['servers']:
serverdata = conf.conf['servers'][target]
else:
irc.error('Unknown network %r' % target)
return
# Get extended protocol details: IRCd type, virtual server info
protocol_name = serverdata.get('protocol')
ircd_type = None
# A bit of hardcoding here :(
if protocol_name == 'ts6':
ircd_type = serverdata.get('ircd', 'charybdis[default]')
elif protocol_name == 'inspircd':
ircd_type = serverdata.get('target_version', 'insp20[default]')
elif protocol_name == 'p10':
ircd_type = serverdata.get('ircd') or serverdata.get('p10_ircd') or 'nefarious[default]'
if protocol_name and ircd_type:
protocol_name = '%s/%s' % (protocol_name, ircd_type)
elif netobj and not protocol_name: # Show virtual server detail if applicable
try:
parent_name = netobj.virtual_parent.name
except AttributeError:
parent_name = None
protocol_name = 'none; virtual server defined by \x02%s\x02' % parent_name
irc.reply('Information on network \x02%s\x02: \x02%s\x02' %
(target, netobj.get_full_network_name() if netobj else '\x1dCurrently not connected\x1d'))
irc.reply('\x02PyLink protocol module\x02: %s; \x02Encoding\x02: %s' %
(protocol_name, netobj.encoding if netobj else serverdata.get('encoding', 'utf-8[default]')))
# Extended info: target host, defined hostname / SID
if extended:
connected = netobj and netobj.connected.is_set()
irc.reply('\x02Connected?\x02 %s' % ('\x0303true' if connected else '\x0304false'))
if serverdata.get('ip'):
irc.reply('\x02Server target\x02: \x1f%s:%s' % (serverdata['ip'], serverdata.get('port')))
if serverdata.get('hostname'):
irc.reply('\x02PyLink hostname\x02: %s; \x02SID:\x02 %s; \x02SID range:\x02 %s' %
(serverdata.get('hostname') or _none,
serverdata.get('sid') or _none,
serverdata.get('sidrange') or _none))
@utils.add_cmd
def showchan(irc, source, args):
"""<channel>