77 lines
2.5 KiB
Python
Executable File
77 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import getpass
|
|
# Local imports from the modular structure
|
|
from inwx_config import login, logout
|
|
from inwx_dns_functions import get_dns_info, add_record, update_record, delete_record
|
|
|
|
|
|
def main_menu():
|
|
"""
|
|
Main loop for the INWX DNS CLI application.
|
|
Handles user login, displays the main action menu, and routes input.
|
|
"""
|
|
|
|
# 1. AUTHENTICATION & LOGIN
|
|
# Try to get credentials from environment variables first
|
|
INWX_USER = os.getenv('INWX_USER')
|
|
INWX_PASS = os.getenv('INWX_PASS')
|
|
|
|
if not INWX_USER:
|
|
INWX_USER = input("Enter your INWX username: ")
|
|
|
|
if not INWX_PASS:
|
|
# Use getpass to securely hide the password input in the console
|
|
INWX_PASS = getpass.getpass("Enter your INWX password: ")
|
|
|
|
# Attempt to log in to the INWX API
|
|
if not login(INWX_USER, INWX_PASS):
|
|
# Exit if login fails (login function handles error messages)
|
|
return
|
|
|
|
# 2. MAIN APPLICATION LOOP
|
|
try:
|
|
while True:
|
|
# Display the main action menu (Emojis replaced for maximum compatibility)
|
|
print("\n" + "=" * 40)
|
|
print(" INWX DNS-CLI (MC-Style) - DOMAIN MANAGEMENT")
|
|
print("=" * 40)
|
|
print("1: [i] **View Records** (nameserver.info)")
|
|
print("---")
|
|
print("2: [+] **Add Record** (nameserver.createRecord)")
|
|
print("3: [~] **Modify Record** (nameserver.updateRecord)")
|
|
print("4: [x] **Delete Record** (nameserver.deleteRecord)")
|
|
print("---")
|
|
print("9: [>] Logout & Exit")
|
|
print("-" * 40)
|
|
|
|
choice = input("Select an action (1-4 or 9): ").strip()
|
|
|
|
if choice == '1':
|
|
domain = input("Enter the domain whose records you want to view: ").strip()
|
|
if domain:
|
|
get_dns_info(domain)
|
|
elif choice == '2':
|
|
# nameserver.createRecord
|
|
add_record()
|
|
elif choice == '3':
|
|
# nameserver.updateRecord
|
|
update_record()
|
|
elif choice == '4':
|
|
# nameserver.deleteRecord
|
|
delete_record()
|
|
elif choice == '9':
|
|
break
|
|
else:
|
|
print("Invalid selection. Please try again.")
|
|
|
|
finally:
|
|
# Ensure logout is always performed, even if an error occurs
|
|
logout()
|
|
|
|
if __name__ == "__main__":
|
|
main_menu()
|
|
|