Advertisement
Guest User

Untitled

a guest
Jan 29th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.15 KB | None | 0 0
  1. # main.py
  2. if __name__ == '__main__':
  3.     from lib import GUI as gui
  4.     from lib import Settings
  5.     from lib import Sqlite
  6.     import os
  7.     import PySimpleGUI as Sg
  8.  
  9.     path = os.path.dirname(os.path.realpath(__file__))
  10.     print(path)
  11.     name = 'database'
  12.     db = ''
  13.     loggedin = False
  14.     created = False
  15.     # the currently open case
  16.     active_case = ''
  17.  
  18.  
  19.     def makeCase(number, title, note):
  20.         values = {"number": number, "title": title, "note": note}
  21.         db.set_case(values)
  22.  
  23.     # The layout of the window is created with the 'layout' variable
  24.     layout = [[Sg.Text('At which location would you like to save the TUF database?')],
  25.               [Sg.Input(path), Sg.FolderBrowse()],
  26.               [Sg.T(' ' * 25), Sg.Button('Yes'), Sg.Button('No')]]
  27.     startWindow = Sg.Window('TUF - Turtle Forensics', icon='ICON.ico').Layout(layout)
  28.  
  29.     createCaseWindow2_active = createCaseWindow_active = win4_active = loggedWindow_active = loginWindow_active = False
  30.  
  31.     while True:
  32.         ev1, vals1 = startWindow.Read()
  33.         # If the 'close' button is pushed the program is going to stop with running
  34.         if ev1 is None:
  35.             break
  36.         # If the 'No' button is pushed the program is going to stop with running
  37.         if ev1 == 'No':
  38.             break
  39.         # If the 'Yes' button is pushed the program is going to save the database in the location you've chose
  40.         if ev1 == 'Yes':
  41.             if path != vals1[0]:
  42.                 path = vals1[0]
  43.             db = Sqlite.Sqlite(path, name)
  44.             db.setup_database()
  45.         # If the 'Yes' button is pushed the program is going to activate the 2nd window and hide the previous window.
  46.         if not loginWindow_active and ev1 == 'Yes':
  47.             loginWindow_active = True
  48.             startWindow.Hide()
  49.             # The layout of the window is created with the 'layout' variable
  50.             layout2 = [[Sg. Text('Login as a TUF user or create a new user account.')],
  51.                        [Sg.Text('Username'), Sg.Input()],
  52.                        [Sg.Text('Password'), Sg.Input(password_char='*')],
  53.                        [Sg.Button('Login'), Sg.Button('Create User')]]
  54.             loginWindow = Sg.Window('TUF - Turtle Forensics', size=(400, 300), icon='ICON.ico').Layout(layout2)
  55.  
  56.         if loginWindow_active:
  57.             ev2, vals2 = loginWindow.Read()
  58.  
  59.             if ev2 == "Create User":
  60.                 created = False
  61.                 username = vals2[0]
  62.  
  63.                 print("creating")
  64.  
  65.                 if ev2 == 'Create User':
  66.  
  67.  
  68.                 if ev2 is None:
  69.                     break
  70.             else:
  71.                 username = vals2[0]
  72.                 password = vals2[1]
  73.  
  74.                 if ev2 == 'Login':
  75.                     check_loggedin = db.check_user(username, password)
  76.  
  77.                     if check_loggedin is True:
  78.                         loggedin = True
  79.                         Sg.Popup("You've been logged in successfully! Welcome " + vals2[0] + "!")
  80.                         break
  81.  
  82.                     elif check_loggedin is False:
  83.                         loggedin = False
  84.                         Sg.Popup("This combination of username and password does not exist.")
  85.                         ev2, vals2 = loginWindow.Read()
  86.  
  87.                     else:
  88.                         Sg.Popup("Something went wrong. Try again.")
  89.                         loggedin = False
  90.  
  91.         if not loggedWindow_active and loggedin is True and created is False:
  92.             cases = db.get_cases()
  93.             table = Sg.Table(cases,
  94.                              headings=["case", "case id", "title", "description", "date created"],
  95.                              enable_events=True)
  96.             loggedWindow_active = True
  97.             loginWindow.Hide()
  98.             # The layout of the window is created with the 'layout' variable
  99.             layout3 = [[Sg.T(' ' * 20), Sg.Text('Welcome to Turtle Forensics!')],
  100.                        [Sg.Text('', key='OUTPUT')],
  101.                        [Sg.Text('Would you like to create a new case or open a recent one?')],
  102.                        [table],
  103.                        [Sg.Button('Open Case'), Sg.Button('Create Case')]]
  104.             loggedWindow = Sg.Window('TUF - Turtle Forensics', icon='ICON.ico').Layout(layout3)
  105.  
  106.             while True:
  107.                 if loggedWindow_active:
  108.                     ev3, vals3 = loggedWindow.Read()
  109.  
  110.                     if ev3 == 'clicked':
  111.  
  112.                         Sg.Popup(vals3)
  113.                     if ev3 == 'Open Case':
  114.                         active_case = cases[vals3[0][0]][0]
  115.                         break
  116.  
  117.                     if ev3 is None:
  118.                         break
  119.  
  120.                 if not createCaseWindow_active and ev3 == 'Create Case':
  121.                     createCaseWindow_active = True
  122.                     loggedWindow.Hide()
  123.                     # The layout of the window is created with the 'layout' variable
  124.                     layout4 = [[Sg.Text('Case Number: '), Sg.Input()],
  125.                                [Sg.Text('Case Title:      '), Sg.Input('')],
  126.                                [Sg.Text('Case Note:     '), Sg.Input()],
  127.                                [Sg.Button('Back'), Sg.Button('Save Case')]]
  128.                     createCaseWindow = Sg.Window('Turtle Forensics - Create Case', icon='ICON.ico').Layout(layout4)
  129.  
  130.                     if createCaseWindow_active and loggedin is True:
  131.                         ev4, vals4 = createCaseWindow.Read()
  132.                         if ev4 == 'Save Case':
  133.                             x = ev4, vals4[0]
  134.                             number = x[1]
  135.                             y = ev4, vals4[1]
  136.                             title = y[1]
  137.                             z = ev4, vals4[2]
  138.                             note = z[1]
  139.  
  140.                             makeCase(number, title, note)
  141.                             Sg.Popup('The case: ', title, 'has been made.', icon='ICON.ico')
  142.  
  143.                             createCaseWindow2_active = True
  144.                             createCaseWindow_active = False
  145.                             createCaseWindow.Hide()
  146.                             # The layout of the window is created with the 'layout' variable
  147.                             layout5 = [[Sg.Radio('E01', "Image", key='E01'), Sg.Radio('RAW', "Image", key='RAW')],
  148.                                        [Sg.Text('Image source:    '), Sg.Input(), Sg.FolderBrowse()],
  149.                                        [Sg.Checkbox('Hash Image after Indexing')],
  150.                                        [Sg.Button('Back'), Sg.Button('Save')]]
  151.                             createCaseWindow2 = Sg.Window('Turtle Forensics - Create Case', icon='ICON.ico').Layout(layout5)
  152.  
  153.                     if createCaseWindow2_active:
  154.                         ev5, vals5 = createCaseWindow2.Read()
  155.  
  156.                         if ev5 == 'Save':
  157.                             if vals5['E01']:
  158.                                 print('e01')
  159.                             if vals5['RAW']:
  160.                                 print('raw')
  161.  
  162.                 # case overview
  163.                 if not createCaseWindow2_active and ev3 == 'Open Case' and loggedin is True:
  164.                     case = db.get_case(active_case)
  165.                     loggedWindow.Hide()
  166.                     print(case)
  167.                     layout5 = [[Sg.Radio('E01', "Image", key='e01'), Sg.Radio('RAW', "Image", key='RAW')],
  168.                                [Sg.Text('Image source:    '), Sg.Input(), Sg.FolderBrowse()],
  169.                                [Sg.Checkbox('Hash Image after Indexing')],
  170.                                [Sg.Button('Back'), Sg.Button('Save')]]
  171.                     createCaseWindow2 = Sg.Window('Turtle Forensics - case ' + str(case[2]), icon='ICON.ico').Layout(layout5)
  172.  
  173. def CreatUser(username, password):
  174.     check_created = db.check_exist(username)
  175.  
  176.     if check_created == username:
  177.         created = True
  178.         Sg.Popup("This user already exists!")
  179.         ev2, vals2 = loginWindow.Read()
  180.  
  181.     else:
  182.         db.set_user(values)
  183.         Sg.Popup("The user with the name " + username + " has been created!")
  184.         loggedin = True
  185.         created = False
  186.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement