Exemplo n.º 1
0
def ConfigureHostnames(config):
    """This configures the hostnames stored in the config."""

    if flags.FLAGS.external_hostname:
        hostname = flags.FLAGS.external_hostname
    else:
        print "Guessing public hostname of your server..."
        try:
            hostname = maintenance_utils.GuessPublicHostname()
            print "Using %s as public hostname" % hostname
        except (OSError, IOError):
            print "Sorry, we couldn't guess your public hostname"

        hostname = RetryQuestion(
            "Please enter your public hostname e.g. "
            "grr.example.com", "^([\\.A-Za-z0-9-]+)*$")

    print """\n\nServer URL
The Server URL specifies the URL that the clients will connect to
communicate with the server. This needs to be publically accessible. By default
this will be port 8080 with the URL ending in /control.
"""
    location = RetryQuestion("Server URL", "^http://.*/control$",
                             "http://%s:8080/control" % hostname)
    config.Set("Client.control_urls", [location])

    frontend_port = urlparse.urlparse(location).port or 80
    if frontend_port != config_lib.CONFIG.Get("Frontend.bind_port"):
        config.Set("Frontend.bind_port", frontend_port)
        print "\nSetting the frontend listening port to %d.\n" % frontend_port
        print "Please make sure that this matches your client settings.\n"

    print """\nUI URL:
The UI URL specifies where the Administrative Web Interface can be found.
"""
    ui_url = RetryQuestion("AdminUI URL", "^http[s]*://.*$",
                           "http://%s:8000" % hostname)
    config.Set("AdminUI.url", ui_url)
Exemplo n.º 2
0
def ConfigureBaseOptions(config):
    """Configure the basic options required to run the server."""

    print "We are now going to configure the server using a bunch of questions.\n"

    print """\nFor GRR to work each client has to be able to communicate with the
server. To do this we normally need a public dns name or IP address to
communicate with. In the standard configuration this will be used to host both
the client facing server and the admin user interface.\n"""
    if flags.FLAGS.external_hostname:
        hostname = flags.FLAGS.external_hostname
    else:
        print "Guessing public hostname of your server..."
        try:
            hostname = maintenance_utils.GuessPublicHostname()
            print "Using %s as public hostname" % hostname
        except (OSError, IOError):
            print "Sorry, we couldn't guess your public hostname"

        hostname = RetryQuestion(
            "Please enter your public hostname e.g. "
            "grr.example.com", "^([\\.A-Za-z0-9-]+)*$")

    print """\n\nServer URL
The Server URL specifies the URL that the clients will connect to
communicate with the server. This needs to be publically accessible. By default
this will be port 8080 with the URL ending in /control.
"""
    location = RetryQuestion("Server URL", "^http://.*/control$",
                             "http://%s:8080/control" % hostname)
    config.Set("Client.control_urls", [location])

    frontend_port = urlparse.urlparse(location).port or 80
    if frontend_port != config_lib.CONFIG.Get("Frontend.bind_port"):
        config.Set("Frontend.bind_port", frontend_port)
        print "\nSetting the frontend listening port to %d.\n" % frontend_port
        print "Please make sure that this matches your client settings.\n"

    print """\nUI URL:
The UI URL specifies where the Administrative Web Interface can be found.
"""
    ui_url = RetryQuestion("AdminUI URL", "^http[s]*://.*$",
                           "http://%s:8000" % hostname)
    config.Set("AdminUI.url", ui_url)

    print """\nMonitoring/Email domain name:
Emails concerning alerts or updates must be sent to this domain.
"""
    domain = RetryQuestion("Email domain", "^([\\.A-Za-z0-9-]+)*$",
                           "example.com")
    config.Set("Logging.domain", domain)

    print """\nMonitoring email address
Address where monitoring events get sent, e.g. crashed clients, broken server
etc.
"""
    email = RetryQuestion("Monitoring email", "", "grr-monitoring@%s" % domain)
    config.Set("Monitoring.alert_email", email)

    print """\nEmergency email address
Address where high priority events such as an emergency ACL bypass are sent.
"""
    emergency_email = RetryQuestion("Monitoring emergency email", "",
                                    "grr-emergency@%s" % domain)
    config.Set("Monitoring.emergency_access_email", emergency_email)

    config.Write()
    print("Configuration parameters set. You can edit these in %s" %
          config.parser)