Ejemplo n.º 1
0
def setaccess(user, args, socket):
    if not args and len(args) > 0:
        return
    
    args = args.split(",")
    if len(args) < 3:
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", "Invalid input.")
        return
    
    # Check if input is valid
    channame = args[0]
    if channame.lower() not in channels:
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", "Channel "+ channame + " does not exist.")
        return
    chan = channels[channame.lower()]
    
    # verify user
    targetivleid = args[1]
    if not user_controller.user_ivleidExist(targetivleid):
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", targetivleid + " does not exist.")
        return

    
    try:
        accesslevel = int(args[2])
    except:
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", "Invalid input.")
        return

    # Check if  access is out of bound
    if accesslevel < -1 or accesslevel > levels['Admin']:
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", "Access level out of bound.")
        return
    
    # Check if user have access
    access = chan.accesscontrollist.get(user.ivleid)
    toAccess = chan.accesscontrollist.get(targetivleid)
    if access <= toAccess or accesslevel > access:
        user_controller.user_sendSocketMessage(socket, "notice", "channel,setaccess", "You have insufficient access level.")
        return
    
    # Update
    targetUser = user_controller.user_getUser(targetivleid)
    if accesslevel == 0:
        chan.accesscontrollist.remove(targetivleid)
        db.deleteACLEntry(targetUser, chan)
    else:
        if chan.accesscontrollist.get(targetivleid) == 0:
            chan.accesscontrollist.add(targetivleid,accesslevel)
            db.insertACLEntry(targetUser, chan, accesslevel)
        else:
            chan.accesscontrollist.add(targetivleid,accesslevel)
            db.updateACLEntry(targetUser, chan, accesslevel)
    
    # Notify
    for u in chan.joined:
        user_controller.user_send(chan.joined[u], "channel", "setaccess", chan.name + "," + targetivleid + "," + str(accesslevel))     
Ejemplo n.º 2
0
def channel_verifyUser(ivleid, socket):
    # check if user exist
    if not user_controller.user_ivleidExist(ivleid):
        return (False, "channel", ivleid + " does not exist.")

    # check if user is online
    if user_controller.user_ivleidOnline(ivleid) == 0:
        return (False, ivleid + " is not online.")

    return True, 'ok'
Ejemplo n.º 3
0
def channel_verifyUser(ivleid, socket):
    # check if user exist
    if not user_controller.user_ivleidExist(ivleid):
        return (False, "channel", ivleid + " does not exist.")

    # check if user is online
    if user_controller.user_ivleidOnline(ivleid) == 0:
        return (False, ivleid + " is not online.")

    return True, 'ok'
Ejemplo n.º 4
0
def auth_ivleauth(key, socket):
    try:
        ivleid, email, fullname = ivlehelper.getUserIvleInfo(key)
        if len(ivleid) == 0:
            socket.write_message("Invalid login.")
            socket.on_close()
            return
    
        # First login
        if not user_controller.user_ivleidExist(ivleid):
            socket.user = User.User(ivleid, email, fullname, "ivle/"+ivleid)
            user_controller.user_addUser(socket.user.ivleid, socket.user)
            db.insertUser(socket.user)
        else:
            socket.user = user_controller.user_getUser(ivleid)
            socket.user.fullname = fullname
            socket.user.email = email
            db.updateUser(socket.user)
            
        socket.user.sockets.append(socket)
        socket.validated = True
        socket.write_message("welcome,userinfo,"+json.dumps(socket.user.infoToObject()))
        socket.write_message("welcome,userpreference,"+json.dumps(socket.user.welcomeInfoToObject()))
        socket.write_message("welcome,availablelevels,"+json.dumps(channel_controller.levels))
        socket.write_message("welcome,availablepermissions,"+json.dumps(channel_controller.permissionTypes))
        
        # if user does not have a new session
        if user_controller.user_ivleidOnline(ivleid):
            for c in socket.user.joined.keys():
                socket.write_message("channel,joinedchannel," + json.dumps(socket.user.joined[c].infoToObject()))
                socket.write_message("channel,canvasdata,"+c+","+json.dumps(socket.user.joined[c].canvas.toObject()))
        
        # Normal login, update with new ivle data
        else: 
            db.updateUser(socket.user)
            # Autojoin channels
            for chan in socket.user.autojoin:
                channel_controller.requestjoin(socket.user, chan, socket)
        
        # Resume private chat
        for u in socket.user.userprivatechat:
            socket.write_message("user,requestedprivchat,"+u);
        
        socket.user.online += 1       
        
    except Exception, e:
        print e
        pass
Ejemplo n.º 5
0
def setaccess(user, args, socket):
    if not args and len(args) > 0:
        return

    args = args.split(",")
    if len(args) < 3:
        user_controller.user_sendSocketMessage(socket, "notice",
                                               "channel,setaccess",
                                               "Invalid input.")
        return

    # Check if input is valid
    channame = args[0]
    if channame.lower() not in channels:
        user_controller.user_sendSocketMessage(
            socket, "notice", "channel,setaccess",
            "Channel " + channame + " does not exist.")
        return
    chan = channels[channame.lower()]

    # verify user
    targetivleid = args[1]
    if not user_controller.user_ivleidExist(targetivleid):
        user_controller.user_sendSocketMessage(
            socket, "notice", "channel,setaccess",
            targetivleid + " does not exist.")
        return

    try:
        accesslevel = int(args[2])
    except:
        user_controller.user_sendSocketMessage(socket, "notice",
                                               "channel,setaccess",
                                               "Invalid input.")
        return

    # Check if  access is out of bound
    if accesslevel < -1 or accesslevel > levels['Admin']:
        user_controller.user_sendSocketMessage(socket, "notice",
                                               "channel,setaccess",
                                               "Access level out of bound.")
        return

    # Check if user have access
    access = chan.accesscontrollist.get(user.ivleid)
    toAccess = chan.accesscontrollist.get(targetivleid)
    if access <= toAccess or accesslevel > access:
        user_controller.user_sendSocketMessage(
            socket, "notice", "channel,setaccess",
            "You have insufficient access level.")
        return

    # Update
    targetUser = user_controller.user_getUser(targetivleid)
    if accesslevel == 0:
        chan.accesscontrollist.remove(targetivleid)
        db.deleteACLEntry(targetUser, chan)
    else:
        if chan.accesscontrollist.get(targetivleid) == 0:
            chan.accesscontrollist.add(targetivleid, accesslevel)
            db.insertACLEntry(targetUser, chan, accesslevel)
        else:
            chan.accesscontrollist.add(targetivleid, accesslevel)
            db.updateACLEntry(targetUser, chan, accesslevel)

    # Notify
    for u in chan.joined:
        user_controller.user_send(
            chan.joined[u], "channel", "setaccess",
            chan.name + "," + targetivleid + "," + str(accesslevel))