-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathugmfunctions.py
More file actions
893 lines (780 loc) · 39.9 KB
/
ugmfunctions.py
File metadata and controls
893 lines (780 loc) · 39.9 KB
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
#!/usr/bin/python3
import os
import subprocess as sub
from sys import platform
from Script_Runner import *
from threading import *
from tkinter import *
from tkinter.ttk import *
import tkinter as tk # used to force certain widget type
import tkinter.font as tkFont
from Script_Runner import *
import time
import random
if platform == 'linux':
import crypt
import pwd
import distro # for figuring out what linux distro
# global variables
OS = distro.linux_distribution()
ops = OS[0]
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def changeVar(function, var, change):
var = change
print(var)
print(function)
function
class usrGruFunc:
def __init__(self):
pass
def addusr(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Add User To System')
name = StringVar()
paswd = StringVar()
group = StringVar()
def addusrEXEC():
if platform == 'linux':
username = name.get()
passwds = passwd.get()
admin = group.get()
encrypted_password = crypt.crypt(passwds)
print(username)
print(encrypted_password)
print(admin)
if admin == 'yes' or admin == 'Yes':
print('This user will be an admin')
command = "sudo -S useradd -m " + username + " -p " + encrypted_password
if ops == 'Manjaro Linux':
command2 = "sudo -S usermod --append --groups wheel " + username
command3 = "sudo -S usermod --append --groups adm " + username
else:
command2 = "sudo -S usermod -a -G sudo " + username
command3 = "sudo -S usermod -a -G adm " + username
userCheck = "sudo id -u " + username
os.system(command)
os.system(command2)
os.system(command3)
print(pwd.getpwnam(username))
print('User ' + username + " has been successfully added!")
topusr.destroy()
elif admin == 'no' or admin == 'No':
print('The user will not be an admin')
command = "sudo -S useradd -m " + username + " -p " + encrypted_password
userCheck = "sudo id -u " + username
os.system(command)
print(pwd.getpwnam(username))
print('User ' + username + " has been successfully added!")
topusr.destroy()
elif platform == 'win32':
username = name.get()
passwds = passwd.get()
admin = group.get()
print(username)
print(passwds)
print(admin)
if admin == 'yes' or admin == 'Yes':
print('This user will be an admin')
print(os.getcwd())
command = """
$nusnm = """ + '"{}"'.format(username) + """
$nuspss = ConvertTo-SecureString """ + '"{}"'.format(passwds) + """ -AsPlainText -Force
New-LocalUser -Name $nusnm -Password $nuspss
Add-LocalGroupMember -Group "Administrators" -Member $nusnm
Get-LocalUser
"""
print(command)
sub.Popen(["powershell", "& {" + command + "}"])
print('User ' + username + " has been successfully added!")
topusr.destroy()
elif admin == 'no' or admin == 'No':
print('This user will not be an admin')
command = """
$nusnm = """ + '"{}"'.format(username) + """
$nuspss = ConvertTo-SecureString """ + '"{}"'.format(passwds) + """ -AsPlainText -Force
New-LocalUser -Name $nusnm -Password $nuspss
Get-LocalUser
"""
print(command)
sub.Popen(["powershell", "& {" + command + "}"])
print('User ' + username + " has been successfully added!")
topusr.destroy()
elif platform == 'darwin':
username = name.get()
passwds = passwd.get()
admin = group.get()
print(username)
print(passwds)
print(admin)
numb = random.randint(1001, 5000)
if admin == 'yes' or admin == 'Yes':
print('This user will be an admin')
command = 'sudo dscl . -create /Users/' + username
command2 = 'sudo dscl . -create /Users/' + username + ' NFSHomeDirectory /Users/' + username
command3 = 'sudo dscl . -create /Users/' + username + ' RealName ' + username
command4 = 'sudo dscl . -create /Users/' + username + ' UniqueID ' + str(numb)
command5 = 'sudo dscl . -create /Users/' + username + ' PrimaryGroupID ' + str(numb)
command6 = 'sudo dscl . -passwd /Users/' + username + ' ' + passwds
command7 = 'sudo dscl . -append /Groups/admin GroupMembership ' + username
sub.Popen(command.split())
sub.Popen(command2.split())
sub.Popen(command3.split())
sub.Popen(command4.split())
sub.Popen(command5.split())
sub.Popen(command6.split())
sub.Popen(command7.split())
print('User ' + username + " has been successfully added!")
topusr.destroy()
elif admin == 'no' or admin == 'No':
print('This user will not be an admin')
command = 'sudo dscl . -create /Users/' + username
command2 = 'sudo dscl . -create /Users/' + username + ' NFSHomeDirectory /Users/' + username
command3 = 'sudo dscl . -create /Users/' + username + ' RealName ' + username
command4 = 'sudo dscl . -create /Users/' + username + ' UniqueID ' + str(numb)
command5 = 'sudo dscl . -create /Users/' + username + ' PrimaryGroupID ' + str(numb)
command6 = 'sudo dscl . -passwd /Users/' + username + ' ' + passwds
sub.Popen(command.split())
sub.Popen(command2.split())
sub.Popen(command3.split())
sub.Popen(command4.split())
sub.Popen(command5.split())
sub.Popen(command6.split())
print('User ' + username + " has been successfully added!")
topusr.destroy()
else:
print('This command does not yet support this OS')
userlbl = Label(topusr, text='What is the name of the User you would like to add?')
userlbl.grid(row='1', column='1', sticky='W')
name = Entry(topusr, textvariable=name)
name.grid(row='2', column='1', sticky='W', padx='5', pady='2')
passlbl = Label(topusr, text='Please insert secure password here:')
passlbl.grid(row='3', column='1', sticky='W')
passwd = Entry(topusr, textvariable=paswd)
passwd.grid(row='4', column='1', sticky='W', padx='5', pady='2')
grouplbl = Label(topusr, text='Is this user an admin? [yes/no]')
grouplbl.grid(row='5', column='1', sticky='W')
group = Entry(topusr, textvariable=group)
group.grid(row='6', column='1', sticky='W', padx='5', pady='2')
Confirm = Button(topusr, text='Confirm', command=addusrEXEC)
Confirm.grid(row='7', column='2', sticky='W', padx='5', pady='5')
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row='7', column='1', sticky='W', padx='5', pady='5')
def rmuser(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Remove User From System')
name = StringVar()
topusr.geometry('650x450')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='USERS')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=1, sticky='nsew')
# Needs to show list of users to remove
def rmusrEXEC():
if platform == 'linux':
username = name.get()
command = 'userdel -r ' + username
sub.Popen(command.split())
print('User ' + username + ' has been successfully removed!')
topusr.destroy()
elif platform == 'win32':
username = name.get()
command = 'Remove-LocalUser -Name ' + username
sub.Popen(command.split())
print('User ' + username + ' has been successfully removed!')
topusr.destroy()
elif platform == 'darwin':
username = name.get()
command = 'sudo dscl . delete /Users/' + username
command2 = 'sudo rm -r /Users/' + username
sub.Popen(command.split())
sub.Popen(command2.split())
print('User ' + username + ' has been successfully removed!')
topusr.destroy()
else:
print('This command does not yet support this OS')
userlbl = Label(topusr, text='What is the name of the user\nyou would like to remove?')
userlbl.grid(row=0, column=0, sticky='nw', pady=10)
name = Entry(topusr, textvariable=name)
name.grid(row=0, column=0, sticky='nw', padx='5', pady='45')
if platform == 'linux':
command = """cat /etc/passwd | grep "/home" | cut -d":" -f1 > userlist.txt"""
os.system(command)
# print(exec)
with open("userlist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("userlist.txt")
print(output)
elif platform == 'win32':
command = "Get-LocalUser"
exec = sub.Popen(["powershell", "& {Get-LocalUser}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
elif platform == 'darwin':
command = "sudo dscl . list /Users | grep -v '_'"
exec = sub.Popen(command.split(), stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
Confirm = Button(topusr, text='Confirm', command=rmusrEXEC)
Confirm.grid(row=2, column=1, sticky='e', padx='5', pady='5')
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=2, column=0, sticky='e', padx='5', pady='5')
def adgru(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Create User Group')
name = StringVar()
def adgruEXEC():
if platform == 'linux':
gruname = name.get()
command = 'sudo groupadd ' + gruname
print(command)
sub.Popen(command.split())
print('Group ' + gruname + ' has been successfully added!')
topusr.destroy()
elif platform == 'win32':
gruname = name.get()
command = 'New-LocalGroup -Name ' + gruname
print(command)
sub.Popen(["powershell", "& {" + command + "}"])
print('Group ' + gruname + ' has been successfully added!')
topusr.destroy()
elif platform == 'darwin':
gruname = name.get()
print('This command does not support MacOS')
topusr.destroy()
else:
print('This command does not yet support this OS')
grulbl = Label(topusr, text='What is the name of the Group you would like to add?')
grulbl.grid(row=1, column=1, sticky='W')
name = Entry(topusr, textvariable=name)
name.grid(row=2, column=1, sticky='W', padx=5, pady=2)
Confirm = Button(topusr, text='Confirm', command=adgruEXEC)
Confirm.grid(row=7, column=2, sticky='W', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=1, sticky='W', padx=5, pady=5)
def rmgru(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Remove User Group')
topusr.geometry('950x450')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='Local Groups')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=1, sticky='nsew')
name = StringVar()
def rmgruEXEC():
if platform == 'linux':
gruname = name.get()
command = 'sudo groupdel ' + gruname
sub.Popen(command.split())
# os.system(command)
print('Group ' + gruname + ' has been successfully removed!')
topusr.destroy()
elif platform == 'win32':
gruname = name.get()
command = 'Remove-LocalGroup -Name ' + gruname
sub.Popen(["powershell", "& {" + command + "}"])
print('Group ' + gruname + ' has been successfully removed!')
topusr.destroy()
elif platform == 'darwin':
print('This command is does not support MacOS')
else:
print('This command does not yet support this OS')
# Lists groups in box
if platform == 'linux':
command = 'getent group | cut -d: -f1 > grouplist.txt'
os.system(command)
with open("grouplist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("grouplist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
print('This command is not complete yet')
elif platform == 'win32':
command = 'Get-LocalGroup'
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
grulbl = Label(topusr, text='What is the name of the Group you would like to remove?')
grulbl.grid(row=0, column=0, sticky='nw', pady=10)
name = Entry(topusr, textvariable=name)
name.grid(row=0, column=0, sticky='nw', padx=5, pady=30)
Confirm = Button(topusr, text='Confirm', command=rmgruEXEC)
Confirm.grid(row=7, column=1, sticky='W', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=0, sticky='W', padx=5, pady=5)
def adusrtogru(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Add User to Group')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='USERS')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=0, sticky='nsew')
framlabel2 = tk.LabelFrame(topusr, text='GROUPS')
framlabel2.config(bd=5, background='lightgreen')
framlabel2.grid(row=0, column=1, sticky='nsew')
name = StringVar()
gruname = StringVar()
def adusrtogruEXEC():
if platform == 'linux':
username = name.get()
group = gruname.get()
if ops == 'Manjaro Linux':
command = "sudo -S usermod --append --groups " + group + " " + username
else:
command = "sudo -S usermod -a -G " + group + " " + username
os.system(command)
print("User " + username + " has been successfully add to group " + group)
topusr.destroy()
elif platform == 'win32':
username = name.get()
group = gruname.get()
command = "Add-LocalGroupMember -Name " + username + " -Member " + group
sub.Popen(["powershell", "& {" + command + "}"])
print("User " + username + " has been successfully add to group " + group)
topusr.destroy()
print('This command is not complete yet')
elif platform == 'darwin':
print('This command does not work on MacOS')
else:
print('This command does not yet support this OS')
# Lists Users
if platform == 'linux':
command = """cat /etc/passwd | grep "/home" | cut -d":" -f1 > userlist.txt"""
os.system(command)
# print(exec)
with open("userlist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("userlist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
command = "Get-LocalUser"
exec = sub.Popen(["powershell", "& {Get-LocalUser}"], stdout=sub.PIPE)
output, _ = exec.communicate()
print(output.decode("utf-8"))
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
command = "sudo dscl . list /Users | grep -v '_'"
exec = sub.Popen(command.split(), stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
else:
print('This command does not yet support this OS')
# Lists Groups
if platform == 'linux':
command = 'getent group | cut -d: -f1 > grouplist.txt'
os.system(command)
with open("grouplist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("grouplist.txt")
print(output)
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
print('This command is not complete yet')
elif platform == 'win32':
command = 'Get-LocalGroup'
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
adlbl = Label(topusr, text='What is the name of the User you would like to add to a group?')
adlbl.grid(row=1, column=0, sticky='nw')
usrname = Entry(topusr, textvariable=name)
usrname.grid(row=2, column=0, sticky='nw', padx='5', pady='2')
grulbl = Label(topusr, text='What is the name of the Group you would like to add the User to?')
grulbl.grid(row=1, column=1, sticky='nw')
gruname = Entry(topusr, textvariable=gruname)
gruname.grid(row=2, column=1, sticky='nw', padx='5', pady='2')
Confirm = Button(topusr, text='Confirm', command=adusrtogruEXEC)
Confirm.grid(row=7, column=0, sticky='w', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=1, sticky='e', padx=5, pady=5)
def rmusrfrogru(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Remove User from Group')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='USERS')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=0, sticky='nsew')
framlabel2 = tk.LabelFrame(topusr, text='GROUPS')
framlabel2.config(bd=5, background='lightgreen')
framlabel2.grid(row=0, column=1, sticky='nsew')
name = StringVar()
gruname = StringVar()
def rmusrfrogruEXEC():
if platform == 'linux':
username = name.get()
group = gruname.get()
command = 'gpasswd -d ' + username + " " + group
os.system(command)
print('User ' + username + ' has been removed successfully from group ' + group)
topusr.destroy()
elif platform == 'win32':
username = name.get()
group = gruname.get()
command = 'Remove-LocalGroupMember -Group ' + group + ' -Member ' + username
sub.Popen(["powershell", "& {" + command + "}"])
topusr.destroy()
elif platform == 'darwin':
print('This command does not work on MacOS')
topusr.destroy()
else:
print('This command does not yet support this OS')
# Lists Users
if platform == 'linux':
command = """cat /etc/passwd | grep "/home" | cut -d":" -f1 > userlist.txt"""
os.system(command)
# print(exec)
with open("userlist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("userlist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
command = "Get-LocalUser"
exec = sub.Popen(["powershell", "& {Get-LocalUser}"], stdout=sub.PIPE)
output, _ = exec.communicate()
print(output.decode("utf-8"))
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
command = "sudo dscl . list /Users | grep -v '_'"
exec = sub.Popen(command.split(), stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
else:
print('This command does not yet support this OS')
# Lists Groups
if platform == 'linux':
command = 'getent group | cut -d: -f1 > grouplist.txt'
os.system(command)
with open("grouplist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("grouplist.txt")
print(output)
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
print('This command is not complete yet')
elif platform == 'win32':
command = 'Get-LocalGroup'
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=0, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
adlbl = Label(topusr, text='What is the name of the User you would like to remove from a group?')
adlbl.grid(row=1, column=0, sticky='nw')
usrname = Entry(topusr, textvariable=name)
usrname.grid(row=2, column=0, sticky='nw', padx='5', pady='2')
grulbl = Label(topusr, text='What is the name of the Group you would like to remove the User from?')
grulbl.grid(row=1, column=1, sticky='nw')
gruname = Entry(topusr, textvariable=gruname)
gruname.grid(row=2, column=1, sticky='nw', padx='5', pady='2')
Confirm = Button(topusr, text='Confirm', command=rmusrfrogruEXEC)
Confirm.grid(row=7, column=0, sticky='w', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=1, sticky='e', padx=5, pady=5)
def lslocausr(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('List Local Users')
topusr.geometry('950x450')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='OUTPUT')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=1, sticky='nsew')
def lslocausrEXEC():
if platform == 'linux':
command = """cat /etc/passwd | grep "/home" | cut -d":" -f1 > userlist.txt"""
os.system(command)
# print(exec)
with open("userlist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("userlist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
command = "Get-LocalUser"
exec = sub.Popen(["powershell", "& {Get-LocalUser}"], stdout=sub.PIPE)
output, _ = exec.communicate()
print(output.decode("utf-8"))
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
command = "sudo dscl . list /Users | grep -v '_'"
exec = sub.Popen(command.split(), stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
else:
print('This command does not yet support this OS')
fontSize = tkFont.Font(size=14)
lsusrs = tk.Button(topusr, text='List all\nusers on system', width=20, command=lslocausrEXEC)
lsusrs.config(font=fontSize)
lsusrs.grid(row=0, column=0, padx=5, pady=10, sticky='nswe')
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=1, column=1, sticky='w', padx='5', pady='5')
def lslocagru(self):
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('List Local User Groups')
topusr.geometry('950x450')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='Local Groups')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=1, sticky='nsew')
def lsLocaGruEXEC():
if platform == 'linux':
command = 'getent group | cut -d: -f1 > grouplist.txt'
os.system(command)
with open("grouplist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("grouplist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
print('This command is not complete yet')
elif platform == 'win32':
command = 'Get-LocalGroup'
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
fontSize = tkFont.Font(size=14)
lsgrus = tk.Button(topusr, text='List all\nusers on system', width=20, command=lsLocaGruEXEC)
lsgrus.config(font=fontSize)
lsgrus.grid(row=0, column=0, padx=5, pady=10, sticky='nswe')
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=1, column=1, sticky='w', padx='5', pady='5')
def lsmemgru(self): # Missing MacOS commands
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('List Members of Group')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='GROUPS')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=0, sticky='nsew')
framlabel2 = tk.LabelFrame(topusr, text='GROUP MEMBERS')
framlabel2.config(bd=5, background='lightgreen')
framlabel2.grid(row=0, column=1, sticky='nsew')
gruname = StringVar()
def lsmemgruEXEC():
if platform == 'linux':
group = gruname.get()
command = 'grep -i --color ' + group + ' /etc/group'
exec = sub.Popen(command.split(), stdout=PIPE)
stdout, _ = exec.communicate()
ouput = stdout.decode("utf-8")
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
group = gruname.get()
command = 'Get-LocalGroupMember -Name ' + group
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
if platform == 'linux':
command = 'getent group | cut -d: -f1 > grouplist.txt'
os.system(command)
with open("grouplist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("grouplist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
print('This command is not complete yet')
elif platform == 'win32':
command = 'Get-LocalGroup'
exec = sub.Popen(["powershell", "& {" + command + "}"], stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
grulbl = Label(topusr, text='What is the name of the Group that you would like to see the Members of?')
grulbl.grid(row=1, column=0, sticky='nw')
gruname = Entry(topusr, textvariable=gruname)
gruname.grid(row=2, column=0, sticky='nw', padx='5', pady='2')
Confirm = Button(topusr, text='Confirm', command=lsmemgruEXEC)
Confirm.grid(row=7, column=0, sticky='w', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=1, sticky='e', padx=5, pady=5)
def lsgruusrin(self): # Missing Windows Commands and MacOS commands
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('List Members of Group')
topusr.rowconfigure(0, weight=1)
topusr.columnconfigure(1, weight=1)
framlabel = tk.LabelFrame(topusr, text='USERS')
framlabel.config(bd=5, background='lightgreen')
framlabel.grid(row=0, column=0, sticky='nsew')
framlabel2 = tk.LabelFrame(topusr, text='USER IS A MEMBER OF THE FOLLOWING GROUPS')
framlabel2.config(bd=5, background='lightgreen')
framlabel2.grid(row=0, column=1, sticky='nsew')
name = StringVar()
def lsgruusrinEXEC():
if platform == 'linux':
username = name.get()
command = 'groups ' + username + ' > groupsuserin.txt'
os.system(command)
with open("groupsuserin.txt", "r") as f:
for line in f:
output = f.read()
os.remove("groupsuserin.txt")
outputBOX = Label(framlabel2, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
username = name.get()
print('This command is not complete yet')
elif platform == 'darwin':
username = name.get()
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
# Lists Users
if platform == 'linux':
command = """cat /etc/passwd | grep "/home" | cut -d":" -f1 > userlist.txt"""
os.system(command)
# print(exec)
with open("userlist.txt", "r") as f:
for line in f:
output = f.read()
os.remove("userlist.txt")
print(output)
outputBOX = Label(framlabel, text=output, background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'win32':
command = "Get-LocalUser"
exec = sub.Popen(["powershell", "& {Get-LocalUser}"], stdout=sub.PIPE)
output, _ = exec.communicate()
print(output.decode("utf-8"))
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
elif platform == 'darwin':
command = "sudo dscl . list /Users | grep -v '_'"
exec = sub.Popen(command.split(), stdout=sub.PIPE)
stdout, _ = exec.communicate()
output = stdout.decode("utf-8")
outputBOX = Label(framlabel, text=output.decode("utf-8"), background='lightgreen')
outputBOX.grid(row=0, column=1, columnspan=2, padx=5, pady=10, sticky='nsew')
else:
print('This command does not yet support this OS')
userlbl = Label(topusr,
text='What is the name of the User that you would like to see the groups that they are in?')
userlbl.grid(row=1, column=0, sticky='W')
name = Entry(topusr, textvariable=name)
name.grid(row=2, column=0, sticky='W', padx='5', pady='2')
Confirm = Button(topusr, text='Confirm', command=lsgruusrinEXEC)
Confirm.grid(row=7, column=1, sticky='W', padx='5', pady='5')
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=0, sticky='W', padx='5', pady='5')
def chngusrspass(self): # Missing windows and MacOS commands
topusr = Toplevel()
topusr.iconphoto(False, tk.PhotoImage(file="cup2.png"))
topusr.title('Add User To System')
paswd = StringVar()
def chngusrspassEXEC():
if platform == 'linux':
passwds = paswd.get()
command = """
userlist=( $(eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1) )
echo ${userlist[@]}
usersleft=${#userlist[@]}
echo $usersleft
newpasswd=""" + passwds + """
i=0
while [ $usersleft != 0 ]; do
sudo echo "${userlist[$i]}:${newpasswd}" | sudo chpasswd
echo "User ${userlist[$i]} password has been changed successfully!"
let i=i+1
echo $i
let usersleft=usersleft-1
echo $usersleft
sleep 0.5s
done
"""
os.system(command)
print('This command is not complete yet')
elif platform == 'win32':
print('This command is not complete yet')
elif platform == 'darwin':
print('This command is not complete yet')
else:
print('This command does not yet support this OS')
passlbl = Label(topusr, text='Please insert secure password here:')
passlbl.grid(row=0, column=0, sticky='w')
passwd = Entry(topusr, textvariable=paswd)
passwd.grid(row=1, column=0, sticky='w', padx=5, pady=2)
Confirm = Button(topusr, text='Confirm', command=chngusrspassEXEC)
Confirm.grid(row=7, column=1, sticky='W', padx=5, pady=5)
cancel = Button(topusr, text='Cancel', command=topusr.destroy)
cancel.grid(row=7, column=0, sticky='W', padx='5', pady='5')