Esempio n. 1
0
	def addself(self):
		connection = httplib.HTTPConnection(util.host(self.controller), util.port(controller), True, 10)
		connection.request("GET", "/add" + self.type + "?host=" + self.selfhost)
		response = connection.getresponse()
		data = response.read()
		lines = data.split("\n")
		self.handle_connect(lines)
Esempio n. 2
0
def request(host, path, postdata = None):
	if postdata == None:
		type = "GET"
		body = ""
	else:
		type = "POST"
		body = postdata
	connection = httplib.HTTPConnection(util.host(host), util.port(host), True, 10)
	connection.request(type, path, body)
	response = connection.getresponse()
	data = response.read()
	connection.close()
	return data
Esempio n. 3
0
def generate(config):
    iptables_location = config["iptables_location"]
    public_ip = config["public_ip"]
    current_ip = config["base_ip"]
    current_port = config["base_port"]

    iptables_content = generate_iptables('80', public_ip, current_ip, current_port, iptables_location)
    current_port += 1
    iptables_content += generate_iptables('443', public_ip, current_ip, current_port, iptables_location)
    current_port += 1
    for group in config["groups"].values():
        for proxy in group["proxies"]:
            if proxy["dnat"]:
                current_ip = long2ip(ip2long(current_ip) + 1)
                for protocol in proxy["protocols"]:
                    iptables_content += generate_iptables(port(protocol), public_ip, current_ip, current_port, iptables_location)
                    current_port += 1
    return iptables_content
Esempio n. 4
0
def generate(config):
    public_ip = config["public_ip"]
    current_ip = config["base_ip"]
    current_port = config["base_port"]

    rinetd_content = generate_rinetd('80', public_ip, current_ip, current_port)
    current_port += 1
    rinetd_content += generate_rinetd('443', public_ip, current_ip, current_port)
    current_port += 1

    for group in config["groups"].values():
        for proxy in group["proxies"]:
            if proxy["dnat"]:
                current_ip = long2ip(ip2long(current_ip) + 1)
                for protocol in proxy["protocols"]:
                    rinetd_content += generate_rinetd(port(protocol), public_ip, current_ip, current_port)
                    current_port += 1
    return rinetd_content
Esempio n. 5
0
	def port(self):
		return util.port(self.selfhost)
Esempio n. 6
0
def generate(config, dnat=False, test=True):
    bind_ip = config["bind_ip"]
    server_options = config["server_options"]
    if "base_port" in config:
        current_port = config["base_port"]
    elif dnat:
        return

    haproxy_content = generate_global()
    haproxy_content += generate_defaults()

    if not dnat:
        http_port = 80
        https_port = 443
    else:
        http_port = current_port
        https_port = current_port + 1

    haproxy_catchall_frontend_content = generate_frontend('catchall', 'http', bind_ip, http_port, True)
    haproxy_catchall_backend_content = generate_backend('catchall', 'http', None, None, None, True)

    haproxy_catchall_frontend_ssl_content = generate_frontend('catchall', 'https', bind_ip, https_port, True)
    haproxy_catchall_backend_ssl_content = generate_backend('catchall', 'https', None, None, None, True)

    if config["stats"]["enabled"]:
        haproxy_content += generate_stats(config["stats"], bind_ip)

    for group in config["groups"].values():
        for proxy in group["proxies"]:
            if not dnat or (dnat and not proxy["dnat"]):
                for protocol in proxy["protocols"]:
                    if protocol == 'http':
                        haproxy_catchall_frontend_content += generate_frontend_catchall_entry(proxy["domain"], protocol)
                        haproxy_catchall_backend_content += generate_backend_catchall_entry(proxy["domain"], protocol, port(protocol), server_options)
                    elif protocol == 'https':
                        haproxy_catchall_frontend_ssl_content += generate_frontend_catchall_entry(proxy["domain"], protocol)
                        haproxy_catchall_backend_ssl_content += generate_backend_catchall_entry(proxy["domain"], protocol, port(protocol), server_options)
    if test:
        haproxy_catchall_frontend_content += generate_frontend_catchall_entry('ptest.verdandi.is', 'http')
        haproxy_catchall_backend_content += generate_backend_catchall_entry('ptest.verdandi.is', 'http', '80', server_options)

        haproxy_catchall_frontend_ssl_content += generate_frontend_catchall_entry('ptest.verdandi.is', 'https')
        haproxy_catchall_backend_ssl_content += generate_backend_catchall_entry('ptest.verdandi.is', 'https', '443', server_options)

    haproxy_content += haproxy_catchall_frontend_content + os.linesep
    haproxy_content += haproxy_catchall_backend_content
    haproxy_content += haproxy_catchall_frontend_ssl_content + os.linesep
    haproxy_content += haproxy_catchall_backend_ssl_content

    if dnat:
        current_port += 2
        for group in config["groups"].values():
            for proxy in group["proxies"]:
                if proxy["dnat"]:
                    for protocol in proxy["protocols"]:
                        haproxy_content += generate_frontend(proxy["alias"], protocol, bind_ip, current_port, False)
                        haproxy_content += generate_backend(proxy["alias"], protocol, proxy["domain"], port(protocol), server_options, False)
                        current_port += 1

    haproxy_content += generate_deadend('http')
    haproxy_content += generate_deadend('https')

    return haproxy_content