')
+
+ node = ""
+ line_new2 = [1,""]
+ 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 - 750
+ if line.find("backend") == 0:
+ node = line
+ 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:
+ bind = line.split(":")
+ if stats_port not in bind[1]:
+ bind[1] = bind[1].strip(' ')
+ 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+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 - 1050
+ j = j + 1
+ if "check" in line:
+ line_new = line.split("check")
+ else:
+ line_new = line.split("if ")
+ if "server" in line:
+ line_new1 = line_new[0].split("server")
+ line_new[0] = line_new1[1]
+ line_new2 = line_new[0].split(":")
+ line_new[0] = line_new2[0]
+
+ line_new[0] = line_new[0].strip(' \t\n\r')
+ line_new2[1] = line_new2[1].strip(' \t\n\r')
+
+ if j % 2 == 0:
+ 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-230,i-0),label_pos=(k-225,i+180))
+
+ if line_new2[1] != "":
+ G.add_edge(node, line_new[0], port=line_new2[1])
+ else:
+ G.add_edge(node,line_new[0])
+
+ os.system("/bin/rm -f " + cfg)
+
+ pos=nx.get_node_attributes(G,'pos')
+ pos_label=nx.get_node_attributes(G,'label_pos')
+ edge_labels = nx.get_edge_attributes(G,'port')
+
+ try:
+ 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)
+ nx.draw_networkx_edges(G,pos, width=0.5,alpha=0.5, edge_color="#5D9CEB",arrows=False)
+ nx.draw_networkx_edge_labels(G, pos,label_pos=0.5,font_color="blue", labels=edge_labels, font_size=8)
+
+ plt.savefig("map.png")
+ plt.show()
+ except Exception as e:
+ print('
' + str(e) + '
')
+
+ cmd = "rm -f "+os.path.dirname(os.getcwd())+"/map*.png && mv map.png "+os.path.dirname(os.getcwd())+"/map"+date+".png"
+ output, stderr = funct.subprocess_execute(cmd)
+ print(stderr)
+
+ print('' % date)
+
if form.getvalue('servaction') is not None:
server_state_file = sql.get_setting('server_state_file')
@@ -310,6 +530,7 @@ if form.getvalue('servaction') is not None:
action = 'edit.py ' + enable + ' ' + backend
funct.logging(serv, action)
+
if act == "showCompareConfigs":
import glob
from jinja2 import Environment, FileSystemLoader
@@ -321,6 +542,7 @@ if act == "showCompareConfigs":
template = template.render(serv=serv, right=right, left=left, return_files=funct.get_files())
print(template)
+
if serv is not None and form.getvalue('right') is not None:
from jinja2 import Environment, FileSystemLoader
left = form.getvalue('left')
@@ -336,6 +558,7 @@ if serv is not None and form.getvalue('right') is not None:
print(template)
print(stderr)
+
if serv is not None and act == "configShow":
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
@@ -360,6 +583,7 @@ if serv is not None and act == "configShow":
if form.getvalue('configver') is None:
os.system("/bin/rm -f " + cfg)
+
if form.getvalue('master'):
master = form.getvalue('master')
slave = form.getvalue('slave')
@@ -390,6 +614,7 @@ if form.getvalue('master'):
os.system("rm -f %s" % script)
sql.update_server_master(master, slave)
+
if form.getvalue('masteradd'):
master = form.getvalue('masteradd')
slave = form.getvalue('slaveadd')
@@ -412,9 +637,11 @@ if form.getvalue('masteradd'):
os.system("rm -f %s" % script)
+
if form.getvalue('haproxyaddserv'):
funct.install_haproxy(form.getvalue('haproxyaddserv'), syn_flood=form.getvalue('syn_flood'), hapver=form.getvalue('hapver'))
+
if form.getvalue('installwaf'):
funct.waf_install(form.getvalue('installwaf'))
@@ -422,8 +649,10 @@ if form.getvalue('installwaf'):
if form.getvalue('update_haproxy_wi'):
funct.update_haproxy_wi()
+
if form.getvalue('metrics_waf'):
sql.update_waf_metrics_enable(form.getvalue('metrics_waf'), form.getvalue('enable'))
+
if form.getvalue('table_metrics'):
import http.cookies
@@ -498,6 +727,7 @@ if form.getvalue('get_hap_v'):
output = funct.check_haproxy_version(serv)
print(output)
+
if form.getvalue('bwlists'):
list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+form.getvalue('color')+"/"+form.getvalue('bwlists')
try:
@@ -508,6 +738,7 @@ if form.getvalue('bwlists'):
except IOError:
print('
Cat\'n read '+form.getvalue('color')+' list
')
+
if form.getvalue('bwlists_create'):
list_name = form.getvalue('bwlists_create').split('.')[0]
list_name += '.lst'
@@ -518,6 +749,7 @@ if form.getvalue('bwlists_create'):
except IOError as e:
print('
Cat\'n create new '+form.getvalue('color')+' list. %s
')
-
- node = ""
- line_new2 = [1,""]
- 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 - 750
- if line.find("backend") == 0:
- node = line
- 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:
- bind = line.split(":")
- if stats_port not in bind[1]:
- bind[1] = bind[1].strip(' ')
- 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+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 - 1050
- j = j + 1
- if "check" in line:
- line_new = line.split("check")
- else:
- line_new = line.split("if ")
- if "server" in line:
- line_new1 = line_new[0].split("server")
- line_new[0] = line_new1[1]
- line_new2 = line_new[0].split(":")
- line_new[0] = line_new2[0]
-
- line_new[0] = line_new[0].strip(' \t\n\r')
- line_new2[1] = line_new2[1].strip(' \t\n\r')
-
- if j % 2 == 0:
- 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-230,i-0),label_pos=(k-225,i+180))
-
- if line_new2[1] != "":
- G.add_edge(node, line_new[0], port=line_new2[1])
- else:
- G.add_edge(node,line_new[0])
-
- os.system("/bin/rm -f " + cfg)
-
- pos=nx.get_node_attributes(G,'pos')
- pos_label=nx.get_node_attributes(G,'label_pos')
- edge_labels = nx.get_edge_attributes(G,'port')
-
- try:
- 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)
- nx.draw_networkx_edges(G,pos, width=0.5,alpha=0.5, edge_color="#5D9CEB",arrows=False)
- nx.draw_networkx_edge_labels(G, pos,label_pos=0.5,font_color="blue", labels=edge_labels, font_size=8)
-
- plt.savefig("map.png")
- plt.show()
- except Exception as e:
- print('
' + str(e) + '
')
-
- cmd = "rm -f "+os.path.dirname(os.getcwd())+"/map*.png && mv map.png "+os.path.dirname(os.getcwd())+"/map"+date+".png"
- output, stderr = funct.subprocess_execute(cmd)
- print(stderr)
-
- print('' % date)
\ No newline at end of file
diff --git a/app/settings.py b/app/settings.py
deleted file mode 100644
index 62e79973..00000000
--- a/app/settings.py
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env python3
-import cgi
-import os
-import funct
-import sql
-import http
-from jinja2 import Environment, FileSystemLoader
-env = Environment(loader=FileSystemLoader('templates/'))
-template = env.get_template('settings.html')
-form = cgi.FieldStorage()
-
-print('Content-type: text/html\n')
-funct.check_login()
-funct.page_for_admin()
-
-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)
- settings = sql.get_setting('', all=1)
- token = sql.get_token(user_id.value)
-except:
- pass
-
-
-template = template.render(h2 = 1, title = "Settings",
- role = sql.get_user_role_by_uuid(user_id.value),
- user = user,
- settings = settings,
- versions = funct.versions(),
- token = token)
-print(template)
\ No newline at end of file
diff --git a/app/sql.py b/app/sql.py
index 1853fc98..e0feb09e 100644
--- a/app/sql.py
+++ b/app/sql.py
@@ -1405,13 +1405,13 @@ def check_token():
sys.exit()
-def check_group(group):
+def check_group(group, role_id):
import http.cookies
import os
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
user_group = get_user_group_by_uuid(user_id.value)
- if user_group == group or user_group == '1':
+ if user_group == group or user_group == '1' or role_id == 1:
return True
else:
funct.logging(new_user, ' tried to change user group', haproxywi=1, login=1)
@@ -1430,8 +1430,8 @@ if form.getvalue('newuser') is not None:
if password is None or role is None or group is None:
print(error_mess)
else:
- if check_group(group):
- role_id = get_role_id_by_name(role)
+ role_id = get_role_id_by_name(role)
+ if check_group(group, role_id):
if funct.is_admin(level=role_id):
if add_user(new_user, email, password, role, group, activeuser):
show_update_user(new_user, page)
@@ -1452,8 +1452,8 @@ if form.getvalue('updateuser') is not None:
if new_user is None or role is None or group is None:
print(error_mess)
else:
- if check_group(group):
- role_id = get_role_id_by_name(role)
+ role_id = get_role_id_by_name(role)
+ if check_group(group, role_id):
if funct.is_admin(level=role_id):
update_user(new_user, email, role, group, id, activeuser)
else:
diff --git a/app/templates/admin.html b/app/templates/admin.html
index 977473c3..a8aedc9b 100644
--- a/app/templates/admin.html
+++ b/app/templates/admin.html
@@ -17,6 +17,8 @@
+ {% set current_ver = versions.0 %}
+ {% set new_ver = versions.1 %}
+ {% set current_ver_without_dots = versions.2 %}
+ {% set new_ver_without_dots = versions.3 %}
+
+
+
Currnet version
+
Last version
+
+
+
+
+ {{current_ver}}
+
+
+ {{new_ver}}
+
+
+
+ {% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %}
+ Update
+ {% endif %}
+
+
+
+ Note:
+ For update you have to use HAProxy-WI repository. How start use repository read here
+
+
+ If server uses proxy to connection Internet add proxy settings in yum.conf
+
+
+ Read more about update in docs
+ and changelog
+
-{% endblock %}
\ No newline at end of file
diff --git a/app/templates/update.html b/app/templates/update.html
deleted file mode 100644
index 28df1953..00000000
--- a/app/templates/update.html
+++ /dev/null
@@ -1,39 +0,0 @@
-{% extends "base.html" %}
-{% block content %}
-{% set current_ver = versions.0 %}
- {% set new_ver = versions.1 %}
- {% set current_ver_without_dots = versions.2 %}
- {% set new_ver_without_dots = versions.3 %}
-
-
-
-
Currnet version
-
Last version
-
-
-
-
- {{current_ver}}
-
-
- {{new_ver}}
-
-
-
- {% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %}
- Update
- {% endif %}
-
-
-
- Note:
- For update you have to use HAProxy-WI repository. If do not use repositiry then use update.sh script in HAProxy-WI home directory
-
- If server uses proxy to connection Internet add proxy settings in yum.conf
-
-
- Read more about update in docs
- and changelog
-
-
-{% endblock %}
\ No newline at end of file
diff --git a/app/update.py b/app/update.py
deleted file mode 100644
index 675d0bbb..00000000
--- a/app/update.py
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env python3
-import http.cookies
-import os
-import funct, sql
-from jinja2 import Environment, FileSystemLoader
-env = Environment(loader=FileSystemLoader('templates/'))
-template = env.get_template('update.html')
-
-print('Content-type: text/html\n')
-funct.check_login()
-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)
- token = sql.get_token(user_id.value)
-except:
- pass
-
-
-output_from_parsed_template = template.render(h2 = 1, title = "Check updates",
- role = sql.get_user_role_by_uuid(user_id.value),
- user = user,
- versions = funct.versions(),
- token = token)
-print(output_from_parsed_template)
\ No newline at end of file
diff --git a/app/users.py b/app/users.py
index 47c25779..222bb2dc 100644
--- a/app/users.py
+++ b/app/users.py
@@ -23,22 +23,24 @@ try:
users = sql.select_users()
servers = sql.get_dick_permit()
token = sql.get_token(user_id.value)
+ settings = sql.get_setting('', all=1)
ldap_enable = sql.get_setting('ldap_enable')
except:
pass
-output_from_parsed_template = template.render(title = "Admin area: users manage",
- role = sql.get_user_role_by_uuid(user_id.value),
- user = user,
- users = users,
- groups = sql.select_groups(),
- servers = sql.select_servers(full=1),
- roles = sql.select_roles(),
- masters = sql.select_servers(get_master_servers=1),
- sshs = sql.select_ssh(),
- telegrams = sql.select_telegram(),
- token = token,
- versions = funct.versions(),
- ldap_enable = ldap_enable)
-print(output_from_parsed_template)
+template = template.render(title = "Admin area: users manage",
+ role = sql.get_user_role_by_uuid(user_id.value),
+ user = user,
+ users = users,
+ groups = sql.select_groups(),
+ servers = sql.select_servers(full=1),
+ roles = sql.select_roles(),
+ masters = sql.select_servers(get_master_servers=1),
+ sshs = sql.select_ssh(),
+ telegrams = sql.select_telegram(),
+ token = token,
+ versions = funct.versions(),
+ settings = settings,
+ ldap_enable = ldap_enable)
+print(template)
diff --git a/app/viewlogs.py b/app/viewlogs.py
index bc70ed5a..6793da0c 100644
--- a/app/viewlogs.py
+++ b/app/viewlogs.py
@@ -58,14 +58,8 @@ try:
except:
pass
-
-def get_files():
- file = []
- for files in glob.glob(os.path.join(log_path,'*.log*')):
- file += [(files.split('/')[5], files.split('/')[5])]
- return sorted(file, reverse=True)
-selects = get_files()
+selects = funct.get_files(log_path, format="log")
selects.append(['haproxy-wi.error.log','error.log'])
selects.append(['haproxy-wi.access.log','access.log'])
output_from_parsed_template = template.render(h2 = 1,
diff --git a/inc/jquery-linenumbers.js b/inc/jquery-linenumbers.js
new file mode 100644
index 00000000..4553cc4e
--- /dev/null
+++ b/inc/jquery-linenumbers.js
@@ -0,0 +1,2 @@
+!function($){$.fn.linenumbers=function(t){var e=$.extend({col_width:"65px",start:1,digits:3},t);return $("[data-name='linenumbers']").remove(),this.each(function(){var t=$(this).prop("offsetWidth"),r=$(this).prop("offsetHeight"),s=parseInt(t)-parseInt(e.col_width);$(this).before(''),$(this).css({width:s+"px",height:r+"px"}),$(this).after('');var n=$(this).parent().find('textarea[disabled="disabled"]');$(this).bind("blur focus change keyup keydown",function(){var t="\n"+$(this).val();t=t.match(/[^\n]*\n[^\n]*/gi);var r="",s="",a="";for(i=0;iPlease don\'t close and don\'t represh page. Wait until the work is completed. This may take some time
Update was success!');
} else if (data.indexOf('Unauthorized') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you Unauthorized in the HAProxy-WI repository. How to get HAProxy-WI auth you can read hear ');
+ $("#ajax-update").html('
It is seems like you Unauthorized in the HAProxy-WI repository. How to get HAProxy-WI auth you can read hear ');
} else if (data.indexOf('but not installed') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
You have settings for HAProxy-WI repository, but installed HAProxy-WI without repository. Please reinstall with yum or use update.sh');
+ $("#ajax-update").html('
You have settings for HAProxy-WI repository, but installed HAProxy-WI without repository. Please reinstall with yum or use update.sh');
} else if (data.indexOf('No Match for argument') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you do not have HAProxy-WI repository settings. Please read docs fordetail');
+ $("#ajax-update").html('
It is seems like you do not have HAProxy-WI repository settings. Please read docs fordetail');
} else if (data.indexOf('password for') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you need add Apache user to sudoers. Please read docs fordetail');
+ $("#ajax-update").html('
It is seems like you need add Apache user to sudoers. Please read docs fordetail');
} else if (data.indexOf('No packages marked for update') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you have the lastest version HAProxy-WI');
+ $("#ajax-update").html('
It is seems like you have the lastest version HAProxy-WI');
} else if (data.indexOf('Connection timed out') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
Cannot connect to HAProxy-WI repository. Connection timed out');
+ $("#ajax-update").html('
Cannot connect to HAProxy-WI repository. Connection timed out');
} else if (data.indexOf('--disable') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you have problem with your repositorys.');
+ $("#ajax-update").html('
It is seems like you have problem with your repositorys.');
} else if (data.indexOf('Unauthorized') != '-1') {
$('.alert-danger').remove();
$('.alert-warning').remove();
- $("#ajax").html('
It is seems like you Unauthorized in the HAProxy-WI repository.');
+ $("#ajax-update").html('
It is seems like you Unauthorized in the HAProxy-WI repository.');
}
}
} );