def get_settings(args=None, override_defaults={}):
    """Parse args and set other settings based on them

    Default settings can be overriden by passing in a dictionary
    
    Return a new dictionary containing all args and settings
    """
    # Parse the arguments:
    parser = argparser()
    args = parser.parse_args(args)
        
    settings = {
        # Store args object:
        'args': args,
        # Instruct client to post stdout back to the server:
        'receive_postbacks': True,
        # Run client script with this shell interpreter:
        'shell_command': 'bash',
        # Client fetches URL resources with this command:
        'http_fetcher': 'curl -LSs',
        # Mime type to serve resource as:
        'mime_type': args.mime_type,
        # Client should send it's hostname in the request header:
        'require_hostname_header': False,
        # Log client stdout to server stdout:
        'log_post_backs': args.log_post_backs,
        # Enable TLS
        'ssl': args.ssl,
        # ssl context passed to server
        'ssl_context': None,
        # Enable SSL certificate pinning in client command:
        'pin': args.pin or args.ssl is None,
        # Total number of allowed HTTP gets on resource:
        'num_gets': args.num_gets,
        # Require X-knock header:
        'require_knock': not args.disable_knock,
        # The current knock:
        'knock': args.knock,
        # Server verbose flag
        'verbose': args.verbose,
        # Print curl command without shell_command
        'survey': args.survey,
        # SSH tunnel
        'ssh': args.ssh,
        # Server quiet flag
        'quiet': args.quiet and not args.verbose,
        # Log stdout on client:
        'client_logging': args.client_logging,
        # Client quiet flag
        'client_quiet': args.client_quiet,
        # Popen object processing log_post_backs
        'log_process': None,
        # File to receive log_post_backs:
        'log_file': None,
        # Don't print knock in wrapped curlbomb command:
        'require_knock_from_environment': True,
        # Client should use wget instead of curl
        'wget': args.wget,
        # Don't wrap curlbomb 
        'unwrapped': args.unwrapped,
        # Use alternative stdin, only used in tests
        'stdin': sys.stdin,
        # Use alternative stdout, only used in tests
        'stdout': sys.stdout,
        # Output how long the command takes:
        'time_command': False,
        # Function to get curlbomb command given settings:
        'get_curlbomb_command': get_curlbomb_command
    }
    settings.update(override_defaults)
    
    if args.verbose:
        logging.getLogger('curlbomb').setLevel(level=logging.INFO)
        settings['log_post_backs'] = True
        logging.getLogger('tornado.access').setLevel(level=logging.INFO)

    if args.debug:
        settings['verbose'] = True
        logging.getLogger('curlbomb').setLevel(level=logging.DEBUG)
        settings['log_post_backs'] = True
        logging.getLogger('tornado.access').setLevel(level=logging.DEBUG)
        
    if settings['require_knock'] and not settings['knock']:
        settings['knock'] = base64.b64encode(bytes(random.sample(range(256), 12)),
                                             altchars=b'_.').decode("utf-8")

    if settings['survey']:
        # Don't recieve post backs in survey mode:
        settings['receive_postbacks'] = False
        settings['client_logging'] = False

    if args.disable_postback:
        settings['receive_postbacks'] = False
        
    if settings['unwrapped']:
        # Output the unrwapped version of the curlbomb Without this
        # setting, curlbomb usually outputs a url that retrieves a
        # wrapper script that wraps the longer more complicated client
        # command. This will output this unrwapped version instead.
        settings['require_knock_from_environment'] = False

    if args.pin and args.ssl is False:
        print("--pin requires --ssl")
        sys.exit(1)
        
    if args.wget:
        settings['http_fetcher'] = "wget -q -O -"
        if args.log_post_backs:
            print("wget can't stream the client output, so --log-posts is not "
                  "supported in wget mode")
            sys.exit(1)
        if args.pin:
            print("SSL certificate pinning only works in curl mode")
            sys.exit(1)

    if args.port == "random":
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind(('',0))
        settings['port'] = s.getsockname()[1]
        s.close()
    else:
        settings['port'] = int(args.port)

    settings['display_host'] = socket.gethostbyname(socket.gethostname())
    settings['display_port'] = settings['port']

    if settings['ssh']:
        ssh_parts = settings['ssh'].split(":")
        ssh_host = ssh_parts[0]
        ssh_port = 22
        http_port = settings['port']
        if len(ssh_parts) == 3:
            ssh_port = ssh_parts[1]
            http_port = ssh_parts[2]
        elif len(ssh_parts) == 2:
            http_port = ssh_parts[1]
        settings['ssh_forward'] = "0.0.0.0:{http_port}:localhost:{port}".format(
            port=settings['port'], http_port=http_port)
        settings['ssh_host'] = ssh_host
        settings['ssh_port'] = ssh_port
        settings['display_port'] = http_port
        if '@' in ssh_host:
            settings['ssh_user'], settings['display_host'] = ssh_host.split('@')
        else:
            settings['display_host'] = ssh_host

    if args.domain:
        # Override displayed host:port
        parts = args.domain.split(":")
        settings['display_host'] = parts[0]
        if len(parts) > 1:
            settings['display_port'] = parts[1]


    if settings['ssl'] is not False:
        settings['ssl_context'] = tls.get_ssl_context_from_settings(settings)
            
    if not settings['stdout'].isatty() and not settings['quiet']:
        # Imply we want log-posts if we pipe to a non-tty:
        settings['log_post_backs'] = True

    try:
        prepare_cmd = args.prepare_command
    except __HOLE__:
        # No sub-command specified, default to run command with stdin
        args.command = None
        args.script_hash = None
        args.signature = None
        args.resource = settings['stdin']
        prepare_cmd = run.prepare
    prepare_cmd(args, settings, parser)

    return settings
dataset/ETHPy150Open EnigmaCurry/curlbomb/curlbomb/settings.py/get_settings