From ac1945b48ee58612c7637770e47364a19ed91c04 Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Sat, 28 Apr 2018 20:42:38 +0600 Subject: [PATCH] v2.3 add an alternate vrrp --- README.md | 49 ++++++++--------- {cgi-bin => app}/add.py | 0 {cgi-bin => app}/config.py | 0 {cgi-bin => app}/configshow.py | 0 {cgi-bin => app}/configver.py | 0 {cgi-bin => app}/create_db.py | 0 {cgi-bin => app}/delver.py | 0 {cgi-bin => app}/diff.py | 0 {cgi-bin => app}/edit.py | 0 {cgi-bin => app}/funct.py | 52 +++++++++---------- {cgi-bin => app}/ha.py | 38 ++++++++++++++ {cgi-bin => app}/haproxy-webintarface.config | 8 +-- {cgi-bin => app}/haproxy-wi.db.sql | 0 {cgi-bin => app}/keepalivedconfig.py | 0 {cgi-bin => app}/login.py | 10 ++-- {cgi-bin => app}/logs.py | 0 {cgi-bin => app}/map.py | 0 {cgi-bin => app}/options.py | 24 ++++++++- {cgi-bin => app}/overview.py | 2 +- {cgi-bin => app}/ovw.py | 8 +-- app/scripts/add_vrrp.sh | 49 +++++++++++++++++ {cgi-bin => app}/scripts/install_haproxy.sh | 2 +- .../scripts/install_keepalived.sh | 2 +- {cgi-bin => app}/settings.py | 0 {cgi-bin => app}/sql.py | 0 {cgi-bin => app}/update_db.py | 0 {cgi-bin => app}/users.py | 0 {cgi-bin => app}/viewlogs.py | 0 {cgi-bin => app}/viewsttats.py | 0 .../hap_config/172.28.5.5.cfg | 0 configs/kp_config/172.28.5.5.cfg | 1 + install.sh | 12 ++--- 32 files changed, 184 insertions(+), 73 deletions(-) rename {cgi-bin => app}/add.py (100%) rename {cgi-bin => app}/config.py (100%) rename {cgi-bin => app}/configshow.py (100%) rename {cgi-bin => app}/configver.py (100%) rename {cgi-bin => app}/create_db.py (100%) rename {cgi-bin => app}/delver.py (100%) rename {cgi-bin => app}/diff.py (100%) rename {cgi-bin => app}/edit.py (100%) rename {cgi-bin => app}/funct.py (87%) rename {cgi-bin => app}/ha.py (53%) rename {cgi-bin => app}/haproxy-webintarface.config (88%) rename {cgi-bin => app}/haproxy-wi.db.sql (100%) rename {cgi-bin => app}/keepalivedconfig.py (100%) rename {cgi-bin => app}/login.py (93%) rename {cgi-bin => app}/logs.py (100%) rename {cgi-bin => app}/map.py (100%) rename {cgi-bin => app}/options.py (90%) rename {cgi-bin => app}/overview.py (67%) rename {cgi-bin => app}/ovw.py (93%) create mode 100644 app/scripts/add_vrrp.sh rename {cgi-bin => app}/scripts/install_haproxy.sh (93%) rename {cgi-bin => app}/scripts/install_keepalived.sh (91%) rename {cgi-bin => app}/settings.py (100%) rename {cgi-bin => app}/sql.py (100%) rename {cgi-bin => app}/update_db.py (100%) rename {cgi-bin => app}/users.py (100%) rename {cgi-bin => app}/viewlogs.py (100%) rename {cgi-bin => app}/viewsttats.py (100%) rename {cgi-bin => configs}/hap_config/172.28.5.5.cfg (100%) create mode 100644 configs/kp_config/172.28.5.5.cfg diff --git a/README.md b/README.md index cf2f67be..90c489b3 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,25 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave ![alt text](image/haproxy-wi-config-show.jpeg "Show config page") -# Capabilities: -1. View statistics of all servers in one place -2. Server and service statsus in one place -3. View logs of all servers in one place -4. Map frontend, backends and servers -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 -9. Rollback to previous versions of the config -10. Master/slave servers -11. Configure firewalld on HAProxy servers based on config ports -12. Comparing versions of configs -13. Users roles: admin, editor, viewer -14. Server groups -15. Telegram notification -16. Creating HA HAProxy cluster -17. Editing keepalived configs +# Features: +1. Configure HAproxy In a jiffy with haproxy-wi +2. View and analyse Status of all Frontend/backend server via haproxy-wi from a single control panel. +3. View/Analyse HAproxy logs straight from the haproxy-wi web interface +4. Create and visualise the HAproxy workflow from Web Ui. +5. Push Your changes to your HAproxy servers with a single click through web interface. +6. Get info on past changes, Evaluate your config files and restore a previous stable config anytime with a single click straight from Web interface. +7. Add/Edit Frontend or backend servers via web interface with a click of a button. +8. Edit config of HAproxy and push changes to All Master/Slave server with a single click. +9. Add Multiple server to ensure Config Sync between servers. +10. Auto management of ports assigned to Fronted. +11. Evaluate the changes of recent configs pushed to HAproxy instances straight from web ui +12. Multiple User Roles support for privileged based Viewing and editing of Config. +13. Create Groups and add /remove servers to ensure proper identification for your HAproxy Clusters +14. Send notifications to telegram directly from haproxy-wi. +15. haproxy-wi supports high Availability to ensure uptime to all Master slave servers configured. +16. SSL certificate support. +17. SSH Key support for managing multiple HAproxy Servers straight from haproxy-wi + # Install The installer will ask you a few questions @@ -37,7 +38,7 @@ $ cd /var/www/ $ git clone https://github.com/Aidaho12/haproxy-wi.git /var/www/haproxy-wi $ chown -R apache:apache haproxy-wi/ $ pip install -r haproxy-wi/requirements.txt -$ chmod +x haproxy-wi/cgi-bin/*.py +$ chmod +x haproxy-wi/app/*.py ``` For Apache do virtualhost with cgi-bin. Like this: @@ -49,7 +50,7 @@ For Apache do virtualhost with cgi-bin. Like this: CustomLog /var/log/httpd/haproxy-wi.access.log combined DocumentRoot /var/www/haproxy-wi - ScriptAlias /cgi-bin/ "/var/www/haproxy-wi/cgi-bin/" + ScriptAlias /cgi-bin/ "/var/www/haproxy-wi/app/" Options +ExecCGI @@ -74,7 +75,7 @@ MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIE # Settings ``` -Edit $HOME_HAPROXY-WI/cgi-bin/haproxy-webintarface.config with your env +Edit $HOME_HAPROXY-WI/app/haproxy-webintarface.config with your env ``` Copy ssh key on all HAproxy servers @@ -95,14 +96,14 @@ For Runtime API enable state file on HAproxt servers and need install socat on a # Update DB ``` -$ cd /var/www/haproxy-wi/cgi-bin +$ cd /var/www/haproxy-wi/app $ ./update_db.py ``` # Troubleshooting If you have error: ``` Forbidden -You don't have permission to access /cgi-bin/overview.py on this server. +You don't have permission to access /app/overview.py on this server. ``` Check owner(must be apache, or another user for apache) @@ -114,7 +115,7 @@ Internal Server Error Do this: ``` -$ cd /var/www/haproxy-wi +$ cd /var/www/haproxy-wi/app $ ./update_db.py ``` diff --git a/cgi-bin/add.py b/app/add.py similarity index 100% rename from cgi-bin/add.py rename to app/add.py diff --git a/cgi-bin/config.py b/app/config.py similarity index 100% rename from cgi-bin/config.py rename to app/config.py diff --git a/cgi-bin/configshow.py b/app/configshow.py similarity index 100% rename from cgi-bin/configshow.py rename to app/configshow.py diff --git a/cgi-bin/configver.py b/app/configver.py similarity index 100% rename from cgi-bin/configver.py rename to app/configver.py diff --git a/cgi-bin/create_db.py b/app/create_db.py similarity index 100% rename from cgi-bin/create_db.py rename to app/create_db.py diff --git a/cgi-bin/delver.py b/app/delver.py similarity index 100% rename from cgi-bin/delver.py rename to app/delver.py diff --git a/cgi-bin/diff.py b/app/diff.py similarity index 100% rename from cgi-bin/diff.py rename to app/diff.py diff --git a/cgi-bin/edit.py b/app/edit.py similarity index 100% rename from cgi-bin/edit.py rename to app/edit.py diff --git a/cgi-bin/funct.py b/app/funct.py similarity index 87% rename from cgi-bin/funct.py rename to app/funct.py index 93b132de..9cf7e6d0 100644 --- a/cgi-bin/funct.py +++ b/app/funct.py @@ -166,46 +166,46 @@ def links(): '' - '' + '' '') def show_login_links(): @@ -213,9 +213,9 @@ def show_login_links(): login = cookie.get('login') if login is None: - print('
  • ') + print('
  • ') else: - print('
  • ' % login.value) + print('
  • ' % login.value) def footer(): print('' @@ -246,7 +246,7 @@ def get_auto_refresh(h2): '' '' '' - '
    ' + '
    ' '
      ' '
    • ' '5 seconds' diff --git a/cgi-bin/ha.py b/app/ha.py similarity index 53% rename from cgi-bin/ha.py rename to app/ha.py index e22a1614..5d3d728f 100644 --- a/cgi-bin/ha.py +++ b/app/ha.py @@ -17,6 +17,7 @@ serv = "" print('' '

      Configure HA

      ' '' + '' '' '' '' @@ -50,6 +51,43 @@ print('' '' + '

      Create new HA cluster

      MasterSlave' 'Create' '
      ' + + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' '

      Or add VRRP to exist

      MasterSlaveVRRP interfaceVRRP IPRestart Keepalived(?)
      ' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + 'Add' + '
      ' '
      ') diff --git a/cgi-bin/haproxy-webintarface.config b/app/haproxy-webintarface.config similarity index 88% rename from cgi-bin/haproxy-webintarface.config rename to app/haproxy-webintarface.config index 6b9eba41..e0574779 100644 --- a/cgi-bin/haproxy-webintarface.config +++ b/app/haproxy-webintarface.config @@ -1,7 +1,7 @@ [main] #Path to files destination fullpath = /var/www/haproxy-wi -cgi_path = ${fullpath}/cgi-bin/ +cgi_path = ${fullpath}/app/ log_path = ${fullpath}/log/ cert_local_dir = ${cgi_path}/certs/ time_zone = UTC @@ -10,8 +10,8 @@ time_zone = UTC #Server for save configs from HAproxy servers haproxy_configs_server = localhost #Dir where configs will be save -haproxy_save_configs_dir = ${main:fullpath}/cgi-bin/hap_config/ -kp_save_configs_dir = ${main:fullpath}/cgi-bin/kp_config/ +haproxy_save_configs_dir = ${main:fullpath}/app/hap_config/ +kp_save_configs_dir = ${main:fullpath}/app/kp_config/ [mysql] #Enable MySQL DB. If default will be used Sqlite DB. Default disable @@ -25,7 +25,7 @@ mysql_host = 127.0.0.1 #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 = ${main:fullpath}/cgi-bin/id_rsa.pem +ssh_keys = ${main:fullpath}/app/id_rsa.pem #Username for connect ssh ssh_user_name = root ssh_pass = diff --git a/cgi-bin/haproxy-wi.db.sql b/app/haproxy-wi.db.sql similarity index 100% rename from cgi-bin/haproxy-wi.db.sql rename to app/haproxy-wi.db.sql diff --git a/cgi-bin/keepalivedconfig.py b/app/keepalivedconfig.py similarity index 100% rename from cgi-bin/keepalivedconfig.py rename to app/keepalivedconfig.py diff --git a/cgi-bin/login.py b/app/login.py similarity index 93% rename from cgi-bin/login.py rename to app/login.py index 939887c4..9d90a3b4 100644 --- a/cgi-bin/login.py +++ b/app/login.py @@ -39,8 +39,8 @@ def login_page(error): print('') if form.getvalue('logout') is not None: - print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly") - print("Set-cookie: role=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly") + print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/app/; httponly") + print("Set-cookie: role=; expires=Wed May 18 03:33:20 2003; path=/app/; httponly") print("Content-type: text/html\n") print('') @@ -60,13 +60,13 @@ if login is not None and password is not None: role = 3 c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) c["login"] = login - c["login"]["path"] = "/cgi-bin/" + c["login"]["path"] = "/app/" c["login"]["expires"] = "Wed May 18 03:33:20 2033" c["role"] = role - c["role"]["path"] = "/cgi-bin/" + c["role"]["path"] = "/app/" c["role"]["expires"] = "Wed May 18 03:33:20 2033" c["group"] = users[4] - c["group"]["path"] = "/cgi-bin/" + c["group"]["path"] = "/app/" c["group"]["expires"] = "Wed May 18 03:33:20 2033" print(c) if form.getvalue('ref') is None: diff --git a/cgi-bin/logs.py b/app/logs.py similarity index 100% rename from cgi-bin/logs.py rename to app/logs.py diff --git a/cgi-bin/map.py b/app/map.py similarity index 100% rename from cgi-bin/map.py rename to app/map.py diff --git a/cgi-bin/options.py b/app/options.py similarity index 90% rename from cgi-bin/options.py rename to app/options.py index 10a46649..4201c4df 100644 --- a/cgi-bin/options.py +++ b/app/options.py @@ -248,4 +248,26 @@ if form.getvalue('master'): funct.ssh_command(slave, commands) os.system("rm -f %s" % script) - sql.update_server_master(master, slave) \ No newline at end of file + sql.update_server_master(master, slave) + +if form.getvalue('masteradd'): + master = form.getvalue('masteradd') + slave = form.getvalue('slaveadd') + interface = form.getvalue('interfaceadd') + vrrpip = form.getvalue('vrrpipadd') + kp = form.getvalue('kp') + tmp_config_path = config.get('haproxy', 'tmp_config_path') + script = "add_vrrp.sh" + + os.system("cp scripts/%s ." % script) + + funct.upload(master, tmp_config_path, script) + funct.upload(slave, tmp_config_path, script) + + commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script+" MASTER "+interface+" "+vrrpip+" "+kp] + funct.ssh_command(master, commands) + + commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script+" BACKUP "+interface+" "+vrrpip+" "+kp ] + funct.ssh_command(slave, commands) + + os.system("rm -f %s" % script) \ No newline at end of file diff --git a/cgi-bin/overview.py b/app/overview.py similarity index 67% rename from cgi-bin/overview.py rename to app/overview.py index e726baf9..e6db6197 100644 --- a/cgi-bin/overview.py +++ b/app/overview.py @@ -8,7 +8,7 @@ funct.head("Overview") funct.check_config() funct.check_login() funct.get_auto_refresh("Overview") - +print("") print('
      ') funct.footer() \ No newline at end of file diff --git a/cgi-bin/ovw.py b/app/ovw.py similarity index 93% rename from cgi-bin/ovw.py rename to app/ovw.py index 2269a42b..5a6ee181 100644 --- a/cgi-bin/ovw.py +++ b/app/ovw.py @@ -81,10 +81,10 @@ def get_overview(): print('start' % server[2]) print('start' % server[2]) print('restart' % server[2]) - print('show' % server[2]) - print('edit' % server[2]) - print('compare' % server[2]) - print('map' % server[2]) + print('show' % server[2]) + print('edit' % server[2]) + print('compare' % server[2]) + print('map' % server[2]) print('') funct.ssh_command(server[2], commands1) print('') diff --git a/app/scripts/add_vrrp.sh b/app/scripts/add_vrrp.sh new file mode 100644 index 00000000..ee15bc79 --- /dev/null +++ b/app/scripts/add_vrrp.sh @@ -0,0 +1,49 @@ +#!/bin/bash +CONF=/etc/keepalived/keepalived.conf +IP=`cat $CONF |grep $3 |sed s/' '//g|sed s/'\t'//g` + +if [[ $IP == $3 ]];then + echo -e "error: VRRP address alredy use" + exit 1 +fi + +cat << EOF >> $CONF +vrrp_instance VI_2 { + state MASTER + interface eth1 + virtual_router_id 101 + priority 103 + + #check if we are still running + track_script { + chk_haproxy + } + + advert_int 1 + authentication { + auth_type PASS + auth_pass VerySecretPass2! + } + virtual_ipaddress { + 0.0.0.1 + } + +} +EOF +if [ $? -eq 1 ] +then + echo "Can't read keepalived config" + exit 1 +fi +sed -i "s/MASTER/$1/g" $CONF +sed -i "s/eth1/$2/g" $CONF +sed -i "s/0.0.0.1/$3/g" $CONF + +if [[ $1 == "BACKUP" ]];then + sed -i "s/102/103/g" $CONF +fi + +if [[ $4 == "1" ]];then + systemctl restart keepalived +fi +echo "success" \ No newline at end of file diff --git a/cgi-bin/scripts/install_haproxy.sh b/app/scripts/install_haproxy.sh similarity index 93% rename from cgi-bin/scripts/install_haproxy.sh rename to app/scripts/install_haproxy.sh index 39a8b9ff..d27ecc72 100644 --- a/cgi-bin/scripts/install_haproxy.sh +++ b/app/scripts/install_haproxy.sh @@ -2,7 +2,7 @@ yum install haproxy socat -y > /dev/null if [ -f /etc/haproxy/haproxy.cfg ];then - echo -e "error: Haproxy alredy installed" + echo -e 'error: Haproxy alredy installed. You can edit confighere' exit 1 fi echo "" > /etc/haproxy/haproxy.cfg diff --git a/cgi-bin/scripts/install_keepalived.sh b/app/scripts/install_keepalived.sh similarity index 91% rename from cgi-bin/scripts/install_keepalived.sh rename to app/scripts/install_keepalived.sh index 667325de..9d50832c 100644 --- a/cgi-bin/scripts/install_keepalived.sh +++ b/app/scripts/install_keepalived.sh @@ -2,7 +2,7 @@ CONF=/etc/keepalived/keepalived.conf if [ -f $CONF ];then - echo -e "error: Keepalived alredy installed" + echo -e 'error: Keepalived alredy installed. You can edit config here' exit 1 fi diff --git a/cgi-bin/settings.py b/app/settings.py similarity index 100% rename from cgi-bin/settings.py rename to app/settings.py diff --git a/cgi-bin/sql.py b/app/sql.py similarity index 100% rename from cgi-bin/sql.py rename to app/sql.py diff --git a/cgi-bin/update_db.py b/app/update_db.py similarity index 100% rename from cgi-bin/update_db.py rename to app/update_db.py diff --git a/cgi-bin/users.py b/app/users.py similarity index 100% rename from cgi-bin/users.py rename to app/users.py diff --git a/cgi-bin/viewlogs.py b/app/viewlogs.py similarity index 100% rename from cgi-bin/viewlogs.py rename to app/viewlogs.py diff --git a/cgi-bin/viewsttats.py b/app/viewsttats.py similarity index 100% rename from cgi-bin/viewsttats.py rename to app/viewsttats.py diff --git a/cgi-bin/hap_config/172.28.5.5.cfg b/configs/hap_config/172.28.5.5.cfg similarity index 100% rename from cgi-bin/hap_config/172.28.5.5.cfg rename to configs/hap_config/172.28.5.5.cfg diff --git a/configs/kp_config/172.28.5.5.cfg b/configs/kp_config/172.28.5.5.cfg new file mode 100644 index 00000000..90fec49b --- /dev/null +++ b/configs/kp_config/172.28.5.5.cfg @@ -0,0 +1 @@ +Just empty file for folder diff --git a/install.sh b/install.sh index 96a91eff..986d97ed 100644 --- a/install.sh +++ b/install.sh @@ -107,7 +107,7 @@ cat << EOF > /etc/httpd/conf.d/haproxy-wi.conf CustomLog /var/log/httpd/haproxy-wi.access.log combined DocumentRoot /var/www/$HOME_HAPROXY_WI - ScriptAlias "/cgi-bin/ "/var/www/$HOME_HAPROXY_WI/cgi-bin/" + ScriptAlias "/cgi-bin/ "/var/www/$HOME_HAPROXY_WI/app/" @@ -235,13 +235,13 @@ if [[ $DB == 2 ]];then echo "" echo "" echo "################################" - sed -i '0,/enable = 0/s//enable = 1/' /var/www/$HOME_HAPROXY_WI/cgi-bin/haproxy-webintarface.config + sed -i '0,/enable = 0/s//enable = 1/' /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config else - cd /var/www/$HOME_HAPROXY_WI/cgi-bin + cd /var/www/$HOME_HAPROXY_WI/app ./update_db.py fi if [[ -n $IP ]];then - sed -i "0,/mysql_host = 127.0.0.1/s//mysql_host = $IP/" /var/www/$HOME_HAPROXY_WI/cgi-bin/haproxy-webintarface.config + sed -i "0,/mysql_host = 127.0.0.1/s//mysql_host = $IP/" /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config fi echo "################################" echo "" @@ -274,7 +274,7 @@ else fi - sed -i "s|^fullpath = .*|fullpath = /var/www/$HOME_HAPROXY_WI|g" /var/www/$HOME_HAPROXY_WI/cgi-bin/haproxy-webintarface.config + sed -i "s|^fullpath = .*|fullpath = /var/www/$HOME_HAPROXY_WI|g" /var/www/$HOME_HAPROXY_WI/app/haproxy-webintarface.config echo "################################" echo "" echo "" @@ -287,7 +287,7 @@ echo "Edit firewalld" firewall-cmd --zone=public --add-port=$PORT/tcp --permanent firewall-cmd --reload -chmod +x /var/www/$HOME_HAPROXY_WI/cgi-bin/*.py +chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py chown -R apache:apache /var/www/$HOME_HAPROXY_WI/ rm -f /var/www/$HOME_HAPROXY_WI/log/config_edit.log