def requestinvite(user, args, socket): if not args and len(args) > 0: return # Check if channel exist comma = args.find(",") channame = args[:comma] if channame.lower() in channels: chan = channels[channame.lower()] else: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", channame + " does not exist.") return # Check access access = chan.accesscontrollist.get(user.ivleid) permission = chan.permissionlist.get("invite") if permission > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", "Insufficient access level.") return targetivleid = args[comma+1:] print "check" value, check = channel_verifyUser(targetivleid, socket) print value print check if not value: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", check) return print "asd" # check if user is in channel if targetivleid in chan.joined: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", targetivleid + " is already in " + chan.name + ".") return # Update accessToUpdate = False; if not chan.public: if chan.accesscontrollist.get(targetivleid) == 0: chan.accesscontrollist.add(targetivleid,1) db.insertACLEntry(user_controller.user_getUser(targetivleid), chan, 1) accessToUpdate = True for u in chan.joined: user_controller.user_send(chan.joined[u], "channel", "invite", user.ivleid + "," + targetivleid + "," + user_controller.user_getUser(targetivleid).nickname + "," + chan.name) if accessToUpdate: user_controller.user_send(chan.joined[u], "channel", "setaccess", chan.name + "," + targetivleid + "," + "1") user_controller.user_send(user_controller.user_getUser(targetivleid), "channel", "invited", user.ivleid + "," + user.nickname + "," + chan.name)
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))
def requestkick(user, args, socket): if not args and len(args) > 0: return # Check if channel exist comma = args.find(",") channame = args[:comma] if channame.lower() not in channels: user_controller.user_sendSocketMessage( socket, "notice", "channel,requestkick", "Channel " + channame + " does not exist.") return chan = channels[channame.lower()] targetivleid = args[comma + 1:] check = channel_verifyUser(targetivleid, socket) if not check[0]: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", check[1]) return # Check if user is in channel if targetivleid not in chan.joined: user_controller.user_sendSocketMessage( socket, "notice", "channel,requestkick", targetivleid + " is not in " + chan.name + ".") return # Check if user have access access = chan.accesscontrollist.get(user.ivleid) if chan.permissionlist.get('kick') > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", "Insufficient access level.") return # Check if user have higher access than kickedUser kickedaccess = chan.accesscontrollist.get(targetivleid) if kickedaccess > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", "Insufficient access level.") return # Notify for u in chan.joined: user_controller.user_send( chan.joined[u], "channel", "kicked", user.ivleid + "," + targetivleid + "," + chan.name) # Update del chan.joined[targetivleid] del user_controller.user_getUser(targetivleid).joined[chan.name.lower()]
def auth_no_ivleauth(noivleid, socket): try: if noivleid[0] != '.' or user_controller.user_getUser(noivleid) is None: socket.write_message("Invalid login.") socket.on_close() return socket.user = user_controller.user_getUser(noivleid); 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(noivleid): 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: # 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 socket.user.updateLastSeen() except Exception, e: print e print noivleid pass
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
def document_upload(sessionkey, data): try: # Check if document exists if (preparelist.has_key(sessionkey) == False): return False # Get document document = preparelist[sessionkey] # Set file data k = Key(bucket) k.key = sessionkey k.set_metadata("Content-Type", document.contenttype) k.set_metadata("Content-Disposition", str('attachment; filename="' + document.filename + '"')) k.set_contents_from_string( str( base64.decodestring(data[data.find("base64,") + len("base64,"):]))) k.set_acl('public-read') # Update del preparelist[sessionkey] del preparelistname[document.channame + "/" + document.filename] channelfolder = document_getChannelFolder(document.channame) channelfolder[document.filename] = document db.createDocument(document) except: print "error uploading" try: bucket.delete_key(sessionkey) except: pass # Send results channel = channel_controller.channel_getChannel(document.channame) for u in channel.joined: if channel.accesscontrollist.get(u) >= channel.permissionlist.get( "download"): user_controller.user_send(channel.joined[u], "document", "uploadedfile", json.dumps(document.toObject())) user_controller.user_send( user_controller.user_getUser(document.uploaderivleid), "document", "useruploaded", json.dumps(document.toObject()))
def requestkick(user, args, socket): if not args and len(args) > 0: return # Check if channel exist comma = args.find(",") channame = args[:comma] if channame.lower() not in channels: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", "Channel "+ channame + " does not exist.") return chan = channels[channame.lower()] targetivleid = args[comma+1:] check = channel_verifyUser(targetivleid, socket) if not check[0]: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", check[1]) return # Check if user is in channel if targetivleid not in chan.joined: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", targetivleid + " is not in " + chan.name + ".") return # Check if user have access access = chan.accesscontrollist.get(user.ivleid) if chan.permissionlist.get('kick') > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", "Insufficient access level.") return # Check if user have higher access than kickedUser kickedaccess = chan.accesscontrollist.get(targetivleid) if kickedaccess > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestkick", "Insufficient access level.") return # Notify for u in chan.joined: user_controller.user_send(chan.joined[u], "channel", "kicked", user.ivleid + "," + targetivleid + "," + chan.name) # Update del chan.joined[targetivleid] del user_controller.user_getUser(targetivleid).joined[chan.name.lower()]
def document_upload(sessionkey, data): try: # Check if document exists if (preparelist.has_key(sessionkey) == False): return False # Get document document = preparelist[sessionkey] # Set file data k = Key(bucket) k.key = sessionkey k.set_metadata("Content-Type", document.contenttype) k.set_metadata("Content-Disposition", str('attachment; filename="'+document.filename+'"')) k.set_contents_from_string(str(base64.decodestring(data[data.find("base64,")+len("base64,"):]))) k.set_acl('public-read') # Update del preparelist[sessionkey] del preparelistname[document.channame + "/" + document.filename] channelfolder = document_getChannelFolder(document.channame) channelfolder[document.filename] = document db.createDocument(document) except: print "error uploading" try: bucket.delete_key(sessionkey) except: pass # Send results channel = channel_controller.channel_getChannel(document.channame) for u in channel.joined: if channel.accesscontrollist.get(u) >= channel.permissionlist.get("download"): user_controller.user_send(channel.joined[u], "document", "uploadedfile", json.dumps(document.toObject())) user_controller.user_send(user_controller.user_getUser(document.uploaderivleid), "document", "useruploaded", json.dumps(document.toObject()))
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))
def requestinvite(user, args, socket): if not args and len(args) > 0: return # Check if channel exist comma = args.find(",") channame = args[:comma] if channame.lower() in channels: chan = channels[channame.lower()] else: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", channame + " does not exist.") return # Check access access = chan.accesscontrollist.get(user.ivleid) permission = chan.permissionlist.get("invite") if permission > access: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", "Insufficient access level.") return targetivleid = args[comma + 1:] print "check" value, check = channel_verifyUser(targetivleid, socket) print value print check if not value: user_controller.user_sendSocketMessage(socket, "notice", "channel,requestinvite", check) return print "asd" # check if user is in channel if targetivleid in chan.joined: user_controller.user_sendSocketMessage( socket, "notice", "channel,requestinvite", targetivleid + " is already in " + chan.name + ".") return # Update accessToUpdate = False if not chan.public: if chan.accesscontrollist.get(targetivleid) == 0: chan.accesscontrollist.add(targetivleid, 1) db.insertACLEntry(user_controller.user_getUser(targetivleid), chan, 1) accessToUpdate = True for u in chan.joined: user_controller.user_send( chan.joined[u], "channel", "invite", user.ivleid + "," + targetivleid + "," + user_controller.user_getUser(targetivleid).nickname + "," + chan.name) if accessToUpdate: user_controller.user_send( chan.joined[u], "channel", "setaccess", chan.name + "," + targetivleid + "," + "1") user_controller.user_send( user_controller.user_getUser(targetivleid), "channel", "invited", user.ivleid + "," + user.nickname + "," + chan.name)