diff --git a/app/create_db.py b/app/create_db.py index f3fa0ffb..270f949e 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -152,51 +152,54 @@ def create_table(**kwargs): def update_db_v_31(**kwargs): con, cur = get_cur() - sql = [ "INSERT INTO settings (param, value, section, `desc`) values('time_zone', 'UTC', 'main', 'Time Zone');", - "INSERT INTO settings (param, value, section, `desc`) values('proxy', '', 'main', 'Proxy server. Use proto://ip:port');", - "INSERT INTO settings (param, value, section, `desc`) values('session_ttl', '5', 'main', 'Time to live users sessions. In days');", - "INSERT INTO settings (param, value, section, `desc`) values('token_ttl', '5', 'main', 'Time to live users tokens. In days');", - "INSERT INTO settings (param, value, section, `desc`) values('local_path_logs', '/var/log/haproxy.log', 'logs', 'Logs save locally, disable by default');", - "INSERT INTO settings (param, value, section, `desc`) values('syslog_server_enable', '0', 'logs', 'If exist syslog server for HAproxy logs, enable this option');", - "INSERT INTO settings (param, value, section, `desc`) values('syslog_server', '0', 'logs', 'IP address syslog server');", - "INSERT INTO settings (param, value, section, `desc`) values('log_time_storage', '14', 'logs', 'Time of storage of logs of user activity, in days');", - "INSERT INTO settings (param, value, section, `desc`) values('restart_command', 'systemctl restart haproxy', 'haproxy', 'Command for restart HAproxy service');", - "INSERT INTO settings (param, value, section, `desc`) values('status_command', 'systemctl status haproxy', 'haproxy', 'Command for status check HAproxy service');", - "INSERT INTO settings (param, value, section, `desc`) values('stats_user', 'admin', 'haproxy', 'Username for Stats web page HAproxy');", - "INSERT INTO settings (param, value, section, `desc`) values('stats_password', 'password', 'haproxy', 'Password for Stats web page HAproxy');", - "INSERT INTO settings (param, value, section, `desc`) values('stats_port', '8085', 'haproxy', 'Port Stats web page HAproxy');", - "INSERT INTO settings (param, value, section, `desc`) values('stats_page', 'stats', 'haproxy', 'URI Stats web page HAproxy');", - "INSERT INTO settings (param, value, section, `desc`) values('haproxy_dir', '/etc/haproxy/', 'haproxy', 'Path to HAProxy dir');", - "INSERT INTO settings (param, value, section, `desc`) values('haproxy_config_path', '/etc/haproxy/haproxy.cfg', 'haproxy', 'Path to HAProxy config');", - "INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');", - "INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');", - "INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');", - "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');", - "INSERT INTO settings (param, value, section, `desc`) values('lists_path', 'lists', 'main', 'Path to black/white lists');", - "INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');" - "INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_port', '389', 'ldap', 'Default port is 389 or 636');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_user', '', 'ldap', 'Login for connect to LDAP server. Enter: user@domain.com');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_password', '', 'ldap', 'Password for connect to LDAP server');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_base', '', 'ldap', 'Base domain. Example: dc=domain, dc=com');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_domain', '', 'ldap', 'Domain for login, that after @, like user@domain.com, without user@');", - "INSERT INTO settings (param, value, section, `desc`) values('ldap_search_field', 'mail', 'ldap', 'Field where user e-mail saved'" ] - try: - for i in sql: + sql = list() + sql.append("INSERT INTO settings (param, value, section, `desc`) values('time_zone', 'UTC', 'main', 'Time Zone');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('proxy', '', 'main', 'Proxy server. Use proto://ip:port');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('session_ttl', '5', 'main', 'Time to live users sessions. In days');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('token_ttl', '5', 'main', 'Time to live users tokens. In days');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('local_path_logs', '/var/log/haproxy.log', 'logs', 'Logs save locally, disable by default');") + 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('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');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('stats_page', 'stats', 'haproxy', 'URI Stats web page HAproxy');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_dir', '/etc/haproxy/', 'haproxy', 'Path to HAProxy dir');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_config_path', '/etc/haproxy/haproxy.cfg', 'haproxy', 'Path to HAProxy config');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');") + 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('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');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_port', '389', 'ldap', 'Default port is 389 or 636');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_user', '', 'ldap', 'Login for connect to LDAP server. Enter: user@domain.com');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_password', '', 'ldap', 'Password for connect to LDAP server');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_base', '', 'ldap', 'Base domain. Example: dc=domain, dc=com');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_domain', '', 'ldap', 'Domain for login, that after @, like user@domain.com, without user@');") + sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_search_field', 'mail', 'ldap', 'Field where user e-mail saved');") + + for i in sql: + try: cur.execute(i) con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - if e.args[0] == 'column param is not unique' or e == "1060 (42S21): column param is not unique ": - print('Updating... go to version 3.2') - else: - print("An error occurred:", e) - return False + except sqltool.Error as e: + pass + # if kwargs.get('silent') != 1: + # if e.args[0] == 'column param is not unique' or e == "1060 (42S21): column param is not unique ": + # print('Updating... go to version 3.2') + # else: + # print("An error occurred:", e) else: - pass + if kwargs.get('silent') != 1: + print('Updating... go to version 3.2') return True cur.close() con.close() @@ -398,7 +401,7 @@ def update_db_v_3_4_7(**kwargs): def update_ver(**kwargs): con, cur = get_cur() - sql = """update version set version = '3.4.7'; """ + sql = """update version set version = '3.4.8'; """ try: cur.execute(sql) con.commit() diff --git a/app/funct.py b/app/funct.py index 21061619..4b16b79b 100644 --- a/app/funct.py +++ b/app/funct.py @@ -261,13 +261,18 @@ def get_section_from_config(config, section): continue if record: - if line.startswith('listen') or line.startswith('frontend') or line.startswith('backend') or line.startswith('cache') or line.startswith('defaults') or line.startswith('global'): + if line.startswith('listen') or line.startswith('frontend') or line.startswith('backend') or line.startswith('cache') or line.startswith('defaults') or line.startswith('global') or line.startswith('#HideBlockEnd') or line.startswith('#HideBlockStart'): record = False end_line = index end_line = end_line - 1 else: return_config += line - + + if end_line == "": + f = open (config,"r" ) + lineList = f.readlines() + end_line = len(lineList) + return start_line, end_line, return_config @@ -282,6 +287,7 @@ def rewrite_section(start_line, end_line, config, section): if index == start_line: record = True return_config += section + return_config += "\n" continue if index == end_line: record = False diff --git a/app/haproxy-wi.cfg b/app/haproxy-wi.cfg index a73e5203..a5b31e27 100644 --- a/app/haproxy-wi.cfg +++ b/app/haproxy-wi.cfg @@ -14,7 +14,7 @@ kp_save_configs_dir = ${main:fullpath}/configs/kp_config/ #Enable MySQL DB. Default will be used Sqlite DB. Default disable enable = 0 mysql_user = haproxy-wi -mysql_password = haproxy-wi +mysql_password = haproxywi mysql_db = haproxywi mysql_host = 127.0.0.1 diff --git a/app/login.py b/app/login.py index 3c1663e7..bd1a9e1a 100644 --- a/app/login.py +++ b/app/login.py @@ -54,6 +54,7 @@ def ban(): c["ban"] = 1 c["ban"]["path"] = "/app/" c["ban"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") + funct.logging('locahost', login+' Failed log in', haproxywi=1, login=1) print(c) print("Content-type: text/html\n") print('ban') diff --git a/app/ovw.py b/app/ovw.py index b2b2bb43..fb41d843 100644 --- a/app/ovw.py +++ b/app/ovw.py @@ -72,6 +72,8 @@ async def async_get_overviewServers(serv1, serv2, desc): cmd = 'echo "show info" |nc %s %s |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % (serv2, haproxy_sock_port) out = funct.subprocess_execute(cmd) out1 = "" + user_id = cookie.get('uuid') + role = sql.get_user_role_by_uuid(user_id.value) hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') cfg = hap_configs_dir + serv2 + "-" + funct.get_data('config') + ".cfg" funct.get_config(serv2, cfg) @@ -86,19 +88,23 @@ async def async_get_overviewServers(serv1, serv2, desc): else: out1 = "Can\'t connect to HAproxy" - # server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),funct.show_backends(serv2, ret=1), desc) - server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),backends, desc) + if role <= 2: + server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),backends, desc) + else: + server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),funct.show_backends(serv2, ret=1), desc) + return server_status async def get_runner_overviewServers(): template = env.get_template('overviewServers.html') - + user_id = cookie.get('uuid') + role = sql.get_user_role_by_uuid(user_id.value) futures = [async_get_overviewServers(server[1], server[2], server[11]) for server in listhap] for i, future in enumerate(asyncio.as_completed(futures)): result = await future servers.append(result) servers_sorted = sorted(servers, key=funct.get_key) - template = template.render(service_status=servers_sorted) + template = template.render(service_status=servers_sorted, role=role) print(template) def get_overviewServers(): @@ -135,17 +141,17 @@ def get_map(serv): node = "" line_new2 = [1,""] - i,k = 1200, 1200 + i,k = 800, 800 j, m = 0, 0 for line in conf: if line.startswith('listen') or line.startswith('frontend'): if "stats" not in line: node = line - i = i - 500 + i = i - 750 if line.find("backend") == 0: node = line - i = i - 500 - G.add_node(node,pos=(k,i),label_pos=(k,i+150)) + i = i - 700 + G.add_node(node,pos=(k,i),label_pos=(k,i+100)) if "bind" in line or (line.startswith('listen') and ":" in line) or (line.startswith('frontend') and ":" in line): try: @@ -155,13 +161,13 @@ def get_map(serv): bind = bind[1].split("crt") node = node.strip(' \t\n\r') node = node + ":" + bind[0] - G.add_node(node,pos=(k,i),label_pos=(k,i+150)) + G.add_node(node,pos=(k,i),label_pos=(k,i+100)) except: pass if "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line and "#" not in line: if "timeout" not in line and "default-server" not in line and "#" not in line and "stats" not in line: - i = i - 300 + i = i - 1050 j = j + 1 if "check" in line: line_new = line.split("check") @@ -177,9 +183,9 @@ def get_map(serv): line_new2[1] = line_new2[1].strip(' \t\n\r') if j % 2 == 0: - G.add_node(line_new[0],pos=(k+250,i-350),label_pos=(k+225,i-100)) + G.add_node(line_new[0],pos=(k+230,i-335),label_pos=(k+225,i-180)) else: - G.add_node(line_new[0],pos=(k-250,i-50),label_pos=(k-225,i+180)) + G.add_node(line_new[0],pos=(k-230,i-0),label_pos=(k-225,i+180)) if line_new2[1] != "": G.add_edge(node, line_new[0], port=line_new2[1]) @@ -193,7 +199,7 @@ def get_map(serv): edge_labels = nx.get_edge_attributes(G,'port') try: - plt.figure(10,figsize=(15,20)) + plt.figure(10,figsize=(10,15)) nx.draw(G, pos, with_labels=False, font_weight='bold', width=3, alpha=0.1,linewidths=5) nx.draw_networkx_nodes(G,pos, node_color="skyblue", node_size=100, alpha=0.8, node_shape="p") nx.draw_networkx_labels(G,pos=pos_label, alpha=1, font_color="green", font_size=10) diff --git a/app/templates/ajax/config_show.html b/app/templates/ajax/config_show.html index 3bf058bf..9099e872 100644 --- a/app/templates/ajax/config_show.html +++ b/app/templates/ajax/config_show.html @@ -1,7 +1,9 @@

Config from {{serv}}

- Edit + {% if role %} + Edit + {% endif %} Expand all @@ -23,7 +25,7 @@ {% endif %} {% if line.startswith('global') %} {{ line }} - {% if role <= 2 %} + {% if role %} Edit @@ -33,7 +35,7 @@ {% endif %} {% if line.startswith('defaults') %} {{ line }} - {% if role <= 2 %} + {% if role %} Edit @@ -43,7 +45,7 @@ {% endif %} {% if line.startswith('listen') %} {{ line }} - {% if role <= 2 %} + {% if role %} Edit @@ -53,7 +55,7 @@ {% endif %} {% if line.startswith('frontend') %} {{ line }} - {% if role <= 2 %} + {% if role %} Edit @@ -63,7 +65,7 @@ {% endif %} {% if line.startswith('backend') %} {{ line }} - {% if role <= 2 %} + {% if role %} Edit diff --git a/app/templates/base.html b/app/templates/base.html index b74c8cc1..a839e992 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -110,7 +110,7 @@ v{{current_ver}} {% endif %}
- Donate + Donate diff --git a/app/templates/sections.html b/app/templates/sections.html index b3f63983..19d96478 100644 --- a/app/templates/sections.html +++ b/app/templates/sections.html @@ -55,6 +55,7 @@ {% else %}

Config ok
+ Configs | Go to view stats {% endif %} diff --git a/inc/style.css b/inc/style.css index 45af9944..3b238251 100644 --- a/inc/style.css +++ b/inc/style.css @@ -126,7 +126,7 @@ margin-top: -4px; top:0; left: 0; width: 100%; - height: 100%; + height: 110%; background: rgba(0,0,0,.1); z-index: 500; } @@ -739,7 +739,7 @@ label { .even { background-color: #f3f8fb; } -.mCSB_container { - overflow-y: hidden !important; - overflow-x: auto !important; -} \ No newline at end of file +/* .mCSB_container { */ + /* overflow-y: hidden !important; */ + /* overflow-x: auto !important; */ +/* } */ \ No newline at end of file