示例#1
0
    def cvp(self, id):
        server = meta.getServer(id)

        # Return 404 if not found
        if server is None:
            return jsonify(message="Not Found"), 404

        allowed = bool(get_server_conf(meta, server, 'x_cvp'))
        if not allowed:
            return jsonify(message="CVP Disabled"), 403

        # Fetch tree from server
        tree = server.getTree()

        # Get server properties relevant to CVP
        rname = get_server_conf(meta, server, 'registername')
        rhost = get_server_conf(meta, server, 'registerhostname')
        port = get_server_port(meta, server)

        # Build the CVP object
        cvp = {
            "root": cvp_chan_to_dict(tree),
            "name": rname if rname != '' else 'Root',
            "x_uptime": server.getUptime(),
            "id": server.id()
        }

        if rhost != '':
            cvp['x_connecturl'] = "mumble://%s:%d/?version=1.2.0" % (rhost,
                                                                     port)

        return Response(json.dumps(cvp, sort_keys=True, indent=4),
                        mimetype='application/json')
示例#2
0
    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)
示例#3
0
    def index(self):
        """
        Lists all servers
        """

        servers = []
        for s in meta.getAllServers():
            servers.append({
                'id': s.id(),
                'name': get_server_conf(meta, s, 'registername'),
                'address': '%s:%s' % (
                    get_server_conf(meta, s, 'host'),
                    get_server_port(meta, s),
                ),
                'host': get_server_conf(meta, s, 'host'),
                'port': get_server_port(meta, s),
                'running': s.isRunning(),
                'users': (s.isRunning() and len(s.getUsers())) or 0,
                'maxusers': get_server_conf(meta, s, 'users') or 0,
                'channels': (s.isRunning() and len(s.getChannels())) or 0,
                'uptime_seconds': s.getUptime() if s.isRunning() else 0,
                'uptime': str(
                    timedelta(seconds=s.getUptime()) if s.isRunning() else ''
                ),
                'log_length': s.getLogLen()
            })

        # Workaround response due to jsonify() not allowing top-level json response
        # https://github.com/mitsuhiko/flask/issues/170
        return Response(json.dumps(servers, sort_keys=True, indent=4), mimetype='application/json')
示例#4
0
    def index(self):
        """
        Lists all servers
        """

        servers = []
        for s in meta.getAllServers():
            servers.append({
                'id': s.id(),
                'name': get_server_conf(meta, s, 'registername'),
                'address': '%s:%s' % (
                    get_server_conf(meta, s, 'host'),
                    get_server_port(meta, s),
                ),
                'host': get_server_conf(meta, s, 'host'),
                'port': get_server_port(meta, s),
                'running': s.isRunning(),
                'users': (s.isRunning() and len(s.getUsers())) or 0,
                'maxusers': get_server_conf(meta, s, 'users') or 0,
                'channels': (s.isRunning() and len(s.getChannels())) or 0,
                'uptime_seconds': s.getUptime() if s.isRunning() else 0,
                'uptime': str(
                    timedelta(seconds=s.getUptime()) if s.isRunning() else ''
                ),
                'log_length': s.getLogLen(),
                'users': [s.getUsers()[uid].name for uid in s.getUsers().keys()] if s.isRunning() else None,
            })

        return Response(json.dumps(servers, sort_keys=True, indent=4), mimetype='application/json')
示例#5
0
文件: api.py 项目: alfg/murmur-rest
    def cvp(self, id):
        server = meta.getServer(id)

        # Return 404 if not found
        if server is None:
            return jsonify(message="Not Found"), 404

        allowed = bool(get_server_conf(meta, server, 'x_cvp'))
        if not allowed:
            return jsonify(message="CVP Disabled"), 403

        # Fetch tree from server
        tree = server.getTree()

        # Get server properties relevant to CVP
        rname = get_server_conf(meta, server, 'registername')
        rhost = get_server_conf(meta, server, 'registerhostname')
        port = get_server_port(meta, server)

        # Build the CVP object
        cvp = {
            "root": cvp_chan_to_dict(tree),
            "name": rname if rname != '' else 'Root',
            "x_uptime": server.getUptime(),
            "id": server.id()
        }

        if rhost != '':
            cvp['x_connecturl'] = "mumble://%s:%d/?version=1.2.0" % (rhost, port)

        return Response(json.dumps(cvp, sort_keys=True, indent=4), mimetype='application/json')
示例#6
0
    def index(self):
        """
        Lists all servers
        """

        servers = []
        for s in meta.getAllServers():
            servers.append({
                'id': s.id(),
                'name': get_server_conf(meta, s, 'registername'),
                'address': '%s:%s' % (
                    get_server_conf(meta, s, 'host'),
                    get_server_port(meta, s),
                ),
                'host': get_server_conf(meta, s, 'host'),
                'port': get_server_port(meta, s),
                'running': s.isRunning(),
                'users': (s.isRunning() and len(s.getUsers())) or 0,
                'maxusers': get_server_conf(meta, s, 'users') or 0,
                'channels': (s.isRunning() and len(s.getChannels())) or 0,
                'uptime_seconds': s.getUptime() if s.isRunning() else 0,
                'uptime': str(
                    timedelta(seconds=s.getUptime()) if s.isRunning() else ''
                ),
                'log_length': s.getLogLen()
            })

        # Workaround response due to jsonify() not allowing top-level json response
        # https://github.com/mitsuhiko/flask/issues/170
        return Response(json.dumps(servers, sort_keys=True, indent=4), mimetype='application/json')
示例#7
0
    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)
示例#8
0
    def index(self):
        """
        Lists all servers
        """

        servers = []
        for s in meta.getAllServers():
            host = get_server_conf(meta, s, 'host')
            port = get_server_port(meta, s)
            is_running = s.isRunning()
            uptime = s.getUptime() if is_running else 0

            servers.append({
                'id':
                s.id(),
                'name':
                get_server_conf(meta, s, 'registername'),
                'address':
                '%s:%s' % (host, port),
                'host':
                host,
                'port':
                port,
                'running':
                is_running,
                'users': (is_running and len(s.getUsers())) or 0,
                'maxusers':
                get_server_conf(meta, s, 'users') or 0,
                'channels': (is_running and len(s.getChannels())) or 0,
                'uptime_seconds':
                uptime if is_running else 0,
                'uptime':
                str(timedelta(seconds=uptime) if is_running else ''),
                'log_length':
                s.getLogLen()
            })

        return jsonify(servers)
示例#9
0
    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)