-
Notifications
You must be signed in to change notification settings - Fork 0
/
rulesGUI.pyw
269 lines (256 loc) · 14.6 KB
/
rulesGUI.pyw
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
import wx
import wx.lib.scrolledpanel
import mysocket
import select
import sys
import cx_Oracle
class MyFrame(wx.Frame):
""" We simply derive a new class of Frame. """
def __init__(self):
self.connection = cx_Oracle.connect("Coexecute01/DePaul123@rasinsrv06.cstcis.cti.depaul.edu:1521/Oracle12c")
self.cursor = self.connection.cursor()
wx.Frame.__init__(self,None,-1,"Coexecution Rules",size=(600,450))
self.topPanel = wx.Panel(self)
self.bottomPanel = wx.lib.scrolledpanel.ScrolledPanel(self,-1, style=wx.SIMPLE_BORDER)
self.bottomPanel.SetupScrolling()
self.bottomPanel.SetAutoLayout(1)
self.bottomPanel.SetBackgroundColour('#DDDDDD')
self.rulesSizer = wx.BoxSizer(wx.HORIZONTAL)
self.bottomPanel.SetSizer(self.rulesSizer)
self.topPanel.SetBackgroundColour('#FFFFFF')
self.panels = wx.BoxSizer(wx.VERTICAL)
self.panels.Add(self.topPanel,0,wx.ALIGN_CENTER|wx.EXPAND)
self.panels.Add(self.bottomPanel,1,wx.ALIGN_CENTER|wx.EXPAND)
self.tabs = wx.BoxSizer(wx.HORIZONTAL)
self.coexecutionerTab = wx.Button(self.topPanel,label="Coexecutioner Permissions")
self.executorTab= wx.Button(self.topPanel,label="Executor Permissions")
self.sensitiveFieldsTab = wx.Button(self.topPanel,label="Sensitive Field")
self.tabs.Add(self.coexecutionerTab,0,wx.ALIGN_CENTER)
self.tabs.Add(self.executorTab,0,wx.ALIGN_CENTER)
self.tabs.Add(self.sensitiveFieldsTab,0,wx.ALIGN_CENTER)
self.topPanel.SetSizer(self.tabs)
self.SetSizer(self.panels)
self.CoexecutionerTab(None)
self.topPanel.Bind(wx.EVT_BUTTON, self.CoexecutionerTab, self.coexecutionerTab)
self.topPanel.Bind(wx.EVT_BUTTON, self.ExecutorTab, self.executorTab)
self.topPanel.Bind(wx.EVT_BUTTON, self.SensitiveFieldsTab, self.sensitiveFieldsTab)
self.SetIcon(wx.Icon('images/databaseIcon.ico', wx.BITMAP_TYPE_ICO))
def CoexecutionerTab(self, evt):
for i in range(self.rulesSizer.GetItemCount())[::-1]:
self.rulesSizer.Hide(i)
self.rulesSizer.Remove(i)
self.cursor.execute("SELECT TABLE_NAME, USER_NAME FROM CAN_GIVE_PERMISSION ORDER BY TABLE_NAME")
font = wx.Font(16,wx.FONTFAMILY_ROMAN,wx.FONTSTYLE_ITALIC,wx.FONTWEIGHT_BOLD)
font2 = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
tableHeading = wx.StaticText(self.bottomPanel,label="Table name:")
tableHeading.SetFont(font)
self.textCtrl1 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
userHeading = wx.StaticText(self.bottomPanel,label="Coexecutioner name:")
userHeading.SetFont(font)
self.textCtrl2 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
addHeading = wx.StaticText(self.bottomPanel,label="")
addHeading.SetFont(font)
addButton = wx.Button(self.bottomPanel, label="Add Rule")
addButton.Bind(wx.EVT_BUTTON, self.addCoexecutionerRule)
self.column1 = wx.BoxSizer(wx.VERTICAL)
self.column2 = wx.BoxSizer(wx.VERTICAL)
self.column3 = wx.BoxSizer(wx.VERTICAL)
self.column1.Add(tableHeading,0,wx.ALIGN_CENTER)
self.column2.Add(userHeading,0,wx.ALIGN_CENTER)
self.column3.Add(addHeading,0,wx.ALIGN_CENTER)
self.column1.Add(self.textCtrl1,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(self.textCtrl2,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(addButton,0,wx.ALIGN_CENTER|wx.ALL,5)
self.rulesSizer.Add(self.column1,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column2,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column3,0,wx.ALIGN_TOP)
for row in self.cursor:
tablename= wx.StaticText(self.bottomPanel,label=row[0],size=(-1,26))
username= wx.StaticText(self.bottomPanel,label=row[1],size=(-1,26))
tablename.SetFont(font2)
username.SetFont(font2)
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=row[0], user=row[1], count=self.column1.GetItemCount():
self.removeCoexecutionerRule(evt,table,user,count))
self.column1.Add(tablename,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(username,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
def removeCoexecutionerRule(self, evt, tablename, username, index):
self.cursor.execute("DELETE FROM CAN_GIVE_PERMISSION WHERE TABLE_NAME='"+tablename+"' AND USER_NAME='"+username+"'")
self.connection.commit()
self.column1.Hide(index)
self.column2.Hide(index)
self.column3.Hide(index)
self.Layout()
self.bottomPanel.FitInside()
def addCoexecutionerRule(self, evt):
if self.textCtrl1.GetValue() and self.textCtrl2.GetValue():
tablename = self.textCtrl1.GetValue()
username = self.textCtrl2.GetValue()
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=tablename, user=username, count=self.column1.GetItemCount():
self.removeCoexecutionerRule(evt,table,user,count))
self.textCtrl1.Clear()
self.textCtrl2.Clear()
self.cursor.execute("INSERT INTO CAN_GIVE_PERMISSION(TABLE_NAME,USER_NAME) VALUES('"+tablename+"', '"+username+"')")
self.connection.commit()
font = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
table=wx.StaticText(self.bottomPanel,label=tablename)
user=wx.StaticText(self.bottomPanel,label=username)
table.SetFont(font)
user.SetFont(font)
self.column1.Add(table,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(user,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
def ExecutorTab(self, evt):
for i in range(self.rulesSizer.GetItemCount())[::-1]:
self.rulesSizer.Hide(i)
self.rulesSizer.Remove(i)
self.cursor.execute("SELECT TABLE_NAME, USER_NAME FROM HAVE_PERMISSION ORDER BY TABLE_NAME")
font = wx.Font(16,wx.FONTFAMILY_ROMAN,wx.FONTSTYLE_ITALIC,wx.FONTWEIGHT_BOLD)
font2 = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
tableHeading = wx.StaticText(self.bottomPanel,label="Table name:")
tableHeading.SetFont(font)
self.textCtrl1 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
userHeading = wx.StaticText(self.bottomPanel,label="Executor name:")
userHeading.SetFont(font)
self.textCtrl2 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
addHeading = wx.StaticText(self.bottomPanel,label="")
addHeading.SetFont(font)
addButton = wx.Button(self.bottomPanel, label="Add Rule")
addButton.Bind(wx.EVT_BUTTON, self.addExecutorRule)
self.column1 = wx.BoxSizer(wx.VERTICAL)
self.column2 = wx.BoxSizer(wx.VERTICAL)
self.column3 = wx.BoxSizer(wx.VERTICAL)
self.column1.Add(tableHeading,0,wx.ALIGN_CENTER)
self.column2.Add(userHeading,0,wx.ALIGN_CENTER)
self.column3.Add(addHeading,0,wx.ALIGN_CENTER)
self.column1.Add(self.textCtrl1,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(self.textCtrl2,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(addButton,0,wx.ALIGN_CENTER|wx.ALL,5)
self.rulesSizer.Add(self.column1,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column2,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column3,0,wx.ALIGN_TOP)
for row in self.cursor:
tablename= wx.StaticText(self.bottomPanel,label=row[0],size=(-1,26))
username= wx.StaticText(self.bottomPanel,label=row[1],size=(-1,26))
tablename.SetFont(font2)
username.SetFont(font2)
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=row[0], user=row[1], count=self.column1.GetItemCount():
self.removeExecutorRule(evt,table,user,count))
self.column1.Add(tablename,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(username,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
def removeExecutorRule(self, evt, tablename, username, index):
self.cursor.execute("DELETE FROM HAVE_PERMISSION WHERE TABLE_NAME='"+tablename+"' AND USER_NAME='"+username+"'")
self.connection.commit()
self.column1.Hide(index)
self.column2.Hide(index)
self.column3.Hide(index)
self.Layout()
self.bottomPanel.FitInside()
def addExecutorRule(self, evt):
if self.textCtrl1.GetValue() and self.textCtrl2.GetValue():
tablename = self.textCtrl1.GetValue()
username = self.textCtrl2.GetValue()
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=tablename, user=username, count=self.column1.GetItemCount():
self.removeExecutorRule(evt,table,user,count))
self.textCtrl1.Clear()
self.textCtrl2.Clear()
self.cursor.execute("INSERT INTO HAVE_PERMISSION(TABLE_NAME,USER_NAME) VALUES('"+tablename+"', '"+username+"')")
self.connection.commit()
font = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
table=wx.StaticText(self.bottomPanel,label=tablename)
user=wx.StaticText(self.bottomPanel,label=username)
table.SetFont(font)
user.SetFont(font)
self.column1.Add(table,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(user,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
def SensitiveFieldsTab(self, evt):
for i in range(self.rulesSizer.GetItemCount())[::-1]:
self.rulesSizer.Hide(i)
self.rulesSizer.Remove(i)
self.cursor.execute("SELECT COEX_TABLE, SENSITIVE_FIELD FROM SENSITIVE_FIELDS ORDER BY COEX_TABLE")
font = wx.Font(16,wx.FONTFAMILY_ROMAN,wx.FONTSTYLE_ITALIC,wx.FONTWEIGHT_BOLD)
font2 = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
tableHeading = wx.StaticText(self.bottomPanel,label="Coexecution Table:")
tableHeading.SetFont(font)
self.textCtrl1 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
fieldHeading = wx.StaticText(self.bottomPanel,label="Sensitive Field:")
fieldHeading.SetFont(font)
self.textCtrl2 = wx.TextCtrl(self.bottomPanel,style=wx.TE_LEFT,size=(-1,28))
addHeading = wx.StaticText(self.bottomPanel,label="")
addHeading.SetFont(font)
addButton = wx.Button(self.bottomPanel, label="Add Rule")
addButton.Bind(wx.EVT_BUTTON, self.addSensitiveFieldsRule)
self.column1 = wx.BoxSizer(wx.VERTICAL)
self.column2 = wx.BoxSizer(wx.VERTICAL)
self.column3 = wx.BoxSizer(wx.VERTICAL)
self.column1.Add(tableHeading,0,wx.ALIGN_CENTER)
self.column2.Add(fieldHeading,0,wx.ALIGN_CENTER)
self.column3.Add(addHeading,0,wx.ALIGN_CENTER)
self.column1.Add(self.textCtrl1,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(self.textCtrl2,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(addButton,0,wx.ALIGN_CENTER|wx.ALL,5)
self.rulesSizer.Add(self.column1,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column2,0,wx.ALIGN_TOP)
self.rulesSizer.Add(self.column3,0,wx.ALIGN_TOP)
for row in self.cursor:
tablename= wx.StaticText(self.bottomPanel,label=row[0],size=(-1,26))
fieldname= wx.StaticText(self.bottomPanel,label=row[1],size=(-1,26))
tablename.SetFont(font2)
fieldname.SetFont(font2)
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=row[0], field=row[1], count=self.column1.GetItemCount():
self.removeSensitiveFieldsRule(evt,table,field,count))
self.column1.Add(tablename,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(fieldname,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
def removeSensitiveFieldsRule(self, evt, tablename, fieldname, index):
self.cursor.execute("DELETE FROM SENSITIVE_FIELDS WHERE COEX_TABLE='"+tablename+"' AND SENSITIVE_FIELD='"+fieldname+"'")
self.connection.commit()
self.column1.Remove(index)
self.column2.Remove(index)
self.column3.Remove(index)
self.Layout()
self.bottomPanel.FitInside()
def addSensitiveFieldsRule(self, evt):
if self.textCtrl1.GetValue() and self.textCtrl2.GetValue():
tablename = self.textCtrl1.GetValue()
fieldname = self.textCtrl2.GetValue()
remove= wx.Button(self.bottomPanel,label="Remove Rule")
remove.Bind(wx.EVT_BUTTON, lambda evt, table=tablename, field=fieldname, count=self.column1.GetItemCount():
self.removeSensitiveFieldsRule(evt,table,field,count))
self.textCtrl1.Clear()
self.textCtrl2.Clear()
self.cursor.execute("INSERT INTO SENSITIVE_FIELDS(COEX_TABLE,SENSITIVE_FIELD) VALUES('"+tablename+"', '"+fieldname+"')")
self.connection.commit()
font = wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
table=wx.StaticText(self.bottomPanel,label=tablename)
field=wx.StaticText(self.bottomPanel,label=fieldname)
table.SetFont(font)
field.SetFont(font)
self.column1.Add(table,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column2.Add(field,0,wx.ALIGN_CENTER|wx.ALL,5)
self.column3.Add(remove,0,wx.ALIGN_CENTER|wx.ALL,5)
self.Layout()
self.bottomPanel.FitInside()
#app = wx.App(False)
#To get errors use the following instead...
app = wx.App(True,'Error_Rules.txt')
frame = MyFrame()
frame.Show(True)
app.MainLoop()