Pavel Loginov 2020-11-02 23:01:08 +06:00
parent aefed2d987
commit f7dd5398da
26 changed files with 419 additions and 263 deletions

View File

@ -20,58 +20,58 @@ aftersave = ""
try: try:
user, user_id, role, token, servers = funct.get_users_params() user, user_id, role, token, servers = funct.get_users_params()
except: except Exception:
pass pass
if service == 'keepalived': if service == 'keepalived':
title = "Working with Keepalived configs" title = "Working with Keepalived configuration files"
action = "config.py?service=keepalived" action = "config.py?service=keepalived"
configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir') configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir')
format = 'conf' file_format = 'conf'
servers = sql.get_dick_permit(keepalived=1) servers = sql.get_dick_permit(keepalived=1)
elif service == 'nginx': elif service == 'nginx':
title = "Working with Nginx configs" title = "Working with Nginx configuration files"
action = "config.py?service=nginx" action = "config.py?service=nginx"
configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir') configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir')
format = 'conf' file_format = 'conf'
servers = sql.get_dick_permit(nginx=1) servers = sql.get_dick_permit(nginx=1)
else: else:
title = "Working with HAProxy configs" title = "Working with HAProxy configuration files"
action = "config.py" action = "config.py"
configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
format = 'cfg' file_format = 'cfg'
servers = sql.get_dick_permit() servers = sql.get_dick_permit()
if serv is not None: if serv is not None:
cfg = configs_dir + serv + "-" + funct.get_data('config') + "."+format cfg = configs_dir + serv + "-" + funct.get_data('config') + "."+file_format
if serv is not None and form.getvalue('open') is not None : if serv is not None and form.getvalue('open') is not None:
funct.check_is_server_in_group(serv) funct.check_is_server_in_group(serv)
if service == 'keepalived': if service == 'keepalived':
error = funct.get_config(serv, cfg, keepalived=1) error = funct.get_config(serv, cfg, keepalived=1)
try: try:
funct.logging(serv, " Keepalived config has opened for ") funct.logging(serv, " Keepalived config has opened for ")
except: except Exception:
pass pass
elif service == 'nginx': elif service == 'nginx':
error = funct.get_config(serv, cfg, nginx=1) error = funct.get_config(serv, cfg, nginx=1)
try: try:
funct.logging(serv, " Nginx config has opened ") funct.logging(serv, " Nginx config has opened ")
except: except Exception:
pass pass
else: else:
error = funct.get_config(serv, cfg) error = funct.get_config(serv, cfg)
try: try:
funct.logging(serv, " HAProxy config has opened ") funct.logging(serv, " HAProxy config has opened ")
except: except Exception:
pass pass
try: try:
conf = open(cfg, "r") conf = open(cfg, "r")
config_read = conf.read() config_read = conf.read()
conf.close conf.close()
except IOError: except IOError:
error += '<br />Can\'t read import config file' error += '<br />Cannot read import config file'
os.system("/bin/mv %s %s.old" % (cfg, cfg)) os.system("/bin/mv %s %s.old" % (cfg, cfg))
@ -79,7 +79,7 @@ if serv is not None and form.getvalue('config') is not None:
funct.check_is_server_in_group(serv) funct.check_is_server_in_group(serv)
try: try:
funct.logging(serv, "config.py edited config") funct.logging(serv, "config.py edited config")
except: except Exception:
pass pass
config = form.getvalue('config') config = form.getvalue('config')
@ -104,20 +104,20 @@ if serv is not None and form.getvalue('config') is not None:
os.system("/bin/rm -f " + configs_dir + "*.old") os.system("/bin/rm -f " + configs_dir + "*.old")
template = template.render(h2 = 1, title = title, template = template.render(h2=1, title=title,
role = role, role=role,
action = action, action=action,
user = user, user=user,
select_id = "serv", select_id="serv",
serv = serv, serv=serv,
aftersave = aftersave, aftersave=aftersave,
config = config_read, config=config_read,
cfg = cfg, cfg=cfg,
selects = servers, selects=servers,
stderr = stderr, stderr=stderr,
error = error, error=error,
note = 1, note=1,
versions = funct.versions(), versions=funct.versions(),
service = service, service=service,
token = token) token=token)
print(template) print(template)

View File

@ -297,12 +297,12 @@ def update_db_v_3_8_1(**kwargs):
try: try:
cur.execute(i) cur.execute(i)
con.commit() con.commit()
except sqltool.Error as e: except sqltool.Error:
pass pass
else: else:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
print('Updating... go to version 3.12.0.0') print('Updating... go to version 3.12.0.0')
return True
cur.close() cur.close()
con.close() con.close()
@ -359,10 +359,9 @@ def update_db_v_3_13(**kwargs):
print('Updating... go to version 4.0.0') print('Updating... go to version 4.0.0')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else: else:
print("Updating... go to version 4.0.0") print("Updating... go to version 4.0.0")
return True
cur.close() cur.close()
con.close() con.close()
@ -388,7 +387,7 @@ def update_db_v_4(**kwargs):
else: else:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
print('Updating... one more for version 4.0.0') print('Updating... one more for version 4.0.0')
return True
cur.close() cur.close()
con.close() con.close()
@ -407,10 +406,9 @@ def update_db_v_41(**kwargs):
print('Updating... one more for version 4.0.0') print('Updating... one more for version 4.0.0')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else: else:
print("Updating... one more for version 4.0.0") print("Updating... one more for version 4.0.0")
return True
cur.close() cur.close()
con.close() con.close()
@ -429,10 +427,9 @@ def update_db_v_42(**kwargs):
print('Updating... go to version 4.2.3') print('Updating... go to version 4.2.3')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else: else:
print("Updating... go to version 4.2.3") print("Updating... go to version 4.2.3")
return True
cur.close() cur.close()
con.close() con.close()
@ -451,9 +448,7 @@ def update_db_v_4_2_3(**kwargs):
print('Updating... go to version 4.3.0') print('Updating... go to version 4.3.0')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -472,9 +467,7 @@ def update_db_v_4_3(**kwargs):
print('Updating... go to version 4.3.0') print('Updating... go to version 4.3.0')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -498,9 +491,7 @@ def update_db_v_4_3_0(**kwargs):
print('Updating... go to version 4.3.1') print('Updating... go to version 4.3.1')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -519,10 +510,9 @@ def update_db_v_4_3_1(**kwargs):
print('Updating... go to version 4.3.2') print('Updating... go to version 4.3.2')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else: else:
print("DB was update to 4.3.1") print("DB was update to 4.3.1")
return True
cur.close() cur.close()
con.close() con.close()
@ -541,10 +531,9 @@ def update_db_v_4_3_2(**kwargs):
print('Updating... go to version 4.4.0') print('Updating... go to version 4.4.0')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else: else:
print("Updating... go to version 4.4.0") print("Updating... go to version 4.4.0")
return True
cur.close() cur.close()
con.close() con.close()
@ -581,9 +570,7 @@ def update_db_v_4_4(**kwargs):
print('Updating... go to version 4.4.1') print('Updating... go to version 4.4.1')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -607,9 +594,7 @@ def update_db_v_4_4_2(**kwargs):
print('Updating... go to version 4.4.1') print('Updating... go to version 4.4.1')
else: else:
print("Updating... go to version to 4.4.1") print("Updating... go to version to 4.4.1")
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -628,14 +613,11 @@ def update_db_v_4_4_2_1(**kwargs):
print('Updating... go to version 4.4.2') print('Updating... go to version 4.4.2')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
cur.close()
con.close()
return False
else: else:
print("DB was update to 4.4.2") print("DB was update to 4.4.2")
cur.close() cur.close()
con.close() con.close()
return True
def update_db_v_4_3_2_1(**kwargs): def update_db_v_4_3_2_1(**kwargs):
@ -688,9 +670,7 @@ def update_db_v_4_5(**kwargs):
print('Updating... go to version 4.5.0') print('Updating... go to version 4.5.0')
else: else:
print("Updating... go to version to 4.5.0") print("Updating... go to version to 4.5.0")
return False
else:
return True
cur.close() cur.close()
con.close() con.close()
@ -723,14 +703,13 @@ def update_db_v_4_5_1(**kwargs):
else: else:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
print('DB was update to 4.5.0') print('DB was update to 4.5.0')
return True
cur.close() cur.close()
con.close() con.close()
def update_ver(**kwargs): def update_ver(**kwargs):
con, cur = get_cur() con, cur = get_cur()
sql = """update version set version = '4.5.2.0'; """ sql = """update version set version = '4.5.3.0'; """
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()

View File

@ -19,12 +19,12 @@ def get_config_var(sec, var):
path_config = "haproxy-wi.cfg" path_config = "haproxy-wi.cfg"
config = ConfigParser(interpolation=ExtendedInterpolation()) config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config) config.read(path_config)
except: except Exception:
print('Content-type: text/html\n') print('Content-type: text/html\n')
print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be: app/haproxy-webintarface.config</div>') print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be: app/haproxy-wi.cfg</div>')
try: try:
return config.get(sec, var) return config.get(sec, var)
except: except Exception:
print('Content-type: text/html\n') print('Content-type: text/html\n')
print('<center><div class="alert alert-danger">Check the config file. Presence section %s and parameter %s</div>' % (sec, var)) print('<center><div class="alert alert-danger">Check the config file. Presence section %s and parameter %s</div>' % (sec, var))
@ -35,7 +35,7 @@ def get_data(type):
import sql import sql
try: try:
now_utc = datetime.now(timezone(sql.get_setting('time_zone'))) now_utc = datetime.now(timezone(sql.get_setting('time_zone')))
except: except Exception:
now_utc = datetime.now(timezone('UTC')) now_utc = datetime.now(timezone('UTC'))
if type == 'config': if type == 'config':
fmt = "%Y-%m-%d.%H:%M:%S" fmt = "%Y-%m-%d.%H:%M:%S"
@ -50,6 +50,7 @@ def get_data(type):
def get_user_group(**kwargs): def get_user_group(**kwargs):
import sql import sql
import http.cookies import http.cookies
try: try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_group_id = cookie.get('group') user_group_id = cookie.get('group')
@ -61,7 +62,7 @@ def get_user_group(**kwargs):
user_group = g[0] user_group = g[0]
else: else:
user_group = g[1] user_group = g[1]
except: except Exception:
user_group = '' user_group = ''
return user_group return user_group
@ -79,13 +80,13 @@ def logging(serv, action, **kwargs):
try: try:
ip = cgi.escape(os.environ["REMOTE_ADDR"]) ip = cgi.escape(os.environ["REMOTE_ADDR"])
except: except Exception:
ip = '' ip = ''
try: try:
user_uuid = cookie.get('uuid') user_uuid = cookie.get('uuid')
login = sql.get_user_name_by_uuid(user_uuid.value) login = sql.get_user_name_by_uuid(user_uuid.value)
except: except Exception:
login = '' login = ''
if kwargs.get('alerting') == 1: if kwargs.get('alerting') == 1:
@ -132,7 +133,7 @@ def telegram_send_mess(mess, **kwargs):
channel_name = telegram[2] channel_name = telegram[2]
if token_bot == '' or channel_name == '': if token_bot == '' or channel_name == '':
mess = " Fatal: Can't send message. Add Telegram chanel before use alerting at this servers group" mess = " Fatal: Can't send message. Add Telegram channel before use alerting at this servers group"
print(mess) print(mess)
logging('localhost', mess, haproxywi=1) logging('localhost', mess, haproxywi=1)
sys.exit() sys.exit()
@ -144,7 +145,7 @@ def telegram_send_mess(mess, **kwargs):
bot.send_message(chat_id=channel_name, text=mess) bot.send_message(chat_id=channel_name, text=mess)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
logging('localhost', str(e).decode(encoding='UTF-8'), haproxywi=1) logging('localhost', str(e), haproxywi=1)
sys.exit() sys.exit()
@ -233,6 +234,7 @@ def ssh_connect(serv, **kwargs):
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv) ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv)
servers = sql.select_servers(server=serv) servers = sql.select_servers(server=serv)
ssh_port = 22
for server in servers: for server in servers:
ssh_port = server[10] ssh_port = server[10]
@ -316,7 +318,7 @@ def diff_config(oldcfg, cfg):
try: try:
user_uuid = cookie.get('uuid') user_uuid = cookie.get('uuid')
login = sql.get_user_name_by_uuid(user_uuid.value) login = sql.get_user_name_by_uuid(user_uuid.value)
except: except Exception:
login = '' login = ''
output, stderr = subprocess_execute(cmd) output, stderr = subprocess_execute(cmd)
@ -429,19 +431,19 @@ def rewrite_section(start_line, end_line, config, section):
def get_backends_from_config(serv, backends='', **kwargs): def get_backends_from_config(serv, backends='', **kwargs):
configs_dir = get_config_var('configs', 'haproxy_save_configs_dir') configs_dir = get_config_var('configs', 'haproxy_save_configs_dir')
format = 'cfg' format_cfg = 'cfg'
try: try:
cfg = configs_dir+get_files(dir=configs_dir, format=format)[0] cfg = configs_dir+get_files(dir=configs_dir, format=format_cfg)[0]
except Exception as e: except Exception as e:
logging('localhost', str(e), haproxywi=1) logging('localhost', str(e), haproxywi=1)
try: try:
cfg = configs_dir + serv + "-" + get_data('config') + '.'+format cfg = configs_dir + serv + "-" + get_data('config') + '.'+format_cfg
except: except Exception:
logging('localhost', ' Cannot generate cfg path', haproxywi=1) logging('localhost', ' Cannot generate cfg path', haproxywi=1)
try: try:
error = get_config(serv, cfg) error = get_config(serv, cfg)
except: except Exception:
logging('localhost', ' Cannot download config', haproxywi=1) logging('localhost', ' Cannot download config', haproxywi=1)
print('error: Cannot get backends') print('error: Cannot get backends')
sys.exit() sys.exit()
@ -488,6 +490,7 @@ def install_haproxy(serv, **kwargs):
stats_password = sql.get_setting('stats_password') stats_password = sql.get_setting('stats_password')
proxy = sql.get_setting('proxy') proxy = sql.get_setting('proxy')
hapver = kwargs.get('hapver') hapver = kwargs.get('hapver')
ssh_port = 22
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv) ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv)
if ssh_enable == 0: if ssh_enable == 0:

View File

@ -37,7 +37,7 @@ if form.getvalue('getcerts') is not None and serv is not None:
try: try:
funct.ssh_command(serv, commands, ip="1") funct.ssh_command(serv, commands, ip="1")
except Exception as e: except Exception as e:
print('error: Cannot connect to the server: ' + str(e)) print('error: Cannot connect to the server: ' + e.args[0])
if form.getvalue('checkSshConnect') is not None and serv is not None: if form.getvalue('checkSshConnect') is not None and serv is not None:
print(funct.ssh_command(serv, ["ls -1t"])) print(funct.ssh_command(serv, ["ls -1t"]))
@ -48,8 +48,8 @@ if form.getvalue('getcert') is not None and serv is not None:
commands = ["cat " + cert_path + "/" + id] commands = ["cat " + cert_path + "/" + id]
try: try:
funct.ssh_command(serv, commands, ip="1") funct.ssh_command(serv, commands, ip="1")
except: except Exception as e:
print('error: Can not connect to the server') print('error: Can not connect to the server ' + e.args[0])
if serv and form.getvalue('ssl_cert'): if serv and form.getvalue('ssl_cert'):
cert_local_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('ssl_local_path') cert_local_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('ssl_local_path')
@ -107,8 +107,7 @@ if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is
haproxy_sock_port = sql.get_setting('haproxy_sock_port') haproxy_sock_port = sql.get_setting('haproxy_sock_port')
backend = form.getvalue('ipbackend') backend = form.getvalue('ipbackend')
backend_server = form.getvalue('backend_server') backend_server = form.getvalue('backend_server')
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |grep "%s" |awk \'{print $5":"$19}\' |head -1' % ( cmd = 'echo "show servers state"|nc %s %s |grep "%s" |grep "%s" |awk \'{print $5":"$19}\' |head -1' % (serv, haproxy_sock_port, backend, backend_server)
serv, haproxy_sock_port, backend, backend_server)
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
print(output[0]) print(output[0])
@ -130,13 +129,11 @@ if form.getvalue('backend_ip') is not None:
MASTERS = sql.is_master(serv) MASTERS = sql.is_master(serv)
for master in MASTERS: for master in MASTERS:
if master[0] is not None: if master[0] is not None:
cmd = 'echo "set server %s/%s addr %s port %s check-port %s" |nc %s %s' % ( cmd = 'echo "set server %s/%s addr %s port %s check-port %s" |nc %s %s' % (backend_backend, backend_server, backend_ip, backend_port, backend_port, master[0], haproxy_sock_port)
backend_backend, backend_server, backend_ip, backend_port, backend_port, master[0], haproxy_sock_port)
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
print(output[0]) print(output[0])
cmd = 'echo "set server %s/%s addr %s port %s check-port %s" |nc %s %s' % ( cmd = 'echo "set server %s/%s addr %s port %s check-port %s" |nc %s %s' % (backend_backend, backend_server, backend_ip, backend_port, backend_port, serv, haproxy_sock_port)
backend_backend, backend_server, backend_ip, backend_port, backend_port, serv, haproxy_sock_port)
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
if stderr != '': if stderr != '':
@ -147,8 +144,7 @@ if form.getvalue('backend_ip') is not None:
cfg = configs_dir + serv + "-" + funct.get_data('config') + ".cfg" cfg = configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
error = funct.get_config(serv, cfg) error = funct.get_config(serv, cfg)
cmd = 'string=`grep %s %s -n -A25 |grep "server %s" |head -1|awk -F"-" \'{print $1}\'` && sed -Ei "$( echo $string)s/((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5]):[0-9]+/%s:%s/g" %s' % ( cmd = 'string=`grep %s %s -n -A25 |grep "server %s" |head -1|awk -F"-" \'{print $1}\'` && sed -Ei "$( echo $string)s/((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5]):[0-9]+/%s:%s/g" %s' % (backend_backend, cfg, backend_server, backend_ip, backend_port, cfg)
backend_backend, cfg, backend_server, backend_ip, backend_port, cfg)
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save='save') stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save='save')
@ -187,8 +183,7 @@ if form.getvalue('maxconn_frontend') is not None:
cfg = configs_dir + serv + "-" + funct.get_data('config') + ".cfg" cfg = configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
error = funct.get_config(serv, cfg) error = funct.get_config(serv, cfg)
cmd = 'string=`grep %s %s -n -A5 |grep maxcon -n |awk -F":" \'{print $2}\'|awk -F"-" \'{print $1}\'` && sed -Ei "$( echo $string)s/[0-9]+/%s/g" %s' % ( cmd = 'string=`grep %s %s -n -A5 |grep maxcon -n |awk -F":" \'{print $2}\'|awk -F"-" \'{print $1}\'` && sed -Ei "$( echo $string)s/[0-9]+/%s/g" %s' % (frontend, cfg, maxconn, cfg)
frontend, cfg, maxconn, cfg)
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save='save') stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save='save')
print('success: Maxconn for %s has been set to %s ' % (frontend, maxconn)) print('success: Maxconn for %s has been set to %s ' % (frontend, maxconn))
@ -419,7 +414,7 @@ if form.getvalue('action_service') is not None:
elif action == "restart": elif action == "restart":
cmd = "sudo systemctl restart %s --now" % serv cmd = "sudo systemctl restart %s --now" % serv
output, stderr = funct.subprocess_execute(cmd) output, stderr = funct.subprocess_execute(cmd)
funct.logging('localhost', ' The service ' + serv + 'was ' + action + 'ed', haproxywi=1, login=1) funct.logging('localhost', ' The service ' + serv + ' was ' + action + 'ed', haproxywi=1, login=1)
if act == "overviewHapserverBackends": if act == "overviewHapserverBackends":
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
@ -429,29 +424,29 @@ if act == "overviewHapserverBackends":
service = form.getvalue('service') service = form.getvalue('service')
if service == 'haproxy': if service == 'haproxy':
configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
format = 'cfg' format_file = 'cfg'
elif service == 'nginx': elif service == 'nginx':
configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir') configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir')
format = 'conf' format_file = 'conf'
try: try:
sections = funct.get_sections(configs_dir + funct.get_files(dir=configs_dir, format=format)[0], service=service) sections = funct.get_sections(configs_dir + funct.get_files(dir=configs_dir, format=format_file)[0], service=service)
except Exception as e: except Exception as e:
funct.logging('localhost', str(e), haproxywi=1) funct.logging('localhost', str(e), haproxywi=1)
try: try:
cfg = configs_dir + serv + "-" + funct.get_data('config') + '.' + format cfg = configs_dir + serv + "-" + funct.get_data('config') + '.' + format_file
except: except Exception as e:
funct.logging('localhost', ' Cannot generate cfg path', haproxywi=1) funct.logging('localhost', ' Cannot generate cfg path ' + str(e), haproxywi=1)
try: try:
if service == 'nginx': if service == 'nginx':
error = funct.get_config(serv, cfg, nginx=1) error = funct.get_config(serv, cfg, nginx=1)
else: else:
error = funct.get_config(serv, cfg) error = funct.get_config(serv, cfg)
except: except Exception as e:
funct.logging('localhost', ' Cannot download config', haproxywi=1) funct.logging('localhost', ' Cannot download config ' + str(e), haproxywi=1)
try: try:
sections = funct.get_sections(cfg, service=service) sections = funct.get_sections(cfg, service=service)
except: except Exception as e:
funct.logging('localhost', ' Cannot get sections from config file', haproxywi=1) funct.logging('localhost', ' Cannot get sections from config file ' + str(e), haproxywi=1)
sections = 'Cannot get backends' sections = 'Cannot get backends'
template = template.render(backends=sections, serv=serv, service=service) template = template.render(backends=sections, serv=serv, service=service)
@ -465,15 +460,15 @@ if act == "overviewHapservers":
commands = ["ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % config_path] commands = ["ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % config_path]
try: try:
print(funct.ssh_command(serv, commands)) print(funct.ssh_command(serv, commands))
except: except Exception as e:
print('error: Cannot get last date') print('error: Cannot get last date ' + str(e))
if act == "overview": if act == "overview":
import asyncio import asyncio
import http.cookies
from jinja2 import Environment, FileSystemLoader
async def async_get_overview(serv1, serv2): async def async_get_overview(serv1, serv2):
server_status = ()
commands2 = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"] commands2 = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"]
cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Process_num"' % (serv2, sql.get_setting('haproxy_sock_port')) cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Process_num"' % (serv2, sql.get_setting('haproxy_sock_port'))
keepalived = sql.select_keealived(serv2) keepalived = sql.select_keealived(serv2)
@ -502,8 +497,6 @@ if act == "overview":
async def get_runner_overview(): async def get_runner_overview():
import http.cookies
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True, env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True,
extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do'])
@ -526,24 +519,22 @@ if act == "overview":
if act == "overviewwaf": if act == "overviewwaf":
import asyncio import asyncio
import http.cookies
from jinja2 import Environment, FileSystemLoader
async def async_get_overviewWaf(serv1, serv2): async def async_get_overviewWaf(serv1, serv2):
haproxy_dir = sql.get_setting('haproxy_dir') haproxy_path = sql.get_setting('haproxy_dir')
server_status = () commands0 = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"]
commands = ["ps ax |grep waf/bin/modsecurity |grep -v grep |wc -l"] commands1 = ["cat %s/waf/modsecurity.conf |grep SecRuleEngine |grep -v '#' |awk '{print $2}'" % haproxy_path]
commands1 = ["cat %s/waf/modsecurity.conf |grep SecRuleEngine |grep -v '#' |awk '{print $2}'" % haproxy_dir]
server_status = (serv1, serv2, server_status = (serv1, serv2,
funct.ssh_command(serv2, commands), funct.ssh_command(serv2, commands0),
funct.ssh_command(serv2, commands1).strip(), funct.ssh_command(serv2, commands1).strip(),
sql.select_waf_metrics_enable_server(serv2)) sql.select_waf_metrics_enable_server(serv2))
return server_status return server_status
async def get_runner_overviewWaf(): async def get_runner_overviewWaf():
import http.cookies
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True, env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True,
extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do'])
template = env.get_template('overivewWaf.html') template = env.get_template('overivewWaf.html')
@ -569,8 +560,6 @@ if act == "overviewServers":
async def async_get_overviewServers(serv1, serv2, service): async def async_get_overviewServers(serv1, serv2, service):
server_status = ()
if service == 'haproxy': if service == 'haproxy':
cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % ( cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % (
serv2, sql.get_setting('haproxy_sock_port')) serv2, sql.get_setting('haproxy_sock_port'))
@ -780,7 +769,7 @@ if serv is not None and act == "showMap":
node = node.strip(' \t\n\r') node = node.strip(' \t\n\r')
node = node + ":" + bind[0] node = node + ":" + bind[0]
G.add_node(node, pos=(k, i), label_pos=(k, i + 100)) G.add_node(node, pos=(k, i), label_pos=(k, i + 100))
except: except Exception:
pass 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 "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line and "#" not in line:
@ -851,8 +840,7 @@ if form.getvalue('servaction') is not None:
if enable != "show": if enable != "show":
print( print(
'<center><h3>You %s %s on HAproxy %s. <a href="viewsttats.py?serv=%s" title="View stat" target="_blank">Look it</a> or <a href="runtimeapi.py" title="RutimeAPI">Edit something else</a></h3><br />' % ( '<center><h3>You %s %s on HAproxy %s. <a href="viewsttats.py?serv=%s" title="View stat" target="_blank">Look it</a> or <a href="runtimeapi.py" title="Runtime API">Edit something else</a></h3><br />' % (enable, backend, serv, serv))
enable, backend, serv, serv))
print(funct.ssh_command(serv, command, show_log="1")) print(funct.ssh_command(serv, command, show_log="1"))
action = 'runtimeapi.py ' + enable + ' ' + backend action = 'runtimeapi.py ' + enable + ' ' + backend
@ -968,8 +956,7 @@ if form.getvalue('master'):
funct.install_nginx(slave) funct.install_nginx(slave)
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port + commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
" ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " SYN_FLOOD=" + syn_flood + " HOST=" + str( " ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " SYN_FLOOD=" + syn_flood + " HOST=" + str(master) +
master) +
" USER=" + str(ssh_user_name) + " PASS=" + str(ssh_user_password) + " KEY=" + str(ssh_key_name)] " USER=" + str(ssh_user_name) + " PASS=" + str(ssh_user_password) + " KEY=" + str(ssh_key_name)]
output, error = funct.subprocess_execute(commands[0]) output, error = funct.subprocess_execute(commands[0])
@ -985,7 +972,7 @@ if form.getvalue('master'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -1017,7 +1004,7 @@ if form.getvalue('master'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -1402,13 +1389,15 @@ if form.getvalue('metrics_hapwi_cpu'):
if form.getvalue('new_metrics'): if form.getvalue('new_metrics'):
serv = form.getvalue('server') serv = form.getvalue('server')
metric = sql.select_metrics(serv) time_range = form.getvalue('time_range')
metric = sql.select_metrics(serv, time_range=time_range)
metrics = {'chartData': {}} metrics = {'chartData': {}}
metrics['chartData']['labels'] = {} metrics['chartData']['labels'] = {}
labels = '' labels = ''
curr_con = '' curr_con = ''
curr_ssl_con = '' curr_ssl_con = ''
sess_rate = '' sess_rate = ''
server = ''
for i in metric: for i in metric:
label = str(i[5]) label = str(i[5])
@ -1431,7 +1420,8 @@ if form.getvalue('new_metrics'):
if form.getvalue('new_waf_metrics'): if form.getvalue('new_waf_metrics'):
serv = form.getvalue('server') serv = form.getvalue('server')
metric = sql.select_waf_metrics(serv) time_range = form.getvalue('time_range')
metric = sql.select_waf_metrics(serv, time_range=time_range)
metrics = {'chartData': {}} metrics = {'chartData': {}}
metrics['chartData']['labels'] = {} metrics['chartData']['labels'] = {}
labels = '' labels = ''
@ -1463,12 +1453,11 @@ if form.getvalue('get_exporter_v'):
print(funct.check_service(serv, form.getvalue('get_exporter_v'))) print(funct.check_service(serv, form.getvalue('get_exporter_v')))
if form.getvalue('bwlists'): if form.getvalue('bwlists'):
list = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue( list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color') + "/" + form.getvalue('bwlists')
'group') + "/" + form.getvalue('color') + "/" + form.getvalue('bwlists')
try: try:
file = open(list, "r") file = open(list_path, "r")
file_read = file.read() file_read = file.read()
file.close file.close()
print(file_read) print(file_read)
except IOError: except IOError:
print('error: Cat\'n read ' + form.getvalue('color') + ' list , ') print('error: Cat\'n read ' + form.getvalue('color') + ' list , ')
@ -1477,28 +1466,26 @@ if form.getvalue('bwlists_create'):
color = form.getvalue('color') color = form.getvalue('color')
list_name = form.getvalue('bwlists_create').split('.')[0] list_name = form.getvalue('bwlists_create').split('.')[0]
list_name += '.lst' list_name += '.lst'
list = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue( list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + list_name
'group') + "/" + color + "/" + list_name
try: try:
open(list, 'a').close() open(list_path, 'a').close()
print(color) print('success: ')
try: try:
funct.logging(server[1], 'has created ' + color + ' list ' + list_name, haproxywi=1, login=1) funct.logging(serv, 'has created ' + color + ' list ' + list_name, haproxywi=1, login=1)
except: except Exception:
pass pass
except IOError as e: except IOError as e:
print('error: Cat\'n create new ' + color + ' list. %s , ' % e) print('error: Cannot create new ' + color + ' list. %s , ' % e)
if form.getvalue('bwlists_save'): if form.getvalue('bwlists_save'):
color = form.getvalue('color') color = form.getvalue('color')
bwlists_save = form.getvalue('bwlists_save') bwlists_save = form.getvalue('bwlists_save')
list = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue( list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_save
'group') + "/" + color + "/" + bwlists_save
try: try:
with open(list, "w") as file: with open(list_path, "w") as file:
file.write(form.getvalue('bwlists_content')) file.write(form.getvalue('bwlists_content'))
except IOError as e: except IOError as e:
print('error: Cat\'n save ' + color + ' list. %s , ' % e) print('error: Cannot save ' + color + ' list. %s , ' % e)
path = sql.get_setting('haproxy_dir') + "/" + color path = sql.get_setting('haproxy_dir') + "/" + color
servers = [] servers = []
@ -1518,14 +1505,15 @@ if form.getvalue('bwlists_save'):
for serv in servers: for serv in servers:
funct.ssh_command(serv, ["sudo mkdir " + path]) funct.ssh_command(serv, ["sudo mkdir " + path])
funct.ssh_command(serv, ["sudo chown $(whoami) " + path]) funct.ssh_command(serv, ["sudo chown $(whoami) " + path])
error = funct.upload(serv, path + "/" + bwlists_save, list, dir='fullpath') error = funct.upload(serv, path + "/" + bwlists_save, list_path, dir='fullpath')
if error: if error:
print('error: Upload fail: %s , ' % error) print('error: Upload fail: %s , ' % error)
else: else:
print('success: Edited ' + color + ' list was uploaded to ' + serv + ' , ') print('success: Edited ' + color + ' list was uploaded to ' + serv + ' , ')
try: try:
funct.logging(serv, 'has edited ' + color + ' list ' + bwlists_save, haproxywi=1, login=1) funct.logging(serv, 'has edited ' + color + ' list ' + bwlists_save, haproxywi=1, login=1)
except: except Exception:
pass pass
haproxy_enterprise = sql.get_setting('haproxy_enterprise') haproxy_enterprise = sql.get_setting('haproxy_enterprise')
@ -1540,11 +1528,10 @@ if form.getvalue('bwlists_save'):
funct.ssh_command(serv, ["sudo systemctl reload " + haproxy_service_name]) funct.ssh_command(serv, ["sudo systemctl reload " + haproxy_service_name])
if form.getvalue('get_lists'): if form.getvalue('get_lists'):
list = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue( list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color')
'group') + "/" + form.getvalue('color') lists = funct.get_files(dir=list_path, format="lst")
lists = funct.get_files(dir=list, format="lst") for l in lists:
for list in lists: print(l)
print(list)
if form.getvalue('get_ldap_email'): if form.getvalue('get_ldap_email'):
username = form.getvalue('get_ldap_email') username = form.getvalue('get_ldap_email')
@ -1574,7 +1561,7 @@ if form.getvalue('get_ldap_email'):
results = [entry for dn, entry in result if isinstance(entry, dict)] results = [entry for dn, entry in result if isinstance(entry, dict)]
try: try:
print('["' + results[0][ldap_search_field][0].decode("utf-8") + '","' + domain + '"]') print('["' + results[0][ldap_search_field][0].decode("utf-8") + '","' + domain + '"]')
except: except Exception:
print('error: user not found') print('error: user not found')
finally: finally:
l.unbind() l.unbind()
@ -1621,6 +1608,7 @@ if form.getvalue('newuser') is not None:
if form.getvalue('userdel') is not None: if form.getvalue('userdel') is not None:
userdel = form.getvalue('userdel') userdel = form.getvalue('userdel')
user = sql.select_users(id=userdel) user = sql.select_users(id=userdel)
username = ''
for u in user: for u in user:
username = u[1] username = u[1]
if sql.delete_user(userdel): if sql.delete_user(userdel):
@ -1646,11 +1634,11 @@ if form.getvalue('updateuser') is not None:
if form.getvalue('updatepassowrd') is not None: if form.getvalue('updatepassowrd') is not None:
password = form.getvalue('updatepassowrd') password = form.getvalue('updatepassowrd')
id = form.getvalue('id') user_id = form.getvalue('id')
user = sql.select_users(id=id) user = sql.select_users(id=user_id)
for u in user: for u in user:
username = u[1] username = u[1]
sql.update_user_password(password, id) sql.update_user_password(password, user_id)
funct.logging('user ' + username, ' has changed password ', haproxywi=1, login=1) funct.logging('user ' + username, ' has changed password ', haproxywi=1, login=1)
print("Ok") print("Ok")
@ -1802,7 +1790,7 @@ if form.getvalue('sshdel') is not None:
cmd = 'rm -f %s' % ssh_key_name cmd = 'rm -f %s' % ssh_key_name
try: try:
funct.subprocess_execute(cmd) funct.subprocess_execute(cmd)
except: except Exception:
pass pass
if sql.delete_ssh(sshdel): if sql.delete_ssh(sshdel):
print("Ok") print("Ok")
@ -1927,27 +1915,27 @@ if form.getvalue('updatesettings') is not None:
print("Ok") print("Ok")
if form.getvalue('getusergroups'): if form.getvalue('getusergroups'):
id = form.getvalue('getusergroups') group_id = form.getvalue('getusergroups')
groups = [] groups = []
u_g = sql.select_user_groups(id=id) u_g = sql.select_user_groups(id=group_id)
for g in u_g: for g in u_g:
groups.append(g[0]) groups.append(g[0])
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_groups.html') template = env.get_template('/show_user_groups.html')
template = template.render(groups=sql.select_groups(), user_groups=groups, id=id) template = template.render(groups=sql.select_groups(), user_groups=groups, id=group_id)
print(template) print(template)
if form.getvalue('changeUserGroupId') is not None: if form.getvalue('changeUserGroupId') is not None:
id = form.getvalue('changeUserGroupId') group_id = form.getvalue('changeUserGroupId')
groups = form.getvalue('changeUserGroups') groups = form.getvalue('changeUserGroups')
user = form.getvalue('changeUserGroupsUser') user = form.getvalue('changeUserGroupsUser')
if sql.delete_user_groups(id): if sql.delete_user_groups(group_id):
for group in groups: for group in groups:
if group[0] == ',': if group[0] == ',':
continue continue
sql.update_user_groups(groups=group[0], id=id) sql.update_user_groups(groups=group[0], id=group_id)
funct.logging('localhost', ' has upgraded groups for user: ' + user, haproxywi=1, login=1) funct.logging('localhost', ' has upgraded groups for user: ' + user, haproxywi=1, login=1)
@ -1957,14 +1945,14 @@ if form.getvalue('getcurrentusergroup') is not None:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid') user_id = cookie.get('uuid')
group = cookie.get('group') group = cookie.get('group')
id = sql.get_user_id_by_uuid(user_id.value) group_id = sql.get_user_id_by_uuid(user_id.value)
groups = sql.select_user_groups_with_names(id=id) groups = sql.select_user_groups_with_names(id=group_id)
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_current_group.html') template = env.get_template('/show_user_current_group.html')
template = template.render(groups=groups, group=group.value, id=id) template = template.render(groups=groups, group=group.value, id=group_id)
print(template) print(template)
if form.getvalue('newsmon') is not None: if form.getvalue('newsmon') is not None:
@ -1981,7 +1969,7 @@ if form.getvalue('newsmon') is not None:
try: try:
port = int(port) port = int(port)
except: except Exception:
print('SMON error: port must number') print('SMON error: port must number')
sys.exit() sys.exit()
if port > 65535 or port < 0: if port > 65535 or port < 0:
@ -2007,10 +1995,10 @@ if form.getvalue('newsmon') is not None:
if form.getvalue('smondel') is not None: if form.getvalue('smondel') is not None:
user_group = funct.get_user_group(id=1) user_group = funct.get_user_group(id=1)
id = form.getvalue('smondel') smon_id = form.getvalue('smondel')
if funct.check_user_group(): if funct.check_user_group():
if sql.delete_smon(id, user_group): if sql.delete_smon(smon_id, user_group):
print('Ok') print('Ok')
funct.logging('SMON', ' Has been delete server from SMON ', haproxywi=1, login=1) funct.logging('SMON', ' Has been delete server from SMON ', haproxywi=1, login=1)
@ -2026,7 +2014,7 @@ if form.getvalue('showsmon') is not None:
print(template) print(template)
if form.getvalue('updateSmonIp') is not None: if form.getvalue('updateSmonIp') is not None:
id = form.getvalue('id') smon_id = form.getvalue('id')
ip = form.getvalue('updateSmonIp') ip = form.getvalue('updateSmonIp')
port = form.getvalue('updateSmonPort') port = form.getvalue('updateSmonPort')
en = form.getvalue('updateSmonEn') en = form.getvalue('updateSmonEn')
@ -2038,7 +2026,7 @@ if form.getvalue('updateSmonIp') is not None:
try: try:
port = int(port) port = int(port)
except: except Exception:
print('SMON error: port must number') print('SMON error: port must number')
sys.exit() sys.exit()
if port > 65535 or port < 0: if port > 65535 or port < 0:
@ -2051,7 +2039,7 @@ if form.getvalue('updateSmonIp') is not None:
print('SMON error: Cannot be HTTP with 443 port') print('SMON error: Cannot be HTTP with 443 port')
sys.exit() sys.exit()
if sql.update_smon(id, ip, port, body, telegram, group, desc, en): if sql.update_smon(smon_id, ip, port, body, telegram, group, desc, en):
print("Ok") print("Ok")
funct.logging('SMON', ' Has been update the server ' + ip + ' to SMON ', haproxywi=1, login=1) funct.logging('SMON', ' Has been update the server ' + ip + ' to SMON ', haproxywi=1, login=1)
@ -2086,7 +2074,7 @@ if form.getvalue('alert_consumer'):
message = sql.select_alerts(user_group) message = sql.select_alerts(user_group)
for m in message: for m in message:
print(m[0] + ': ' + m[1] + ' date: ' + m[2] + ';') print(m[0] + ': ' + m[1] + ' date: ' + m[2] + ';')
except: except Exception:
pass pass
if form.getvalue('waf_rule_id'): if form.getvalue('waf_rule_id'):
@ -2107,7 +2095,7 @@ if form.getvalue('waf_rule_id'):
try: try:
funct.logging('WAF', ' Has been ' + en_for_log + ' WAF rule: ' + rule_file + ' for the server ' + serv, funct.logging('WAF', ' Has been ' + en_for_log + ' WAF rule: ' + rule_file + ' for the server ' + serv,
haproxywi=1, login=1) haproxywi=1, login=1)
except: except Exception:
pass pass
print(funct.ssh_command(serv, cmd)) print(funct.ssh_command(serv, cmd))
@ -2153,7 +2141,7 @@ if form.getvalue('lets_domain'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -2218,3 +2206,26 @@ if form.getvalue('actionvpn') is not None:
except IOError as e: except IOError as e:
print(e.args[0]) print(e.args[0])
funct.logging('localhost', e.args[0], haproxywi=1) funct.logging('localhost', e.args[0], haproxywi=1)
if form.getvalue('scan_ports') is not None:
serv_id = form.getvalue('scan_ports')
server = sql.select_servers(id=serv_id)
for s in server:
ip = s[2]
cmd = "sudo nmap -sS %s |grep -E '^[[:digit:]]'|sed 's/ */ /g'" % ip
cmd1 = "sudo nmap -sS %s |head -5|tail -3" % ip
stdout, stderr = funct.subprocess_execute(cmd)
stdout1, stderr1 = funct.subprocess_execute(cmd1)
if stderr != '':
print(stderr)
else:
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'), autoescape=True)
template = env.get_template('ajax/scan_ports.html')
template = template.render(ports=stdout, info=stdout1)
print(template)

View File

@ -24,6 +24,10 @@ done
export ANSIBLE_HOST_KEY_CHECKING=False export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
export ACTION_WARNINGS=False
export LOCALHOST_WARNING=False
export COMMAND_WARNINGS=False
PWD=`pwd` PWD=`pwd`
PWD=$PWD/scripts/ansible/ PWD=$PWD/scripts/ansible/
echo $HOST > $PWD/$HOST echo $HOST > $PWD/$HOST

View File

@ -23,6 +23,10 @@ done
export ANSIBLE_HOST_KEY_CHECKING=False export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
export ACTION_WARNINGS=False
export LOCALHOST_WARNING=False
export COMMAND_WARNINGS=False
PWD=`pwd` PWD=`pwd`
PWD=$PWD/scripts/ansible/ PWD=$PWD/scripts/ansible/
echo $HOST > $PWD/$HOST echo $HOST > $PWD/$HOST

View File

@ -32,6 +32,9 @@ fi
export ANSIBLE_HOST_KEY_CHECKING=False export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
export ACTION_WARNINGS=False export ACTION_WARNINGS=False
export LOCALHOST_WARNING=False
export COMMAND_WARNINGS=False
PWD=`pwd` PWD=`pwd`
PWD=$PWD/scripts/ansible/ PWD=$PWD/scripts/ansible/
echo $HOST > $PWD/$HOST echo $HOST > $PWD/$HOST
@ -46,5 +49,7 @@ if [ $? -gt 0 ]
then then
echo "error: Can't install Nginx service <br /><br />" echo "error: Can't install Nginx service <br /><br />"
exit 1 exit 1
else
echo "ok"
fi fi
rm -f $PWD/$HOST rm -f $PWD/$HOST

View File

@ -30,7 +30,9 @@ fi
export ANSIBLE_HOST_KEY_CHECKING=False export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
export ACTION_WARNINGS=False export ACTION_WARNINGS=False
export ANSIBLE_DEPRECATION_WARNINGS=False export LOCALHOST_WARNING=False
export COMMAND_WARNINGS=False
PWD=`pwd` PWD=`pwd`
PWD=$PWD/scripts/ansible/ PWD=$PWD/scripts/ansible/
echo $HOST > $PWD/$HOST echo $HOST > $PWD/$HOST

View File

@ -795,11 +795,15 @@
<div id="lists"> <div id="lists">
<table class="overview"> <table class="overview">
<tr class="overviewHead"> <tr class="overviewHead">
<th class="padding10 first-collumn">Server for upload</th> <th class="padding10 first-collumn">New blacklist</th>
<th>New blacklist</th> <th>Server for uploading</th>
<th>Existing blacklists</th> <th>Existing blacklists</th>
</tr> </tr>
<tr> <tr>
<td class="padding10 first-collumn" style="width: 25%;">
Name: {{ input('new_blacklist_name') }}
<button onclick="createList('black')">Create</button>
</td>
<td class="padding10 first-collumn"> <td class="padding10 first-collumn">
<select required name="serv-black-list" id="serv-black-list"> <select required name="serv-black-list" id="serv-black-list">
<option disabled selected>Choose server</option> <option disabled selected>Choose server</option>
@ -809,10 +813,6 @@
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
<td style="width: 25%;">
Name: {{ input('new_blacklist_name') }}
<button onclick="createList('black')">Create</button>
</td>
<td style="width: 30%;"> <td style="width: 30%;">
{% for list in black_lists %} {% for list in black_lists %}
<a onclick="editList('{{ list }}', 'black')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a> <a onclick="editList('{{ list }}', 'black')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a>
@ -824,11 +824,15 @@
</table> </table>
<table> <table>
<tr class="overviewHead"> <tr class="overviewHead">
<th class="padding10 first-collumn">Server for upload</th> <th class="padding10 first-collumn">New whitelist</th>
<th>New whitelist</th> <th>Server for uploading</th>
<th>Existing whitelists</th> <th>Existing whitelists</th>
</tr> </tr>
<tr> <tr>
<td class="padding10 first-collumn" style="width: 25%;">
Name: {{ input('new_whitelist_name') }}
<button onclick="createList('white')">Create</button>
</td>
<td class="padding10 first-collumn"> <td class="padding10 first-collumn">
<select required name="serv-white-list" id="serv-white-list"> <select required name="serv-white-list" id="serv-white-list">
<option disabled selected>Choose server</option> <option disabled selected>Choose server</option>
@ -838,10 +842,6 @@
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
<td style="width: 25%;">
Name: {{ input('new_whitelist_name') }}
<button onclick="createList( 'white')">Create</button>
</td>
<td style="width: 30%;"> <td style="width: 30%;">
{% for list in white_lists %} {% for list in white_lists %}
<a onclick="editList('{{ list }}', 'white')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a> <a onclick="editList('{{ list }}', 'white')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a>

View File

@ -1,7 +1,7 @@
<div class="sort_menu"> <div class="sort_menu">
<a href="#" title="Do not sort by status" onclick="showSmon('not_sort')">Do not sort</a> | <a href="#" title="Do not sort by status" onclick="showSmon('not_sort')">Do not sort</a> |
<a href="#" id="sort_by_status" title="Sort by status" onclick="sort_by_status()">Sort by status</a> | <a href="#" id="sort_by_status" title="Sort by status" onclick="sort_by_status()">Sort by status</a> |
<a href="#" title="Refresh page" onclick="showSmon('refresh');">Refresh</a> <a href="#" title="SMOM Dashboard - HAProxy-WI" onclick="showSmon('refresh');">Refresh</a>
<span style="padding-left: 20px;"> <span style="padding-left: 20px;">
{% set down = [] %} {% set down = [] %}
{% set up = [] %} {% set up = [] %}
@ -35,12 +35,12 @@
{% endif %} {% endif %}
{% if s.3 == 1 %} {% if s.3 == 1 %}
{% if s.2 == 1 and s.10 == 1 and s.12 == 1 %} {% if s.2 == 1 and s.10 == 1 and s.12 == 1 %}
<div class="smon_services good"> <div class="smon_services good div-server-head-up">
{% else %} {% else %}
<div class="smon_services err"> <div class="smon_services err div-server-head-down">
{% endif %} {% endif %}
{% else %} {% else %}
<div class="smon_services dis"> <div class="smon_services dis div-server-head-dis">
{% endif %} {% endif %}
<div class="ip"> <div class="ip">
{% if s.0|string|length > 23 %} {% if s.0|string|length > 23 %}

View File

@ -278,9 +278,10 @@
</div> </div>
<div class="footer-div"> <div class="footer-div">
<a href="https://haproxy-wi.org" class="footer-link" target="_blank" title="About HAProxy-WI">About</a> <a href="https://haproxy-wi.org" class="footer-link" target="_blank" title="About HAProxy-WI">About</a>
<a href="https://github.com/Aidaho12/haproxy-wi/issues" class="footer-link" target="_blank">Help</a> <a href="https://github.com/Aidaho12/haproxy-wi/issues" class="footer-link" target="_blank" title="Community help">Help</a>
<a href="https://sd.haproxy-wi.org" class="footer-link" target="_blank" title="Service Desk">SD</a>
<a href="https://haproxy-wi.org/contacts.py" class="footer-link" target="_blank">Contacts</a> <a href="https://haproxy-wi.org/contacts.py" class="footer-link" target="_blank">Contacts</a>
<a href="https://haproxy-wi.org/cabinet.py" class="footer-link" target="_blank" title="Private cabinet for donaterers">Cabinet</a> <a href="https://haproxy-wi.org/cabinet.py" class="footer-link" target="_blank" title="Private cabinet">Cabinet</a>
</div> </div>
</div> </div>
<div id="current-user-groups-dialog" style="display: none;"> <div id="current-user-groups-dialog" style="display: none;">

View File

@ -8,10 +8,8 @@
{% if selects|length == 0 %} {% if selects|length == 0 %}
{% include 'include/getstarted.html' %} {% include 'include/getstarted.html' %}
{% else %} {% else %}
<h3>Choose server</h3>
<p> <p>
<form action="{{ action }}" method="post"> <form action="{{ action }}" method="post">
<a class="ui-button ui-widget ui-corner-all" title="Return back" id="back" onclick="history.go(-2)">Back</a>
<input type="hidden" id="service" value="{{service|default('haproxy', true)}}" /> <input type="hidden" id="service" value="{{service|default('haproxy', true)}}" />
<select autofocus required name="serv" id="{{ select_id }}"> <select autofocus required name="serv" id="{{ select_id }}">
<option disabled>Choose server</option> <option disabled>Choose server</option>
@ -105,7 +103,7 @@
<style> <style>
.CodeMirror { .CodeMirror {
line-height: 1.2em; line-height: 1.2em;
height: 50%; height: 60%;
} }
</style> </style>
<script> <script>

View File

@ -1,11 +1,9 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<center> <center>
<h3>Choose server</h3>
<p> <p>
<form action="{{ action }}" method="post"> <form action="{{ action }}" method="post">
<input type="hidden" id="service" value="{{service}}"> <input type="hidden" id="service" value="{{service}}">
<a class="ui-button ui-widget ui-corner-all" title="Return back" onclick="history.back()">Back</a>
{% include 'include/select.html' %} {% include 'include/select.html' %}
<button type="submit" value="open" name="open" class="btn btn-default">Open</button> <button type="submit" value="open" name="open" class="btn btn-default">Open</button>
</form> </form>

View File

@ -5,15 +5,17 @@
{% include 'include/getstarted.html' %} {% include 'include/getstarted.html' %}
{% else %} {% else %}
<center> <center>
<h3>Choose server</h3>
<p> <p>
<form action="{{ action }}" method="post"> <form action="{{ action }}" method="post">
<a class="ui-button ui-widget ui-corner-all" title="Return back" onclick="history.back()">Back</a>
{% include 'include/select.html' %} {% include 'include/select.html' %}
<button type="submit" value="open" name="open" class="btn btn-default">Open</button> <button type="submit" value="open" name="open" class="btn btn-default">Open</button>
{% if service != 'keepalived' %}
<a href="config.py" class="ui-button ui-widget ui-corner-all" title="Configs page">Configs</a>
<a class="ui-button ui-widget ui-corner-all" title="View stat" onclick="openStats()">Stat</a>
{% endif %}
</form> </form>
{% if not aftersave and not open %} {% if not aftersave and not open %}
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;"> <div class="add-note addName alert-info" style="width: inherit; margin-right: 15px; margin-top: 40%">
Here you can work with previous versions of {%if service == 'keepalived' %}Keepalived{%else%}HAProxy{%endif%} configs. Roll back to them, view or delete Here you can work with previous versions of {%if service == 'keepalived' %}Keepalived{%else%}HAProxy{%endif%} configs. Roll back to them, view or delete
</div> </div>
{% endif %} {% endif %}

View File

@ -85,9 +85,35 @@
showBytes('{{ s.2 }}') showBytes('{{ s.2 }}')
} }
showMetrics(); showMetrics();
$( function() {
$("#time-range").on('selectmenuchange', function () {
removeData()
let metrics = new Promise(
(resolve, reject) => {
{% for s in servers %}
getChartData('{{s.2}}')
getWafChartData('{{s.2}}')
{% endfor %}
});
metrics.then();
});
});
</script> </script>
{% endif %} {% endif %}
<div id="div-server-{{s.0}}" class="div-server-hapwi" {% if not serv %}style="cursor: move;"{%endif%}> {% if service == 'nginx' %}
{% if s.5.0.3 == 'active' %}
{% set additional_status_class = 'div-server-head-up' %}
{% else %}
{% set additional_status_class = 'div-server-head-down' %}
{% endif %}
{% else %}
{% if s.5 != False %}
{% set additional_status_class = 'div-server-head-up' %}
{% else %}
{% set additional_status_class = 'div-server-head-down' %}
{% endif %}
{% endif %}
<div id="div-server-{{s.0}}" class="div-server-hapwi {{additional_status_class}}" {% if not serv %}style="cursor: move;"{%endif%}>
<div class="server-name"> <div class="server-name">
<input type="hidden" id="server-name-{{s.0}}" value="{{s.1}}" /> <input type="hidden" id="server-name-{{s.0}}" value="{{s.1}}" />
<input type="hidden" id="service" value="{{service}}" /> <input type="hidden" id="service" value="{{service}}" />
@ -227,9 +253,21 @@
{% endfor %} {% endfor %}
</div> </div>
{% if serv and service == 'haproxy' %} {% if serv and service == 'haproxy' %}
<div id="refresh" style="text-align: right;margin-right: 105px;clear: both;display: block;margin-bottom: -25px;" title="Refresh metrics" onclick="showMetrics()"> <div style="clear: both; width: 95%;">
<div style="padding-left: 25px;float: left;margin-top: -15px;">
<b>Time range:</b>
<select title="Choose time range" id="time-range">
<option value="30">30 minutes</option>
<option value="60">1 hour</option>
<option value="180">3 hours</option>
<option value="360">6 hours</option>
<option value="720">12 hours</option>
</select>
</div>
<div id="refresh" style="text-align: right;margin-right: 3%;" title="Refresh metrics" onclick="showMetrics()">
<span class="service-reload"></span> <span class="service-reload"></span>
</div> </div>
</div>
{% for s in servers %} {% for s in servers %}
<div class="chart-container" style="display: block; width: 91.3%; height: 300px;"> <div class="chart-container" style="display: block; width: 91.3%; height: 300px;">
<canvas id="{{s.2}}" role="img"></canvas> <canvas id="{{s.2}}" role="img"></canvas>

View File

@ -15,7 +15,7 @@
<div id="create" style="margin-top: 20px;"> <div id="create" style="margin-top: 20px;">
<div id="left-collumn"> <div id="left-collumn">
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-listen-head">
<div class="server-name"> <div class="server-name">
<span title="Create Listen" class="redirectListen span-link">Create Listen</span> <span title="Create Listen" class="redirectListen span-link">Create Listen</span>
</div> </div>
@ -25,7 +25,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-listen-head">
<div class="server-name"> <div class="server-name">
<span title="Create HTTP Listen" class="redirectListen span-link" id="create-http-listen">Create HTTP Listen</span> <span title="Create HTTP Listen" class="redirectListen span-link" id="create-http-listen">Create HTTP Listen</span>
</div> </div>
@ -35,7 +35,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-listen-head">
<div class="server-name"> <div class="server-name">
<span title="Create SSL Listen" class="redirectListen span-link" id="create-ssl-listen">Create SSL Listen</span> <span title="Create SSL Listen" class="redirectListen span-link" id="create-ssl-listen">Create SSL Listen</span>
</div> </div>
@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-listen-head">
<div class="server-name"> <div class="server-name">
<span title="Create SSL Listen" class="redirectListen span-link" id="create-https-listen">Create HTTPS Listen</span> <span title="Create SSL Listen" class="redirectListen span-link" id="create-https-listen">Create HTTPS Listen</span>
</div> </div>
@ -56,7 +56,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-listen-head">
<div class="server-name"> <div class="server-name">
<span title="Create presaved options" class="span-link" id="add4">Create presaved options</span> <span title="Create presaved options" class="span-link" id="add4">Create presaved options</span>
</div> </div>
@ -68,7 +68,7 @@
</div> </div>
<div id="middle-collumn"> <div id="middle-collumn">
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-frontend-head">
<div class="server-name"> <div class="server-name">
<span title="Create Frontend" class="redirectFrontend span-link">Create Frontend</span> <span title="Create Frontend" class="redirectFrontend span-link">Create Frontend</span>
</div> </div>
@ -79,7 +79,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="div-server"> <div class="div-server add-proxy-frontend-head">
<div class="server-name"> <div class="server-name">
<span title="Create HTTP Frontend" class="redirectListen span-link" id="create-http-frontend">Create HTTP Frontend</span> <span title="Create HTTP Frontend" class="redirectListen span-link" id="create-http-frontend">Create HTTP Frontend</span>
</div> </div>
@ -88,7 +88,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-frontend-head">
<div class="server-name"> <div class="server-name">
<span title="Create SSL Frontend" class="redirectListen span-link" id="create-ssl-frontend">Create SSL Frontend</span> <span title="Create SSL Frontend" class="redirectListen span-link" id="create-ssl-frontend">Create SSL Frontend</span>
</div> </div>
@ -98,7 +98,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-frontend-head">
<div class="server-name"> <div class="server-name">
<span title="Create HTTPS Frontend" class="redirectListen span-link" id="create-https-frontend">Create HTTPS Frontend</span> <span title="Create HTTPS Frontend" class="redirectListen span-link" id="create-https-frontend">Create HTTPS Frontend</span>
</div> </div>
@ -108,7 +108,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-frontend-head">
<div class="server-name"> <div class="server-name">
<span title="Create presaved servers" class="span-link" id="add5">Create presaved servers</span> <span title="Create presaved servers" class="span-link" id="add5">Create presaved servers</span>
</div> </div>
@ -120,7 +120,7 @@
</div> </div>
<div id="right-collumn"> <div id="right-collumn">
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-backend-head">
<div class="server-name"> <div class="server-name">
<span title="Create Backend" class="redirectBackend span-link">Create Backend</span> <span title="Create Backend" class="redirectBackend span-link">Create Backend</span>
</div> </div>
@ -131,7 +131,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="div-server"> <div class="div-server add-proxy-backend-head">
<div class="server-name"> <div class="server-name">
<span title="Create SSL Backend" class="redirectListen span-link" id="create-http-backend">Create HTTP Backend</span> <span title="Create SSL Backend" class="redirectListen span-link" id="create-http-backend">Create HTTP Backend</span>
</div> </div>
@ -140,7 +140,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-backend-head">
<div class="server-name"> <div class="server-name">
<span title="Create HTTPS Backend" class="redirectListen span-link" id="create-ssl-backend">Create SSL Backend</span> <span title="Create HTTPS Backend" class="redirectListen span-link" id="create-ssl-backend">Create SSL Backend</span>
</div> </div>
@ -150,7 +150,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-backend-head">
<div class="server-name"> <div class="server-name">
<span title="Create SSL Backend" class="redirectListen span-link" id="create-https-backend">Create HTTPS Backend</span> <span title="Create SSL Backend" class="redirectListen span-link" id="create-https-backend">Create HTTPS Backend</span>
</div> </div>
@ -160,7 +160,7 @@
</div> </div>
</div> </div>
<div class="div-pannel"> <div class="div-pannel">
<div class="div-server"> <div class="div-server add-proxy-backend-head">
<div class="server-name"> <div class="server-name">
<span title="Create userlists" class="span-link" id="add6">Create userlists</span> <span title="Create userlists" class="span-link" id="add6">Create userlists</span>
</div> </div>

View File

@ -19,6 +19,7 @@
<span title="Actions with the master config will automatically apply on the slave">Slave for</span> <span title="Actions with the master config will automatically apply on the slave">Slave for</span>
</th> </th>
<th class="cred-field" style="width: 15%">Credentials</th> <th class="cred-field" style="width: 15%">Credentials</th>
<th class="cred-field" style="width: 200px;"></th>
<th style="width: 100%">Description</th> <th style="width: 100%">Description</th>
<th></th> <th></th>
<th></th> <th></th>
@ -114,6 +115,9 @@
<button onclick="checkSshConnect('{{server.2}}')" title="Check SSH connect to the server {{server.1}}">check</button> <button onclick="checkSshConnect('{{server.2}}')" title="Check SSH connect to the server {{server.1}}">check</button>
</div> </div>
</td> </td>
<td>
<button onclick="scanPorts('{{server.0}}')" title="Scanning open/filtered ports for the server {{server.1}}">scan</button>
</td>
<td> <td>
{% set id = 'desc-' + server.0|string() %} {% set id = 'desc-' + server.0|string() %}
{% if server.11 != "None" %} {% if server.11 != "None" %}

View File

@ -29,16 +29,24 @@ th, tr, td {
{% include 'include/getstarted.html' %} {% include 'include/getstarted.html' %}
{% else %} {% else %}
<div id="table_metrics"></div> <div id="table_metrics"></div>
<div style="padding-left: 25px;float: left;margin-top: 6px;">
<b>Time range:</b>
<select title="Choose time range" id="time-range">
<option value="30">30 minutes</option>
<option value="60">1 hour</option>
<option value="180">3 hours</option>
<option value="360">6 hours</option>
<option value="720">12 hours</option>
</select>
</div>
<div id="refresh" style="text-align: right;margin-top: 20px;margin-right: 10px;" title="Refresh metrics" onclick="showMetrics()"> <div id="refresh" style="text-align: right;margin-top: 20px;margin-right: 10px;" title="Refresh metrics" onclick="showMetrics()">
<span class="service-reload"></span> <span class="service-reload"></span>
</div> </div>
<div id="sortable">
{% for s in servers %} {% for s in servers %}
<div class="chart-container"> <div class="chart-container">
<canvas id="{{s.0}}" role="img"></canvas> <canvas id="{{s.0}}" role="img"></canvas>
</div> </div>
{% endfor %} {% endfor %}
</div>
<script> <script>
function showMetrics() { function showMetrics() {
let metrics = new Promise( let metrics = new Promise(
@ -51,6 +59,18 @@ th, tr, td {
metrics.then(); metrics.then();
} }
showMetrics() showMetrics()
$( function() {
$("#time-range").on('selectmenuchange', function () {
removeData()
let metrics = new Promise(
(resolve, reject) => {
{% for s in servers %}
getChartData('{{s.0}}')
{% endfor %}
});
metrics.then();
});
});
</script> </script>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -5,14 +5,8 @@
<script src="/inc/codemirror/nginx.js"></script> <script src="/inc/codemirror/nginx.js"></script>
<script src="/inc/codemirror/haproxy.js"></script> <script src="/inc/codemirror/haproxy.js"></script>
<center> <center>
<h3>Choose a section</h3>
<p> <p>
<form action="{{ action }}" method="post"> <form action="{{ action }}" method="post">
{% if aftersave %}
<a class="ui-button ui-widget ui-corner-all" title="Return back" onclick="history.go(-3)">Back</a>
{% else %}
<a class="ui-button ui-widget ui-corner-all" title="Return back" onclick="history.back()">Back</a>
{% endif %}
<select autofocus required name="section" id="{{ select_id }}"> <select autofocus required name="section" id="{{ select_id }}">
<option disabled>Choose a section</option> <option disabled>Choose a section</option>
{% for s in sections %} {% for s in sections %}

View File

@ -49,6 +49,7 @@
host = host.replace(/\./g, '\\.'); host = host.replace(/\./g, '\\.');
hostnamea.push(host); hostnamea.push(host);
{% endfor %} {% endfor %}
</script> </script>
{% if servers_all|length == 0 %} {% if servers_all|length == 0 %}
{% include 'include/getstarted.html' %} {% include 'include/getstarted.html' %}
@ -63,7 +64,7 @@
</td> </td>
<td class="padding10"> <td class="padding10">
WAF mode WAF mode
</td class="padding10"> </td>
<td> <td>
Metrics Metrics
</td> </td>
@ -85,7 +86,17 @@
<script src="/inc/overview.js"></script> <script src="/inc/overview.js"></script>
<script src="/inc/metrics.js"></script> <script src="/inc/metrics.js"></script>
<script src="/inc/chart.min.js"></script> <script src="/inc/chart.min.js"></script>
<div id="refresh" style="text-align: right;margin-top: 20px;margin-right: 20px;" title="Refresh metrics" onclick="showWafMetrics()"> <div style="padding-left: 25px;float: left;margin-top: 3px;">
<b>Time range:</b>
<select title="Choose time range" id="time-range">
<option value="30">30 minutes</option>
<option value="60">1 hour</option>
<option value="180">3 hours</option>
<option value="360">6 hours</option>
<option value="720">12 hours</option>
</select>
</div>
<div id="refresh" style="text-align: right;margin-top: 10px;margin-right: 20px; margin-bottom: 10px;" title="Refresh metrics" onclick="showWafMetrics()">
<span class="service-reload"></span> <span class="service-reload"></span>
</div> </div>
{% for s in servers %} {% for s in servers %}
@ -104,6 +115,18 @@
} }
showWafMetrics(); showWafMetrics();
showOverviewWaf(ip, hostnamea); showOverviewWaf(ip, hostnamea);
$( function() {
$("#time-range").on('selectmenuchange', function () {
removeData()
let metrics = new Promise(
(resolve, reject) => {
{% for s in servers %}
getWafChartData('{{s.0}}')
{% endfor %}
});
metrics.then();
});
});
</script> </script>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px; clear: both;"> <div class="add-note addName alert-info" style="width: inherit; margin-right: 15px; clear: both;">
You can read the description and watch a video about WAF <a href="https://haproxy-wi.org/description.py?description=waf" title="WAF" target="_blank">here</a> You can read the description and watch a video about WAF <a href="https://haproxy-wi.org/description.py?description=waf" title="WAF" target="_blank">here</a>

View File

@ -1313,8 +1313,7 @@ function createList(color) {
toastr.info(data); toastr.info(data);
} else if (data.indexOf('success') != '-1' ) { } else if (data.indexOf('success') != '-1' ) {
toastr.clear(); toastr.clear();
toastr.success('WAF service has installed'); toastr.success('List has been created');
showOverviewWaf(ip, hostnamea)
setTimeout(function () { setTimeout(function () {
location.reload(); location.reload();
}, 2500); }, 2500);
@ -1383,7 +1382,7 @@ function saveList(action, list, color) {
for (i = 0; i < data.length; i++) { for (i = 0; i < data.length; i++) {
if (data[i]) { if (data[i]) {
if (data[i].indexOf('error:') != '-1') { if (data[i].indexOf('error: ') != '-1') {
toastr.error(data[i]); toastr.error(data[i]);
} else { } else {
toastr.success(data[i]); toastr.success(data[i]);

View File

@ -4,6 +4,7 @@ function getChartData(server) {
data: { data: {
new_metrics: '1', new_metrics: '1',
server: server, server: server,
time_range: $( "#time-range option:selected" ).val(),
token: $('#token').val() token: $('#token').val()
}, },
type: "POST", type: "POST",
@ -19,6 +20,13 @@ function getChartData(server) {
} }
}); });
} }
function removeData() {
for (i = 0; i < charts.length; i++) {
chart = charts[i];
chart.destroy();
}
}
var charts = []
function renderChart(data, labels, server) { function renderChart(data, labels, server) {
var ctx = document.getElementById(server) var ctx = document.getElementById(server)
var myChart = new Chart(ctx, { var myChart = new Chart(ctx, {
@ -85,6 +93,7 @@ function renderChart(data, labels, server) {
} }
} }
}); });
charts.push(myChart);
} }
function getWafChartData(server) { function getWafChartData(server) {
@ -93,6 +102,7 @@ function getWafChartData(server) {
data: { data: {
new_waf_metrics: '1', new_waf_metrics: '1',
server: server, server: server,
time_range: $( "#time-range option:selected" ).val(),
token: $('#token').val() token: $('#token').val()
}, },
type: "POST", type: "POST",
@ -158,8 +168,9 @@ function renderWafChart(data, labels, server) {
} }
} }
}); });
charts.push(myChart);
} }
console.log(charts);
$("#secIntervals").css("display", "none"); $("#secIntervals").css("display", "none");
function loadMetrics() { function loadMetrics() {

View File

@ -308,7 +308,7 @@ function showStats() {
}, },
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
if (data.indexOf('error:') != '-1') { if (data.indexOf('error:') != '-1' && data.indexOf('Internal error:') == '-1') {
toastr.error(data); toastr.error(data);
} else { } else {
toastr.clear(); toastr.clear();

View File

@ -394,7 +394,7 @@ pre {
font-weight: bold; font-weight: bold;
} }
.serverUp { .serverUp {
background-color: #5CB85C; background-color: #5ad05a;
} }
.serverNone { .serverNone {
background-color: #ddd; background-color: #ddd;
@ -421,7 +421,7 @@ pre {
font-size: 13px; font-size: 13px;
} }
.serverDown { .serverDown {
background-color: red; background-color: #be2424;
} }
.padding10 { .padding10 {
padding: 10px 10px 10px 0; padding: 10px 10px 10px 0;
@ -745,6 +745,27 @@ label {
.div-server { .div-server {
height: 95px; height: 95px;
} }
.div-server-head-up {
border-top: 3px solid #5ad05a !important;
}
.div-server-head-down {
border-top: 3px solid #be2424 !important;
}
.div-server-head-dis {
border-top: 3px solid #aaa !important;
}
.div-server-head-up, .div-server-head-down, .div-server-head-dis {
padding-top: 7px;
}
.add-proxy-listen-head {
border-top: 3px solid #02869b;
}
.add-proxy-frontend-head {
border-top: 3px solid #00a4bd;
}
.add-proxy-backend-head {
border-top: 3px solid #00b8d7;
}
.div-backends { .div-backends {
width: 89.3%; width: 89.3%;
} }
@ -862,6 +883,7 @@ label {
background-color: #fbfbfb;; background-color: #fbfbfb;;
margin: 10px; margin: 10px;
padding-left: 15px; padding-left: 15px;
padding-top: 0;
border: 1px solid #A4C7F5; border: 1px solid #A4C7F5;
} }
#good_services { #good_services {
@ -947,15 +969,17 @@ label {
} }
.div-server { .div-server {
margin-bottom: 30px !important; margin-bottom: 30px !important;
width: 43%; width: 300px;
height: 100px; height: 100px;
} }
.server-desc {
width: 300px;
}
} }
@media (max-width: 1280px) { @media (max-width: 1280px) {
.div-server { .div-server {
margin-bottom: 30px !important; margin-bottom: 30px !important;
width: 90%; height: 100px;
height: 70px;
} }
#ssl_name { #ssl_name {
width: 100px; width: 100px;

View File

@ -173,6 +173,7 @@ $( function() {
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
data = data.replace(/\s+/g,' '); data = data.replace(/\s+/g,' ');
$("#ajax").html('')
if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') { if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') {
toastr.error(data); toastr.error(data);
} else if (data.indexOf('success') != '-1' ){ } else if (data.indexOf('success') != '-1' ){
@ -205,6 +206,7 @@ $( function() {
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
data = data.replace(/\s+/g,' '); data = data.replace(/\s+/g,' ');
$("#ajax").html('')
if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') { if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') {
toastr.clear(); toastr.clear();
toastr.error(data); toastr.error(data);
@ -222,7 +224,7 @@ $( function() {
} ); } );
}); });
$('#grafna_install').click(function() { $('#grafna_install').click(function() {
$("#ajaxmon").html('') $("#ajaxmon").html('');
$("#ajaxmon").html(wait_mess); $("#ajaxmon").html(wait_mess);
$.ajax( { $.ajax( {
url: "options.py", url: "options.py",
@ -233,6 +235,7 @@ $( function() {
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
data = data.replace(/\s+/g,' '); data = data.replace(/\s+/g,' ');
$("#ajaxmon").html('');
if (data.indexOf('FAILED') != '-1') { if (data.indexOf('FAILED') != '-1') {
toastr.clear(); toastr.clear();
toastr.error(data);; toastr.error(data);;
@ -261,6 +264,7 @@ $( function() {
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
data = data.replace(/\s+/g,' '); data = data.replace(/\s+/g,' ');
$("#ajaxmon").html('');
if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') { if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') {
toastr.clear(); toastr.clear();
toastr.error(data); toastr.error(data);
@ -291,6 +295,7 @@ $( function() {
type: "POST", type: "POST",
success: function( data ) { success: function( data ) {
data = data.replace(/\s+/g,' '); data = data.replace(/\s+/g,' ');
$("#ajaxmon").html('');
if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') { if (data.indexOf('error:') != '-1' || data.indexOf('FAILED') != '-1') {
toastr.error(data); toastr.error(data);
} else if (data.indexOf('success') != '-1' ){ } else if (data.indexOf('success') != '-1' ){
@ -2047,3 +2052,35 @@ function OpenVpnSess(id, action) {
} }
} ); } );
} }
function scanPorts(id) {
$.ajax({
url: "options.py",
data: {
scan_ports: id,
token: $('#token').val()
},
type: "POST",
success: function (data) {
data = data.replace(/\s+/g, ' ');
if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error:') != '-1') {
toastr.error(data);
} else {
toastr.clear();
$("#show_scans_ports_body").html(data);
$("#show_scans_ports" ).dialog({
resizable: false,
height: "auto",
width: 360,
modal: true,
title: "Openned ports",
buttons: {
Close: function() {
$( this ).dialog( "close" );
$("#show_scans_ports_body").html('');
}
}
});
}
}
} );
}

View File

@ -80,6 +80,7 @@ function installWaf(ip1) {
} }
function changeWafMode(id) { function changeWafMode(id) {
var waf_mode = $('#'+id+' option:selected').val(); var waf_mode = $('#'+id+' option:selected').val();
console.log('1')
var server_hostname = id.split('_')[0]; var server_hostname = id.split('_')[0];
$.ajax( { $.ajax( {
url: "options.py", url: "options.py",
@ -105,14 +106,12 @@ $( function() {
}); });
}); });
function waf_rules_en(id) { function waf_rules_en(id) {
console.log('1')
var enable = 0; var enable = 0;
if ($('#rule_id-'+id).is(':checked')) { if ($('#rule_id-'+id).is(':checked')) {
enable = '1'; enable = '1';
} }
var serv = findGetParameter('serv') var serv = findGetParameter('serv')
console.log(serv)
console.log(id)
console.log(enable)
$.ajax( { $.ajax( {
url: "options.py", url: "options.py",
data: { data: {