Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.54 KB | None | 0 0
  1. import wx
  2. import os
  3. import wx.html
  4. import cStringIO
  5. import sys
  6. import random
  7. import ConfigParser
  8. import datetime
  9. import UltimateListCtrl as ULC
  10. import time
  11. import hashlib
  12. import md5
  13. from DataBase import *
  14.  
  15. class TabSettings(wx.Panel):
  16. def __init__(self, parent):
  17. wx.Panel.__init__(self, parent=parent)
  18.  
  19. #self.Konekt()
  20.  
  21. self.listaTablica = []
  22. self.nemaDuple = 1;
  23.  
  24. self.korisnik = ""
  25. self.lozinka = ""
  26. self.stroj = ""
  27. self.db = ""
  28. self.portnum = ""
  29.  
  30. self.tablice = []
  31. self.BAZE_PODATAKA = ['MYSQL', 'POSTGRESQL', 'MSSQL']
  32.  
  33. wx.StaticBox(self, -1, 'Settings for malware scanner', (5, 5), size=(755, 490))
  34. self.SetBackgroundColour('#ADB2BF')
  35.  
  36. vbox = wx.BoxSizer(wx.VERTICAL)
  37. hbox1 = wx.BoxSizer(wx.HORIZONTAL)
  38. hbox2 = wx.BoxSizer(wx.HORIZONTAL)
  39. hbox3 = wx.BoxSizer(wx.HORIZONTAL)
  40. hbox4 = wx.BoxSizer(wx.HORIZONTAL)
  41. hbox5 = wx.BoxSizer(wx.HORIZONTAL)
  42. hboxListBox = wx.BoxSizer(wx.HORIZONTAL)
  43. hboxLoadSave = wx.BoxSizer(wx.HORIZONTAL)
  44. hboxTestConnection = wx.BoxSizer(wx.HORIZONTAL)
  45. hboxTableOptions = wx.BoxSizer(wx.HORIZONTAL)
  46. hboxcbWantAll = wx.BoxSizer(wx.HORIZONTAL)
  47. hboxNotAll = wx.BoxSizer(wx.HORIZONTAL)
  48. hboxDropDown = wx.BoxSizer(wx.HORIZONTAL)
  49. hboxGetPut = wx.BoxSizer(wx.HORIZONTAL)
  50.  
  51. st1 = wx.StaticText(self, -1, 'Username:', size=(110, -1))
  52. st2 = wx.StaticText(self, -1, 'Password:', size=(110, -1))
  53. st3 = wx.StaticText(self, -1, 'Instance:', size=(110, -1))
  54. st4 = wx.StaticText(self, -1, 'IP addr:', size=(110, -1))
  55. st5 = wx.StaticText(self, -1, 'Port:', size=(110, -1))
  56.  
  57. self.tc1 = wx.TextCtrl(self, -1, size=(120, 18))
  58. self.tc2 = wx.TextCtrl(self, -1, size=(120, 18), style = wx.TE_PASSWORD)
  59. self.tc3 = wx.TextCtrl(self, -1, size=(120, 18))
  60. self.tc4 = wx.TextCtrl(self, -1, size=(120, 18))
  61. self.tc5 = wx.TextCtrl(self, -1, size=(120, 18))
  62.  
  63. self.btnLoad = wx.Button(self, 30, "Load conf", size=(116, -1))
  64. self.btnSave = wx.Button(self, 31, "Save conf", size=(116, -1))
  65.  
  66. cbDropBaze = wx.ComboBox(self, -1, size=(116, -1), choices=self.BAZE_PODATAKA, style=wx.CB_READONLY)
  67. btnTest = wx.Button(self, 888, "Test connection", size=(116, -1))
  68. stSve = wx.StaticText(self, -1, 'Tables options: ')
  69. self.cb1 = wx.CheckBox(self, 20, 'I want to scan all tables in database')
  70. self.cb1.SetValue(False)
  71. stOdredjene = wx.StaticText(self, -1, 'I want to scan only these certain tables: ')
  72. self.cbTablice = wx.ComboBox(self, -1, pos=(50, 340), size=(230, -1), choices=self.tablice, style=wx.CB_READONLY)
  73.  
  74. btnDodajUdrop = wx.Button(self, 222, 'Get tables', size=(115, -1))
  75. btnDodajZaScan = wx.Button(self, 2, 'Add table for scan', size=(115, -1))
  76.  
  77. hbox1.Add(st1, 0, wx.LEFT, 50)
  78. hbox1.Add(self.tc1, 0, wx.LEFT, 0)
  79. hbox2.Add(st2, 0, wx.LEFT, 50)
  80. hbox2.Add(self.tc2, 0, wx.LEFT, 0)
  81. hbox3.Add(st3, 0, wx.LEFT, 50)
  82. hbox3.Add(self.tc3, 0, wx.LEFT, 0)
  83. hbox4.Add(st4, 0, wx.LEFT, 50)
  84. hbox4.Add(self.tc4, 0, wx.LEFT, 0)
  85. hbox5.Add(st5, 0, wx.LEFT, 50)
  86. hbox5.Add(self.tc5, 0, wx.LEFT, 0)
  87. hboxLoadSave.Add(self.btnLoad, 0, wx.LEFT, 50)
  88. hboxLoadSave.Add(self.btnSave, 0, wx.LEFT, 0)
  89. hboxTestConnection.Add(cbDropBaze, 0, wx.LEFT, 50)
  90. hboxTestConnection.Add(btnTest, 0, wx.LEFT, 0)
  91. hboxTableOptions.Add(stSve, 0, wx.LEFT, 50)
  92. hboxcbWantAll.Add(self.cb1, 0, wx.LEFT, 50)
  93. hboxNotAll.Add(stOdredjene, 0, wx.LEFT, 50)
  94. hboxDropDown.Add(self.cbTablice, 0, wx.LEFT, 50)
  95. hboxGetPut.Add(btnDodajUdrop, 0, wx.LEFT, 50)
  96. hboxGetPut.Add(btnDodajZaScan, 0, wx.LEFT, 0)
  97.  
  98. vbox.Add(hbox1, 0, wx.TOP, 50)
  99. vbox.Add(hbox2, 0, wx.TOP, 10)
  100. vbox.Add(hbox3, 0, wx.TOP, 10)
  101. vbox.Add(hbox4, 0, wx.TOP, 10)
  102. vbox.Add(hbox5, 0, wx.TOP, 10)
  103. vbox.Add(hboxLoadSave, 0, wx.TOP, 10)
  104. vbox.Add(hboxTestConnection, 0, wx.TOP, 5)
  105. vbox.Add(hboxTableOptions, 0, wx.TOP, 20)
  106. vbox.Add(hboxcbWantAll, 0, wx.TOP, 20)
  107. vbox.Add(hboxNotAll, 0, wx.TOP, 10)
  108. vbox.Add(hboxDropDown, 0, wx.TOP, 20)
  109. vbox.Add(hboxGetPut, 0, wx.TOP, 5)
  110. #vbox.Add(self.write, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, 15)
  111.  
  112. stTables = wx.StaticText(self, -1, 'Selected tables: ', (350, 30))
  113. self.lc = wx.ListCtrl(self, -1, (350, 50), (360, 230), style=wx.LC_REPORT)
  114. self.lc.InsertColumn(0, 'Table')
  115. self.lc.InsertColumn(1, 'Number of records')
  116. self.lc.SetColumnWidth(0, 220)
  117. self.lc.SetColumnWidth(1, 135)
  118.  
  119. self.btnObrisiListu = wx.Button(self, 3, 'Delete all tables from list', size=(180, -1), pos=(350, 290))
  120. self.btnObrisiListu = wx.Button(self, 1, 'Remove selected table', size=(180, -1), pos=(530, 290))
  121.  
  122. stTables = wx.StaticText(self, -1, 'Malware scan detailed options: ', (350, 330))
  123. self.pdf = wx.CheckBox(self, -1, 'PDF Malware', (350, 360))
  124. self.pdf.SetValue(True)
  125. self.inj = wx.CheckBox(self, -1, 'Malware Injection', (500, 360))
  126. self.inj.SetValue(True)
  127. self.exe = wx.CheckBox(self, -1, 'Discover EXE Files', (350, 385))
  128. self.exe.SetValue(True)
  129. self.ifr = wx.CheckBox(self, -1, 'IFrame detection', (500, 385))
  130. self.ifr.SetValue(True)
  131. self.ClrSet = wx.Button(self, 777, 'Clear all settings', size=(180, -1), pos=(350, 420))
  132. self.Apply = wx.Button(self, 666, 'Apply settings', size=(180, -1), pos=(530, 420))
  133.  
  134. # ################# EVENTOVI ########################################
  135.  
  136. self.Bind (wx.EVT_BUTTON, self.MakniJednu, id=1)
  137. self.Bind (wx.EVT_BUTTON, self.Dodaj, id=2)
  138. self.Bind (wx.EVT_BUTTON, self.Ocisti, id=3)
  139. self.Bind (wx.EVT_BUTTON, self.Load, id=30)
  140. self.Bind (wx.EVT_BUTTON, self.Save, id=31)
  141. self.Bind (wx.EVT_BUTTON, self.ClearAllSettings, id=777)
  142. self.Bind (wx.EVT_BUTTON, self.ApplySettings, id=666)
  143. self.Bind (wx.EVT_BUTTON, self.Testiraj, id=888)
  144.  
  145. self.Bind (wx.EVT_BUTTON, self.PuniDrop, id=222)
  146. self.Bind (wx.EVT_CHECKBOX, self.DodajMakniSve, id=20)
  147.  
  148. # sizer = wx.BoxSizer(wx.VERTICAL)
  149. # sizer.Add(btn, 0, wx.ALL, 10)
  150. self.SetSizer(vbox)
  151.  
  152. # ################## METODE #########################################
  153.  
  154. def Testiraj(self, event):
  155. try:
  156. self.Konekt()
  157. wx.MessageBox('Connection succesful', 'OK')
  158. except Exception:
  159. wx.MessageBox('Error connecting to database!', 'Error')
  160.  
  161. def ClearAllSettings(self, event):
  162. #obisi sve settingse
  163. self.cbTablice.Clear()
  164. self.lc.DeleteAllItems()
  165. self.tc1.SetValue("")
  166. self.tc2.SetValue("")
  167. self.tc3.SetValue("")
  168. self.tc4.SetValue("")
  169. self.tc5.SetValue("")
  170. self.exe.SetValue(True)
  171. self.ifr.SetValue(True)
  172. self.inj.SetValue(True)
  173. self.pdf.SetValue(True)
  174. self.cb1.SetValue(False)
  175.  
  176. def ApplySettings(self, event):
  177. #save settings
  178. return
  179.  
  180. def PuniDrop(self, event):
  181. #dijalog = wx.MessageDialog(self, "Populate dropdown with all tables?", "Get tables", wx.YES_NO | wx.ICON_QUESTION)
  182. #rez = dijalog.ShowModal() == wx.ID_YES
  183. self.cbTablice.SetItems(self.tab)
  184. #dijalog.Destroy()
  185.  
  186. def DodajMakniSve(self, event):
  187.  
  188. self.lc.DeleteAllItems()
  189.  
  190. if self.cb1.GetValue():
  191. for x in self.tab:
  192. self.listaTablica.append(x)
  193. num_items = self.lc.GetItemCount()
  194. self.lc.InsertStringItem(num_items, x)
  195. self.lc.SetStringItem(num_items, 1, str(self.dbase.GetRowCount(x)))
  196. wx.Yield()
  197.  
  198. elif not self.cb1.GetValue():
  199. self.listaTablica = []
  200. self.lc.DeleteAllItems()
  201. #wx.MessageBox('deletam', 'error');
  202.  
  203. def Dodaj(self, event):
  204. if not self.cbTablice.GetValue():
  205. wx.MessageBox('Table not selected!', 'Error')
  206. return
  207.  
  208. for t in self.listaTablica:
  209. if t == self.cbTablice.GetValue():
  210. wx.MessageBox('Table already selected!', 'Error')
  211. self.nemaDuple = 0;
  212. return
  213. else:
  214. self.nemaDuple = 1;
  215.  
  216. if self.nemaDuple == 1:
  217. self.listaTablica.append(self.cbTablice.GetValue())
  218. num_items = self.lc.GetItemCount()
  219. zaUbacivanje = self.cbTablice.GetValue()
  220. self.lc.InsertStringItem(num_items, zaUbacivanje)
  221. self.lc.SetStringItem(num_items, 1, str(self.dbase.GetRowCount(zaUbacivanje)))
  222. #self.nemaDuple = 1;
  223. return
  224. else:
  225. return
  226.  
  227. def MakniJednu(self, event):
  228. index = self.lc.GetFocusedItem()
  229. selektirani=self.lc.GetItemText(index)
  230. self.lc.DeleteItem(index)
  231. self.listaTablica.remove(selektirani)
  232. self.nemaDuple = 1;
  233.  
  234. def Ocisti(self, event):
  235. self.lc.DeleteAllItems()
  236. self.listaTablica = []
  237. self.nemaDuple = 1;
  238.  
  239. def Load(self, event):
  240. try:
  241. conf = ConfigParser.RawConfigParser()
  242. conf.sections()
  243. conf.read('settings.config')
  244. conf.sections()
  245. self.korisnik = conf.get('configuration', 'user')
  246. self.lozinka = conf.get('configuration', 'pass')
  247. self.stroj = conf.get('configuration', 'dbname')
  248. self.db = conf.get('configuration', 'host')
  249. self.portnum = conf.get('configuration', 'port')
  250.  
  251. self.tc1.SetValue(self.korisnik)
  252. self.tc2.SetValue(self.lozinka)
  253. self.tc3.SetValue(self.stroj)
  254. self.tc4.SetValue(self.db)
  255. self.tc5.SetValue(self.portnum)
  256.  
  257. except Exception:
  258. wx.MessageBox('Error loading configuration!', 'Error')
  259.  
  260. def Save(self, event):
  261. try:
  262. config = ConfigParser.RawConfigParser()
  263. config.remove_section('configuration')
  264. config.add_section('configuration')
  265. config.set('configuration', 'user', self.tc1.GetValue())
  266. config.set('configuration', 'pass', self.tc2.GetValue())
  267. config.set('configuration', 'host', self.tc4.GetValue())
  268. config.set('configuration', 'dbname', self.tc3.GetValue())
  269. config.set('configuration', 'port', self.tc5.GetValue())
  270.  
  271. with open('settings.config', 'wb') as configfile:
  272. config.write(configfile)
  273.  
  274. wx.MessageBox('Configuration saved!', 'Info')
  275.  
  276. except Exception:
  277. wx.MessageBox('Error saving configuration!', 'Error')
  278.  
  279. def Konekt(self):
  280. self.dbase = DataBase(DB_ENGINE_MYSQL, self.tc4.GetValue(), self.tc3.GetValue(), self.tc1.GetValue(), self.tc2.GetValue())
  281. self.tab = self.dbase.GetTables()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement