From fa842b05fcc8fb44027b3d23a20695b991d448f3 Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Wed, 4 Apr 2018 14:44:45 +0600 Subject: [PATCH] v1.9.1 Improved Runtime API --- README.md | 15 ++-- cgi-bin/edit.py | 123 ++++++++++++++++------------ cgi-bin/funct.py | 2 +- cgi-bin/haproxy-webintarface.config | 2 + haproxy-webintarface.config | 55 ------------- image/10.jpeg | Bin 274248 -> 275464 bytes image/2.jpeg | Bin 861446 -> 886491 bytes image/3.jpeg | Bin 340449 -> 543218 bytes image/4.jpeg | Bin 426280 -> 439279 bytes image/5.jpeg | Bin 245973 -> 254961 bytes image/6.jpeg | Bin 391453 -> 422267 bytes image/7.jpeg | Bin 604215 -> 596630 bytes image/8.jpeg | Bin 301264 -> 331446 bytes image/9.jpeg | Bin 282584 -> 283968 bytes index.html | 4 +- 15 files changed, 85 insertions(+), 116 deletions(-) delete mode 100644 haproxy-webintarface.config diff --git a/README.md b/README.md index 95189bbe..50ab69db 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave 2. Server and service statsus in one place 3. View logs of all servers in one place 4. Map frontend, backends and servers -5. Disabling / enabling the backend servers without reboot (after reboot, will work as specified in the config), viewing server state data +5. Runtime API with the ability to save changes (need install socat on all haproxy servers) 6. Browsing Configs 7. Add sections: listen, frontend, backend from web interface 8. Editing configs @@ -34,15 +34,16 @@ Edit listserv.py, add your HAproxy servers. ![alt text](image/7.jpeg "Overview page") # Settings -edit haproxy-webintarface.config with your env +Edit haproxy-webintarface.config with your env -copy ssh key on all HAproxy servers +Copy ssh key on all HAproxy servers -For online edit HAproxy settings enable socket on HAproxt servers: +For Runtime API enable state file on HAproxt servers and need install socat on all haproxy servers: ``` -global - log 172.28.0.5 local2 debug err - stats socket *:1999 level admin + global + server-state-file /etc/haproxy/haproxy/haproxy.state + defaults + load-server-state-from-file global ``` ![alt text](image/4.jpeg "View logs page") diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py index 5de29406..96e74505 100644 --- a/cgi-bin/edit.py +++ b/cgi-bin/edit.py @@ -6,14 +6,57 @@ import subprocess import os import http.cookies import funct +import configparser from funct import head as head form = cgi.FieldStorage() serv = form.getvalue('serv') +action = form.getvalue('servaction') +backend = form.getvalue('servbackend') -head("Edit & show HAproxy settings") +head("Runtime API") funct.check_login() +funct.check_config() + +path_config = "haproxy-webintarface.config" +config = configparser.ConfigParser() +config.read(path_config) + +server_state_file = config.get('haproxy', 'server_state_file') +haproxy_sock = config.get('haproxy', 'haproxy_sock') + +if backend is None: + backend = "" + autofocus = "" +else: + autofocus = "autofocus" + +if action == 'disable': + selected1 = 'selected' + selected2 = '' + selected3 = '' + selected4 = '' +elif action == 'enable': + selected1 = '' + selected2 = 'selected' + selected3 = '' + selected4 = '' +elif action == 'set': + selected1 = '' + selected2 = '' + selected3 = 'selected' + selected4 = '' +elif action == 'show': + selected1 = '' + selected2 = '' + selected3 = '' + selected4 = 'selected' +else: + selected1 = '' + selected2 = '' + selected3 = '' + selected4 = '' print('
' '

Edit & show HAproxy settings

' @@ -23,71 +66,49 @@ print('
' 'Server' 'Disable/Enable server or output any information' 'Command' + 'Save change' '' '' '' - '' + '' '
' - '' '') funct.choose_server_with_vip(serv) -action = form.getvalue('servaction') -backend = form.getvalue('servbackend') - -if action == '1': - selected1 = 'selected' - selected2 = '' - selected3 = '' -elif action == '2': - selected1 = '' - selected2 = 'selected' - selected3 = '' -elif action == '3': - selected1 = '' - selected2 = '' - selected3 = 'selected' -else: - selected1 = '' - selected2 = '' - selected3 = '' - +print('' + '' + '') -print('') -print('') +print('' % (backend, autofocus)) -print('') +print('' + '' + '') funct.mode_admin("Enter") print('
' '') if form.getvalue('servaction') is not None: - action = form.getvalue('servaction') - backend = form.getvalue('servbackend') - - if action == '1': - enable = 'disable' - elif action == '2': - enable = 'enable' - elif action == '3': - enable = 'show' - - cmd='echo "%s %s" |nc %s 1999' % (enable, backend, serv) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True) - stdout, stderr = p.communicate() - err = stderr.splitlines() - output = stdout.splitlines() - - print('

You %s %s on HAproxy %s. Look it or Edit something else


' % (enable, backend, serv, serv)) - print('
'.join(map(str, output))) - if err: - print('
'.join(map(str, err))) + enable = form.getvalue('servaction') + cmd='echo "%s %s" |socat stdio %s | cut -d "," -f 1-2,5-10,34-36 | column -s, -t' % (enable, backend, haproxy_sock) + + if form.getvalue('save') == "on": + save_command = 'echo "show servers state" | socat stdio %s > %s' % (haproxy_sock, server_state_file) + command = [ cmd, save_command ] + else: + command = [ cmd ] + + if enable != "show": + print('

You %s %s on HAproxy %s. Look it or Edit something else


' % (enable, backend, serv, serv)) + + funct.ssh_command(serv, command, show_log="1") action = 'edit.py ' + enable + ' ' + backend funct.logging(serv, action) diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 5174bc25..0fdcf9ab 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -151,7 +151,7 @@ def links(): '
  • Map
  • ' '' '' - '
  • Edit settings
  • ' + '
  • Runtime API
  • ' '
  • Configs' '