Pavel Loginov 2021-08-08 19:02:00 +06:00
parent fab9eb4837
commit 701b560df6
12 changed files with 179 additions and 141 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import funct
from sql import out_error
from db_model import *
from funct import check_ver
def default_values():
@ -43,9 +44,9 @@ def default_values():
'group': '1'},
{'param': 'haproxy_config_path', 'value': '/etc/haproxy/haproxy.cfg', 'section': 'haproxy', 'desc': 'Path to the HAProxy configuration file',
'group': '1'},
{'param': 'server_state_file', 'value': 'stats', 'section': 'haproxy', 'desc': 'Path to the HAProxy state file',
{'param': 'server_state_file', 'value': '/etc/haproxy/haproxy.state', 'section': 'haproxy', 'desc': 'Path to the HAProxy state file',
'group': '1'},
{'param': 'haproxy_sock', 'value': '/etc/haproxy/haproxy.state', 'section': 'haproxy',
{'param': 'haproxy_sock', 'value': '/var/run/haproxy.sock', 'section': 'haproxy',
'desc': 'Socket port for HAProxy', 'group': '1'},
{'param': 'haproxy_sock_port', 'value': '1999', 'section': 'haproxy', 'desc': 'HAProxy sock port',
'group': '1'},
@ -91,7 +92,7 @@ def default_values():
try:
Setting.insert_many(data_source).on_conflict_ignore().execute()
except Exception as e:
funct.out_error(e)
out_error(e)
data_source = [
{'username': 'admin', 'email': 'admin@localhost', 'password': '21232f297a57a5a743894a0e4a801fc3', 'role': 'superAdmin', 'groups': '1'},
@ -102,7 +103,7 @@ def default_values():
try:
User.insert_many(data_source).on_conflict_ignore().execute()
except Exception as e:
funct.out_error(e)
out_error(e)
data_source = [
{'name': 'admin', 'description': 'Can do everything'},
@ -113,12 +114,12 @@ def default_values():
try:
Role.insert_many(data_source).on_conflict_ignore().execute()
except Exception as e:
funct.out_error(e)
out_error(e)
try:
Groups.insert(name='All', description='All servers enter in this group').on_conflict_ignore().execute()
except Exception as e:
funct.out_error(e)
out_error(e)
def update_db_v_3_4_5_22():
@ -236,7 +237,7 @@ def update_db_v_4_3_2_1(**kwargs):
try:
query_res = query.execute()
except Exception as e:
funct.out_error(e)
out_error(e)
else:
groups = query_res
@ -265,7 +266,7 @@ def update_db_v_4_5_1(**kwargs):
try:
cursor.execute(sql)
except Exception as e:
funct.out_error(e)
out_error(e)
else:
role = cursor.fetchall()
@ -593,7 +594,7 @@ def update_db_v_4_5_8_2(**kwargs):
try:
query_res = query.execute()
except Exception as e:
funct.out_error(e)
out_error(e)
else:
groups = query_res
@ -717,7 +718,7 @@ def update_ver():
def update_all():
if funct.check_ver() is None:
if check_ver() is None:
update_db_v_3_4_5_22()
update_db_v_4()
update_db_v_41()
@ -740,7 +741,7 @@ def update_all():
def update_all_silent():
if funct.check_ver() is None:
if check_ver() is None:
update_db_v_3_4_5_22()
update_db_v_4(silent=1)
update_db_v_41(silent=1)

View File

@ -3,14 +3,25 @@ import cgi
import os
import sys
def is_ip_or_dns(server_from_request: str) -> str:
import re
ip_regex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
dns_regex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
try:
if re.match(ip_regex, server_from_request):
return server_from_request
else:
if re.match(dns_regex, server_from_request):
return server_from_request
else:
return ''
except:
return ''
form = cgi.FieldStorage()
serv = form.getvalue('serv')
def get_app_dir():
d = sys.path[0]
d = d.split('/')[-1]
return sys.path[0] if d == "app" else os.path.dirname(sys.path[0])
serv = is_ip_or_dns(form.getvalue('serv'))
def get_config_var(sec, var):
@ -245,8 +256,8 @@ def is_admin(**kwargs):
try:
return True if role <= level else False
except Exception as e:
print('error: '+str(e))
# return False
# print('error: '+str(e))
return False
def page_for_admin(**kwargs):
@ -934,7 +945,7 @@ def show_haproxy_log(serv, rows=10, waf='0', grep=None, hour='00', minut='00', h
if service == 'nginx' or service == 'haproxy':
syslog_server_enable = sql.get_setting('syslog_server_enable')
if syslog_server_enable is None or syslog_server_enable == "0":
if syslog_server_enable is None or syslog_server_enable == 0:
if service == 'nginx':
local_path_logs = sql.get_setting('nginx_path_error_logs')
commands = ["sudo cat %s| awk '$2>\"%s:00\" && $2<\"%s:00\"' |tail -%s %s %s" % (local_path_logs, date, date1, rows, grep_act, exgrep_act)]
@ -949,7 +960,7 @@ def show_haproxy_log(serv, rows=10, waf='0', grep=None, hour='00', minut='00', h
if waf == "1":
local_path_logs = '/var/log/modsec_audit.log'
commands = ["sudo cat %s |tail -%s %s %s" % (local_path_logs, rows, grep_act, exgrep_act)]
if kwargs.get('html') == 0:
a = ssh_command(syslog_server, commands)
return show_log(a, html=0, grep=grep)
@ -957,13 +968,13 @@ def show_haproxy_log(serv, rows=10, waf='0', grep=None, hour='00', minut='00', h
return ssh_command(syslog_server, commands, show_log='1', grep=grep)
elif service == 'apache':
apache_log_path = sql.get_setting('apache_log_path')
if serv == 'roxy-wi.access.log':
cmd = "cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % (apache_log_path+"/"+serv, date, date1, rows, grep_act, exgrep_act)
cmd = "cat {}| awk -F\"/|:\" '$3>\"{}:00\" && $3<\"{}:00\"' |tail -{} {} {}".format(apache_log_path+"/"+serv, date, date1, rows, grep_act, exgrep_act)
elif serv == 'roxy-wi.error.log':
cmd = "cat %s| awk '$4>\"%s:00\" && $4<\"%s:00\"' |tail -%s %s %s" % (apache_log_path+"/"+serv, date, date1, rows, grep_act, exgrep_act)
cmd = "cat {}| awk '$4>\"{}:00\" && $4<\"{}:00\"' |tail -{} {} {}".format(apache_log_path+"/"+serv, date, date1, rows, grep_act, exgrep_act)
elif serv == 'fail2ban.log':
cmd = "cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % ("/var/log/"+serv, date, date1, rows, grep_act, exgrep_act)
cmd = "cat {}| awk -F\"/|:\" '$3>\"{}:00\" && $3<\"{}:00\"' |tail -{} {} {}".format("/var/log/"+serv, date, date1, rows, grep_act, exgrep_act)
output, stderr = subprocess_execute(cmd)

View File

@ -7,7 +7,7 @@ import funct
import sql
form = funct.form
serv = form.getvalue("serv")
serv = funct.is_ip_or_dns(form.getvalue('serv'))
act = form.getvalue("act")
if (form.getvalue('new_metrics') or
@ -108,7 +108,7 @@ if form.getvalue('ip_select') is not None:
funct.show_backends(serv)
if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is None:
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port'))
backend = form.getvalue('ipbackend')
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |awk \'{print $4}\'' % (serv, haproxy_sock_port, backend)
output, stderr = funct.subprocess_execute(cmd)
@ -119,7 +119,7 @@ if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is
print(i + '<br>')
if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is not None:
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port'))
backend = form.getvalue('ipbackend')
backend_server = form.getvalue('backend_server')
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)
@ -377,12 +377,12 @@ if form.getvalue("change_pos") is not None:
pos = form.getvalue('change_pos')
sql.update_server_pos(pos, serv)
if form.getvalue('ip') is not None and serv is not None:
commands = ["sudo ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'"]
if form.getvalue('show_ip') is not None and serv is not None:
commands = ["sudo ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'"]
funct.ssh_command(serv, commands, ip="1")
if form.getvalue('showif'):
commands = ["sudo ip link|grep 'UP' |grep -v 'lo'| awk '{print $2}' |awk -F':' '{print $1}'"]
commands = ["sudo ip link|grep 'UP' |grep -v 'lo'| awk '{print $2}' |awk -F':' '{print $1}'"]
funct.ssh_command(serv, commands, ip="1")
if form.getvalue('action_hap') is not None and serv is not None:
@ -507,6 +507,8 @@ if form.getvalue('show_userlists'):
if act == "overviewHapservers":
if form.getvalue('service') == 'nginx':
config_path = sql.get_setting('nginx_config_path')
elif form.getvalue('service') == 'keepalived':
config_path = '/etc/keepalived/keepalived.conf'
else:
config_path = sql.get_setting('haproxy_config_path')
commands = ["ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % config_path]
@ -749,7 +751,7 @@ if serv is not None and act == "stats":
else:
print(data.decode('utf-8'))
if serv is not None and form.getvalue('rows') is not None:
if serv is not None and form.getvalue('show_log') is not None:
rows = form.getvalue('rows')
waf = form.getvalue('waf')
grep = form.getvalue('grep')
@ -897,16 +899,15 @@ if serv is not None and act == "showMap":
print('<img src="/map%s.png" alt="map">' % date)
if form.getvalue('servaction') is not None:
server_state_file = sql.get_setting('server_state_file')
haproxy_sock = sql.get_setting('haproxy_sock')
enable = form.getvalue('servaction')
backend = form.getvalue('servbackend')
cmd = 'echo "%s %s" |sudo socat stdio %s' % (enable, backend, haproxy_sock)
cmd = 'echo "{} {}" |sudo socat stdio {}'.format(enable, backend, haproxy_sock)
if form.getvalue('save') == "on":
save_command = 'echo "show servers state" | sudo socat %s stdio > %s' % (haproxy_sock, server_state_file)
save_command = 'echo "show servers state" | sudo socat {} stdio > {}'.format(haproxy_sock, server_state_file)
command = [cmd + ';' + save_command]
else:
command = [cmd]
@ -991,7 +992,7 @@ if serv is not None and act == "configShow":
conf = open(cfg, "r")
except IOError:
print('<div class="alert alert-danger">Can\'t read config file</div>')
is_serv_protected = sql.is_serv_protected(serv)
from jinja2 import Environment, FileSystemLoader
@ -1315,7 +1316,7 @@ if form.getvalue('node_exp_install'):
else:
proxy_serv = ''
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
output, error = funct.subprocess_execute(commands[0])
@ -2290,16 +2291,16 @@ if form.getvalue('showBytes') is not None:
serv = form.getvalue('showBytes')
port = sql.get_setting('haproxy_sock_port')
bin_bout = []
cmd = "echo 'show stat' |nc " + serv + " " + port + " |cut -d ',' -f 1-2,9|grep -E '[0-9]'|awk -F',' '{sum+=$3;}END{print sum;}'"
cmd = "echo 'show stat' |nc {} {} |cut -d ',' -f 1-2,9|grep -E '[0-9]'|awk -F',' '{{sum+=$3;}}END{{print sum;}}'".format(serv, port)
bin, stderr = funct.subprocess_execute(cmd)
bin_bout.append(bin[0])
cmd = "echo 'show stat' |nc " + serv + " " + port + " |cut -d ',' -f 1-2,10|grep -E '[0-9]'|awk -F',' '{sum+=$3;}END{print sum;}'"
cmd = "echo 'show stat' |nc {} {} |cut -d ',' -f 1-2,10|grep -E '[0-9]'|awk -F',' '{{sum+=$3;}}END{{print sum;}}'".format(serv, port)
bin, stderr = funct.subprocess_execute(cmd)
bin_bout.append(bin[0])
cmd = "echo 'show stat' |nc " + serv + " " + port + " |cut -d ',' -f 1-2,5|grep -E '[0-9]'|awk -F',' '{sum+=$3;}END{print sum;}'"
cmd = "echo 'show stat' |nc {} {} |cut -d ',' -f 1-2,5|grep -E '[0-9]'|awk -F',' '{{sum+=$3;}}END{{print sum;}}'".format(serv, port)
bin, stderr = funct.subprocess_execute(cmd)
bin_bout.append(bin[0])
cmd = "echo 'show stat' |nc " + serv + " " + port + " |cut -d ',' -f 1-2,8|grep -E '[0-9]'|awk -F',' '{sum+=$3;}END{print sum;}'"
cmd = "echo 'show stat' |nc {} {} |cut -d ',' -f 1-2,8|grep -E '[0-9]'|awk -F',' '{{sum+=$3;}}END{{print sum;}}'".format(serv, port)
bin, stderr = funct.subprocess_execute(cmd)
bin_bout.append(bin[0])

View File

@ -8,10 +8,10 @@ mysql_enable = funct.get_config_var('mysql', 'enable')
def out_error(error):
error = str(error)
# try:
# funct.logging('localhost', error, haproxywi=1, login=1)
# except Exception:
# funct.logging('localhost', error, haproxywi=1)
try:
funct.logging('localhost', error, haproxywi=1, login=1)
except Exception:
funct.logging('localhost', error, haproxywi=1)
print('error: '+error)
@ -149,9 +149,9 @@ def add_setting_for_new_group(group_id):
'group': group_id},
{'param': 'haproxy_config_path', 'value': '/etc/haproxy/haproxy.cfg', 'section': 'haproxy', 'desc': 'Path to the HAProxy configuration file',
'group': group_id},
{'param': 'server_state_file', 'value': 'stats', 'section': 'haproxy', 'desc': 'Path to the HAProxy state file',
{'param': 'server_state_file', 'value': '/etc/haproxy/haproxy.state', 'section': 'haproxy', 'desc': 'Path to the HAProxy state file',
'group': group_id},
{'param': 'haproxy_sock', 'value': '/etc/haproxy/haproxy.state', 'section': 'haproxy',
{'param': 'haproxy_sock', 'value': '/var/run/haproxy.sock', 'section': 'haproxy',
'desc': 'Path to the HAProxy sock file', 'group': group_id},
{'param': 'haproxy_sock_port', 'value': '1999', 'section': 'haproxy', 'desc': 'Socket port for HAProxy',
'group': group_id},
@ -444,7 +444,7 @@ def select_servers(**kwargs):
sql = """select * from servers where enable = '1' ORDER BY groups """
if kwargs.get("server") is not None:
sql = """select * from servers where ip='%s' """ % kwargs.get("server")
sql = """select * from servers where ip='{}' """.format(kwargs.get("server"))
if kwargs.get("full") is not None:
sql = """select * from servers ORDER BY hostname """
if kwargs.get("get_master_servers") is not None:
@ -453,16 +453,16 @@ def select_servers(**kwargs):
sql = """ select servers.id, servers.hostname from servers
left join user as user on servers.groups = user.groups
left join uuid as uuid on user.id = uuid.user_id
where uuid.uuid = '%s' and servers.master = 0 and servers.type_ip = 0 and servers.enable = 1 ORDER BY servers.groups
""" % kwargs.get('uuid')
where uuid.uuid = '{}' and servers.master = 0 and servers.type_ip = 0 and servers.enable = 1 ORDER BY servers.groups
""".format(kwargs.get('uuid'))
if kwargs.get("id"):
sql = """select * from servers where id='%s' """ % kwargs.get("id")
sql = """select * from servers where id='{}' """.format(kwargs.get("id"))
if kwargs.get("hostname"):
sql = """select * from servers where hostname='%s' """ % kwargs.get("hostname")
sql = """select * from servers where hostname='{}' """.format(kwargs.get("hostname"))
if kwargs.get("id_hostname"):
sql = """select * from servers where hostname='%s' or id = '%s' or ip = '%s'""" % (kwargs.get("id_hostname"), kwargs.get("id_hostname"), kwargs.get("id_hostname"))
sql = """select * from servers where hostname='{}' or id = '{}' or ip = '{}'""".format(kwargs.get("id_hostname"), kwargs.get("id_hostname"), kwargs.get("id_hostname"))
if kwargs.get("server") and kwargs.get("keep_alive"):
sql = """select active from servers where ip='%s' """ % kwargs.get("server")
sql = """select active from servers where ip='{}' """.format(kwargs.get("server"))
try:
cursor.execute(sql)
except Exception as e:
@ -567,7 +567,7 @@ def delete_old_uuid():
def update_last_act_user(uuid):
session_ttl = int(get_setting('session_ttl'))
query = UUID.update(exp=funct.get_data('regular', timedelta=session_ttl))
query = UUID.update(exp=funct.get_data('regular', timedelta=session_ttl)).where(UUID.uuid == uuid)
try:
query.execute()
except Exception as e:
@ -717,7 +717,7 @@ def get_dick_permit(**kwargs):
if funct.check_user_group(token=token):
cursor = conn.cursor()
if grp == '1' and not only_group:
sql = """ select * from servers where enable = 1 %s %s %s %s %s order by pos""" % (disable, type_ip, nginx, keepalived, ip)
sql = """ select * from servers where enable = 1 {} {} {} {} {} order by pos""" .format(disable, type_ip, nginx, keepalived, ip)
else:
sql = """ select * from servers where groups = '{group}' and (enable = 1 {disable}) {type_ip} {ip} {haproxy} {nginx} {keepalived} order by pos
""".format(group=grp, disable=disable, type_ip=type_ip, ip=ip, haproxy=haproxy, nginx=nginx, keepalived=keepalived)
@ -1640,7 +1640,18 @@ def get_setting(param, **kwargs):
return query_res
else:
for setting in query_res:
return setting.value
if (
param == 'nginx_stats_port' or param == 'session_ttl' or param == 'token_ttl' or
param == 'stats_port' or param == 'haproxy_sock_port' or param == 'ldap_type' or
param == 'ldap_port' or param == 'ldap_enable' or param == 'log_time_storage' or
param == 'syslog_server_enable' or param == 'smon_check_interval' or
param == 'checker_check_interval' or param == 'port_scan_interval' or
param == 'smon_keep_history_range' or param == 'checker_keep_history_range' or
param == 'portscanner_keep_history_range' or param == 'haproxy_enterprise'
):
return int(setting.value)
else:
return setting.value
def update_setting(param, val):
@ -1679,7 +1690,7 @@ def select_alert(**kwargs):
cursor = conn.cursor()
sql = """select ip from servers where alert = 1 and enable = 1 """
if kwargs.get("group") is not None:
sql = """select ip from servers where alert = 1 and `groups` = '%s' and enable = 1 """ % kwargs.get("group")
sql = """select ip from servers where alert = 1 and `groups` = '{}' and enable = 1 """.format(kwargs.get("group"))
try:
cursor.execute(sql)
except Exception as e:
@ -1708,7 +1719,7 @@ def select_nginx_alert(**kwargs):
cursor = conn.cursor()
sql = """select ip from servers where nginx_alert = 1 and enable = 1 """
if kwargs.get("group") is not None:
sql = """select ip from servers where nginx_alert = 1 and `groups` = '%s' and enable = 1 """ % kwargs.get("group")
sql = """select ip from servers where nginx_alert = 1 and `groups` = '{}' and enable = 1 """.format(kwargs.get("group"))
try:
cursor.execute(sql)
except Exception as e:
@ -2076,21 +2087,24 @@ def response_time(time, smon_id):
def smon_list(user_group):
cursor = conn.cursor()
if user_group == 1:
user_group = ''
query = (SMON.select(SMON.ip, SMON.port,SMON.status,SMON.en,SMON.desc,SMON.response_time,SMON.time_state,
SMON.group,SMON.script,SMON.http,SMON.http_status,SMON.body,SMON.body_status)
.order_by(SMON.group)
)
else:
user_group = "where user_group='%s'" % user_group
query = (SMON.select(SMON.ip, SMON.port, SMON.status, SMON.en, SMON.desc, SMON.response_time, SMON.time_state,
SMON.group, SMON.script, SMON.http, SMON.http_status, SMON.body, SMON.body_status)
.where(SMON.user_group == user_group)
.order_by(SMON.group)
)
sql = """ select ip,port,status,en,`desc`,response_time,time_state,`group`,script,http,http_status,body,body_status
from smon %s order by `group` desc """ % user_group
try:
cursor.execute(sql)
query_res = query.execute()
except Exception as e:
out_error(e)
else:
return cursor.fetchall()
return query_res
def insert_alerts(user_group, level, ip, port, message, service):
@ -2153,8 +2167,7 @@ def insert_port_scanner_settings(server_id, user_group_id, enabled, notify, hist
PortScannerSettings.insert(server_id=server_id, user_group_id=user_group_id, enabled=enabled,
notify=notify, history=history).execute()
return True
except Exception as e:
out_error(e)
except:
return False
@ -2274,7 +2287,7 @@ def delete_alert_history(keep_interval: int, service: str):
def delete_portscanner_history(keep_interval: int):
query = PortScannerHistory.delete().where(
PortScannerHistory.date < funct.get_data('regular', timedelta_minus=keep_interval))
PortScannerHistory.date < funct.get_data('regular', timedelta_minus=int(keep_interval)))
try:
query.execute()
except Exception as e:

View File

@ -7,14 +7,14 @@
{% set up = [] %}
{% set dis = [] %}
{% for s in smon %}
{% if s.3 == 1 %}
{% if s.2 == 1 and s.10 == 1 and s.12 == 1 %}
{% if s.en == 1 %}
{% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
{% if up.append('1') %} {% endif %}
{% else %}
{% if down.append('1') %} {% endif %}
{% endif %}
{% else %}
{% if dis.append(s.7) %} {% endif %}
{% if dis.append(s.group) %} {% endif %}
{% endif %}
{% endfor %}
<b>Counting state: UP: {{up|length}}, DOWN: {{down|length}}, Disabled: {{dis|length}}</b>
@ -23,15 +23,15 @@
{% set group = [] %}
{% set group_prev = [] %}
{%- for s in smon -%}
{% if s.7 %}
{% if s.7 not in group %}
{% if s.group %}
{% if s.group not in group %}
<div class="smon_group">
<div class="group_name">
{{ s.7 }}
{{ s.group }}
</div>
</div>
{% endif %}
{% if group.append(s.7) %} {% endif %}
{% if group.append(s.group) %} {% endif %}
{% else %}
<div class="smon_group">
<div class="group_name">
@ -39,8 +39,8 @@
</div>
</div>
{% endif %}
{% if s.3 == 1 %}
{% if s.2 == 1 and s.10 == 1 and s.12 == 1 %}
{% if s.en == 1 %}
{% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
<div class="smon_services good div-server-head-up"
{% else %}
<div class="smon_services err div-server-head-down"
@ -49,37 +49,37 @@
<div class="smon_services dis div-server-head-dis"
{% endif %}
title="Enabled checks:
Port check{% if s.9 %},
HTTP status check: {{s.9.split(':')[0]}}://{{s.0}}:{{s.1}}{{s.9.split(':')[1]}}
{% if s.11 and s.11 is not none %}, Body response check: {{s.11}}{% endif %}
Port check{% if s.http %},
HTTP status check: {{s.http.split(':')[0]}}://{{s.ip}}:{{s.port}}{{s.http.split(':')[1]}}
{% if s.body and s.body is not none %}, Body response check: {{s.body}}{% endif %}
{% endif %}">
<div class="ip">
{% if s.0|string|length > 23 %}
{% if s.ip|string|length > 23 %}
<span style="font-size: 11px;">
{% elif s.0|string|length > 20 %}
{% elif s.ip|string|length > 20 %}
<span style="font-size: 12px;">
{% elif s.0|string|length > 17 %}
{% elif s.ip|string|length > 17 %}
<span style="font-size: 15px;">
{% else %}
<span>
{% endif %}
<a href="smon.py?action=history&host={{s.0}}" title="View history for {{s.0}} host" class="link">{{s.0}}:{{s.1}}</a>
<a href="smon.py?action=history&host={{s.ip}}" title="View history for {{s.ip}} host" class="link">{{s.ip}}:{{s.port}}</a>
</span>
</span>
</div>
<div class="desc">
{% if s.4 is not none %}
<b>{{s.4}}</b>
{% if s.desc is not none %}
<b>{{s.desc}}</b>
{% else %}
Desc: None
{% endif %}
</div>
<div class="desc">
{% if s.3 == 1 %}
{% if s.2 == 1 and s.10 == 1 and s.12 == 1 %}
Uptime: <time class="timeago" datetime="{{s.6}}">{{s.6}}</time>
{% elif s.2 == 0 or s.10 == 0 or s.12 == 0 %}
Downtime: <time class="timeago" datetime="{{s.6}}">{{s.6}}</time>
{% if s.en == 1 %}
{% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
Uptime: <time class="timeago" datetime="{{s.time_state}}">{{s.time_state}}</time>
{% elif s.status == 0 or s.http_status == 0 or s.body_status == 0 %}
Downtime: <time class="timeago" datetime="{{s.time_state}}">{{s.time_state}}</time>
{% else %}
Uptime: N/A
{% endif %}
@ -88,14 +88,14 @@ HTTP status check: {{s.9.split(':')[0]}}://{{s.0}}:{{s.1}}{{s.9.split(':')[1]}}
{% endif %}
</div>
<div class="res_time">
{% if s.3 == 1 %}
{% if s.2 == 1 %}
{% if s.en == 1 %}
{% if s.status == 1 %}
Resp time:
{% else %}
Last resp time:
{% endif %}
{% if s.5 %}
<span title="{{s.5}} ms">{{s.5|truncate(9)}} ms</span>
{% if s.responce_time %}
<span title="{{s.responce_time}} ms">{{s.responce_time|truncate(9)}} ms</span>
{% else %}
N/A
{% endif %}
@ -103,26 +103,26 @@ HTTP status check: {{s.9.split(':')[0]}}://{{s.0}}:{{s.1}}{{s.9.split(':')[1]}}
N/A
{% endif %}
</div>
{% if s.3 == 1 %}
{% if s.2 == 1 and s.10 == 1 and s.12 == 1 %}
{% if s.en == 1 %}
{% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %}
<div class="up">
<center>
UP
</center>
</div>
{% elif s.10 == 0 %}
{% elif s.http_status == 0 %}
<div class="down">
<center style="padding-top: 7px;">
HTTP IS FAILURE
</center>
</div>
{% elif s.12 == 0 %}
{% elif s.body_status == 0 %}
<div class="down">
<center style="padding-top: 7px;">
BODY IS FAILURE
</center>
</div>
{% elif s.2 == 3 %}
{% elif s.status == 3 %}
<div class="unknown">
<center style="padding-top: 7px;">
UNKNOWN

View File

@ -8,7 +8,7 @@
p {margin: 0;}
</style>
<table class="overview">
<caption><h3>Create new HA cluster</h3></caption>
<caption><h3>Create a new HA cluster</h3></caption>
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
@ -17,13 +17,13 @@
<td class="checkbox-head help_cursor"><span title="Roxy-WI will try to install HAProxy">HAProxy</span></td>
<td class="checkbox-head help_cursor"><span title="Roxy-WI will try to install Nginx">Nginx</span></td>
<td class="checkbox-head help_cursor"><span title="Roxy-WI will add VRRP address as a separated server">Add VIRT</span></td>
<td class="checkbox-head">SYN flood protect</td>
<td class="checkbox-head">SYN-flood protection</td>
<td></td>
</tr>
<tr>
<td class="padding10 first-collumn">
<select id="master">
<option disabled selected>Choose master</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -31,7 +31,7 @@
</td>
<td>
<select id="slave">
<option disabled selected>Choose master</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -50,7 +50,7 @@
</table>
<table class="overview">
<caption><h3>Or add VRRP to exist</h3></caption>
<caption><h3>Add VRRP to an existing cluster</h3></caption>
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
@ -66,7 +66,7 @@
<tr>
<td class="padding10 first-collumn">
<select id="master-add">
<option disabled selected>Choose master</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -74,7 +74,7 @@
</td>
<td>
<select id="slave-add">
<option disabled selected>Choose master</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}

View File

@ -142,9 +142,9 @@
<input type="hidden" id="service" value="{{service}}" />
{% if service == 'nginx' or service == 'keepalived' %}
{% if s.5.0.1 == 'active' %}
<span class="serverUp server-status" title="Uptime: {{s.5.0.4}}"></span>
<span class="serverUp server-status" title="Started: {{s.5.0.4}}"></span>
{% else %}
<span class="serverDown server-status" title="Downtime: : {{s.5.0.4}}"></span>
<span class="serverDown server-status" title="Stopped: : {{s.5.0.4}}"></span>
{% endif %}
{% else %}
{% if s.5 != False %}
@ -201,9 +201,9 @@
Version: {{s.5.0.0}} Process_num: {{s.5.0.3}}
<br />
{% if s.5.0.1 == 'active' %}
Uptime:
Started:
{% else %}
Downtime:
Stopped:
{% endif %}
{{s.5.0.2}}
{% else %}

View File

@ -21,21 +21,30 @@
{% set section.section = set.section %}
<tr class="{{ loop.cycle('odd', 'even') }} {{set.section}}-section" style="display: none">
<td class="addName">
<a href="#{{set.param}}" title="{{set.param}}" style="color: #000;">{{set.param}}</a>
{{set.param}}
</td>
<td class="addOption">
{% if set.param == 'ldap_password' %}
{% if set.value == 'None' %}
<input type="password" name="{{set.param}}" id="{{set.param}}" value="" title="" size="25" class="form-control" autocomplete="new-password">
{% if set.param == 'ldap_password' or set.param == 'stats_password' or set.param == 'nginx_stats_password' %}
{% if set.value is none %}
{{ input(set.param, size='25', type='password') }}
{% else %}
{{ input(set.param, size='25', type='password', placeholder='*****') }}
{% endif %}
{% elif set.param == 'nginx_stats_port' or set.param == 'session_ttl' or set.param == 'token_ttl' or
set.param == 'stats_port' or set.param == 'haproxy_sock_port' or set.param == 'ldap_type' or
set.param == 'ldap_port' or set.param == 'ldap_enable' or set.param == 'log_time_storage' or
set.param == 'syslog_server_enable' or set.param == 'smon_check_interval' or
set.param == 'checker_check_interval' or set.param == 'port_scan_interval' or
set.param == 'smon_keep_history_range' or set.param == 'checker_keep_history_range' or
set.param == 'portscanner_keep_history_range' or set.param == 'haproxy_enterprise' %}
{{ input(set.param, value=set.value, style='width: 210px;', type='number') }}
{% else %}
<input type="password" name="{{set.param}}" id="{{set.param}}" value="" placeholder="*****" title="" size="25" class="form-control" autocomplete="new-password">
{% endif %}
{% else %}
{% if set.value == 'None' %}
<input type="text" name="{{set.param}}" id="{{set.param}}" value="" title="" size="25" class="form-control">
{% else %}
<input type="text" name="{{set.param}}" id="{{set.param}}" value="{{set.value}}" title="" size="25" class="form-control">
{% endif %}
{% if set.value is none %}
{{ input(set.param, size='25') }}
{% else %}
{{ input(set.param, value=set.value, size='25') }}
{% endif %}
{% endif %}
</td>
<td class="addOption">

View File

@ -16,8 +16,8 @@
<td style="width: 5%;">WAF logs</td>
{% endif %}
<td>Number rows</td>
<td class="padding10 help_cursor"><span title="Find in log file(supports regular expressions)">Find<span></td>
<td class="padding10 help_cursor"><span title="Exclude from search in log file(supports regular expressions)">Exclude<span></td>
<td class="padding10 help_cursor"><span title="Find in a log file(supports regular expressions)">Find<span></td>
<td class="padding10 help_cursor"><span title="Exclude from search in a log file(supports regular expressions)">Exclude<span></td>
<td style="width: 10%;">
<label for="time_range_out_hour" style="padding: 0">Time range:</label>
{{ input('time_range_out_hour', value=hour, class='time-range', readonly='readonly') }}:{{ input('time_range_out_minut', value=minut, class='time-range', readonly='readonly') }}
@ -30,7 +30,7 @@
<form action="" method="post" id="show_log_form">
{% if select_id == 'viewlogs' %}
<select autofocus required name="serv" id="{{ select_id }}">
<option disabled selected>Choose log</option>
<option disabled selected>------</option>
{% for select in selects %}
{% if page == 'for_editor' %}
{% if select.1.startswith('roxy-wi') or select.1.startswith('config_edit') or select.1.startswith('port_sca') %}
@ -76,8 +76,7 @@
</td>
</tr>
</table>
<div id="ajax">
</div>
<div id="ajax"></div>
{% if select_id == 'viewlogs' and serv != '' and viewlogs != '' and viewlogs != 'roxy-wi.error.log' and viewlogs != 'roxy-wi.access.log' %}
<script>
viewLogs()
@ -88,15 +87,15 @@
}
</script>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
You can read the descriptions about all logs <a href="https://roxy-wi.org/description.py?description=logs" title="Servers description" target="_blank">here</a>
</div>
You can read the descriptions about all logs <a href="https://roxy-wi.org/description.py?description=logs" title="Servers description" target="_blank" class="link">here</a>
</div>
{% elif serv == 'roxy-wi.error.log' or serv == 'roxy-wi.access.log' %}
<script>
showApacheLog('{{serv}}');
</script>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
You can read the description about all logs file <a href="https://roxy-wi.org/description.py?description=logs" title="Servers description" target="_blank">here</a>
</div>
You can read the description about all logs file <a href="https://roxy-wi.org/description.py?description=logs" title="Servers description" target="_blank" class="link">here</a>
</div>
{% else %}
<script>
{% if waf == '1' %}

View File

@ -18,7 +18,7 @@ except Exception:
pass
if manage_rules == '1':
serv = form.getvalue('serv')
serv = funct.is_ip_or_dns(form.getvalue('serv'))
funct.check_is_server_in_group(serv)
title = "Manage rules - Web application firewall"
servers_waf = ''

View File

@ -265,7 +265,7 @@ $( function() {
$.ajax( {
url: "options.py",
data: {
ip: request.term,
show_ip: request.term,
serv: $("#serv").val(),
token: $('#token').val()
},

View File

@ -397,7 +397,7 @@ function showLog() {
$.ajax( {
url: "options.py",
data: {
rows: rows,
show_log: rows,
serv: $("#serv").val(),
waf: waf,
grep: grep,
@ -616,8 +616,11 @@ function viewLogs() {
},
type: "POST",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("View logs", "View logs", cur_url[0] + "?type="+ type +
if (data.indexOf('error: ') != '-1') {
toastr.error(data);
} else {
$("#ajax").html(data);
window.history.pushState("View logs", "View logs", cur_url[0] + "?type=" + type +
"&viewlogs=" + viewlogs +
'&rows=' + rows +
'&grep=' + grep +
@ -626,6 +629,7 @@ function viewLogs() {
'&minut=' + minut +
'&hour1=' + hour1 +
'&minut1=' + minut1);
}
}
} );
}