Revert "v1.4"

This reverts commit 555488f48d.
pull/19/head
Aidaho12 2018-01-25 15:04:17 +06:00
parent 000bb84018
commit 55308cc234
17 changed files with 90 additions and 691 deletions

View File

@ -1,334 +0,0 @@
#!/usr/bin/env python3
import html
import cgi
import listserv as listhap
import os
import funct
import paramiko
import configparser
import http.cookies
from paramiko import SSHClient
from datetime import datetime
from pytz import timezone
funct.head("Add")
funct.check_config()
funct.check_login("add.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
form = cgi.FieldStorage()
if form.getvalue('mode') is not None:
serv = form.getvalue('serv')
port = form.getvalue('port')
mode = " mode " + form.getvalue('mode')
if form.getvalue('balance') is not None:
balance = " balance " + form.getvalue('balance') + "\n"
else:
balance = ""
if form.getvalue('ip') is not None:
ip = form.getvalue('ip')
else:
ip = ""
if form.getvalue('listner') is not None:
name = "listen " + form.getvalue('listner')
backend = ""
elif form.getvalue('frontend') is not None:
name = "\nfrontend " + form.getvalue('frontend')
backend = " default_backend " + form.getvalue('backend') + "\n"
elif form.getvalue('backend') is not None:
name = "backend " + form.getvalue('backend')
backend = ""
if not ip and form.getvalue('port') is not None:
bind = " bind *:"+ port + "\n"
elif port is not None:
bind = " bind " + ip + ":" + port + "\n"
else:
bind = ""
if form.getvalue('option') is not None:
options = form.getvalue('option')
i = options.split("\n")
options_split = ""
for j in i:
options_split += " " + j + "\n"
else:
options_split = ""
if form.getvalue('servers') is not None:
servers = form.getvalue('servers')
i = servers.split("\n")
servers_split = ""
for j in i:
servers_split += " " + j + "\n"
else:
servers_split = ""
config_add = name + "\n" + bind + mode + "\n" + balance + options_split + backend + servers_split + "\n"
os.chdir(config.get('configs', 'haproxy_save_configs_dir'))
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.get_config(serv, cfg)
try:
with open(cfg, "a") as conf:
conf.write(config_add)
#print('<meta http-equiv="refresh" content="50; url=add.py?add=%s&conf=%s">' % (name, config_add))
except IOError:
print("Can't read import config file")
funct.logging(serv, "add.py add new %s" % name)
print('<div class="line3">')
if funct.upload_and_restart(serv, cfg):
print('<meta http-equiv="refresh" content="30; url=add.py?add=%s&conf=%s">' % (name, config_add))
print('</div>')
if form.getvalue('add') is not None:
print('<h3 class="addSuc"> ' + form.getvalue('add') + ' was successfully added</h3>')
print('<div class="line3">')
print(form.getvalue('conf'))
print('</div>')
print('<div id="tabs">'
'<ul>'
'<li><a href="#listner">Listner</a></li>'
'<li><a href="#frontend">Frontend</a></li>'
'<li><a href="#backend">Backend</a></li>'
'</ul>'
'<div id="listner">'
'<form name="add-listner" action="add.py">'
'<table>'
'<caption>Add listner</caption>'
'<tr>'
'<td class="addName">Select server: </td>'
'<td class="addOption">'
'<select required name="serv" id="serv">'
'<option disabled selected>Choose server</option>')
for i in sorted(listhap.listhap):
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
print('</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Name:</td>'
'<td class="addOption">'
'<input type="text" name="listner" id="name" required title="Name Listner" placeholder="web_80">'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">IP and Port:</td>'
'<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>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Mode: </td>'
'<td class="addOption">'
'<select required name="mode">'
'<option value="http" selected>http</option>'
'<option value="tcp">tcp</option>'
'</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Balance: </td>'
'<td class="addOption">'
'<select required name="balance">'
'<option value="roundrobin" selected>roundrobin</option>'
'<option value="source">source</option>'
'<option value="leastconn">leastconn</option>'
'<option value="first">first</option>'
'<option value="rdp-cookie">rdp-cookie</option>'
'</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Optinons:</td>'
'<td class="addOption">'
'<div class="tooltip">'
'<span style="padding-right: 10px;">Start typing options: </span>'
'<input type="text" id="options" >'
'<span style="padding-left: 10px;">'
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
'</span>'
'</div>'
'<textarea name="option" title="Options thru" id="optionsInput" cols=80 placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Servers:</td>'
'<td class="addOption">'
'<textarea name="servers" required title="Backend servers" cols=80 placeholder="server server.local 172.28.0.1:8080 check"></textarea>'
'</td>'
'</tr>'
'<tr>'
'<td class="addButton">')
funct.mode_admin("Add Listner")
print('</td>'
'</tr>'
'</form>'
'</table></div>'
'<!-- Second tabs -->'
'<div id="frontend">'
'<form name="add-frontend" action="add.py">'
'<table>'
'<caption>Add frontend</caption>'
'<tr>'
'<td class="addName">Select server: </td>'
'<td class="addOption">'
'<select required name="serv" id="serv2">'
'<option disabled selected>Choose server</option>')
for i in sorted(listhap.listhap):
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
print('</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Name:</td>'
'<td class="addOption">'
'<input type="text" name="frontend" id="frontend" required title="Name frontend" placeholder="web_80" >'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">IP and Port:</td>'
'<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>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Mode: </td>'
'<td class="addOption">'
'<select required name="mode">'
'<option value="http" selected>http</option>'
'<option value="tcp">tcp</option>'
'</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Optinons:</td>'
'<td class="addOption">'
'<div style="font-size: 12px; padding-bottom: 10px;">'
'<span style="padding-right: 10px;">Start typing options: </span>'
'<input type="text" id="options1" >'
'<span style="padding-left: 10px;">'
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
'</span>'
'</div>'
'<textarea name="option" title="Options thru" cols=80 id="optionsInput1" placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Default backend</td>'
'<td class="addOption">'
'<div style="font-size: 12px; padding-bottom: 10px;">Start typing backend, or press down</div>'
'<input name="backend" id="backends" required size="30" placeholder="some_backend">'
'<span style="font-size: 12px; padding-left: 10px;"> .</span>'
'<p style="font-size: 12px"><b>Note:</b> If backend don\'t exist, you must <a href="#" style="color: #23527c" title="Create backend" id="redirectBackend">create backend first</a>.</p>'
'</td>'
'</tr>'
'<tr>'
'<td class="addButton">')
funct.mode_admin("Add Frontend")
print('</td>'
'</tr>'
'</form></table>'
'</div>'
'<!-- Third tabs -->'
'<div id="backend">'
'<form name="add-backend" action="add.py">'
'<table>'
'<caption>Add frontend</caption>'
'<tr>'
'<td class="addName">Select server: </td>'
'<td class="addOption">'
'<select required name="serv">'
'<option disabled selected>Choose server</option>')
for i in sorted(listhap.listhap):
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
print('</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Name:</td>'
'<td class="addOption">'
'<input type="text" name="backend" id="backend" required title="Name backend" placeholder="web_80" >'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Mode: </td>'
'<td class="addOption">'
'<select required name="mode">'
'<option value="http" selected>http</option>'
'<option value="tcp">tcp</option>'
'</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Balance: </td>'
'<td class="addOption">'
'<select required name="balance">'
'<option value="roundrobin" selected>roundrobin</option>'
'<option value="source">source</option>'
'<option value="leastconn">leastconn</option>'
'<option value="first">first</option>'
'<option value="rdp-cookie">rdp-cookie</option>'
'</select>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Optinons:</td>'
'<td class="addOption">'
'<div style="font-size: 12px; padding-bottom: 10px;">'
'<span style="padding-right: 10px;">Start typing options: </span>'
'<input type="text" id="options2" >'
'<span style="padding-left: 10px;">'
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
'</span>'
'</div>'
'<textarea name="option" title="Options thru" cols=80 id="optionsInput2" placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
'</td>'
'</tr>'
'<tr>'
'<td class="addName">Servers:</td>'
'<td class="addOption">'
'<textarea name="servers" title="Backend servers" required cols=80 placeholder="server server.local 172.28.0.1:8080 check"></textarea>'
'</td>'
'</tr>'
'<tr>'
'<td class="addButton">')
funct.mode_admin("Add Backend")
print('</td>'
'</tr>'
'</form></div></table>'
'</div></div>')
funct.footer()

View File

@ -14,10 +14,11 @@ from pytz import timezone
form = cgi.FieldStorage()
serv = form.getvalue('serv')
servNew = form.getvalue('serNew')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
funct.head("Edit HAproxy config")
funct.check_config()
funct.check_login("config.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
@ -27,6 +28,9 @@ fullpath = config.get('main', 'fullpath')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
time_zone = config.get('main', 'time_zone')
if login is None:
print('<meta http-equiv="refresh" content="0; url=login.py?ref=config.py">')
if serv is not None:
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone(time_zone))
@ -45,9 +49,7 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
print('<p>')
funct.mode_admin("Save and restart")
print('</p></form>')
print('<p><button type="submit" value="save and restart" onclick="return confirm(\'are u shure?\')">save and restart</button></p></form>')
conf.close
os.system("/bin/sudo /bin/mv %s %s.old" % (cfg, cfg))

View File

@ -15,7 +15,6 @@ servNew = form.getvalue('serNew')
funct.head("Show HAproxy config")
funct.check_config()
funct.check_login("configshow.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()

View File

@ -14,10 +14,11 @@ from pytz import timezone
form = cgi.FieldStorage()
serv = form.getvalue('serv')
configver = form.getvalue('configver')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
funct.head("Old Versions HAproxy config")
funct.check_config()
funct.check_login("configver.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
@ -25,6 +26,9 @@ config.read(path_config)
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
if login is None:
print('<meta http-equiv="refresh" content="0; url=login.py?ref=configver.py">')
funct.chooseServer("configver.py#conf", "Old Versions HAproxy config", "y")
if serv is not None and form.getvalue('open') is not None:
@ -63,12 +67,9 @@ if serv is not None and form.getvalue('open') is not None:
print('<form action="configver.py#conf" method="get">')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="%s" name="configver">' % configver)
print('<input type="hidden" value="1" name="config">')
print('<a name="conf"></a></center>')
funct.show_config(configver)
print('<center><p>')
funct.mode_admin("Upload and restart")
print('</p></form></center>')
print('<center><p><button type="submit" value="Upload and restart" onclick="return confirm(\'are u shure?\')">Upload and restart</button></p></form></center>')
if form.getvalue('serv') is not None and form.getvalue('config') is not None:

View File

@ -17,7 +17,6 @@ right = form.getvalue('right')
funct.head("Compare HAproxy configs")
funct.check_config()
funct.check_login("diff.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
@ -71,6 +70,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
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")
funct.ssh_command(haproxy_configs_server, commands)
funct.footer()

View File

@ -10,10 +10,14 @@ from funct import head as head
form = cgi.FieldStorage()
serv = form.getvalue('serv')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
head("Edit & show HAproxy settings")
funct.check_login("edit.py")
if login is None:
print('<meta http-equiv="refresh" content="0; url=login.py?ref=configver.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>')
@ -51,9 +55,7 @@ print('<option value=2 %s>Enable server</option>' % selected2)
print('<option value=3 %s>Show</option>' % selected3)
print('</select>')
print('<input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required>')
print('<p>')
funct.mode_admin("Enter")
print('</p></form>')
print('<p><button type="submit">Enter</button></p></form>')
if form.getvalue('servaction') is not None:
action = form.getvalue('servaction')

View File

@ -28,7 +28,6 @@ ssh_user_name = config.get('ssh', 'ssh_user_name')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
tmp_config_path = config.get('haproxy', 'tmp_config_path')
restart_command = config.get('haproxy', 'restart_command')
time_zone = config.get('main', 'time_zone')
@ -43,43 +42,17 @@ def logging(serv, action):
log = open(fullpath + "log/config_edit.log", "a")
log.write(mess)
log.close
def check_login(ref):
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
if login is None:
print('<meta http-equiv="refresh" content="0; url=login.py?ref=%s">' % ref)
def show_login_links():
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
if login is None:
print('<a href=/cgi-bin/login.py? title="Login" style="size:5">Login</a>')
else:
print('<a href=/cgi-bin/login.py?logout=logout title="Logout" style="size:5">Logout</a>')
def mode_admin(button):
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
role = cookie.get('role')
if role.value == "admin":
print('<button type="submit">%s</button>' % 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/logs.py title="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>')
print('<a href=/cgi-bin/configshow.py title="Show Config">Show</a> ')
print('<a href=/cgi-bin/diff.py title="Compare Configs">Compare</a> ')
print('<a href=/cgi-bin/add.py title="Add single listen/frontend/backend" style="size:5">Add</a> ')
print('<a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> ')
print('<a href=/cgi-bin/configver.py title="Upload old config" style="size:5">Upload old</a>')
show_login_links()
def head(title):
print('Content-type: text/html\n')
@ -89,11 +62,21 @@ def head(title):
'<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'
'<script src="https://code.jquery.com/jquery-1.12.4.js"></script>'
'<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'
'<script src="/script.js"></script>'
'</head>'
'<body>'
'<a name="top"></a>'
'<div class="top-menu">')
'<script>'
'$( function() {'
'$( "select" ).selectmenu();'
'} );'
'$( function() {'
'$( "input[type=submit], button" ).button();'
'} );'
'$( function() {'
'$( document ).tooltip();'
'} );'
'</script>'
'<a name="top"></a>')
print('<div class="top-menu">')
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">')
@ -163,10 +146,6 @@ def show_config(cfg):
conf.close
def upload_and_restart(serv, cfg):
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
@ -176,109 +155,59 @@ def upload_and_restart(serv, cfg):
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
print("connected<br />")
sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file)
sftp.put(cfg, haproxy_config_path)
sftp.close()
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command]
i = 0
commands = [ "service haproxy restart" ]
for command in commands:
i = i + 1
print("</br>Executing: {}".format( command ))
print("</br>")
stdin , stdout, stderr = ssh.exec_command(command)
print(stdout.read().decode(encoding='UTF-8'))
if i == 1:
if not stderr.read():
print('<h3 style="color: #23527c">Config ok</h3>')
else:
print('<h3 style="color: red">In your config have errors, please check, and try again</h3>')
print(stderr.read().decode(encoding='UTF-8'))
return False
break
if i is not 1:
print("</br>Errors:")
print(stderr.read().decode(encoding='UTF-8'))
print("</br>")
return True
print("</br>Errors:")
print(stderr.read().decode(encoding='UTF-8'))
print("</br>")
ssh.close()
def compare(stdout):
i = 0
minus = 0
plus = 0
total_change = 0
print('</center><div class="out">')
print('<div class="diff">')
for line in stdout:
i = i + 1
if i is 1:
print('<div class="diffHead">' + line + '<br />')
elif i is 2:
print(line + '</div>')
elif line.find("-") == 0 and i is not 1:
print('<div class="lineDiffMinus">' + line + '</div>')
minus = minus + 1
elif line.find("+") == 0 and i is not 2:
print('<div class="lineDiffPlus">' + line + '</div>')
plus = plus + 1
elif line.find("@") == 0:
print('<div class="lineDog">' + line + '</div>')
else:
print('<div class="lineDiff">' + line + '</div>')
total_change = minus + plus
print('<div class="diffHead">Total change: %s, additions: %s & deletions: %s </div>' % (total_change, minus, plus))
print('</div></div>')
def show_log(stdout):
i = 0
for line in stdout:
i = i + 1
if i % 2 == 0:
print('<div class="line3">' + line + '</div>')
else:
print('<div class="line">' + line + '</div>')
print('</div></div>')
def show_ip(stdout):
for line in stdout:
print(line)
def ssh_command(serv, commands, **kwargs):
def ssh_command(serv, commands):
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
ip = 0
compare_funct = 0
show_log_funct = 0
for k in kwargs:
if "ip" in kwargs[k]:
ip = 1
if "compare" in kwargs[k]:
compare_funct = 1
if "show_log" in kwargs[k]:
show_log_funct = 1
for command in commands:
stdin , stdout, stderr = ssh.exec_command(command)
if ip is 1:
show_ip(stdout)
if compare_funct is 1:
compare(stdout)
if show_log_funct is 1:
show_log(stdout)
print('</center><div class="out">')
if serv == haproxy_configs_server:
print('<div class="diff">')
i = 0
minus = 0
plus = 0
for line in stdout:
i = i + 1
if serv == haproxy_configs_server:
if i is 1:
print('<div class="diffHead">' + line + '<br />')
elif i is 2:
print(line + '</div>')
elif line.find("-") == 0 and i is not 1:
print('<div class="lineDiffMinus">' + line + '</div>')
minus = minus + 1
elif line.find("+") == 0 and i is not 2:
print('<div class="lineDiffPlus">' + line + '</div>')
plus = plus + 1
elif line.find("@") == 0:
print('<div class="lineDog">' + line + '</div>')
else:
print('<div class="lineDiff">' + line + '</div>')
elif i % 2 == 0:
print('<div class="line3">' + line + '</div>')
else:
print('<div class="line">' + line + '</div>')
total_change = minus + plus
if serv == haproxy_configs_server:
print('<div class="diffHead">Total change: %s, additions: %s & deletions: %s </div>' % (total_change, minus, plus))
print('</div></div>')
print(stderr.read().decode(encoding='UTF-8'))
ssh.close()
@ -320,6 +249,3 @@ def merge_two_dicts(x, y):
z = x.copy()
z.update(y)
return z

View File

@ -1,7 +1,10 @@
listhap= {
'haproxy1': '172.28.0.1',
'haproxy2': '172.28.0.2'
'kz-webhap01': '172.28.9.159',
'kz-webhap02': '172.28.9.160',
'kz-mysqlhap01': '172.28.5.6',
'kz-mysqlhap02': '172.28.5.5',
}
list_hap_vip = {
'haproxy-vip': '172.28.0.3'
'kz-webhap-vip': '172.28.9.161',
'kz-mysqlhap-vip': '172.28.5.17'
}

View File

@ -13,8 +13,6 @@ login = form.getvalue('login')
password = form.getvalue('pass')
USERS = 'cgi-bin/users'
funct.check_login("login.py")
try:
with open(USERS, "r") as user:
pass
@ -23,16 +21,12 @@ except IOError:
def login_page(error):
if error == "error":
printError = "<b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b><br /><br />"
printError = "<b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b></br></br>"
else:
printError = "<b style='color: red'>First you need to login.</b><br /><br />"
ref = form.getvalue('ref')
if ref is None:
ref = "/index.html"
printError = "<b style='color: red'>First you need to login.</b></br></br>"
funct.head("Login page")
print('<center><form name="auth" action="login.py" class="form-horizontal" method="post">')
print(printError)
print('<label for="login"> Login: </label> <input type="text" name="login" class="form-control">')
@ -41,34 +35,26 @@ def login_page(error):
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")
print("Set-cookie: FirstName=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
print("Set-cookie: LastName=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
print("Set-cookie: role=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
print('<meta http-equiv="refresh" content="0; url=/">')
if login is None:
login_page("n")
if login is not None and password is not None:
for f in open(USERS, 'r'):
users = json.loads(f)
print(users['login'])
if login in users['login'] and password == users['password']:
print("Set-cookie: login=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % login)
print("Set-cookie: FirstName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['firstName'])
print("Set-cookie: LastName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['lastName'])
print("Set-cookie: role=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['role'])
if form.getvalue('ref') is None:
ref = "/index.html"
if ref is None:
ref = "index.html"
print("Content-type: text/html\n")
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)
else:
login_page("error")
break
login_page("error")
funct.footer()

View File

@ -12,7 +12,6 @@ serv = form.getvalue('serv')
funct.head("HAproxy Logs")
funct.check_config()
funct.check_login("config.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
@ -71,6 +70,6 @@ if form.getvalue('serv') is not None:
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
syslog_server = config.get('logs', 'syslog_server')
funct.ssh_command(syslog_server, commands, show_log="show_log")
funct.ssh_command(syslog_server, commands)
funct.footer()

View File

@ -1,57 +0,0 @@
#!/usr/bin/env python3
import html
import cgi
import json
import subprocess
import funct
options = [ "acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "tcpka", "tcplog", "forwardfor", "option" ]
form = cgi.FieldStorage()
req = form.getvalue('req')
serv = form.getvalue('serv')
print('Content-type: text/html\n')
#print('Content-type: application/json\n')
if req is not None:
if req is 1:
for i in options:
if req in i:
print(i)
else:
for i in options:
print(i)
backend = form.getvalue('backend')
if backend is not None:
cmd='echo "show backend" |nc %s 1999' % serv
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
stdout, stderr = p.communicate()
output = stdout.splitlines()
for line in output:
if "#" in line or "stats" in line:
continue
if backend != "1":
if backend in line:
print(json.dumps(line))
continue
if backend == "1":
print(json.dumps(line))
continue
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 }'" ]
funct.ssh_command(serv, commands, ip="ip")
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:
#print(line)
if s in line and name in line:
# print(line)
print("yes")
break

View File

@ -1,2 +1 @@
{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin", "role": "admin" }
{ "firstName": "Guest", "lastName": "Guest", "login": "Guest", "password": "Guest@123", "role": "guest" }
{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin" }

View File

@ -8,7 +8,6 @@ import configparser
from requests_toolbelt.utils import dump
funct.check_config()
funct.check_login("config.py")
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()

View File

@ -6,7 +6,7 @@ server_port = 8000
log_path = %(fullpath)s/log/
time_zone = UTC
#Enable logo on top menu. Default disable
logo_enable = 0
logo_enable = 1
logo_path = /logo.png
[configs]
@ -36,7 +36,5 @@ user = admin
password = password
stats_port = 8085
haproxy_config_path = /etc/haproxy/haproxy.cfg
#Temp store configs, for haproxy check
tmp_config_path = /tmp
#Time in seconds for auto refresh view stats_port
refresh_time = 120
refresh_time = 30

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>HAProxy web manager</title>
<title>HAProxy monitoryng</title>
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link href="style.css" rel="stylesheet">
@ -17,7 +17,6 @@
<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/add.py title="Add single listen/frontend/backend">Add</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 />
<div class="copyright">

View File

@ -1,98 +0,0 @@
$( function() {
$( "#tabs" ).tabs();
$( "#redirectBackend" ).on( "click", function() {
$( "#tabs" ).tabs( "option", "active", 2 );
} );
$( "select" ).selectmenu();
$( document ).tooltip();
$( "input[type=submit], button" ).button();
} );
$( function() {
var availableTags = [
"acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "tcpka", "tcplog", "forwardfor", "option"
];
$( "#ip" ).autocomplete({
source: function( request, response ) {
if ( request.term == "" ) {
request.term = 1
}
$.ajax( {
url: "options.py",
data: {
ip: request.term,
serv: $("#serv").val()
},
success: function( data ) {
response(data.split("\n"));
}
} );
},
autoFocus: true,
minLength: -1
});
$( "#ip1" ).autocomplete({
source: function( request, response ) {
if ( request.term == "" ) {
request.term = 1
}
$.ajax( {
url: "options.py",
data: {
ip: request.term,
serv: $("#serv").val()
},
success: function( data ) {
response(data.split("\n"));
}
} );
},
autoFocus: true,
minLength: -1
});
$( "#backends" ).autocomplete({
source: function( request, response ) {
if ( request.term == "" ) {
request.term = 1
}
$.ajax( {
url: "options.py",
data: {
backend: request.term,
serv: $("#serv2").val()
},
success: function( data ) {
response(data.split('"'));
}
} );
},
autoFocus: true,
minLength: -1
});
$( "#options" ).autocomplete({
source: availableTags,
autoFocus: true,
minLength: -1,
select: function( event, ui ) {
$("#optionsInput").append(ui.item.value + " ");
$("#options").empty();
}
});
$( "#options1" ).autocomplete({
source: availableTags,
autoFocus: true,
minLength: -1,
select: function( event, ui ) {
$("#optionsInput1").append(ui.item.value + " ");
}
});
$( "#options2" ).autocomplete({
source: availableTags,
autoFocus: true,
minLength: -1,
select: function( event, ui ) {
$("#optionsInput2").append(ui.item.value + " ")
}
});
} );

View File

@ -119,30 +119,6 @@ body {
.comment {
color: #aaa;
}
.addName {
background-color: #eee;
width: 120px;
}
.addOption, .addName {
border: 1px solid #ddd;
padding: 15px;
}
.addButton {
padding-top: 15px;
}
.addSuc {
padding-left: 20px;
padding-top: 20px;
color: #23527c;
}
.tooltip {
font-size: 12px;
padding-bottom: 10px;
}
.tooltipTop {
margin-bottom: -20px;
padding-top: 10px;
}
.footer {
background-color: #222;
min-height: 50px;