diff --git a/app/create_db.py b/app/create_db.py index 4b4e4cac..d12ee9c1 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -709,7 +709,7 @@ def update_db_v_4_5_4(**kwargs): def update_ver(**kwargs): con, cur = get_cur() - sql = """update version set version = '4.5.4.0'; """ + sql = """update version set version = '4.5.5.0'; """ try: cur.execute(sql) con.commit() diff --git a/app/funct.py b/app/funct.py index 0e5f7663..ec7bcd8b 100644 --- a/app/funct.py +++ b/app/funct.py @@ -627,8 +627,13 @@ def install_nginx(serv): def update_haproxy_wi(service): if service != 'haproxy-wi': + try: + if service != 'keep_alive': + service = service.split('_')[0] + except Exception: + pass service = 'haproxy-wi-'+service - cmd = 'sudo -S yum -y update '+service + cmd = 'sudo -S yum -y update '+service output, stderr = subprocess_execute(cmd) print(output) print(stderr) diff --git a/app/metrics.py b/app/metrics.py index 78770fdb..57c3d60e 100644 --- a/app/metrics.py +++ b/app/metrics.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import sql import funct import sql from jinja2 import Environment, FileSystemLoader @@ -18,7 +17,7 @@ try: servers = '' else: servers = sql.select_servers_metrics(user_id.value) -except: +except Exception: pass @@ -28,6 +27,6 @@ template = template.render(h2=1, title="Metrics", user=user, servers=servers, versions=funct.versions(), - services=service_ver[0], + services=service_ver[0], token=token) print(template) diff --git a/app/options.py b/app/options.py index 2525c9c2..91da1b42 100644 --- a/app/options.py +++ b/app/options.py @@ -1526,6 +1526,42 @@ if form.getvalue('bwlists_save'): elif form.getvalue('bwlists_restart') == 'reload': funct.ssh_command(serv, ["sudo systemctl reload " + haproxy_service_name]) +if form.getvalue('bwlists_delete'): + color = form.getvalue('color') + bwlists_delete = form.getvalue('bwlists_delete') + list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_delete + try: + os.remove(list_path) + except IOError as e: + print('error: Cannot delete ' + color + ' list. %s , ' % e) + + path = sql.get_setting('haproxy_dir') + "/" + color + servers = [] + + if serv != 'all': + servers.append(serv) + + MASTERS = sql.is_master(serv) + for master in MASTERS: + if master[0] is not None: + servers.append(master[0]) + else: + server = sql.get_dick_permit() + for s in server: + servers.append(s[2]) + + for serv in servers: + error = funct.ssh_command(serv, ["sudo rm " + path + "/" + bwlists_delete], return_err=1) + + if error: + print('error: Deleting fail: %s , ' % error) + else: + print('success: ' + color + ' list was delete on ' + serv + ' , ') + try: + funct.logging(serv, 'has deleted ' + color + ' list ' + bwlists_save, haproxywi=1, login=1) + except Exception: + pass + if form.getvalue('get_lists'): list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') lists = funct.get_files(dir=list_path, format="lst") @@ -2069,6 +2105,34 @@ if form.getvalue('showBytes') is not None: template = template.render(bin_bout=bin_bout, serv=serv) print(template) +if form.getvalue('nginxConnections'): + import requests + serv = form.getvalue('nginxConnections') + port = sql.get_setting('nginx_stats_port') + user = sql.get_setting('nginx_stats_user') + password = sql.get_setting('nginx_stats_password') + page = sql.get_setting('nginx_stats_page') + + r = requests.get('http://' + serv + ':' + port + '/' + page, auth=(user, password)) + + if r.status_code == 200: + bin_bout = [0, 0] + for num, line in enumerate(r.text.split('\n')): + #bin_bout.append(line.encode(encoding='ISO-8859-1')) + if num == 0: + bin_bout.append(line.split(' ')[2]) + if num == 2: + bin_bout.append(line.split(' ')[3]) + + from jinja2 import Environment, FileSystemLoader + + env = Environment(loader=FileSystemLoader('templates')) + template = env.get_template('ajax/bin_bout.html') + template = template.render(bin_bout=bin_bout, serv=serv, service='nginx') + print(template) + else: + print('error: cannot connect to Nginx stat page') + if form.getvalue('alert_consumer'): try: user_group = funct.get_user_group(id=1) @@ -2231,3 +2295,21 @@ if form.getvalue('scan_ports') is not None: template = env.get_template('ajax/scan_ports.html') template = template.render(ports=stdout, info=stdout1) print(template) + +if form.getvalue('viewFirewallRules') is not None: + serv = form.getvalue('viewFirewallRules') + + cmd = ["sudo iptables -L INPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"] + cmd1 = ["sudo iptables -L IN_public_allow -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"] + cmd2 = ["sudo iptables -L OUTPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"] + + input = funct.ssh_command(serv, cmd, raw=1) + IN_public_allow = funct.ssh_command(serv, cmd1, raw=1) + output = funct.ssh_command(serv, cmd2, raw=1) + + from jinja2 import Environment, FileSystemLoader + + env = Environment(loader=FileSystemLoader('templates')) + template = env.get_template('ajax/firewall_rules.html') + template = template.render(input=input, IN_public_allow=IN_public_allow, output=output) + print(template) diff --git a/app/templates/add.html b/app/templates/add.html index d85994fc..aefad805 100644 --- a/app/templates/add.html +++ b/app/templates/add.html @@ -7,10 +7,10 @@ 'url_param userid':'url_param userid'} %} {% set checks = dict() %} {% set checks = {'':'Choose custom health check','option tcp-check':'Check a TCP Port', -'option ssl-hello-chk':'Check an SSL Port','option httpchk':'Check an HTTP service', -'option ldap-check':'Check an LDAP service', 'option mysql-check':'Check a MySql Service', +'option ssl-hello-chk':'Check a SSL Port','option httpchk':'Check a HTTP service', +'option ldap-check':'Check a LDAP service', 'option mysql-check':'Check a MySql Service', 'option pgsql-check':'Check a PgSQL Service', 'option redis-check': 'Check a Redis Service', -'option smtpchk':'Check an SMTP service'} %} +'option smtpchk':'Check a SMTP service'} %}
diff --git a/app/templates/metrics.html b/app/templates/metrics.html index 76d5cc48..6678fa0e 100644 --- a/app/templates/metrics.html +++ b/app/templates/metrics.html @@ -20,7 +20,7 @@ th, tr, td { {% if services == '* is not installed' %}

-

You do not have installed Metrics service +

You do not have installed Metrics service. Read hear how to install Metrics service

@@ -28,6 +28,15 @@ th, tr, td { {% if servers|length == 0 %} {% include 'include/getstarted.html' %} {% else %} + + + + +
+ Metrics + + +
Time range: @@ -54,7 +63,12 @@ th, tr, td { {% for s in servers %} getChartData('{{s.0}}') {% endfor %} - loadMetrics() + if (localStorage.getItem('table_metrics') == 0 || localStorage.getItem('table_metrics') === null) { + $('#dis_table_metric').css('display', 'none'); + } else { + $('#en_table_metric').css('display', 'none'); + loadMetrics(); + } }); metrics.then(); } @@ -71,6 +85,7 @@ th, tr, td { metrics.then(); }); }); + {% endif %} {% endif %} diff --git a/inc/add.js b/inc/add.js index a2beda36..f2a47d31 100644 --- a/inc/add.js +++ b/inc/add.js @@ -1344,6 +1344,10 @@ function editList(list, color) { modal: true, title: "Edit "+color+" list "+list, buttons: { + "Delete": function() { + $( this ).dialog( "close" ); + deleteList(list, color); + }, "Just save": function() { $( this ).dialog( "close" ); saveList('save', list, color); @@ -1398,3 +1402,35 @@ function saveList(action, list, color) { }); } } +function deleteList(list, color) { + var serv = $( "#serv-"+color+"-list option:selected" ).val(); + if (serv == 'Choose server') { + toastr.warning('Choose a server before deleting'); + } else { + $.ajax({ + url: "options.py", + data: { + bwlists_delete: list, + serv: serv, + color: color, + group: $('#group').val(), + token: $('#token').val() + }, + type: "POST", + success: function (data) { + if (data.indexOf('error:') != '-1' || data.indexOf('Failed') != '-1') { + toastr.error(data); + } else if (data.indexOf('Info') != '-1' ){ + toastr.clear(); + toastr.info(data); + } else if (data.indexOf('success') != '-1' ) { + toastr.clear(); + toastr.success('List has been deleted'); + setTimeout(function () { + location.reload(); + }, 2500); + } + } + }); + } +} \ No newline at end of file diff --git a/inc/awesome.css b/inc/awesome.css index 58d29843..5a28f41b 100644 --- a/inc/awesome.css +++ b/inc/awesome.css @@ -254,3 +254,8 @@ font-family: "Font Awesome 5 Solid"; content: "\f0c9"; } +.minus::before { + display: none; + font-family: "Font Awesome 5 Solid"; + content: "\f068"; +} diff --git a/inc/metrics.js b/inc/metrics.js index 6aca2e5d..c2a91c14 100644 --- a/inc/metrics.js +++ b/inc/metrics.js @@ -170,8 +170,7 @@ function renderWafChart(data, labels, server) { }); charts.push(myChart); } -console.log(charts); -$("#secIntervals").css("display", "none"); +$("#secIntervals").css("display", "none"); function loadMetrics() { $.ajax({ @@ -319,4 +318,17 @@ function renderChartHapWiCpu(data) { } }); } - +$( function() { + $('#dis_table_metric').click(function() { + localStorage.setItem('table_metrics', 0); + $('#body_table_metrics').css('display', 'none'); + $('#en_table_metric').css('display', 'inline'); + $('#dis_table_metric').css('display', 'none'); + }); + $('#en_table_metric').click(function() { + localStorage.setItem('table_metrics', 1); + $('#en_table_metric').css('display', 'none'); + $('#dis_table_metric').css('display', 'inline'); + loadMetrics(); + }); +});