本文整理汇总了Python中pritunl.server.Server.iter_servers方法的典型用法代码示例。如果您正苦于以下问题:Python Server.iter_servers方法的具体用法?Python Server.iter_servers怎么用?Python Server.iter_servers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pritunl.server.Server
的用法示例。
在下文中一共展示了Server.iter_servers方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_wsgi
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
def _run_wsgi(self):
if self.ssl:
self._setup_server_cert()
logger.info('Starting server...')
if self.auto_start_servers:
from pritunl.server import Server
for server in Server.iter_servers():
if server.org_count:
try:
server.start()
except:
logger.exception('Failed to auto start server. %r' % {
'server_id': server.id,
})
server = cherrypy.wsgiserver.CherryPyWSGIServer(
(self.bind_addr, self.port), self.app,
request_queue_size=SERVER_REQUEST_QUEUE_SIZE,
server_name=cherrypy.wsgiserver.CherryPyWSGIServer.version)
if self.ssl:
server.ConnectionClass = HTTPConnectionPatch
server.ssl_adapter = SSLAdapter(
self._server_cert_path, self._server_key_path)
try:
server.start()
except (KeyboardInterrupt, SystemExit):
pass
except:
logger.exception('Server error occurred')
raise
finally:
signal.signal(signal.SIGINT, signal.SIG_IGN)
logger.info('Stopping server...')
self._on_exit()
示例2: status_get
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
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,
})
示例3: server_get
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
def server_get(server_id=None):
if server_id:
return utils.jsonify(Server.get_server(server_id).dict())
else:
servers = []
servers_dict = {}
servers_sort = []
for server in Server.iter_servers():
servers.append(server.dict())
return utils.jsonify(servers)
示例4: status_get
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
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,
})
示例5: server_put_post
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
def server_put_post(server_id=None):
network_used = set()
interface_used = set()
port_used = set()
for server in Server.iter_servers():
if server.id == server_id:
continue
network_used.add(server.network)
interface_used.add(server.interface)
port_used.add('%s%s' % (server.port, server.protocol))
name = None
name_def = False
if 'name' in flask.request.json:
name_def = True
name = utils.filter_str(flask.request.json['name'])
network = None
network_def = False
if 'network' in flask.request.json:
network_def = True
network = flask.request.json['network']
if network not in SAFE_PUB_SUBNETS:
network_split = network.split('/')
if len(network_split) != 2:
return _network_invalid()
address = network_split[0].split('.')
if len(address) != 4:
return _network_invalid()
for i, value in enumerate(address):
try:
address[i] = int(value)
except ValueError:
return _network_invalid()
if address[0] != 10:
return _network_invalid()
if address[1] > 255 or address[1] < 0 or \
address[2] > 255 or address[2] < 0:
return _network_invalid()
if address[3] != 0:
return _network_invalid()
try:
subnet = int(network_split[1])
except ValueError:
return _network_invalid()
if subnet < 8 or subnet > 24:
return _network_invalid()
interface = None
interface_def = False
if 'interface' in flask.request.json:
interface_def = True
interface = flask.request.json['interface']
if not re.match('^[a-z0-9]+$', interface):
return _interface_invalid()
if interface[:3] != 'tun':
return _interface_invalid()
try:
interface_num = int(interface[3:])
except ValueError:
return _interface_invalid()
if interface_num > 64:
return _interface_invalid()
interface = interface[:3] + str(interface_num)
protocol = 'udp'
protocol_def = False
if 'protocol' in flask.request.json:
protocol_def = True
protocol = flask.request.json['protocol'].lower()
if protocol not in ('udp', 'tcp'):
return utils.jsonify({
'error': PROTOCOL_INVALID,
'error_msg': PROTOCOL_INVALID_MSG,
}, 400)
port = None
port_def = False
if 'port' in flask.request.json:
port_def = True
port = flask.request.json['port']
try:
port = int(port)
except ValueError:
return _port_invalid()
if port < 1 or port > 65535:
#.........这里部分代码省略.........
示例6: export_get
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
def export_get():
data_path = app_server.data_path
temp_path = os.path.join(data_path, TEMP_DIR)
empty_temp_path = os.path.join(temp_path, EMPTY_TEMP_DIR)
data_archive_name = '%s_%s.tar' % (APP_NAME,
time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime()))
data_archive_path = os.path.join(temp_path, data_archive_name)
# Create empty temp directory to recreate temp dirs in tarfile
if not os.path.exists(empty_temp_path):
os.makedirs(empty_temp_path)
tar_file = tarfile.open(data_archive_path, 'w')
try:
tar_add(tar_file, os.path.join(data_path, AUTH_LOG_NAME))
tar_add(tar_file, os.path.join(data_path, 'pritunl.db'))
tar_add(tar_file, os.path.join(data_path, SERVER_CERT_NAME))
tar_add(tar_file, os.path.join(data_path, SERVER_KEY_NAME))
tar_add(tar_file, os.path.join(data_path, VERSION_NAME))
for org in Organization.iter_orgs():
tar_add(tar_file, org.get_path())
tar_file.add(empty_temp_path,
arcname=os.path.relpath(os.path.join(org.path, TEMP_DIR),
data_path))
for user in org.iter_users():
tar_add(tar_file, user.reqs_path)
tar_add(tar_file, user.key_path)
tar_add(tar_file, user.cert_path)
tar_add(tar_file, user.get_path())
tar_add(tar_file, org.ca_cert.reqs_path)
tar_add(tar_file, org.ca_cert.key_path)
tar_add(tar_file, org.ca_cert.cert_path)
tar_add(tar_file, org.ca_cert.get_path())
for server in Server.iter_servers():
tar_add(tar_file, server.dh_param_path)
tar_add(tar_file, server.ip_pool_path)
tar_add(tar_file, server.get_path())
tar_add(tar_file, os.path.join(server.path, NODE_SERVER))
tar_file.add(empty_temp_path,
arcname=os.path.relpath(os.path.join(server.path, TEMP_DIR),
data_path))
tar_file.close()
with open(data_archive_path, 'r') as archive_file:
response = flask.Response(response=archive_file.read(),
mimetype='application/octet-stream')
response.headers.add('Content-Disposition',
'attachment; filename="%s"' % data_archive_name)
return response
finally:
try:
tar_file.close()
except OSError:
pass
try:
os.remove(data_archive_path)
except OSError:
pass
示例7: server_put_post
# 需要导入模块: from pritunl.server import Server [as 别名]
# 或者: from pritunl.server.Server import iter_servers [as 别名]
def server_put_post(server_id=None):
network_used = set()
interface_used = set()
port_used = set()
for server in Server.iter_servers():
if server.id == server_id:
continue
network_used.add(server.network)
interface_used.add(server.interface)
port_used.add("%s%s" % (server.port, server.protocol))
name = None
name_def = False
if "name" in flask.request.json:
name_def = True
name = utils.filter_str(flask.request.json["name"])
type = SERVER
type_def = False
if "type" in flask.request.json:
type_def = True
if flask.request.json["type"] == NODE_SERVER:
type = NODE_SERVER
network = None
network_def = False
if "network" in flask.request.json:
network_def = True
network = flask.request.json["network"]
if network not in SAFE_PUB_SUBNETS:
network_split = network.split("/")
if len(network_split) != 2:
return _network_invalid()
address = network_split[0].split(".")
if len(address) != 4:
return _network_invalid()
for i, value in enumerate(address):
try:
address[i] = int(value)
except ValueError:
return _network_invalid()
if address[0] != 10:
return _network_invalid()
if address[1] > 255 or address[1] < 0 or address[2] > 255 or address[2] < 0:
return _network_invalid()
if address[3] != 0:
return _network_invalid()
try:
subnet = int(network_split[1])
except ValueError:
return _network_invalid()
if subnet < 8 or subnet > 24:
return _network_invalid()
interface = None
interface_def = False
if "interface" in flask.request.json:
interface_def = True
interface = flask.request.json["interface"]
if not re.match("^[a-z0-9]+$", interface):
return _interface_invalid()
if interface[:3] != "tun":
return _interface_invalid()
try:
interface_num = int(interface[3:])
except ValueError:
return _interface_invalid()
if interface_num > 64:
return _interface_invalid()
interface = interface[:3] + str(interface_num)
protocol = "udp"
protocol_def = False
if "protocol" in flask.request.json:
protocol_def = True
protocol = flask.request.json["protocol"].lower()
if protocol not in ("udp", "tcp"):
return utils.jsonify({"error": PROTOCOL_INVALID, "error_msg": PROTOCOL_INVALID_MSG}, 400)
port = None
port_def = False
if "port" in flask.request.json:
port_def = True
port = flask.request.json["port"]
try:
port = int(port)
except ValueError:
#.........这里部分代码省略.........