#!/usr/bin/env python3 import html import cgi import os import http.cookies from configparser import ConfigParser, ExtendedInterpolation import funct import sql from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/')) template = env.get_template('config.html') print('Content-type: text/html\n') funct.check_login() funct.page_for_admin() form = cgi.FieldStorage() serv = form.getvalue('serv') config_read = "" cfg = "" stderr = "" aftersave = "" error = "" 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) servers = sql.is_master("123", master_slave=1) except: pass 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') 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 : try: funct.logging(serv, "keepalivedconfig.py open config") except: pass funct.get_config(serv, cfg, keepalived=1) try: conf = open(cfg, "r",encoding='utf-8', errors='ignore') config_read = conf.read() except IOError: print('