diff --git a/README.md b/README.md index 4ba9a2a8..f5bbae68 100644 --- a/README.md +++ b/README.md @@ -13,26 +13,19 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers 7. Rollback to previous versions of the config 8. Comparing versions of configs 9. Users roles: admin, viewer +10. Telegram notification # Install For install just dowload archive and untar somewhere: ``` $ cd /opt $ unzip master.zip -$ mv haproxy-web-interface-master/ haproxy -$ cd /opt/haproxy -$ pip3 install -r requirements.txt -$ chmod +x server.py -$ chmod +x -R cgi-bin/ -$ chown user:user -R haproxy +$ mv haproxy-wi-master/ haproxy-wi +$ cd /opt/haproxy-wi +$ chmod +x install.sh ``` Edit listserv.py, add your HAproxy servers. -If foler not /opt/haproxy/, edit server.py: -``` -path_config = "/opt/haproxy/haproxy-webintarface.config" -``` - # Settings edit haproxy-webintarface.config with your env @@ -46,24 +39,12 @@ global ``` ![alt text](image/4.jpeg "View logs page") -# Start -Create systemd service to auto start: +# Start and auto start ``` -[Unit] -Description=Haproxy web interface -After=syslog.target network.target - -[Service] -Type=simple -User=user_name - -ExecStart=/opt/haproxy/server.py >> /opt/haproxy/log/haproxy-webface.log - -RestartSec=2s -Restart=on-failure -TimeoutStopSec=1s - -[Install] -WantedBy=multi-user.target +systemctl enable haproxy-wi.service +systemctl start haproxy-wi.service ``` -![alt text](image/1.jpeg "Start page") + +# Deb support + +Sorry, but not use, because adapt yourself diff --git a/cgi-bin/add.py b/cgi-bin/add.py index aa9fef61..d741f5b8 100644 --- a/cgi-bin/add.py +++ b/cgi-bin/add.py @@ -13,7 +13,7 @@ from pytz import timezone funct.head("Add") funct.check_config() -funct.check_login("add.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() @@ -122,6 +122,7 @@ for i in sorted(listhap.listhap): print('' % (listhap.listhap.get(i), i)) print('' + '
Note: If you reconfigure First server, second will reconfigured automatically
' '' '' '' @@ -135,7 +136,7 @@ print('' '' ':' '' - '
IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.
' + '
IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.
' '' '' '' @@ -202,6 +203,7 @@ for i in sorted(listhap.listhap): print('' % (listhap.listhap.get(i), i)) print('' + '
Note: If you reconfigure First server, second will reconfigured automatically
' '' '' '' @@ -215,7 +217,7 @@ print('' '' ':' '' - '
IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.
' + '
IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.
' '' '' '' @@ -274,6 +276,7 @@ for i in sorted(listhap.listhap): print('' % (listhap.listhap.get(i), i)) print('' + '
Note: If you reconfigure First server, second will reconfigured automatically
' '' '' '' diff --git a/cgi-bin/config.py b/cgi-bin/config.py index 4c446c84..7319ad81 100644 --- a/cgi-bin/config.py +++ b/cgi-bin/config.py @@ -17,7 +17,7 @@ servNew = form.getvalue('serNew') funct.head("Edit HAproxy config") funct.check_config() -funct.check_login("config.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() diff --git a/cgi-bin/configshow.py b/cgi-bin/configshow.py index fd9a12cc..6e7626cf 100644 --- a/cgi-bin/configshow.py +++ b/cgi-bin/configshow.py @@ -15,7 +15,7 @@ servNew = form.getvalue('serNew') funct.head("Show HAproxy config") funct.check_config() -funct.check_login("configshow.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() diff --git a/cgi-bin/configver.py b/cgi-bin/configver.py index 5ced61cd..97b9dc13 100644 --- a/cgi-bin/configver.py +++ b/cgi-bin/configver.py @@ -17,7 +17,7 @@ configver = form.getvalue('configver') funct.head("Old Versions HAproxy config") funct.check_config() -funct.check_login("configver.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() diff --git a/cgi-bin/diff.py b/cgi-bin/diff.py index 03c99e39..ea7420a4 100644 --- a/cgi-bin/diff.py +++ b/cgi-bin/diff.py @@ -17,7 +17,7 @@ right = form.getvalue('right') funct.head("Compare HAproxy configs") funct.check_config() -funct.check_login("diff.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py index 7b7f5a22..442b6426 100644 --- a/cgi-bin/edit.py +++ b/cgi-bin/edit.py @@ -13,12 +13,12 @@ serv = form.getvalue('serv') head("Edit & show HAproxy settings") -funct.check_login("edit.py") +funct.check_login() print('

Edit & show HAproxy settings

') print('

Choose server & action: Disable/Enable server or output any information about the server:

') print('
') -print('

') print('') funct.choose_server_with_vip(serv) @@ -44,7 +44,7 @@ else: selected3 = '' print('') -print('') print('') print('' % selected1) print('' % selected2) diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index c18caf0c..c4b712a1 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -57,9 +57,10 @@ def telegram_send_mess(mess): bot = telegram.Bot(token=token_bot, request=pp) bot.send_message(chat_id=channel_name, text=mess) -def check_login(ref): +def check_login(): cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) login = cookie.get('login') + ref = os.environ.get("SCRIPT_NAME") if login is None: print('' % ref) diff --git a/cgi-bin/login.py b/cgi-bin/login.py index 35c74724..02c31506 100644 --- a/cgi-bin/login.py +++ b/cgi-bin/login.py @@ -13,7 +13,7 @@ login = form.getvalue('login') password = form.getvalue('pass') USERS = 'cgi-bin/users' -funct.check_login("login.py") +funct.check_login() try: with open(USERS, "r") as user: @@ -32,19 +32,14 @@ def login_page(error): ref = "/index.html" funct.head("Login page") -<<<<<<< HEAD print('

') -======= - - print('
') ->>>>>>> parent of fe00260... v1.3 print(printError) - print(' ') - print(' ') + print(' ') + print(' ') print('' % ref) - print('') - print('
') + print('') + print('
') if form.getvalue('logout') is not None: print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly") @@ -71,6 +66,7 @@ if login is not None and password is not None: print('Redirecting') print('') print('' % ref) + funct.logging("localhost", "login now") break login_page("error") diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index 27a5f20c..22f6f136 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -12,7 +12,7 @@ serv = form.getvalue('serv') funct.head("HAproxy Logs") funct.check_config() -funct.check_login("config.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() @@ -21,7 +21,7 @@ config.read(path_config) print('

HAproxy Logs

') print('

Choose server & number rows

') print('
') -print('

') print('') for i in sorted(listhap.listhap): diff --git a/cgi-bin/viewsttats.py b/cgi-bin/viewsttats.py index 786a1e2f..4d71ad4d 100644 --- a/cgi-bin/viewsttats.py +++ b/cgi-bin/viewsttats.py @@ -8,7 +8,7 @@ import configparser from requests_toolbelt.utils import dump funct.check_config() -funct.check_login("config.py") +funct.check_login() path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() @@ -55,3 +55,4 @@ print('

') data = dump.dump_all(response) print('') print(data.decode('utf-8')) + diff --git a/haproxy-webintarface.config b/haproxy-webintarface.config index 4f712903..5b709c8b 100644 --- a/haproxy-webintarface.config +++ b/haproxy-webintarface.config @@ -1,6 +1,6 @@ [main] #Path to files destination -fullpath = /opt/haproxy/ +fullpath = /opt/haproxy-wi/ server_bind_ip = 0.0.0.0 server_port = 8000 log_path = %(fullpath)s/log/ @@ -13,13 +13,13 @@ logo_path = /logo.png #Server for save configs from HAproxy servers haproxy_configs_server = localhost #Dir where configs will be save -haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/ +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/cgi-bin/id_rsa.pem +ssh_keys = /opt/haproxy-wi/cgi-bin/id_rsa.pem #Username for connect ssh ssh_user_name = root ssh_pass = diff --git a/haproxy-wi.service b/haproxy-wi.service new file mode 100644 index 00000000..21d52e6f --- /dev/null +++ b/haproxy-wi.service @@ -0,0 +1,16 @@ +[Unit] +Description=Haproxy web interface +After=syslog.target network.target + +[Service] +Type=simple +User=haproxy-wi + +ExecStart=/opt/haproxy/server.py >> /opt/haproxy/log/haproxy-webface.log + +RestartSec=2s +Restart=on-failure +TimeoutStopSec=1s + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 00000000..711c0273 --- /dev/null +++ b/install.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +echo "Enter dir for HAproxy-WI. Default: [/opt/haproxy-wi]" +read DIR +echo "Enter user for HAproxy-WI. Defailt: [haproxy-wi]" +read USER + +if [[ $DIR = "" ]]; then + DIR="/opt/haproxy-wi" +else + sed -i "s!/opt/haproxy-wi!$DIR!" haproxy-webintarface.config + sed -i "s!/opt/haproxy-wi!$DIR!" server.py + sed -i "s!/opt/haproxy-wi!$DIR!" haproxy-wi.service +fi + +if [[ $USER = "" ]]; then + USER="haproxy-wi" +fi + +echo "Install req" +pip3 install -r requirements.txt + +echo "Add user $USER" +useradd $USER -d $DIR -s /sbin/nologin + +chmod +x server.py +chmod +x cgi-bin/*.py +chown $USER:$USER -R * + +echo "Creating service" +sed -i "s/haproxy-wi/$USER/" haproxy-wi.service +mv haproxy-wi.service /etc/systemd/system +systemctl daemon-reload \ No newline at end of file diff --git a/server.py b/server.py index 7d2b2e3f..54a2cc34 100644 --- a/server.py +++ b/server.py @@ -2,7 +2,7 @@ import os, sys import configparser -path_config = "/opt/haproxy/haproxy-webintarface.config" +path_config = "/opt/haproxy-wi/haproxy-webintarface.config" config = configparser.ConfigParser() config.read(path_config) log_path = config.get('main', 'log_path')