diff --git a/app/add.py b/app/add.py index 979f6d7a..bdcce6d3 100644 --- a/app/add.py +++ b/app/add.py @@ -4,7 +4,7 @@ import funct import sql import http.cookies from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('add.html') form = funct.form serv = form.getvalue('serv') diff --git a/app/create_db.py b/app/create_db.py index f2fb66b8..6fdea545 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -172,9 +172,6 @@ def update_db_v_31(**kwargs): sql.append("INSERT INTO settings (param, value, section, `desc`) values('syslog_server_enable', '0', 'logs', 'If exist syslog server for HAproxy logs, enable this option');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('syslog_server', '0', 'logs', 'IP address syslog server');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('log_time_storage', '14', 'logs', 'Time of storage of logs of user activity, in days');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('restart_command', 'systemctl restart haproxy', 'haproxy', 'Command for restart HAproxy service');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('reload_command', 'systemctl reload haproxy', 'haproxy', 'Command for reload HAproxy service');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('status_command', 'systemctl status haproxy', 'haproxy', 'Command for status check HAproxy service');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('stats_user', 'admin', 'haproxy', 'Username for Stats web page HAproxy');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('stats_password', 'password', 'haproxy', 'Password for Stats web page HAproxy');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('stats_port', '8085', 'haproxy', 'Port Stats web page HAproxy');") @@ -264,25 +261,6 @@ def update_db_v_3_4_7(**kwargs): con.close() -def update_db_v_3_4_9_5(**kwargs): - con, cur = get_cur() - sql = """INSERT INTO settings (param, value, section, `desc`) values('reload_command', 'systemctl reload haproxy', 'haproxy', 'Command for reload HAproxy service'); """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: param' or e == "1060 (42S21): Duplicate column name 'param' ": - print('DB was update to 3.4.9.5') - else: - print("Updating... go to version 3.8.1") - return False - else: - return True - cur.close() - con.close() - - def update_db_v_3_5_3(**kwargs): con, cur = get_cur() sql = """CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); """ @@ -392,9 +370,6 @@ def update_db_v_4(**kwargs): sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_stats_password', 'password', 'nginx', 'Password for Stats web page Nginx');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_stats_port', '8086', 'nginx', 'Stats port for web page Nginx');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_stats_page', 'stats', 'nginx', 'URI Stats for web page Nginx');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_restart_command', 'systemctl restart nginx', 'nginx', 'Command for restart Nginx service');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_reload_command', 'systemctl reload nginx', 'nginx', 'Command for reload Nginx service');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_status_command', 'systemctl status nginx', 'nginx', 'Command for status check Nginx service');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_dir', '/etc/nginx/conf.d/', 'nginx', 'Path to Nginx dir');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_config_path', '/etc/nginx/conf.d/default.conf', 'nginx', 'Path to Nginx config');") for i in sql: @@ -473,7 +448,6 @@ def update_all(): if funct.check_ver() is None: update_db_v_3_4_5_22() update_db_v_3_4_7() - update_db_v_3_4_9_5() update_db_v_3_5_3() update_db_v_3_8_1() update_db_v_3_12() @@ -491,7 +465,6 @@ def update_all_silent(): if funct.check_ver() is None: update_db_v_3_4_5_22() update_db_v_3_4_7(silent=1) - update_db_v_3_4_9_5(silent=1) update_db_v_3_5_3(silent=1) update_db_v_3_8_1(silent=1) update_db_v_3_12(silent=1) diff --git a/app/funct.py b/app/funct.py index cba5a0cd..3f241064 100644 --- a/app/funct.py +++ b/app/funct.py @@ -583,18 +583,18 @@ def upload_and_restart(serv, cfg, **kwargs): if kwargs.get("just_save") == "save": commands = [ "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q"] elif kwargs.get("just_save") == "reload": - commands = [ "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q && sudo " + sql.get_setting('nginx_reload_command') ] + commands = [ "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q && sudo systemctl reload nginx" ] else: - commands = [ "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q && sudo " + sql.get_setting('nginx_restart_command') ] + commands = [ "sudo mv -f " + tmp_file + " " + config_path + " && sudo nginx -t -q && sudo systemctl restart nginx" ] else: if kwargs.get("just_save") == "test": commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo rm -f " + tmp_file ] elif kwargs.get("just_save") == "save": commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + config_path ] elif kwargs.get("just_save") == "reload": - commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + config_path + " && sudo " + sql.get_setting('reload_command') ] + commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + config_path + " && sudo systemctl reload haproxy" ] else: - commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + config_path + " && sudo " + sql.get_setting('restart_command') ] + commands = [ "sudo haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + config_path + " && sudo systemctl restart haproxy" ] if sql.get_setting('firewall_enable') == "1": commands.extend(open_port_firewalld(cfg)) error += str(upload(serv, tmp_file, cfg, dir='fullpath')) diff --git a/app/ha.py b/app/ha.py index ca93c2ec..ffb988bf 100644 --- a/app/ha.py +++ b/app/ha.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import funct from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('ha.html') print('Content-type: text/html\n') diff --git a/app/hapservers.py b/app/hapservers.py index 2e7a5821..e29e7890 100644 --- a/app/hapservers.py +++ b/app/hapservers.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import funct, sql from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('hapservers.html') print('Content-type: text/html\n') @@ -25,6 +25,9 @@ if service == 'nginx': stderr = '' servers = sql.get_dick_permit(virt=1, nginx=1) service = 'nginx' + if serv: + servers = sql.select_servers(server=serv) + autorefresh = 1 else: title = "HAProxy servers overview" cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l" diff --git a/app/login.py b/app/login.py index 9846e1a6..ebe1b4f2 100644 --- a/app/login.py +++ b/app/login.py @@ -11,7 +11,7 @@ import create_db import datetime import uuid from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('login.html') form = funct.form diff --git a/app/logs.py b/app/logs.py index d9f9333c..18c0374c 100644 --- a/app/logs.py +++ b/app/logs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import funct from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('logs.html') form = funct.form diff --git a/app/metrics.py b/app/metrics.py index 7e3e3da8..f2b9198b 100644 --- a/app/metrics.py +++ b/app/metrics.py @@ -3,7 +3,7 @@ import sql import funct import sql from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) +env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) template = env.get_template('metrics.html') print('Content-type: text/html\n') diff --git a/app/options.py b/app/options.py index f7e4a85e..4bddb16d 100644 --- a/app/options.py +++ b/app/options.py @@ -137,7 +137,7 @@ if form.getvalue('action_waf') is not None and serv is not None: if act == "overviewHapserverBackends": from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax')) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) template = env.get_template('haproxyservers_backends.html') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') @@ -208,7 +208,7 @@ if act == "overview": async def get_runner_overview(): import http.cookies from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True,extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) servers = [] template = env.get_template('overview.html') @@ -246,7 +246,7 @@ if act == "overviewwaf": async def get_runner_overviewWaf(): import http.cookies from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True,extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) template = env.get_template('overivewWaf.html') servers = [] @@ -288,7 +288,7 @@ if act == "overviewServers": async def get_runner_overviewServers(**kwargs): import http.cookies from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True,extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) template = env.get_template('overviewServers.html') servers = [] @@ -884,7 +884,7 @@ if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupup funct.logging('backup ', ' has created a new backup job for server '+server , haproxywi=1, login=1) import http.cookies from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax')) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) template = env.get_template('new_backup.html') template = template.render(backups=sql.select_backups(server=server, rserver=rserver), sshs=sql.select_ssh()) print(template) @@ -924,7 +924,7 @@ if form.getvalue('metrics_waf'): if form.getvalue('table_metrics'): import http.cookies from jinja2 import Environment, FileSystemLoader - env = Environment(loader=FileSystemLoader('templates/ajax')) + env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) template = env.get_template('table_metrics.html') cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) @@ -1045,7 +1045,7 @@ if form.getvalue('bwlists_save'): print('