本文整理汇总了Python中pritunl.organization.Organization类的典型用法代码示例。如果您正苦于以下问题:Python Organization类的具体用法?Python Organization怎么用?Python Organization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Organization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_put
def user_put(org_id, user_id):
org = Organization(org_id)
user = org.get_user(user_id)
name = flask.request.json['name']
name = ''.join(x for x in name if x.isalnum() or x in NAME_SAFE_CHARS)
user.rename(name)
return utils.jsonify({})
示例2: user_post
def user_post(org_id):
org = Organization(org_id)
name = flask.request.json['name']
name = ''.join(x for x in name if x.isalnum() or x in NAME_SAFE_CHARS)
user = org.new_user(CERT_CLIENT, name)
return utils.jsonify({})
示例3: user_get
def user_get(org_id):
org = Organization(org_id)
org_servers = org.get_servers()
users = []
users_dict = {}
users_sort = []
clients = {}
for server in org_servers:
server_clients = server.get_clients()
for client_id in server_clients:
client = server_clients[client_id]
if client_id not in clients:
clients[client_id] = []
clients[client_id].append(client['virt_address'])
for user in org.get_users():
name_id = '%s_%s' % (user.name, user.id)
users_sort.append(name_id)
users_dict[name_id] = {
'id': user.id,
'organization': org.id,
'name': user.name,
'type': user.type,
'status': True if user.id in clients else False,
'virt_addresses': clients[user.id] if user.id in clients else [],
}
for name_id in sorted(users_sort):
users.append(users_dict[name_id])
return utils.jsonify(users)
示例4: org_get
def org_get(org_id=None):
if org_id:
return utils.jsonify(Organization.get_org(id=org_id).dict())
else:
orgs = []
for org in Organization.iter_orgs():
orgs.append(org.dict())
return utils.jsonify(orgs)
示例5: _get_key_inline
def _get_key_inline(org_id, user_id):
org = Organization(org_id)
user = org.get_user(user_id)
archive = user.build_key_inline()
response = flask.Response(response=archive, mimetype='application/octet-stream' )
response.headers.add('Content-Disposition', 'inline; filename="%s.ovpn"' % user.name)
return response
示例6: user_delete
def user_delete(org_id, user_id):
org = Organization(org_id)
user = org.get_user(user_id)
user_id = user.id
user.remove()
for server in org.get_servers():
server_clients = server.get_clients()
if user_id in server_clients:
server.restart()
return utils.jsonify({})
示例7: _get_key_archive
def _get_key_archive(org_id, user_id):
org = Organization(org_id)
user = org.get_user(user_id)
archive_temp_path = user.build_key_archive()
with open(archive_temp_path, "r") as archive_file:
response = flask.Response(response=archive_file.read(), mimetype="application/x-tar")
response.headers.add("Content-Disposition", 'inline; filename="%s.tar"' % user.name)
os.remove(archive_temp_path)
return response
示例8: user_key_link_get
def user_key_link_get(org_id, user_id):
org = Organization.get_org(id=org_id)
key_id = uuid.uuid4().hex
view_id = None
uri_id = None
for i in xrange(2):
for i in xrange(2048):
temp_id = ''.join(random.sample(SHORT_URL_CHARS, SHORT_URL_LEN))
if not view_id:
if not cache_db.exists(_get_view_key(temp_id)):
view_id = temp_id
break
else:
if not cache_db.exists(_get_uri_key(temp_id)):
uri_id = temp_id
break
if not view_id and not uri_id:
raise KeyLinkError('Failed to generate random id')
cache_db.expire(_get_key_key(key_id), KEY_LINK_TIMEOUT)
cache_db.dict_set(_get_key_key(key_id), 'org_id', org_id)
cache_db.dict_set(_get_key_key(key_id), 'user_id', user_id)
cache_db.dict_set(_get_key_key(key_id), 'view_id', view_id)
cache_db.dict_set(_get_key_key(key_id), 'uri_id', uri_id)
conf_urls = []
if app_server.inline_certs:
for server in org.iter_servers():
conf_id = uuid.uuid4().hex
cache_db.expire(_get_conf_key(conf_id), KEY_LINK_TIMEOUT)
cache_db.dict_set(_get_conf_key(conf_id), 'org_id', org_id)
cache_db.dict_set(_get_conf_key(conf_id), 'user_id', user_id)
cache_db.dict_set(_get_conf_key(conf_id), 'server_id', server.id)
conf_urls.append({
'id': conf_id,
'server_name': server.name,
'url': '/key/%s.ovpn' % conf_id,
})
cache_db.expire(_get_view_key(view_id), KEY_LINK_TIMEOUT)
cache_db.dict_set(_get_view_key(view_id), 'org_id', org_id)
cache_db.dict_set(_get_view_key(view_id), 'user_id', user_id)
cache_db.dict_set(_get_view_key(view_id), 'key_id', key_id)
cache_db.dict_set(_get_view_key(view_id), 'uri_id', uri_id)
cache_db.dict_set(_get_view_key(view_id),
'conf_urls', json.dumps(conf_urls))
cache_db.expire(_get_uri_key(uri_id), KEY_LINK_TIMEOUT)
cache_db.dict_set(_get_uri_key(uri_id), 'org_id', org_id)
cache_db.dict_set(_get_uri_key(uri_id), 'user_id', user_id)
return utils.jsonify({
'id': key_id,
'key_url': '/key/%s.tar' % key_id,
'view_url': '/k/%s' % view_id,
'uri_url': '/ku/%s' % uri_id,
})
示例9: status_get
def status_get():
orgs = Organization.get_orgs()
orgs_count = len(orgs)
servers_count = 0
servers_online_count = 0
clients_count = 0
for server in Server.get_servers():
servers_count += 1
if server.status:
servers_online_count += 1
clients_count += len(server.get_clients())
users_count = 0
for org in orgs:
for user in org.get_users():
if user.type != CERT_CLIENT:
continue
users_count += 1
if not app_server.public_ip:
app_server.load_public_ip()
return utils.jsonify({
'orgs_available': orgs_count,
'orgs_total': orgs_count,
'users_online': clients_count,
'users_total': users_count,
'servers_online': servers_online_count,
'servers_total': servers_count,
'server_version': __version__,
'public_ip': app_server.public_ip,
})
示例10: user_put
def user_put(org_id, user_id):
org = Organization.get_org(id=org_id)
user = org.get_user(user_id)
name = utils.filter_str(flask.request.json['name'])
user.rename(name)
return utils.jsonify(user.dict())
示例11: user_post
def user_post(org_id):
org = Organization.get_org(id=org_id)
users = []
if isinstance(flask.request.json, list):
users_data = flask.request.json
else:
users_data = [flask.request.json]
for user_data in users_data:
name = utils.filter_str(user_data['name'])
email = utils.filter_str(user_data.get('email'))
user = org.new_user(type=CERT_CLIENT, name=name, email=email)
disabled = user_data.get('disabled')
if disabled is not None:
user.disabled = disabled
user.commit()
users.append(user.dict())
Event(type=ORGS_UPDATED)
Event(type=USERS_UPDATED, resource_id=org.id)
Event(type=SERVERS_UPDATED)
if isinstance(flask.request.json, list):
LogEntry(message='Created %s new users.' % len(flask.request.json))
return utils.jsonify(users)
else:
LogEntry(message='Created new user "%s".' % users[0]['name'])
return utils.jsonify(users[0])
示例12: user_otp_secret_put
def user_otp_secret_put(org_id, user_id):
org = Organization.get_org(id=org_id)
user = org.get_user(user_id)
user.generate_otp_secret()
user.commit()
Event(type=USERS_UPDATED, resource_id=org.id)
return utils.jsonify(user.dict())
示例13: status_get
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,
})
示例14: user_put
def user_put(org_id, user_id):
org = Organization.get_org(id=org_id)
user = org.get_user(user_id)
name = flask.request.json.get('name')
if name:
name = utils.filter_str(name)
if 'email' in flask.request.json:
email = flask.request.json['email']
if email:
user.email = utils.filter_str(email)
else:
user.email = None
disabled = flask.request.json.get('disabled')
if disabled is not None:
user.disabled = disabled
if name:
user.rename(name)
else:
user.commit()
Event(type=USERS_UPDATED, resource_id=user.org.id)
if disabled:
if user.type == CERT_CLIENT:
LogEntry(message='Disabled user "%s".' % user.name)
for server in org.iter_servers():
server_clients = server.clients
if user_id in server_clients:
server.restart()
elif disabled == False and user.type == CERT_CLIENT:
LogEntry(message='Enabled user "%s".' % user.name)
send_key_email = flask.request.json.get('send_key_email')
if send_key_email and user.email:
try:
user.send_key_email(send_key_email)
except EmailNotConfiguredError:
return utils.jsonify({
'error': EMAIL_NOT_CONFIGURED,
'error_msg': EMAIL_NOT_CONFIGURED_MSG,
}, 400)
except EmailFromInvalid:
return utils.jsonify({
'error': EMAIL_FROM_INVALID,
'error_msg': EMAIL_FROM_INVALID_MSG,
}, 400)
except EmailApiKeyInvalid:
return utils.jsonify({
'error': EMAIL_API_KEY_INVALID,
'error_msg': EMAIL_API_KEY_INVALID_MSG,
}, 400)
return utils.jsonify(user.dict())
示例15: user_get
def user_get(org_id, user_id=None, page=None):
org = Organization.get_org(id=org_id)
if user_id:
return utils.jsonify(org.get_user(user_id).dict())
else:
page = flask.request.args.get('page', None)
page = int(page) if page else page
search = flask.request.args.get('search', None)
limit = int(flask.request.args.get('limit', USER_PAGE_COUNT))
otp_auth = False
search_more = True
server_count = 0
clients = {}
for server in org.iter_servers():
server_count += 1
if server.otp_auth:
otp_auth = True
server_clients = server.clients
for client_id in server_clients:
client = server_clients[client_id]
if client_id not in clients:
clients[client_id] = {}
clients[client_id][server.id] = client
users = []
for user in org.iter_users(page=page, prefix=search,
prefix_limit=limit):
if user is None:
search_more = False
break
is_client = user.id in clients
user_dict = user.dict()
user_dict['status'] = True if is_client else False
user_dict['otp_auth'] = otp_auth
user_dict['servers'] = clients[user.id] if is_client else {}
users.append(user_dict)
if page is not None:
return utils.jsonify({
'page': page,
'page_total': org.page_total,
'server_count': server_count,
'users': users,
})
elif search is not None:
return utils.jsonify({
'search': search,
'search_more': search_more,
'search_limit': limit,
'search_count': org.get_last_prefix_count(),
'search_time': round((time.time() - flask.g.start), 4),
'server_count': server_count,
'users': users,
})
else:
return utils.jsonify(users)