codekingpro/portable-devtools
115k
1import re2import sys3 4DEPRECATED = """5--confdir6-Z7--body-size-limit8--stream9--palette10--palette-transparent11--follow12--order13--no-mouse14--reverse15--http2-priority16--no-http2-priority17--no-websocket18--websocket19--upstream-bind-address20--ciphers-client21--ciphers-server22--client-certs23--no-upstream-cert24--add-upstream-certs-to-client-chain25--upstream-trusted-confdir26--upstream-trusted-ca27--ssl-version-client28--ssl-version-server29--no-onboarding30--onboarding-host31--onboarding-port32--server-replay-use-header33--no-pop34--replay-ignore-content35--replay-ignore-payload-param36--replay-ignore-param37--replay-ignore-host38--replace-from-file39"""40 41REPLACED = """42-t43-u44--wfile45-a46--afile47-z48-b49--bind-address50--port51-I52--ignore53--tcp54--cert55--insecure56-c57--replace58--replacements59-i60-f61--filter62--socks63--server-replay-nopop64"""65 66REPLACEMENTS = {67 "--stream": "stream_large_bodies",68 "--palette": "console_palette",69 "--palette-transparent": "console_palette_transparent:",70 "--follow": "console_focus_follow",71 "--order": "view_order",72 "--no-mouse": "console_mouse",73 "--reverse": "view_order_reversed",74 "--no-websocket": "websocket",75 "--no-upstream-cert": "upstream_cert",76 "--upstream-trusted-confdir": "ssl_verify_upstream_trusted_confdir",77 "--upstream-trusted-ca": "ssl_verify_upstream_trusted_ca",78 "--no-onboarding": "onboarding",79 "--no-pop": "server_replay_reuse",80 "--replay-ignore-content": "server_replay_ignore_content",81 "--replay-ignore-payload-param": "server_replay_ignore_payload_params",82 "--replay-ignore-param": "server_replay_ignore_params",83 "--replay-ignore-host": "server_replay_ignore_host",84 "--replace-from-file": "replacements (use @ to specify path)",85 "-t": "--stickycookie",86 "-u": "--stickyauth",87 "--wfile": "--save-stream-file",88 "-a": "-w Prefix path with + to append.",89 "--afile": "-w Prefix path with + to append.",90 "-z": "--anticomp",91 "-b": "--listen-host",92 "--bind-address": "--listen-host",93 "--port": "--listen-port",94 "-I": "--ignore-hosts",95 "--ignore": "--ignore-hosts",96 "--tcp": "--tcp-hosts",97 "--cert": "--certs",98 "--insecure": "--ssl-insecure",99 "-c": "-C",100 "--replace": ["--modify-body", "--modify-headers"],101 "--replacements": ["--modify-body", "--modify-headers"],102 "-i": "--intercept",103 "-f": "--view-filter",104 "--filter": "--view-filter",105 "--socks": "--mode socks5",106 "--server-replay-nopop": "--server-replay-reuse",107}108 109 110def check():111 args = sys.argv[1:]112 print()113 if "-U" in args:114 print("-U is deprecated, please use --mode upstream:SPEC instead")115 116 if "-T" in args:117 print("-T is deprecated, please use --mode transparent instead")118 119 for option in ("-e", "--eventlog", "--norefresh"):120 if option in args:121 print(f"{option} has been removed.")122 123 for option in ("--nonanonymous", "--singleuser", "--htpasswd"):124 if option in args:125 print(126 "{} is deprecated.\n"127 "Please use `--proxyauth SPEC` instead.\n"128 'SPEC Format: "username:pass", "any" to accept any user/pass combination,\n'129 '"@path" to use an Apache htpasswd file, or\n'130 '"ldap[s]:url_server_ldap[:port]:dn_auth:password:dn_subtree[?search_filter_key=...]" '131 "for LDAP authentication.".format(option)132 )133 134 for option in REPLACED.splitlines():135 if option in args:136 r = REPLACEMENTS.get(option)137 if isinstance(r, list):138 new_options = r139 else:140 new_options = [r]141 print(142 "{} is deprecated.\nPlease use `{}` instead.".format(143 option, "` or `".join(new_options)144 )145 )146 147 for option in DEPRECATED.splitlines():148 if option in args:149 print(150 "{} is deprecated.\n"151 "Please use `--set {}=value` instead.\n"152 "To show all options and their default values use --options".format(153 option,154 REPLACEMENTS.get(option, None)155 or option.lstrip("-").replace("-", "_"),156 )157 )158 159 # Check for underscores in the options. Options always follow '--'.160 for argument in args:161 underscoreParam = re.search(r"[-]{2}((.*?_)(.*?(\s|$)))+", argument)162 if underscoreParam is not None:163 print(164 "{} uses underscores, please use hyphens {}".format(165 argument, argument.replace("_", "-")166 )167 )168 