Pavel Loginov 2021-07-15 09:14:13 +06:00
parent a4407a1362
commit 5286856460
13 changed files with 396 additions and 319 deletions

View File

@ -1289,7 +1289,7 @@ def update_db_v_5_2_0(**kwargs):
def update_ver():
con, cur = get_cur()
sql = """update version set version = '5.2.1.0'; """
sql = """update version set version = '5.2.2.0'; """
try:
cur.execute(sql)
con.commit()

View File

@ -112,6 +112,19 @@ for s in servers:
servers_with_status.append(sql.is_master(s[2]))
servers_with_status.append(sql.select_servers(server=s[2]))
is_keepalived = sql.select_keealived(s[2])
if is_keepalived:
try:
cmd = ['sudo kill -USR1 `cat /var/run/keepalived.pid` && grep State /tmp/keepalived.data -m 1 |awk -F"=" \'{print $2}\'|tr -d \'[:space:]\' && sudo rm -f /tmp/keepalived.data' ]
out = funct.ssh_command(s[2], cmd)
out1 = ('1', out)
servers_with_status.append(out1)
except Exception:
servers_with_status.append('')
else:
servers_with_status.append('')
servers_with_status1.append(servers_with_status)
template = template.render(h2=1,

View File

@ -545,8 +545,8 @@ if act == "overview":
server_status = (serv1,
serv2,
haproxy,
haproxy_process,
sql.select_servers(server=serv2, keep_alive=1),
waf_process,
waf,
keepalived,

View File

@ -27,7 +27,10 @@ if action == 'add':
title = "SMON Admin"
autorefresh = 0
elif action == 'history':
smon = sql.alerts_history('SMON', user_group)
if form.getvalue('host'):
smon = sql.alerts_history('SMON', user_group, host=form.getvalue('host'))
else:
smon = sql.alerts_history('SMON', user_group)
title = "SMON History"
autorefresh = 0
elif action == 'checker_history':

View File

@ -1450,19 +1450,6 @@ def insert_metrics_http(serv, http_2xx, http_3xx, http_4xx, http_5xx):
con.close()
# def select_waf_metrics_enable(id):
# con, cur = get_cur()
# sql = """ select waf.metrics from waf left join servers as serv on waf.server_id = serv.id where server_id = '%s' """ % id
# try:
# cur.execute(sql)
# except sqltool.Error as e:
# funct.out_error(e)
# else:
# return cur.fetchall()
# cur.close()
# con.close()
def select_waf_metrics_enable_server(ip):
con, cur = get_cur()
sql = """ select waf.metrics from waf left join servers as serv on waf.server_id = serv.id where ip = '%s' """ % ip
@ -2168,9 +2155,9 @@ def select_roles(**kwargs):
def select_alert(**kwargs):
con, cur = get_cur()
sql = """select ip from servers where alert = 1 """
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' """ % kwargs.get("group")
sql = """select ip from servers where alert = 1 and `groups` = '%s' and enable = 1 """ % kwargs.get("group")
try:
cur.execute(sql)
except sqltool.Error as e:
@ -2183,9 +2170,9 @@ def select_alert(**kwargs):
def select_all_alerts(**kwargs):
con, cur = get_cur()
sql = """select ip from servers where alert = 1 or nginx_alert = 1 """
sql = """select ip from servers where alert = 1 or nginx_alert = 1 and enable = 1 """
if kwargs.get("group") is not None:
sql = """select ip from servers where (alert = 1 or nginx_alert = 1) and `groups` = '%s' """ % kwargs.get("group")
sql = """select ip from servers where (alert = 1 or nginx_alert = 1) and `groups` = '%s' and enable = 1 """ % kwargs.get("group")
try:
cur.execute(sql)
except sqltool.Error as e:
@ -2198,9 +2185,9 @@ def select_all_alerts(**kwargs):
def select_nginx_alert(**kwargs):
con, cur = get_cur()
sql = """select ip from servers where nginx_alert = 1 """
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' """ % kwargs.get("group")
sql = """select ip from servers where nginx_alert = 1 and `groups` = '%s' and enable = 1 """ % kwargs.get("group")
try:
cur.execute(sql)
except sqltool.Error as e:
@ -2268,7 +2255,7 @@ def update_keepalived(serv):
con.close()
def select_nginx(serv, **kwargs):
def select_nginx(serv):
con, cur = get_cur()
sql = """select nginx from `servers` where ip='%s' """ % serv
try:
@ -2298,6 +2285,20 @@ def update_nginx(serv):
con.close()
def select_haproxy(serv):
con, cur = get_cur()
sql = """select haproxy from `servers` where ip='%s' """ % serv
try:
cur.execute(sql)
except sqltool.Error as e:
funct.out_error(e)
else:
for value in cur.fetchone():
return value
cur.close()
con.close()
def update_haproxy(serv):
con, cur = get_cur()
sql = """update `servers` set `haproxy` = '1' where ip = '%s' """ % serv
@ -2330,11 +2331,11 @@ def update_firewall(serv):
con.close()
def update_server_pos(pos, id):
def update_server_pos(pos, server_id):
con, cur = get_cur()
sql = """ update servers set
pos = '%s'
where id = '%s'""" % (pos, id)
where id = '%s'""" % (pos, server_id)
try:
cur.execute(sql)
con.commit()
@ -2469,14 +2470,22 @@ def update_smon(id, ip, port, body, telegram, group, desc, en):
con.close()
def alerts_history(service, user_group):
def alerts_history(service, user_group, **kwargs):
con, cur = get_cur()
and_host = ''
if kwargs.get('host'):
and_host = "and ip = '{}'".format(kwargs.get('host'))
if user_group == 1:
sql_user_group = ""
else:
sql_user_group = "and user_group = '" + str(user_group) + "'"
sql = """ select message, level, ip, port, date from alerts
where service = '%s' %s order by date desc; """ % (service, sql_user_group)
sql_user_group = "and user_group = '{}'".format(user_group)
sql = (f"select message, level, ip, port, date "
f"from alerts "
f"where service = '{service}' {sql_user_group} {and_host} "
f"order by date desc; ")
try:
cur.execute(sql)
except sqltool.Error as e:

View File

@ -77,7 +77,7 @@
<li class="p_menu">
<a title="Actions with Nginx" class="nginx-menu">Nginx</a>
<ul class="v_menu">
<li><a href="/app/hapservers.py?service=nginx" title="Overview Nginx servers" class="overview-link head-submenu">Overview</a> </li>
<li><a href="/app/hapservers.py?service=nginx" title="Overview Nginx servers" class="overview-link head-submenu">Overview</a></li>
<li><a href="/app/config.py?service=nginx" title="Working with Nginx configs" class="edit head-submenu">Configs</a></li>
<li><a href="/app/viewsttats.py?service=nginx" title="Nginx statistics" class="stats head-submenu">Stats</a></li>
{% if role <= 3 %}
@ -90,6 +90,7 @@
<li class="p_menu">
<a title="Keepalived" class="ha">Keepalived</a>
<ul class="v_menu">
<li><a href="/app/hapservers.py?service=keepalived" title="Overview Keepalived servers" class="overview-link head-submenu">Overview</a> </li>
<li><a href="/app/ha.py" title="Create and configure HA cluster - Roxy-WI" class="keepalived head-submenu">HA</a></li>
<li><a href="/app/config.py?service=keepalived" title="Working with Keepalived configs" class="edit head-submenu">Configs</a></li>
<li><a href="/app/versions.py?service=keepalived" title="Working with versions Keepalived configs" class="version head-submenu keepalived_versions">Versions</a></li>

View File

@ -12,11 +12,12 @@
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
<td><span title="Interface for VRRP address">Interface(?)</span></td>
<td><span title="Interface for VRRP address">Interface</span></td>
<td>VRRP IP</td>
<td><span title="Roxy-WI will try to install HAProxy">HAProxy(?)</span></td>
<td><span title="Roxy-WI will try to install Nginx">Nginx(?)</span></td>
<td>SYN flood protect</td>
<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></td>
</tr>
<tr>
@ -36,11 +37,12 @@
{% endfor %}
</select>
</td>
<td>{{ input('interface', size='7') }}</td>
<td>{{ input('interface', size='7', title='Interface for VRRP address') }}</td>
<td>{{ input('vrrp-ip', size='14') }}</td>
<td>{{ checkbox('hap') }}</td>
<td>{{ checkbox('nginx') }}</td>
<td>{{ checkbox('syn_flood') }}</td>
<td class="checkbox help_cursor">{{ checkbox('hap', title='Roxy-WI will try to install HAProxy') }}</td>
<td class="checkbox help_cursor">{{ checkbox('nginx', title='Roxy-WI will try to install Nginx') }}</td>
<td class="checkbox help_cursor">{{ checkbox('virt_server', title='Roxy-WI will add VRRP address as a separated server', checked='checked') }}</td>
<td class="checkbox">{{ checkbox('syn_flood') }}</td>
<td>
<button id="create" title="Create HA configuration">Create</button>
</td>
@ -52,12 +54,14 @@
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
<td><span title="Interface for VRRP address">Interface(?)</span></td>
<td><span title="Interface for VRRP address">Interface</span></td>
<td>VRRP IP</td>
<td><span title="If checked Roxy-WI will restart Keepalived">Restart(?)</span></td>
<td class="checkbox-head"><span title="If checked Roxy-WI will restart Keepalived">Restart</span></td>
<td style="width: 23%;"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="padding10 first-collumn">
@ -76,9 +80,11 @@
{% endfor %}
</select>
</td>
<td>{{ input('interface-add', size='7') }}</td>
<td>{{ input('interface-add', size='7', title='Interface for VRRP address') }}</td>
<td>{{ input('vrrp-ip-add', size='14') }}</td>
<td>{{ checkbox('kp') }}</td>
<td class="checkbox">{{ checkbox('kp', title='If checked Roxy-WI will restart Keepalived') }}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
@ -87,7 +93,7 @@
</tr>
</table>
<div id="ajax"></div>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
<div class="add-note alert addName alert-info" style="width: inherit; margin-right: 15px;">
Read <a href="https://haproxy-wi.org/howto.py?howto=ha_cluster" title="How to create high available cluster" target="_blank">How to create high available cluster</a>
</div>
<div id="server_creating" style="display: none;">

View File

@ -224,6 +224,15 @@
{% if s.7.0.0 != None %}
Master for: <b>{{ s.7.0.1 }}</b>
{% endif %}
{% if s.9.0 == '1' %}
VRRP status: <b>
{% if s.9.1 == 'MASTER' or s.9.1 == 'BACKUP' or s.9.1 == 'INIT' or s.9.1 == 'FAULT' %}
{{s.9.1}}
{% else %}
<span title="Cannot get Keepalived Status" class="help_cursor">Error</span>
{% endif %}
</b>
{% endif %}
</div>
<div class="server-act-links" id="server-{{s.8.0.0|string()}}-{{service}}">
{% if role <= 2 and service != 'keepalived' %}

View File

@ -1,56 +1,57 @@
{% extends "base.html" %}
{% block content %}
{% from 'include/input_macros.html' import input, checkbox, select %}
<script src="/inc/smon.js"></script>
<script src="/inc/users.js"></script>
<script src="/inc/fontawesome.min.js"></script>
<script src="/inc/jquery.timeago.js" type="text/javascript"></script>
{% if smon_error != '' %}
<center>
<div style="text-align: center;">
<br />
<h3>You do not have installed SMON service. Read <a href="https://haproxy-wi.org/services.py?service=smon"
title="Simple monitoring network ports with alerting via Telegram and WEB pannel" target="_blank">here</a> how to install SMON service</h3>
</center>
title="Simple monitoring network ports with alerting via Telegram and WEB panel" target="_blank">here</a> how to install SMON service</h3>
</div>
{% elif smon_status.0 == 'failed' %}
<center>
<div style="text-align: center;">
<br />
<h3>SMON service is not run. Run the SMON service <a href="users.py#services" title="Roxy-WI services" target="_blank">here</a> before use</h3>
</center>
</div>
{% elif smon|length == 0 and action != 'add' and action != 'history' and action != 'checker_history' %}
<center>
<div style="text-align: center;">
<br />
<h3>You do not have added servers in SMON service. Create you first server <a href="smon.py?action=add" title="Roxy-WI SMON" target="_blank">here</a> before use</h3>
<br />
<iframe width="860" height="515" src="https://www.youtube.com/embed/bJtRJeHG5B0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</center>
</div>
{% elif smon|length == 0 and action != 'add' and action == 'history' %}
<center>
<div style="text-align: center;">
<br />
<h3>There are not any events yet. Check if there are any checks added <a href="smon.py?action=add" title="Roxy-WI SMON" target="_blank">here</a></h3>
<br />
</center>
</div>
{% elif smon|length == 0 and action != 'add' and action == 'checker_history' %}
<center>
<div style="text-align: center;">
<br />
<h3>
There are not any events yet. Check if there are any Checker are enabled on the "<a href="hapservers.py" title="HAProxy Overview">HAProxy Overview</a>"
or on "<a href="hapservers.py?service=nginx" title="Nginx Overview">Nginx Overview</a>" pages
</h3>
<br />
</center>
</div>
{% else %}
{% if action == 'add' %}
<table class="overview" id="ajax-smon">
<thead>
<tr class="overviewHead">
<th class="padding10 first-collumn" style="width: 150px;">IP</th>
<th style="width: 10px;">Port</th>
<th style="width: 80px;">Enabled</th>
<th style="width: 80px;">Protocol</th>
<th>URI</th>
<th>Body</th>
<th style="width: 190px;">Telegram</th>
<th>Group</th>
<th>Description</th>
<th style="width: 2%;">Port</th>
<th style="width: 5%;">Enabled</th>
<th style="width: 10%;">Protocol</th>
<th style="width: 15%;">URI</th>
<th style="width: 20%;">Body</th>
<th style="width: 15%;">Telegram</th>
<th style="width: 10%;">Group</th>
<th style="width: 100%;">Description</th>
<!--<th></th>-->
<th></th>
</tr>
@ -71,13 +72,7 @@
</div>
<div id="smon-add-table" style="display: none;">
<table class="overview">
<tr>
<td colspan="2">
<p class="validateTips alert alert-success">
Form fields tag "<span class="need-field">*</span>" are required.
</p>
</td>
</tr>
{% include 'include/tr_validate_tips.html' %}
<tr>
<td class="padding20">
IP
@ -97,17 +92,13 @@
</td>
</tr>
<tr>
<td class="padding20">
Enable
</td>
<td class="padding20">Enable</td>
<td>
{{ checkbox('new-smon-enable', checked='checked') }}
</td>
</tr>
<tr>
<td class="padding20">
Protocol
</td>
<td class="padding20">Protocol</td>
<td>
{% set values = dict() %}
{% set values = {'':'', 'http':'http','https':'https'} %}
@ -115,25 +106,15 @@
</td>
</tr>
<tr>
<td class="padding20">
URI
</td>
<td>
{{ input('new-smon-uri') }}
</td>
<td class="padding20">URI</td>
<td>{{ input('new-smon-uri') }}</td>
</tr>
<tr>
<td class="padding20">
Body
</td>
<td>
{{ input('new-smon-body') }}
</td>
<td class="padding20">Body</td>
<td>{{ input('new-smon-body') }}</td>
</tr>
<tr>
<td class="padding20">
Telegram
</td>
<td class="padding20">Telegram</td>
<td>
<select id="new-smon-telegram">
<option value="0">Disabled</option>
@ -144,20 +125,12 @@
</td>
</tr>
<tr>
<td class="padding20">
Group
</td>
<td>
{{ input('new-smon-group') }}
</td>
<td class="padding20">Group</td>
<td>{{ input('new-smon-group') }}</td>
</tr>
<tr>
<td class="padding20">
Description
</td>
<td>
{{ input('new-smon-description') }}
</td>
<td class="padding20">Description</td>
<td>{{ input('new-smon-description') }}</td>
</tr>
</table>
{% include 'include/del_confirm.html' %}

View File

@ -49,7 +49,6 @@ $( function() {
add_master_addr(kp);
$.getScript("/inc/fontawesome.min.js");
add_slave_addr(kp);
}
});
$('#create').click(function() {
@ -144,6 +143,10 @@ function create_master_keepalived(hap, nginx, syn_flood) {
} else if (hap == '1' && nginx == '1') {
var progress_value = '50';
}
var virt_server = 0;
if ($('#virt_server').is(':checked')) {
virt_server = '1';
}
$.ajax( {
url: "options.py",
data: {
@ -154,6 +157,7 @@ function create_master_keepalived(hap, nginx, syn_flood) {
hap: hap,
nginx: nginx,
syn_flood: syn_flood,
virt_server: virt_server,
token: $('#token').val()
},
type: "POST",

View File

@ -76,6 +76,15 @@ $( function() {
$(this).parent().find('a').css('padding-left', '20px');
$(this).find('a').css('padding-left', '30px');
$(this).find('a').css('border-left', '4px solid #5D9CEB');
} else if(cur_url[0] == 'hapservers.py' && cur_url[1].split('&')[0] == 'service=keepalived' && link2 == 'hapservers.py?service=keepalived'){
$(this).parent().css('display', 'contents');
$(this).parent().css('font-size', '13px');
$(this).parent().css('top', '0');
$(this).parent().css('left', '0');
$(this).parent().children().css('margin-left', '-20px');
$(this).parent().find('a').css('padding-left', '20px');
$(this).find('a').css('padding-left', '30px');
$(this).find('a').css('border-left', '4px solid #5D9CEB');
} else if(cur_url[0] == 'viewsttats.py' && cur_url[1].split('&')[0] == 'service=nginx' && link2 == 'viewsttats.py?service=nginx'){
$(this).parent().css('display', 'contents');
$(this).parent().css('font-size', '13px');
@ -1185,54 +1194,6 @@ function changeCurrentGroupF(){
} );
}
function sort_by_status() {
$('<div id="err_services" style="clear: both;"></div>').appendTo('.main');
$('<div id="good_services" style="clear: both;"></div>').appendTo('.main');
$('<div id="dis_services" style="clear: both;"></div>').appendTo('.main');
$(".good").prependTo("#good_services");
$(".err").prependTo("#err_services");
$(".dis").prependTo("#dis_services");
$('.group').remove();
$('.group_name').detach();
window.history.pushState("SMON Dashboard", "SMON Dashboard", cur_url[0]+"?action=view&sort=by_status");
}
function showSmon(action) {
var sort = '';
var location = window.location.href;
var cur_url = '/app/' + location.split('/').pop();
cur_url = cur_url.split('?');
cur_url[1] = cur_url[1].split('#')[0];
if (action == 'refresh') {
try {
sort = cur_url[1].split('&')[1];
sort = sort.split('=')[1];
} catch (e) {
sort = '';
}
}
$.ajax( {
url: "options.py",
data: {
showsmon: 1,
sort: sort,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
if (data.indexOf('SMON error:') != '-1') {
toastr.error(data);
} else {
toastr.clear();
$("#smon_dashboard").html(data);
if (action == 'not_sort') {
window.history.pushState("SMON Dashboard", document.title, "smon.py?action=view");
} else {
window.history.pushState("SMON Dashboard", document.title, cur_url[0] + "?" + cur_url[1]);
}
}
}
} );
}
function updateTips( t ) {
var tips = $( ".validateTips" );
tips.text( t ).addClass( "alert-warning" );

234
inc/smon.js Normal file
View File

@ -0,0 +1,234 @@
function sort_by_status() {
$('<div id="err_services" style="clear: both;"></div>').appendTo('.main');
$('<div id="good_services" style="clear: both;"></div>').appendTo('.main');
$('<div id="dis_services" style="clear: both;"></div>').appendTo('.main');
$(".good").prependTo("#good_services");
$(".err").prependTo("#err_services");
$(".dis").prependTo("#dis_services");
$('.group').remove();
$('.group_name').detach();
window.history.pushState("SMON Dashboard", "SMON Dashboard", cur_url[0]+"?action=view&sort=by_status");
}
function showSmon(action) {
var sort = '';
var location = window.location.href;
var cur_url = '/app/' + location.split('/').pop();
cur_url = cur_url.split('?');
cur_url[1] = cur_url[1].split('#')[0];
if (action == 'refresh') {
try {
sort = cur_url[1].split('&')[1];
sort = sort.split('=')[1];
} catch (e) {
sort = '';
}
}
$.ajax( {
url: "options.py",
data: {
showsmon: 1,
sort: sort,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
if (data.indexOf('SMON error:') != '-1') {
toastr.error(data);
} else {
toastr.clear();
$("#smon_dashboard").html(data);
if (action == 'not_sort') {
window.history.pushState("SMON Dashboard", document.title, "smon.py?action=view");
} else {
window.history.pushState("SMON Dashboard", document.title, cur_url[0] + "?" + cur_url[1]);
}
}
}
} );
}
function addNewSmonServer(dialog_id) {
var valid = true;
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
if ($('#new-smon-proto').val() != '' || $('#new-smon-uri').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
}
if( $('#new-smon-body').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
valid = valid && checkLength( $('#new-smon-body'), "Body", 1 );
}
var enable = 0;
if ($('#new-smon-enable').is(':checked')) {
enable = '1';
}
if (valid) {
$.ajax( {
url: "options.py",
data: {
newsmon: $('#new-smon-ip').val(),
newsmonport: $('#new-smon-port').val(),
newsmonenable: enable,
newsmonproto: $('#new-smon-proto').val(),
newsmonuri: $('#new-smon-uri').val(),
newsmonbody: $('#new-smon-body').val(),
newsmongroup: $('#new-smon-group').val(),
newsmondescription: $('#new-smon-description').val(),
newsmontelegram: $('#new-smon-telegram').val(),
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
toastr.error(data);
} else {
common_ajax_action_after_success(dialog_id, 'newserver', 'ajax-smon', data);
$( "input[type=submit], button" ).button();
$( "input[type=checkbox]" ).checkboxradio();
$( "select" ).selectmenu();
$.getScript('/inc/users.js');
}
}
} );
}
}
function confirmDeleteSmon(id) {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
title: "Are you sure you want to delete server " +$('#smon-ip-'+id).val() + "?",
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
removeSmon(id);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
function removeSmon(id) {
$("#smon-"+id).css("background-color", "#f2dede");
$.ajax( {
url: "options.py",
data: {
smondel: id,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if(data == "Ok ") {
$("#smon-"+id).remove();
} else {
toastr.error(data);
}
}
} );
}
function updateSmon(id) {
toastr.clear();
var enable = 0;
if ($('#smon-enable-'+id).is(':checked')) {
enable = '1';
}
$.ajax( {
url: "options.py",
data: {
updateSmonIp: $('#smon-ip-'+id).val(),
updateSmonPort: $('#smon-port-'+id).val(),
updateSmonEn: enable,
updateSmonHttp: $('#smon-proto1-'+id).text(),
updateSmonBody: $('#smon-body-'+id).text(),
updateSmonTelegram: $('#smon-telegram-'+id).val(),
updateSmonGroup: $('#smon-group-'+id).val(),
updateSmonDesc: $('#smon-desc-'+id).val(),
id: id,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
toastr.error(data);
} else {
toastr.clear();
$("#smon-"+id).addClass( "update", 1000 );
setTimeout(function() {
$( "#smon-"+id ).removeClass( "update" );
}, 2500 );
}
}
} );
}
function cloneSmom(id) {
$( "#add-smon-button" ).trigger( "click" );
if ($('#smon-enable-'+id).is(':checked')) {
$('#new-smon-enable').prop('checked', true)
} else {
$('#new-smon-enable').prop('checked', false)
}
$('#new-smon-enable').checkboxradio("refresh");
$('#new-smon-ip').val($('#smon-ip-'+id).val());
$('#new-smon-port').val($('#smon-port-'+id).val());
$('#new-smon-group').val($('#smon-group-'+id).val());
$('#new-smon-description').val($('#smon-desc-'+id).val())
$('#new-smon-telegram').val($('#smon-telegram-'+id+' option:selected').val()).change()
$('#new-smon-telegram').selectmenu("refresh");
}
$( function() {
$('#add-smon-button').click(function() {
addSmonServer.dialog('open');
});
$( "#ajax-smon input" ).change(function() {
var id = $(this).attr('id').split('-');
updateSmon(id[2])
});
$( "#ajax-smon select" ).on('selectmenuchange',function() {
var id = $(this).attr('id').split('-');
updateSmon(id[2])
});
var addSmonServer = $( "#smon-add-table" ).dialog({
autoOpen: false,
resizable: false,
height: "auto",
width: 600,
modal: true,
title: "Create a new server for monitoring",
show: {
effect: "fade",
duration: 200
},
hide: {
effect: "fade",
duration: 200
},
buttons: {
"Add": function () {
addNewSmonServer(this);
},
Cancel: function () {
$(this).dialog("close");
clearTips();
}
}
});
});

View File

@ -563,34 +563,6 @@ $( function() {
}
}
});
$('#add-smon-button').click(function() {
addSmonServer.dialog('open');
});
var addSmonServer = $( "#smon-add-table" ).dialog({
autoOpen: false,
resizable: false,
height: "auto",
width: 600,
modal: true,
title: "Create a new server for monitoring",
show: {
effect: "fade",
duration: 200
},
hide: {
effect: "fade",
duration: 200
},
buttons: {
"Add": function () {
addNewSmonServer(this);
},
Cancel: function () {
$(this).dialog("close");
clearTips();
}
}
});
$( "#ajax-users input" ).change(function() {
var id = $(this).attr('id').split('-');
updateUser(id[1])
@ -626,14 +598,6 @@ $( function() {
var val = $(this).val();
updateSettings(id, val);
});
$( "#ajax-smon input" ).change(function() {
var id = $(this).attr('id').split('-');
updateSmon(id[2])
});
$( "#ajax-smon select" ).on('selectmenuchange',function() {
var id = $(this).attr('id').split('-');
updateSmon(id[2])
});
$('#new-ssh_enable').click(function() {
if ($('#new-ssh_enable').is(':checked')) {
$('#ssh_pass').css('display', 'none');
@ -789,7 +753,39 @@ $( function() {
loadopenvpn();
}
});
$('#nginx-section-head').click(function () {
hideAndShowSettings('nginx');
});
$('#main-section-head').click(function () {
hideAndShowSettings('main');
});
$('#monitoring-section-head').click(function () {
hideAndShowSettings('monitoring');
});
$('#haproxy-section-head').click(function () {
hideAndShowSettings('haproxy');
});
$('#ldap-section-head').click(function () {
hideAndShowSettings('ldap');
});
$('#logs-section-head').click(function () {
hideAndShowSettings('logs');
});
} );
function hideAndShowSettings(section) {
var ElemId = $('#' + section + '-section-h3');
if(ElemId.attr('class') == 'plus-after') {
$('.' + section + '-section').show();
ElemId.removeClass('plus-after');
ElemId.addClass('minus-after');
$.getScript(awesome);
} else {
$('.' + section + '-section').hide();
ElemId.removeClass('minus-after');
ElemId.addClass('plus-after');
$.getScript(awesome);
}
}
window.onload = function() {
var activeTabIdx = $('#tabs').tabs('option','active')
if (cur_url[0].split('#')[0] == 'users.py') {
@ -819,66 +815,6 @@ function common_ajax_action_after_success(dialog_id, new_group, ajax_append_id,
$( "."+new_group ).removeClass( "update" );
}, 2500 );
}
function addNewSmonServer(dialog_id) {
var valid = true;
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
if ($('#new-smon-proto').val() != '' || $('#new-smon-uri').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
}
if( $('#new-smon-body').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
valid = valid && checkLength( $('#new-smon-body'), "Body", 1 );
}
var enable = 0;
if ($('#new-smon-enable').is(':checked')) {
enable = '1';
}
if (valid) {
$.ajax( {
url: "options.py",
data: {
newsmon: $('#new-smon-ip').val(),
newsmonport: $('#new-smon-port').val(),
newsmonenable: enable,
newsmonproto: $('#new-smon-proto').val(),
newsmonuri: $('#new-smon-uri').val(),
newsmonbody: $('#new-smon-body').val(),
newsmongroup: $('#new-smon-group').val(),
newsmondescription: $('#new-smon-description').val(),
newsmontelegram: $('#new-smon-telegram').val(),
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
toastr.error(data);
} else {
common_ajax_action_after_success(dialog_id, 'newserver', 'ajax-smon', data);
$( "input[type=submit], button" ).button();
$( "input[type=checkbox]" ).checkboxradio();
$( "select" ).selectmenu();
$.getScript('/inc/users.js');
}
}
} );
}
}
function addUser(dialog_id) {
var valid = true;
toastr.clear();
@ -1365,24 +1301,6 @@ function confirmDeleteBackup(id) {
}
});
}
function confirmDeleteSmon(id) {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
title: "Are you sure you want to delete server " +$('#smon-ip-'+id).val() + "?",
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
removeSmon(id);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
function cloneServer(id) {
$( "#add-server-button" ).trigger( "click" );
if ($('#enable-'+id).is(':checked')) {
@ -1603,25 +1521,6 @@ function removeBackup(id) {
}
} );
}
function removeSmon(id) {
$("#smon-"+id).css("background-color", "#f2dede");
$.ajax( {
url: "options.py",
data: {
smondel: id,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if(data == "Ok ") {
$("#smon-"+id).remove();
} else {
toastr.error(data);
}
}
} );
}
function updateUser(id) {
toastr.remove();
cur_url[0] = cur_url[0].split('#')[0]
@ -1900,41 +1799,6 @@ function updateBackup(id) {
} );
}
}
function updateSmon(id) {
toastr.clear();
var enable = 0;
if ($('#smon-enable-'+id).is(':checked')) {
enable = '1';
}
$.ajax( {
url: "options.py",
data: {
updateSmonIp: $('#smon-ip-'+id).val(),
updateSmonPort: $('#smon-port-'+id).val(),
updateSmonEn: enable,
updateSmonHttp: $('#smon-proto1-'+id).text(),
updateSmonBody: $('#smon-body-'+id).text(),
updateSmonTelegram: $('#smon-telegram-'+id).val(),
updateSmonGroup: $('#smon-group-'+id).val(),
updateSmonDesc: $('#smon-desc-'+id).val(),
id: id,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
toastr.error(data);
} else {
toastr.clear();
$("#smon-"+id).addClass( "update", 1000 );
setTimeout(function() {
$( "#smon-"+id ).removeClass( "update" );
}, 2500 );
}
}
} );
}
function showApacheLog(serv) {
var rows = $('#rows').val()
var grep = $('#grep').val()