Fixed bugs
pull/19/head
Aidaho12 2018-01-26 10:24:20 +06:00
parent 23745ae61d
commit 06e8e65d85
5 changed files with 106 additions and 52 deletions

View File

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

View File

@ -23,9 +23,9 @@ form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
if serv is None: if serv is None:
first_serv = list(listhap.list_hap_vip.values()) first_serv = sorted(list(listhap.listhap.values()))
serv = first_serv[0] serv = first_serv[0]
try: try:
response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass)) response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass))
except requests.exceptions.ConnectTimeout: except requests.exceptions.ConnectTimeout:
@ -34,6 +34,7 @@ except requests.exceptions.ReadTimeout:
print('Oops. Read timeout occured') print('Oops. Read timeout occured')
print("Content-type: text/html\n") 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: for i in listhap.listhap:
if listhap.listhap.get(i) == serv: if listhap.listhap.get(i) == serv:
@ -54,4 +55,3 @@ print('</select><input type="submit"></p></form>')
data = dump.dump_all(response) data = dump.dump_all(response)
print('<a name="conf"></a>') print('<a name="conf"></a>')
print(data.decode('utf-8')) print(data.decode('utf-8'))

View File

@ -6,16 +6,13 @@ server_port = 8000
#Log for server.py #Log for server.py
log_path = %(fullpath)s/log/ log_path = %(fullpath)s/log/
time_zone = UTC time_zone = UTC
<<<<<<< HEAD
#Enable logo on top menu. Default disable #Enable logo on top menu. Default disable
logo_enable = 0 logo_enable = 0
logo_path = /logo.png logo_path = /logo.png
=======
>>>>>>> parent of fe00260... v1.3
[configs] [configs]
#Server for save configs from HAproxy servers #Server for save configs from HAproxy servers
haproxy_configs_server = haproxy_configs_server = localhost
#Dir where configs will be save #Dir where configs will be save
haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/ haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/
@ -28,7 +25,6 @@ ssh_user_name = root
[logs] [logs]
#Logs save localy, disable by default #Logs save localy, disable by default
local_path_logs = /var/log/haproxy.log local_path_logs = /var/log/haproxy.log
#
syslog_server_enable = enable syslog_server_enable = enable
syslog_server = 172.28.5.112 syslog_server = 172.28.5.112
@ -45,5 +41,5 @@ haproxy_config_path = /etc/haproxy/haproxy.cfg
tmp_config_path = /tmp tmp_config_path = /tmp
#Time in seconds for auto refresh view stats_port #Time in seconds for auto refresh view stats_port
refresh_time = 120 refresh_time = 120
=======
>>>>>>> parent of fe00260... v1.3

View File

@ -8,10 +8,9 @@
<link href="style.css" rel="stylesheet"> <link href="style.css" rel="stylesheet">
</head> </head>
<body> <body>
<<<<<<< HEAD
<center> <center>
<div class="conteinerIndex"> <div class="conteinerIndex">
<h2>Welcome! HAproxy Web Intarface</h2> <h2>Welcome! HAproxy Web Interface</h2>
<h3>Choose your destiny!</h3> <h3>Choose your destiny!</h3>
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br /> <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/edit.py" title="Edit settings">Edit settings</a> <br />
@ -26,7 +25,6 @@
</div> </div>
</div> </div>
</center> </center>
=======
<center> <center>
<h2>Welcome! HAproxy Web intarface</h2> <h2>Welcome! HAproxy Web intarface</h2>
<h3>Choose your destiny!</h3> <h3>Choose your destiny!</h3>
@ -39,6 +37,5 @@
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br /> <a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
</center> </center>
>>>>>>> parent of fe00260... v1.3
</body> </body>
</html> </html>

View File

@ -6,7 +6,7 @@ body {
font-size: 14px; font-size: 14px;
line-height: 1.42857143; line-height: 1.42857143;
color: #000; color: #000;
background-color: #fff; background-color: #eee;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
@ -18,6 +18,12 @@ body {
position: fixed; position: fixed;
right: 0; right: 0;
left: 0; left: 0;
z-index: 1000;
}
.top-menu img {
max-width: 125px;
float: left;
padding-left: 100px;
} }
.top-menu a, .footer a { .top-menu a, .footer a {
padding: 10px; padding: 10px;
@ -39,9 +45,79 @@ body {
margin-left: 35%; margin-left: 35%;
} }
.conteiner { .conteiner {
clear: both; clear: both;
margin-top: 65px; margin-top: 65px;
min-height: calc(100vh - 115px); min-height: calc(100vh - 115px);
width: 45%;
background-color: #fff;
margin-left: 27%;
}
.configShow, .diff {
margin-left: 16%;
max-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;
} }
.addName { .addName {
background-color: #eee; background-color: #eee;
@ -142,7 +218,9 @@ input::-moz-focus-inner {
border: 0; border: 0;
} }
input { input {
line-height: normal; line-height: normal;
border-radius: 4px;
padding: 4px;
} }
fieldset { fieldset {
@ -198,6 +276,7 @@ a:focus {
padding-left: 15px; padding-left: 15px;
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
}
.container-fluid { .container-fluid {
padding-right: 15px; padding-right: 15px;
padding-left: 15px; padding-left: 15px;