mirror of https://github.com/Aidaho12/haproxy-wi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
7 years ago
|
#!/usr/bin/env python3
|
||
5 years ago
|
import http.cookies
|
||
7 years ago
|
import cgi
|
||
|
import os
|
||
7 years ago
|
import funct, sql
|
||
7 years ago
|
import glob
|
||
7 years ago
|
from jinja2 import Environment, FileSystemLoader
|
||
|
env = Environment(loader=FileSystemLoader('templates/'))
|
||
|
template = env.get_template('delver.html')
|
||
7 years ago
|
|
||
7 years ago
|
print('Content-type: text/html\n')
|
||
|
funct.check_login()
|
||
7 years ago
|
funct.page_for_admin(level = 2)
|
||
7 years ago
|
|
||
7 years ago
|
form = cgi.FieldStorage()
|
||
|
serv = form.getvalue('serv')
|
||
5 years ago
|
Select = form.getvalue('del')
|
||
|
configver = form.getvalue('configver')
|
||
7 years ago
|
stderr = ""
|
||
|
aftersave = ""
|
||
|
file = set()
|
||
6 years ago
|
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||
7 years ago
|
|
||
5 years ago
|
if form.getvalue('configver'):
|
||
|
template = env.get_template('configver.html')
|
||
|
|
||
7 years ago
|
try:
|
||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||
|
user_id = cookie.get('uuid')
|
||
|
user = sql.get_user_name_by_uuid(user_id.value)
|
||
6 years ago
|
servers = sql.get_dick_permit(disable=0)
|
||
7 years ago
|
token = sql.get_token(user_id.value)
|
||
7 years ago
|
except:
|
||
|
pass
|
||
5 years ago
|
|
||
7 years ago
|
|
||
5 years ago
|
if serv is not None and form.getvalue('del') is not None:
|
||
7 years ago
|
if Select is not None:
|
||
7 years ago
|
aftersave = 1
|
||
7 years ago
|
for get in form:
|
||
|
if "cfg" in get:
|
||
|
try:
|
||
7 years ago
|
os.remove(os.path.join(hap_configs_dir, form.getvalue(get)))
|
||
|
file.add(form.getvalue(get) + "<br />")
|
||
5 years ago
|
funct.logging(serv, "versions.py deleted config: %s" % form.getvalue(get))
|
||
6 years ago
|
except OSError as e:
|
||
7 years ago
|
stderr = "Error: %s - %s." % (e.filename,e.strerror)
|
||
5 years ago
|
print('<meta http-equiv="refresh" content="10; url=versions.py?serv=%s&open=open">' % form.getvalue('serv'))
|
||
|
|
||
|
|
||
|
if serv is not None and form.getvalue('config') is not None:
|
||
|
configver = hap_configs_dir + configver
|
||
|
save = form.getvalue('save')
|
||
|
aftersave = 1
|
||
|
try:
|
||
|
funct.logging(serv, "configver.py upload old config %s" % configver)
|
||
|
except:
|
||
|
pass
|
||
|
|
||
|
MASTERS = sql.is_master(serv)
|
||
|
for master in MASTERS:
|
||
|
if master[0] != None:
|
||
|
funct.upload_and_restart(master[0], configver, just_save=save)
|
||
|
|
||
|
stderr = funct.upload_and_restart(serv, configver, just_save=save)
|
||
|
|
||
|
if save:
|
||
|
c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||
|
c["restart"] = form.getvalue('serv')
|
||
|
print(c)
|
||
|
|
||
7 years ago
|
|
||
5 years ago
|
output_from_parsed_template = template.render(h2 = 1, title = "Working with versions HAProxy configs",
|
||
7 years ago
|
role = sql.get_user_role_by_uuid(user_id.value),
|
||
5 years ago
|
action = "versions.py",
|
||
7 years ago
|
user = user,
|
||
|
select_id = "serv",
|
||
|
serv = serv,
|
||
|
aftersave = aftersave,
|
||
6 years ago
|
return_files = funct.get_files(),
|
||
7 years ago
|
selects = servers,
|
||
|
stderr = stderr,
|
||
|
open = form.getvalue('open'),
|
||
|
Select = form.getvalue('del'),
|
||
7 years ago
|
file = file,
|
||
5 years ago
|
versions = funct.versions(),
|
||
5 years ago
|
configver = configver,
|
||
7 years ago
|
token = token)
|
||
6 years ago
|
print(output_from_parsed_template)
|