mirror of https://github.com/Aidaho12/haproxy-wi
parent
66ac5edf61
commit
c3ec003f69
19
app/funct.py
19
app/funct.py
|
@ -1512,16 +1512,25 @@ def check_new_version(**kwargs):
|
||||||
else:
|
else:
|
||||||
last_ver = ''
|
last_ver = ''
|
||||||
|
|
||||||
|
user_name = sql.select_user_name()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if proxy is not None and proxy != '' and proxy != 'None':
|
if proxy is not None and proxy != '' and proxy != 'None':
|
||||||
proxy_dict = {"https": proxy, "http": proxy}
|
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)
|
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)
|
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:
|
else:
|
||||||
response = requests.get('https://roxy-wi.org/update.py?last_ver'+last_ver+'=1', timeout=1)
|
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)
|
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')
|
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:
|
except requests.exceptions.RequestException as e:
|
||||||
logging('localhost', ' '+str(e), haproxywi=1)
|
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/-/./'"
|
cmd = "apt list --installed 2>&1 |grep " + service_name + "|awk '{print $2}'|sed 's/-/./'"
|
||||||
else:
|
else:
|
||||||
cmd = "rpm -q " + service_name + "|awk -F\"" + service_name + "\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'"
|
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)
|
service_ver, stderr = subprocess_execute(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1936,7 +1946,7 @@ def string_to_dict(dict_string) -> dict:
|
||||||
return literal_eval(dict_string)
|
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 pika
|
||||||
import sql
|
import sql
|
||||||
rabbit_user = sql.get_setting('rabbitmq_user')
|
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_host = sql.get_setting('rabbitmq_host')
|
||||||
rabbit_port = sql.get_setting('rabbitmq_port')
|
rabbit_port = sql.get_setting('rabbitmq_port')
|
||||||
rabbit_vhost = sql.get_setting('rabbitmq_vhost')
|
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)
|
credentials = pika.PlainCredentials(rabbit_user, rabbit_password)
|
||||||
parameters = pika.ConnectionParameters(rabbit_host,
|
parameters = pika.ConnectionParameters(rabbit_host,
|
||||||
|
@ -1957,7 +1970,7 @@ def send_message_to_rabbit(message: str) -> None:
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
channel.queue_declare(queue=rabbit_queue)
|
channel.queue_declare(queue=rabbit_queue)
|
||||||
channel.basic_publish(exchange='',
|
channel.basic_publish(exchange='',
|
||||||
routing_key='roxy-wi',
|
routing_key=rabbit_queue,
|
||||||
body=message)
|
body=message)
|
||||||
|
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
35
app/login.py
35
app/login.py
|
@ -9,6 +9,7 @@ import sql
|
||||||
import create_db
|
import create_db
|
||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
import distro
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
|
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
|
||||||
template = env.get_template('login.html')
|
template = env.get_template('login.html')
|
||||||
|
@ -16,9 +17,14 @@ form = funct.form
|
||||||
|
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
user_id = cookie.get('uuid')
|
user_id = cookie.get('uuid')
|
||||||
ref = form.getvalue('ref')
|
try:
|
||||||
login = form.getvalue('login')
|
ref = form.getvalue('ref')
|
||||||
password = form.getvalue('pass')
|
login = form.getvalue('login')
|
||||||
|
password = form.getvalue('pass')
|
||||||
|
except Exception:
|
||||||
|
ref = ''
|
||||||
|
login = ''
|
||||||
|
password = ''
|
||||||
db_create = ""
|
db_create = ""
|
||||||
error_log = ""
|
error_log = ""
|
||||||
error = ""
|
error = ""
|
||||||
|
@ -73,6 +79,29 @@ def send_cookie(login):
|
||||||
pass
|
pass
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
print('ok')
|
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()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
54
app/sql.py
54
app/sql.py
|
@ -273,7 +273,7 @@ def delete_server(server_id):
|
||||||
def update_hapwi_server(server_id, alert, metrics, active, service_name):
|
def update_hapwi_server(server_id, alert, metrics, active, service_name):
|
||||||
try:
|
try:
|
||||||
if service_name == 'nginx':
|
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)
|
nginx_metrics=metrics).where(Server.server_id == server_id)
|
||||||
elif service_name == 'keepalived':
|
elif service_name == 'keepalived':
|
||||||
update_hapwi = Server.update(keepalived_alert=alert, keepalived_active=active).where(
|
update_hapwi = Server.update(keepalived_alert=alert, keepalived_active=active).where(
|
||||||
|
@ -3133,3 +3133,55 @@ def select_services():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
return query_res
|
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
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{% if s.1.0 == 'active' %}
|
{% if s.1.0 == 'active' %}
|
||||||
<span title="{{s.0}} is started"><span class="serverUp server-status"></span></span>
|
<span title="{{s.0}} is started"><span class="serverUp server-status"></span></span>
|
||||||
{% else %}
|
{% 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>
|
<span title="{{s.0}} is stopped"><span class="serverDown server-status"></span></span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span title="{{s.0}} is not installed"><span class="serverNone server-status"></span></span>
|
<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:]}}
|
{{s.0[0]|upper}}{{s.0[1:]}}
|
||||||
</td>
|
</td>
|
||||||
<td class="padding10 first-collumn">
|
<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">
|
<a id="start-{{ s.0 }}" class="start" title="Start and enable {{s.0}} service">
|
||||||
<span class="service-start" onclick="confirmAjaxServiceAction('start', '{{s.0}}')"></span>
|
<span class="service-start" onclick="confirmAjaxServiceAction('start', '{{s.0}}')"></span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -22,9 +25,10 @@
|
||||||
<a id="stop-{{ s.0 }}" class="stop" title="Stop and disable {{s.0}} service">
|
<a id="stop-{{ s.0 }}" class="stop" title="Stop and disable {{s.0}} service">
|
||||||
<span class="service-stop" onclick="confirmAjaxServiceAction('stop', '{{s.0}}')"></span>
|
<span class="service-stop" onclick="confirmAjaxServiceAction('stop', '{{s.0}}')"></span>
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if s.3 != '* is not installed' %}
|
{% if 'is not installed' not in s.3 %}
|
||||||
{{ s.3 }}
|
{{ s.3 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -115,12 +115,11 @@
|
||||||
</b>
|
</b>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if s.3 != '* is not installed' %}
|
{% if 'is not installed' not in s.3 %}
|
||||||
{% if is_need_update %}
|
{% if is_need_update %}
|
||||||
<a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{s.0}}')" title="Update {{service_name}}">Update</a>
|
<a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{s.0}}')" title="Update {{service_name}}">Update</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% 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>
|
<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 %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<script src="/inc/codemirror/searchcursor.js"></script>
|
<script src="/inc/codemirror/searchcursor.js"></script>
|
||||||
<script src="/inc/codemirror/jump-to-line.js"></script>
|
<script src="/inc/codemirror/jump-to-line.js"></script>
|
||||||
<script src="/inc/configshow.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}}">
|
<meta http-equiv="refresh" content="0; url=/app/hapservers.py?service={{service}}">
|
||||||
{% else %}
|
{% else %}
|
||||||
<center>
|
<center>
|
||||||
|
|
|
@ -39,12 +39,12 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
{% for s in services %}
|
{% for s in services %}
|
||||||
{% if s.1 == '* is not installed' or s.1 == '' %}
|
{% if 'is not installed' in s.1 or s.1 == '' %}
|
||||||
{% if s.0 == 'checker_haproxy' %}
|
{% if s.0 == 'roxy-wi-checker' %}
|
||||||
$(':regex(id, alert)').checkboxradio('disable');
|
$(':regex(id, alert)').checkboxradio('disable');
|
||||||
{% elif s.0 == 'keep_alive' %}
|
{% elif s.0 == 'rpxy-wi-keep_alive' %}
|
||||||
$(':regex(id, active-)').checkboxradio('disable');
|
$(':regex(id, active-)').checkboxradio('disable');
|
||||||
{% elif s.0 == 'metrics_haproxy' %}
|
{% elif s.0 == 'roxy-wi-metrics' %}
|
||||||
$(':regex(id, metrics-)').checkboxradio('disable');
|
$(':regex(id, metrics-)').checkboxradio('disable');
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -174,7 +174,7 @@
|
||||||
<span class="service-stop" onclick="confirmAjaxAction('stop', '{{action_service}}', '{{s.2}}')"></span>
|
<span class="service-stop" onclick="confirmAjaxAction('stop', '{{action_service}}', '{{s.2}}')"></span>
|
||||||
</a>
|
</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>
|
<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>
|
<span class="menu-bar" onclick="serverSettings('{{s.0}}', '{{s.1}}')" title="Edit settings for {{s.1}} service"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -233,7 +233,7 @@
|
||||||
SMON
|
SMON
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if smon == 'inactive' or smon== 'failed' %}
|
{% if smon == 'inactive' or smon == 'failed' %}
|
||||||
<span class="serverDown server-status" title="SMON is stopped"></span>
|
<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">
|
<a href="/app/users.py#services" title="Start SMON - Roxy-WI service" class="logs_link">
|
||||||
SMON
|
SMON
|
||||||
|
|
Loading…
Reference in New Issue