Exemplo n.º 1
0
    def __init__(self, socket_port=0, ssl_certificate="", ssl_private_key="", *args, **kwargs):

        santiago.debug_log("Creating Monitor.")

        super(HttpsMonitor, self).__init__(*args, **kwargs)

        cherrypy.server.socket_port = int(socket_port)
        cherrypy.server.ssl_certificate = ssl_certificate
        cherrypy.server.ssl_private_key = ssl_private_key

        try:
            dispatch = cherrypy.tree.apps[""].config["/"]["request.dispatch"]
        except KeyError:
            dispatch = cherrypy.dispatch.RoutesDispatcher()

        root = HttpRoot(self.santiago)

        routing_pairs = (
            ("/hosting/:client/:service", HttpHostedService(self.santiago)),
            ("/hosting/:client", HttpHostedClient(self.santiago)),
            ("/hosting", HttpHosting(self.santiago)),
            ("/consuming/:host/:service", HttpConsumedService(self.santiago)),
            ("/consuming/:host", HttpConsumedHost(self.santiago)),
            ("/consuming", HttpConsuming(self.santiago)),
            ("/query/:host/:service", HttpQuery(self.santiago)),
            ("/stop", HttpStop(self.santiago)),
            ("/freedombuddy", root),
        )

        for location, handler in routing_pairs:
            HttpsMonitor.rest_connect(dispatch, location, handler)

        cherrypy.tree.mount(root, "", {"/": {"request.dispatch": dispatch}})

        santiago.debug_log("Monitor Created.")
Exemplo n.º 2
0
    def index(self):
        """Receive an incoming Santiago request from another Santiago client."""

        try:
            body = cherrypy.request.body.read()
            santiago.debug_log("Received request {0}".format(str(body)))

            kwargs = urlparse.parse_qs(body)

            command("--request {0}".format(pipes.quote(kwargs["request"][0])))
        except Exception as error:
            logging.exception(error)
Exemplo n.º 3
0
    def index(self):
        """Receive an incoming Santiago request from another Santiago client."""

        try:
            body = cherrypy.request.body.read()
            santiago.debug_log("Received request {0}".format(str(body)))

            kwargs = urlparse.parse_qs(body)

            command("--request {0}".format(pipes.quote(kwargs["request"][0])))
        except Exception as error:
            logging.exception(error)
Exemplo n.º 4
0
def allow_requests(requests=None):
    """Refuse non-whitelisted request types.

    Defaults to "GET"

    """
    if requests is None:
        requests = ["GET"]

    # just in case they entered a single allowed type, like "POST"
    if not hasattr(requests, "__iter__"):
        requests = [requests]

    if cherrypy.request.method not in requests:
        santiago.debug_log("Request of improper type.  Forbidden.")
        raise cherrypy.HTTPError(405)
Exemplo n.º 5
0
def allow_ips(ips=None):
    """Refuse connections from non-whitelisted IPs.

    Defaults to the localhost.

    Hook documentation is available in:

    http://docs.cherrypy.org/dev/progguide/extending/customtools.html

    """
    if ips == None:
        ips = ["127.0.0.1"]

    if cherrypy.request.remote.ip not in ips:
        santiago.debug_log("Request from non-local IP.  Forbidden.")
        raise cherrypy.HTTPError(403)
Exemplo n.º 6
0
    def __init__(self, socket_port=0, ssl_certificate="", ssl_private_key="", *args, **kwargs):

        santiago.debug_log("Creating Listener.")

        super(HttpsListener, self).__init__(*args, **kwargs)

        cherrypy.server.socket_port = int(socket_port)
        cherrypy.server.ssl_certificate = ssl_certificate
        cherrypy.server.ssl_private_key = ssl_private_key

        dispatch = cherrypy.dispatch.RoutesDispatcher()
        dispatch.connect("index", "/", self.index)

        cherrypy.tree.mount(cherrypy.Application(self), "", {"/": {"request.dispatch": dispatch}})

        santiago.debug_log("Listener Created.")
Exemplo n.º 7
0
def allow_requests(requests = None):
    """Refuse non-whitelisted request types.

    Defaults to "GET"

    """
    if requests is None:
        requests = [ "GET" ]

    # just in case they entered a single allowed type, like "POST"
    if not hasattr(requests, "__iter__"):
        requests = [requests]

    if cherrypy.request.method not in requests:
        santiago.debug_log("Request of improper type.  Forbidden.")
        raise cherrypy.HTTPError(405)
Exemplo n.º 8
0
def allow_ips(ips = None):
    """Refuse connections from non-whitelisted IPs.

    Defaults to the localhost.

    Hook documentation is available in:

    http://docs.cherrypy.org/dev/progguide/extending/customtools.html

    """
    if ips == None:
        ips = [ "127.0.0.1" ]

    if cherrypy.request.remote.ip not in ips:
        santiago.debug_log("Request from non-local IP.  Forbidden.")
        raise cherrypy.HTTPError(403)
Exemplo n.º 9
0
    def __init__(self, socket_port=0,
                 ssl_certificate="", ssl_private_key="",
                 *args, **kwargs):

        santiago.debug_log("Creating Listener.")

        super(HttpsListener, self).__init__(*args, **kwargs)

        cherrypy.server.socket_port = int(socket_port)
        cherrypy.server.ssl_certificate = ssl_certificate
        cherrypy.server.ssl_private_key = ssl_private_key

        dispatch = cherrypy.dispatch.RoutesDispatcher()
        dispatch.connect("index", "/", self.index)

        cherrypy.tree.mount(cherrypy.Application(self), "",
                            {"/": {"request.dispatch": dispatch}})

        santiago.debug_log("Listener Created.")
Exemplo n.º 10
0
    def __init__(self, socket_port=0,
                 ssl_certificate="", ssl_private_key="",
                 *args, **kwargs):

        santiago.debug_log("Creating Monitor.")

        super(HttpsMonitor, self).__init__(*args, **kwargs)

        cherrypy.server.socket_port = int(socket_port)
        cherrypy.server.ssl_certificate = ssl_certificate
        cherrypy.server.ssl_private_key = ssl_private_key

        try:
            dispatch = cherrypy.tree.apps[""].config["/"]["request.dispatch"]
        except KeyError:
            dispatch = cherrypy.dispatch.RoutesDispatcher()

        root = HttpRoot(self.santiago)

        routing_pairs = (
            ('/hosting/:client/:service', HttpHostedService(self.santiago)),
            ('/hosting/:client', HttpHostedClient(self.santiago)),
            ('/hosting', HttpHosting(self.santiago)),
            ('/consuming/:host/:service', HttpConsumedService(self.santiago)),
            ('/consuming/:host', HttpConsumedHost(self.santiago)),
            ('/consuming', HttpConsuming(self.santiago)),
            ('/query/:host/:service', HttpQuery(self.santiago)),
            ("/stop", HttpStop(self.santiago)),
            ("/freedombuddy", root),
            )

        for location, handler in routing_pairs:
            HttpsMonitor.rest_connect(dispatch, location, handler)

        cherrypy.tree.mount(root, "", {"/": {"request.dispatch": dispatch}})

        santiago.debug_log("Monitor Created.")
Exemplo n.º 11
0
    def outgoing_request(self, request, destination):
        """Send an HTTPS request to each Santiago client.

        Don't queue, just immediately send the reply to each location we know.

        It's both simple and as reliable as possible.

        ``request`` is literally the request's text.  It needs to be wrapped for
        transport across the protocol.

        """
        santiago.debug_log("request {0}".format(str(request)))

        body = urllib.urlencode({"request": request})

        if self.proxy:
            destination = str(destination)
            self.proxy.connect((destination.rsplit(":", 1)[0], int(destination.rsplit(":", 1)[1])))
            self.proxy.send("POST " + body)
            self.proxy.close()
        else:
            connection = httplib.HTTPSConnection(destination.split("//")[1])
            connection.request("POST", "/", body)
            connection.close()
Exemplo n.º 12
0
    def outgoing_request(self, request, destination):
        """Send an HTTPS request to each Santiago client.

        Don't queue, just immediately send the reply to each location we know.

        It's both simple and as reliable as possible.

        ``request`` is literally the request's text.  It needs to be wrapped for
        transport across the protocol.

        """
        santiago.debug_log("request {0}".format(str(request)))

        body = urllib.urlencode({ "request": request })

        if self.proxy:
            destination = str(destination)
            self.proxy.connect((destination.rsplit(":", 1)[0], int(destination.rsplit(":", 1)[1])))
            self.proxy.send('POST ' + body)
            self.proxy.close()
        else:
            connection = httplib.HTTPSConnection(destination.split("//")[1])
            connection.request("POST", "/", body)
            connection.close()
Exemplo n.º 13
0
        logging.getLogger("cherrypy.error").setLevel(logging.DEBUG)

    # load configuration settings
    config_data = (utilities.load_config(options.config) if options.config else
                   utilities.load_default_configs())

    mykey = config_data.get("general", "keyid")
    protocols = listify_string(config_data.get("connectors", "protocols"))
    connectors = load_connectors(protocols, config_data)
    force_sender = config_data.get("connectors", "force_sender")

    # create listeners and senders
    listeners, senders, monitors = configure_connectors(protocols, connectors)

    # if we can't find a service config file, load default services.
    hosting, consuming = load_services(utilities.CONFIG_DIRS, config_data)

    santiago.debug_log("Santiago!")
    freedombuddy = santiago.Santiago(
        listeners, senders, hosting, consuming,
        my_key_id=mykey, monitors=monitors,
        save_dir="data", save_services=(not options.forget_services),
        force_sender=force_sender)

    # run
    with freedombuddy:
        if "https" in protocols:
            webbrowser.open_new_tab(hosting[mykey]["freedombuddy-monitor"])

    santiago.debug_log("Santiago startup finished!")
Exemplo n.º 14
0
        service = "freedombuddy"
        hosting = {
            mykey: {
                service: [url],
                service + "-monitor": [url + "/freedombuddy"]
            }
        }
        consuming = {
            mykey: {
                service: [url],
                service + "-monitor": [url + "/freedombuddy"]
            }
        }
    else:
        hosting = consuming = None
    santiago.debug_log("Santiago!")
    freedombuddy = santiago.Santiago(listeners,
                                     senders,
                                     hosting,
                                     consuming,
                                     my_key_id=mykey,
                                     monitors=monitors,
                                     save_dir="data",
                                     force_sender=force_sender)

    # run
    with freedombuddy:
        if "https" in protocols:
            webbrowser.open_new_tab(url + "/freedombuddy")

    santiago.debug_log("Santiago finished!")
Exemplo n.º 15
0
    # load configuration settings
    mykey, protocols, connectors, force_sender, url = (
        load_config(options.config))

    # create listeners and senders
    listeners, senders, monitors = configure_connectors(protocols, connectors)

    # configure system
    # TODO Set this automatically when no relevant data/(keyid).dat file exists.
    if options.default_services:
        service = "freedombuddy"
        hosting = { mykey: { service: [url],
                             service + "-monitor" : [url + "/freedombuddy"] } }
        consuming = { mykey: { service: [url],
                             service + "-monitor" : [url + "/freedombuddy"] } }
    else:
        hosting = consuming = None
    santiago.debug_log("Santiago!")
    freedombuddy = santiago.Santiago(listeners, senders, hosting, consuming,
                                     my_key_id=mykey, monitors=monitors,
                                     save_dir="data",
                                     force_sender=force_sender)

    # run
    with freedombuddy:
        if "https" in protocols:
            webbrowser.open_new_tab(url + "/freedombuddy")

    santiago.debug_log("Santiago finished!")