2020-05-04 22:06:03 +02:00
|
|
|
|
|
|
|
|
def args(
|
|
|
|
|
):
|
|
|
|
|
argumentparser = _argparse.ArgumentParser(
|
|
|
|
|
description = "INWX CLI Frontend"
|
|
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-c",
|
|
|
|
|
"--conf",
|
2020-05-04 22:06:03 +02:00
|
|
|
dest = "conf",
|
2023-05-29 12:03:38 +02:00
|
|
|
default = _os.path.join(str(_pathlib.Path.home()), ".inwx-conf.json"),
|
|
|
|
|
metavar = "<conf>",
|
|
|
|
|
help = "path to configuration file",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-e",
|
|
|
|
|
"--environment",
|
2020-05-04 22:06:03 +02:00
|
|
|
dest = "environment",
|
2023-05-29 12:03:38 +02:00
|
|
|
metavar = "<environment>",
|
|
|
|
|
default = None,
|
|
|
|
|
help = "environment to use; one of the keys in the 'url' filed of the configuration; overwrites the configuration value",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-u",
|
|
|
|
|
"--username",
|
2020-05-04 22:06:03 +02:00
|
|
|
dest = "username",
|
2023-05-29 12:03:38 +02:00
|
|
|
metavar = "<username>",
|
|
|
|
|
default = None,
|
|
|
|
|
help = "username; overwrites the configuration value",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-p",
|
|
|
|
|
"--password",
|
2020-05-04 22:06:03 +02:00
|
|
|
dest = "password",
|
2023-05-29 12:03:38 +02:00
|
|
|
metavar = "<password>",
|
|
|
|
|
default = None,
|
|
|
|
|
help = "password; overwrites the configuration value",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
'''
|
|
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-d",
|
|
|
|
|
"--domain",
|
2020-05-04 22:06:03 +02:00
|
|
|
dest = "domain",
|
2023-05-29 12:03:38 +02:00
|
|
|
default = None,
|
|
|
|
|
metavar = "<domain>",
|
|
|
|
|
help = "the domain to work with"
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
'''
|
2023-05-29 11:39:33 +02:00
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"-x",
|
|
|
|
|
"--challenge-prefix",
|
|
|
|
|
dest = "challenge_prefix",
|
|
|
|
|
metavar = "<challenge-prefix>",
|
|
|
|
|
default = "_acme-challenge",
|
|
|
|
|
help = "which subdomain to use for ACME challanges",
|
|
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
|
|
|
|
"-w",
|
|
|
|
|
"--delay",
|
2023-05-29 11:39:33 +02:00
|
|
|
dest = "delay",
|
|
|
|
|
type = float,
|
|
|
|
|
default = 60.0,
|
2023-05-29 12:03:38 +02:00
|
|
|
metavar = "<delay>",
|
2023-05-29 11:39:33 +02:00
|
|
|
help = "seconds to wait at end of certbot auth hook",
|
|
|
|
|
)
|
2020-05-04 22:06:03 +02:00
|
|
|
argumentparser.add_argument(
|
2023-05-29 12:03:38 +02:00
|
|
|
"action",
|
|
|
|
|
type = str,
|
|
|
|
|
choices = ["info", "list", "save", "certbot-hook"],
|
|
|
|
|
metavar = "<action>",
|
|
|
|
|
help = "action to execute",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
argumentparser.add_argument(
|
|
|
|
|
"parameter",
|
|
|
|
|
nargs = "*",
|
2023-05-29 12:03:38 +02:00
|
|
|
type = str,
|
|
|
|
|
metavar = "<parameters>",
|
|
|
|
|
help = "action specific parameters",
|
2020-05-04 22:06:03 +02:00
|
|
|
)
|
|
|
|
|
arguments = argumentparser.parse_args()
|
|
|
|
|
return arguments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(
|
|
|
|
|
):
|
|
|
|
|
arguments = args()
|
|
|
|
|
|
|
|
|
|
conf_load(arguments.conf)
|
|
|
|
|
if (not (arguments.environment is None)): conf_set("environment", arguments.environment)
|
|
|
|
|
if (not (arguments.username is None)): conf_set("account.username", arguments.username)
|
|
|
|
|
if (not (arguments.password is None)): conf_set("account.password", arguments.password)
|
|
|
|
|
|
2023-05-29 12:03:38 +02:00
|
|
|
if (arguments.action == "info"):
|
2020-05-04 22:06:03 +02:00
|
|
|
result = api_macro_info(
|
|
|
|
|
conf_get("environment"),
|
|
|
|
|
conf_get("account.username"),
|
|
|
|
|
conf_get("account.password")
|
|
|
|
|
)
|
|
|
|
|
print(_json.dumps(result, indent = "\t"))
|
2023-05-29 12:03:38 +02:00
|
|
|
elif (arguments.action == "list"):
|
2020-05-04 22:06:03 +02:00
|
|
|
domain = arguments.parameter[0]
|
|
|
|
|
result = api_macro_list(
|
|
|
|
|
conf_get("environment"),
|
|
|
|
|
conf_get("account.username"),
|
|
|
|
|
conf_get("account.password"),
|
|
|
|
|
domain
|
|
|
|
|
)
|
|
|
|
|
print(_json.dumps(result, indent = "\t"))
|
2023-05-29 12:03:38 +02:00
|
|
|
elif (arguments.action == "save"):
|
2020-05-04 22:06:03 +02:00
|
|
|
domain = arguments.parameter[0]
|
|
|
|
|
name = arguments.parameter[1]
|
|
|
|
|
type_ = arguments.parameter[2]
|
|
|
|
|
content = arguments.parameter[3]
|
|
|
|
|
api_macro_save(
|
|
|
|
|
conf_get("environment"),
|
|
|
|
|
conf_get("account.username"),
|
|
|
|
|
conf_get("account.password"),
|
|
|
|
|
domain,
|
|
|
|
|
name,
|
|
|
|
|
type_,
|
|
|
|
|
content
|
|
|
|
|
)
|
|
|
|
|
# print(_json.dumps(result, indent = "\t"))
|
2023-05-29 12:03:38 +02:00
|
|
|
elif (arguments.action == "certbot-hook"):
|
2023-05-29 11:39:33 +02:00
|
|
|
domain_full_parts = _os.environ["CERTBOT_DOMAIN"].split(".", 1)
|
|
|
|
|
domain = domain_full_parts[1]
|
2023-05-29 12:03:38 +02:00
|
|
|
name = (arguments.challenge_prefix + "." + domain_full_parts[0])
|
2023-05-29 11:39:33 +02:00
|
|
|
type_ = "TXT"
|
|
|
|
|
content = _os.environ["CERTBOT_VALIDATION"]
|
|
|
|
|
api_macro_save(
|
|
|
|
|
conf_get("environment"),
|
|
|
|
|
conf_get("account.username"),
|
|
|
|
|
conf_get("account.password"),
|
|
|
|
|
domain,
|
|
|
|
|
name,
|
|
|
|
|
type_,
|
|
|
|
|
content
|
|
|
|
|
)
|
2023-05-29 12:03:38 +02:00
|
|
|
_time.sleep(arguments.delay)
|
2023-05-29 11:39:33 +02:00
|
|
|
# print(_json.dumps(result, indent = "\t"))
|
2020-05-04 22:06:03 +02:00
|
|
|
else:
|
2023-05-29 12:03:38 +02:00
|
|
|
log("unhandled action '%s'" % (arguments.action, ))
|
2020-05-04 22:06:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
main()
|
|
|
|
|
except ValueError as error:
|
|
|
|
|
_sys.stderr.write(str(error) + "\n")
|
|
|
|
|
|