stderr = "" aftersave = "" file = set() if form.getvalue('configver'): template = env.get_template('configver.html') try: user, user_id, role, token, servers = funct.get_users_params(disable=1) except: pass if service == 'keepalived': configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir') title = "Working with versions Keepalived configs" files = funct.get_files(dir=configs_dir, format='conf') action = 'versions.py?service=keepalived' format = 'conf' servers = sql.get_dick_permit(keepalived=1) elif service == 'nginx': configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir') title = "Working with versions Nginx configs" files = funct.get_files(dir=configs_dir, format='conf') action = 'versions.py?service=nginx' format = 'conf' servers = sql.get_dick_permit(nginx=1) else: title = "Working with versions HAProxy configs" files = funct.get_files() action = "versions.py" configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
funct.ssh_command(serv, command, show_log="1") action = 'edit.py ' + enable + ' ' + backend funct.logging(serv, action) if act == "showCompareConfigs": import glob from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax')) template = env.get_template('/show_compare_configs.html') left = form.getvalue('left') right = form.getvalue('right') template = template.render(serv=serv, right=right, left=left, return_files=funct.get_files()) print(template) if serv is not None and form.getvalue('right') is not None: from jinja2 import Environment, FileSystemLoader left = form.getvalue('left') right = form.getvalue('right') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') cmd = 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) env = Environment(loader=FileSystemLoader('templates/ajax'), extensions=['jinja2.ext.loopcontrols', "jinja2.ext.do"]) template = env.get_template('compare.html') output, stderr = funct.subprocess_execute(cmd)
if form.getvalue('action_waf') is not None and serv is not None: serv = form.getvalue('serv') action = form.getvalue('action_waf') funct.logging(serv, 'WAF service was ' + action, haproxywi=1, login=1) commands = ["sudo systemctl %s waf" % action] funct.ssh_command(serv, commands) if act == "overviewHapserverBackends": from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax')) template = env.get_template('haproxyservers_backends.html') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') try: sections = funct.get_sections(hap_configs_dir + funct.get_files()[0]) except: try: cfg = hap_configs_dir + serv + "-" + funct.get_data( 'config') + ".cfg" except: funct.logging('localhost', ' Cannot generate cfg path', haproxywi=1) try: error = funct.get_config(serv, cfg) except: funct.logging('localhost', ' Cannot download config', haproxywi=1) try: sections = funct.get_sections(cfg) except:
servbackend = "" except: pass dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') white_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting( 'lists_path') + "/" + user_group + "/white" black_dir = os.path.dirname(os.getcwd()) + "/" + sql.get_setting( 'lists_path') + "/" + user_group + "/black" if not os.path.exists(dir): os.makedirs(dir) if not os.path.exists(dir + "/" + user_group): os.makedirs(dir + "/" + user_group) if not os.path.exists(white_dir): os.makedirs(white_dir) if not os.path.exists(black_dir): os.makedirs(black_dir) white_lists = funct.get_files(dir=white_dir, format="lst") black_lists = funct.get_files(dir=black_dir, format="lst") template = template.render(h2=1, title="Lists", role=sql.get_user_role_by_uuid(user_id.value), user=user, white_lists=white_lists, black_lists=black_lists, group=user_group, versions=funct.versions(), token=token) print(template)
if "cfg" in get: try: os.remove(os.path.join(hap_configs_dir, form.getvalue(get))) file.add(form.getvalue(get) + "<br />") funct.logging( serv, "delver.py deleted config: %s" % form.getvalue(get)) except OSError as e: stderr = "Error: %s - %s." % (e.filename, e.strerror) print( '<meta http-equiv="refresh" content="10; url=delver.py?serv=%s&open=open">' % form.getvalue('serv')) output_from_parsed_template = template.render( h2=1, title="Delete old versions HAProxy config", role=sql.get_user_role_by_uuid(user_id.value), action="delver.py", user=user, select_id="serv", serv=serv, aftersave=aftersave, return_files=funct.get_files(), selects=servers, stderr=stderr, open=form.getvalue('open'), Select=form.getvalue('del'), file=file, token=token) print(output_from_parsed_template)
commands = ["sudo mkdir " + path] funct.ssh_command(server[2], commands) try: ssh = funct.ssh_connect(server[2]) except Exception as e: print('<div class="alert alert-danger">Connect fail: %s</div>' % e) try: sftp = ssh.open_sftp() file = sftp.put(list, path + "/" + form.getvalue('bwlists_save')) sftp.close() ssh.close() print( '<div class="alert alert-success" style="margin:10px">Edited ' + form.getvalue('color') + ' list was uploaded to ' + server[1] + '</div>') except Exception as e: print('<div class="alert alert-danger">Upload fail: %s</div>' % e) if form.getvalue('bwlists_restart') == 'restart': commands = ["sudo " + sql.get_setting('restart_command')] funct.ssh_command(server[2], commands) if form.getvalue('get_lists'): list = os.path.dirname(os.getcwd()) + "/" + sql.get_setting( 'lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue( 'color') lists = funct.get_files(dir=list, format="lst") for list in lists: print(list)
if form.getvalue('configver'): template = env.get_template('configver.html') 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) token = sql.get_token(user_id.value) servers = sql.get_dick_permit(disable=0) except: pass if service == 'keepalived': title = "Working with versions Keepalived configs" files = funct.get_files(dir=funct.get_config_var('configs', 'kp_save_configs_dir'), format='conf') action = 'versions.py?service=keepalived' configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir') format = 'conf' else: title = "Working with versions HAProxy configs" files = funct.get_files() action = "versions.py" configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') format = 'cfg' if serv is not None and form.getvalue('del') is not None: if Select is not None: aftersave = 1 for get in form:
if enable != "show": print('<center><h3>You %s %s on HAproxy %s. <a href="viewsttats.py?serv=%s" title="View stat" target="_blank">Look it</a> or <a href="edit.py" title="Edit">Edit something else</a></h3><br />' % (enable, backend, serv, serv)) funct.ssh_command(serv, command, show_log="1") action = 'edit.py ' + enable + ' ' + backend funct.logging(serv, action) if act == "showCompareConfigs": import glob from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True) template = env.get_template('/show_compare_configs.html') left = form.getvalue('left') right = form.getvalue('right') template = template.render(serv=serv, right=right, left=left, return_files=funct.get_files()) print(template) if serv is not None and form.getvalue('right') is not None: from jinja2 import Environment, FileSystemLoader left = form.getvalue('left') right = form.getvalue('right') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') cmd='diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True, extensions=['jinja2.ext.loopcontrols', "jinja2.ext.do"]) template = env.get_template('compare.html') output, stderr = funct.subprocess_execute(cmd) template = template.render(stdout=output) print(template)
if form.getvalue('action_waf') is not None and serv is not None: serv = form.getvalue('serv') action = form.getvalue('action_waf') funct.logging(serv, 'WAF service was '+action, haproxywi=1, login=1) commands = [ "sudo systemctl %s waf" % action ] funct.ssh_command(serv, commands) if act == "overviewHapserverBackends": from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax')) template = env.get_template('haproxyservers_backends.html') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') try: sections = funct.get_sections(hap_configs_dir +funct.get_files()[0]) except: try: cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg" except: funct.logging('localhost', ' Cannot generate cfg path', haproxywi=1) try: error = funct.get_config(serv, cfg) except: funct.logging('localhost', ' Cannot download config', haproxywi=1) try: sections = funct.get_sections(cfg) except: funct.logging('localhost', ' Cannot get sections from config file', haproxywi=1) sections = 'Cannot get backends'