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' '
      ' '
    • Show
    • ' diff --git a/cgi-bin/haproxy-webintarface.config b/cgi-bin/haproxy-webintarface.config index 4c5787c4..ee34397f 100644 --- a/cgi-bin/haproxy-webintarface.config +++ b/cgi-bin/haproxy-webintarface.config @@ -49,6 +49,8 @@ password = password stats_port = 8085 stats_page = stats haproxy_config_path = /etc/haproxy/haproxy.cfg +server_state_file = /etc/haproxy/haproxy.state +haproxy_sock = /var/run/haproxy.sock #Temp store configs, for haproxy check tmp_config_path = /tmp #Time in seconds for auto refresh view stats_port diff --git a/haproxy-webintarface.config b/haproxy-webintarface.config deleted file mode 100644 index 97047f13..00000000 --- a/haproxy-webintarface.config +++ /dev/null @@ -1,55 +0,0 @@ -[main] -#Path to files destination -fullpath = /opt/haproxy-wi/ -server_bind_ip = 0.0.0.0 -server_port = 8000 -log_path = %(fullpath)s/log/ -time_zone = UTC -#Enable logo on top menu. Default disable -logo_enable = 0 -logo_path = /logo.png - -[configs] -#Server for save configs from HAproxy servers -haproxy_configs_server = localhost -#Dir where configs will be save -haproxy_save_configs_dir = /opt/haproxy-wi/cgi-bin/hap_config/ - -[ssh] -#If ssh connect disable entare password for ssh connect. Default enable -ssh_keys_enable = 1 -#SSH keys to connect without password to HAproxy servers -ssh_keys = /opt/haproxy-wi/cgi-bin/id_rsa.pem -#Username for connect ssh -ssh_user_name = root -ssh_pass = - -[logs] -#Logs save locally, disable by default -local_path_logs = /var/log/haproxy.log -#If exist syslog server for HAproxy logs -syslog_server_enable = 0 -syslog_server = - -[telegram] -#Send log message to telegram channel -#Default bot send message disable -enable = 0 -token = -channel_name = -proxy = - -[haproxy] -#Command for restart HAproxy service -restart_command = service haproxy restart -status_command = systemctl status haproxy -#Username and password for Stats web page HAproxy -user = admin -password = password -stats_port = 8085 -stats_page = stats -haproxy_config_path = /etc/haproxy/haproxy.cfg -#Temp store configs, for haproxy check -tmp_config_path = /tmp -#Time in seconds for auto refresh view stats_port -refresh_time = 120 diff --git a/image/10.jpeg b/image/10.jpeg index cf4e114e..ee892e86 100644 Binary files a/image/10.jpeg and b/image/10.jpeg differ diff --git a/image/2.jpeg b/image/2.jpeg index 4bbe3d62..746652be 100644 Binary files a/image/2.jpeg and b/image/2.jpeg differ diff --git a/image/3.jpeg b/image/3.jpeg index e9d1bed5..3362ca40 100644 Binary files a/image/3.jpeg and b/image/3.jpeg differ diff --git a/image/4.jpeg b/image/4.jpeg index 862aa6c9..a9c7e902 100644 Binary files a/image/4.jpeg and b/image/4.jpeg differ diff --git a/image/5.jpeg b/image/5.jpeg index d2451701..b858612a 100644 Binary files a/image/5.jpeg and b/image/5.jpeg differ diff --git a/image/6.jpeg b/image/6.jpeg index cc8aab3c..aa7dc6cf 100644 Binary files a/image/6.jpeg and b/image/6.jpeg differ diff --git a/image/7.jpeg b/image/7.jpeg index d66ae4cd..0d1edb5f 100644 Binary files a/image/7.jpeg and b/image/7.jpeg differ diff --git a/image/8.jpeg b/image/8.jpeg index fa30c783..7e0636c8 100644 Binary files a/image/8.jpeg and b/image/8.jpeg differ diff --git a/image/9.jpeg b/image/9.jpeg index 3081794b..f726cb3a 100644 Binary files a/image/9.jpeg and b/image/9.jpeg differ diff --git a/index.html b/index.html index 98228fc2..2f5d4714 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ View stats
      Logs
      Map
      - Edit settings
      + Runtime API
      Compare
      Show
      Add
      @@ -24,7 +24,7 @@ Upload old config
      Delete old config