mirror of https://github.com/Aidaho12/haproxy-wi
v8.1.2: Remove unused imports and simplify user status checks
Removed the unused 'distro' and 'Union' imports for code cleanliness. Simplified the user status check mechanism by introducing a direct method, `get_user_status`, and modified the service control flow accordingly. Simplified 'update_plan' function to only insert a default username.pull/401/head
parent
0128321642
commit
61ed3e92c3
|
@ -1,5 +1,3 @@
|
|||
from typing import Union
|
||||
|
||||
from app.modules.db.db_model import UserName, RoxyTool, Version
|
||||
from app.modules.db.common import out_error
|
||||
|
||||
|
@ -28,11 +26,18 @@ def update_user_status(status, plan, method):
|
|||
out_error(e)
|
||||
|
||||
|
||||
def get_user() -> Union[UserName, bool]:
|
||||
def get_user() -> UserName:
|
||||
try:
|
||||
return UserName.get()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
|
||||
def get_user_status() -> int:
|
||||
try:
|
||||
return UserName.get().Status
|
||||
except Exception:
|
||||
return False
|
||||
return 0
|
||||
|
||||
|
||||
def get_roxy_tools():
|
||||
|
|
|
@ -2,7 +2,6 @@ import os
|
|||
import re
|
||||
from packaging import version
|
||||
|
||||
import distro
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
from requests.packages.urllib3.util.retry import Retry
|
||||
|
@ -102,7 +101,7 @@ def action_service(action: str, service: str) -> str:
|
|||
'restart': 'restart',
|
||||
}
|
||||
cmd = f"sudo systemctl {actions[action]} {service}"
|
||||
if not roxy_sql.get_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" ' \
|
||||
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
|
||||
if is_in_docker:
|
||||
|
@ -113,36 +112,5 @@ def action_service(action: str, service: str) -> str:
|
|||
|
||||
|
||||
def update_plan():
|
||||
try:
|
||||
if distro.id() == 'ubuntu':
|
||||
path_to_repo = '/etc/apt/auth.conf.d/roxy-wi.conf'
|
||||
cmd = "grep login /etc/apt/auth.conf.d/roxy-wi.conf |awk '{print $2}'"
|
||||
cmd2 = "grep password /etc/apt/auth.conf.d/roxy-wi.conf |awk '{print $2}'"
|
||||
else:
|
||||
path_to_repo = '/etc/yum.repos.d/roxy-wi.repo'
|
||||
cmd = "grep base /etc/yum.repos.d/roxy-wi.repo |grep -v '#' |awk -F\":\" '{print $2}'|awk -F\"/\" '{print $3}'"
|
||||
cmd2 = "grep base /etc/yum.repos.d/roxy-wi.repo |grep -v '#' |awk -F\":\" '{print $3}'|awk -F\"@\" '{print $1}'"
|
||||
if os.path.exists(path_to_repo):
|
||||
get_user_name, stderr = server_mod.subprocess_execute(cmd)
|
||||
user_name = get_user_name[0]
|
||||
cur_license = sql.get_setting('license')
|
||||
if not cur_license:
|
||||
get_license, stderr = server_mod.subprocess_execute(cmd2)
|
||||
user_license = get_license[0]
|
||||
|
||||
if user_license:
|
||||
try:
|
||||
sql.update_setting('license', user_license, 1)
|
||||
except Exception as e:
|
||||
roxywi_common.logging('Roxy-WI server', f'error: Cannot update license {e}', roxywi=1)
|
||||
else:
|
||||
user_name = 'git'
|
||||
|
||||
if roxy_sql.get_user().UserName:
|
||||
roxy_sql.update_user_name(user_name)
|
||||
else:
|
||||
roxy_sql.insert_user_name(user_name)
|
||||
except Exception as e:
|
||||
roxywi_common.logging('Cannot update subscription: ', str(e), roxywi=1)
|
||||
|
||||
roxy_sql.insert_user_name('user')
|
||||
update_user_status()
|
||||
|
|
Loading…
Reference in New Issue