Ejemplo n.º 1
0
def main(_):
    """Run the main test harness."""
    config_lib.CONFIG.AddContext(
        "AdminUI Context",
        "Context applied when running the admin user interface GUI.")
    startup.Init()

    # Start up a server in another thread
    bind_address = config_lib.CONFIG["AdminUI.bind"]
    ip = ipaddr.IPAddress(bind_address)
    if ip.version == 4:
        # Address looks like an IPv4 address.
        ThreadingDjango.address_family = socket.AF_INET

    max_port = config_lib.CONFIG.Get("AdminUI.port_max",
                                     config_lib.CONFIG["AdminUI.port"])

    for port in range(config_lib.CONFIG["AdminUI.port"], max_port + 1):
        # Make a simple reference implementation WSGI server
        try:
            server = simple_server.make_server(bind_address,
                                               port,
                                               django_lib.GetWSGIHandler(),
                                               server_class=ThreadingDjango)
            break
        except socket.error as e:
            if e.errno == socket.errno.EADDRINUSE and port < max_port:
                logging.info("Port %s in use, trying %s", port, port + 1)
            else:
                raise

    proto = "HTTP"

    if config_lib.CONFIG["AdminUI.enable_ssl"]:
        cert_file = config_lib.CONFIG["AdminUI.ssl_cert_file"]
        if not cert_file:
            raise ValueError("Need a valid cert file to enable SSL.")

        key_file = config_lib.CONFIG["AdminUI.ssl_key_file"]
        server.socket = ssl.wrap_socket(server.socket,
                                        certfile=cert_file,
                                        keyfile=key_file,
                                        server_side=True)
        proto = "HTTPS"

        # SSL errors are swallowed by the WSGIServer so if your configuration does
        # not work, uncomment the line below, point your browser at the gui and look
        # at the log file to see why SSL complains:
        # server.socket.accept()

    sa = server.socket.getsockname()
    logging.info("Serving %s on %s port %d ...", proto, sa[0], sa[1])
    startup.DropPrivileges()

    server.serve_forever()
Ejemplo n.º 2
0
    def run(self):
        """Run the django server in a thread."""
        logging.info("Base URL is %s", self.base_url)
        port = config_lib.CONFIG["AdminUI.port"]
        logging.info("Django listening on port %d.", port)
        try:
            # Make a simple reference implementation WSGI server
            server = simple_server.make_server("0.0.0.0", port,
                                               django_lib.GetWSGIHandler())
        except socket.error as e:
            raise socket.error("Error while listening on port %d: %s." %
                               (port, str(e)))

        while self.keep_running:
            server.handle_request()
Ejemplo n.º 3
0
  def run(self):
    """Run the django server in a thread."""
    logging.info("Base URL is %s", self.base_url)
    port = self.port
    logging.info("Django listening on port %d.", port)
    try:
      # Make a simple reference implementation WSGI server
      server = simple_server.make_server("0.0.0.0", port,
                                         django_lib.GetWSGIHandler())
    except socket.error as e:
      raise socket.error(
          "Error while listening on port %d: %s." % (port, str(e)))

    # We want to notify other threads that we are now ready to serve right
    # before we enter the serving loop.
    self.ready_to_serve.set()
    while self.keep_running:
      server.handle_request()
def main(_):
  """Run the main test harness."""
  config_lib.CONFIG.AddContext(
      "AdminUI Context",
      "Context applied when running the admin user interface GUI.")
  startup.Init()

  # Start up a server in another thread

  # Make a simple reference implementation WSGI server
  server = simple_server.make_server(config_lib.CONFIG["AdminUI.bind"],
                                     config_lib.CONFIG["AdminUI.port"],
                                     django_lib.GetWSGIHandler(),
                                     server_class=ThreadingDjango)

  proto = "HTTP"

  if config_lib.CONFIG["AdminUI.enable_ssl"]:
    cert_file = config_lib.CONFIG["AdminUI.ssl_cert_file"]
    if not cert_file:
      raise ValueError("Need a valid cert file to enable SSL.")

    key_file = config_lib.CONFIG["AdminUI.ssl_key_file"]
    server.socket = ssl.wrap_socket(server.socket, certfile=cert_file,
                                    keyfile=key_file, server_side=True)
    proto = "HTTPS"

    # SSL errors are swallowed by the WSGIServer so if your configuration does
    # not work, uncomment the line below, point your browser at the gui and look
    # at the log file to see why SSL complains:
    # server.socket.accept()

  sa = server.socket.getsockname()
  logging.info("Serving %s on %s port %d ...", proto, sa[0], sa[1])

  server.serve_forever()