Mini Shell

Direktori : /proc/thread-self/root/proc/self/root/opt/tier1adv/bin/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/opt/tier1adv/bin/validate_zone

#!/opt/imh-python/bin/python3
import argparse
import sys
from pathlib import Path
import subprocess
from rads.color import green

sys.path.insert(0, '/opt/support/lib')
from arg_types import valid_domain
from output import err_exit


def get_args() -> str:
    """Parse domain from command arguments"""
    parser = argparse.ArgumentParser()
    parser.add_argument('domain', type=valid_domain, help='domain to check')
    return parser.parse_args().domain


def main():
    domain = get_args()
    zone_file = Path('/var/named', f"{domain}.db")
    if zone_file.is_file():
        print(green(f'Zone File exists at {zone_file}'))
    else:
        err_exit(f'Zone file does not exist at {zone_file}')
    try:
        ret_code = subprocess.call(['named-checkzone', domain, str(zone_file)])
    except FileNotFoundError as exc:  # named-checkzone is missing
        err_exit(str(exc))
    if ret_code:  # non-zero return code
        err_exit(f'Failed to validate the zone file at {zone_file}')
    print(green(f'Successfully validated the zone file at {zone_file}'))


if __name__ == "__main__":
    main()

Zerion Mini Shell 1.0