From 9062c3a0835287d0d3114aa9b620b88d1a0d2c30 Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Sun, 12 Jan 2020 19:13:48 +0300 Subject: [PATCH] v3.12.1.0 Changelog: https://haproxy-wi.org/changelog.py#3_12_1 --- app/add.py | 22 ++- app/create_db.py | 199 +++++-------------------- app/funct.py | 21 ++- app/haproxy-wi.cfg | 4 +- app/haproxy-wi.db.sql | 8 +- app/lists.py | 54 ------- app/options.py | 22 ++- app/servers.py | 2 +- app/sql.py | 2 +- app/templates/add.html | 49 +++++- app/templates/admin.html | 1 + app/templates/base.html | 4 +- app/templates/include/add_servers.html | 13 +- app/templates/lists.html | 41 ----- app/templates/servers.html | 1 + inc/add.js | 22 +++ 16 files changed, 175 insertions(+), 290 deletions(-) delete mode 100644 app/lists.py delete mode 100644 app/templates/lists.html diff --git a/app/add.py b/app/add.py index a0ecd75b..69dfd9b0 100644 --- a/app/add.py +++ b/app/add.py @@ -28,6 +28,21 @@ try: token = sql.get_token(user_id.value) except: pass + +dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path') +white_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+user_group+"/white" +black_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+user_group+"/black" +if not os.path.exists(dir): + os.makedirs(dir) +if not os.path.exists(dir+"/"+user_group): + os.makedirs(dir+"/"+user_group) +if not os.path.exists(white_dir): + os.makedirs(white_dir) +if not os.path.exists(black_dir): + os.makedirs(black_dir) + +white_lists = funct.get_files(dir=white_dir, format="lst") +black_lists = funct.get_files(dir=black_dir, format="lst") template = template.render(title = "Add", @@ -40,6 +55,8 @@ template = template.render(title = "Add", versions = funct.versions(), options = sql.select_options(), saved_servers = sql.select_saved_servers(), + white_lists = white_lists, + black_lists = black_lists, token = token) print(template) @@ -153,7 +170,10 @@ if form.getvalue('mode') is not None: server_port = form.getlist('server_port') i = 0 for server in servers: - servers_split += " server "+server+" " + server +":"+server_port[i]+ check + "\n" + if form.getvalue('template') is None: + servers_split += " server "+server+" " + server +":"+server_port[i]+ check + "\n" + else: + servers_split += " server-template "+form.getvalue('prefix')+" "+form.getvalue('template-number')+" "+ server +":"+server_port[i]+ check + "\n" i += 1 compression = form.getvalue("compression") diff --git a/app/create_db.py b/app/create_db.py index 0c6666fa..bcf9f3b8 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -72,6 +72,8 @@ def create_table(**kwargs): `password` VARCHAR ( 128 ), `role` VARCHAR ( 128 ), `groups` VARCHAR ( 120 ), + ldap_user INTEGER NOT NULL DEFAULT 0, + activeuser INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`id`) ); INSERT INTO user (username, email, password, role, groups) VALUES ('admin','admin@localhost','21232f297a57a5a743894a0e4a801fc3','admin','1'), @@ -88,6 +90,9 @@ def create_table(**kwargs): cred INTEGER NOT NULL DEFAULT 1, alert INTEGER NOT NULL DEFAULT 0, metrics INTEGER NOT NULL DEFAULT 0, + port INTEGER NOT NULL DEFAULT 22, + `desc` varchar(64), + active INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`) ); CREATE TABLE IF NOT EXISTS `role` ( @@ -124,6 +129,8 @@ def create_table(**kwargs): CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `backups` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `rhost` VARCHAR ( 120 ), `rpath` VARCHAR ( 120 ), `type` VARCHAR ( 120 ), `time` VARCHAR ( 120 ), cred INTEGER, `description` VARCHAR ( 120 ), PRIMARY KEY(`id`)); + CREATE TABLE IF NOT EXISTS `waf` (`server_id` INTEGER UNIQUE, metrics INTEGER); + CREATE TABLE IF NOT EXISTS `waf_metrics` (`serv` varchar(64), conn INTEGER, `date` DATETIME default '0000-00-00 00:00:00'); """ try: cur.executescript(sql) @@ -149,7 +156,8 @@ def create_table(**kwargs): return True cur.close() con.close() - + + def update_db_v_31(**kwargs): con, cur = get_cur() sql = list() @@ -176,7 +184,7 @@ def update_db_v_31(**kwargs): sql.append("INSERT INTO settings (param, value, section, `desc`) values('tmp_config_path', '/tmp/', 'haproxy', 'Temp store configs, for haproxy check');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('cert_path', '/etc/ssl/certs/', 'haproxy', 'Path to SSL dir');") sql.append("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');") - sql.append("INSERT INTO settings (param, value, section, `desc`) values('lists_path', 'lists', 'main', 'Path to black/white lists');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('lists_path', 'lists', 'main', 'Path to black/white lists. This is a relative path, begins with $HOME_HAPROXY-WI');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');") @@ -202,150 +210,6 @@ def update_db_v_31(**kwargs): cur.close() con.close() -def update_db_v_3_2(**kwargs): - con, cur = get_cur() - sql = """CREATE TABLE IF NOT EXISTS `waf` (`server_id` INTEGER UNIQUE, metrics INTEGER); """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: server_id' or e == "1060 (42S21): Duplicate column name 'server_id' ": - print('Updating... go to version 3.2') - else: - print("An error occurred:", e.args[0]) - return False - else: - return True - cur.close() - con.close() - -def update_db_v_3_21(**kwargs): - con, cur = get_cur() - sql = """CREATE TABLE IF NOT EXISTS `waf_metrics` (`serv` varchar(64), conn INTEGER, `date` DATETIME default '0000-00-00 00:00:00'); """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: token' or e == "1060 (42S21): Duplicate column name 'token' ": - print('Updating... go to version 2.6') - else: - print("An error occurred:", e.args[0]) - return False - else: - return True - cur.close() - con.close() - -def update_db_v_3_2_3(**kwargs): - con, cur = get_cur() - sql = """ - ALTER TABLE `servers` ADD COLUMN port INTEGER NOT NULL DEFAULT 22; - """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: port' or e == " 1060 (42S21): Duplicate column name 'port' ": - print('Updating... go to version 3.2.8') - else: - print("An error occurred:", e) - return False - else: - print("DB was update to 3.2.3") - return True - cur.close() - con.close() - -def update_db_v_3_2_8(**kwargs): - con, cur = get_cur() - sql = """ - ALTER TABLE `servers` ADD COLUMN `desc` varchar(64); - """ - try: - cur.execute(sql) - con.commit() - 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('Updating... go to version 3.3') - else: - print("An error occurred:", e) - return False - else: - print("DB was update to 3.2.8") - return True - cur.close() - con.close() - - -def update_db_v_3_31(**kwargs): - con, cur = get_cur() - sql = """ - ALTER TABLE `user` ADD COLUMN ldap_user INTEGER NOT NULL DEFAULT 0; - """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: ldap_user' or e == " 1060 (42S21): Duplicate column name 'ldap_user' ": - print('Updating... go to version 3.4') - else: - print("An error occurred:", e) - return False - else: - print("DB was update to 3.3") - return True - cur.close() - con.close() - - -def update_db_v_3_4(**kwargs): - con, cur = get_cur() - sql = """ - ALTER TABLE `servers` ADD COLUMN active INTEGER NOT NULL DEFAULT 0; - """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: active' or e == " 1060 (42S21): Duplicate column name 'active' ": - print('Updating... go to version 3.4.1') - else: - print("An error occurred:", e) - return False - else: - print("Updating... go to version 3.4.1") - return True - cur.close() - con.close() - - -def update_db_v_3_4_1(**kwargs): - con, cur = get_cur() - sql = """ - ALTER TABLE `user` ADD COLUMN activeuser INTEGER NOT NULL DEFAULT 1; - """ - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'duplicate column name: activeuser' or e == " 1060 (42S21): Duplicate column name 'activeuser' ": - print('Updating... go to version 3.4.9.5') - else: - print("An error occurred:", e) - return False - else: - print("Updating... go to version 3.4.5.2") - return True - cur.close() - con.close() - def update_db_v_3_4_5_2(**kwargs): con, cur = get_cur() @@ -452,7 +316,7 @@ def update_db_v_3_8_1(**kwargs): pass else: if kwargs.get('silent') != 1: - print('DB was update to 3.8.1') + print('Updating... go to version 3.12.0.0') return True cur.close() con.close() @@ -467,9 +331,9 @@ def update_db_v_3_12(**kwargs): except sqltool.Error as e: if kwargs.get('silent') != 1: if e.args[0] == 'duplicate column name: id' or e == "1060 (42S21): Duplicate column name 'id' ": - print('DB was update to 3.12') + print('Updating... go to version 3.12.1.0') else: - print("DB was update to 3.12") + print("Updating... go to version 3.12.1.0") return False else: return True @@ -477,9 +341,28 @@ def update_db_v_3_12(**kwargs): con.close() +def update_db_v_3_12_1(**kwargs): + con, cur = get_cur() + sql = """INSERT INTO settings (param, value, section, `desc`) values('ssl_local_path', 'certs', 'main', 'Path to dir for local save SSL certs. This is a relative path, begins with $HOME_HAPROXY-WI/app/'); """ + 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.12.1.0') + else: + print("DB was update to 3.12.1.0") + return False + else: + return True + cur.close() + con.close() + + def update_ver(**kwargs): con, cur = get_cur() - sql = """update version set version = '3.12.0.0'; """ + sql = """update version set version = '3.12.1.0'; """ try: cur.execute(sql) con.commit() @@ -491,13 +374,6 @@ def update_ver(**kwargs): def update_all(): update_db_v_31() - update_db_v_3_2() - update_db_v_3_21() - update_db_v_3_2_3() - update_db_v_3_2_8() - update_db_v_3_31() - update_db_v_3_4() - update_db_v_3_4_1() update_db_v_3_4_5_2() if funct.check_ver() is None: update_db_v_3_4_5_22() @@ -506,18 +382,12 @@ def update_all(): update_db_v_3_5_3() update_db_v_3_8_1() update_db_v_3_12() + update_db_v_3_12_1() update_ver() 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_3(silent=1) - update_db_v_3_2_8(silent=1) - update_db_v_3_31(silent=1) - update_db_v_3_4(silent=1) - update_db_v_3_4_1(silent=1) update_db_v_3_4_5_2(silent=1) if funct.check_ver() is None: update_db_v_3_4_5_22() @@ -526,6 +396,7 @@ def update_all_silent(): update_db_v_3_5_3(silent=1) update_db_v_3_8_1(silent=1) update_db_v_3_12(silent=1) + update_db_v_3_12_1(silent=1) update_ver() diff --git a/app/funct.py b/app/funct.py index 556e9d7f..e95b9f49 100644 --- a/app/funct.py +++ b/app/funct.py @@ -162,7 +162,7 @@ def page_for_admin(**kwargs): sys.exit() -def return_ssh_keys_path(serv): +def return_ssh_keys_path(serv, **kwargs): import sql fullpath = get_config_var('main', 'fullpath') ssh_enable = '' @@ -170,11 +170,18 @@ def return_ssh_keys_path(serv): ssh_user_name = '' ssh_user_password = '' - for sshs in sql.select_ssh(serv=serv): - ssh_enable = sshs[3] - ssh_user_name = sshs[4] - ssh_user_password = sshs[5] - ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2] + if kwargs.get('id') != '': + for sshs in sql.select_ssh(id=kwargs.get('id')): + ssh_enable = sshs[2] + ssh_user_name = sshs[3] + ssh_user_password = sshs[4] + ssh_key_name = fullpath+'/keys/%s.pem' % sshs[1] + else: + for sshs in sql.select_ssh(serv=serv): + ssh_enable = sshs[3] + ssh_user_name = sshs[4] + ssh_user_password = sshs[5] + ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2] return ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name @@ -466,7 +473,7 @@ def upload(serv, path, file, **kwargs): try: file = sftp.put(file, full_path) except Exception as e: - logging('localhost', ' Cannot upload '+file+' to '+full_path+'. Error: '+str(e.args), haproxywi=1) + logging('localhost', ' Cannot upload '+file+' to '+full_path+' to server: '+serv+' Error: '+str(e.args), haproxywi=1) pass try: diff --git a/app/haproxy-wi.cfg b/app/haproxy-wi.cfg index 3613ef35..c1182643 100644 --- a/app/haproxy-wi.cfg +++ b/app/haproxy-wi.cfg @@ -1,9 +1,7 @@ [main] #Path to files destination fullpath = /var/www/haproxy-wi -cgi_path = ${fullpath}/app/ -log_path = ${fullpath}/log/ -cert_local_dir = ${cgi_path}/certs/ +log_path = ${fullpath}/log/ [configs] #Dir where configs will be save diff --git a/app/haproxy-wi.db.sql b/app/haproxy-wi.db.sql index 6542fbaa..9e390f32 100644 --- a/app/haproxy-wi.db.sql +++ b/app/haproxy-wi.db.sql @@ -1,8 +1,8 @@ -CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER NOT NULL AUTO_INCREMENT,`username` VARCHAR ( 64 ) UNIQUE,`email` VARCHAR ( 120 ) UNIQUE, `password` VARCHAR ( 128 ),`role` VARCHAR ( 128 ),`groups` VARCHAR ( 120 ), PRIMARY KEY(`id`) ); +CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER NOT NULL AUTO_INCREMENT,`username` VARCHAR ( 64 ) UNIQUE,`email` VARCHAR ( 120 ) UNIQUE, `password` VARCHAR ( 128 ),`role` VARCHAR ( 128 ),`groups` VARCHAR ( 120 ), activeuser INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`id`) ); INSERT INTO `user` (username, email, password, role, groups) VALUES ('admin','admin@localhost','21232f297a57a5a743894a0e4a801fc3','admin','1'); INSERT INTO `user` (username, email, password, role, groups) VALUES ('editor','editor@localhost','5aee9dbd2a188839105073571bee1b1f','editor','1'); INSERT INTO `user` (username, email, password, role, groups) VALUES ('guest','guest@localhost','084e0343a0486ff05530df6c705c8bb4','guest','1'); -CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), type_ip INTEGER NOT NULL DEFAULT 0, enable INTEGER NOT NULL DEFAULT 1, master INTEGER NOT NULL DEFAULT 0, cred INTEGER NOT NULL DEFAULT 1, alert INTEGER NOT NULL DEFAULT 0, metrics INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`) ); +CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), type_ip INTEGER NOT NULL DEFAULT 0, enable INTEGER NOT NULL DEFAULT 1, master INTEGER NOT NULL DEFAULT 0, cred INTEGER NOT NULL DEFAULT 1, alert INTEGER NOT NULL DEFAULT 0, metrics INTEGER NOT NULL DEFAULT 0, port INTEGER NOT NULL DEFAULT 22, `desc` varchar(64), active INTEGER NOT NULL DEFAULT 0,PRIMARY KEY(`id`) ); CREATE TABLE IF NOT EXISTS `role` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`) ); INSERT INTO `role` (name, description) VALUES ('admin','Can do everything'); INSERT INTO `role` (name, description) VALUES ('editor','Can edit configs'); @@ -18,4 +18,6 @@ CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar CREATE TABLE IF NOT EXISTS `version` (`version` varchar(64)); CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); -CREATE TABLE IF NOT EXISTS `backups` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `rhost` VARCHAR ( 120 ), `rpath` VARCHAR ( 120 ), `time` VARCHAR ( 120 ), cred INTEGER, `description` VARCHAR ( 120 ), PRIMARY KEY(`id`)); \ No newline at end of file +CREATE TABLE IF NOT EXISTS `backups` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `rhost` VARCHAR ( 120 ), `rpath` VARCHAR ( 120 ), `time` VARCHAR ( 120 ), cred INTEGER, `description` VARCHAR ( 120 ), PRIMARY KEY(`id`)); +CREATE TABLE IF NOT EXISTS `waf` (`server_id` INTEGER UNIQUE, metrics INTEGER); +CREATE TABLE IF NOT EXISTS `waf_metrics` (`serv` varchar(64), conn INTEGER, `date` DATETIME default '0000-00-00 00:00:00'); \ No newline at end of file diff --git a/app/lists.py b/app/lists.py deleted file mode 100644 index 62146a46..00000000 --- a/app/lists.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -import os -import http, cgi -import funct -import sql -from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('templates/')) -template = env.get_template('lists.html') - -print('Content-type: text/html\n') -funct.check_login() -form = funct.form -funct.page_for_admin(level = 2) - -try: - cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) - user_id = cookie.get('uuid') - user = sql.get_user_name_by_uuid(user_id.value) - user_group = sql.get_user_group_by_uuid(user_id.value) - servers = sql.get_dick_permit(virt=1) - token = sql.get_token(user_id.value) - servbackend = form.getvalue('servbackend') - serv = form.getvalue('serv') - if servbackend is None: - servbackend = "" -except: - pass - - -dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path') -white_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+user_group+"/white" -black_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+user_group+"/black" -if not os.path.exists(dir): - os.makedirs(dir) -if not os.path.exists(dir+"/"+user_group): - os.makedirs(dir+"/"+user_group) -if not os.path.exists(white_dir): - os.makedirs(white_dir) -if not os.path.exists(black_dir): - os.makedirs(black_dir) - -white_lists = funct.get_files(dir=white_dir, format="lst") -black_lists = funct.get_files(dir=black_dir, format="lst") - -template = template.render(h2 = 1, - title = "Lists", - role = sql.get_user_role_by_uuid(user_id.value), - user = user, - white_lists = white_lists, - black_lists = black_lists, - group = user_group, - versions = funct.versions(), - token = token) -print(template) diff --git a/app/options.py b/app/options.py index 9d83e57e..4c831b2c 100644 --- a/app/options.py +++ b/app/options.py @@ -76,7 +76,8 @@ if form.getvalue('ssh_cert'): pass if serv and form.getvalue('ssl_cert'): - cert_local_dir = funct.get_config_var('main', 'cert_local_dir') + #cert_local_dir = funct.get_config_var('main', 'cert_local_dir') + cert_local_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('ssl_local_path') cert_path = sql.get_setting('cert_path') if not os.path.exists(cert_local_dir): @@ -936,34 +937,40 @@ if form.getvalue('bwlists'): if form.getvalue('bwlists_create'): + color = form.getvalue('color') list_name = form.getvalue('bwlists_create').split('.')[0] list_name += '.lst' - list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+form.getvalue('color')+"/"+list_name + list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+color+"/"+list_name try: open(list, 'a').close() print('
'+form.getvalue('color')+' list was created
') + funct.logging(server[1], 'has created '+color+' list '+list_name, haproxywi=1, login=1) except IOError as e: print('
Cat\'n create new '+form.getvalue('color')+' list. %s
' % e) if form.getvalue('bwlists_save'): - list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+form.getvalue('color')+"/"+form.getvalue('bwlists_save') + color = form.getvalue('color') + bwlists_save = form.getvalue('bwlists_save') + list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+color+"/"+bwlists_save try: with open(list, "w") as file: file.write(form.getvalue('bwlists_content')) except IOError as e: - print('
Cat\'n save '+form.getvalue('color')+' list. %s
' % e) + print('
Cat\'n save '+color+' list. %s
' % e) servers = sql.get_dick_permit() - path = sql.get_setting('haproxy_dir')+"/"+form.getvalue('color') + path = sql.get_setting('haproxy_dir')+"/"+color for server in servers: funct.ssh_command(server[2], ["sudo mkdir "+path]) - error = funct.upload(server[2], path+"/"+form.getvalue('bwlists_save'), list, dir='fullpath') + funct.ssh_command(server[2], ["sudo chown $(whoami) "+path]) + error = funct.upload(server[2], path+"/"+bwlists_save, list, dir='fullpath') if error: print('
Upload fail: %s
' % error) else: - print('
Edited '+form.getvalue('color')+' list was uploaded to '+server[1]+'
') + print('
Edited '+color+' list was uploaded to '+server[1]+'
') + funct.logging(server[1], 'has edited '+color+' list '+bwlists_save, haproxywi=1, login=1) if form.getvalue('bwlists_restart') == 'restart': funct.ssh_command(server[2], ["sudo " + sql.get_setting('restart_command')]) @@ -1016,3 +1023,4 @@ if form.getvalue('change_waf_mode'): serv = sql.select_server_by_name(server_hostname) commands = [ "sudo sed -i 's/^SecRuleEngine.*/SecRuleEngine %s/' %s/waf/modsecurity.conf " % (waf_mode, haproxy_dir) ] funct.ssh_command(serv, commands) + funct.logging(serv, 'Was changed WAF mod to '+waf_mode, haproxywi=1, login=1) diff --git a/app/servers.py b/app/servers.py index 7fb366dc..8386fa8d 100644 --- a/app/servers.py +++ b/app/servers.py @@ -37,6 +37,6 @@ output_from_parsed_template = template.render(title = "Servers manage", telegrams = sql.get_user_telegram_by_uuid(user_id.value), token = token, versions = funct.versions(), - backups = sql.select_backups(), + backups = sql.select_backups(), ldap_enable = ldap_enable) print(output_from_parsed_template) diff --git a/app/sql.py b/app/sql.py index 16eb1cf3..fd113d71 100644 --- a/app/sql.py +++ b/app/sql.py @@ -1635,7 +1635,7 @@ if form.getvalue('newserver') is not None: else: if add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, desc, active): show_update_server(ip, page) - funct.logging('a new server '+hostname, ' created ', haproxywi=1, login=1) + #funct.logging('a new server '+hostname, ' created ', haproxywi=1, login=1) if form.getvalue('serverdel') is not None: diff --git a/app/templates/add.html b/app/templates/add.html index cbbb8e12..cb7a2fce 100644 --- a/app/templates/add.html +++ b/app/templates/add.html @@ -19,9 +19,11 @@ h3 {
  • SSL certificates
  • Options
  • Servers
  • -
  • Userlist
  • +
  • Userlists
  • +
  • Lists
  • {% include 'include/login.html' %} + {% include 'include/add_proxy.html' %}
    @@ -172,6 +174,9 @@ h3 { Servers: {% include 'include/add_servers.html' %} +
    +
    + {{ checkbox('template-listen', name='template', title='Use server-template instead servers list', value='template', desc='Server-template') }} @@ -470,6 +475,9 @@ h3 { Servers: {% include 'include/add_servers.html' %} +
    +
    + {{ checkbox('template-backend', name='template', title='Use server-template instead servers list', value='template', desc='Server-template') }} @@ -739,6 +747,45 @@ h3 {
    +
    + + + + + + + + + + {{ input('group', value=group, type='hidden') }} +
    New black list + Exists black lists + New white list + Exists white lists +
    + Name: {{ input('new_blacklist_name') }} + + + {% for list in black_lists %} + {{ list }} + {% endfor %} + + Name: {{ input('new_whitelist_name') }} + + + {% for list in white_lists %} + {{ list }} + {% endfor %} +
    +
    + In this section you can create and edit black and white lists. And after use them in the HAProxy configs or in the "Add proxy" pages +
    +
    + +
    {% include 'include/del_confirm.html' %}