Add files via upload

pull/1/head
Aidaho12 2018-01-18 15:15:11 +06:00 committed by GitHub
parent 97089d3ce8
commit 0c84b1217b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 40 deletions

View File

@ -26,13 +26,14 @@ config.read(path_config)
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('Asia/Almaty'))
now_utc = datetime.now(timezone(time_zone))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.chooseServer("config.py#conf", "Edit HAproxy config", "y")
@ -49,7 +50,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
print('<p><button type="submit" value="save and restart" onclick="return confirm(\'are u shure?\')">save and restart</button></p></form>')
print('<center><h3><a href="#top" title="UP">UP</a></center>')
conf.close
os.system("/bin/sudo /bin/mv %s %s.old" % (cfg, cfg))

View File

@ -24,10 +24,11 @@ ssh_keys = config.get('ssh', 'ssh_keys')
ssh_user_name = config.get('ssh', 'ssh_user_name')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
time_zone = config.get('main', 'time_zone')
if serv is not None:
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone('Asia/Almaty'))
now_utc = datetime.now(timezone(time_zone))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.chooseServer("configshow.py#conf", "Show HAproxy config", "n")
@ -35,12 +36,10 @@ funct.chooseServer("configshow.py#conf", "Show HAproxy config", "n")
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.get_config(serv, cfg)
conf = open(cfg, "r")
print('<a name="conf"></a>')
print("<h3>Config from %s</h3>" % serv)
print('<textarea class="ro" readonly name="config" rows="35" cols="100"> %s </textarea>' % conf.read())
print('<center><h3><a href="#top" title="UP">UP</a></center>')
conf.close
funct.show_config(cfg)
os.system("/bin/sudo /bin/rm -f " + cfg)

View File

@ -63,16 +63,14 @@ if serv is not None and form.getvalue('open') is not None:
configver = form.getvalue('configver')
funct.logging(serv, "open old config %s" % configver)
conf = open(configver, "r")
print("<h3>Config from %s, and version is: %s</h3>" % (serv, configver))
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('<a name="conf"></a>')
print('<textarea class="ro" name="config" rows="35" cols="100" readonly> %s </textarea>' % conf.read())
print('<p><button type="submit" value="Upload and restart" onclick="return confirm(\'are u shure?\')">Upload and restart</button></p></form>')
print('<center><h3><a href="#top" title="UP">UP</a></center>')
conf.close
print('<a name="conf"></a></center>')
funct.show_config(configver)
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:
configver = form.getvalue('configver')
@ -84,4 +82,6 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
funct.upload_and_restart(serv, configver)
print('</br><a href="viewsttats.py" title="View stats">Go to view stats</a> <br />')
print('<center><br /><a href="viewsttats.py" title="View stats">Go to view stats</a> <br /></center>')
funct.footer()

View File

@ -30,10 +30,11 @@ 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')
restart_command = config.get('haproxy', 'restart_command')
time_zone = config.get('main', 'time_zone')
def logging(serv, action):
dateFormat = "%b %d %H:%M:%S"
now_utc = datetime.now(timezone('Asia/Almaty'))
now_utc = datetime.now(timezone(time_zone))
IP = cgi.escape(os.environ["REMOTE_ADDR"])
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
firstName = cookie.get('FirstName')
@ -43,6 +44,18 @@ def logging(serv, action):
log.write(mess)
log.close
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.23.16.154:3000/dashboard/db/haproxy" title="Mon" target="_blanck">Monitoring</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/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>')
def head(title):
print("Content-type: text/html\n")
print('<html><head><title>%s</title>' % title)
@ -50,28 +63,13 @@ def head(title):
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">')
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/edit.py title="Edit settings" style="size:5">Edit settings</a> ')
print('<a href=/cgi-bin/logs.py title="Logs" style="size:6">Logs</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/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>')
links()
print('</div></div><div class="conteiner">')
def footer():
print('<center><h3><a href="#top" title="UP">UP</a></center>')
print('</center></div><div class="footer"><div class="footer-link">')
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/edit.py title="Edit settings" style="size:5">Edit settings</a> ')
print('<a href=/cgi-bin/logs.py title="Logs" style="size:6">Logs</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/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>')
links()
print('</div></div></body></html>')
def get_config(serv, cfg):
@ -87,6 +85,43 @@ def get_config(serv, cfg):
sftp.close()
ssh.close()
def show_config(cfg):
print('</center><div class="configShow">')
conf = open(cfg, "r")
i = 0
for line in conf:
i = i + 1
if not line.find("global"):
print('<div class="param">' + line + '</div>')
continue
if not line.find("defaults"):
print('<div class="param">' + line + '</div>')
continue
if not line.find("listen"):
print('<div class="param">' + line + '</div>')
continue
if not line.find("frontend"):
print('<div class="param">' + line + '</div>')
continue
if not line.find("backend"):
print('<div class="param">' + line + '</div>')
continue
if "acl" in line or "option" in line or "server" in line:
print('<div class="paramInSec"><span class="numRow">')
print(i)
print('</span>' + line + '</div>')
continue
if "#" in line:
print('<div class="comment">')
print(i)
print(line + '</div>')
continue
print('<div class="configLine"><span class="numRow">')
print(i)
print('</span>' + line + '</div>')
print('</div>')
conf.close
def upload_and_restart(serv, cfg):
ssh = SSHClient()
ssh.load_system_host_keys()
@ -119,9 +154,15 @@ def ssh_command(serv, commands):
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
for command in commands:
stdin , stdout, stderr = ssh.exec_command(command)
print('<pre>')
print(stdout.read().decode(encoding='UTF-8'))
print('</pre>')
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>')
ssh.close()
def chooseServer(formName, title, note):
@ -156,7 +197,7 @@ def choose_server_with_vip(serv):
selected = 'selected'
else:
selected = ''
print('<option value="%s" %s>%s</option>' % (listhap.listhap.get(i), selected, i))
print('<option value="%s" %s>%s</option>' % (listhap.listhap.get(i), selected, i))
def merge_two_dicts(x, y):
z = x.copy()

View File

@ -72,6 +72,4 @@ if form.getvalue('serv') is not None:
funct.ssh_command(syslog_server, commands)
print('<center><h3><a href="#top" title="UP">UP</a></center>')
funct.footer()

View File

@ -22,7 +22,7 @@ form = cgi.FieldStorage()
serv = form.getvalue('serv')
if serv is None:
serv = '172.28.9.161'
serv = '172.28.5.17'
try:
response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass))