Esempio n. 1
0
def listenHttp(httpoprt):
    factory = HTTPFactory()
    def _dummy(*args, **argd):
        pass 
    factory.log = _dummy
    factory.protocol = TyHttpChannel
    reactor.listenTCP(httpoprt, factory)
Esempio n. 2
0
File: main.py Progetto: gil/pac4cli
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")
    
    servicemanager.notify_ready();
Esempio n. 3
0
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")

    systemd.daemon.notify(systemd.daemon.Notification.READY)
Esempio n. 4
0
 def __init__(self):
     HTTPFactory.__init__(self)
     # We track all sub-protocols for response channel mapping
     self.reply_protocols = {}
     # Make a factory for WebSocket protocols
     self.ws_factory = WebSocketServerFactory("ws://127.0.0.1:8000")
     self.ws_factory.protocol = WebsocketProtocol
     self.ws_factory.reply_protocols = self.reply_protocols
Esempio n. 5
0
 def __init__(self):
     HTTPFactory.__init__(self)
     # We track all sub-protocols for response channel mapping
     self.reply_protocols = {}
     # Make a factory for WebSocket protocols
     self.ws_factory = WebSocketServerFactory("ws://127.0.0.1:8000")
     self.ws_factory.protocol = WebsocketProtocol
     self.ws_factory.reply_protocols = self.reply_protocols
 def __init__(self, *args, **kwargs):
     """
     @TODO: what happens if the connection is closed? 
            (I don't believe cups.Connection is holding open a persistent
            connection, but this will need to be verified)
     """
     HTTPFactory.__init__(self, *args, **kwargs)
     
     self._connection = cups.Connection()
Esempio n. 7
0
def listenHttp(httpoprt):
    factory = HTTPFactory()

    def _dummy(*args, **argd):
        pass

    factory.log = _dummy
    factory.protocol = TyHttpChannel
    reactor.listenTCP(httpoprt, factory)
Esempio n. 8
0
 def __init__(self, dbpool, cfg=None, wmscfg=None):
     HTTPFactory.__init__(self)
     self.dbpool = dbpool
     self.CFG = cfg
     self.WMSCFG = wmscfg
     proxy = cfg.get('proxy', None) # 'proxy' is required, but we
                                    # use .get for safety
     if proxy:
         self.proxy = urlparse.urlparse(proxy)
     else:
         self.proxy = None
Esempio n. 9
0
    def __init__(self, logPath=None, timeout=60*60*12, restrictedToPort=443): 
        """ 
        @param logPath: The same as for HTTPFactory. 
        @param timeout: The same as for HTTPFactory. 
 
        @param restrictedToPort: Only CONNECT requests to this port number 
            are allowed.  This may be None, in which case any port 
            is allowed. 
        @type restrictedToPort: C{int} or None 
        """ 
        assert restrictedToPort is None or type(restrictedToPort) is int, 'Invalid restrictedToPort value: %r' % (restrictedToPort,) 
 
        self.restrictedToPort = restrictedToPort 
        HTTPFactory.__init__(self, logPath, timeout) 
Esempio n. 10
0
def start_proxy(port):
    """Start the internal HTTP proxy server.

    The proxy, which runs locally, serves as a middleware,
    i.e. the client handler forwards clients' requests to the proxy,
    and the proxy is reponsible for communicating with the target server.

    It is suggested that an external HTTP proxy is specified
    in place of the internal one,
    for performance and stability considerations.
    See command line arguments for detailed information.
    """
    factory = HTTPFactory()
    factory.protocol = ConnectProxy
    reactor.listenTCP(port, factory, interface="127.0.0.1")
Esempio n. 11
0
def start_proxy(port):
    """Start the internal HTTP proxy server.

    The proxy, which runs locally, serves as a middleware,
    i.e. the client handler forwards clients' requests to the proxy,
    and the proxy is reponsible for communicating with the target server.

    It is suggested that an external HTTP proxy is specified
    in place of the internal one,
    for performance and stability considerations.
    See command line arguments for detailed information.
    """
    factory = HTTPFactory()
    factory.protocol = ConnectProxy
    reactor.listenTCP(port, factory, interface="127.0.0.1")
Esempio n. 12
0
 def buildProtocol(self, addr):
     p = HTTPFactory.buildProtocol(self, addr)
     p.dbpool = self.dbpool
     p.proxy  = self.proxy
     p.CFG = self.CFG
     p.WMSCFG = self.WMSCFG
     
     return p
Esempio n. 13
0
    def __init__(self,
                 logPath=None,
                 timeout=60 * 60 * 12,
                 restrictedToPort=443):
        """ 
        @param logPath: The same as for HTTPFactory. 
        @param timeout: The same as for HTTPFactory. 
 
        @param restrictedToPort: Only CONNECT requests to this port number 
            are allowed.  This may be None, in which case any port 
            is allowed. 
        @type restrictedToPort: C{int} or None 
        """
        assert restrictedToPort is None or type(
            restrictedToPort) is int, 'Invalid restrictedToPort value: %r' % (
                restrictedToPort, )

        self.restrictedToPort = restrictedToPort
        HTTPFactory.__init__(self, logPath, timeout)
Esempio n. 14
0
def start_server(interface, port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    interface_ips = resolve(interface)
    print(interface_ips)
    for interface_ip in interface_ips:
        logger.info("Binding to interface: '%s'" % interface_ip)
        try:
            yield reactor.listenTCP(port, factory, interface=interface_ip)
        except OSError as e:
            # Most likely the most famous reason we will see this log for,
            # is that we are trying to bind to an IPv6 interface on a
            # system that has the IPv6 stack disabled.
            logger.error("Failed to bind to interface '%s'" % interface_ip)
            continue

    servicemanager.notify_ready()
Esempio n. 15
0
def protoParser(protos, proto_func, ptype):
    """
        根据server.json中配置的server和client字段,进行
        监听和连接操作
        #service server protocol config example:
        "protocols": { 
            "server":{"co-udp":5000, "co-tcp":5001},
            "client":{"query-udp":["LO*:co-udp"]}
        } 
        这里只处理业务进程的protocol,
        Agent的相关处理在support.tcpagent.wrapper中
    """
    is_server = (ptype == "server")
    if ptype not in protos:
        return
    ps = protos[ptype]
    for p in ps:
        # get class by proto short name...
        _c = proto_func(p)
        if is_server:
            if p.endswith("-udp"):
                pinst = _c()
                reactor.listenUDP(ps[p], pinst)
            if p.endswith("-tcp"):
                factory = Factory()
                factory.protocol = _c
                reactor.listenTCP(ps[p], factory)
            if p.endswith("-http"):

                def _dummy(*args, **argd):
                    pass

                factory = HTTPFactory()
                factory.log = _dummy
                factory.protocol = _c
                reactor.listenTCP(ps[p], factory)
        else:
            if p == "query-udp":
                for target in ps[p]:
                    target_server, target_pro_name = target.split(":")
                    if target_server.endswith("*"):
                        tss = server_type_map[target_server[:-1]]
                        for target_svr_id in tss:
                            _init_query_udp(target_svr_id, target_pro_name)
                    else:
                        _init_query_udp(target_server, target_pro_name)
Esempio n. 16
0
def Proxy(createEndpoint, **kwargs):
    factory = HTTPFactory()
    factory.protocol = _Proxy
    factory.protocol.createEndpoint = createEndpoint
    return factory
Esempio n. 17
0
 def __init__(self, allowed_address, *args, **kwargs):
     self.allowed_address = allowed_address
     HTTPFactory.__init__(self, *args, **kwargs)
Esempio n. 18
0
        self.port = port

    def clientConnectionFailed(self, connector, reason):
        self.request.fail("Gateway Error", str(reason))


if __name__ == '__main__':
    _log.startLogging(sys.stdout)

    ap = argparse.ArgumentParser()
    ap.add_argument('port', default=8090, nargs='?', type=int)
    ap.add_argument('--ssl-cert', type=str)
    ap.add_argument('--ssl-key', type=str)
    ns = ap.parse_args()

    factory = HTTPFactory()
    factory.protocol = ConnectProxy

    if ns.ssl_key and not ns.ssl_cert:
        log.info("--ssl-key must be used with --ssl-cert")
        sys.exit(1)
    if ns.ssl_cert:
        with open(ns.ssl_cert, 'rb') as fp:
            ssl_cert = fp.read()
        if ns.ssl_key:
            from OpenSSL import crypto
            with open(ns.ssl_key, 'rb') as fp:
                ssl_key = fp.read()
            certificate = ssl.PrivateCertificate.load(
                ssl_cert, ssl.KeyPair.load(ssl_key, crypto.FILETYPE_PEM),
                crypto.FILETYPE_PEM)
Esempio n. 19
0
 def __init__(self, allowed_address, *args, **kwargs):
     self.allowed_address = allowed_address
     HTTPFactory.__init__(self, *args, **kwargs)
Esempio n. 20
0
                self.setHeader('Content-Type', 'application/json')
                self.setResponseCode(NOT_FOUND)
                self.write(_NOT_FOUND_MSG)
                self.finish()
                return

            controllerClass(self, **kwargs)

    return FrontHandler


class FrontChannel(HTTPChannel):
    requestFactory = getFrontHandler()


httpFactory = HTTPFactory.forProtocol(FrontChannel)


class TCPServer(BaseTCPServer):

    def startService(self):
        BaseTCPServer.startService(self)

        protocolFactory = self.args[1]
        mainController = protocolFactory.protocol.requestFactory.mainController
        mainController.onStart()

    def stopService(self):
        protocolFactory = self.args[1]
        mainController = protocolFactory.protocol.requestFactory.mainController
        mainController.onStop()
Esempio n. 21
0
def Proxy(createEndpoint, **kwargs):
    factory = HTTPFactory()
    factory.protocol = _Proxy
    factory.protocol.createEndpoint = createEndpoint
    return factory
Esempio n. 22
0
 def __init__(self):
     HTTPFactory.__init__(self)
     #self.agent = client.Agent(reactor, pool = client.HTTPConnectionPool(reactor))
     self.agent = client.Agent(reactor, pool=SlowPool(reactor))
class HTTPSClientCertProxyChannel(HTTPChannel):

    requestFactory = ClientCertRequest


if __name__ == "__main__":

    import argparse

    parser = argparse.ArgumentParser(description="""HTTP proxy that uses a given client certificate to authenticate all proxied
requests with the server.
Notice, that all requests have to be http, even if the target is https.
All requests will be rewritten to https.""")
    parser.add_argument('-c', '--cert', dest="cert", type=str, required=True,
                        help="The certificate to use in pem format.")
    parser.add_argument('-k', '--key', dest="key", type=str, required=True,
                        help="The private key to use in pem format.")
    parser.add_argument('-p', '--port', dest='port', type=int, default=8080,
                        help="The port the HTTP proxy listens on (default: 8080).")
    args = parser.parse_args()

    CERTFILE = args.cert
    KEYFILE = args.key

    httpFactory = HTTPFactory()
    httpFactory.protocol = HTTPSClientCertProxyChannel
    reactor.listenTCP(args.port, httpFactory)
    print "now starting..."
    reactor.run()
Esempio n. 24
0
File: http.py Progetto: 18sg/SHET
	def __init__(self, shet):
		self.shet = shet
		HTTPFactory.__init__(self)
 def __init__(self, logPath=None, timeout=60*60*12):
     HTTPFactory.__init__(self, logPath,timeout)
Esempio n. 26
0
 def __init__(self):
     HTTPFactory.__init__(self)
     #self.agent = client.Agent(reactor, pool = client.HTTPConnectionPool(reactor))
     self.agent = client.Agent(reactor, pool = SlowPool(reactor))
Esempio n. 27
0
File: http.py Progetto: 18sg/SHET
	def buildProtocol(self, *args, **kwargs):
		p = HTTPFactory.buildProtocol(self, *args, **kwargs)
		p.shet = self.shet
		return p
Esempio n. 28
0
All requests will be rewritten to https.""")
    parser.add_argument('-c',
                        '--cert',
                        dest="cert",
                        type=str,
                        required=True,
                        help="The certificate to use in pem format.")
    parser.add_argument('-k',
                        '--key',
                        dest="key",
                        type=str,
                        required=True,
                        help="The private key to use in pem format.")
    parser.add_argument(
        '-p',
        '--port',
        dest='port',
        type=int,
        default=8080,
        help="The port the HTTP proxy listens on (default: 8080).")
    args = parser.parse_args()

    CERTFILE = args.cert
    KEYFILE = args.key

    httpFactory = HTTPFactory()
    httpFactory.protocol = HTTPSClientCertProxyChannel
    reactor.listenTCP(args.port, httpFactory)
    print "now starting..."
    reactor.run()