From 5b402b597b86897dccd854d9649f97c42c6a22c3 Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Thu, 23 Aug 2018 20:27:28 +0600 Subject: [PATCH] v3.2.1 Debian support improved --- app/create_db.py | 29 ++++++++++++++++++++++++++--- app/funct.py | 8 ++++---- app/options.py | 5 +++-- app/templates/logs.html | 4 ++++ app/tools/metrics_master.py | 4 ++-- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app/create_db.py b/app/create_db.py index fca42693..cab2e159 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -518,7 +518,7 @@ def update_db_v_3(**kwargs): except sqltool.Error as e: if kwargs.get('silent') != 1: if e.args[0] == 'duplicate column name: section' or e == " 1060 (42S21): Duplicate column name 'section' ": - print('Updating... go to version 3.2') + print('Updating... go to version 3.1') else: print("An error occurred:", e) return False @@ -550,7 +550,7 @@ def update_db_v_31(**kwargs): "INSERT INTO settings (param, value, section, `desc`) values('tmp_config_path', '/tmp/', 'haproxy', 'Temp store configs, for haproxy check');", "INSERT INTO settings (param, value, section, `desc`) values('cert_path', '/etc/ssl/certs/', 'haproxy', 'Path to SSL dir');", "INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');", - "update settings set `section` = 'main', `desc` = 'Path to black/white lists` where param = 'lists_path' "] + "update settings set `section` = 'main', `desc` = 'Path to black/white lists' where param = 'lists_path' "] try: for i in sql: cur.execute(i) @@ -558,7 +558,7 @@ def update_db_v_31(**kwargs): except sqltool.Error as e: if kwargs.get('silent') != 1: if e.args[0] == 'duplicate column name: desc' or e == "1060 (42S21): Duplicate column name 'desc' ": - print('') + print('Updating... go to version 3.2') else: print("An error occurred:", e) return False @@ -603,6 +603,27 @@ def update_db_v_3_21(**kwargs): return True cur.close() con.close() + +def update_db_v_3_2_1(**kwargs): + con, cur = get_cur() + sql = """ + insert into `settings` (param, value, section, `desc`) values ('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs'); + """ + try: + cur.execute(sql) + con.commit() + except sqltool.Error as e: + if kwargs.get('silent') != 1: + if e.args[0] == 'column param is not unique' or e == "1062 (23000): Duplicate entry 'lists_path' for key 'param'": + print('DB was update') + else: + print("An error occurred:", e) + return False + else: + print("Updating... go to version 3.0
") + return True + cur.close() + con.close() def update_all(): update_db_v_2_0_1() @@ -624,6 +645,7 @@ def update_all(): update_db_v_31() update_db_v_3_2() update_db_v_3_21() + update_db_v_3_2_1() def update_all_silent(): update_db_v_2_0_1(silent=1) @@ -645,4 +667,5 @@ def update_all_silent(): update_db_v_31(silent=1) update_db_v_3_2(silent=1) update_db_v_3_21(silent=1) + update_db_v_3_2_1(silent=1) \ No newline at end of file diff --git a/app/funct.py b/app/funct.py index 06a788c0..c816287e 100644 --- a/app/funct.py +++ b/app/funct.py @@ -362,9 +362,9 @@ def upload_and_restart(serv, cfg, **kwargs): commands = [ "sudo mv -f " + tmp_file + " /etc/keepalived/keepalived.conf", "sudo systemctl restart keepalived" ] else: if kwargs.get("just_save") == "save": - commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') ] + commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') ] else: - commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') + " && sudo " + sql.get_setting('restart_command') ] + commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') + " && sudo " + sql.get_setting('restart_command') ] try: if sql.get_setting('firewall_enable') == "1": commands.extend(open_port_firewalld(cfg)) @@ -452,11 +452,11 @@ def ssh_command(serv, commands, **kwargs): else: return stdout.read().decode(encoding='UTF-8') - print(stderr.read().decode(encoding='UTF-8')) + print("
"+stderr.read().decode(encoding='UTF-8')+"
") try: ssh.close() except: - print(ssh) + print("
"+ssh+"
") pass def escape_html(text): diff --git a/app/options.py b/app/options.py index aeff5a26..da5b6493 100644 --- a/app/options.py +++ b/app/options.py @@ -210,6 +210,7 @@ if serv is not None and form.getvalue('rows1') is not None: minut1 = form.getvalue('minut1') date = hour+':'+minut date1 = hour1+':'+minut1 + apache_log_path = sql.get_setting('apache_log_path') if grep is not None: grep_act = '|grep' @@ -218,9 +219,9 @@ if serv is not None and form.getvalue('rows1') is not None: grep = '' if serv == 'haproxy-wi.access.log': - cmd="cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, grep_act, grep) + cmd="cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % (apache_log_path+"/"+serv, date, date1, rows, grep_act, grep) else: - cmd="cat %s| awk '$4>\"%s:00\" && $4<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, grep_act, grep) + cmd="cat %s| awk '$4>\"%s:00\" && $4<\"%s:00\"' |tail -%s %s %s" % (apache_log_path+"/"+serv, date, date1, rows, grep_act, grep) output, stderr = funct.subprocess_execute(cmd) diff --git a/app/templates/logs.html b/app/templates/logs.html index d2b2910d..94adf96a 100644 --- a/app/templates/logs.html +++ b/app/templates/logs.html @@ -10,7 +10,9 @@ Server {% endif %} + {% if onclick != 'viewLogs()' %} WAF logs + {% endif %} Number rows Ex for grep @@ -45,9 +47,11 @@ {% endif %} + {% if onclick != 'viewLogs()' %} + {% endif %} diff --git a/app/tools/metrics_master.py b/app/tools/metrics_master.py index 33be65b5..6ef99284 100644 --- a/app/tools/metrics_master.py +++ b/app/tools/metrics_master.py @@ -74,12 +74,12 @@ def start_waf_worker(serv): port = sql.get_setting('haproxy_sock_port') cmd = "tools/metrics_waf_worker.py %s --port %s &" % (serv, port) os.system(cmd) - funct.logging("localhost", " Masrer started new metrics worker for: "+serv, metrics=1) + funct.logging("localhost", " Masrer started new WAF metrics worker for: "+serv, metrics=1) def kill_waf_worker(serv): cmd = "ps ax |grep 'tools/metrics_waf_worker.py %s'|grep -v grep |awk '{print $1}' |xargs kill" % serv output, stderr = funct.subprocess_execute(cmd) - funct.logging("localhost", " Masrer killed metrics worker for: "+serv, metrics=1) + funct.logging("localhost", " Masrer killed WAF metrics worker for: "+serv, metrics=1) if stderr: funct.logging("localhost", stderr, metrics=1)