Exemplo n.º 1
0
    def open_investigation(self):
        """Open investigation data"""
        db = Database()
        investigation_ids = db.retrieve_investigation_ids()
        if not investigation_ids:
            messagebox.showinfo("No saved investigations", "Please save an investigation before loading data")
            db.close_connection()
        if investigation_ids:
            # clear investigation id
            self.investigation_id_tracker = ""

            self.open = OpenTool()
            self.open.title('Open investigation')
            self.open.geometry('+%d+%d' % (root.winfo_x() +
                                                  20, root.winfo_y() + 20))
            if sys.platform == "win32":
                self.open.iconbitmap(self.icon)
            self.open.resizable(width=False, height=False)
            self.open.protocol('WM_DELETE_WINDOW', self.open.quit_open)
            # set focus on window
            self.open.grab_set()
            self.open.focus()

            # start mainloop
            self.open.mainloop()
Exemplo n.º 2
0
class SaveTool(tk.Toplevel):
    """Opens a window to store investigation data"""
    def __init__(self, master=None, investigation_id=None, data=None, *args, **kwargs):
        """Initializes Toplevel object and builds interface"""
        super().__init__(master, *args, **kwargs)
        # initialize variables
        self.investigation_id = investigation_id
        self.data = data
        # initialize database
        self.db_handler = Database()
        # hide window in background during drawing and load, to prevent flickering and glitches during frame load
        self.withdraw()
        # build and draw the window
        self.build()
        # unhide the Toplevel window immediately after draw and load 
        self.after(0, self.deiconify)

    def build(self):
        """Initializes and builds application widgets"""
        # create input labelframe
        labelframe_1 = tk.LabelFrame(self, fg='brown')
        labelframe_1.pack(side="top", expand='yes', fill='both', padx=2, pady=2, anchor="n")

        # create explanation label
        self.label = tk.Label(labelframe_1, text='Save As...')
        self.label.pack(expand=True, fill='x', side="left", padx=2, pady=2)

        # create data input entry widget
        self.entry = tk.Entry(labelframe_1)
        self.entry.pack(expand=True, fill='x', side="left", padx=2, pady=2)
        
        # create save button
        self.save_button = tk.Button(labelframe_1, text="Save", command=self.save_data)
        self.save_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

        # create cancel button
        self.cancel_button = tk.Button(labelframe_1, text="Cancel", command=self.quit_save)
        self.cancel_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

        self.entry.insert(0, self.investigation_id)

    def save_data(self):
        """Stores investigation data within database"""
        if self.data:
            try:
                self.db_handler.store_investigation(self.entry.get(), self.data)
                messagebox.showinfo("Success", "Successfully saved investigation")
                self.quit_save()

            except Exception:
                messagebox.showerror("Error saving data", "Failed to save data!")
                self.quit_save()
        else:
            messagebox.showinfo("No data", "There is no data to save")

    def quit_save(self):
        """Quits the save window"""
        self.db_handler.close_connection()
        self.destroy()
Exemplo n.º 3
0
class DeleteTool(tk.Toplevel):
    """Opens a window to retrieve investigation data"""
    def __init__(self, master=None, *args, **kwargs):
        """Initializes Toplevel object and builds interface"""
        super().__init__(master, *args, **kwargs)
        # initialize variables
        self.selection = tk.StringVar(self)
        # initialize database
        self.db_handler = Database()
        # hide window in background during drawing and load, to prevent flickering and glitches during frame load
        self.withdraw()
        # build and draw the window
        self.build()
        # unhide the Toplevel window immediately after draw and load 
        self.after(0, self.deiconify)

    def build(self):
        """Initializes and builds application widgets"""
        # create input labelframe
        labelframe_1 = tk.LabelFrame(self, fg='brown')
        labelframe_1.pack(side="top", expand='yes', fill='both', padx=2, pady=2, anchor="n")

        # create explanation label
        self.label = tk.Label(labelframe_1, text='Delete...')
        self.label.pack(expand=True, fill='x', side="left", padx=2, pady=2)

        # create data input entry widget
        self.options = tk.OptionMenu(labelframe_1, self.selection, *self.db_handler.retrieve_investigation_ids(),
        command=self.delete_data)
        self.options.pack(expand=True, fill='x', side="left", padx=2, pady=2)
        self.selection.set(self.db_handler.retrieve_investigation_ids()[0])

        # create save button
        self.save_button = tk.Button(labelframe_1, text="Delete", command=self.delete_data)
        self.save_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

        # create cancel button
        self.cancel_button = tk.Button(labelframe_1, text="Cancel", command=self.quit)
        self.cancel_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

    def delete_data(self, value=None):
        """Deletes investigation data from database"""
        if value:
            investigation_id = value
        else:
            investigation_id = self.selection.get()
        try:
            self.db_handler.delete_investigation(investigation_id)
            self.quit()

        except Exception as e:
            print("[*] Error: ", e)
            self.quit()

    def quit(self):
        """Quits the open window"""
        self.db_handler.close_connection()
        self.destroy()
Exemplo n.º 4
0
class ApiTool(tk.Toplevel):
    """Opens a new window providing users ability to input api keys"""

    def __init__(self, master=None, *args, **kwargs):
        """Initializes Toplevel object and builds interface"""
        super().__init__(master, *args, **kwargs)
        self.db_handler = Database()
        # hide window in background during drawing and load, to prevent flickering and glitches during frame load
        self.withdraw()
        # build and draw the window
        self.build()
        # unhide the Toplevel window immediately after draw and load 
        self.after(0, self.deiconify)

    def build(self):
        """Initializes and builds application widgets"""
        # create input labelframe
        labelframe_1 = tk.LabelFrame(self, text="api key manager", fg='brown')
        labelframe_1.pack(side="top", expand='yes', fill='both', padx=2, pady=2, anchor="n") 
        
        # create data mining action selection drop down
        self.selector = ttk.Combobox(labelframe_1, values=self.db_handler.get_apis(), state="readonly", width=50)
        self.selector.current(0)
        self.selector.pack(expand=True, fill='x', side="top", padx=2, pady=2)

        # create data input entry widget
        self.entry = tk.Entry(labelframe_1)
        self.entry.pack(expand=True, fill='x', side="top", padx=2, pady=2)

        # create status label
        self.status = tk.Label(self, text='hit return to store api key', font=('verdana', 6, 'normal'))
        self.status.pack(anchor='se')

        # gui bindings
        self.selector.bind("<<ComboboxSelected>>", self.grab_api_key)
        self.selector.bind("<Return>", self.grab_api_key)
        self.entry.bind('<Return>', self.add_api_key)

    def grab_api_key(self, event=None):
        """Returns api key of selected api"""
        api = self.selector.get()
        _key = self.db_handler.get_api_key(api)
        self.entry.delete(0, tk.END)
        self.entry.insert(0, _key)
        self.status['text'] = "api key retrieved"
        if not _key:
            self.status['text'] = "no api key exists, create one?"

    def add_api_key(self, event=None):
        """Adds api key in database"""
        _key = self.entry.get()
        if self.entry.get():
            self.db_handler.insert_api_key(self.selector.get(), self.entry.get())
            self.grab_api_key()
            self.status['text'] = "api key added"
        if not self.entry.get():
            if self.db_handler.get_api_key(self.selector.get()):
                self.db_handler.insert_api_key(self.selector.get(), self.entry.get())
                self.grab_api_key()
                self.status['text'] = "api key deleted"
            else:
                self.status['text'] = "no api key provided"

    def close_window(self):
        """Closes program window and database"""
        self.db_handler.close_connection()
        self.destroy()