Browse Source

v3.10.0.0

pull/197/head
Pavel Loginov 5 years ago
parent
commit
859bf81ed9
  1. 7
      README.md
  2. 2
      app/create_db.py
  3. 20
      app/funct.py
  4. 19
      app/hapservers.py
  5. 48
      app/options.py
  6. 2
      app/overview.py
  7. 14
      app/templates/ajax/haproxyservers_backends.html
  8. 48
      app/templates/ajax/overview.html
  9. 46
      app/templates/hapservers.html
  10. 15
      app/templates/ovw.html
  11. 115
      inc/overview.js
  12. 68
      inc/script.js
  13. 12
      inc/style.css
  14. 2
      requirements.txt

7
README.md

@ -64,6 +64,8 @@ Supports EL7 and EL8
#### Before uses RPM repository you should donate to support project on [Patreon](https://www.patreon.com/haproxy_wi/overview) or on [PayPal](https://www.paypal.me/loginovpavel) and I will send you credentials for access. Actual prices you can see on [Patreon](https://www.patreon.com/haproxy_wi/overview)
### More information on the official [site](https://haproxy-wi.org/installation.py#rpm)
## Manual install
For install just clone:
```
@ -178,6 +180,8 @@ For Apache do virtualhost with cgi-bin. Like this:
</VirtualHost>
```
### More information on the official [site](https://haproxy-wi.org/installation.py#manual)
# OS support
HAProxy-WI was tested on EL7, EL8 and all scripts too. Debian/Ubuntu OS support at 'beta' stage, may work not correct
@ -192,6 +196,9 @@ MariaDB [(none)]> create database haproxywi;
MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'%' IDENTIFIED BY 'haproxy-wi';
MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIED BY 'haproxy-wi';
```
### More information on the official [site](https://haproxy-wi.org/settings.py#db_settings)
![alt text](image/haproxy-wi-overview.png "Overview page")
# Settings

2
app/create_db.py

@ -459,7 +459,7 @@ def update_db_v_3_8_1(**kwargs):
def update_ver(**kwargs):
con, cur = get_cur()
sql = """update version set version = '3.9.4'; """
sql = """update version set version = '3.10.0.0'; """
try:
cur.execute(sql)
con.commit()

20
app/funct.py

@ -99,7 +99,7 @@ def telegram_send_mess(mess, **kwargs):
token_bot = telegram[1]
channel_name = telegram[2]
if proxy is not None:
if proxy is not None and proxy != '' and proxy != 'None':
apihelper.proxy = {'https': proxy}
try:
bot = telebot.TeleBot(token=token_bot)
@ -359,8 +359,12 @@ def install_haproxy(serv, **kwargs):
if hapver is None:
hapver = '2.0.7-1'
if proxy is not None and proxy != '' and proxy != 'None':
proxy_serv = proxy
else:
proxy_serv = ''
proxy_serv = proxy if proxy is not None else ''
syn_flood_protect = '1' if kwargs.get('syn_flood') == "1" else ''
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+
@ -400,7 +404,12 @@ def waf_install(serv, **kwargs):
os.system("cp scripts/%s ." % script)
commands = [ "sudo chmod +x "+tmp_config_path+script+" && " +tmp_config_path+script +" PROXY=" + proxy+
if proxy is not None and proxy != '' and proxy != 'None':
proxy_serv = proxy
else:
proxy_serv = ''
commands = [ "sudo chmod +x "+tmp_config_path+script+" && " +tmp_config_path+script +" PROXY=" + proxy_serv+
" HAPROXY_PATH="+haproxy_dir +" VERSION="+ver ]
error = str(upload(serv, tmp_config_path, script))
@ -651,8 +660,8 @@ def ssh_command(serv, commands, **kwargs):
try:
ssh.close()
except:
print("<div class='alert alert-danger' style='margin: 0;'>"+str(ssh)+"<a title='Close' id='errorMess'><b>X</b></a></div>")
logging('localhost', ' '+str(ssh), haproxywi=1)
return "<div class='alert alert-danger' style='margin: 0;'>"+str(ssh)+"<a title='Close' id='errorMess'><b>X</b></a></div>"
pass
@ -731,13 +740,12 @@ def check_ver():
def check_new_version():
import requests
import ssl
import sql
proxy = sql.get_setting('proxy')
try:
if proxy:
if proxy is not None and proxy != '' and proxy != 'None':
proxyDict = { "https" : proxy, "http" : proxy }
response = requests.get('https://haproxy-wi.org/update.py?last_ver=1', timeout=1, proxies=proxyDict)
else:

19
app/hapservers.py

@ -27,14 +27,11 @@ serv = form.getvalue('serv')
if serv:
servers = sql.select_servers(server=serv)
autorefresh = 1
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
else:
servers = sql.get_dick_permit()
autorefresh = 0
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
haproxy_config_path = sql.get_setting('haproxy_config_path')
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
servers_with_status1 = []
out1 = ""
for s in servers:
@ -52,22 +49,6 @@ for s in servers:
out1 = False
servers_with_status.append(out1)
servers_with_status.append(s[12])
try:
servers_with_status.append(funct.ssh_command(s[2], commands))
except:
servers_with_status.append('Cannot get last date')
if serv:
try:
sections = funct.get_sections(hap_configs_dir +funct.get_files()[0])
except:
try:
cfg = hap_configs_dir + s[2] + "-" + funct.get_data('config') + ".cfg"
error = funct.get_config(s[2], cfg)
sections = funct.get_sections(cfg)
except:
pass
servers_with_status.append(sections)
servers_with_status1.append(servers_with_status)

48
app/options.py

@ -146,6 +146,42 @@ if form.getvalue('action_waf') is not None and serv is not None:
funct.ssh_command(serv, commands)
if act == "overviewHapserverBackends":
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'))
template = env.get_template('haproxyservers_backends.html')
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
try:
sections = funct.get_sections(hap_configs_dir +funct.get_files()[0])
except:
try:
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
except:
funct.logging('localhost', ' Cannot generate cfg path', haproxywi=1)
try:
error = funct.get_config(serv, cfg)
except:
funct.logging('localhost', ' Cannot download config', haproxywi=1)
try:
sections = funct.get_sections(cfg)
except:
funct.logging('localhost', ' Cannot get sections from config file', haproxywi=1)
sections = 'Cannot get backends'
template = template.render(backends=sections, serv=serv)
print(template)
if act == "overviewHapservers":
haproxy_config_path = sql.get_setting('haproxy_config_path')
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
try:
print(funct.ssh_command(serv, commands))
except:
print('Cannot get last date')
if act == "overview":
import asyncio
async def async_get_overview(serv1, serv2):
@ -170,7 +206,7 @@ if act == "overview":
template = env.get_template('overview.html')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
futures = [async_get_overview(server[1], server[2]) for server in sql.get_dick_permit()]
futures = [async_get_overview(server[1], server[2]) for server in sql.select_servers(server=serv)]
for i, future in enumerate(asyncio.as_completed(futures)):
result = await future
servers.append(result)
@ -587,7 +623,10 @@ if form.getvalue('master'):
if ssh_enable == 0:
ssh_key_name = ''
proxy_serv = proxy if proxy is not None else ""
if proxy is not None and proxy != '' and proxy != 'None':
proxy_serv = proxy
else:
proxy_serv = ''
os.system("cp scripts/%s ." % script)
@ -663,7 +702,10 @@ if form.getvalue('masteradd'):
if ssh_enable == 0:
ssh_key_name = ''
proxy_serv = proxy if proxy is not None else ""
if proxy is not None and proxy != '' and proxy != 'None':
proxy_serv = proxy
else:
proxy_serv = ''
os.system("cp scripts/%s ." % script)

2
app/overview.py

@ -33,6 +33,7 @@ try:
keep_alive, stderr = funct.subprocess_execute(cmd)
cmd = "ps ax |grep '(wsgi:api)'|grep -v grep|wc -l"
api, stderr = funct.subprocess_execute(cmd)
servers = sql.get_dick_permit()
except:
pass
@ -55,5 +56,6 @@ template = template.render(h2 = 1,
error = stderr,
versions = funct.versions(),
haproxy_wi_log = funct.haproxy_wi_log(),
servers = servers,
token = token)
print(template)

14
app/templates/ajax/haproxyservers_backends.html

@ -0,0 +1,14 @@
<style>
.div-backends {
height: auto !important;
}
</style>
{% if backends == 'Cannot get backends' %}
{{backends}}
{% else %}
{% for b in backends %}
<a href="/app/sections.py?serv={{ serv}}&section={{b}}" title="Edit backend {{b}}" target="_blank" style="padding-right: 10px;">
{{b}}
</a>
{% endfor %}
{% endif %}

48
app/templates/ajax/overview.html

@ -1,26 +1,24 @@
{% for service in service_status %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td class="padding10 first-collumn">
<a href="/app/hapservers.py?serv={{ service.1 }}" title="{{service.0 }}'s overview" class="logs_link">
{{ service.0 }}
</a>
</td>
<td>
{% if service.2|int() >= 1 %}
<span class="serverUp server-status" title="running {{service.2 }} processes" style="margin-left: 25px !important;"></span>
{% else %}
<span class="serverDown server-status" style="margin-left: 25px !important;"></span>
{% endif %}
</td>
<td class="third-collumn-wi">
{% if service.5.0|length() == 0 %}
<span class="serverNone server-status" title="WAF is not installed" style="margin-left: 4px !important;"></span>
{% elif service.5.0 != '' and service.4|int() == 0 %}
<span class="serverDown server-status" title="WAF down" style="margin-left: 4px !important;"></span>
{% elif service.5.0 != '' and service.4|int() >= 1 %}
<span class="serverUp server-status" title="running {{service.4 }} processes" style="margin-left: 4px !important;"></span>
{% endif %}
</td>
<td></td>
</tr>
{% for service in service_status %}
<td class="padding10 first-collumn">
<a href="/app/hapservers.py?serv={{ service.1 }}" title="{{service.0 }}'s overview" class="logs_link">
{{ service.0 }}
</a>
</td>
<td>
{% if service.2|int() >= 1 %}
<span class="serverUp server-status" title="running {{service.2 }} processes" style="margin-left: 25px !important;"></span>
{% else %}
<span class="serverDown server-status" style="margin-left: 25px !important;"></span>
{% endif %}
</td>
<td class="third-collumn-wi">
{% if service.5.0|length() == 0 %}
<span class="serverNone server-status" title="WAF is not installed" style="margin-left: 4px !important;"></span>
{% elif service.5.0 != '' and service.4|int() == 0 %}
<span class="serverDown server-status" title="WAF down" style="margin-left: 4px !important;"></span>
{% elif service.5.0 != '' and service.4|int() >= 1 %}
<span class="serverUp server-status" title="running {{service.4 }} processes" style="margin-left: 4px !important;"></span>
{% endif %}
</td>
<td></td>
{% endfor %}

46
app/templates/hapservers.html

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% block content %}
<script src="/inc/overview.js"></script>
{% if serv %}
<style>
@media (max-width: 1280px) {
@ -9,8 +10,23 @@
}
</style>
{% endif %}
<style>
.alert-danger {
width: 250px;
padding: 5px;
margin-bottom: -20px !important;
}
</style>
<div id="up-pannel">
{% for s in servers %}
<script>
var ip = []
var hostnamea = []
{% for s in servers %}
ip.push("{{s[2]}}")
hostnamea.push("{{s[1]}}")
{% endfor %}
</script>
{% if serv %}
<link href="/inc/chart.min.css" rel="stylesheet">
<script src="/inc/metrics.js"></script>
@ -69,16 +85,9 @@
{{s.5.0.0}} {{s.5.0.1}} {{s.5.0.2}}
{% endif %}
<br />
<span title="Date of last edit config">
{% if s.7 != None %}
{% if "ls: cannot access" in s.7 %}
Cannot find HAProxy config
{% else %}
Last edit: {{s.7}}
{% endif %}
{% else %}
Cannot connect to HAProxy server
{% endif %}
<span title="Date of last edit config" >
Last edit:
<span id="{{s.1}}"></span>
</span>
<br />
IP: {{s.2}}
@ -97,20 +106,12 @@
<div id="ajax-server-{{s.0}}" class="ajax-server"></div>
{% if serv %}
{% if s.8 is defined %}
<div class="div-server div-backends">
<div class="server-name">
Backends:
</div>
<div style="margin-top: 10px;">
{% for b in s.8 %}
<a href="/app/sections.py?serv={{ s.2 }}&section={{b}}" title="Edit backend {{b}}" target="_blank" style="padding-right: 10px;">
{{b}}
</a>
{% endfor %}
</div>
<div style="margin-top: 10px;" id="top-{{s.1}}"></div>
</div>
{% endif %}
{% endif %}
</div>
{% endfor %}
@ -131,5 +132,10 @@
<div id="dialog-confirm" style="display: none;">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:3px 12px 20px 0;"></span>Are you sure?</p>
</div>
<script src="/inc/overview.js"></script>
<script>
{% if serv %}
overviewHapserverBackends(ip, hostnamea);
{% endif %}
showHapservers(ip, hostnamea);
</script>
{% endblock %}

15
app/templates/ovw.html

@ -1,7 +1,14 @@
{% extends "base.html" %}
{% block content %}
<script src="/inc/overview.js"></script>
<script>
$("#secIntervals").css("display", "none");
var ip = []
var hostnamea = []
{% for s in servers %}
ip.push("{{s[2]}}")
hostnamea.push("{{s[1]}}")
{% endfor %}
</script>
<table class="overview-wi">
<tr class="overviewHead">
@ -19,10 +26,12 @@
</a>
</td class="padding10">
<td>
<a onclick="showOverview()" title="Refresh" style="float: right; margin-right: 25px;"><img src="/inc/images/update.png" alt="restart" class="icon"></a>
<a onclick="showOverview(ip, hostnamea)" title="Refresh" style="float: right; margin-right: 25px;"><img src="/inc/images/update.png" alt="hostname" class="icon"></a>
</td>
</tr>
<tbody id="ajaxstatus"></tbody>
{% for s in servers %}
<tr class="{{ loop.cycle('odd', 'even') }}" id="{{s[1]}}"></tr>
{% endfor %}
</table>
<table class="overview-wi" style="height: 170;">
<tr class="overviewHead" style="height: 40px;">
@ -283,7 +292,7 @@
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:3px 12px 20px 0;"></span>Are you sure?</p>
</div>
<script>
window.onload = showOverview()
showOverview(ip, hostnamea)
</script>
{% endblock %}

115
inc/overview.js

@ -1,5 +1,118 @@
var cur_url = window.location.href.split('/').pop();
cur_url = cur_url.split('?');
function showOverviewHapWI() {
$.ajax( {
url: "options.py",
data: {
act: "overviewHapwi",
token: $('#token').val()
},
beforeSend: function() {
$('#ajaxHapwi').html('<img class="loading_hapwi_overview" src="/inc/images/loading.gif" />')
},
type: "POST",
success: function( data ) {
$("#ajaxHapwi").html(data);
}
} );
}
function showHapservers(serv, hostnamea) {
var i;
for (i = 0; i < serv.length; i++) {
showHapserversCallBack(serv[i], hostnamea[i])
}
}
function showHapserversCallBack(serv, hostnamea) {
$.ajax( {
url: "options.py",
data: {
act: "overviewHapservers",
serv: serv,
token: $('#token').val()
},
beforeSend: function() {
$("#"+hostnamea).html('<img class="loading_small_haproxyservers" src="/inc/images/loading.gif" />');
},
type: "POST",
success: function( data ) {
$("#"+hostnamea).empty();
$("#"+hostnamea).html(data);
}
} );
}
function overviewHapserverBackends(serv, hostnamea) {
console.log("#top-"+hostnamea)
$.ajax( {
url: "options.py",
data: {
act: "overviewHapserverBackends",
serv: serv[0],
token: $('#token').val()
},
beforeSend: function() {
$("#top-"+hostnamea).html('<img class="loading_small" style="padding-left: 45%;" src="/inc/images/loading.gif" />');
},
type: "POST",
success: function( data ) {
$("#top-"+hostnamea).empty();
$("#top-"+hostnamea).html(data);
}
} );
}
function showOverview(serv, hostnamea) {
showOverviewHapWI()
var i;
for (i = 0; i < serv.length; i++) {
showOverviewCallBack(serv[i], hostnamea[i])
}
$.getScript('/inc/overview.js');
}
function showOverviewCallBack(serv, hostnamea) {
$.ajax( {
url: "options.py",
data: {
act: "overview",
serv: serv,
token: $('#token').val()
},
beforeSend: function() {
$("#"+hostnamea).html('<img class="loading_small" src="/inc/images/loading.gif" />');
},
type: "POST",
success: function( data ) {
$("#"+hostnamea).empty();
$("#"+hostnamea).html(data);
}
} );
}
function showOverviewServer(name,ip,id) {
$.ajax( {
url: "options.py",
data: {
act: "overviewServers",
name: name,
serv: ip,
id: id,
page: 'hapservers.py',
token: $('#token').val()
},
type: "POST",
success: function( data ) {
$("#ajax-server-"+id).empty();
$("#ajax-server-"+id).css('display', 'block');
$("#ajax-server-"+id).css('background-color', '#fbfbfb');
$("#ajax-server-"+id).css('border', '1px solid #A4C7F5');
$(".ajax-server").css('display', 'block');
$(".div-server").css('clear', 'both');
$(".div-pannel").css('clear', 'both');
$(".div-pannel").css('display', 'block');
$(".div-pannel").css('padding-top', '10px');
$(".div-pannel").css('height', '70px');
$("#div-pannel-"+id).insertBefore('#up-pannel')
$("#ajax-server-"+id).html(data);
}
} );
}
function ajaxActionServers(action, id) {
var bad_ans = 'Bad config, check please';
$.ajax( {
@ -17,7 +130,7 @@ function ajaxActionServers(action, id) {
if (cur_url[0] == "hapservers.py") {
location.reload()
} else {
setTimeout(showOverview, 2000)
setTimeout(showOverview(ip, hostnamea), 2000)
}
}
},

68
inc/script.js

@ -135,7 +135,7 @@ function startSetInterval(interval) {
interval = 60000;
}
intervalId = setInterval('showOverview()', interval);
showOverview();
showOverview(ip, hostnamea);
} else if (cur_url[0] == "viewlogs.py") {
intervalId = setInterval('viewLogs()', interval);
viewLogs();
@ -192,53 +192,6 @@ $( document ).ajaxComplete(function( event, request, settings ) {
$('#cover').fadeOut('fast');
NProgress.done();
});
function showOverview() {
showOverviewHapWI()
$.ajax( {
url: "options.py",
data: {
act: "overview",
token: $('#token').val()
},
beforeSend: function() {
$('#ajaxstatus').html('<img class="loading" src="/inc/images/loading.gif" />')
},
type: "POST",
success: function( data ) {
$("#ajaxstatus").empty();
$("#ajaxstatus").html(data);
$.getScript('/inc/overview.js');
}
} );
}
function showOverviewServer(name,ip,id) {
$.ajax( {
url: "options.py",
data: {
act: "overviewServers",
name: name,
serv: ip,
id: id,
page: 'hapservers.py',
token: $('#token').val()
},
type: "POST",
success: function( data ) {
$("#ajax-server-"+id).empty();
$("#ajax-server-"+id).css('display', 'block');
$("#ajax-server-"+id).css('background-color', '#fbfbfb');
$("#ajax-server-"+id).css('border', '1px solid #A4C7F5');
$(".ajax-server").css('display', 'block');
$(".div-server").css('clear', 'both');
$(".div-pannel").css('clear', 'both');
$(".div-pannel").css('display', 'block');
$(".div-pannel").css('padding-top', '10px');
$(".div-pannel").css('height', '70px');
$("#div-pannel-"+id).insertBefore('#up-pannel')
$("#ajax-server-"+id).html(data);
}
} );
}
function showOverviewWaf() {
if (cur_url[0] == "waf.py") {
$.getScript('/inc/chart.min.js');
@ -274,22 +227,6 @@ function showOverviewWaf() {
}
} );
}
function showOverviewHapWI() {
$.ajax( {
url: "options.py",
data: {
act: "overviewHapwi",
token: $('#token').val()
},
beforeSend: function() {
$('#ajaxHapwi').html('<img class="loading_hapwi_overview" src="/inc/images/loading.gif" />')
},
type: "POST",
success: function( data ) {
$("#ajaxHapwi").html(data);
}
} );
}
function showStats() {
$.ajax( {
url: "options.py",
@ -516,6 +453,9 @@ function viewLogs() {
}
}
$( function() {
$('#errorMess').click(function(){
$('#error').remove();
});
$( "#serv" ).on('selectmenuchange',function() {
$("#show").css("pointer-events", "inherit");
$("#show").css("cursor", "pointer");

12
inc/style.css

@ -744,6 +744,7 @@ label {
.div-server {
background-color: #fbfbfb;
border: 1px solid #A4C7F5;
height: 153px;
width: 365px;
padding: 20px;
padding-left: 15px;
@ -780,7 +781,7 @@ label {
padding-bottom: 10px;
color: #999;
padding-top: 10px;
min-height: 60px;
height: 80px;
}
.server-act-links {
margin-left: -2px;
@ -1027,6 +1028,15 @@ label {
.loading_hapwi_overview{
margin-left: 40%;
}
.loading_small {
width: 39px;
height: 39px;
padding-left: 103%;
}
.loading_small_haproxyservers {
width: 15px;
height: 15px;
}
.tooltip {
font-size: 12px;
padding-bottom: 10px;

2
requirements.txt

@ -2,9 +2,7 @@ configparser==3.5.0
paramiko>=2.5.0
pytz==2017.3
requests>=2.22.0
requests_toolbelt==0.8.0
pyTelegramBotAPI==3.6.3
dump==0.0.4
networkx==2.1
matplotlib==2.1.2
future==0.13.1

Loading…
Cancel
Save