-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.py
478 lines (368 loc) · 20.1 KB
/
local.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
import os
from functionality import *
os.system("clear")
def local_basicOperation():
i = 1
while (1) :
os.system("tput setaf 1")
print("You Select Basic Operation" , end = "\n\n")
print("""
\t 1: check system date
\t 2: System Calender
\t 3: Check Currently User Name
\t 4: Currently Working Ditectory
\t 5: Listing Of File
\t 6. Open Editor
\t 7: Count Number Of Words In A File
\t 8: exit
""")
os.system("tput setaf 7")
ch2 = input("Enter Your Choice : ")
if (("date" in ch2) or ("Date" in ch2) or ("DATE" in ch2)) :
os.system("date")
elif (("cal" in ch2) or ("Cal" in ch2) or ("CAL" in ch2)) :
os.system("cal")
elif ((("curr" in ch2) or ("Curr" in ch2) or ("Curr" in ch2) or ("che" in ch2) or ("Che" in ch2) or ("CHE" in ch2)) and ((("user" in ch2) or ("User" in ch2) or ("USER" in ch2)))) :
os.system("whoami")
elif ((("curr" in ch2) or ("Curr" in ch2) or ("Curr" in ch2) ) and ((("dir" in ch2) or ("Dir" in ch2) or ("DIR" in ch2) or ("fol" in ch2) or ("Fol" in ch2) or ("FOL" in ch2)))) :
os.system("pwd")
elif ((("list" in ch2) or ("List" in ch2) or ("LIST" in ch2)) and ((("file" in ch2) or ("File" in ch2) or ("FILE" in ch2)))) :
os.system("ls")
elif ((("open" in ch2) or ("Open" in ch2) or ("OPEN" in ch2)) and (("editor" in ch2) or ("Editor" in ch2) or ("EDITOR" in ch2))) :
os.system("vim")
elif ((("cou" in ch2) or ("Cou" in ch2) or ("COU" in ch2)) and (("word" in ch2) or ("Word" in ch2) or "WORD" in ch2)) :
fileName = input("Enter Name Of File Which You Want To Count : ")
os.system("cat {} | wc".format(fileName))
elif (("exit" in ch2) or ("quit" in ch2) or ("Exit" in ch2) or ("Quit" in ch2)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")
#Package Management
def local_packManagement():
while (1):
os.system("tput setaf 1")
print("You Select Package Management" , end = "\n\n")
print("""
\t 1: Check Package Install Or Not
\t 2: Install Package
\t 3: Remove Package
\t 4: exit
""")
os.system("tput setaf 7")
ch2 = input("Enter Your Choice : ")
if ((("che" in ch2) or ("Che" in ch2) or ("CHE" in ch2)) and (("pac" in ch2) or ("Pac" in ch2) or ("PAC" in ch2))) :
pack = input("Enter Package Name Which You Want To Check : ")
os.system("rpm -q {}".format(pack))
elif ((("ins" in ch2) or ("Ins" in ch2) or ("INS" in ch2)) and (("pac" in ch2) or ("Pac" in ch2) or ("PAC" in ch2))) :
pack = input("Enter Package Name Which You Want To Install : ")
x = os.system("rpm -q {}".format(pack))
if x != 0 :
print("""
In your System {} not installed yet.
So we download it first and it will take some time
""".format(pack))
os.system("dnf install {} -y".format(pack))
else :
print("{} already in our system".format(pack))
elif (((("uni" in ch2) or ("Uni" in ch2) or ("Uni" in ch2)) or (("rem" in ch2) or ("Rem" in ch2) or ("REM" in ch2)) or (("del" in ch2) or ("Del" in ch2) or ("DEL" in ch2))) and (("pac" in ch2) or ("Pac" in ch2) or ("PAC" in ch2))) :
pack = input("Enter Package Name Which You Want To Uninstall : ")
x = os.system("rpm -q {}".format(pack))
if x == 0 :
print("""
In your System {} installed .
So we remove it for you and it will take some time
""".format(pack))
os.system("dnf remove {} -y".format(pack))
elif (("exit" in ch2) or ("quit" in ch2) or ("Exit" in ch2) or ("Quit" in ch2)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")
def local_userManagement():
while (1):
print("You Select User Management" , end = "\n\n")
os.system("tput setaf 1")
print("""
\t 1: Check Current Login User
\t 2: Show All User Name
\t 3: Add User
\t 4: Remove User
\t 5: Change Password Of A User
\t 6: Add Group
\t 7: Remove Group
\t 8: lock User
\t 9: Unlock User
\t 10: exit
""")
os.system("tput setaf 7")
ch2 = input("Enter Your Choise : ")
if ((("log" in ch2) or ("Log" in ch2) or ("LOG" in ch2)) and (("user" in ch2) or ("User" in ch2) or ("USER" in ch2))) :
os.system("whoami")
elif ((("user" in ch2) or ("User" in ch2) or ("USER" in ch2)) and (("name" in ch2) or ("Name" in ch2) or ("NAME" in ch2))) :
os.system("ls /home/")
elif ((("add" in ch2) or ("Add" in ch2) or ("ADD" in ch2)) and (("user" in ch2) or ("User" in ch2) or ("USER" in ch2))) :
userName = input("Enter User Name : ")
os.system("useradd {}".format(userName))
os.system("passwd {}".format(userName))
print("User added Successfuly")
elif (((("rem" in ch2) or ("Rem" in ch2) or ("REM" in ch2)) or (("del" in ch2) or ("Del" in ch2) or ("DEL" in ch2)) )and (("user" in ch2) or ("User" in ch2) or ("USER" in ch2))) :
userName = input("Enter User Name Which You want to Delete : ")
os.system("userdel {}".format(userName))
os.system("rm -rf /home/{}".format(userName))
print("User Successfuly Remove")
elif (((("cha" in ch2) or ("Cha" in ch2) or ("CHA" in ch2)) or (("upd" in ch2) or ("Upd" in ch2) or ("UPD" in ch2)) )and (("pass" in ch2) or ("Pass" in ch2) or ("PASS" in ch2))) :
userName = input("Enter User Name which user Password you want to change : ")
os.system("passwd {}".format(userName))
print("User Password Successfuly")
elif ((("add" in ch2) or ("Add" in ch2) or ("ADD" in ch2)) and (("gro" in ch2) or ("Gro" in ch2) or ("GRO" in ch2))) :
grpName = input("Enter Group Name : ")
os.system("groupadd {}".format(grpName))
print("User added Successfuly")
elif (((("del" in ch2) or ("Del" in ch2) or ("DEL" in ch2)) or (("rem" in ch2) or ("Rem" in ch2) or ("REM" in ch2)) )and (("gro" in ch2) or ("Gro" in ch2) or ("GRO" in ch2))) :
grpName = input("Enter Group Name which You Want To Delete : ")
os.system("groupdel {}".format(grpName))
print("User Deleted Successfuly")
elif ((("loc" in ch2) or ("Loc" in ch2) or ("LOC" in ch2)) and (("user" in ch2) or ("User" in ch2) or ("USER" in ch2))) :
userName = input("Enter User Name Which User You Want To Lock : ")
os.system("usermod -l")
elif ((("unl" in ch2) or ("Unl" in ch2) or ("UNL" in ch2)) and (("user" in ch2) or ("User" in ch2) or ("USER" in ch2))) :
userName = input("Enter User Name Which User You Want To Unlock : ")
os.system("usermod -u")
elif (("exit" in ch2) or ("quit" in ch2) or ("Exit" in ch2) or ("Quit" in ch2)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")
def local_Networking():
while (1) :
print("You Select Networking " , end = "\n\n")
os.system("tput setaf 1")
print("""
\t 1: Check IP Address
\t 2: Istall HTTPD
\t 3: Start Services Of Web Server
\t 4: Stop Services Of Web Server
\t 5: Check Status Of Web Server
\t 6: exit
""")
os.system("tput setaf 7")
ch2 = input("Enter Your Choise : ")
if ((("check" in ch2) or ("Check" in ch2) or ("CHECK" in ch2)) and (("ip" in ch2) or ("Ip" in ch2) or ("IP" in ch2))) :
os.system("ifconfig")
elif ((("ins" in ch2) or ("Ins" in ch2) or ("INS" in ch2)) and (("httpd" in ch2) or ("Httpd" in ch2) or ("HTTPD" in ch2))) :
i = os.system("rpm -q httpd")
if i != 0 :
print("""
In your System httpd not installed yet.
So we download it first and it will take some time
""")
os.system("dnf install httpd -y")
else :
print("httpd already install in our system")
elif ((("start" in ch2) or ("Start" in ch2) or ("START" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl start httpd")
elif ((("stop" in ch2) or ("Stop" in ch2) or ("STOP" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl stop httpd")
elif ((("status" in ch2) or ("Status" in ch2) or ("STATUS" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl status httpd")
elif (("exit" in ch2) or ("quit" in ch2) or ("Exit" in ch2) or ("Quit" in ch2)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")
def local_serviceManagement():
while (1) :
print("You Select Services Management " , end = "\n\n")
os.system("tput setaf 1")
print("""
\t 1: Start Services Of Web Server
\t 2: Stop Services Of Web Server
\t 3: Check Status Of Web Server
\t 4: Start Services Of Firewall
\t 5: Stop Services Of Firewall
\t 6: Check Status Of Firewall
\t 7: Start Services Of Docker
\t 8: Stop Services Of Docker
\t 9: Check Status Of Docker
\t 10: exit
""")
os.system("tput setaf 7")
ch2 = input("Enter Your Choice : ")
if ((("start" in ch2) or ("Start" in ch2) or ("START" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl start httpd")
os.system("systemctl stop firewalld")
elif ((("stop" in ch2) or ("Stop" in ch2) or ("STOP" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl stop httpd")
elif ((("status" in ch2) or ("Status" in ch2) or ("STATUS" in ch2)) and (("web" in ch2) or ("Web" in ch2) or ("WEB" in ch2))) :
os.system("systemctl status httpd")
elif ((("start" in ch2) or ("Start" in ch2) or ("START" in ch2)) and (("firewall" in ch2) or ("Firewall" in ch2) or ("FIREWALL" in ch2))) :
os.system("systemctl start firewalld")
elif ((("stop" in ch2) or ("Stop" in ch2) or ("STOP" in ch2)) and (("firewall" in ch2) or ("Firewall" in ch2) or ("FIREWALL" in ch2))) :
os.system("systemctl stop firewalld")
elif ((("status" in ch2) or ("Status" in ch2) or ("STATUS" in ch2)) and (("firewall" in ch2) or ("Firewall" in ch2) or ("FIREWALL" in ch2))) :
os.system("systemctl status firewalld")
elif ((("start" in ch2) or ("Start" in ch2) or ("START" in ch2)) and (("docker" in ch2) or ("Docker" in ch2) or ("DOCKER" in ch2))) :
os.system("systemctl start docker")
elif ((("stop" in ch2) or ("Stop" in ch2) or ("STOP" in ch2)) and (("docker" in ch2) or ("Docker" in ch2) or ("DOCKER" in ch2))) :
os.system("systemctl stop docker")
elif ((("status" in ch2) or ("Status" in ch2) or ("STATUS" in ch2)) and (("docker" in ch2) or ("Docker" in ch2) or ("DOCKER" in ch2))) :
os.system("systemctl status docker")
elif (("exit" in ch2) or ("quit" in ch2) or ("Exit" in ch2) or ("Quit" in ch2)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")
def local_permission() :
while (1) :
os.system("tput setaf 1")
print("""
\t 1. give rwx permission to a file
\t 2. revoke rwx permission to a file
\t 3. Give rwx permission to a folder/directory
\t 4. revoke rwx permission to a folder/directory
\t 5. exit
""")
os.system("tput setaf 7")
opr = input("Enter Yor Requirment from the given operation :- ")
if (("give" in opr) or ("Give" in opr) or ("GIVE" in opr) and ("file" in opr) or ("File" in opr) or ("FILE" in opr)) :
user = input("Enter User type (user, group, other) :- ")
if (("user" in user) or ("User" in user) or ("USER" in user)) :
u = "u"
per_opt()
permission = input("Enter Which permission you want give to User : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("group" in user) or ("Group" in user) or ("GROUP" in user)) :
u = "g"
per_opt()
permission = input("Enter Which permission you want give to Group : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("other" in user) or ("Other" in user) or ("OTHER" in user)) :
u = "o"
per_opt()
permission = input("Enter Which permission you want give to Other : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
else :
print("No match found please try again")
elif (("re" in opr) or ("Re" in opr) or ("RE" in opr) and ("file" in opr) or ("File" in opr) or ("FILE" in opr)) :
user = input("Enter User type (user, group, other) :- ")
if (("user" in user) or ("User" in user) or ("USER" in user)) :
u = "u"
per_opt()
permission = input("Enter Which permission you want give to User : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("group" in user) or ("Group" in user) or ("GROUP" in user)) :
u = "g"
per_opt()
permission = input("Enter Which permission you want give to Group : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("other" in user) or ("Other" in user) or ("OTHER" in user)) :
u = "o"
per_opt()
permission = input("Enter Which permission you want give to Other : - ")
file_name = input("Enter File Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
else :
print("No match found please try again")
elif (("give" in opr) or ("Give" in opr) or ("GIVE" in opr) and ("dir" in opr) or ("Dir" in opr) or ("DIR" in opr) or ("fol" in opr) or ("Fol" in opr) or ("FOL" in opr)) :
user = input("Enter User type (user, group, other) :- ")
if (("user" in user) or ("User" in user) or ("USER" in user)) :
u = "u"
per_opt()
permission = input("Enter Which permission you want give to User : - ")
fold_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter Folder path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,fold_name)
print(cmd)
os.system(cmd)
elif (("group" in user) or ("Group" in user) or ("GROUP" in user)) :
u = "g"
per_opt()
permission = input("Enter Which permission you want give to Group : - ")
fold_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter Folder path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,fold_name)
print(cmd)
os.system(cmd)
elif (("other" in user) or ("Other" in user) or ("OTHER" in user)) :
u = "o"
per_opt()
permission = input("Enter Which permission you want give to Other : - ")
fold_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter Folder path :- ")
cmd = "chmod {}+{} {}/{}".format(u,permission,path,fold_name)
print(cmd)
os.system(cmd)
else :
print("No match found please try again")
elif (("re" in opr) or ("Re" in opr) or ("RE" in opr) and ("dir" in opr) or ("Dir" in opr) or ("DIR" in opr) or ("fol" in opr) or ("Fol" in opr) or ("FOL" in opr)) :
user = input("Enter User type (user, group, other) :- ")
if (("user" in user) or ("User" in user) or ("USER" in user)) :
u = "u"
per_opt()
permission = input("Enter Which permission you want give to User : - ")
file_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("group" in user) or ("Group" in user) or ("GROUP" in user)) :
u = "g"
per_opt()
permission = input("Enter Which permission you want give to Group : - ")
file_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
elif (("other" in user) or ("Other" in user) or ("OTHER" in user)) :
u = "o"
per_opt()
permission = input("Enter Which permission you want give to Other : - ")
file_name = input("Enter Folder Name Which permission you want to change :- ")
path = input("Enter file path :- ")
cmd = "chmod {}-{} {}/{}".format(u,permission,path,file_name)
print(cmd)
os.system(cmd)
else :
print("No match found please try again")
elif (("exit" in opr) or ("quit" in opr) or ("Exit" in opr) or ("Quit" in opr)) :
print("""
You exit For Current Menu
""")
break
else :
print("No Match Found Please Try Again")