<reponame>six-two/pentest-logger
# local files
from pt_helper import ParamManipulator, ParamInfo, Settings, BaseToolWrapper, Param
from pt_helper.utils import HOSTNAME, IP_ADDRESS

# -h is short for --header
FLAG_BLOCKLIST = ["-v", "--version", "--help"]

PARAMS = {
    # --proxy <host:port|auto>      (experimental) proxy connects via <host:port>, auto: values from $env ($http(s)_proxy)
    Param.Proxy: ParamInfo("--proxy"),
}

# There are way to many output options to check for them all

# testssl --help | grep \\-oA
# --out(f,F)ile|-oa/-oA <fname> log to a LOG,JSON,CSV,HTML file (see nmap). -oA/-oa: pretty/flat JSON.
OUTPUT_ALL = ParamInfo("-oA", ["--outfile", "--outFile", "-oa"])

# "testssl <URI>", where <URI> is:
#     <URI>                         host|host:port|URL|URL:port   port 443 is default, URL can only contain HTTPS protocol)
TARGET_PATTERN_LIST = [
    # Protocol? + Host + Port? + Path?
    r"(https://)?" + f"({HOSTNAME}|{IP_ADDRESS})" + r"(:\d{1,5})?"+ r"(\/.*)?"
]


class Testssl(BaseToolWrapper):
    def __init__(self, settings: Settings) -> None:
        super().__init__(
            settings, FLAG_BLOCKLIST, PARAMS, TARGET_PATTERN_LIST, add_at_the_front=True
        )

    def rewrite_arguments_custom(
        self, params: ParamManipulator, output_dir: str
    ) -> None:
        params.add_if_unset(OUTPUT_ALL, [output_dir], self.add_at_the_front)

# local files
from pt_helper import ParamManipulator, ParamInfo, Settings, BaseToolWrapper, Param
from pt_helper.utils import HOSTNAME, IP_ADDRESS

# -h is short for --header
FLAG_BLOCKLIST = ["-v", "--version", "--help"]

PARAMS = {
    # --proxy <host:port|auto>      (experimental) proxy connects via <host:port>, auto: values from $env ($http(s)_proxy)
    Param.Proxy: ParamInfo("--proxy"),
}

# There are way to many output options to check for them all

# testssl --help | grep \\-oA
# --out(f,F)ile|-oa/-oA <fname> log to a LOG,JSON,CSV,HTML file (see nmap). -oA/-oa: pretty/flat JSON.
OUTPUT_ALL = ParamInfo("-oA", ["--outfile", "--outFile", "-oa"])

# "testssl <URI>", where <URI> is:
#     <URI>                         host|host:port|URL|URL:port   port 443 is default, URL can only contain HTTPS protocol)
TARGET_PATTERN_LIST = [
    # Protocol? + Host + Port? + Path?
    r"(https://)?" + f"({HOSTNAME}|{IP_ADDRESS})" + r"(:\d{1,5})?"+ r"(\/.*)?"
]


class Testssl(BaseToolWrapper):
    def __init__(self, settings: Settings) -> None:
        super().__init__(
            settings, FLAG_BLOCKLIST, PARAMS, TARGET_PATTERN_LIST, add_at_the_front=True
        )

    def rewrite_arguments_custom(
        self, params: ParamManipulator, output_dir: str
    ) -> None:
        params.add_if_unset(OUTPUT_ALL, [output_dir], self.add_at_the_front)
# local files # -h is short for --header # --proxy <host:port|auto>      (experimental) proxy connects via <host:port>, auto: values from $env ($http(s)_proxy) # There are way to many output options to check for them all # testssl --help | grep \\-oA # --out(f,F)ile|-oa/-oA <fname> log to a LOG,JSON,CSV,HTML file (see nmap). -oA/-oa: pretty/flat JSON. # "testssl <URI>", where <URI> is: #     <URI>                         host|host:port|URL|URL:port   port 443 is default, URL can only contain HTTPS protocol) # Protocol? + Host + Port? + Path?