示例#1
0
def handle_meet(bot, ievent):
    """ user-meet <nick> .. introduce a new user to the bot """
    try:
        nick = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<nick>')
        return
    if users.exist(nick):
        ievent.reply('there is already a user with username %s' % nick)
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    username = users.getname(userhost)
    if username:
        ievent.reply('we already have a user with userhost %s (%s)' % \
(userhost, username))
        return
    result = 0
    try:
        result = users.add(nick.lower(), [userhost, ], ['USER', ])
    except Exception, ex:
        ievent.reply('ERROR: %s' % str(ex))
        return
示例#2
0
def handle_merge(bot, ievent):
    """ user-merge <name> <nick> .. merge the userhost into a already \
        existing user """
    if len(ievent.args) != 2:
        ievent.missing('<name> <nick>')
        return  
    name, nick = ievent.args
    name = name.lower()
    if users.gotperm(name, 'OPER') and not users.allowed(ievent.userhost, \
'OPER'):
        ievent.reply("only OPER perm can merge with OPER user")
        return
    if name == 'owner' and not bot.ownercheck(ievent, "can merge with owner \
user"):
         return 
    if not users.exist(name):
        ievent.reply("we have no user %s" % name)
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    username = users.getname(userhost)
    if username:
        ievent.reply('we already have a user with userhost %s (%s)' % \
(userhost, username))
        return
    result = 0
    try:
        result = users.merge(name, userhost)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#3
0
def handle_addshare(bot, ievent):
    """ share a project with another user """
    username = users.getname(ievent.userhost)
    try:
        project, otheruser = ievent.rest.split(' ', 1)
    except ValueError:
        ievent.missing('<projectname> <user>')
        return
    project = project.strip().lower()
    if hascontrib(username, project):
        ievent.reply('only project owner can share a project')
        return
    if not hasproject(username, project):
        ievent.reply('no project %s' % project)
        return
    if not users.exist(otheruser):
        ievent.reply('unknown user %s' % otheruser)
        return
    if hasproject(otheruser, project) or \
    hascontrib(otheruser, project):
        ievent.reply('%s already has a project named %s' \
        % (otheruser, project))
        return
    addshare(username, project, otheruser)
    desc = getdesc(username, project) or project
    ievent.reply('sharing %s with %s' % (desc, otheruser))
示例#4
0
def handle_time(bot, ievent):
    """ show current time """

    authuser = users.getname(ievent.userhost)

    if authuser:

        if ievent.rest:
            if users.exist(ievent.rest.lower()):
                username = ievent.rest.lower()
            else:
                ievent.reply("We don't have a user %s" % ievent.rest)
                return
        else:
            username = authuser

        userstate = UserState(username)

        try:
            tz = userstate['TZ']
        except KeyError:
            if username == authuser:
                tz = handle_ask_timezone(bot, ievent)
                if tz and set_timezone(bot, ievent, userstate, tz):
                    tz = userstate['TZ']
                else:
                    return
            else:
                ievent.reply("%s doesn't have a timezone set" % username)
                return
        ievent.reply(get_time(tz, username, authuser))

    else:
        ievent.reply(get_time('UTC', '', ''))
示例#5
0
def handle_time(bot, ievent):

    """ show current time """

    authuser = users.getname(ievent.userhost)

    if authuser:

        if ievent.rest:
            if users.exist(ievent.rest.lower()):
                username = ievent.rest.lower()
            else:
                ievent.reply("We don't have a user %s" % ievent.rest)
                return
        else:
            username = authuser

        userstate = UserState(username)

        try:
            tz = userstate['TZ']
        except KeyError:
            if username == authuser:
                tz = handle_ask_timezone(bot, ievent)
                if tz and set_timezone(bot, ievent, userstate, tz):
                    tz = userstate['TZ']
                else:
                    return
            else:
                ievent.reply("%s doesn't have a timezone set" % username)
                return
        ievent.reply(get_time(tz, username, authuser))

    else:
        ievent.reply(get_time('UTC', '', ''))
示例#6
0
def handle_register(bot, ievent):
    if not cfg.get('enable'):
        ievent.reply('register is not enabled')
        return
    if 'OPER' in cfg.get('perms'):
        ievent.reply("can't use OPER permission in register command")
        return
    if not ievent.rest:
        ievent.missing('<username>')
        return
    name = ievent.args[0]
    if users.exist(name):
        ievent.reply('we already have a user with the name %s' % name)
        return
    uh = ievent.userhost
    username = users.getname(uh)
    if username:
        ievent.reply('we already have a user with userhost %s' % uh)
        return
    if users.add(name, [uh, ], perms = cfg.get('perms')):
        throttlestate['level'][uh] = 10
        ievent.reply('%s added to the user database with permission %s' % \
(uh, cfg.get('perms')))
    else:
        ievent.reply('error adding %s (%s) in the user database' % (name, uh))
示例#7
0
def handle_cloudmeet(bot, ievent):
    if not ievent.rest:
        ievent.missing('<nodename>')
        return
    name = ievent.rest
    node = cloud.byname(name)
    if not node:
        ievent.reply('%s is not a cloud node' % name)
        return
    if not node.client.host:
        ievent.reply("can't determine host of %s" % name)
        return
    try:
        if not users.exist(name):
            users.add(name, [
                "cloud@%s" % node.client.host,
            ], [
                'CLOUD',
            ])
            ievent.reply("%s (%s) added to database" %
                         (name, node.client.host))
        else:
            ievent.reply("%s node already exists" % name)
    except Exception, ex:
        ievent.reply('error adding %s to the database: %s' % (name, str(ex)))
示例#8
0
def handle_addshare(bot, ievent):
    """ share a project with another user """
    username = users.getname(ievent.userhost)
    try:
        project, otheruser = ievent.rest.split(' ', 1)
    except ValueError:
        ievent.missing('<projectname> <user>')
        return
    project = project.strip().lower()
    if hascontrib(username, project):
        ievent.reply('only project owner can share a project')
        return
    if not hasproject(username, project):
        ievent.reply('no project %s' % project)
        return
    if not users.exist(otheruser):
        ievent.reply('unknown user %s' % otheruser)
        return
    if hasproject(otheruser, project) or \
    hascontrib(otheruser, project):
        ievent.reply('%s already has a project named %s' \
        % (otheruser, project))
        return
    addshare(username, project, otheruser)
    desc = getdesc(username, project) or project
    ievent.reply('sharing %s with %s' % (desc, otheruser))
示例#9
0
def handle_setemail(bot, ievent):
    """ user-setemail <name> .. set email of name """
    try:
        name, email = ievent.args
    except ValueError:
        ievent.missing('<name> <email>')
        return
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    users.setemail(name, email)
    ievent.reply('email set')
示例#10
0
def handle_idadd(bot, ievent):
    if len(ievent.args) != 2:
        ievent.missing('<nick> <user>')
        return
    if idmanager.get(bot, ievent.args[0].lower()):
        ievent.reply('%s is already known on %s' % (ievent.args[0].lower(), bot.name))
        return
    if not users.exist(ievent.args[1]):
        ievent.reply('user %s unknown' % ievent.args[1].lower())
        return
    else:
        idmanager.add(bot, ievent.args[0].lower(), ievent.args[1].lower())
        ievent.reply('ok')
示例#11
0
def addrecord_POST(server, request):
    try:
        input = getpostdata(request)
        name = input['name']
    except KeyError:
        rlog(5, host, 'addrecord .. no name provided')
        return dumps('no name provided')
    rlog(10, 'cloud', 'addrecord request for %s (%s)' % (name, request.ip)) 
    try:
        if not users.exist(name):
            users.add(name, ["cloud@%s" % request.ip, ], ['CLOUD', ])
            return dumps("%s added" % name)
    except Exception, ex:
        pass
示例#12
0
def handle_idadd(bot, ievent):
    if len(ievent.args) != 2:
        ievent.missing('<nick> <user>')
        return
    if idmanager.get(bot, ievent.args[0].lower()):
        ievent.reply('%s is already known on %s' %
                     (ievent.args[0].lower(), bot.name))
        return
    if not users.exist(ievent.args[1]):
        ievent.reply('user %s unknown' % ievent.args[1].lower())
        return
    else:
        idmanager.add(bot, ievent.args[0].lower(), ievent.args[1].lower())
        ievent.reply('ok')
示例#13
0
def handle_getemail(bot, ievent):
    """ user-getemail <name> .. get email of name """
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    email = users.getuseremail(name)
    if email:
        ievent.reply(email)
    else:
        ievent.reply('no email set')
示例#14
0
def handle_getperms(bot, ievent):
    """ user-getperms <name> .. get permissions of name"""
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    perms = users.getuserperms(name)
    if perms:
        ievent.reply("permissions of %s: " % name, perms, dot=True)
    else:
        ievent.reply('%s has no permissions set' % name)
示例#15
0
def handle_getstatus(bot, ievent):
    """ user-getstatus <name> .. get status of name """
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    status = users.getuserstatuses(name)
    if status:
        ievent.reply("status of %s: " % name, status, dot=True)
    else:
        ievent.reply('%s has no status set' % name)
示例#16
0
def handle_delstatus(bot, ievent):
    """ user-delstatus <name> <status> .. delete status of name """
    if len(ievent.args) != 2:
        ievent.missing('<name> <status>')
        return
    name, status = ievent.args
    status = status.upper()
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    result = 0
    try:
        result = users.deluserstatus(name, status)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#17
0
def handle_delperm(bot, ievent):
    """ user-delperm <name> <perm> .. delete permission of name """
    if len(ievent.args) != 2:
        ievent.missing('<name> <perm>')
        return
    name, perm = ievent.args
    perm = perm.upper()
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    result = 0
    try:
        result = users.deluserperm(name, perm)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#18
0
def addrecord_POST(server, request):
    try:
        input = getpostdata(request)
        name = input['name']
    except KeyError:
        rlog(5, host, 'addrecord .. no name provided')
        return dumps('no name provided')
    rlog(10, 'cloud', 'addrecord request for %s (%s)' % (name, request.ip))
    try:
        if not users.exist(name):
            users.add(name, [
                "cloud@%s" % request.ip,
            ], [
                'CLOUD',
            ])
            return dumps("%s added" % name)
    except Exception, ex:
        pass
示例#19
0
def handle_show(bot, ievent):
    """ user-show <name> .. get data of <name> """
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    userhosts = users.getuserhosts(name)
    perms = users.getuserperms(name)
    email = users.getuseremail(name)
    permits = users.getuserpermits(name)
    status = users.getuserstatuses(name)
    ievent.reply('userrecord of %s = userhosts: %s perms: %s email: %s \
permits: %s status: %s' % (name, str(userhosts), str(perms), \
str(email), str(permits), str(status)))
示例#20
0
def handle_deluserhost(bot, ievent):
    """ user-deluserhost <name> <userhost> .. remove from userhosts of name """
    if len(ievent.args) != 2:
        ievent.missing('<name> <userhost>')
        return
    name, userhost = ievent.args
    name = name.lower()
    if name == 'owner'  and not bot.ownercheck(ievent, 'can delete userhosts \
from owner'):
        return 
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    result = 0
    try:
        result = users.deluserhost(name, userhost)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#21
0
def handle_cloudmeet(bot, ievent):
    if not ievent.rest:
        ievent.missing('<nodename>')
        return
    name = ievent.rest
    node = cloud.byname(name)
    if not node:
       ievent.reply('%s is not a cloud node' % name)
       return
    if not node.client.host:
       ievent.reply("can't determine host of %s" % name)
       return
    try:
        if not users.exist(name):
            users.add(name, ["cloud@%s" % node.client.host, ], ['CLOUD', ])
            ievent.reply("%s (%s) added to database" % (name, node.client.host))
        else:
            ievent.reply("%s node already exists" % name)
    except Exception, ex:
        ievent.reply('error adding %s to the database: %s' % (name, str(ex)))
示例#22
0
def handle_addperm(bot, ievent):
    """ user-addperm <name> <perm> .. add permission """
    if len(ievent.args) != 2:
        ievent.missing('<name> <perm>')
        return
    name, perm = ievent.args
    perm = perm.upper()
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    result = 0
    if users.gotperm(name, perm):
        ievent.reply('%s already has permission %s' % (name, perm))
        return         
    try:
        result = users.adduserperm(name, perm)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#23
0
def handle_addstatus(bot, ievent):
    """ user-addstatus <name> <status> .. add status of name """
    if len(ievent.args) != 2:
        ievent.missing('<name> <status>')
        return
    name, status = ievent.args
    status = status.upper()
    name = name.lower()
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    result = 0
    if users.gotstatus(name, status):
        ievent.reply('%s already has status %s' % (name, status))
        return
    try:
        result = users.adduserstatus(name, status)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#24
0
def handle_userdelpermit(bot, ievent):
    """ user-delpermit <name> <permit> .. remove (name, permit) from permit 
        list """
    try:
        who, what = ievent.args
    except ValueError:
        ievent.missing("<name> <what>")
        return
    if not users.exist(who):
        ievent.reply("can't find registered name of %s" % who)
        return
    name = users.getname(ievent.userhost)
    if not users.gotpermit(name, (who, what)):
        ievent.reply('%s is already not allowed to do %s' % (who, what))
        return
    result = 0
    try:
        result = users.deluserpermit(name, (who, what))
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#25
0
def handle_addpermit(bot, ievent):
    """ user-addpermit <name> <permit> .. add permit to permit list \
        of <name> """
    try:
        who, what = ievent.args
    except ValueError:
        ievent.missing("<name> <permit>")
        return
    if not users.exist(who):
        ievent.reply("can't find username of %s" % who)
        return
    name = users.getname(ievent.userhost)
    if users.gotpermit(name, (who, what)):
        ievent.reply('%s is already allowed to do %s' % (who, what))
        return
    result = 0
    try:
        result = users.adduserpermit(name, (who, what))
    except Exception, ex:
        handle_exception()
        ievent.reply("ERROR: %s" % str(ex))
        return
示例#26
0
def handle_adduserhost(bot, ievent):
    """ user-adduserhost <name> <userhost> .. add to userhosts of name """ 
    if len(ievent.args) != 2:
        ievent.missing('<name> <userhost>')
        return
    name, userhost = ievent.args
    name = name.lower()
    if name == 'owner' and not bot.ownercheck(ievent, 'can adduserhost to \
owner'):
        return
    if not users.exist(name):
        ievent.reply("can't find user %s" % name)
        return
    if users.gotuserhost(name, userhost):
        ievent.reply('%s already has userhost %s' % (name, userhost))
        return
    result = 0
    try:
        result = users.adduserhost(name, userhost)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return