|
|
|
@ -7,7 +7,7 @@ import os
|
|
|
|
|
import sys
|
|
|
|
|
import urllib.parse
|
|
|
|
|
from os import environ, mkdir
|
|
|
|
|
from os.path import isdir, isfile, join, split
|
|
|
|
|
from os.path import isdir, isfile, islink, join, split
|
|
|
|
|
from typing import Union
|
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ def run_add(url: str, jsonout: bool, headers: dict):
|
|
|
|
|
output(out, jsonout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_audit(url: str, jsonout: bool, headers: dict):
|
|
|
|
|
def run_log(url: str, jsonout: bool, headers: dict):
|
|
|
|
|
response = requests.get(url, headers=headers)
|
|
|
|
|
string = response.content.decode("utf-8")
|
|
|
|
|
if jsonout:
|
|
|
|
@ -139,7 +139,15 @@ def run_config(
|
|
|
|
|
baseurl: Union[None, str] = None,
|
|
|
|
|
username: Union[None, str] = None,
|
|
|
|
|
password: Union[None, str] = None,
|
|
|
|
|
current: Union[None, str] = None,
|
|
|
|
|
):
|
|
|
|
|
if current:
|
|
|
|
|
if os.path.islink(config_filename):
|
|
|
|
|
actual_path = os.readlink(config_filename)
|
|
|
|
|
print(actual_path.split('-')[-1])
|
|
|
|
|
else:
|
|
|
|
|
print("none")
|
|
|
|
|
return
|
|
|
|
|
config = {"baseurl": baseurl, "username": username, "password": password}
|
|
|
|
|
needed = []
|
|
|
|
|
if context:
|
|
|
|
@ -354,8 +362,12 @@ def main() -> int:
|
|
|
|
|
addcmd.add_argument("-t", "--ttl")
|
|
|
|
|
addcmd.add_argument("-z", "--zone", required=True)
|
|
|
|
|
|
|
|
|
|
audit_description = "Audit the log file for errors."
|
|
|
|
|
subparsers.add_parser("audit", description=audit_description)
|
|
|
|
|
auditlog_description = "Audit the log file for errors."
|
|
|
|
|
subparsers.add_parser("auditlog", description=auditlog_description)
|
|
|
|
|
|
|
|
|
|
changelog_description = "View the changelog of a zone."
|
|
|
|
|
changelogcmd = subparsers.add_parser("changelog", description=changelog_description)
|
|
|
|
|
changelogcmd.add_argument("-z", "--zone", required=True)
|
|
|
|
|
|
|
|
|
|
complete_description = "Generate shell completion script."
|
|
|
|
|
completecmd = subparsers.add_parser("completion", description=complete_description)
|
|
|
|
@ -365,6 +377,7 @@ def main() -> int:
|
|
|
|
|
configcmd = subparsers.add_parser("config", description=config_description)
|
|
|
|
|
configcmd.add_argument("-b", "--baseurl")
|
|
|
|
|
configcmd.add_argument("-c", "--context")
|
|
|
|
|
configcmd.add_argument("-C", "--current", action=argparse.BooleanOptionalAction)
|
|
|
|
|
configcmd.add_argument("-p", "--password")
|
|
|
|
|
configcmd.add_argument("-u", "--username")
|
|
|
|
|
|
|
|
|
@ -433,7 +446,7 @@ def main() -> int:
|
|
|
|
|
|
|
|
|
|
if args.command == "config":
|
|
|
|
|
run_config(
|
|
|
|
|
config_filename, args.context, args.baseurl, args.username, args.password
|
|
|
|
|
config_filename, args.context, args.baseurl, args.username, args.password, args.current
|
|
|
|
|
)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
@ -473,8 +486,8 @@ def main() -> int:
|
|
|
|
|
soa_url = setup_url(baseurl, None, None, zname, "SOA", None, args.zone)
|
|
|
|
|
soa_json = run_list(soa_url, True, headers, ret=True)
|
|
|
|
|
ttl = soa_json[0]["ttl"]
|
|
|
|
|
if args.command == "audit":
|
|
|
|
|
url = baseurl + "/user/auditlog"
|
|
|
|
|
elif args.command in ["auditlog", "changelog"]:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
url = setup_url(
|
|
|
|
@ -499,8 +512,12 @@ def main() -> int:
|
|
|
|
|
run_list(url, args.json, headers)
|
|
|
|
|
elif args.command == "update":
|
|
|
|
|
run_update(url, args.json, headers)
|
|
|
|
|
elif args.command == "audit":
|
|
|
|
|
run_audit(url, args.json, headers)
|
|
|
|
|
elif args.command == "auditlog":
|
|
|
|
|
url = baseurl + "/user/auditlog"
|
|
|
|
|
run_log(url, args.json, headers)
|
|
|
|
|
elif args.command == "changelog":
|
|
|
|
|
url = baseurl + f"/zones/changelog/{args.zone.rstrip('.')}"
|
|
|
|
|
run_log(url, args.json, headers)
|
|
|
|
|
else:
|
|
|
|
|
parser.print_help(sys.stderr)
|
|
|
|
|
return 1
|
|
|
|
|