Exemplo n.º 1
0
def init():
    settings.local.host = Host()

    try:
        settings.local.host.load()
    except NotFound:
        pass

    settings.local.host.status = ONLINE
    settings.local.host.users_online = 0
    settings.local.host.start_timestamp = utils.now()
    settings.local.host.ping_timestamp = utils.now()
    if settings.local.public_ip:
        settings.local.host.auto_public_address = settings.local.public_ip
    if settings.local.public_ip6:
        settings.local.host.auto_public_address6 = settings.local.public_ip6

    try:
        settings.local.host.hostname = socket.gethostname()
    except:
        logger.exception('Failed to get hostname', 'host')
        settings.local.host.hostname = None

    if settings.conf.local_address_interface == 'auto':
        try:
            settings.local.host.auto_local_address = utils.get_local_address()
        except:
            logger.exception('Failed to get auto_local_address', 'host')
            settings.local.host.local_address = None

        try:
            settings.local.host.auto_local_address6 = \
                utils.get_local_address6()
        except:
            logger.exception('Failed to get auto_local_address6', 'host')
            settings.local.host.local_address6 = None
    else:
        try:
            settings.local.host.auto_local_address = \
                utils.get_interface_address(
                    str(settings.conf.local_address_interface))
        except:
            logger.exception('Failed to get auto_local_address', 'host',
                interface=settings.conf.local_address_interface)
            settings.local.host.auto_local_address = None

        try:
            settings.local.host.auto_local_address6 = \
                utils.get_interface_address6(
                    str(settings.conf.local_address_interface))
        except:
            logger.exception('Failed to get auto_local_address6', 'host',
                interface=settings.conf.local_address_interface)
            settings.local.host.auto_local_address6 = None

    settings.local.host.auto_instance_id = utils.get_instance_id()
    settings.local.host.local_networks = utils.get_local_networks()

    settings.local.host.commit()
    event.Event(type=HOSTS_UPDATED)
Exemplo n.º 2
0
def status_get():
    orgs_count = 0
    servers_count = 0
    servers_online_count = 0
    clients_count = 0

    for server in Server.iter_servers():
        servers_count += 1
        if server.status:
            servers_online_count += 1
        clients_count += len(server.clients)

    user_count = 0
    for org in Organization.iter_orgs():
        orgs_count += 1
        user_count += org.user_count

    local_networks = utils.get_local_networks()

    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__,
        'public_ip': app_server.public_ip,
        'local_networks': local_networks,
    })
Exemplo n.º 3
0
def status_get():
    orgs_count = 0
    servers_count = 0
    servers_online_count = 0
    clients_count = 0

    for server in Server.iter_servers():
        servers_count += 1
        if server.status:
            servers_online_count += 1
        clients_count += len(server.clients)

    user_count = 0
    for org in Organization.iter_orgs():
        orgs_count += 1
        user_count += org.user_count

    local_networks = utils.get_local_networks()

    if app_server.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 = app_server.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__,
        'public_ip': app_server.public_ip,
        'local_networks': local_networks,
        'notification': notification,
    })
Exemplo n.º 4
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,
    })
Exemplo n.º 5
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__,
        'public_ip': settings.local.public_ip,
        'local_networks': local_networks,
        'notification': notification,
    })
Exemplo n.º 6
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,
    })
Exemplo n.º 7
0
def init():
    settings.local.host = Host()

    try:
        settings.local.host.load()
    except NotFound:
        pass

    settings.local.host.status = ONLINE
    settings.local.host.users_online = 0
    settings.local.host.start_timestamp = utils.now()
    settings.local.host.ping_timestamp = utils.now()
    if settings.local.public_ip:
        settings.local.host.auto_public_address = settings.local.public_ip
    if settings.local.public_ip6:
        settings.local.host.auto_public_address6 = settings.local.public_ip6

    try:
        settings.local.host.hostname = socket.gethostname()
    except:
        logger.exception('Failed to get hostname', 'host')
        settings.local.host.hostname = None

    if settings.conf.local_address_interface == 'auto':
        try:
            settings.local.host.auto_local_address = utils.get_local_address()
        except:
            logger.exception('Failed to get auto_local_address', 'host')
            settings.local.host.local_address = None

        try:
            settings.local.host.auto_local_address6 = \
                utils.get_local_address6()
        except:
            logger.exception('Failed to get auto_local_address6', 'host')
            settings.local.host.local_address6 = None
    else:
        try:
            settings.local.host.auto_local_address = \
                utils.get_interface_address(
                    str(settings.conf.local_address_interface))
        except:
            logger.exception('Failed to get auto_local_address',
                             'host',
                             interface=settings.conf.local_address_interface)
            settings.local.host.auto_local_address = None

        try:
            settings.local.host.auto_local_address6 = \
                utils.get_interface_address6(
                    str(settings.conf.local_address_interface))
        except:
            logger.exception('Failed to get auto_local_address6',
                             'host',
                             interface=settings.conf.local_address_interface)
            settings.local.host.auto_local_address6 = None

    settings.local.host.auto_instance_id = utils.get_instance_id()
    settings.local.host.local_networks = utils.get_local_networks()

    settings.local.host.commit()
    event.Event(type=HOSTS_UPDATED)