def get(self, id): """ Lists server details """ id = long(id) s = meta.getServer(id) tree = obj_to_dict(s.getTree()) json_data = { 'id': s.id(), 'name': get_server_conf(meta, s, 'registername'), 'host': get_server_conf(meta, s, 'host'), 'port': get_server_port(meta, s), 'address': '%s:%s' % ( get_server_conf(meta, s, 'host'), get_server_port(meta, s), ), 'password': get_server_conf(meta, s, 'password'), 'welcometext': get_server_conf(meta, s, 'welcometext'), 'user_count': (s.isRunning() and len(s.getUsers())) or 0, 'maxusers': get_server_conf(meta, s, 'users') or 0, 'uptime': s.getUptime() if s.isRunning() else 0, 'humanize_uptime': str( timedelta(seconds=s.getUptime()) if s.isRunning() else '' ), 'parent_channel': tree['c'], 'sub_channels': tree['children'], 'users': tree['users'], 'registered_users': s.getRegisteredUsers(''), 'log_length': s.getLogLen() } return jsonify(json_data)
def channel_acl(self, id, channel_id): """ Gets all channel ACLs in server """ server = meta.getServer(id) data = obj_to_dict(server.getACL(channel_id)) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def get(self, id): """ Lists server details """ id = int(id) s = meta.getServer(id) # Return 404 if not found if s is None: return jsonify(message="Not Found"), 404 tree = obj_to_dict(s.getTree()) if s.isRunning() else None json_data = { 'id': s.id(), 'host': get_server_conf(meta, s, 'host'), 'port': get_server_port(meta, s), 'address': '%s:%s' % ( get_server_conf(meta, s, 'host'), get_server_port(meta, s), ), 'welcometext': get_server_conf(meta, s, 'welcometext'), 'user_count': (s.isRunning() and len(s.getUsers())) or 0, 'maxusers': get_server_conf(meta, s, 'users') or 0, 'running': s.isRunning(), 'uptime': s.getUptime() if s.isRunning() else 0, 'humanize_uptime': str( timedelta(seconds=s.getUptime()) if s.isRunning() else '' ), 'users': [s.getUsers()[uid].name for uid in s.getUsers().keys()] if s.isRunning() else None, } return jsonify(json_data)
def user_new_user(self, id): """ Creates user """ server = meta.getServer(int(id)) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 username = request.form.get('username') password = request.form.get('password') new_user = { Murmur.UserInfo.UserName: username, Murmur.UserInfo.UserPassword: password } added = server.registerUser(new_user) data = obj_to_dict(server.getRegistration(added)) json_data = { "user_id": added, "username": data['UserName'], "last_active": data['UserLastActive'] } return Response(json.dumps(json_data, sort_keys=True, indent=4), mimetype='application/json')
def user_new_user(self, id): """ Creates user """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 username = request.form.get('username') password = request.form.get('password') new_user = { Murmur.UserInfo.UserName: username, Murmur.UserInfo.UserPassword: password } added = server.registerUser(new_user) data = obj_to_dict(server.getRegistration(added)) json_data = { "user_id": added, "username": data['UserName'], "last_active": data['UserLastActive'] } return Response(json.dumps(json_data, sort_keys=True, indent=4), mimetype='application/json')
def conf(self, id): """ Gets all configuration in server """ server = meta.getServer(id) data = obj_to_dict(server.getAllConf()) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def bans(self, id): """ Gets all banned IPs in server """ server = meta.getServer(id) data = obj_to_dict(server.getBans()) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def get(self, id): """ Lists server details """ id = long(id) s = meta.getServer(id) # Return 404 if not found if s is None: return jsonify(message="Not Found"), 404 tree = obj_to_dict(s.getTree()) if s.isRunning() else None json_data = { 'id': s.id(), 'name': get_server_conf(meta, s, 'registername'), 'host': get_server_conf(meta, s, 'host'), 'port': get_server_port(meta, s), 'address': '%s:%s' % ( get_server_conf(meta, s, 'host'), get_server_port(meta, s), ), 'password': get_server_conf(meta, s, 'password'), 'welcometext': get_server_conf(meta, s, 'welcometext'), 'user_count': (s.isRunning() and len(s.getUsers())) or 0, 'maxusers': get_server_conf(meta, s, 'users') or 0, 'running': s.isRunning(), 'uptime': s.getUptime() if s.isRunning() else 0, 'humanize_uptime': str(timedelta(seconds=s.getUptime()) if s.isRunning() else ''), 'parent_channel': tree['c'] if s.isRunning() else None, 'sub_channels': tree['children'] if s.isRunning() else None, 'users': tree['users'] if s.isRunning() else None, 'registered_users': s.getRegisteredUsers('') if s.isRunning() else None, 'log_length': s.getLogLen(), 'bans': s.getBans() if s.isRunning() else 0 } return jsonify(json_data)
def channel_acl(self, id, channel_id): """ Gets all channel ACLs in server """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 data = obj_to_dict(server.getACL(channel_id)) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def channel(self, id, channel_id): """ Gets a specific channel from a server """ server = meta.getServer(int(id)) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 data = obj_to_dict(server.getChannelState(int(channel_id))) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def register_user(self, id, user): """ Gets registered user by ID """ server = meta.getServer(int(id)) data = obj_to_dict(server.getRegistration(user)) json_data = { "user_id": user, "username": data['UserName'], "last_active": data['UserLastActive'] } return Response(json.dumps(json_data, sort_keys=True, indent=4), mimetype='application/json')
def channel_new_channel(self, id): """ Creates channel """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 name = request.form.get('name') parent = request.form.get('parent') added = server.addChannel(name, int(parent)) data = obj_to_dict(server.getChannelState(int(added))) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def register_user(self, id, user): """ Gets registered user by ID """ server = meta.getServer(int(id)) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 data = obj_to_dict(server.getRegistration(int(user))) json_data = { "user_id": user, "username": data['UserName'], "last_active": data['UserLastActive'] } return Response(json.dumps(json_data, sort_keys=True, indent=4), mimetype='application/json')
def register_user(self, id, user): """ Gets registered user by ID """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 data = obj_to_dict(server.getRegistration(int(user))) json_data = { "user_id": user, "username": data['UserName'], "last_active": data['UserLastActive'] } return Response(json.dumps(json_data, sort_keys=True, indent=4), mimetype='application/json')
def update_channel(self, id, channel_id): """ Update specific channel attributes """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 # Return 404 if not found channel = server.getChannelState(channel_id) if channel is None: return jsonify(message="Not Found"), 404 name = request.form.get('name') parent = request.form.get('parent') description = request.form.get('description') links = request.form.getlist('links[]') description = request.form.get('description') position = request.form.get('position') temporary = request.form.get('temporary') if name is not None: channel.name = str(name) if parent is not None: channel.parent = int(parent) if description is not None: channel.description = str(description) if links is not None: for idx in range(len(links)): links[idx] = int(links[idx]) channel.links = links if position is not None: channel.position = int(position) if temporary is not None: channel.temporary = bool(temporary) server.setChannelState(channel) data = obj_to_dict(server.getChannelState(channel_id)) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')
def update_channel_acl(self, id, channel_id): """ Update specific channel ACL """ server = meta.getServer(id) # Return 404 if not found if server is None: return jsonify(message="Not Found"), 404 origin_acl = server.getACL(channel_id) update_acls = origin_acl[0] update_groups = origin_acl[1] update_inherit = origin_acl[2] params = request.get_json() if "acls" in params and params['acls'] is not None: new_acls = [] for props in params['acls']: new_acls.append( Murmur.ACL(props['applyHere'], props['applySubs'], props['inherited'], props['userid'], props['group'], props['allow'], props['deny'])) update_acls = new_acls if "groups" in params and params['groups'] is not None: new_groups = [] for props in params['groups']: new_groups.append( Murmur.Group(props['name'], props['inherited'], props['inherit'], props['inheritable'], props['add'], props['remove'])) update_groups = new_groups if "inherit" in params and params['inherit'] is not None: update_inherit = bool(params['inherit']) server.setACL(channel_id, update_acls, update_groups, update_inherit) data = obj_to_dict(server.getACL(channel_id)) return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json')