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