Example #1
0
def main(unused_argv):
    """Main."""
    token = GetToken()
    config_lib.CONFIG.AddContext("Commandline Context")
    config_lib.CONFIG.AddContext("ConfigUpdater Context")

    if flags.FLAGS.subparser_name == "initialize":
        startup.ConfigInit()
        if flags.FLAGS.noprompt:
            InitializeNoPrompt(config_lib.CONFIG, token=token)
        else:
            Initialize(config_lib.CONFIG, token=token)
        return

    startup.Init()

    try:
        print "Using configuration %s" % config_lib.CONFIG
    except AttributeError:
        raise RuntimeError("No valid config specified.")

    if flags.FLAGS.subparser_name == "generate_keys":
        try:
            GenerateKeys(config_lib.CONFIG,
                         overwrite_keys=flags.FLAGS.overwrite_keys)
        except RuntimeError, e:
            # GenerateKeys will raise if keys exist and overwrite_keys is not set.
            print "ERROR: %s" % e
            sys.exit(1)
        config_lib.CONFIG.Write()
Example #2
0
def Initialize(config=None, token=None):
  """Initialize or update a GRR configuration."""

  print "Checking write access on config %s" % config.parser
  if not os.access(config.parser.filename, os.W_OK):
    raise IOError("Config not writeable (need sudo?)")

  print "\nStep 0: Importing Configuration from previous installation."
  options_imported = 0
  prev_config_file = config.Get("ConfigUpdater.old_config", default=None)
  if prev_config_file and os.access(prev_config_file, os.R_OK):
    print "Found config file %s." % prev_config_file
    if raw_input("Do you want to import this configuration?"
                 " [yN]: ").upper() == "Y":
      options_imported = ImportConfig(prev_config_file, config)
  else:
    print "No old config file found."

  print "\nStep 1: Key Generation"
  if config.Get("PrivateKeys.server_key", default=None):
    if options_imported > 0:
      print ("Since you have imported keys from another installation in the "
             "last step,\nyou probably do not want to generate new keys now.")
    if ((raw_input("You already have keys in your config, do you want to"
                   " overwrite them? [yN]: ").upper() or "N") == "Y"):
      flags.FLAGS.overwrite = True
      GenerateKeys(config)
  else:
    GenerateKeys(config)

  print "\nStep 2: Setting Basic Configuration Parameters"
  ConfigureBaseOptions(config)

  # Now load our modified config.
  startup.ConfigInit()

  print "\nStep 3: Adding Admin User"
  try:
    AddUser("admin", labels=["admin"], token=token)
  except UserError:
    if ((raw_input("User 'admin' already exists, do you want to"
                   "reset the password? [yN]: ").upper() or "N") == "Y"):
      UpdateUser("admin", password=True, add_labels=["admin"], token=token)

  print "\nStep 4: Uploading Memory Drivers to the Database"
  LoadMemoryDrivers(flags.FLAGS.share_dir, token=token)

  print "\nStep 5: Repackaging clients with new configuration."
  # We need to update the config to point to the installed templates now.
  config.Set("ClientBuilder.executables_path", os.path.join(
      flags.FLAGS.share_dir, "executables"))

  # Build debug binaries, then build release binaries.
  maintenance_utils.RepackAllBinaries(upload=True, debug_build=True,
                                      token=token)
  maintenance_utils.RepackAllBinaries(upload=True, token=token)

  print "\nInitialization complete, writing configuration."
  config.Write()
  print "Please restart the service for it to take effect.\n\n"
Example #3
0
def main(unused_argv):
    """Main."""
    # Change the startup sequence in order to set the database path, if needed.
    startup.AddConfigContext()
    startup.ConfigInit()

    if flags.FLAGS.path:
        config_lib.CONFIG.Set("Datastore.location", flags.FLAGS.path)

    startup.ServerLoggingStartupInit()
    stats.STATS = stats.StatsCollector()

    # We avoid starting some hooks because they add unneeded things
    # to the data store.
    do_not_start = set(
        ["ConfigurationViewInitHook", "FileStoreInit", "GRRAFF4Init"])
    registry.Init(skip_set=do_not_start)

    Start(data_store.DB, port=flags.FLAGS.port, is_master=flags.FLAGS.master)