示例#1
0
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)

log_path = config.get('main', 'log_path')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')

funct.chooseServer("config.py", "Edit HAproxy config", "y")

if serv is not None:
    cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"

if form.getvalue('serv') is not None and form.getvalue('open') is not None:

    funct.logging(serv, "config.py open config")
    funct.get_config(serv, cfg)

    try:
        conf = open(cfg, "r")
    except IOError:
        print(
            '<div class="alert alert-danger">Can\'t read import config file</div>'
        )

    print("<center><h3>Config from %s</h3>" % serv)
    print('<form action="config.py" method="get">')
    print('<input type="hidden" value="%s" name="serv">' % serv)
    print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
    print(
        '<textarea name="config" class="config" rows="35" cols="100">%s</textarea>'
        % conf.read())
示例#2
0
        servers_with_status.append(out1)
    servers_with_status.append(s[12])
    try:
        servers_with_status.append(funct.ssh_command(s[2], commands))
    except:
        servers_with_status.append('Cannot get last date')

    if serv:
        try:
            sections = funct.get_sections(hap_configs_dir +
                                          funct.get_files()[0])
        except:
            try:
                cfg = hap_configs_dir + s[2] + "-" + funct.get_data(
                    'config') + ".cfg"
                error = funct.get_config(s[2], cfg)
                sections = funct.get_sections(cfg)
            except:
                pass
        servers_with_status.append(sections)

    servers_with_status1.append(servers_with_status)

template = template.render(h2=1,
                           autorefresh=autorefresh,
                           title="HAProxy servers overview",
                           role=sql.get_user_role_by_uuid(user_id.value),
                           user=user,
                           users=users,
                           groups=groups,
                           servers=servers_with_status1,
示例#3
0
def get_map(serv):
	from datetime import datetime
	from pytz import timezone
	import networkx as nx
	import matplotlib
	matplotlib.use('Agg')
	import matplotlib.pyplot as plt
	
	date = funct.get_data('config')
	cfg = hap_configs_dir + serv + "-" + date + ".cfg"
	
	print('<center>')
	print("<h3>Map from %s</h3><br />" % serv)
	
	G = nx.DiGraph()
	
	funct.get_config(serv, cfg)	
	try:
		conf = open(cfg, "r")
	except IOError:
		print('<div class="alert alert-danger">Can\'t read import config file</div>')
	
	node = ""
	line_new2 = [1,""]
	i = 1200
	k = 1200
	j = 0
	m = 0
	for line in conf:
		if "listen" in line or "frontend" in line:
			if "stats" not in line:				
				node = line
				i = i - 500	
		if line.find("backend") == 0: 
			node = line
			i = i - 500	
			G.add_node(node,pos=(k,i),label_pos=(k,i+150))
		
		if "bind" in line:
			bind = line.split(":")
			if stats_port not in bind[1]:
				bind[1] = bind[1].strip(' ')
				bind = bind[1].split("crt")
				node = node.strip(' \t\n\r')
				node = node + ":" + bind[0]
				G.add_node(node,pos=(k,i),label_pos=(k,i+150))

		if "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line:
			if "timeout" not in line and "default-server" not in line and "#" not in line and "stats" not in line:
				i = i - 300
				j = j + 1				
				if "check" in line:
					line_new = line.split("check")
				else:
					line_new = line.split("if ")
				if "server" in line:
					line_new1 = line_new[0].split("server")
					line_new[0] = line_new1[1]	
					line_new2 = line_new[0].split(":")
					line_new[0] = line_new2[0]					
				
				line_new[0] = line_new[0].strip(' \t\n\r')
				line_new2[1] = line_new2[1].strip(' \t\n\r')

				if j % 2 == 0:
					G.add_node(line_new[0],pos=(k+250,i-350),label_pos=(k+225,i-100))
				else:
					G.add_node(line_new[0],pos=(k-250,i-50),label_pos=(k-225,i+180))

				if line_new2[1] != "":	
					G.add_edge(node, line_new[0], port=line_new2[1])
				else:
					G.add_edge(node,line_new[0])

	os.system("/bin/rm -f " + cfg)	
	os.chdir(cgi_path)

	pos=nx.get_node_attributes(G,'pos')
	pos_label=nx.get_node_attributes(G,'label_pos')
	edge_labels = nx.get_edge_attributes(G,'port')
	
	try:
		plt.figure(10,figsize=(9.5,15))
		nx.draw(G, pos, with_labels=False, font_weight='bold', width=3, alpha=0.1,linewidths=5)	
		nx.draw_networkx_nodes(G,pos, node_color="skyblue", node_size=100, alpha=0.8, node_shape="p")
		nx.draw_networkx_labels(G,pos=pos_label, alpha=1, font_color="green", font_size=10)
		nx.draw_networkx_edges(G,pos, width=0.5,alpha=0.5, edge_color="#5D9CEB",arrows=False)
		nx.draw_networkx_edge_labels(G, pos,label_pos=0.5,font_color="blue", labels=edge_labels, font_size=8)
		
		plt.savefig("map.png")
		plt.show()
	except Exception as e:
		print('<div class="alert alert-danger">' + str(e) + '</div>')
		
	commands = [ "rm -f "+fullpath+"/map*.png", "mv %s/map.png %s/map%s.png" % (cgi_path, fullpath, date) ]
	funct.ssh_command("localhost", commands)
	print('<img src="/map%s.png" alt="map">' % date)
示例#4
0
    user = sql.get_user_name_by_uuid(user_id.value)
    servers = sql.is_master("123", master_slave=1)
    token = sql.get_token(user_id.value)
except:
    pass

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
    error = funct.get_config(serv, cfg, keepalived=1)

    try:
        conf = open(cfg, "r", encoding='utf-8', errors='ignore')
        config_read = conf.read()
        conf.close
    except IOError:
        error += "<br>Can't read import config file"

    os.system("/bin/mv %s %s.old" % (cfg, cfg))

if form.getvalue('serv') is not None and form.getvalue('config') is not None:
    try:
        funct.logging(serv, "keepalivedconfig.py edited config")
    except:
        pass
示例#5
0
    pass

log_path = funct.get_config_var('main', 'log_path')
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')

if serv is not None:
    cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"

if form.getvalue('serv') is not None and form.getvalue('open') is not None:

    try:
        funct.logging(serv, "config.py open config")
    except:
        pass

    error = funct.get_config(serv, cfg)

    try:
        conf = open(cfg, "r")
        config_read = conf.read()
        conf.close
    except IOError:
        error += '<br />Can\'t read import config file'

    os.system("/bin/mv %s %s.old" % (cfg, cfg))

if form.getvalue('serv') is not None and form.getvalue('config') is not None:
    try:
        funct.logging(serv, "config.py edited config")
    except:
        pass
示例#6
0
def get_map(serv):
    from datetime import datetime
    from pytz import timezone
    import networkx as nx
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt

    stats_port = sql.get_setting('stats_port')
    haproxy_config_path = sql.get_setting('haproxy_config_path')
    hap_configs_dir = funct.get_config_var('configs',
                                           'haproxy_save_configs_dir')
    date = funct.get_data('config')
    cfg = hap_configs_dir + serv + "-" + date + ".cfg"

    print('<center>')
    print("<h3>Map from %s</h3><br />" % serv)

    G = nx.DiGraph()

    error = funct.get_config(serv, cfg)
    if error:
        print('<div class="alert alert-danger">' + error + '</div>')
    try:
        conf = open(cfg, "r")
    except IOError:
        print(
            '<div class="alert alert-danger">Can\'t read import config file</div>'
        )

    node = ""
    line_new2 = [1, ""]
    i, k = 1200, 1200
    j, m = 0, 0
    for line in conf:
        if line.startswith('listen') or line.startswith('frontend'):
            if "stats" not in line:
                node = line
                i = i - 500
        if line.find("backend") == 0:
            node = line
            i = i - 500
            G.add_node(node, pos=(k, i), label_pos=(k, i + 150))

        if "bind" in line or (line.startswith('listen')
                              and ":" in line) or (line.startswith('frontend')
                                                   and ":" in line):
            try:
                bind = line.split(":")
                if stats_port not in bind[1]:
                    bind[1] = bind[1].strip(' ')
                    bind = bind[1].split("crt")
                    node = node.strip(' \t\n\r')
                    node = node + ":" + bind[0]
                    G.add_node(node, pos=(k, i), label_pos=(k, i + 150))
            except:
                pass

        if "server " in line or "use_backend" in line or "default_backend" in line and "stats" not in line and "#" not in line:
            if "timeout" not in line and "default-server" not in line and "#" not in line and "stats" not in line:
                i = i - 300
                j = j + 1
                if "check" in line:
                    line_new = line.split("check")
                else:
                    line_new = line.split("if ")
                if "server" in line:
                    line_new1 = line_new[0].split("server")
                    line_new[0] = line_new1[1]
                    line_new2 = line_new[0].split(":")
                    line_new[0] = line_new2[0]

                line_new[0] = line_new[0].strip(' \t\n\r')
                line_new2[1] = line_new2[1].strip(' \t\n\r')

                if j % 2 == 0:
                    G.add_node(line_new[0],
                               pos=(k + 250, i - 350),
                               label_pos=(k + 225, i - 100))
                else:
                    G.add_node(line_new[0],
                               pos=(k - 250, i - 50),
                               label_pos=(k - 225, i + 180))

                if line_new2[1] != "":
                    G.add_edge(node, line_new[0], port=line_new2[1])
                else:
                    G.add_edge(node, line_new[0])

    os.system("/bin/rm -f " + cfg)

    pos = nx.get_node_attributes(G, 'pos')
    pos_label = nx.get_node_attributes(G, 'label_pos')
    edge_labels = nx.get_edge_attributes(G, 'port')

    try:
        plt.figure(10, figsize=(15, 20))
        nx.draw(G,
                pos,
                with_labels=False,
                font_weight='bold',
                width=3,
                alpha=0.1,
                linewidths=5)
        nx.draw_networkx_nodes(G,
                               pos,
                               node_color="skyblue",
                               node_size=100,
                               alpha=0.8,
                               node_shape="p")
        nx.draw_networkx_labels(G,
                                pos=pos_label,
                                alpha=1,
                                font_color="green",
                                font_size=10)
        nx.draw_networkx_edges(G,
                               pos,
                               width=0.5,
                               alpha=0.5,
                               edge_color="#5D9CEB",
                               arrows=False)
        nx.draw_networkx_edge_labels(G,
                                     pos,
                                     label_pos=0.5,
                                     font_color="blue",
                                     labels=edge_labels,
                                     font_size=8)

        plt.savefig("map.png")
        plt.show()
    except Exception as e:
        print('<div class="alert alert-danger">' + str(e) + '</div>')

    cmd = "rm -f " + os.path.dirname(
        os.getcwd()) + "/map*.png && mv map.png " + os.path.dirname(
            os.getcwd()) + "/map" + date + ".png"
    output, stderr = funct.subprocess_execute(cmd)
    print(stderr)

    print('<img src="/map%s.png" alt="map">' % date)
示例#7
0
        servers = sql.get_dick_permit()

if serv is not None:
    if service == 'nginx':
        conf_file_name_short = config_file_name.split('/')[-1]
        cfg = configs_dir + serv + "-" + conf_file_name_short + "-" + funct.get_data(
            'config') + "." + file_format
    else:
        cfg = configs_dir + serv + "-" + funct.get_data(
            'config') + "." + file_format

if serv is not None and form.getvalue(
        'open') is not None and form.getvalue('new_config') is None:
    funct.check_is_server_in_group(serv)
    if service == 'keepalived':
        error = funct.get_config(serv, cfg, keepalived=1)
        try:
            funct.logging(serv, " Keepalived config has been opened for ")
        except Exception:
            pass
    elif service == 'nginx':
        error = funct.get_config(serv,
                                 cfg,
                                 nginx=1,
                                 config_file_name=config_file_name)
        try:
            funct.logging(serv, " Nginx config has been opened ")
        except Exception:
            pass
    else:
        error = funct.get_config(serv, cfg)
示例#8
0
    pass

if manage_rules == '1':
    serv = funct.is_ip_or_dns(form.getvalue('serv'))
    funct.check_is_server_in_group(serv)
    title = "Manage rules - Web application firewall"
    rules = sql.select_waf_rules(serv)
elif waf_rule_id:
    serv = funct.is_ip_or_dns(form.getvalue('serv'))
    funct.check_is_server_in_group(serv)
    title = 'Edit a WAF rule'
    waf_rule_file = sql.select_waf_rule_by_id(waf_rule_id)
    configs_dir = sql.get_setting('tmp_config_path')
    cfg = configs_dir + serv + "-" + funct.get_data(
        'config') + "-" + waf_rule_file
    error = funct.get_config(serv, cfg, waf=1, waf_rule_file=waf_rule_file)

    try:
        conf = open(cfg, "r")
        config_read = conf.read()
        conf.close()
    except IOError:
        print('Cannot read imported config file')
else:
    title = "Web application firewall"
    servers_waf = sql.select_waf_servers_metrics(user_id.value)
    autorefresh = 1

template = template.render(h2=1,
                           title=title,
                           autorefresh=autorefresh,