mirror of https://github.com/Aidaho12/haproxy-wi
v8.1.2: Refactor database interactions and cleanup unused code
Refactor multiple functions to call `get_group` instead of `get_group_name_by_id`. Remove the `ApiToken` class and related database table operations. Simplify the template logic in `show_sub_ovw.html` by removing unnecessary loop and context variables. Cleanup unused imports and streamline several function implementations across the codebase.pull/401/head
parent
e9473088d5
commit
0128321642
|
@ -55,10 +55,12 @@ def login_page():
|
||||||
print(str(e))
|
print(str(e))
|
||||||
return roxywi_common.handle_json_exceptions(e, 'Cannot check login password'), 401
|
return roxywi_common.handle_json_exceptions(e, 'Cannot check login password'), 401
|
||||||
try:
|
try:
|
||||||
return roxywi_auth.do_login(user_params, next_url)
|
response = roxywi_auth.do_login(user_params, next_url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return roxywi_common.handle_json_exceptions(e, 'Cannot do login'), 401
|
return roxywi_common.handle_json_exceptions(e, 'Cannot do login'), 401
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout', methods=['GET', 'POST'])
|
@app.route('/logout', methods=['GET', 'POST'])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
|
|
|
@ -149,19 +149,6 @@ class PD(BaseModel):
|
||||||
table_name = 'pd'
|
table_name = 'pd'
|
||||||
|
|
||||||
|
|
||||||
class ApiToken(BaseModel):
|
|
||||||
token = CharField()
|
|
||||||
user_name = CharField()
|
|
||||||
user_group_id = IntegerField()
|
|
||||||
user_role = IntegerField()
|
|
||||||
create_date = DateTimeField(default=datetime.now)
|
|
||||||
expire_date = DateTimeField(default=datetime.now)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
table_name = 'api_tokens'
|
|
||||||
primary_key = False
|
|
||||||
|
|
||||||
|
|
||||||
class Setting(BaseModel):
|
class Setting(BaseModel):
|
||||||
param = CharField()
|
param = CharField()
|
||||||
value = CharField(null=True)
|
value = CharField(null=True)
|
||||||
|
@ -804,7 +791,7 @@ def create_tables():
|
||||||
conn = connect()
|
conn = connect()
|
||||||
with conn:
|
with conn:
|
||||||
conn.create_tables(
|
conn.create_tables(
|
||||||
[User, Server, Role, Telegram, Slack, ApiToken, Groups, UserGroups, ConfigVersion, Setting, RoxyTool, Alerts,
|
[User, Server, Role, Telegram, Slack, Groups, UserGroups, ConfigVersion, Setting, RoxyTool, Alerts,
|
||||||
Cred, Backup, Metrics, WafMetrics, Version, Option, SavedServer, Waf, ActionHistory, PortScannerSettings,
|
Cred, Backup, Metrics, WafMetrics, Version, Option, SavedServer, Waf, ActionHistory, PortScannerSettings,
|
||||||
PortScannerPorts, PortScannerHistory, ServiceSetting, MetricsHttpStatus, SMON, WafRules, GeoipCodes,
|
PortScannerPorts, PortScannerHistory, ServiceSetting, MetricsHttpStatus, SMON, WafRules, GeoipCodes,
|
||||||
NginxMetrics, SystemInfo, Services, UserName, GitSetting, CheckerSetting, ApacheMetrics, WafNginx, ServiceStatus,
|
NginxMetrics, SystemInfo, Services, UserName, GitSetting, CheckerSetting, ApacheMetrics, WafNginx, ServiceStatus,
|
||||||
|
|
|
@ -3,20 +3,11 @@ from app.modules.db.common import out_error
|
||||||
from app.modules.roxywi.exception import RoxywiResourceNotFound
|
from app.modules.roxywi.exception import RoxywiResourceNotFound
|
||||||
|
|
||||||
|
|
||||||
def select_groups(**kwargs):
|
def select_groups():
|
||||||
if kwargs.get("group") is not None:
|
|
||||||
query = Groups.select().where(Groups.name == kwargs.get('group'))
|
|
||||||
elif kwargs.get("id") is not None:
|
|
||||||
query = Groups.select().where(Groups.group_id == kwargs.get('id'))
|
|
||||||
else:
|
|
||||||
query = Groups.select().order_by(Groups.group_id)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query_res = query.execute()
|
return Groups.select().order_by(Groups.group_id).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
else:
|
|
||||||
return query_res
|
|
||||||
|
|
||||||
|
|
||||||
def add_group(name: str, description: str) -> int:
|
def add_group(name: str, description: str) -> int:
|
||||||
|
@ -107,8 +98,6 @@ def delete_group_settings(group_id):
|
||||||
group_for_delete.execute()
|
group_for_delete.execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def update_group(name, descript, group_id):
|
def update_group(name, descript, group_id):
|
||||||
|
@ -117,24 +106,12 @@ def update_group(name, descript, group_id):
|
||||||
group_update.execute()
|
group_update.execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_group_name_by_id(group_id):
|
def get_group(group_id: int) -> Groups:
|
||||||
try:
|
try:
|
||||||
return Groups.get(Groups.group_id == group_id).name
|
return Groups.get(Groups.group_id == group_id)
|
||||||
except Groups.DoesNotExist:
|
except Groups.DoesNotExist:
|
||||||
raise RoxywiResourceNotFound
|
raise RoxywiResourceNotFound
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
|
|
||||||
|
|
||||||
def get_group_id_by_name(group_name):
|
|
||||||
try:
|
|
||||||
group_id = Groups.get(Groups.name == group_name)
|
|
||||||
except Exception as e:
|
|
||||||
out_error(e)
|
|
||||||
else:
|
|
||||||
return group_id.group_id
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from app.modules.db.db_model import UserName, RoxyTool, Version
|
from app.modules.db.db_model import UserName, RoxyTool, Version
|
||||||
from app.modules.db.common import out_error
|
from app.modules.db.common import out_error
|
||||||
|
|
||||||
|
@ -9,19 +11,9 @@ def insert_user_name(user_name):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def select_user_name():
|
|
||||||
try:
|
|
||||||
query_res = UserName.get().UserName
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return query_res
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_name(user_name):
|
def update_user_name(user_name):
|
||||||
user_update = UserName.update(UserName=user_name)
|
|
||||||
try:
|
try:
|
||||||
user_update.execute()
|
UserName.update(UserName=user_name).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
return False
|
return False
|
||||||
|
@ -30,46 +22,22 @@ def update_user_name(user_name):
|
||||||
|
|
||||||
|
|
||||||
def update_user_status(status, plan, method):
|
def update_user_status(status, plan, method):
|
||||||
user_update = UserName.update(Status=status, Method=method, Plan=plan)
|
|
||||||
try:
|
try:
|
||||||
user_update.execute()
|
UserName.update(Status=status, Method=method, Plan=plan).execute()
|
||||||
|
except Exception as e:
|
||||||
|
out_error(e)
|
||||||
|
|
||||||
|
|
||||||
|
def get_user() -> Union[UserName, bool]:
|
||||||
|
try:
|
||||||
|
return UserName.get()
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def select_user_status():
|
|
||||||
try:
|
|
||||||
query_res = UserName.get().Status
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return query_res
|
|
||||||
|
|
||||||
|
|
||||||
def select_user_plan():
|
|
||||||
try:
|
|
||||||
query_res = UserName.get().Plan
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return query_res
|
|
||||||
|
|
||||||
|
|
||||||
def select_user_all():
|
|
||||||
try:
|
|
||||||
query_res = UserName.select()
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return query_res
|
|
||||||
|
|
||||||
|
|
||||||
def get_roxy_tools():
|
def get_roxy_tools():
|
||||||
query = RoxyTool.select()
|
|
||||||
try:
|
try:
|
||||||
query_res = query.where(RoxyTool.is_roxy == 1).execute()
|
query_res = RoxyTool.select().where(RoxyTool.is_roxy == 1).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from peewee import Case, JOIN
|
from peewee import Case, JOIN
|
||||||
|
|
||||||
from app.modules.db.db_model import User, UserGroups, Groups, ApiToken
|
from app.modules.db.db_model import User, UserGroups, Groups
|
||||||
from app.modules.db.sql import get_setting
|
from app.modules.db.sql import get_setting
|
||||||
from app.modules.db.common import out_error
|
from app.modules.db.common import out_error
|
||||||
import app.modules.roxy_wi_tools as roxy_wi_tools
|
import app.modules.roxy_wi_tools as roxy_wi_tools
|
||||||
|
@ -29,13 +29,6 @@ def add_user(user, email, password, role, enabled, group):
|
||||||
return last_id
|
return last_id
|
||||||
|
|
||||||
|
|
||||||
def update_user(user, email, role, user_id, enabled):
|
|
||||||
try:
|
|
||||||
User.update(username=user, email=email, role_id=role, enabled=enabled).where(User.user_id == user_id).execute()
|
|
||||||
except Exception as e:
|
|
||||||
out_error(e)
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_from_admin_area(user_id, **kwargs):
|
def update_user_from_admin_area(user_id, **kwargs):
|
||||||
try:
|
try:
|
||||||
User.update(**kwargs).where(User.user_id == user_id).execute()
|
User.update(**kwargs).where(User.user_id == user_id).execute()
|
||||||
|
@ -85,11 +78,10 @@ def delete_user(user_id):
|
||||||
user_for_delete = User.delete().where(User.user_id == user_id)
|
user_for_delete = User.delete().where(User.user_id == user_id)
|
||||||
user_for_delete.execute()
|
user_for_delete.execute()
|
||||||
delete_user_groups(user_id)
|
delete_user_groups(user_id)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
raise RoxywiResourceNotFound
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_role(user_id: int, group_id: int, role_id: int) -> None:
|
def update_user_role(user_id: int, group_id: int, role_id: int) -> None:
|
||||||
|
|
|
@ -5,7 +5,6 @@ from flask_jwt_extended import verify_jwt_in_request
|
||||||
|
|
||||||
import app.modules.db.sql as sql
|
import app.modules.db.sql as sql
|
||||||
import app.modules.db.user as user_sql
|
import app.modules.db.user as user_sql
|
||||||
import app.modules.db.group as group_sql
|
|
||||||
import app.modules.db.service as service_sql
|
import app.modules.db.service as service_sql
|
||||||
import app.modules.roxywi.common as roxywi_common
|
import app.modules.roxywi.common as roxywi_common
|
||||||
import app.modules.roxy_wi_tools as roxy_wi_tools
|
import app.modules.roxy_wi_tools as roxy_wi_tools
|
||||||
|
@ -113,16 +112,6 @@ def do_login(user_params: dict, next_url: str):
|
||||||
access_token = create_jwt_token(user_params)
|
access_token = create_jwt_token(user_params)
|
||||||
set_access_cookies(response, access_token)
|
set_access_cookies(response, access_token)
|
||||||
|
|
||||||
try:
|
|
||||||
user_group_name = group_sql.get_group_name_by_id(user_params['group'])
|
|
||||||
except Exception:
|
|
||||||
user_group_name = ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
roxywi_common.logging('Roxy-WI server', f'user: {user_params["name"]}, group: {user_group_name} login', roxywi=1)
|
|
||||||
except Exception as e:
|
|
||||||
print(str(e))
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,12 @@ def get_user_group(**kwargs) -> int:
|
||||||
verify_jwt_in_request()
|
verify_jwt_in_request()
|
||||||
claims = get_jwt()
|
claims = get_jwt()
|
||||||
user_group_id = claims['group']
|
user_group_id = claims['group']
|
||||||
groups = group_sql.select_groups(id=user_group_id)
|
group = group_sql.get_group(user_group_id)
|
||||||
for group in groups:
|
if group.group_id == int(user_group_id):
|
||||||
if group.group_id == int(user_group_id):
|
if kwargs.get('id'):
|
||||||
if kwargs.get('id'):
|
user_group = group.group_id
|
||||||
user_group = group.group_id
|
else:
|
||||||
else:
|
user_group = group.name
|
||||||
user_group = group.name
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f'error: {e}')
|
raise Exception(f'error: {e}')
|
||||||
return user_group
|
return user_group
|
||||||
|
@ -273,8 +272,8 @@ def get_user_lang_for_flask() -> str:
|
||||||
|
|
||||||
def return_user_status() -> dict:
|
def return_user_status() -> dict:
|
||||||
user_subscription = {}
|
user_subscription = {}
|
||||||
user_subscription.setdefault('user_status', roxy_sql.select_user_status())
|
user_subscription.setdefault('user_status', roxy_sql.get_user().Status)
|
||||||
user_subscription.setdefault('user_plan', roxy_sql.select_user_plan())
|
user_subscription.setdefault('user_plan', roxy_sql.get_user().Plan)
|
||||||
|
|
||||||
return user_subscription
|
return user_subscription
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,11 @@ def update_group(group_id: int, group_name: str, desc: str) -> None:
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
|
|
||||||
def delete_group(group_id: int) -> str:
|
def delete_group(group_id: int) -> None:
|
||||||
group = group_sql.select_groups(id=group_id)
|
group_name = group_sql.get_group(group_id).name
|
||||||
group_name = ''
|
|
||||||
|
|
||||||
for g in group:
|
try:
|
||||||
group_name = g.name
|
group_sql.delete_group(group_id)
|
||||||
|
|
||||||
if group_sql.delete_group(group_id):
|
|
||||||
roxywi_common.logging('Roxy-WI server', f'The {group_name} has been deleted', roxywi=1, login=1)
|
roxywi_common.logging('Roxy-WI server', f'The {group_name} has been deleted', roxywi=1, login=1)
|
||||||
return 'ok'
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
|
@ -37,7 +37,7 @@ def user_owv() -> str:
|
||||||
def show_sub_ovw() -> str:
|
def show_sub_ovw() -> str:
|
||||||
lang = roxywi_common.get_user_lang_for_flask()
|
lang = roxywi_common.get_user_lang_for_flask()
|
||||||
|
|
||||||
return render_template('ajax/show_sub_ovw.html', sub=roxy_sql.select_user_all(), lang=lang)
|
return render_template('ajax/show_sub_ovw.html', sub=roxy_sql.get_user(), lang=lang)
|
||||||
|
|
||||||
|
|
||||||
def show_overview(serv) -> str:
|
def show_overview(serv) -> str:
|
||||||
|
|
|
@ -102,7 +102,7 @@ def action_service(action: str, service: str) -> str:
|
||||||
'restart': 'restart',
|
'restart': 'restart',
|
||||||
}
|
}
|
||||||
cmd = f"sudo systemctl {actions[action]} {service}"
|
cmd = f"sudo systemctl {actions[action]} {service}"
|
||||||
if not roxy_sql.select_user_status():
|
if not roxy_sql.get_user().Status:
|
||||||
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
|
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
|
||||||
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
|
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
|
||||||
if is_in_docker:
|
if is_in_docker:
|
||||||
|
@ -138,7 +138,7 @@ def update_plan():
|
||||||
else:
|
else:
|
||||||
user_name = 'git'
|
user_name = 'git'
|
||||||
|
|
||||||
if roxy_sql.select_user_name():
|
if roxy_sql.get_user().UserName:
|
||||||
roxy_sql.update_user_name(user_name)
|
roxy_sql.update_user_name(user_name)
|
||||||
else:
|
else:
|
||||||
roxy_sql.insert_user_name(user_name)
|
roxy_sql.insert_user_name(user_name)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from flask import render_template, make_response
|
from flask import render_template, make_response
|
||||||
|
|
||||||
|
@ -9,27 +10,27 @@ import app.modules.roxywi.common as roxywi_common
|
||||||
import app.modules.tools.alerting as alerting
|
import app.modules.tools.alerting as alerting
|
||||||
|
|
||||||
|
|
||||||
def create_user(new_user: str, email: str, password: str, role: int, enabled: int, group: int) -> int:
|
def create_user(new_user: str, email: str, password: str, role: int, enabled: int, group: int) -> Union[int, tuple]:
|
||||||
try:
|
try:
|
||||||
user_id = user_sql.add_user(new_user, email, password, role, enabled, group)
|
user_id = user_sql.add_user(new_user, email, password, role, enabled, group)
|
||||||
roxywi_common.logging(f'a new user {new_user}', 'has been created', roxywi=1, login=1)
|
roxywi_common.logging(f'a new user {new_user}', 'has been created', roxywi=1, login=1)
|
||||||
try:
|
|
||||||
user_sql.update_user_role(user_id, group, role)
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception(f'error: cannot update user role {e}')
|
|
||||||
try:
|
|
||||||
if password == 'aduser':
|
|
||||||
password = 'your domain password'
|
|
||||||
message = f"A user has been created for you on Roxy-WI portal!\n\n" \
|
|
||||||
f"Now you can login to https://{os.environ.get('HTTP_HOST', '')}\n\n" \
|
|
||||||
f"Your credentials are:\n" \
|
|
||||||
f"Login: {new_user}\n" \
|
|
||||||
f"Password: {password}"
|
|
||||||
alerting.send_email(email, 'A user has been created for you', message)
|
|
||||||
except Exception as e:
|
|
||||||
roxywi_common.logging('error: Cannot send email for a new user', e, roxywi=1, login=1)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot create a new user', roxywi=1, login=1)
|
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot create a new user')
|
||||||
|
try:
|
||||||
|
user_sql.update_user_role(user_id, group, role)
|
||||||
|
except Exception as e:
|
||||||
|
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot update user role')
|
||||||
|
try:
|
||||||
|
if password == 'aduser':
|
||||||
|
password = 'your domain password'
|
||||||
|
message = f"A user has been created for you on Roxy-WI portal!\n\n" \
|
||||||
|
f"Now you can login to https://{os.environ.get('HTTP_HOST', '')}\n\n" \
|
||||||
|
f"Your credentials are:\n" \
|
||||||
|
f"Login: {new_user}\n" \
|
||||||
|
f"Password: {password}"
|
||||||
|
alerting.send_email(email, 'A user has been created for you', message)
|
||||||
|
except Exception as e:
|
||||||
|
roxywi_common.logging('error: Cannot send email for a new user', str(e), roxywi=1, login=1)
|
||||||
|
|
||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
|
@ -39,10 +40,13 @@ def delete_user(user_id: int):
|
||||||
count_super_admin_users = user_sql.get_super_admin_count()
|
count_super_admin_users = user_sql.get_super_admin_count()
|
||||||
if count_super_admin_users < 2:
|
if count_super_admin_users < 2:
|
||||||
raise Exception('error: you cannot delete a last user with superAdmin role')
|
raise Exception('error: you cannot delete a last user with superAdmin role')
|
||||||
user = user_sql.get_user_id(user_id)
|
try:
|
||||||
if user_sql.delete_user(user_id):
|
user = user_sql.get_user_id(user_id)
|
||||||
|
user_sql.delete_user(user_id)
|
||||||
user_sql.delete_user_groups(user_id)
|
user_sql.delete_user_groups(user_id)
|
||||||
roxywi_common.logging(user.username, 'has been deleted user', roxywi=1, login=1)
|
roxywi_common.logging(user.username, 'has been deleted user', roxywi=1, login=1)
|
||||||
|
except Exception as e:
|
||||||
|
return roxywi_common.handler_exceptions_for_json_data(e)
|
||||||
|
|
||||||
|
|
||||||
def update_user_password(password, user_id):
|
def update_user_password(password, user_id):
|
||||||
|
@ -83,26 +87,11 @@ def change_user_active_group(group_id: int, user_id: int) -> str:
|
||||||
|
|
||||||
|
|
||||||
def get_user_active_group(group_id: int, user_id: int) -> str:
|
def get_user_active_group(group_id: int, user_id: int) -> str:
|
||||||
# group_id = user_sql.get_user_id_by_uuid(uuid)
|
|
||||||
groups = user_sql.select_user_groups_with_names(user_id)
|
groups = user_sql.select_user_groups_with_names(user_id)
|
||||||
lang = roxywi_common.get_user_lang_for_flask()
|
lang = roxywi_common.get_user_lang_for_flask()
|
||||||
return render_template('ajax/user_current_group.html', groups=groups, group=group_id, lang=lang)
|
return render_template('ajax/user_current_group.html', groups=groups, group=group_id, lang=lang)
|
||||||
|
|
||||||
|
|
||||||
# def show_user_groups_and_roles(user_id: int, lang: str) -> str:
|
|
||||||
# groups = user_sql.select_user_groups_with_names(user_id, user_not_in_group=1)
|
|
||||||
# roles = sql.select_roles()
|
|
||||||
# user_groups = user_sql.select_user_groups_with_names(user_id)
|
|
||||||
# return render_template('ajax/user_groups_and_roles.html', groups=groups, user_groups=user_groups, roles=roles, lang=lang)
|
|
||||||
|
|
||||||
|
|
||||||
# def is_current_user(user_id: int, user_uuid: str) -> bool:
|
|
||||||
# current_user_id = user_sql.get_user_id_by_uuid(user_uuid)
|
|
||||||
# if current_user_id == user_id:
|
|
||||||
# return True
|
|
||||||
# return False
|
|
||||||
|
|
||||||
|
|
||||||
def save_user_group_and_role(user: str, groups_and_roles: dict):
|
def save_user_group_and_role(user: str, groups_and_roles: dict):
|
||||||
resp = make_response('ok')
|
resp = make_response('ok')
|
||||||
for k, v in groups_and_roles.items():
|
for k, v in groups_and_roles.items():
|
||||||
|
|
|
@ -93,7 +93,7 @@ def create_ssh_cred(name: str, password: str, group: int, username: str, enable:
|
||||||
def upload_ssh_key(ssh_id: int, key: str, passphrase: str) -> None:
|
def upload_ssh_key(ssh_id: int, key: str, passphrase: str) -> None:
|
||||||
key = key.replace("'", "")
|
key = key.replace("'", "")
|
||||||
ssh = cred_sql.get_ssh(ssh_id)
|
ssh = cred_sql.get_ssh(ssh_id)
|
||||||
group_name = group_sql.get_group_name_by_id(ssh.group_id)
|
group_name = group_sql.get_group(ssh.group_id).name
|
||||||
lib_path = get_config.get_config_var('main', 'lib_path')
|
lib_path = get_config.get_config_var('main', 'lib_path')
|
||||||
full_dir = f'{lib_path}/keys/'
|
full_dir = f'{lib_path}/keys/'
|
||||||
name = ssh.name
|
name = ssh.name
|
||||||
|
@ -242,7 +242,7 @@ def get_creds(group_id: int = None, cred_id: int = None, not_shared: bool = Fals
|
||||||
|
|
||||||
def _return_correct_ssh_file(cred: CredRequest) -> str:
|
def _return_correct_ssh_file(cred: CredRequest) -> str:
|
||||||
lib_path = get_config.get_config_var('main', 'lib_path')
|
lib_path = get_config.get_config_var('main', 'lib_path')
|
||||||
group_name = group_sql.get_group_name_by_id(cred.group_id)
|
group_name = group_sql.get_group(cred.group_id).name
|
||||||
if group_name not in cred.name:
|
if group_name not in cred.name:
|
||||||
return f'{lib_path}/keys/{cred.name}_{group_name}.pem'
|
return f'{lib_path}/keys/{cred.name}_{group_name}.pem'
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from matplotlib.artist import kwdoc
|
|
||||||
|
|
||||||
import app.modules.db.server as server_sql
|
import app.modules.db.server as server_sql
|
||||||
import app.modules.db.ha_cluster as ha_sql
|
import app.modules.db.ha_cluster as ha_sql
|
||||||
import app.modules.db.service as service_sql
|
import app.modules.db.service as service_sql
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
{% import 'languages/'+lang|default('en')+'.html' as lang %}
|
{% import 'languages/'+lang|default('en')+'.html' as lang %}
|
||||||
{% for s in sub %}
|
{% if sub.Plan == 'user' %}
|
||||||
{% if s.Plan == 'user' %}
|
|
||||||
{% set plan = 'Home' %}
|
{% set plan = 'Home' %}
|
||||||
{% elif s.Plan == 'company' %}
|
{% elif sub.Plan == 'company' %}
|
||||||
{% set plan = 'Enterprise' %}
|
{% set plan = 'Enterprise' %}
|
||||||
{% elif s.Plan == 'cloud' %}
|
{% elif sub.Plan == 'cloud' %}
|
||||||
{% set plan = 'Cloud' %}
|
{% set plan = 'Cloud' %}
|
||||||
{% elif s.Plan == 'support' %}
|
{% elif sub.Plan == 'support' %}
|
||||||
{% set plan = 'Premium' %}
|
{% set plan = 'Premium' %}
|
||||||
{% elif s.Plan == 'Trial' %}
|
{% elif sub.Plan == 'Trial' %}
|
||||||
{% set plan = 'Trial' %}
|
{% set plan = 'Trial' %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set plan = 'Free' %}
|
{% set plan = 'Free' %}
|
||||||
|
@ -24,7 +23,7 @@
|
||||||
N/A
|
N/A
|
||||||
{% else %}
|
{% else %}
|
||||||
<span
|
<span
|
||||||
{% if s.Status|int() == 1 %}
|
{% if sub.Status|int() == 1 %}
|
||||||
style="color: var(--green-color); font-weight: bold">{{lang.words.active|title()}}
|
style="color: var(--green-color); font-weight: bold">{{lang.words.active|title()}}
|
||||||
{% else %}
|
{% else %}
|
||||||
style="color: var(--red-color); font-weight: bold">Blocked
|
style="color: var(--red-color); font-weight: bold">Blocked
|
||||||
|
@ -39,14 +38,13 @@
|
||||||
{% if plan == 'Free' %}
|
{% if plan == 'Free' %}
|
||||||
N/A
|
N/A
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if s.Method == 'Boosty' %}
|
{% if sub.Method == 'Boosty' %}
|
||||||
<a href="https://boosty.to/roxy-wi" title="Boosty.to" class="logs_link" target="_blank">Boosty</a>
|
<a href="https://boosty.to/roxy-wi" title="Boosty.to" class="logs_link" target="_blank">Boosty</a>
|
||||||
{% elif s.Method == 'Patreon' %}
|
{% elif sub.Method == 'Patreon' %}
|
||||||
<a href="https://www.patreon.com/roxy_wi" title="Patreon.con" class="logs_link" target="_blank">Patreon</a>
|
<a href="https://www.patreon.com/roxy_wi" title="Patreon.con" class="logs_link" target="_blank">Patreon</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{s.Method}}
|
{{sub.Method}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
|
||||||
|
|
|
@ -176,6 +176,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
{%- for server in servers %}
|
{%- for server in servers %}
|
||||||
|
sessionStorage.removeItem('server-{{ server.0 }}')
|
||||||
setInterval(serverIsUp, 18000, '{{server.0}}');
|
setInterval(serverIsUp, 18000, '{{server.0}}');
|
||||||
serverIsUp('{{server.0}}');
|
serverIsUp('{{server.0}}');
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
@ -458,9 +458,8 @@ class ServerGroupView(MethodView):
|
||||||
description: 'Server group not found'
|
description: 'Server group not found'
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
groups = group_sql.select_groups(id=group_id)
|
group = group_sql.get_group(group_id)
|
||||||
for group in groups:
|
return model_to_dict(group)
|
||||||
return model_to_dict(group)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot get group')
|
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot get group')
|
||||||
|
|
||||||
|
@ -564,9 +563,7 @@ class ServerGroupView(MethodView):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_is_user_and_group(group_id: int):
|
def _check_is_user_and_group(group_id: int):
|
||||||
try:
|
try:
|
||||||
groups = group_sql.get_group_name_by_id(group_id)
|
group_sql.get_group(group_id)
|
||||||
if len(groups) == 0:
|
|
||||||
raise RoxywiResourceNotFound
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
|
@ -485,9 +485,7 @@ class UserGroupView(MethodView):
|
||||||
def _check_is_user_and_group(user_id: int, group_id: int):
|
def _check_is_user_and_group(user_id: int, group_id: int):
|
||||||
try:
|
try:
|
||||||
_ = user_sql.get_user_id(user_id)
|
_ = user_sql.get_user_id(user_id)
|
||||||
groups = group_sql.get_group_name_by_id(group_id)
|
group_sql.get_group(group_id)
|
||||||
if len(groups) == 0:
|
|
||||||
raise RoxywiResourceNotFound
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue