Fixed bugs
pull/19/head
Aidaho12 2018-01-26 10:08:34 +06:00
parent 7876302313
commit 23745ae61d
13 changed files with 101 additions and 131 deletions

1
.gitignore vendored
View File

@ -99,4 +99,3 @@ ENV/
# mypy
.mypy_cache/
cgi-bin/hap_config/172.28.5.5-2018-01-10.13\:56\:02.cfg

View File

@ -17,10 +17,16 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers
# Install
For install just dowload archive and untar somewhere:
```
$ cd /opt/haproxy-webintarface
$ tar xf haproxy-webintarface-master.zip
$ pip3 -r requirements.txt
$ cd /opt
$ unzip master.zip
$ mv haproxy-web-interface-master/ haproxy
$ pip3 install -r requirements.txt
$ chmod +x server.py
$ chmod +x -R cgi-bin/
$ chown user:user -R haproxy
```
Edit listserv.py, add your HAproxy servers.
If foler not /opt/haproxy/, edit server.py:
```
path_config = "/opt/haproxy/haproxy-webintarface.config"
@ -48,7 +54,7 @@ After=syslog.target network.target
[Service]
Type=simple
User=user
User=user_name
ExecStart=/opt/haproxy/server.py >> /opt/haproxy/log/haproxy-webface.log

View File

@ -35,12 +35,12 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('<form action="diff.py#diff" method="get">')
print('<center><h3><span style="padding: 75px;">Choose left</span><span style="padding: 100px;">Choose right</span></h3>')
print('<p><select autofocus required name="left" id="left">')
print('<p><select autofocus required name="left">')
print('<option disabled selected>Choose version</option>')
os.chdir(hap_configs_dir)
for files in sorted(glob.glob('*.cfg')):
for files in glob.glob('*.cfg'):
ip = files.split("-")
if serv == ip[0]:
if left == files:
@ -51,10 +51,10 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('</select>')
print('<select autofocus required name="right" id="right">')
print('<select autofocus required name="right">')
print('<option disabled selected>Choose version</option>')
for files in sorted(glob.glob('*.cfg')):
for files in glob.glob('*.cfg'):
ip = files.split("-")
if serv == ip[0]:
if right == files:
@ -66,11 +66,13 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('</select>')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="open" name="open">')
print('<p><button type="submit" value="Compare" name="Compare">Compare</button></p></form></center>')
print('<p><button type="submit" value="Compare" name="Compare">Compare</button></p></form>')
if form.getvalue('serv') is not None and form.getvalue('right') is not None:
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
funct.ssh_command(haproxy_configs_server, commands, compare="compare")
print('<h3><a href="#top" title="UP">UP</a></center>')
funct.footer()

View File

@ -18,7 +18,7 @@ funct.check_login("edit.py")
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" id="serv">')
print('<p><select autofocus required name="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" id="chooseServer">')
print('<select autofocus required name="servaction">')
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)

View File

@ -12,7 +12,8 @@ def check_config():
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]:
if not config.has_section(section):
print('<b style="color: red">Check config file, no %s section</b>' % section)
@ -70,7 +71,6 @@ def mode_admin(button):
def links():
print('<a href=/ title="Home Page" style="size:5">Home Page</a> ')
print('<a href=/cgi-bin/viewsttats.py title="View Stats" style="size:5">Stats</a> ')
print('<a href="http://172.28.5.106:3000/dashboard/db/haproxy" title="Mon" target="_blanck">Monitoring</a> ')
print('<a href=/cgi-bin/logs.py title="View logs" style="size:6">Logs</a>')
print('<a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> ')
print('<span style="color: #fff"> | Configs: </span>')
@ -82,8 +82,9 @@ def links():
show_login_links()
def head(title):
print('Content-type: text/html\n')
print("Content-type: text/html\n")
print('<html><head><title>%s</title>' % title)
<<<<<<< HEAD
print('<link href="/favicon.ico" rel="icon" type="image/png" />'
'<link href="/style.css" rel="stylesheet"><meta charset="UTF-8">'
'<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'
@ -97,18 +98,18 @@ def head(title):
if config.get('main', 'logo_enable') == "1":
print('<img src="%s" title="Logo" class="logo">' % config.get('main', 'logo_path'))
print('<div class="top-link">')
=======
print('<link href="/favicon.ico" rel="icon" type="image/png" />')
print('<link href="/style.css" rel="stylesheet"><meta charset="UTF-8"></head><body>')
print('<a name="top"></a>')
print('<div class="top-menu"><div class="top-link">')
>>>>>>> parent of fe00260... v1.3
links()
print('</div></div><div class="conteiner">')
def footer():
print('<center>'
'<h3>'
'<a href="#top" title="UP">UP</a>'
'</h3>'
'</center>'
'</center></div>'
'<div class="footer">'
'<div class="footer-link">')
print('<center><h3><a href="#top" title="UP">UP</a></center>')
print('</center></div><div class="footer"><div class="footer-link">')
links()
print('</div></div></body></html>')
@ -152,9 +153,9 @@ def show_config(cfg):
print('</span>' + line + '</div>')
continue
if "#" in line:
print('<div class="comment"><span class="numRow">')
print('<div class="comment">')
print(i)
print(line + '</span></div>')
print(line + '</div>')
continue
print('<div class="configLine"><span class="numRow">')
print(i)
@ -202,6 +203,7 @@ def upload_and_restart(serv, cfg):
return True
ssh.close()
<<<<<<< HEAD
def compare(stdout):
i = 0
@ -250,6 +252,10 @@ def show_ip(stdout):
print(line)
def ssh_command(serv, commands, **kwargs):
=======
def ssh_command(serv, commands):
>>>>>>> parent of fe00260... v1.3
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
@ -271,6 +277,7 @@ def ssh_command(serv, commands, **kwargs):
for command in commands:
stdin , stdout, stderr = ssh.exec_command(command)
<<<<<<< HEAD
if ip is 1:
show_ip(stdout)
@ -280,13 +287,24 @@ def ssh_command(serv, commands, **kwargs):
show_log(stdout)
print(stderr.read().decode(encoding='UTF-8'))
=======
print('</center><div class="out">')
i = 1
for line in stdout:
i = i + 1
if i % 2 == 0:
print('<div class="line">' + line + '</div>')
else:
print('<div class="line2">' + line + '</div>')
print('</div>')
>>>>>>> parent of fe00260... v1.3
ssh.close()
def chooseServer(formName, title, note):
print('<center><h2>' + title + '</h2>')
print('<h3>Choose server</h3>')
print('<form action=' + formName + ' method="get">')
print('<p><select autofocus required name="serv" id="chooseServer">')
print('<p><select autofocus required name="serv">')
print('<option disabled>Choose server</option>')
form = cgi.FieldStorage()
@ -304,7 +322,7 @@ def chooseServer(formName, title, note):
print('</select>')
print('<p><button type="submit" value="open" name="open">Open</button></p></form>')
if note == "y":
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p><br />')
def choose_server_with_vip(serv):
import listserv as listhap

View File

@ -32,14 +32,19 @@ 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('<input type="hidden" value="%s" name="ref">' % ref)
print('<button type="submit" name="Login" value="Enter">Sign Up</button>')
print('</form></center>')
print('<button type="submit" name="Login" value="Enter">Sign</button>')
print('</form></div></center>')
if form.getvalue('logout') is not None:
print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")

View File

@ -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" id="serv">')
print('<p><select autofocus required name="serv">')
print('<option disabled>Choose server</option>')
for i in sorted(listhap.listhap):

View File

@ -25,7 +25,7 @@ serv = form.getvalue('serv')
if serv is None:
first_serv = list(listhap.list_hap_vip.values())
serv = first_serv[0]
try:
response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass))
except requests.exceptions.ConnectTimeout:
@ -34,7 +34,6 @@ except requests.exceptions.ReadTimeout:
print('Oops. Read timeout occured')
print("Content-type: text/html\n")
print('<meta http-equiv="refresh" content="%s; url=viewsttats.py?serv=%s">' % (config.get('haproxy', 'refresh_time') ,serv))
for i in listhap.listhap:
if listhap.listhap.get(i) == serv:

View File

@ -3,15 +3,19 @@
fullpath = /opt/haproxy/
server_bind_ip = 0.0.0.0
server_port = 8000
#Log for server.py
log_path = %(fullpath)s/log/
time_zone = UTC
<<<<<<< HEAD
#Enable logo on top menu. Default disable
logo_enable = 0
logo_path = /logo.png
=======
>>>>>>> parent of fe00260... v1.3
[configs]
#Server for save configs from HAproxy servers
haproxy_configs_server = kz-web14
haproxy_configs_server =
#Dir where configs will be save
haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/
@ -22,9 +26,9 @@ ssh_keys = /opt/haproxy/cgi-bin/id_rsa.pem
ssh_user_name = root
[logs]
#Logs save locally, disable by default
#Logs save localy, disable by default
local_path_logs = /var/log/haproxy.log
#If exist syslog server for HAproxy logs
#
syslog_server_enable = enable
syslog_server = 172.28.5.112
@ -36,7 +40,10 @@ user = admin
password = password
stats_port = 8085
haproxy_config_path = /etc/haproxy/haproxy.cfg
<<<<<<< HEAD
#Temp store configs, for haproxy check
tmp_config_path = /tmp
#Time in seconds for auto refresh view stats_port
refresh_time = 120
refresh_time = 120
=======
>>>>>>> parent of fe00260... v1.3

View File

@ -8,6 +8,7 @@
<link href="style.css" rel="stylesheet">
</head>
<body>
<<<<<<< HEAD
<center>
<div class="conteinerIndex">
<h2>Welcome! HAproxy Web Intarface</h2>
@ -25,5 +26,19 @@
</div>
</div>
</center>
=======
<center>
<h2>Welcome! HAproxy Web intarface</h2>
<h3>Choose your destiny!</h3>
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</a> <br />
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
</center>
>>>>>>> parent of fe00260... v1.3
</body>
</html>

View File

@ -1,9 +1,7 @@
html
cgi
os
http.cookies
configparser
paramiko
pytz
requests
json
configparser==3.5.0
paramiko==2.4.0
pytz==2017.3
requests==2.18.4
requests_toolbelt==0.8.0
telegram==0.0.1
dump==0.0.3

View File

@ -12,9 +12,9 @@ server_port = config.getint('main', 'server_port')
from http.server import HTTPServer, CGIHTTPRequestHandler
sys.stderr = open(log_path + '/opt/haproxy/log/haproxy-monitor.log', 'w')
sys.stderr = open(log_path + '/haproxy-monitor.log', 'w')
webdir = fullpath
os.chdir(webdir)
server_address = (server_bind_ip, server_port)
httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
httpd.serve_forever()
httpd.serve_forever()

View File

@ -6,7 +6,7 @@ body {
font-size: 14px;
line-height: 1.42857143;
color: #000;
background-color: #eee;
background-color: #fff;
margin: 0;
padding: 0;
}
@ -18,12 +18,6 @@ body {
position: fixed;
right: 0;
left: 0;
z-index: 1000;
}
.top-menu img {
max-width: 125px;
float: left;
padding-left: 100px;
}
.top-menu a, .footer a {
padding: 10px;
@ -45,79 +39,9 @@ body {
margin-left: 35%;
}
.conteiner {
clear: both;
margin-top: 65px;
min-height: calc(100vh - 115px);
width: 45%;
background-color: #fff;
margin-left: 27%;
}
.configShow, .diff {
margin-left: 16%;
height: 70%;
overflow: auto;
width: 70%;
border: 1px solid #DCDCDC;
border-radius: 5px;
}
.diffHead {
background-color: #F5F5F5;
padding: 10px;
}
.lineDog {
background-color: #dbedff;
margin-bottom: 10px;
}
.lineDiffMinus, .lineDiffPlus {
padding-left: 5px;
}
.lineDiffMinus {
background-color: #ffdce0;
}
.lineDiffPlus {
background-color: #cdffd8;
}
.lineDiff {
padding-left: 5px;
}
.param {
font-weight: bold;
background-color: #DCDCDC;
padding-left: 13px;
}
.numRow {
padding-left: 10px;
padding-right: 20px;
}
.paramInSec {
font-weight: bold;
}
.conteinerIndex {
width: 20%;
background-color: #fff;
padding: 20px;
border-radius: 10px;
margin-top: 2%;
}
.conteinerIndex img {
max-width: 250px;
}
.copyright {
color: #23527c;
margin-left: 15px;
}
.line {
background-color: #eee;
border: 1px solid #000;
}
.line, .line3 {
padding-top:5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
}
.comment {
color: #aaa;
clear: both;
margin-top: 65px;
min-height: calc(100vh - 115px);
}
.addName {
background-color: #eee;
@ -218,9 +142,7 @@ input::-moz-focus-inner {
border: 0;
}
input {
line-height: normal;
border-radius: 4px;
padding: 4px;
line-height: normal;
}
fieldset {
@ -276,7 +198,6 @@ a:focus {
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.container-fluid {
padding-right: 15px;
padding-left: 15px;