Exemple #1
0
def status_get():
    orgs_count = 0
    servers_count = 0
    servers_online_count = 0
    clients_count = 0
    clients = set()

    for svr in server.iter_servers():
        servers_count += 1
        if svr.status:
            servers_online_count += 1
        # MongoDict doesnt support set(svr.clients)
        clients = clients | set(svr.clients.keys())
    clients_count = len(clients)

    user_count = organization.get_user_count_multi()
    local_networks = utils.get_local_networks()

    if settings.local.openssl_heartbleed:
        notification = 'You are running an outdated version of openssl ' + \
            'containting the heartbleed bug. This could allow an attacker ' + \
            'to compromise your server. Please upgrade your openssl ' + \
            'package and restart the pritunl service.'
    else:
        notification = settings.local.notification

    return utils.jsonify({
        'org_count': orgs_count,
        'users_online': clients_count,
        'user_count': user_count,
        'servers_online': servers_online_count,
        'server_count': servers_count,
        'server_version': __version__,
        'current_host': settings.local.host_id,
        'public_ip': settings.local.public_ip,
        'local_networks': local_networks,
        'notification': notification,
    })
Exemple #2
0
def status_get():
    server_collection = mongo.get_collection('servers')
    host_collection = mongo.get_collection('hosts')
    org_collection = mongo.get_collection('organizations')

    response = server_collection.aggregate([
        {'$project': {
            'client': '$instances.clients',
        }},
        {'$unwind': '$client'},
        {'$unwind': '$client'},
        {'$match': {
            'client.type': CERT_CLIENT,
        }},
        {'$group': {
            '_id': None,
            'clients': {'$addToSet': '$client.id'},
        }},
    ])['result']

    if response:
        users_online = len(response[0]['clients'])
    else:
        users_online = 0

    response = server_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'server_count': {'$sum': 1},
            'servers_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            }
        }},
    ])['result']

    if response:
        server_count = response[0]['server_count']
        servers_online = response[0]['servers_online']
    else:
        server_count = 0
        servers_online = 0

    response = host_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'host_count': {'$sum': 1},
            'hosts_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            }
        }},
    ])['result']

    if response:
        host_count = response[0]['host_count']
        hosts_online = response[0]['hosts_online']
    else:
        host_count = 0
        hosts_online = 0

    user_count = organization.get_user_count_multi()
    local_networks = utils.get_local_networks()

    orgs_count = org_collection.find().count()

    if settings.local.openssl_heartbleed:
        notification = 'You are running an outdated version of openssl ' + \
            'containting the heartbleed bug. This could allow an attacker ' + \
            'to compromise your server. Please upgrade your openssl ' + \
            'package and restart the pritunl service.'
    else:
        notification = settings.local.notification

    return utils.jsonify({
        'org_count': orgs_count,
        'users_online': users_online,
        'user_count': user_count,
        'servers_online': servers_online,
        'server_count': server_count,
        'hosts_online': hosts_online,
        'host_count': host_count,
        'server_version': __version__,
        'current_host': settings.local.host_id,
        'public_ip': settings.local.public_ip,
        'local_networks': local_networks,
        'notification': notification,
    })
Exemple #3
0
 def user_count(self):
     return organization.get_user_count_multi(org_ids=self.organizations)
Exemple #4
0
def status_get():
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    server_collection = mongo.get_collection('servers')
    clients_collection = mongo.get_collection('clients')
    host_collection = mongo.get_collection('hosts')
    org_collection = mongo.get_collection('organizations')

    users_online = len(clients_collection.distinct("user_id", {
        'type': CERT_CLIENT,
    }))

    response = server_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'server_count': {'$sum': 1},
            'servers_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
        }},
    ])

    val = None
    for val in response:
        break

    if val:
        server_count = val['server_count']
        servers_online = val['servers_online']
    else:
        server_count = 0
        servers_online = 0

    response = host_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
            'local_networks': True,
        }},
        {'$group': {
            '_id': None,
            'host_count': {'$sum': 1},
            'hosts_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
            'local_networks': {'$push':'$local_networks'},
        }},
    ])

    val = None
    for val in response:
        break

    local_networks = set()
    if val:
        host_count = val['host_count']
        hosts_online = val['hosts_online']

        for hst_networks in val['local_networks']:
            for network in hst_networks:
                local_networks.add(network)
    else:
        host_count = 0
        hosts_online = 0

    user_count = organization.get_user_count_multi()

    orgs_count = org_collection.find({
       'type': ORG_DEFAULT,
    }, {
        '_id': True,
    }).count()

    notification = settings.local.notification

    resp = {
        'org_count': orgs_count,
        'users_online': users_online,
        'user_count': user_count,
        'servers_online': servers_online,
        'server_count': server_count,
        'hosts_online': hosts_online,
        'host_count': host_count,
        'server_version': __version__,
        'current_host': settings.local.host_id,
        'public_ip': settings.local.public_ip,
        'local_networks': list(local_networks),
        'notification': notification,
    }
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
Exemple #5
0
def status_get():
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    server_collection = mongo.get_collection('servers')
    clients_collection = mongo.get_collection('clients')
    host_collection = mongo.get_collection('hosts')
    org_collection = mongo.get_collection('organizations')

    users_online = len(clients_collection.distinct("user_id", {
        'type': CERT_CLIENT,
    }))

    response = server_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'server_count': {'$sum': 1},
            'servers_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
        }},
    ])

    val = None
    for val in response:
        break

    if val:
        server_count = val['server_count']
        servers_online = val['servers_online']
    else:
        server_count = 0
        servers_online = 0

    response = host_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
            'local_networks': True,
        }},
        {'$group': {
            '_id': None,
            'host_count': {'$sum': 1},
            'hosts_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
            'local_networks': {'$push':'$local_networks'},
        }},
    ])

    val = None
    for val in response:
        break

    local_networks = set()
    if val:
        host_count = val['host_count']
        hosts_online = val['hosts_online']

        for hst_networks in val['local_networks']:
            for network in hst_networks:
                local_networks.add(network)
    else:
        host_count = 0
        hosts_online = 0

    user_count = organization.get_user_count_multi()

    orgs_count = org_collection.find({
       'type': ORG_DEFAULT,
    }, {
        '_id': True,
    }).count()

    if settings.local.openssl_heartbleed:
        notification = 'You are running an outdated version of openssl ' + \
            'containting the heartbleed bug. This could allow an attacker ' + \
            'to compromise your server. Please upgrade your openssl ' + \
            'package and restart the pritunl service.'
    else:
        notification = settings.local.notification

    resp = {
        'org_count': orgs_count,
        'users_online': users_online,
        'user_count': user_count,
        'servers_online': servers_online,
        'server_count': server_count,
        'hosts_online': hosts_online,
        'host_count': host_count,
        'server_version': __version__,
        'current_host': settings.local.host_id,
        'public_ip': settings.local.public_ip,
        'local_networks': list(local_networks),
        'notification': notification,
    }
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
Exemple #6
0
 def user_count(self):
     return organization.get_user_count_multi(org_ids=self.organizations)
Exemple #7
0
def status_get():
    server_collection = mongo.get_collection('servers')
    host_collection = mongo.get_collection('hosts')
    org_collection = mongo.get_collection('organizations')

    response = server_collection.aggregate([
        {'$project': {
            'client': '$instances.clients',
        }},
        {'$unwind': '$client'},
        {'$unwind': '$client'},
        {'$match': {
            'client.type': CERT_CLIENT,
        }},
        {'$group': {
            '_id': None,
            'clients': {'$addToSet': '$client.id'},
        }},
    ])

    val = None
    for val in response:
        break

    if val:
        users_online = len(val['clients'])
    else:
        users_online = 0

    response = server_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'server_count': {'$sum': 1},
            'servers_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
        }},
    ])

    val = None
    for val in response:
        break

    if val:
        server_count = val['server_count']
        servers_online = val['servers_online']
    else:
        server_count = 0
        servers_online = 0

    response = host_collection.aggregate([
        {'$project': {
            '_id': True,
            'status': True,
        }},
        {'$group': {
            '_id': None,
            'host_count': {'$sum': 1},
            'hosts_online': {'$sum': {'$cond': {
                'if': {'$eq': ['$status', ONLINE]},
                'then': 1,
                'else': 0,
            }}},
            'servers': {
                '$push': '$status',
            },
        }},
    ])

    val = None
    for val in response:
        break

    if val:
        host_count = val['host_count']
        hosts_online = val['hosts_online']
    else:
        host_count = 0
        hosts_online = 0

    user_count = organization.get_user_count_multi()
    local_networks = utils.get_local_networks()

    orgs_count = org_collection.find({
       'type': ORG_DEFAULT,
    }, {
        '_id': True,
    }).count()

    if settings.local.openssl_heartbleed:
        notification = 'You are running an outdated version of openssl ' + \
            'containting the heartbleed bug. This could allow an attacker ' + \
            'to compromise your server. Please upgrade your openssl ' + \
            'package and restart the pritunl service.'
    else:
        notification = settings.local.notification

    return utils.jsonify({
        'org_count': orgs_count,
        'users_online': users_online,
        'user_count': user_count,
        'servers_online': servers_online,
        'server_count': server_count,
        'hosts_online': hosts_online,
        'host_count': host_count,
        'server_version': __version__,
        'current_host': settings.local.host_id,
        'public_ip': settings.local.public_ip,
        'local_networks': local_networks,
        'notification': notification,
    })