-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddGroup.py
More file actions
112 lines (85 loc) · 3.19 KB
/
Copy pathaddGroup.py
File metadata and controls
112 lines (85 loc) · 3.19 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
import os
import time
import tkinter as tk
# use of python-dotenv to hide credentials and use environment variables
from dotenv import load_dotenv
from ldap3.core.exceptions import LDAPException
import logsManagement
load_dotenv()
'''
This function displays the form and calls the function to create a group
'''
def display(connection):
# generate the window
root = tk.Tk()
root.geometry("900x500")
root.title("Add a group")
'''
This function handles the creation of a group
'''
def add_a_group():
# determine a good time based complement for the log filename
initial_time = time.strftime("%Y%m%d-%H%M%S")
# define the first line of the logs file
initial_log = "Logs: Add a group " + initial_time
logs = initial_log
# delete content of displayLabel
result_display.config(text="")
# retrieve data from form
cn = input_cn.get()
description = input_description.get()
# if fields are not empty
if (cn != "") and (description != ""):
# generate the dn and the attribute of the new group
dl_group_dn = 'CN=' + cn + os.environ.get("SEARCHDC")
object_class = 'group'
attr = {
'cn': cn,
'description': description,
'groupType': '-2147483644',
'sAMAccountName': cn
}
# add the group
try:
connection.add(dl_group_dn, object_class, attr)
except LDAPException as e:
connection.result['description'] = e
# else display that all fields are required
else:
connection.result['description'] = "All fields required"
# display the description of the result of the operation
info_to_display = "\nGroup \"" + cn + "\" creation : " + connection.result['description']
result_display.config(text=info_to_display)
logs += info_to_display
# print and write logs
logsManagement.write_logs(logs, initial_log, initial_time, "create_group")
# empty form
input_cn.delete(0, 'end')
input_description.delete(0, 'end')
# main title
title = tk.Label(root, text="Add a group", font=("Raleway", 30))
title.pack()
# instructions
instructions = tk.Label(root, text="Fill the form then press the button", font=("Raleway", 22))
instructions.pack()
# form
# form cn part
cn_label = tk.Label(root, text="cn :")
cn_label.pack()
input_cn = tk.Entry(root, width=40)
input_cn.pack(pady=20)
# form description part
input_description_label = tk.Label(root, text="description :")
input_description_label.pack()
input_description = tk.Entry(root, width=40)
input_description.pack(pady=20)
# "add a group" button
add_group_button = tk.Button(root, text="Add group", font="Raleway",
command=add_a_group,
bg="#20bebe", fg="white", height=2, width=10)
add_group_button.pack()
# result display
result_display = tk.Label(root, text="", font=("Raleway", 22))
result_display.pack()
# tkinter main loop
root.mainloop()