mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Log command usage, 'exec' usage, successful logins, and access denied to commands in admin.py
Closes #66.
This commit is contained in:
parent
1b09a00ea9
commit
57e9bf601e
@ -29,9 +29,10 @@ def handle_commands(irc, source, command, args):
|
||||
utils.msg(irc, source, 'Unknown command %r.' % cmd)
|
||||
return
|
||||
try:
|
||||
log.info('(%s) Calling command %r for %s', irc.name, cmd, utils.getHostmask(irc, source))
|
||||
func(irc, source, cmd_args)
|
||||
except Exception as e:
|
||||
log.exception('Unhandled exception caught in command %r' % cmd)
|
||||
log.exception('Unhandled exception caught in command %r', cmd)
|
||||
utils.msg(irc, source, 'Uncaught exception in command %r: %s: %s' % (cmd, type(e).__name__, str(e)))
|
||||
return
|
||||
utils.add_hook(handle_commands, 'PRIVMSG')
|
||||
|
@ -1,13 +1,20 @@
|
||||
# admin.py: PyLink administrative commands
|
||||
import sys, os
|
||||
import sys
|
||||
import os
|
||||
import inspect
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import utils
|
||||
from log import log
|
||||
|
||||
class NotAuthenticatedError(Exception):
|
||||
pass
|
||||
|
||||
def checkauthenticated(irc, source):
|
||||
lastfunc = inspect.stack()[1][3]
|
||||
if not irc.users[source].identified:
|
||||
log.warning('(%s) Access denied for %s calling %r', irc.name,
|
||||
utils.getHostmask(irc, source), lastfunc)
|
||||
raise NotAuthenticatedError("You are not authenticated!")
|
||||
|
||||
def _exec(irc, source, args):
|
||||
@ -20,6 +27,7 @@ def _exec(irc, source, args):
|
||||
if not args.strip():
|
||||
utils.msg(irc, source, 'No code entered!')
|
||||
return
|
||||
log.info('(%s) Executing %r for %s', irc.name, args, utils.getHostmask(irc, source))
|
||||
exec(args, globals(), locals())
|
||||
utils.add_cmd(_exec, 'exec')
|
||||
|
||||
|
@ -34,11 +34,13 @@ def identify(irc, source, args):
|
||||
realuser = conf['login']['user']
|
||||
irc.users[source].identified = realuser
|
||||
utils.msg(irc, source, 'Successfully logged in as %s.' % realuser)
|
||||
log.info("(%s) Successful login to %r by %s.",
|
||||
irc.name, username, utils.getHostmask(irc, source))
|
||||
else:
|
||||
utils.msg(irc, source, 'Incorrect credentials.')
|
||||
u = irc.users[source]
|
||||
log.warning("(%s) Failed login to %r from user '%s!%s@%s' (UID %r).",
|
||||
irc.name, username, u.nick, u.ident, u.host, u.uid)
|
||||
log.warning("(%s) Failed login to %r from %s.",
|
||||
irc.name, username, utils.getHostmask(irc, source))
|
||||
|
||||
def listcommands(irc, source, args):
|
||||
"""takes no arguments.
|
||||
|
@ -95,5 +95,6 @@ class TestUtils(unittest.TestCase):
|
||||
('-m', None), ('+k', 'hello'),
|
||||
('+b', '*!*@*.badisp.net')])
|
||||
self.assertEqual(res, '-o+l-nm+kb 9PYAAAAAA 50 hello *!*@*.badisp.net')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user