Bug fixed
pull/19/head
Aidaho12 2018-05-29 15:53:20 +06:00
parent fe7b682cba
commit 5f4879177b
4 changed files with 38 additions and 9 deletions

View File

@ -76,7 +76,8 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
stderr = funct.upload_and_restart(serv, cfg, just_save=save) stderr = funct.upload_and_restart(serv, cfg, just_save=save)
os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs'))) funct.diff_config(oldcfg, cfg)
os.system("/bin/rm -f " + hap_configs_dir + "*.old") os.system("/bin/rm -f " + hap_configs_dir + "*.old")
output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig HAProxy config", output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig HAProxy config",

View File

@ -17,7 +17,7 @@ def get_config_var(sec, var):
config = ConfigParser(interpolation=ExtendedInterpolation()) config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config) config.read(path_config)
except: except:
print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be in: app/haproxy-webintarface.config</div>') print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be: app/haproxy-webintarface.config</div>')
try: try:
var = config.get(sec, var) var = config.get(sec, var)
@ -31,17 +31,18 @@ def get_data(type):
fmt = "%Y-%m-%d.%H:%M:%S" fmt = "%Y-%m-%d.%H:%M:%S"
if type == 'logs': if type == 'logs':
fmt = '%Y%m%d' fmt = '%Y%m%d'
if type == "date_in_log":
fmt = "%b %d %H:%M:%S"
return now_utc.strftime(fmt) return now_utc.strftime(fmt)
def logging(serv, action): def logging(serv, action):
import sql import sql
dateFormat = "%b %d %H:%M:%S"
now_utc = datetime.now(timezone(get_config_var('main', 'time_zone')))
IP = cgi.escape(os.environ["REMOTE_ADDR"]) IP = cgi.escape(os.environ["REMOTE_ADDR"])
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_uuid = cookie.get('uuid') user_uuid = cookie.get('uuid')
login = sql.get_user_name_by_uuid(user_uuid.value) login = sql.get_user_name_by_uuid(user_uuid.value)
mess = now_utc.strftime(dateFormat) + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n" mess = get_data('date_in_log') + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
log_path = get_config_var('main', 'log_path') log_path = get_config_var('main', 'log_path')
try: try:
@ -241,6 +242,26 @@ def show_config(cfg):
print('</div></div>') print('</div></div>')
conf.close conf.close
def diff_config(oldcfg, cfg):
import subprocess
cmd="/bin/diff -ub %s %s" % (oldcfg, cfg)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
stdout, stderr = p.communicate()
output = stdout.splitlines()
log_path = get_config_var('main', 'log_path')
diff = ""
date = get_data('date_in_log')
for line in output:
diff += date + " " + line + "\n"
try:
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
log.write(diff)
log.close
except IOError:
print('<center><div class="alert alert-danger">Can\'t read write change to log. %s</div></center>' % stderr)
pass
def install_haproxy(serv): def install_haproxy(serv):
script = "install_haproxy.sh" script = "install_haproxy.sh"
tmp_config_path = get_config_var('haproxy', 'tmp_config_path') tmp_config_path = get_config_var('haproxy', 'tmp_config_path')

View File

@ -69,7 +69,8 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1) stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs'))) funct.diff_config(oldcfg, cfg)
os.system("/bin/rm -f " + kp_save_configs_dir + "*.old") os.system("/bin/rm -f " + kp_save_configs_dir + "*.old")
output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig Keepalived config", output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig Keepalived config",

View File

@ -193,9 +193,15 @@ def show_compare_configs(serv):
print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Compare" onclick="showCompare()">Show</a></p></form></center></center>') print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Compare" onclick="showCompare()">Show</a></p></form></center></center>')
def comapre_show(): def comapre_show():
import subprocess
left = form.getvalue('left') left = form.getvalue('left')
right = form.getvalue('right') right = form.getvalue('right')
haproxy_configs_server = funct.get_config_var('configs', 'haproxy_configs_server') haproxy_configs_server = funct.get_config_var('configs', 'haproxy_configs_server')
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ] cmd='diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right)
funct.ssh_command(haproxy_configs_server, commands, compare="1") p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
stdout, stderr = p.communicate()
output = stdout.splitlines()
funct.compare(output)
print(stderr)