mirror of https://github.com/Aidaho12/haproxy-wi
parent
77ffb2f36d
commit
6ef59643dd
|
@ -14,10 +14,11 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave
|
||||||
8. Editing configs
|
8. Editing configs
|
||||||
9. Rollback to previous versions of the config
|
9. Rollback to previous versions of the config
|
||||||
10. Master/slave servers
|
10. Master/slave servers
|
||||||
11. Comparing versions of configs
|
11. Configure firewalld on HAProxy servers based on config ports
|
||||||
12. Users roles: admin, editor, viewer
|
12. Comparing versions of configs
|
||||||
13. Server groups
|
13. Users roles: admin, editor, viewer
|
||||||
14. Telegram notification
|
14. Server groups
|
||||||
|
15. Telegram notification
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
The installer will ask you a few questions
|
The installer will ask you a few questions
|
||||||
|
|
|
@ -63,7 +63,8 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Can't read import config file")
|
print("Can't read import config file")
|
||||||
|
|
||||||
print("<center><b>New config was saved as: %s </b></br></br></center>" % cfg)
|
print('<center><div class="alert alert-info">New config was saved as: %s </div></center>' % cfg)
|
||||||
|
|
||||||
|
|
||||||
MASTERS = sql.is_master(serv)
|
MASTERS = sql.is_master(serv)
|
||||||
for master in MASTERS:
|
for master in MASTERS:
|
||||||
|
|
|
@ -199,7 +199,7 @@ def links():
|
||||||
'</li>')
|
'</li>')
|
||||||
print('</ul>'
|
print('</ul>'
|
||||||
'</nav>'
|
'</nav>'
|
||||||
'<div class="copyright-menu">HAproxy-WI v2.0.7</div>'
|
'<div class="copyright-menu">HAproxy-WI v2.0.8</div>'
|
||||||
'</div>')
|
'</div>')
|
||||||
|
|
||||||
def show_login_links():
|
def show_login_links():
|
||||||
|
@ -377,6 +377,7 @@ def upload(serv, path, file, **kwargs):
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
file = sftp.put(file, full_path)
|
file = sftp.put(file, full_path)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
ssh.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
|
print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
|
||||||
|
|
||||||
|
@ -385,9 +386,9 @@ def upload_and_restart(serv, cfg, **kwargs):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ssh = ssh_connect(serv)
|
ssh = ssh_connect(serv)
|
||||||
print("<center>connected to %s<br />" % serv)
|
print('<center><div class="alert alert-info">connected to %s</div>' % serv)
|
||||||
except:
|
except:
|
||||||
print("Connect fail")
|
print('<center><div class="alert alert-danger">Connect fail</div>')
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
sftp.put(cfg, tmp_file)
|
sftp.put(cfg, tmp_file)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
@ -396,32 +397,49 @@ def upload_and_restart(serv, cfg, **kwargs):
|
||||||
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path ]
|
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path ]
|
||||||
else:
|
else:
|
||||||
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command ]
|
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command ]
|
||||||
|
|
||||||
|
if config.get('haproxy', 'firewall_enable') == "1":
|
||||||
|
commands.extend(open_port_firewalld(cfg))
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for command in commands:
|
for command in commands:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
print("</br>Executing: {}".format( command ))
|
|
||||||
print("</br>")
|
|
||||||
stdin , stdout, stderr = ssh.exec_command(command)
|
stdin , stdout, stderr = ssh.exec_command(command)
|
||||||
print(stdout.read().decode(encoding='UTF-8'))
|
|
||||||
if i == 1:
|
if i == 1:
|
||||||
if not stderr.read():
|
if not stderr.read():
|
||||||
print('<h3 style="color: #23527c">Config ok</h3>')
|
print('<div class="alert alert-success">Config ok</div><pre>')
|
||||||
else:
|
else:
|
||||||
print('<h3 style="color: red">In your config have errors, please check, and try again</h3>')
|
print('<div class="alert alert-danger">In your config have errors, please check, and try again</div>')
|
||||||
print(stderr.read().decode(encoding='UTF-8'))
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
return False
|
return False
|
||||||
break
|
break
|
||||||
if i is not 1:
|
if i is not 1:
|
||||||
print("</br>Errors:")
|
|
||||||
print(stderr.read().decode(encoding='UTF-8'))
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
print("</br>")
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
print('</center>')
|
print('</center>')
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
|
def open_port_firewalld(cfg):
|
||||||
|
try:
|
||||||
|
conf = open(cfg, "r")
|
||||||
|
except IOError:
|
||||||
|
print('<div class="alert alert-danger">Can\'t read export config file</div>')
|
||||||
|
|
||||||
|
firewalld_commands = []
|
||||||
|
|
||||||
|
for line in conf:
|
||||||
|
if "bind" in line:
|
||||||
|
bind = line.split(":")
|
||||||
|
bind[1] = bind[1].strip(' ')
|
||||||
|
bind = bind[1].split("ssl")
|
||||||
|
bind = bind[0].strip(' \t\n\r')
|
||||||
|
firewalld_commands.append('firewall-cmd --zone=public --add-port=%s/tcp --permanent' % bind)
|
||||||
|
|
||||||
|
firewalld_commands.append('firewall-cmd --reload')
|
||||||
|
return firewalld_commands
|
||||||
|
|
||||||
def check_haproxy_config(serv):
|
def check_haproxy_config(serv):
|
||||||
commands = [ "/sbin/haproxy -q -c -f %s" % haproxy_config_path ]
|
commands = [ "/sbin/haproxy -q -c -f %s" % haproxy_config_path ]
|
||||||
ssh = ssh_connect(serv)
|
ssh = ssh_connect(serv)
|
||||||
|
@ -431,7 +449,8 @@ def check_haproxy_config(serv):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
ssh.close()
|
||||||
|
|
||||||
def compare(stdout):
|
def compare(stdout):
|
||||||
i = 0
|
i = 0
|
||||||
minus = 0
|
minus = 0
|
||||||
|
@ -514,6 +533,8 @@ def ssh_command(serv, commands, **kwargs):
|
||||||
print('<div style="margin: -10px;">'+stdout.read().decode(encoding='UTF-8')+'</div>')
|
print('<div style="margin: -10px;">'+stdout.read().decode(encoding='UTF-8')+'</div>')
|
||||||
|
|
||||||
print(stderr.read().decode(encoding='UTF-8'))
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
|
|
||||||
|
ssh.close()
|
||||||
|
|
||||||
def choose_only_select(serv, **kwargs):
|
def choose_only_select(serv, **kwargs):
|
||||||
if kwargs.get("virt"):
|
if kwargs.get("virt"):
|
||||||
|
@ -555,6 +576,6 @@ def chooseServer(formName, title, note, **kwargs):
|
||||||
print('</p></form>')
|
print('</p></form>')
|
||||||
|
|
||||||
if note == "y":
|
if note == "y":
|
||||||
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
|
print('<div class="alert alert-info"><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</div>')
|
||||||
print('</center>')
|
print('</center>')
|
||||||
|
|
||||||
|
|
|
@ -60,3 +60,5 @@ haproxy_sock = /var/run/haproxy.sock
|
||||||
#Temp store configs, for haproxy check
|
#Temp store configs, for haproxy check
|
||||||
tmp_config_path = /tmp
|
tmp_config_path = /tmp
|
||||||
cert_path = /etc/ssl/certs/
|
cert_path = /etc/ssl/certs/
|
||||||
|
#If enable this option Haproxy-wi will be configure firewalld based on config port
|
||||||
|
firewall_enable = 1
|
|
@ -28,6 +28,7 @@ if form.getvalue('getcert') is not None and serv is not None:
|
||||||
|
|
||||||
if form.getvalue('ssh_cert'):
|
if form.getvalue('ssh_cert'):
|
||||||
ssh_keys = config.get('ssh', 'ssh_keys')
|
ssh_keys = config.get('ssh', 'ssh_keys')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(ssh_keys, "w") as conf:
|
with open(ssh_keys, "w") as conf:
|
||||||
conf.write(form.getvalue('ssh_cert'))
|
conf.write(form.getvalue('ssh_cert'))
|
||||||
|
@ -87,16 +88,6 @@ if form.getvalue('ip') is not None and serv is not None:
|
||||||
commands = [ "ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ]
|
commands = [ "ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ]
|
||||||
funct.ssh_command(serv, commands, ip="1")
|
funct.ssh_command(serv, commands, ip="1")
|
||||||
|
|
||||||
if form.getvalue('name') is not None:
|
|
||||||
name = form.getvalue('name')
|
|
||||||
conf = open("/home/ploginov/haproxy/cgi-bin/hap_config/test.cfg", "r")
|
|
||||||
s = form.getvalue('s')
|
|
||||||
for line in conf:
|
|
||||||
|
|
||||||
if s in line and name in line:
|
|
||||||
print("yes")
|
|
||||||
break
|
|
||||||
|
|
||||||
if form.getvalue('action') is not None and serv is not None:
|
if form.getvalue('action') is not None and serv is not None:
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
action = form.getvalue('action')
|
action = form.getvalue('action')
|
||||||
|
@ -225,8 +216,4 @@ if form.getvalue('viewlogs') is not None:
|
||||||
print('<div class="line3">' + line + '</div>')
|
print('<div class="line3">' + line + '</div>')
|
||||||
else:
|
else:
|
||||||
print('<div class="line">' + line + '</div>')
|
print('<div class="line">' + line + '</div>')
|
||||||
|
|
||||||
if form.getvalue('tailf_stop') is not None:
|
|
||||||
serv = form.getvalue('serv')
|
|
||||||
commands = [ "ps ax |grep python3 |grep -v grep |awk '{ print $1 }' |xargs kill" ]
|
|
||||||
funct.ssh_command(serv, commands)
|
|
|
@ -79,7 +79,7 @@ def get_overview():
|
||||||
print('</td><td>')
|
print('</td><td>')
|
||||||
if funct.is_admin():
|
if funct.is_admin():
|
||||||
print('<a id="%s" class="start" title="Start HAproxy service" onclick = "if (! confirm(\'Start service?\')) return false;"><img src=/image/pic/start.png alt="start" class="icon"></a>' % server[2])
|
print('<a id="%s" class="start" title="Start HAproxy service" onclick = "if (! confirm(\'Start service?\')) return false;"><img src=/image/pic/start.png alt="start" class="icon"></a>' % server[2])
|
||||||
print('<a id="%s" class="stop" title="Stop HAproxy service" onclick = "if (! confirm(\'Stop service?\')) return false;"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % server[2])
|
print('<a id="%s" class="stop" title="Stop HAproxy service" onclick = "return confirm(\'Stop service?\')"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % server[2])
|
||||||
print('<a id="%s" class="restart" title="Restart HAproxy service" onclick = "if (! confirm(\'Restart service?\')) return false;"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % server[2])
|
print('<a id="%s" class="restart" title="Restart HAproxy service" onclick = "if (! confirm(\'Restart service?\')) return false;"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % server[2])
|
||||||
print('<a href="/cgi-bin/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % server[2])
|
print('<a href="/cgi-bin/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % server[2])
|
||||||
print('<a href="/cgi-bin/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % server[2])
|
print('<a href="/cgi-bin/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % server[2])
|
||||||
|
|
|
@ -530,6 +530,10 @@ a:focus {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
.alert-danger, .alert-info, .alert-success {
|
||||||
|
width: 400px;
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
.alert-danger {
|
.alert-danger {
|
||||||
color: #a94442;
|
color: #a94442;
|
||||||
background-color: #f2dede;
|
background-color: #f2dede;
|
||||||
|
@ -538,14 +542,17 @@ a:focus {
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
margin-bottom: -50px;
|
margin-bottom: -50px;
|
||||||
margin-left: 20px;
|
|
||||||
}
|
}
|
||||||
.alert-success {
|
.alert-success {
|
||||||
color: #3c763d;
|
color: #3c763d;
|
||||||
background-color: #dff0d8;
|
background-color: #dff0d8;
|
||||||
border-color: #d6e9c6;
|
border-color: #d6e9c6;
|
||||||
width: 400px;
|
|
||||||
margin-left: 15px;
|
}
|
||||||
|
.alert-info {
|
||||||
|
color: #0c5460;
|
||||||
|
background-color: #d1ecf1;
|
||||||
|
border-color: #bee5eb;
|
||||||
}
|
}
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
Loading…
Reference in New Issue