diff --git a/app/funct.py b/app/funct.py index a728de96..b758e047 100644 --- a/app/funct.py +++ b/app/funct.py @@ -1512,16 +1512,25 @@ def check_new_version(**kwargs): else: last_ver = '' + user_name = sql.select_user_name() + try: if proxy is not None and proxy != '' and proxy != 'None': proxy_dict = {"https": proxy, "http": proxy} response = requests.get('https://roxy-wi.org/update.py?last_ver'+last_ver+'=1', timeout=1, proxies=proxy_dict) requests.get('https://roxy-wi.org/update.py?ver_send='+current_ver, timeout=1, proxies=proxy_dict) + response_status = requests.get('https://roxy-wi.org/update.py?user_name='+user_name, timeout=1, proxies=proxy_dict) else: response = requests.get('https://roxy-wi.org/update.py?last_ver'+last_ver+'=1', timeout=1) requests.get('https://roxy-wi.org/update.py?ver_send='+current_ver, timeout=1) + response_status = requests.get('https://roxy-wi.org/update.py?user_name=' + user_name, timeout=1) res = response.content.decode(encoding='UTF-8') + try: + status = response_status.content.decode(encoding='UTF-8') + sql.update_user_status(status) + except: + pass except requests.exceptions.RequestException as e: logging('localhost', ' '+str(e), haproxywi=1) @@ -1691,6 +1700,7 @@ def get_services_status(): cmd = "apt list --installed 2>&1 |grep " + service_name + "|awk '{print $2}'|sed 's/-/./'" else: cmd = "rpm -q " + service_name + "|awk -F\"" + service_name + "\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'" + print(cmd) service_ver, stderr = subprocess_execute(cmd) try: @@ -1936,7 +1946,7 @@ def string_to_dict(dict_string) -> dict: return literal_eval(dict_string) -def send_message_to_rabbit(message: str) -> None: +def send_message_to_rabbit(message: str, **kwargs) -> None: import pika import sql rabbit_user = sql.get_setting('rabbitmq_user') @@ -1944,7 +1954,10 @@ def send_message_to_rabbit(message: str) -> None: rabbit_host = sql.get_setting('rabbitmq_host') rabbit_port = sql.get_setting('rabbitmq_port') rabbit_vhost = sql.get_setting('rabbitmq_vhost') - rabbit_queue = sql.get_setting('rabbitmq_queue') + if kwargs.get('rabbit_queue'): + rabbit_queue = kwargs.get('rabbit_queue') + else: + rabbit_queue = sql.get_setting('rabbitmq_queue') credentials = pika.PlainCredentials(rabbit_user, rabbit_password) parameters = pika.ConnectionParameters(rabbit_host, @@ -1957,7 +1970,7 @@ def send_message_to_rabbit(message: str) -> None: channel = connection.channel() channel.queue_declare(queue=rabbit_queue) channel.basic_publish(exchange='', - routing_key='roxy-wi', + routing_key=rabbit_queue, body=message) connection.close() diff --git a/app/login.py b/app/login.py index be620cb5..7bde7c29 100644 --- a/app/login.py +++ b/app/login.py @@ -9,6 +9,7 @@ import sql import create_db import datetime import uuid +import distro from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('login.html') @@ -16,9 +17,14 @@ form = funct.form cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) user_id = cookie.get('uuid') -ref = form.getvalue('ref') -login = form.getvalue('login') -password = form.getvalue('pass') +try: + ref = form.getvalue('ref') + login = form.getvalue('login') + password = form.getvalue('pass') +except Exception: + ref = '' + login = '' + password = '' db_create = "" error_log = "" error = "" @@ -73,6 +79,29 @@ def send_cookie(login): pass print("Content-type: text/html\n") print('ok') + + try: + if distro.id() == 'ubuntu': + if os.path.exists('/etc/apt/auth.conf.d/roxy-wi.conf'): + cmd = "grep login /etc/apt/auth.conf.d/roxy-wi.conf |awk '{print $2}'" + get_user_name, stderr = funct.subprocess_execute(cmd) + user_name = get_user_name[0] + else: + user_name = 'git' + else: + if os.path.exists('/etc/yum.repos.d/roxy-wi.repo'): + cmd = "grep base /etc/yum.repos.d/roxy-wi.repo |awk -F\":\" '{print $2}'|awk -F\"/\" '{print $3}'" + get_user_name, stderr = funct.subprocess_execute(cmd) + user_name = get_user_name[0] + else: + user_name = 'git' + if sql.select_user_name(): + sql.update_user_name(user_name) + else: + sql.insert_user_name(user_name) + except Exception: + pass + sys.exit() diff --git a/app/sql.py b/app/sql.py index 5cdf9e42..d46cfdb9 100755 --- a/app/sql.py +++ b/app/sql.py @@ -273,7 +273,7 @@ def delete_server(server_id): def update_hapwi_server(server_id, alert, metrics, active, service_name): try: if service_name == 'nginx': - update_hapwi = Server.update(nginx_alert=alert, metrics=metrics, nginx_active=active, + update_hapwi = Server.update(nginx_alert=alert, nginx_active=active, nginx_metrics=metrics).where(Server.server_id == server_id) elif service_name == 'keepalived': update_hapwi = Server.update(keepalived_alert=alert, keepalived_active=active).where( @@ -3133,3 +3133,55 @@ def select_services(): return else: return query_res + + +def insert_user_name(user_name): + try: + UserName.insert(UserName=user_name).execute() + except Exception as e: + out_error(e) + return False + else: + return True + + +def select_user_name(): + try: + query_res = UserName.get().UserName + except Exception as e: + out_error(e) + return False + else: + return query_res + + +def update_user_name(user_name): + user_update = UserName.update(UserName=user_name) + try: + user_update.execute() + except Exception as e: + out_error(e) + return False + else: + return True + + +def update_user_status(status): + user_update = UserName.update(Status=status) + try: + user_update.execute() + except Exception as e: + out_error(e) + return False + else: + return True + + +def select_user_status(): + try: + query_res = UserName.get().Status + except Exception as e: + out_error(e) + return False + else: + return query_res diff --git a/app/templates/ajax/load_services.html b/app/templates/ajax/load_services.html index b5df8219..787a57fb 100644 --- a/app/templates/ajax/load_services.html +++ b/app/templates/ajax/load_services.html @@ -4,7 +4,7 @@ {% if s.1.0 == 'active' %} {% else %} - {% if s.1.0 == 'inactive' or s.1.0 == 'failed' or s.1.0 == 'activating' %} + {% if (s.1.0 == 'inactive' or s.1.0 == 'failed' or s.1.0 == 'activating') and 'is not installed' not in s.3 %} {% else %} @@ -13,6 +13,9 @@ {{s.0[0]|upper}}{{s.0[1:]}} + {% if 'is not installed' in s.3 %} + Read about installation + {% else %} @@ -22,9 +25,10 @@ + {% endif %} - {% if s.3 != '* is not installed' %} + {% if 'is not installed' not in s.3 %} {{ s.3 }} {% endif %} diff --git a/app/templates/ajax/load_updatehapwi.html b/app/templates/ajax/load_updatehapwi.html index 1de0d610..b22ccd34 100644 --- a/app/templates/ajax/load_updatehapwi.html +++ b/app/templates/ajax/load_updatehapwi.html @@ -115,12 +115,11 @@ - {% if s.3 != '* is not installed' %} + {% if 'is not installed' not in s.3 %} {% if is_need_update %} Update {% endif %} {% else %} - {{service_name}} service is not installed Read about installation {% endif %} diff --git a/app/templates/config.html b/app/templates/config.html index 366605d8..322586cc 100644 --- a/app/templates/config.html +++ b/app/templates/config.html @@ -10,7 +10,7 @@ -{% if is_serv_protected %} +{% if is_serv_protected and role > 2 %} {% else %}
diff --git a/app/templates/hapservers.html b/app/templates/hapservers.html index 90888ead..2417901f 100644 --- a/app/templates/hapservers.html +++ b/app/templates/hapservers.html @@ -39,12 +39,12 @@ } }); {% for s in services %} - {% if s.1 == '* is not installed' or s.1 == '' %} - {% if s.0 == 'checker_haproxy' %} + {% if 'is not installed' in s.1 or s.1 == '' %} + {% if s.0 == 'roxy-wi-checker' %} $(':regex(id, alert)').checkboxradio('disable'); - {% elif s.0 == 'keep_alive' %} + {% elif s.0 == 'rpxy-wi-keep_alive' %} $(':regex(id, active-)').checkboxradio('disable'); - {% elif s.0 == 'metrics_haproxy' %} + {% elif s.0 == 'roxy-wi-metrics' %} $(':regex(id, metrics-)').checkboxradio('disable'); {% endif %} {% endif %} @@ -174,7 +174,7 @@ - {% if service != 'keepalived' and service != 'apache' %} + {% if service != 'keepalived' %} {% endif %} diff --git a/app/templates/ovw.html b/app/templates/ovw.html index ed566236..f200641a 100644 --- a/app/templates/ovw.html +++ b/app/templates/ovw.html @@ -233,7 +233,7 @@ SMON {% else %} - {% if smon == 'inactive' or smon== 'failed' %} + {% if smon == 'inactive' or smon == 'failed' %} SMON