Browse Source

v3.2.8

Description for servers
pull/42/head
Aidaho12 6 years ago
parent
commit
3779c047b3
  1. 4
      README.md
  2. 25
      app/create_db.py
  3. 6
      app/ovw.py
  4. 21
      app/sql.py
  5. 34
      app/templates/admin.html
  6. 5
      app/templates/ajax/new_server.html
  7. 6
      app/templates/ajax/overviewServers.html
  8. 2
      app/templates/base.html
  9. BIN
      image/haproxy-wi-admin-area.jpeg
  10. 2
      inc/script.js
  11. 7
      inc/users.js

4
README.md

@ -143,7 +143,7 @@ After update old config saved at /tmp/ folder. Compare new and old config, if in
# Update DB
```
$ cd /var/www/haproxy-wi/app
$ ./update_db.py
$ ./create_db.py
```
# Troubleshooting
If you have error:
@ -162,7 +162,7 @@ Internal Server Error
Do this:
```
$ cd /var/www/haproxy-wi/app
$ ./update_db.py
$ ./create_db.py
```
and check executeble py files

25
app/create_db.py

@ -238,7 +238,7 @@ def update_db_v_3_2_3(**kwargs):
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: port' or e == " 1060 (42S21): Duplicate column name 'port' ":
print('DB was update<br />')
print('Updating... go to version 3.2.8')
else:
print("An error occurred:", e)
return False
@ -247,18 +247,41 @@ def update_db_v_3_2_3(**kwargs):
return True
cur.close()
con.close()
def update_db_v_3_2_8(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN desc varchar(64);
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: desc' or e == " 1060 (42S21): Duplicate column name 'desc' ":
print('DB was update<br />')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 3.2.8<br />")
return True
cur.close()
con.close()
def update_all():
update_db_v_31()
update_db_v_3_2()
update_db_v_3_21()
update_db_v_3_2_3()
update_db_v_3_2_8()
def update_all_silent():
update_db_v_31(silent=1)
update_db_v_3_2(silent=1)
update_db_v_3_21(silent=1)
update_db_v_3_2_3(silent=1)
update_db_v_3_2_8(silent=1)
if __name__ == "__main__":
create_table()

6
app/ovw.py

@ -60,7 +60,7 @@ def get_overviewWaf(url):
ioloop.run_until_complete(get_runner_overviewWaf(url))
ioloop.close()
async def async_get_overviewServers(serv1, serv2):
async def async_get_overviewServers(serv1, serv2, desc):
commands = [ "top -u haproxy -b -n 1" ]
cmd = 'echo "show info" |nc %s %s |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % (serv2, haproxy_sock_port)
out = funct.subprocess_execute(cmd)
@ -73,13 +73,13 @@ async def async_get_overviewServers(serv1, serv2):
out1 += "<br />"
else:
out1 = "Can\'t connect to HAproxy"
server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),funct.show_backends(serv2, ret=1))
server_status = (serv1,serv2, out1, funct.ssh_command(serv2, commands),funct.show_backends(serv2, ret=1), desc)
return server_status
async def get_runner_overviewServers():
template = env.get_template('overviewServers.html')
futures = [async_get_overviewServers(server[1], server[2]) for server in listhap]
futures = [async_get_overviewServers(server[1], server[2], server[11]) for server in listhap]
for i, future in enumerate(asyncio.as_completed(futures)):
result = await future
servers.append(result)

21
app/sql.py

@ -116,11 +116,11 @@ def update_group(name, descript, id):
cur.close()
con.close()
def add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port):
def add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, desc):
con, cur = create_db.get_cur()
sql = """ INSERT INTO servers (hostname, ip, groups, type_ip, enable, master, cred, alert, metrics, port)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port)
sql = """ INSERT INTO servers (hostname, ip, groups, type_ip, enable, master, cred, alert, metrics, port, desc)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, desc)
try:
cur.execute(sql)
con.commit()
@ -146,7 +146,7 @@ def delete_server(id):
cur.close()
con.close()
def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert, metrics, port):
def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert, metrics, port, desc):
con, cur = create_db.get_cur()
sql = """ update servers set
hostname = '%s',
@ -158,8 +158,9 @@ def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert,
cred = '%s',
alert = '%s',
metrics = '%s',
port = '%s'
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, id)
port = '%s',
desc = '%s'
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, desc, id)
try:
cur.execute(sql)
con.commit()
@ -1083,11 +1084,12 @@ if form.getvalue('newserver') is not None:
page = form.getvalue('page')
page = page.split("#")[0]
port = form.getvalue('newport')
desc = form.getvalue('desc')
print('Content-type: text/html\n')
if ip is None or group is None or cred is None or port is None:
print(error_mess)
else:
if add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port):
if add_server(hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, desc):
show_update_server(ip, page)
if form.getvalue('serverdel') is not None:
@ -1133,11 +1135,12 @@ if form.getvalue('updateserver') is not None:
alert = form.getvalue('alert_en')
metrics = form.getvalue('metrics')
port = form.getvalue('port')
desc = form.getvalue('desc')
print('Content-type: text/html\n')
if name is None or ip is None or port is None:
print(error_mess)
else:
update_server(name, ip, group, typeip, enable, master, id, cred, alert, metrics, port)
update_server(name, ip, group, typeip, enable, master, id, cred, alert, metrics, port, desc)
if form.getvalue('updatessh'):
id = form.getvalue('id')

34
app/templates/admin.html

@ -59,7 +59,7 @@
{% endfor %}
</select>
</td>
<td><a class="delete" onclick="confirmDeleteUser({{user.0}})" style="cursor: pointer;"></a></td>
<td><a class="delete" onclick="confirmDeleteUser({{user.0}})" title="Delete user {{user.1}}" style="cursor: pointer;"></a></td>
</tr>
{% endfor %}
</table>
@ -129,7 +129,7 @@
<input type="text" id="descript-{{ group.0 }}" value="{{ group.2 }}" class="form-control" size="100">
</td>
<td>
<a class="delete" onclick="confirmDeleteGroup({{ group.0 }})" style="cursor: pointer;"></a>
<a class="delete" onclick="confirmDeleteGroup({{ group.0 }})" title="Delete group {{group.1}}" style="cursor: pointer;"></a>
</td>
{% endif %}
</tr>
@ -169,6 +169,7 @@
<td><span title="Enable save and show metrics">Metrics(?)</span></td>
<td><span title="Actions with master config will automatically apply on slave">Slave for (?)</span></td>
<td>Credentials</td>
<td>Desciption</td>
<td></td>
</tr>
@ -178,7 +179,7 @@
<input type="text" id="hostname-{{server.0}}" value="{{server.1}}" class="form-control">
</td>
<td>
<input type="text" id="ip-{{server.0}}" value="{{server.2}}" class="form-control">
<input type="text" id="ip-{{server.0}}" value="{{server.2}}" size="14" class="form-control">
</td>
<td>
<input type="text" id="port-{{server.0}}" value="{{server.10}}" size="1" class="form-control">
@ -248,7 +249,14 @@
</select>
</td>
<td>
<a class="delete" onclick="confirmDeleteServer({{server.0}})" style="cursor: pointer;"></a>
{% if server.11 %}
<input type="text" id="desc-{{server.0}}" value="{{server.11}}" size="30" class="form-control">
{% else %}
<input type="text" id="desc-{{server.0}}" value="" size="30" class="form-control">
{% endif %}
</td>
<td>
<a class="delete" onclick="confirmDeleteServer({{server.0}})" title="Delete server {{server.1}}" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}
@ -267,6 +275,7 @@
<td><span title="Enable save and show metrics">Metrics(?)</span></td>
<td title="Actions with master config will automatically apply on slave">Slave for</td>
<td>Credentials</td>
<td>Desciption</td>
<td></td>
</tr>
<tr>
@ -274,7 +283,7 @@
<input type="text" name="new-server-add" id="new-server-add" class="form-control">
</td>
<td>
<input type="text" name="new-ip" id="new-ip" class="form-control">
<input type="text" name="new-ip" id="new-ip" size="14" class="form-control">
</td>
<td>
<input type="text" name="new-port" id="new-port" size=1 class="form-control" value="22">
@ -315,6 +324,9 @@
{% endfor %}
</select>
</td>
<td>
<input type="text" id="desc" size="30" class="form-control">
</td>
<td>
<a class="add-admin" id="add-server" style="cursor: pointer;"></a>
</td>
@ -390,7 +402,7 @@
<br>
</td>
<td>
<a class="delete" onclick="confirmDeleteSsh({{ssh.0}})" style="cursor: pointer;"></a>
<a class="delete" onclick="confirmDeleteSsh({{ssh.0}})" title="Delete SSH credentials {{ssh.1}}" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}
@ -489,7 +501,7 @@
</select>
</td>
<td>
<a class="delete" onclick="confirmDeleteTelegram({{telegram.0}})" style="cursor: pointer;"></a>
<a class="delete" onclick="confirmDeleteTelegram({{telegram.0}})" title="Delete channel {{telegram.2}}" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}
@ -528,4 +540,12 @@
<div id="ajax-telegram"></div>
</div>
</div>
<style>
.ui-selectmenu-button.ui-button {
width: 12em;
}
.first-collumn {
width: 10%;
}
</style>
{% endblock %}

5
app/templates/ajax/new_server.html

@ -78,7 +78,10 @@
</select>
</td>
<td>
<a class="delete" onclick="removeServer({{server.0}})" style="cursor: pointer;"></a>
<input type="text" id="desc-{{server.0}}" value="{{server.11}}" size="30" class="form-control">
</td>
<td>
<a class="delete" onclick="removeServer({{server.0}})" title="Delete server {{server.1}}" style="cursor: pointer;"></a>
</td>
</tr>
{% endfor %}

6
app/templates/ajax/overviewServers.html

@ -2,7 +2,11 @@
<tr>
<td class="overviewTr first-collumn">
<a name="{{ service.0 }}"></a>
<h3 title="IP {{ service.1 }}"> {{ service.0 }} :</h3>
{% if service.5 != "None" %}
<h3 title="IP {{ service.1 }} {{ service.5 }}"> {{ service.0 }} :</h3>
{% else %}
<h3 title="IP {{ service.1 }}"> {{ service.0 }} :</h3>
{% endif %}
</td>
<td class="overviewTd" style="padding-top: 10px;">
<pre style="font-size: 12px;">

2
app/templates/base.html

@ -101,7 +101,7 @@
</ul>
</nav>
<div class="copyright-menu">
HAproxy-WI v3.2.7
HAproxy-WI v3.2.8
<br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
</div>

BIN
image/haproxy-wi-admin-area.jpeg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

After

Width:  |  Height:  |  Size: 350 KiB

2
inc/script.js

@ -85,11 +85,9 @@ function autoRefreshStyle(autoRefresh) {
$('.auto-refresh-resume').css('margin-left', "-25px");
$('.auto-refresh img').remove();
}
function setRefreshInterval(interval) {
if (interval == "0") {
Cookies.remove('auto-refresh');
Cookies.remove('auto-refresh-pause');
pauseAutoRefresh();
$('.auto-refresh').prepend('<img src=/image/pic/update.png alt="restart" class="icon">');
$('.auto-refresh').css('margin-top', '-3px');

7
inc/users.js

@ -220,7 +220,8 @@ $( function() {
cred: $('#credentials').val(),
alert_en: alert_en,
metrics: metrics,
page: cur_url[0]
page: cur_url[0],
desc: $('#desc').val()
},
type: "GET",
success: function( data ) {
@ -235,7 +236,6 @@ $( function() {
$('.alert-danger').remove();
$("#ajax-servers").append(data);
$(".newserver").addClass( "update", 1000, callbackServer );
//$.getScript(url);
$( "input[type=submit], button" ).button();
$( "input[type=checkbox]" ).checkboxradio();
$( "select" ).selectmenu();
@ -734,7 +734,8 @@ function updateServer(id) {
cred: $('#credentials-'+id+' option:selected').val(),
id: id,
metrics: metrics,
alert_en: alert_en
alert_en: alert_en,
desc: $('#desc-'+id).val()
},
type: "GET",
success: function( data ) {

Loading…
Cancel
Save