示例#1
0
文件: host.py 项目: hungld/pritunl
def host_get(hst=None):
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    if hst:
        resp = host.get_by_id(hst).dict()
        if settings.app.demo_mode:
            utils.demo_set_cache(resp)
        return utils.jsonify(resp)

    hosts = []
    page = flask.request.args.get('page', None)
    page = int(page) if page else page

    for hst in host.iter_hosts_dict(page=page):
        hosts.append(hst)

    if page is not None:
        resp = {
            'page': page,
            'page_total': host.get_host_page_total(),
            'hosts': hosts,
        }
    else:
        resp = hosts

    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
示例#2
0
def server_host_put(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'links'))
    hst = host.get_by_id(host_id, fields=('_id', 'name',
        'public_address', 'auto_public_address'))

    try:
        svr.add_host(hst.id)
    except ServerLinkCommonHostError:
        return utils.jsonify({
            'error': SERVER_LINK_COMMON_HOST,
            'error_msg': SERVER_LINK_COMMON_HOST_MSG,
        }, 400)

    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#3
0
def server_host_put(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'links'))
    hst = host.get_by_id(host_id, fields=('_id', 'name',
        'public_address', 'auto_public_address'))

    try:
        svr.add_host(hst.id)
    except ServerLinkCommonHostError:
        return utils.jsonify({
            'error': SERVER_LINK_COMMON_HOST,
            'error_msg': SERVER_LINK_COMMON_HOST_MSG,
        }, 400)

    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#4
0
文件: host.py 项目: zeus911/pritunl
def host_get(hst=None):
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    if hst:
        resp = host.get_by_id(hst).dict()
        if settings.app.demo_mode:
            utils.demo_set_cache(resp)
        return utils.jsonify(resp)

    hosts = []
    page = flask.request.args.get('page', None)
    page = int(page) if page else page

    for hst in host.iter_hosts_dict(page=page):
        if settings.app.demo_mode:
            hst['users_online'] = hst['user_count']
        hosts.append(hst)

    if page is not None:
        resp = {
            'page': page,
            'page_total': host.get_host_page_total(),
            'hosts': hosts,
        }
    else:
        resp = hosts

    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
示例#5
0
文件: host.py 项目: parsicode/pritunl
def host_delete(hst):
    hst = host.get_by_id(hst)
    hst.remove()

    logger.LogEntry(message='Deleted host "%s".' % hst.name)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify({})
示例#6
0
def host_delete(host_id):
    hst = host.get_by_id(host_id)
    hst.remove()

    logger.LogEntry(message='Deleted host "%s".' % hst.name)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify({})
示例#7
0
def host_put(hst=None):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    hst = host.get_by_id(hst)

    if 'name' in flask.request.json:
        hst.name = utils.filter_str(
            flask.request.json['name']) or utils.random_name()

    if 'public_address' in flask.request.json:
        hst.public_address = utils.filter_str(
            flask.request.json['public_address'])

    if 'public_address6' in flask.request.json:
        hst.public_address6 = utils.filter_str(
            flask.request.json['public_address6'])

    if 'routed_subnet6' in flask.request.json:
        routed_subnet6 = flask.request.json['routed_subnet6']
        if routed_subnet6:
            try:
                routed_subnet6 = ipaddress.IPv6Network(
                    flask.request.json['routed_subnet6'])
            except (ipaddress.AddressValueError, ValueError):
                return utils.jsonify({
                    'error': IPV6_SUBNET_INVALID,
                    'error_msg': IPV6_SUBNET_INVALID_MSG,
                }, 400)

            if routed_subnet6.prefixlen > 64:
                return utils.jsonify({
                    'error': IPV6_SUBNET_SIZE_INVALID,
                    'error_msg': IPV6_SUBNET_SIZE_INVALID_MSG,
                }, 400)

            routed_subnet6 = str(routed_subnet6)
        else:
            routed_subnet6 = None

        if hst.routed_subnet6 != routed_subnet6:
            if server.get_online_ipv6_count():
                return utils.jsonify({
                    'error': IPV6_SUBNET_ONLINE,
                    'error_msg': IPV6_SUBNET_ONLINE_MSG,
                }, 400)
            hst.routed_subnet6 = routed_subnet6

    if 'link_address' in flask.request.json:
        hst.link_address = utils.filter_str(
            flask.request.json['link_address'])

    hst.commit(hst.changed)
    event.Event(type=HOSTS_UPDATED)
    messenger.publish('hosts', 'updated')

    return utils.jsonify(hst.dict())
示例#8
0
文件: instance.py 项目: kknet/pritunl
 def link_instance(self, host_id):
     if self.interrupt:
         return
     instance_link = ServerInstanceLink(
         server=self.server,
         linked_server=self.server,
         linked_host=host.get_by_id(host_id),
     )
     instance_link.start()
     self.replica_links[host_id] = instance_link
示例#9
0
文件: host.py 项目: WHCAMERA/pritunl
def host_get(host_id=None):
    if host_id:
        return utils.jsonify(host.get_by_id(host_id).dict())

    hosts = []

    for hst in host.iter_servers_dict():
        hosts.append(hst)

    return utils.jsonify(hosts)
示例#10
0
 def link_instance(self, host_id):
     if self.interrupt:
         return
     instance_link = ServerInstanceLink(
         server=self.server,
         linked_server=self.server,
         linked_host=host.get_by_id(host_id),
     )
     instance_link.start()
     self.replica_links[host_id] = instance_link
示例#11
0
def host_get(host_id=None):
    if host_id:
        return utils.jsonify(host.get_by_id(host_id).dict())

    hosts = []

    for hst in host.iter_servers_dict():
        hosts.append(hst)

    return utils.jsonify(hosts)
示例#12
0
文件: host.py 项目: gergnz/pritunl
def host_delete(hst):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    hst = host.get_by_id(hst)
    hst.remove()

    logger.LogEntry(message='Deleted host "%s".' % hst.name)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify({})
示例#13
0
文件: host.py 项目: hungld/pritunl
def host_usage_get(hst, period):
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    hst = host.get_by_id(hst)
    resp = hst.usage.get_period(period)
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
示例#14
0
文件: host.py 项目: rchicoli/pritunl
def host_put(hst=None):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    hst = host.get_by_id(hst)

    if "name" in flask.request.json:
        hst.name = utils.filter_str(flask.request.json["name"]) or utils.random_name()

    if "public_address" in flask.request.json:
        hst.public_address = utils.filter_str(flask.request.json["public_address"])

    if "public_address6" in flask.request.json:
        hst.public_address6 = utils.filter_str(flask.request.json["public_address6"])

    if "routed_subnet6" in flask.request.json:
        routed_subnet6 = flask.request.json["routed_subnet6"]
        if routed_subnet6:
            try:
                routed_subnet6 = ipaddress.IPv6Network(flask.request.json["routed_subnet6"])
            except (ipaddress.AddressValueError, ValueError):
                return utils.jsonify({"error": IPV6_SUBNET_INVALID, "error_msg": IPV6_SUBNET_INVALID_MSG}, 400)

            if routed_subnet6.prefixlen > 64:
                return utils.jsonify(
                    {"error": IPV6_SUBNET_SIZE_INVALID, "error_msg": IPV6_SUBNET_SIZE_INVALID_MSG}, 400
                )

            routed_subnet6 = str(routed_subnet6)
        else:
            routed_subnet6 = None

        if hst.routed_subnet6 != routed_subnet6:
            if server.get_online_ipv6_count():
                return utils.jsonify({"error": IPV6_SUBNET_ONLINE, "error_msg": IPV6_SUBNET_ONLINE_MSG}, 400)
            hst.routed_subnet6 = routed_subnet6

    if "local_address" in flask.request.json:
        hst.local_address = utils.filter_str(flask.request.json["local_address"])

    if "local_address6" in flask.request.json:
        hst.local_address6 = utils.filter_str(flask.request.json["local_address6"])

    if "link_address" in flask.request.json:
        hst.link_address = utils.filter_str(flask.request.json["link_address"])

    if "instance_id" in flask.request.json:
        hst.instance_id = utils.filter_str(flask.request.json["instance_id"])

    hst.commit(hst.changed)
    event.Event(type=HOSTS_UPDATED)
    messenger.publish("hosts", "updated")

    return utils.jsonify(hst.dict())
示例#15
0
def server_host_delete(server_id, host_id):
    svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'replica_count'))
    hst = host.get_by_id(host_id, fields=('_id', 'name'))

    svr.remove_host(hst.id)
    svr.commit('hosts')

    event.Event(type=SERVERS_UPDATED)
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({})
示例#16
0
文件: host.py 项目: dhh123/pritunl
def host_delete(hst):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    hst = host.get_by_id(hst)
    hst.remove()

    logger.LogEntry(message='Deleted host "%s".' % hst.name)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify({})
示例#17
0
def server_host_delete(server_id, host_id):
    svr = server.get_by_id(server_id, fields=['_id', 'hosts'])
    hst = host.get_by_id(host_id, fields=['_id', 'name'])

    svr.remove_host(hst.id)
    svr.commit('hosts')

    event.Event(type=SERVERS_UPDATED)
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({})
示例#18
0
文件: host.py 项目: fanduel/pritunl
def host_usage_get(hst, period):
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    hst = host.get_by_id(hst)
    resp = hst.usage.get_period(period)
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
示例#19
0
def server_host_put(server_id, host_id):
    svr = server.get_by_id(server_id, fields=['_id', 'hosts'])
    hst = host.get_by_id(host_id, fields=['_id', 'name', 'public_address'])
    svr.add_host(hst.id)
    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#20
0
def server_host_delete(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'replica_count'))
    hst = host.get_by_id(host_id, fields=('_id', 'name'))

    svr.remove_host(hst.id)
    svr.commit('hosts')

    event.Event(type=SERVERS_UPDATED)
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({})
示例#21
0
def server_host_put(server_id, host_id):
    svr = server.get_by_id(server_id, fields=['_id', 'hosts'])
    hst = host.get_by_id(host_id, fields=['_id', 'name', 'public_address'])
    svr.add_host(hst.id)
    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#22
0
def host_put(host_id=None):
    hst = host.get_by_id(host_id)

    if 'name' in flask.request.json:
        hst.name = utils.filter_str(
            flask.request.json['name']) or utils.random_name()

    if 'public_address' in flask.request.json:
        hst.public_address = utils.filter_str(
            flask.request.json['public_address'])

    if 'link_address' in flask.request.json:
        hst.link_address = utils.filter_str(flask.request.json['link_address'])

    hst.commit(hst.changed)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify(hst.dict())
示例#23
0
文件: host.py 项目: WHCAMERA/pritunl
def host_put(host_id=None):
    hst = host.get_by_id(host_id)

    if 'name' in flask.request.json:
        hst.name = utils.filter_str(
            flask.request.json['name']) or utils.random_name()

    if 'public_address' in flask.request.json:
        hst.public_address = utils.filter_str(
            flask.request.json['public_address'])

    if 'link_address' in flask.request.json:
        hst.link_address = utils.filter_str(
            flask.request.json['link_address'])

    hst.commit(hst.changed)
    event.Event(type=HOSTS_UPDATED)

    return utils.jsonify(hst.dict())
示例#24
0
文件: server.py 项目: pritunl/pritunl
def server_host_delete(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id, fields=(
        '_id', 'hosts', 'replica_count'))
    if not svr:
        return flask.abort(404)
    hst = host.get_by_id(host_id, fields=('_id', 'name'))
    if not hst:
        return flask.abort(404)

    svr.remove_host(hst.id)
    svr.commit('hosts')

    event.Event(type=SERVERS_UPDATED)
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({})
示例#25
0
文件: host.py 项目: dhh123/pritunl
def host_get(hst=None):
    if hst:
        return utils.jsonify(host.get_by_id(hst).dict())

    hosts = []
    page = flask.request.args.get('page', None)
    page = int(page) if page else page

    for hst in host.iter_hosts_dict(page=page):
        hosts.append(hst)

    if page is not None:
        return utils.jsonify({
            'page': page,
            'page_total': host.get_host_page_total(),
            'hosts': hosts,
        })
    else:
        return utils.jsonify(hosts)
示例#26
0
文件: host.py 项目: gergnz/pritunl
def host_get(hst=None):
    if hst:
        return utils.jsonify(host.get_by_id(hst).dict())

    hosts = []
    page = flask.request.args.get('page', None)
    page = int(page) if page else page

    for hst in host.iter_hosts_dict(page=page):
        hosts.append(hst)

    if page is not None:
        return utils.jsonify({
            'page': page,
            'page_total': host.get_host_page_total(),
            'hosts': hosts,
        })
    else:
        return utils.jsonify(hosts)
示例#27
0
def server_host_put(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id)
    if not svr:
        return flask.abort(404)
    hst = host.get_by_id(host_id,
                         fields=('_id', 'name', 'public_address',
                                 'auto_public_address', 'auto_public_host',
                                 'public_address6', 'auto_public_address6',
                                 'auto_public_host6'))
    if not svr:
        return flask.abort(404)

    try:
        svr.add_host(hst.id)
    except ServerLinkCommonHostError:
        return utils.jsonify(
            {
                'error': SERVER_LINK_COMMON_HOST,
                'error_msg': SERVER_LINK_COMMON_HOST_MSG,
            }, 400)

    err, err_msg = svr.validate_conf(allow_online=True)
    if err:
        return utils.jsonify({
            'error': err,
            'error_msg': err_msg,
        }, 400)

    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#28
0
文件: server.py 项目: pritunl/pritunl
def server_host_put(server_id, host_id):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    svr = server.get_by_id(server_id)
    if not svr:
        return flask.abort(404)
    hst = host.get_by_id(host_id, fields=('_id', 'name',
        'public_address', 'auto_public_address', 'auto_public_host',
        'public_address6', 'auto_public_address6', 'auto_public_host6'))
    if not svr:
        return flask.abort(404)

    try:
        svr.add_host(hst.id)
    except ServerLinkCommonHostError:
        return utils.jsonify({
            'error': SERVER_LINK_COMMON_HOST,
            'error_msg': SERVER_LINK_COMMON_HOST_MSG,
        }, 400)

    err, err_msg = svr.validate_conf(allow_online=True)
    if err:
        return utils.jsonify({
            'error': err,
            'error_msg': err_msg,
        }, 400)

    svr.commit('hosts')
    event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id)

    return utils.jsonify({
        'id': hst.id,
        'server': svr.id,
        'status': OFFLINE,
        'name': hst.name,
        'address': hst.public_addr,
    })
示例#29
0
 def get_by_id(self, host_id):
     if host_id in self.hosts:
         return host.get_by_id(host_id)
示例#30
0
文件: host.py 项目: zeus911/pritunl
def host_put(hst=None):
    if settings.app.demo_mode:
        return utils.demo_blocked()

    hst = host.get_by_id(hst)

    if 'name' in flask.request.json:
        hst.name = utils.filter_str(
            flask.request.json['name']) or utils.random_name()

    if 'public_address' in flask.request.json:
        public_address = utils.filter_str(flask.request.json['public_address'])
        hst.public_address = public_address

    if 'public_address6' in flask.request.json:
        public_address6 = utils.filter_str(
            flask.request.json['public_address6'])
        hst.public_address6 = public_address6

    if 'routed_subnet6' in flask.request.json:
        routed_subnet6 = flask.request.json['routed_subnet6']
        if routed_subnet6:
            try:
                routed_subnet6 = ipaddress.IPv6Network(
                    flask.request.json['routed_subnet6'])
            except (ipaddress.AddressValueError, ValueError):
                return utils.jsonify(
                    {
                        'error': IPV6_SUBNET_INVALID,
                        'error_msg': IPV6_SUBNET_INVALID_MSG,
                    }, 400)

            if routed_subnet6.prefixlen > 64:
                return utils.jsonify(
                    {
                        'error': IPV6_SUBNET_SIZE_INVALID,
                        'error_msg': IPV6_SUBNET_SIZE_INVALID_MSG,
                    }, 400)

            routed_subnet6 = str(routed_subnet6)
        else:
            routed_subnet6 = None

        if hst.routed_subnet6 != routed_subnet6:
            if server.get_online_ipv6_count():
                return utils.jsonify(
                    {
                        'error': IPV6_SUBNET_ONLINE,
                        'error_msg': IPV6_SUBNET_ONLINE_MSG,
                    }, 400)
            hst.routed_subnet6 = routed_subnet6

    if 'proxy_ndp' in flask.request.json:
        proxy_ndp = True if flask.request.json['proxy_ndp'] else False
        hst.proxy_ndp = proxy_ndp

    if 'local_address' in flask.request.json:
        local_address = utils.filter_str(flask.request.json['local_address'])
        hst.local_address = local_address

    if 'local_address6' in flask.request.json:
        local_address6 = utils.filter_str(flask.request.json['local_address6'])
        hst.local_address6 = local_address6

    if 'link_address' in flask.request.json:
        link_address = utils.filter_str(flask.request.json['link_address'])
        hst.link_address = link_address

    if 'sync_address' in flask.request.json:
        sync_address = utils.filter_str(flask.request.json['sync_address'])
        hst.sync_address = sync_address

    if 'availability_group' in flask.request.json:
        hst.availability_group = utils.filter_str(
            flask.request.json['availability_group']) or DEFAULT

    if 'instance_id' in flask.request.json:
        instance_id = utils.filter_str(flask.request.json['instance_id'])

        if instance_id != hst.aws_id:
            hst.instance_id = instance_id

    hst.commit(hst.changed)
    event.Event(type=HOSTS_UPDATED)
    messenger.publish('hosts', 'updated')

    return utils.jsonify(hst.dict())
示例#31
0
 def get_by_id(self, host_id):
     if host_id in self.hosts:
         return host.get_by_id(host_id)
示例#32
0
def host_usage_get(host_id, period):
    hst = host.get_by_id(host_id)
    return utils.jsonify(hst.usage.get_period(period))
示例#33
0
文件: host.py 项目: dhh123/pritunl
def host_usage_get(hst, period):
    hst = host.get_by_id(hst)
    return utils.jsonify(hst.usage.get_period(period))