mirror of https://github.com/Aidaho12/haproxy-wi
parent
ac8a22669e
commit
7d4e504337
59
app/funct.py
59
app/funct.py
|
@ -33,15 +33,18 @@ def get_data(log_type):
|
|||
from datetime import datetime
|
||||
from pytz import timezone
|
||||
import sql
|
||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||
|
||||
try:
|
||||
now_utc = datetime.now(timezone(sql.get_setting('time_zone')))
|
||||
except Exception:
|
||||
now_utc = datetime.now(timezone('UTC'))
|
||||
|
||||
if log_type == 'config':
|
||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||
if log_type == 'logs':
|
||||
elif log_type == 'logs':
|
||||
fmt = '%Y%m%d'
|
||||
if log_type == "date_in_log":
|
||||
elif log_type == "date_in_log":
|
||||
fmt = "%b %d %H:%M:%S"
|
||||
|
||||
return now_utc.strftime(fmt)
|
||||
|
@ -124,13 +127,14 @@ def logging(serv, action, **kwargs):
|
|||
log.close()
|
||||
except IOError as e:
|
||||
print('<center><div class="alert alert-danger">Can\'t write log. Please check log_path in config %e</div></center>' % e)
|
||||
pass
|
||||
|
||||
|
||||
def telegram_send_mess(mess, **kwargs):
|
||||
import telebot
|
||||
from telebot import apihelper
|
||||
import sql
|
||||
token_bot = ''
|
||||
channel_name = ''
|
||||
|
||||
if kwargs.get('telegram_channel_id'):
|
||||
telegrams = sql.get_telegram_by_id(kwargs.get('telegram_channel_id'))
|
||||
|
@ -164,6 +168,8 @@ def slack_send_mess(mess, **kwargs):
|
|||
import sql
|
||||
from slack_sdk import WebClient
|
||||
from slack_sdk.errors import SlackApiError
|
||||
slack_token = ''
|
||||
channel_name = ''
|
||||
|
||||
if kwargs.get('slack_channel_id'):
|
||||
slacks = sql.get_slack_by_id(kwargs.get('slack_channel_id'))
|
||||
|
@ -248,6 +254,7 @@ def return_ssh_keys_path(serv, **kwargs):
|
|||
ssh_enable = ''
|
||||
ssh_user_name = ''
|
||||
ssh_user_password = ''
|
||||
ssh_key_name = ''
|
||||
|
||||
if kwargs.get('id'):
|
||||
for sshs in sql.select_ssh(id=kwargs.get('id')):
|
||||
|
@ -271,15 +278,16 @@ def ssh_connect(serv, **kwargs):
|
|||
import sql
|
||||
|
||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv)
|
||||
|
||||
servers = sql.select_servers(server=serv)
|
||||
ssh_port = 22
|
||||
|
||||
for server in servers:
|
||||
ssh_port = server[10]
|
||||
|
||||
ssh = SSHClient()
|
||||
ssh.load_system_host_keys()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
try:
|
||||
if ssh_enable == 1:
|
||||
cloud = sql.is_cloud()
|
||||
|
@ -293,27 +301,19 @@ def ssh_connect(serv, **kwargs):
|
|||
return ssh
|
||||
except paramiko.AuthenticationException:
|
||||
return 'Authentication failed, please verify your credentials'
|
||||
pass
|
||||
except paramiko.SSHException as sshException:
|
||||
return 'error: Unable to establish SSH connection: %s ' % sshException
|
||||
pass
|
||||
except paramiko.PasswordRequiredException as e:
|
||||
return 'error: %s ' % e
|
||||
pass
|
||||
except paramiko.BadHostKeyException as badHostKeyException:
|
||||
return 'error: Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
pass
|
||||
except Exception as e:
|
||||
if e == "No such file or directory":
|
||||
return 'error: %s. Check ssh key' % e
|
||||
pass
|
||||
elif e == "Invalid argument":
|
||||
error = 'error: Check the IP of the server'
|
||||
pass
|
||||
return 'error: Check the IP of the server'
|
||||
else:
|
||||
error = e
|
||||
pass
|
||||
return str(error)
|
||||
return str(e)
|
||||
|
||||
|
||||
def get_config(serv, cfg, **kwargs):
|
||||
|
@ -417,7 +417,6 @@ def get_section_from_config(config, section):
|
|||
record = True
|
||||
continue
|
||||
if record:
|
||||
|
||||
if (
|
||||
line.startswith('listen') or
|
||||
line.startswith('frontend') or
|
||||
|
@ -470,7 +469,7 @@ def rewrite_section(start_line, end_line, config, section):
|
|||
return return_config
|
||||
|
||||
|
||||
def get_userlists(config, **kwargs):
|
||||
def get_userlists(config):
|
||||
return_config = ''
|
||||
with open(config, 'r') as f:
|
||||
for line in f:
|
||||
|
@ -480,7 +479,8 @@ def get_userlists(config, **kwargs):
|
|||
|
||||
return return_config
|
||||
|
||||
def get_backends_from_config(serv, backends='', **kwargs):
|
||||
|
||||
def get_backends_from_config(serv, backends=''):
|
||||
configs_dir = get_config_var('configs', 'haproxy_save_configs_dir')
|
||||
format_cfg = 'cfg'
|
||||
|
||||
|
@ -557,7 +557,7 @@ def install_haproxy(serv, **kwargs):
|
|||
stats_user = sql.get_setting('stats_user')
|
||||
stats_password = sql.get_setting('stats_password')
|
||||
proxy = sql.get_setting('proxy')
|
||||
hapver = kwargs.get('hapver')
|
||||
haproxy_ver = kwargs.get('hapver')
|
||||
server_for_installing = kwargs.get('server')
|
||||
ssh_port = 22
|
||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv)
|
||||
|
@ -571,8 +571,8 @@ def install_haproxy(serv, **kwargs):
|
|||
|
||||
os.system("cp scripts/%s ." % script)
|
||||
|
||||
if hapver is None:
|
||||
hapver = '2.3.0-1'
|
||||
if haproxy_ver is None:
|
||||
haproxy_ver = '2.3.0-1'
|
||||
|
||||
if proxy is not None and proxy != '' and proxy != 'None':
|
||||
proxy_serv = proxy
|
||||
|
@ -584,7 +584,7 @@ def install_haproxy(serv, **kwargs):
|
|||
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
|
||||
" SOCK_PORT=" + hap_sock_p + " STAT_PORT=" + stats_port + " STAT_FILE="+server_state_file +
|
||||
" SSH_PORT=" + ssh_port + " STATS_USER=" + stats_user +
|
||||
" STATS_PASS=" + stats_password + " HAPVER=" + hapver + " SYN_FLOOD=" + syn_flood_protect +
|
||||
" STATS_PASS=" + stats_password + " HAPVER=" + haproxy_ver + " SYN_FLOOD=" + syn_flood_protect +
|
||||
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
|
||||
|
||||
output, error = subprocess_execute(commands[0])
|
||||
|
@ -694,6 +694,7 @@ def check_haproxy_version(serv):
|
|||
output, stderr = subprocess_execute(cmd)
|
||||
for line in output:
|
||||
ver = line
|
||||
|
||||
return ver
|
||||
|
||||
|
||||
|
@ -709,7 +710,6 @@ def upload(serv, path, file, **kwargs):
|
|||
error = e.args
|
||||
logging('localhost', str(e.args[0]), haproxywi=1)
|
||||
print(' Cannot upload '+file+' to '+full_path+' to server: '+serv+' error: '+str(e.args))
|
||||
pass
|
||||
|
||||
try:
|
||||
sftp = ssh.open_sftp()
|
||||
|
@ -724,7 +724,6 @@ def upload(serv, path, file, **kwargs):
|
|||
error = e.args
|
||||
print('Cannot upload '+file+' to '+full_path+' to server: '+serv+' error: '+str(e.args))
|
||||
logging('localhost', ' Cannot upload '+file+' to '+full_path+' to server: '+serv+' Error: '+str(e.args), haproxywi=1)
|
||||
pass
|
||||
|
||||
try:
|
||||
sftp.close()
|
||||
|
@ -733,13 +732,13 @@ def upload(serv, path, file, **kwargs):
|
|||
error = e.args
|
||||
logging('localhost', str(error[0]), haproxywi=1)
|
||||
print('Cannot upload '+file+' to '+full_path+' to server: '+serv+' error: '+str(e.args))
|
||||
pass
|
||||
|
||||
return str(error)
|
||||
|
||||
|
||||
def upload_and_restart(serv, cfg, **kwargs):
|
||||
import sql
|
||||
error = ""
|
||||
|
||||
if kwargs.get("nginx"):
|
||||
config_path = sql.get_setting('nginx_config_path')
|
||||
|
@ -747,13 +746,11 @@ def upload_and_restart(serv, cfg, **kwargs):
|
|||
else:
|
||||
config_path = sql.get_setting('haproxy_config_path')
|
||||
tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg"
|
||||
error = ""
|
||||
|
||||
try:
|
||||
os.system("dos2unix "+cfg)
|
||||
except OSError:
|
||||
return 'Please install dos2unix'
|
||||
pass
|
||||
|
||||
if kwargs.get("keepalived") == 1:
|
||||
if kwargs.get("just_save") == "save":
|
||||
|
@ -816,7 +813,7 @@ def open_port_firewalld(cfg, serv, **kwargs):
|
|||
try:
|
||||
conf = open(cfg, "r")
|
||||
except IOError:
|
||||
print('<div class="alert alert-danger">Can\'t read export config file</div>')
|
||||
print('<div class="alert alert-danger">Cannot read exported config file</div>')
|
||||
|
||||
firewalld_commands = ' &&'
|
||||
ports = ''
|
||||
|
@ -873,6 +870,8 @@ def check_haproxy_config(serv):
|
|||
def show_log(stdout, **kwargs):
|
||||
i = 0
|
||||
out = ''
|
||||
grep = ''
|
||||
|
||||
if kwargs.get('grep'):
|
||||
import re
|
||||
grep = kwargs.get('grep')
|
||||
|
@ -1022,8 +1021,8 @@ def ssh_command(serv, commands, **kwargs):
|
|||
for command in commands:
|
||||
try:
|
||||
stdin, stdout, stderr = ssh.exec_command(command, get_pty=True)
|
||||
except Exception:
|
||||
continue
|
||||
except Exception as e:
|
||||
logging('localhost', ' ' + str(e), haproxywi=1)
|
||||
|
||||
if kwargs.get("ip") == "1":
|
||||
show_ip(stdout)
|
||||
|
@ -1045,12 +1044,12 @@ def ssh_command(serv, commands, **kwargs):
|
|||
if line:
|
||||
print("<div class='alert alert-warning'>"+line+"</div>")
|
||||
logging('localhost', ' '+line, haproxywi=1)
|
||||
|
||||
try:
|
||||
ssh.close()
|
||||
except Exception:
|
||||
logging('localhost', ' '+str(ssh), haproxywi=1)
|
||||
return "error: "+str(ssh)
|
||||
pass
|
||||
|
||||
|
||||
def subprocess_execute(cmd):
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<style>
|
||||
table, th, tr, td {
|
||||
border: 1px solid #ddd;
|
||||
align: center;
|
||||
text-align: center;
|
||||
}
|
||||
th, tr, td {
|
||||
width: 6%;
|
||||
min-width: 3%;
|
||||
padding: 10px;
|
||||
table, th, tr, td {
|
||||
border: 1px solid #ddd;
|
||||
align: center;
|
||||
text-align: center;
|
||||
}
|
||||
th, tr, td {
|
||||
width: 6%;
|
||||
min-width: 3%;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
<link href="/inc/chart.min.css" rel="stylesheet">
|
||||
<script src="/inc/metrics.js"></script>
|
||||
<script src="/inc/chart.min.js"></script>
|
||||
{% if services == '0' %}
|
||||
<center>
|
||||
<div style="text-align: center;">
|
||||
<br />
|
||||
<h3>You do not have installed Metrics service.
|
||||
Read <a href="https://haproxy-wi.org/services.py?service=metrics#installation" title="Metrics installation" style="color: #5d9ceb;" target="_blank">hear</a>
|
||||
how to install Metrics service</h3>
|
||||
</center>
|
||||
</div>
|
||||
{% else %}
|
||||
{% if servers|length == 0 %}
|
||||
{% include 'include/getstarted.html' %}
|
||||
|
@ -31,8 +30,8 @@ th, tr, td {
|
|||
<tr class="overviewHead">
|
||||
<th colspan=13 style="background-color: #d1ecf1">
|
||||
<span id="table_metrics_head" style="position: absolute;margin-left: 43%;">Metrics</span>
|
||||
<span id="en_table_metric" class="add switcher_table_metric" title="Enable showing Average table"></span>
|
||||
<span id="dis_table_metric" class="minus switcher_table_metric" title="Disable showing Average table"></span>
|
||||
<span id="en_table_metric" class="plus switcher_table_metric" title="Enable display of the table of averages"></span>
|
||||
<span id="dis_table_metric" class="minus switcher_table_metric" title="Disable display of the table of averages"></span>
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -54,13 +53,18 @@ th, tr, td {
|
|||
<div class="chart-container">
|
||||
<canvas id="{{s.0}}" role="img"></canvas>
|
||||
</div>
|
||||
<div id="http_metrics_div" class="chart-container">
|
||||
<canvas id="http_{{s.0}}" role="img"></canvas>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<script>
|
||||
function showMetrics() {
|
||||
let metrics = new Promise(
|
||||
(resolve, reject) => {
|
||||
removeData();
|
||||
{% for s in servers %}
|
||||
getChartData('{{s.0}}')
|
||||
getHttpChartData('{{s.0}}')
|
||||
{% endfor %}
|
||||
if (localStorage.getItem('table_metrics') == 0 || localStorage.getItem('table_metrics') === null) {
|
||||
$('#dis_table_metric').css('display', 'none');
|
||||
|
@ -79,6 +83,7 @@ th, tr, td {
|
|||
(resolve, reject) => {
|
||||
{% for s in servers %}
|
||||
getChartData('{{s.0}}')
|
||||
getHttpChartData('{{s.0}}')
|
||||
{% endfor %}
|
||||
});
|
||||
metrics.then();
|
||||
|
|
|
@ -253,10 +253,11 @@
|
|||
<td>
|
||||
{% if prometheus|int() >= 1 %}
|
||||
<span class="serverUp server-status" title="running {{ prometheus }} process"></span>
|
||||
<a href="http://{{host}}:9090" target="_blank" title="Open Prometheus" class="logs_link">Prometheus</a>
|
||||
{% else %}
|
||||
<span class="serverNone server-status" title="The service does not started or does not installed"></span>
|
||||
Prometheus
|
||||
{% endif %}
|
||||
Prometheus
|
||||
</td>
|
||||
{% endif %}
|
||||
<td {% if role != 1 %}class="padding10 first-collumn-wi"{%endif%}>
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
font-family: "Font Awesome 5 Solid";
|
||||
content: "\f24d";
|
||||
}
|
||||
.add .fa-clone {
|
||||
.add .fa-clone, .plus .fa-plus {
|
||||
color: var(--green-color);
|
||||
}
|
||||
.add-proxy::before {
|
||||
|
@ -273,6 +273,11 @@
|
|||
font-family: "Font Awesome 5 Solid";
|
||||
content: "\f068";
|
||||
}
|
||||
.plus::before {
|
||||
display: none;
|
||||
font-family: "Font Awesome 5 Solid";
|
||||
content: "\f067";
|
||||
}
|
||||
.row-down::after {
|
||||
display: none;
|
||||
font-family: "Font Awesome 5 Solid";
|
||||
|
|
|
@ -500,7 +500,6 @@ ul{
|
|||
}
|
||||
.menu li:last-child a, .menu li .v_menu li:last-child a{
|
||||
border-radius: 0 0 3px 3px;
|
||||
border-bottom: 0;
|
||||
}
|
||||
.menu li .v_menu li a{
|
||||
border-radius: 0;
|
||||
|
@ -1200,7 +1199,7 @@ label {
|
|||
}
|
||||
.switcher_table_metric {
|
||||
margin-left: 99%;
|
||||
color: #a0d100;
|
||||
color: var(--green-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
.geoip_country_code {
|
||||
|
@ -1210,3 +1209,6 @@ label {
|
|||
width: 110px;
|
||||
height: 60px;
|
||||
}
|
||||
.help_cursor {
|
||||
cursor: help;
|
||||
}
|
Loading…
Reference in New Issue