#!/usr/bin/env python3
# -*- coding: utf-8 -*-"
import html
import cgi
import os
import http.cookies
from configparser import ConfigParser, ExtendedInterpolation
import funct
import sql
import codecs
form = cgi.FieldStorage()
serv = form.getvalue('serv')
servNew = form.getvalue('serNew')
funct.head("Edit Running Keepalived config")
funct.check_config()
funct.check_login()
funct.page_for_admin(level = 1)
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
log_path = config.get('main', 'log_path')
kp_save_configs_dir = config.get('configs', 'kp_save_configs_dir')
print('
Edit Running Keepalived config
'
''
'Choose server
'
'')
if serv is not None:
cfg = kp_save_configs_dir+ serv + '-' + funct.get_data('config') + '.conf'
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.logging(serv, "keepalivedconfig.py open config")
funct.get_config(serv, cfg, keepalived=1)
try:
conf = open(cfg, "r",encoding='utf-8', errors='ignore')
except IOError:
print('Can\'t read import config file
')
print("Config from %s
" % serv)
print('')
conf.close
os.system("/bin/mv %s %s.old" % (cfg, cfg))
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
funct.logging(serv, "keepalivedconfig.py edited config")
config = form.getvalue('config')
oldcfg = form.getvalue('oldconfig')
save = form.getvalue('save')
try:
with open(cfg, "a") as conf:
conf.write(config)
except IOError:
print("Can't read import config file")
print('
New config was saved as: %s
' % cfg)
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')))
os.system("/bin/rm -f kp_config/*.old")
print('Go to view stats
' % serv)
funct.footer()