-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
148 lines (116 loc) · 5.89 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import json
import requests
import class_powerpanel
import colors
import os
from collections import namedtuple
from pathlib import Path
# clear screen
os.system( 'clear' )
# loading config file
config_file = Path(os.path.abspath(os.path.join(os.path.dirname(__file__), 'config.json')))
# Check if config files has found, if not print error and exit
if not config_file.is_file():
print(colors.bcolors.FAIL + 'config.json not found!' + colors.bcolors.ENDC)
print('Make sure you have a config file named config.json. This file contains also your API key.')
exit()
# load config settings from config.json
config = json.load(open(config_file), object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
api_key = config.api_key
selection = True
while selection:
print(colors.bcolors.OKBLUE + """
-----------------------------
---- PowerPanel API tool ----
-----------------------------
Make a choice of one of the following options:
1. Domain info (Sync domain information from the registry)
2. Change domain name servers (Change the name server settings for your domains)
3. Create DNS zones (Enabled DNS zones for the domains)
4. Exit / Quit
""" + colors.bcolors.ENDC)
selection = input("Please choose the number for the action you want to execute: ")
# init PowerPanel Class
oPowerPanel = class_powerpanel.PowerPanel(api_key)
if selection =='1':
# Running domain info for the domains in file domain_list.txt
# clear screen
os.system( 'clear' )
# Ask if domain expireddate needs to update
print(colors.bcolors.WARNING + """
Do you want to udate the domain expiredate? [Default = N]
Y = Yes
N = No
"""+ colors.bcolors.ENDC)
update_expiredate = input("Please Select Y or N: ")
if oPowerPanel.loadListFromDisk("domain_list.txt"):
for domain in oPowerPanel.file_contents:
print('Running getDomainInfo for domain: ' +domain)
data = {}
data["domainname"] = domain
data['live'] = True
if update_expiredate == 'Y':
data['update_subscription_date'] = True
# Set API command
response = oPowerPanel.apiCommand("Domain/info", json.dumps(data))
response_json = json.loads(response.content.decode('UTF-8'))
# print status from action
if response_json['code'] == 1:
print(colors.bcolors.OKGREEN + 'Status: SUCCESS!\n' + response_json['msg'][0] + colors.bcolors.ENDC)
else:
print(colors.bcolors.FAIL + 'Status: FAIL: ' + response_json['msg'][0] + colors.bcolors.ENDC)
print('========================================')
print('Task done, returning to the menu...')
elif selection == '2':
# Running change nameserver settings for the domains in file domain_list.txt
# clear screen
os.system( 'clear' )
# Ask if name server ID needs for the update
print(colors.bcolors.WARNING + "Please enter the number of the name server set ID you want to use to update your domain.\nThis number can be found in the control panel." + colors.bcolors.ENDC)
try:
nss_id = int(input("Please enter the number: "))
except ValueError:
nss_id = 0
if not int(nss_id) > 0:
print(colors.bcolors.FAIL +'Incorrect number given!' + colors.bcolors.ENDC)
break
if oPowerPanel.loadListFromDisk("domain_list.txt"):
for domain in oPowerPanel.file_contents:
print('Running domain modify for domain: ' +domain)
data = {}
data["domainname"] = domain
data['nameserverset_id'] = nss_id
# Set API command
response = oPowerPanel.apiCommand("Domain/modify", json.dumps(data))
response_json = json.loads(response.content.decode('UTF-8'))
# print status from action
if response_json['code'] == 1:
print(colors.bcolors.OKGREEN + 'Status: SUCCESS!\n' + response_json['msg'][0] + colors.bcolors.ENDC)
else:
print(colors.bcolors.FAIL + 'Status: FAIL: ' + response_json['msg'][0] + colors.bcolors.ENDC)
print('========================================')
print('Task done, returning to the menu...')
elif selection == '3':
# Running create DNS zone for the domains in file domain_list.txt
# clear screen
os.system( 'clear' )
if oPowerPanel.loadListFromDisk("domain_list.txt"):
for domain in oPowerPanel.file_contents:
print('Create DNS zone for domain: ' +domain)
data = {}
data["domainname"] = domain
# Set API command
response = oPowerPanel.apiCommand("Dns/createZone", json.dumps(data))
response_json = json.loads(response.content.decode('UTF-8'))
# print status from action
if response_json['code'] == 1:
print(colors.bcolors.OKGREEN + 'Status: SUCCESS!\n' + response_json['msg'][0] + colors.bcolors.ENDC)
else:
print(colors.bcolors.FAIL + 'Status: FAIL: ' + response_json['msg'][0] + colors.bcolors.ENDC)
print('========================================')
print('Task done, returning to the menu...')
elif selection == '4':
print(colors.bcolors.OKBLUE + "Bye Bye!!" + colors.bcolors.ENDC)
break
else:
print(colors.bcolors.FAIL + "Unknown option selected, now exits!" + colors.bcolors.ENDC)