示例#1
0
def main(argv=None):
    del argv  # Unused.

    config.CONFIG.AddContext(contexts.COMMAND_LINE_CONTEXT)
    config.CONFIG.AddContext(
        contexts.CONSOLE_CONTEXT,
        "Context applied when running the console binary.")
    server_startup.Init()
    fleetspeak_connector.Init()

    username = flags.FLAGS.username
    if not username:
        username = os.environ["USER"]

    if not username:
        print("Username has to be specified with either --username flag or "
              "USER environment variable.")
        sys.exit(1)

    grrapi = api.GrrApi(connector=api_shell_raw_access_lib.RawConnector(
        token=access_control.ACLToken(username=username),
        page_size=flags.FLAGS.page_size))

    if flags.FLAGS.exec_code and flags.FLAGS.exec_file:
        print("--exec_code --exec_file flags can't be supplied together.")
        sys.exit(1)
    elif flags.FLAGS.exec_code:
        # pylint: disable=exec-used
        exec(flags.FLAGS.exec_code, dict(grrapi=grrapi))
        # pylint: enable=exec-used
    elif flags.FLAGS.exec_file:
        api_shell_lib.ExecFile(flags.FLAGS.exec_file, grrapi)
    else:
        api_shell_lib.IPShell([sys.argv[0]], user_ns=dict(grrapi=grrapi))
示例#2
0
文件: api_shell.py 项目: syth3/grr
def main(argv=None):
    if not argv:
        argv = sys.argv[1:]

    arg_parser = GrrApiShellArgParser()
    flags = arg_parser.parse_args(args=argv)

    logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stderr))
    if flags.debug:
        logging.getLogger().setLevel(logging.DEBUG)

    auth = None
    if flags.basic_auth_username:
        auth = (flags.basic_auth_username, flags.basic_auth_password or "")

    verify = True
    if flags.no_check_certificate:
        verify = False

    grrapi = api.InitHttp(api_endpoint=flags.api_endpoint,
                          page_size=flags.page_size,
                          auth=auth,
                          verify=verify)

    if flags.exec_code and flags.exec_file:
        print("--exec_code --exec_file flags can't be supplied together")
        sys.exit(1)
    elif flags.exec_code:
        # pylint: disable=exec-used
        exec(flags.exec_code, dict(grrapi=grrapi))
        # pylint: enable=exec-used
    elif flags.exec_file:
        api_shell_lib.ExecFile(flags.exec_file, grrapi)
    else:
        api_shell_lib.IPShell([sys.argv[0]], user_ns=dict(grrapi=grrapi))