Changelog: https://roxy-wi.org/changelog.py#6
pull/321/head
Pavel Loginov 2022-04-23 20:40:27 +03:00
parent 66ac5edf61
commit c3ec003f69
8 changed files with 115 additions and 18 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -4,7 +4,7 @@
{% if s.1.0 == 'active' %}
<span title="{{s.0}} is started"><span class="serverUp server-status"></span></span>
{% 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 %}
<span title="{{s.0}} is stopped"><span class="serverDown server-status"></span></span>
{% else %}
<span title="{{s.0}} is not installed"><span class="serverNone server-status"></span></span>
@ -13,6 +13,9 @@
{{s.0[0]|upper}}{{s.0[1:]}}
</td>
<td class="padding10 first-collumn">
{% if 'is not installed' in s.3 %}
<a href="https://roxy-wi.org/services.py?service={{s.0.split('-')[2]}}#installation" title="{{s.0.split('-')[2]}} installation" target="_blank" class="link">Read about installation</a>
{% else %}
<a id="start-{{ s.0 }}" class="start" title="Start and enable {{s.0}} service">
<span class="service-start" onclick="confirmAjaxServiceAction('start', '{{s.0}}')"></span>
</a>
@ -22,9 +25,10 @@
<a id="stop-{{ s.0 }}" class="stop" title="Stop and disable {{s.0}} service">
<span class="service-stop" onclick="confirmAjaxServiceAction('stop', '{{s.0}}')"></span>
</a>
{% endif %}
</td>
<td>
{% if s.3 != '* is not installed' %}
{% if 'is not installed' not in s.3 %}
{{ s.3 }}
{% endif %}
</td>

View File

@ -115,12 +115,11 @@
</b>
</td>
<td>
{% if s.3 != '* is not installed' %}
{% if 'is not installed' not in s.3 %}
{% if is_need_update %}
<a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{s.0}}')" title="Update {{service_name}}">Update</a>
{% endif %}
{% else %}
{{service_name}} service is not installed
<a href="https://roxy-wi.org/services.py?service={{service_link}}#installation" title="{{service_name}} installation" target="_blank" class="link">Read about installation</a>
{% endif %}
</td>

View File

@ -10,7 +10,7 @@
<script src="/inc/codemirror/searchcursor.js"></script>
<script src="/inc/codemirror/jump-to-line.js"></script>
<script src="/inc/configshow.js"></script>
{% if is_serv_protected %}
{% if is_serv_protected and role > 2 %}
<meta http-equiv="refresh" content="0; url=/app/hapservers.py?service={{service}}">
{% else %}
<center>

View File

@ -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 @@
<span class="service-stop" onclick="confirmAjaxAction('stop', '{{action_service}}', '{{s.2}}')"></span>
</a>
<a href="history.py?service={{service}}&serv={{s.2}}" title="View history for this service" class="history" style="margin: 0 5px 0 10px;"></a>
{% if service != 'keepalived' and service != 'apache' %}
{% if service != 'keepalived' %}
<span class="menu-bar" onclick="serverSettings('{{s.0}}', '{{s.1}}')" title="Edit settings for {{s.1}} service"></span>
{% endif %}
</span>

View File

@ -233,7 +233,7 @@
SMON
</a>
{% else %}
{% if smon == 'inactive' or smon== 'failed' %}
{% if smon == 'inactive' or smon == 'failed' %}
<span class="serverDown server-status" title="SMON is stopped"></span>
<a href="/app/users.py#services" title="Start SMON - Roxy-WI service" class="logs_link">
SMON