-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.py
384 lines (298 loc) · 12.1 KB
/
cmd.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# Author: Alberto Vázquez
# https://github.com/alb3rtov/
# https://informaticaenuno.wordpress.com/
# Version alpha-0.12.8
##############################
### PACKAGES IMPORTED ###
##############################
import subprocess
import time
import os, sys
import os.path as path
import signal
import re
from menus.management import bfunc
#####################
### FUNCTIONS ###
#####################
#Function to avoid Ctrl+C
def sigint_handler(signum, frame):
print();
print("Please, don't press Ctrl+C");
print();
time.sleep(1);
signal.signal(signal.SIGINT, sigint_handler)
#Exit program Function
def ExitProgram():
print("");
optionExit = input("Are you sure you want to exit? (y/n): ");
if (optionExit == "y") or (optionExit == "Y"):
sys.exit();
elif (optionExit == "n") or (optionExit == "N"):
time.sleep(2)
bfunc.PressKey();();
else:
print("");
print(" Use a right option (y/n)")
ExitProgram();
#Operating System check Function
def CheckingOS():
osName = "OS Name";
sistemaOperativo = "Nombre del sistema operativo";
osType1 = "Microsoft Windows Server 2016";
osType2 = "Microsoft Windows Server 2012";
osType3 = "Microsoft Windows Server 2019";
cnt = 0
os.system('systeminfo > systeminfo.txt');
dirFile = 'systeminfo.txt'
with open(dirFile, 'r') as reader:
for line in reader:
if (osName in line or sistemaOperativo in line):
print(f' {line}');
if (osType1 in line or osType2 in line or osType3 in line):
cnt = cnt+1;
if (cnt == 1):
FirstMenu();
else:
print(" Operating System must be Windows Server 2012, 2016 or 2019");
bfunc.PressKey();
sys.exit();
######################################################################################
############################## MENU OPTIONS CHECK ################################
######################################################################################
#Function for 6 options Menus
############################# First Menu Options ##############################
#1- Active Directory check
def CheckAD1():
print();
print(" [*] Wait while it checks Active Directory ",end="");
bfunc.LoadAnimation();();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\adcheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines = len(open('.\\scripts\\cup\\temp\\adcheck.txt').readlines());
p = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\adcheck.txt"],stdout=sys.stdout);
#print(lines);
if (lines != 0):
os.system(f'type nul > menus\\security.txt')
os.system('menus\\adconfig.py');
else:
print();
print(" The Active Directory service is NOT installed");
bfunc.PressKey();
#2- Active Directory check
def CheckAD2():
print();
print(" [*] Wait while it checks Active Directory ",end="");
bfunc.LoadAnimation();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\adcheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines = len(open('.\\scripts\\cup\\temp\\adcheck.txt').readlines());
p = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\adcheck.txt"],stdout=sys.stdout);
#print(lines);
if (lines == 0):
os.system(f'type nul > menus\\security.txt')
os.system('menus\\adinstall.py');
else:
print();
print(" The Active Directory service is ALREADY installed");
bfunc.PressKey();
#3- Active Directory check
def CheckAD3():
print();
print(" [*] Wait while it checks Active Directory ",end="");
bfunc.LoadAnimation();
print();
p = subprocess.Popen(["powershell.exe", "-ExecutionPolicy", "Bypass", ".\\scripts\\adcheck.ps1"], stdout=subprocess.PIPE, stderr= subprocess.PIPE)
for line in p.stdout:
decoded_output = line.decode('utf-8', errors='strict').strip()
if (decoded_output == "False"):
print();
print(" The Active Directory service is NOT installed");
bfunc.PressKey();
else:
print();
print(" The Active Directory service is ALREADY installed");
bfunc.PressKey();
#4 administrar ad
def ManageAD():
print();
print(" [*] Wait while it checks Active Directory ",end="");
bfunc.LoadAnimation();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\adcheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines = len(open('.\\scripts\\cup\\temp\\adcheck.txt').readlines());
p = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\adcheck.txt"],stdout=sys.stdout);
#print(lines);
if (lines == 0):
print();
print(" The Active Directory service is NOT installed");
bfunc.PressKey();();
else:
print();
print(" [*] Checking if your system is a Domain Controller ",end="");
bfunc.LoadAnimation();();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\dccheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines2 = len(open('.\\scripts\\cup\\temp\\checkdcdiag.txt').readlines());
p1 = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\checkdcdiag.txt"],stdout=sys.stdout);
p2 = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\dcdiag.txt"],stdout=sys.stdout);
#print (lines2);
if (lines2 != 0):
print();
print(" This Server is NOT a Domain Controller");
bfunc.PressKey();();
else:
os.system(f'type nul > menus\\security.txt')
os.system('menus\\admanage.py')
#Configuration of DNS
def ConfigureDNS():
print();
print(" [*] Wait while it checks Active Directory ",end="");
bfunc.LoadAnimation();();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\adcheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines = len(open('.\\scripts\\cup\\temp\\adcheck.txt').readlines());
p = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\adcheck.txt"],stdout=sys.stdout);
#print(lines);
if (lines == 0):
print();
print(" The Active Directory service is NOT installed");
bfunc.PressKey();();
else:
print();
print(" [*] Checking if your system is a Domain Controller ",end="");
bfunc.LoadAnimation();();
print();
p = subprocess.Popen(["powershell.exe", ".\\scripts\\cup\\dccheck.ps1"],stdout=sys.stdout); # se ponen dos barras para que no de problemas de codec
p.communicate();
lines2 = len(open('.\\scripts\\cup\\temp\\checkdcdiag.txt').readlines());
p1 = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\checkdcdiag.txt"],stdout=sys.stdout);
p2 = subprocess.Popen(["powershell.exe", "del .\\scripts\\cup\\temp\\dcdiag.txt"],stdout=sys.stdout);
#print (lines2);
if (lines2 != 0):
print();
print(" Your system MUST be Domain Controller to configure DNS");
bfunc.PressKey();();
else:
os.system(f'type nul > menus\\security.txt')
os.system('menus\\dnsconfig.exe')
#6.- Exit to the program
############################################################################
############################## MENUS ###################################
############################################################################
#First menu, checking of Active Directory
def FirstMenu():
while True:
print ("");
print ("==================== Main menu ICAAD Software ====================");
print ("");
print (" 1 -> Active Directory Configuration ");
print (" 2 -> Active Directory Installation ");
print (" 3 -> Check installation of Active Directory ");
print (" 4 -> Active Directory Management ");
print (" 5 -> DNS Configuration ");
print (" 6 -> Exit ");
print ("");
numOptions = 6;
option = bfunc.ChooseOption(numOptions);
if (option == 1):
CheckAD1();
elif (option == 2):
CheckAD2();
elif (option == 3):
CheckAD3();
elif (option == 4):
ManageAD();
elif (option == 5):
ConfigureDNS();
elif (option == 6):
ExitProgram();
else:
break;
def Banner():
print();
print(" ____________ ___ ___ ____ _____ ");
time.sleep(0.5);
print(" / _/ ___/ _ | / _ | / _ \ / __/__ / _/ /__ _____ _______ ");
time.sleep(0.5);
print(" _/ // /__/ __ |/ __ |/ // / _\ \/ _ \/ _/ __/ |/|/ / _ `/ __/ -_)");
time.sleep(0.5);
print(" /___/\___/_/ |_/_/ |_/____/ /___/\___/_/ \__/|__,__/\_,_/_/ \__/");
print();
print(" By Alberto Vázquez");
#PROGRAM INFO
print();
print("[-*-] Welcome to ICAAD Software [-*-]");
print("[-*-] Assitant of installation, configuration and management of AD [-*-]")
print("[-*-] Suitable OS: Windows Server 2012, 2016 & 2019 (All versions) [-*-]");
print("[-*-] Developed in Python 3.6 and Powershell 5 [-*-]");
print("[-*-] Version alpha-0.12.8 [-*-]");
# LOAD
print();
print(" [*] Wait while the program loads ",end="");
bfunc.LoadAnimation();();
print();
print();
print(" [*] Detecting your system components ",end="");
bfunc.LoadAnimation();();
print();
print();
# Program Start
if (len(sys.argv) == 1) :
Banner();
CheckingOS();
if (len(sys.argv) == 2) :
if (sys.argv[1] == "/version" or sys.argv[1] == "-v") :
print();
print("ICAAD Software version alpha 0.12.8");
print();
print("You are executing the CMD version of ICAAD software.");
print("Use /gui to execute the GUI version");
print();
elif (sys.argv[1] == "/help" or sys.argv[1] == "-h") :
print();
print("ICAAD Software version alpha 0.12.8");
print("You can visit the project here --> www.github.com/alb3rtov/icaad-software");
print("Also you can visit my wordpress to see more stuff --> www.informaticaenuno.wordpress.com");
print();
print("This software is licensed under the GNU General Public License v3.0");
print();
print(" cmd.py Start the program");
print();
print("Parameters list:");
print();
print(" /version Shows the current version of the software");
print(" /help Shows a complete help for users");
print(" /gui Executes the GUI version of ICAAD");
print(" /os Shows the suitable Operating Systems");
print();
elif (sys.argv[1] == "/gui" or sys.argv[1] == "-g") :
os.system("gui.py");
elif (sys.argv[1] == "/os" or sys.argv[1] == "-o") :
print();
print("Suitable Operating Systems");
print();
print(" - Windows Server 2012 R2");
print(" - Windows Server 2016");
print(" - Windows Server 2019");
print();
print("For Windows Server 2012 R2 you need to have installed the next Service Packs:");
print();
print(" - KB2919442 ->");
print(" - KB2919335 ->");
print();
else:
print();
print("ICAAD Software version alpha 0.12.8");
print("This software is licensed under the GNU General Public License v3.0");
print();
print("ERROR: Not valid syntax");
print("Error with" , sys.argv[1]);
print();
print("Use the parameter /help to see all the options");
print();