Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import os
- import wx.html
- import cStringIO
- import sys
- import random
- import ConfigParser
- import datetime
- import UltimateListCtrl as ULC
- import time
- import hashlib
- import md5
- from DataBase import *
- class TabSettings(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent=parent)
- #self.Konekt()
- self.listaTablica = []
- self.nemaDuple = 1;
- self.korisnik = ""
- self.lozinka = ""
- self.stroj = ""
- self.db = ""
- self.portnum = ""
- self.tablice = []
- self.BAZE_PODATAKA = ['MYSQL', 'POSTGRESQL', 'MSSQL']
- wx.StaticBox(self, -1, 'Settings for malware scanner', (5, 5), size=(755, 490))
- self.SetBackgroundColour('#ADB2BF')
- vbox = wx.BoxSizer(wx.VERTICAL)
- hbox1 = wx.BoxSizer(wx.HORIZONTAL)
- hbox2 = wx.BoxSizer(wx.HORIZONTAL)
- hbox3 = wx.BoxSizer(wx.HORIZONTAL)
- hbox4 = wx.BoxSizer(wx.HORIZONTAL)
- hbox5 = wx.BoxSizer(wx.HORIZONTAL)
- hboxListBox = wx.BoxSizer(wx.HORIZONTAL)
- hboxLoadSave = wx.BoxSizer(wx.HORIZONTAL)
- hboxTestConnection = wx.BoxSizer(wx.HORIZONTAL)
- hboxTableOptions = wx.BoxSizer(wx.HORIZONTAL)
- hboxcbWantAll = wx.BoxSizer(wx.HORIZONTAL)
- hboxNotAll = wx.BoxSizer(wx.HORIZONTAL)
- hboxDropDown = wx.BoxSizer(wx.HORIZONTAL)
- hboxGetPut = wx.BoxSizer(wx.HORIZONTAL)
- st1 = wx.StaticText(self, -1, 'Username:', size=(110, -1))
- st2 = wx.StaticText(self, -1, 'Password:', size=(110, -1))
- st3 = wx.StaticText(self, -1, 'Instance:', size=(110, -1))
- st4 = wx.StaticText(self, -1, 'IP addr:', size=(110, -1))
- st5 = wx.StaticText(self, -1, 'Port:', size=(110, -1))
- self.tc1 = wx.TextCtrl(self, -1, size=(120, 18))
- self.tc2 = wx.TextCtrl(self, -1, size=(120, 18), style = wx.TE_PASSWORD)
- self.tc3 = wx.TextCtrl(self, -1, size=(120, 18))
- self.tc4 = wx.TextCtrl(self, -1, size=(120, 18))
- self.tc5 = wx.TextCtrl(self, -1, size=(120, 18))
- self.btnLoad = wx.Button(self, 30, "Load conf", size=(116, -1))
- self.btnSave = wx.Button(self, 31, "Save conf", size=(116, -1))
- cbDropBaze = wx.ComboBox(self, -1, size=(116, -1), choices=self.BAZE_PODATAKA, style=wx.CB_READONLY)
- btnTest = wx.Button(self, 888, "Test connection", size=(116, -1))
- stSve = wx.StaticText(self, -1, 'Tables options: ')
- self.cb1 = wx.CheckBox(self, 20, 'I want to scan all tables in database')
- self.cb1.SetValue(False)
- stOdredjene = wx.StaticText(self, -1, 'I want to scan only these certain tables: ')
- self.cbTablice = wx.ComboBox(self, -1, pos=(50, 340), size=(230, -1), choices=self.tablice, style=wx.CB_READONLY)
- btnDodajUdrop = wx.Button(self, 222, 'Get tables', size=(115, -1))
- btnDodajZaScan = wx.Button(self, 2, 'Add table for scan', size=(115, -1))
- hbox1.Add(st1, 0, wx.LEFT, 50)
- hbox1.Add(self.tc1, 0, wx.LEFT, 0)
- hbox2.Add(st2, 0, wx.LEFT, 50)
- hbox2.Add(self.tc2, 0, wx.LEFT, 0)
- hbox3.Add(st3, 0, wx.LEFT, 50)
- hbox3.Add(self.tc3, 0, wx.LEFT, 0)
- hbox4.Add(st4, 0, wx.LEFT, 50)
- hbox4.Add(self.tc4, 0, wx.LEFT, 0)
- hbox5.Add(st5, 0, wx.LEFT, 50)
- hbox5.Add(self.tc5, 0, wx.LEFT, 0)
- hboxLoadSave.Add(self.btnLoad, 0, wx.LEFT, 50)
- hboxLoadSave.Add(self.btnSave, 0, wx.LEFT, 0)
- hboxTestConnection.Add(cbDropBaze, 0, wx.LEFT, 50)
- hboxTestConnection.Add(btnTest, 0, wx.LEFT, 0)
- hboxTableOptions.Add(stSve, 0, wx.LEFT, 50)
- hboxcbWantAll.Add(self.cb1, 0, wx.LEFT, 50)
- hboxNotAll.Add(stOdredjene, 0, wx.LEFT, 50)
- hboxDropDown.Add(self.cbTablice, 0, wx.LEFT, 50)
- hboxGetPut.Add(btnDodajUdrop, 0, wx.LEFT, 50)
- hboxGetPut.Add(btnDodajZaScan, 0, wx.LEFT, 0)
- vbox.Add(hbox1, 0, wx.TOP, 50)
- vbox.Add(hbox2, 0, wx.TOP, 10)
- vbox.Add(hbox3, 0, wx.TOP, 10)
- vbox.Add(hbox4, 0, wx.TOP, 10)
- vbox.Add(hbox5, 0, wx.TOP, 10)
- vbox.Add(hboxLoadSave, 0, wx.TOP, 10)
- vbox.Add(hboxTestConnection, 0, wx.TOP, 5)
- vbox.Add(hboxTableOptions, 0, wx.TOP, 20)
- vbox.Add(hboxcbWantAll, 0, wx.TOP, 20)
- vbox.Add(hboxNotAll, 0, wx.TOP, 10)
- vbox.Add(hboxDropDown, 0, wx.TOP, 20)
- vbox.Add(hboxGetPut, 0, wx.TOP, 5)
- #vbox.Add(self.write, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, 15)
- stTables = wx.StaticText(self, -1, 'Selected tables: ', (350, 30))
- self.lc = wx.ListCtrl(self, -1, (350, 50), (360, 230), style=wx.LC_REPORT)
- self.lc.InsertColumn(0, 'Table')
- self.lc.InsertColumn(1, 'Number of records')
- self.lc.SetColumnWidth(0, 220)
- self.lc.SetColumnWidth(1, 135)
- self.btnObrisiListu = wx.Button(self, 3, 'Delete all tables from list', size=(180, -1), pos=(350, 290))
- self.btnObrisiListu = wx.Button(self, 1, 'Remove selected table', size=(180, -1), pos=(530, 290))
- stTables = wx.StaticText(self, -1, 'Malware scan detailed options: ', (350, 330))
- self.pdf = wx.CheckBox(self, -1, 'PDF Malware', (350, 360))
- self.pdf.SetValue(True)
- self.inj = wx.CheckBox(self, -1, 'Malware Injection', (500, 360))
- self.inj.SetValue(True)
- self.exe = wx.CheckBox(self, -1, 'Discover EXE Files', (350, 385))
- self.exe.SetValue(True)
- self.ifr = wx.CheckBox(self, -1, 'IFrame detection', (500, 385))
- self.ifr.SetValue(True)
- self.ClrSet = wx.Button(self, 777, 'Clear all settings', size=(180, -1), pos=(350, 420))
- self.Apply = wx.Button(self, 666, 'Apply settings', size=(180, -1), pos=(530, 420))
- # ################# EVENTOVI ########################################
- self.Bind (wx.EVT_BUTTON, self.MakniJednu, id=1)
- self.Bind (wx.EVT_BUTTON, self.Dodaj, id=2)
- self.Bind (wx.EVT_BUTTON, self.Ocisti, id=3)
- self.Bind (wx.EVT_BUTTON, self.Load, id=30)
- self.Bind (wx.EVT_BUTTON, self.Save, id=31)
- self.Bind (wx.EVT_BUTTON, self.ClearAllSettings, id=777)
- self.Bind (wx.EVT_BUTTON, self.ApplySettings, id=666)
- self.Bind (wx.EVT_BUTTON, self.Testiraj, id=888)
- self.Bind (wx.EVT_BUTTON, self.PuniDrop, id=222)
- self.Bind (wx.EVT_CHECKBOX, self.DodajMakniSve, id=20)
- # sizer = wx.BoxSizer(wx.VERTICAL)
- # sizer.Add(btn, 0, wx.ALL, 10)
- self.SetSizer(vbox)
- # ################## METODE #########################################
- def Testiraj(self, event):
- try:
- self.Konekt()
- wx.MessageBox('Connection succesful', 'OK')
- except Exception:
- wx.MessageBox('Error connecting to database!', 'Error')
- def ClearAllSettings(self, event):
- #obisi sve settingse
- self.cbTablice.Clear()
- self.lc.DeleteAllItems()
- self.tc1.SetValue("")
- self.tc2.SetValue("")
- self.tc3.SetValue("")
- self.tc4.SetValue("")
- self.tc5.SetValue("")
- self.exe.SetValue(True)
- self.ifr.SetValue(True)
- self.inj.SetValue(True)
- self.pdf.SetValue(True)
- self.cb1.SetValue(False)
- def ApplySettings(self, event):
- #save settings
- return
- def PuniDrop(self, event):
- #dijalog = wx.MessageDialog(self, "Populate dropdown with all tables?", "Get tables", wx.YES_NO | wx.ICON_QUESTION)
- #rez = dijalog.ShowModal() == wx.ID_YES
- self.cbTablice.SetItems(self.tab)
- #dijalog.Destroy()
- def DodajMakniSve(self, event):
- self.lc.DeleteAllItems()
- if self.cb1.GetValue():
- for x in self.tab:
- self.listaTablica.append(x)
- num_items = self.lc.GetItemCount()
- self.lc.InsertStringItem(num_items, x)
- self.lc.SetStringItem(num_items, 1, str(self.dbase.GetRowCount(x)))
- wx.Yield()
- elif not self.cb1.GetValue():
- self.listaTablica = []
- self.lc.DeleteAllItems()
- #wx.MessageBox('deletam', 'error');
- def Dodaj(self, event):
- if not self.cbTablice.GetValue():
- wx.MessageBox('Table not selected!', 'Error')
- return
- for t in self.listaTablica:
- if t == self.cbTablice.GetValue():
- wx.MessageBox('Table already selected!', 'Error')
- self.nemaDuple = 0;
- return
- else:
- self.nemaDuple = 1;
- if self.nemaDuple == 1:
- self.listaTablica.append(self.cbTablice.GetValue())
- num_items = self.lc.GetItemCount()
- zaUbacivanje = self.cbTablice.GetValue()
- self.lc.InsertStringItem(num_items, zaUbacivanje)
- self.lc.SetStringItem(num_items, 1, str(self.dbase.GetRowCount(zaUbacivanje)))
- #self.nemaDuple = 1;
- return
- else:
- return
- def MakniJednu(self, event):
- index = self.lc.GetFocusedItem()
- selektirani=self.lc.GetItemText(index)
- self.lc.DeleteItem(index)
- self.listaTablica.remove(selektirani)
- self.nemaDuple = 1;
- def Ocisti(self, event):
- self.lc.DeleteAllItems()
- self.listaTablica = []
- self.nemaDuple = 1;
- def Load(self, event):
- try:
- conf = ConfigParser.RawConfigParser()
- conf.sections()
- conf.read('settings.config')
- conf.sections()
- self.korisnik = conf.get('configuration', 'user')
- self.lozinka = conf.get('configuration', 'pass')
- self.stroj = conf.get('configuration', 'dbname')
- self.db = conf.get('configuration', 'host')
- self.portnum = conf.get('configuration', 'port')
- self.tc1.SetValue(self.korisnik)
- self.tc2.SetValue(self.lozinka)
- self.tc3.SetValue(self.stroj)
- self.tc4.SetValue(self.db)
- self.tc5.SetValue(self.portnum)
- except Exception:
- wx.MessageBox('Error loading configuration!', 'Error')
- def Save(self, event):
- try:
- config = ConfigParser.RawConfigParser()
- config.remove_section('configuration')
- config.add_section('configuration')
- config.set('configuration', 'user', self.tc1.GetValue())
- config.set('configuration', 'pass', self.tc2.GetValue())
- config.set('configuration', 'host', self.tc4.GetValue())
- config.set('configuration', 'dbname', self.tc3.GetValue())
- config.set('configuration', 'port', self.tc5.GetValue())
- with open('settings.config', 'wb') as configfile:
- config.write(configfile)
- wx.MessageBox('Configuration saved!', 'Info')
- except Exception:
- wx.MessageBox('Error saving configuration!', 'Error')
- def Konekt(self):
- self.dbase = DataBase(DB_ENGINE_MYSQL, self.tc4.GetValue(), self.tc3.GetValue(), self.tc1.GetValue(), self.tc2.GetValue())
- self.tab = self.dbase.GetTables()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement