コード例 #1
0
ファイル: config.py プロジェクト: ptzagk/haproxy-wi
error = ""
aftersave = ""

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.get_dick_permit()
    token = sql.get_token(user_id.value)
except:
    pass

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:
コード例 #2
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)
    conf = open(cfg, "r")

    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 "#use_backend" 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("!!! There was an issue, " + str(e))

    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)
コード例 #3
0
    metrics_worker, stderr = funct.subprocess_execute(cmd)
    cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l"
    keep_alive, stderr = funct.subprocess_execute(cmd)
    cmd = "ps ax |grep '(wsgi:api)'|grep -v grep|wc -l"
    api, stderr = funct.subprocess_execute(cmd)
    servers = sql.get_dick_permit()
except:
    pass

template = template.render(h2=1,
                           autorefresh=1,
                           title="Overview",
                           role=role,
                           user=user,
                           users=users,
                           groups=groups,
                           roles=sql.select_roles(),
                           metrics_master=''.join(metrics_master),
                           metrics_worker=''.join(metrics_worker),
                           checker_master=''.join(checker_master),
                           checker_worker=''.join(checker_worker),
                           keep_alive=''.join(keep_alive),
                           api=''.join(api),
                           date=funct.get_data('logs'),
                           error=stderr,
                           versions=funct.versions(),
                           haproxy_wi_log=funct.haproxy_wi_log(),
                           servers=servers,
                           token=token)
print(template)
コード例 #4
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()
	
	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:
			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:
			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=(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>')
		
	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)		
コード例 #5
0
    title = "Working with Keepalived configs"
    action = "config.py?service=keepalived"
    configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir')
    format = 'conf'
    servers = sql.get_dick_permit()
    keepalived = 1
else:
    title = "Working with HAProxy configs"
    action = "config.py"
    configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
    format = 'cfg'
    servers = sql.get_dick_permit()
    keepalived = 0

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

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

    if service == 'keepalived':
        error = funct.get_config(serv, cfg, keepalived=1)
        try:
            funct.logging(serv, "keepalivedconfig.py open config")
        except:
            pass
    else:
        error = funct.get_config(serv, cfg)
        try:
            funct.logging(serv, "config.py open config")
        except:
            pass
コード例 #6
0
        configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir')
        file_format = 'conf'
        servers = sql.get_dick_permit(nginx=1)
else:
    if funct.check_login(service=1):
        title = "Working with HAProxy configuration files"
        action = "config.py"
        configs_dir = funct.get_config_var('configs',
                                           'haproxy_save_configs_dir')
        file_format = 'cfg'
        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,
コード例 #7
0
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)
    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"
コード例 #8
0
ファイル: keepalivedconfig.py プロジェクト: oy1978/haproxy-wi
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

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"
コード例 #9
0
ファイル: waf.py プロジェクト: gunawanw9/haproxy-wi
    )
except Exception:
    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,
コード例 #10
0
		selected = "selected"
	else:
		selected = ""
	print('<option value="%s" %s>%s</option>' % (server[1],selected, server[0]))
	if serv == server[3]:
		selected = "selected"
	else:
		selected = ""
	print('<option value="%s" %s>%s</option>' % (server[3], selected, server[2]))
	
print('</select>')
funct.get_button("Open", value="open")
print('</form>')

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('<div class="alert alert-danger">Can\'t read import config file</div>')

	print("<center><h3>Config from %s</h3>" % serv)
	print('<form action="" method="get">')
	print('<input type="hidden" value="%s" name="serv">' % serv)
	print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)