mirror of https://github.com/Aidaho12/haproxy-wi
parent
bc9bb95b28
commit
f451e44f5f
41
README.md
41
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
|
|||
```
|
||||

|
||||
|
||||
# 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
|
||||
```
|
||||

|
||||
|
||||
# Deb support
|
||||
|
||||
Sorry, but not use, because adapt yourself
|
||||
|
|
|
@ -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('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||
|
||||
print('</select>'
|
||||
'<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</div>'
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
|
@ -135,7 +136,7 @@ print('</select>'
|
|||
'<td class="addOption">'
|
||||
'<input type="text" name="ip" id="ip" title="" size="15" placeholder="172.28.0.1"><b>:</b>'
|
||||
'<input type="text" name="port" required title="Port for bind listner" size="5" placeholder="8080">'
|
||||
'<div class="tooltip tooltipTop">IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.</div>'
|
||||
'<div class="tooltip tooltipTop">IP for bind listner, <b>if empty will be assignet on all IPs</b>. Start typing ip, or press down.</div>'
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
|
@ -202,6 +203,7 @@ for i in sorted(listhap.listhap):
|
|||
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||
|
||||
print('</select>'
|
||||
'<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</div>'
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
|
@ -215,7 +217,7 @@ print('</select>'
|
|||
'<td class="addOption">'
|
||||
'<input type="text" name="ip" id="ip1" size="15" placeholder="172.28.0.1"><b>:</b>'
|
||||
'<input type="text" name="port" required title="Port for bind listner" size="5" placeholder="8080">'
|
||||
'<div class="tooltip tooltipTop">IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.</div>'
|
||||
'<div class="tooltip tooltipTop">IP for bind listner, <b>if empty will be assignet on all IPs</b>. Start typing ip, or press down.</div>'
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
|
@ -274,6 +276,7 @@ for i in sorted(listhap.listhap):
|
|||
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||
|
||||
print('</select>'
|
||||
'<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</div>'
|
||||
'</td>'
|
||||
'</tr>'
|
||||
'<tr>'
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -13,12 +13,12 @@ serv = form.getvalue('serv')
|
|||
|
||||
head("Edit & show HAproxy settings")
|
||||
|
||||
funct.check_login("edit.py")
|
||||
funct.check_login()
|
||||
|
||||
print('<center><h2>Edit & show HAproxy settings</h2></center>')
|
||||
print('<center><h3>Choose server & action: Disable/Enable server or output any information about the server:</h3>')
|
||||
print('<form action="edit.py" method="get">')
|
||||
print('<p><select autofocus required name="serv">')
|
||||
print('<p><select autofocus required name="serv" id="serv">')
|
||||
print('<option disabled selected>Choose server</option>')
|
||||
|
||||
funct.choose_server_with_vip(serv)
|
||||
|
@ -44,7 +44,7 @@ else:
|
|||
selected3 = ''
|
||||
|
||||
print('</select>')
|
||||
print('<select autofocus required name="servaction">')
|
||||
print('<select autofocus required name="servaction" id="chooseServer">')
|
||||
print('<option disabled selected>Choose action</option>')
|
||||
print('<option value=1 %s>Disable server</option>' % selected1)
|
||||
print('<option value=2 %s>Enable server</option>' % selected2)
|
||||
|
|
|
@ -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('<meta http-equiv="refresh" content="0; url=login.py?ref=%s">' % ref)
|
||||
|
|
|
@ -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('<center><form name="auth" action="login.py" class="form-horizontal" method="post">')
|
||||
=======
|
||||
|
||||
print('<center><div class="conteiner"><form name="auth" action="login.py" class="form-horizontal" method="post">')
|
||||
>>>>>>> parent of fe00260... v1.3
|
||||
print(printError)
|
||||
print('<label for="login"> Login: </label> <input type="text" name="login" class="form-control">')
|
||||
print('<label for="pass"> Pass: </label> <input type="password" name="pass" class="form-control">')
|
||||
print('<label for="login"> Login: </label> <input type="text" name="login" required class="form-control">')
|
||||
print('<label for="pass"> Pass: </label> <input type="password" name="pass" required class="form-control">')
|
||||
print('<input type="hidden" value="%s" name="ref">' % ref)
|
||||
print('<button type="submit" name="Login" value="Enter">Sign</button>')
|
||||
print('</form></div></center>')
|
||||
print('<button type="submit" name="Login" value="Enter">Sign Up</button>')
|
||||
print('</form></center>')
|
||||
|
||||
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('<html><head><title>Redirecting</title><meta charset="UTF-8">')
|
||||
print('<link href="/style.css" rel="stylesheet">')
|
||||
print('<meta http-equiv="refresh" content="0; url=%s">' % ref)
|
||||
funct.logging("localhost", "login now")
|
||||
break
|
||||
login_page("error")
|
||||
|
||||
|
|
|
@ -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('<center><h2>HAproxy Logs</h2></center>')
|
||||
print('<center><h3>Choose server & number rows</h3>')
|
||||
print('<form action="logs.py" method="get">')
|
||||
print('<p><select autofocus required name="serv">')
|
||||
print('<p><select autofocus required name="serv" id="serv">')
|
||||
print('<option disabled>Choose server</option>')
|
||||
|
||||
for i in sorted(listhap.listhap):
|
||||
|
|
|
@ -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('</select><input type="submit"></p></form>')
|
|||
data = dump.dump_all(response)
|
||||
print('<a name="conf"></a>')
|
||||
print(data.decode('utf-8'))
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue