def settingsForm(): root = Toplevel() windowWidth = 700 windowHeight = 340 screenWidth = root.winfo_screenwidth() screenHeight = root.winfo_screenheight() positionRight = int(screenWidth / 2 - windowWidth / 2) positionDown = int(screenHeight / 3 - windowHeight / 2) root.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown)) root.wait_visibility(root) root.wm_attributes('-alpha', 0.98) img = PhotoImage(data=icons.getAppIcon()) root.wm_iconphoto(True, img) root.title('Cerberus - Επεξεργασία Στοιχείων') welcomeFrame = Frame(root, height=130, bg='#1e1e2f') welcomeFrame.pack(side="top", fill=BOTH) appIcon = PhotoImage(data=icons.getLogoIcon()) panel = Label(root, image=appIcon, bg='#1e1e2f').place(x=20, y=20) Label(welcomeFrame, text="Καλώς ορίσατε στον", font=("Comic Sans MS", 32), fg='white', bg='#1e1e2f').place(x=110, y=25) Label(welcomeFrame, text="Cerberus", font=("Helvetica", 32), fg='#d9ddff', bg='#1e1e2f').place(x=380, y=72) mainFrame = Frame(root, bg='lightgrey') mainFrame.pack(side="top", fill=BOTH, expand=True) Label(mainFrame, text="Κύριο Email:", font=("Arial", 12), bg='lightgrey').pack(pady=(25, 0)) emailFrame = Frame(mainFrame, background="white", borderwidth=1, relief="sunken", highlightthickness=1) emailFrame.pack(side="top", padx=0, pady=0) emailEntry = Entry(emailFrame, width=35, borderwidth=0, highlightthickness=0, background="white") emailEntry.image = PhotoImage(data=icons.getEmailIcon()) imageLabel = Label(emailFrame, image=emailEntry.image) imageLabel.pack(side="left") imageLabel['bg'] = 'white' emailEntry.pack(side="left", fill="both", expand=True) Label(mainFrame, text="Κύριος Κωδικός:", font=("Arial", 12), bg='lightgrey').pack(pady=(20,0)) passwordFrame = Frame(mainFrame, background="white", borderwidth=1, relief="sunken", highlightthickness=1) passwordFrame.pack(side="top", padx=0, pady=0) passwordEntry = Entry(passwordFrame, width=35, borderwidth=0, highlightthickness=0, background="white") passwordEntry.image = PhotoImage(data=icons.getPasswordIcon()) imageLabel = Label(passwordFrame, image=passwordEntry.image) imageLabel.pack(side="left") imageLabel['bg'] = 'white' passwordEntry.pack(side="left", fill="both", expand=True) saveIcon = PhotoImage(data=icons.getSaveIcon()) okBtn = Button(mainFrame, borderwidth=1, text="Αποθήκευση", image=saveIcon, compound=LEFT, width=125) okBtn.pack(pady="15") root.resizable(0, 0) root.mainloop()
def __init__(self, master, root): self.exportToCSV = False self.versionApp, self.key, self.salt = self.initApp() self.key = cerberusCryptography.getMasterKey() self.cipher_suite = Fernet(self.key) self.master = master self.master.title('Cerberus') self.windowWidth = 1060 self.windowHeight = 450 self.screenWidth = self.master.winfo_screenwidth() self.screenHeight = self.master.winfo_screenheight() self.positionRight = int(self.screenWidth / 2 - self.windowWidth / 2) self.positionDown = int(self.screenHeight / 3 - self.windowHeight / 2) self.master.geometry("{}x{}+{}+{}".format(self.windowWidth, self.windowHeight, self.positionRight, self.positionDown)) self.img = PhotoImage(data=icons.getAppIcon()) self.master.wm_iconphoto(True, self.img) self.master.resizable(0, 0) self.menubar = Menu(master) filemenu = Menu(self.menubar, tearoff=0) self.menubar.add_cascade(label="Cerberus", menu=filemenu) self.addIcon = PhotoImage(data=icons.getAddIcon()) filemenu.add_command(label="Εισαγωγή Υπηρεσίας", image=self.addIcon, compound='left', command=self.getAddNewServiceForm) self.editIcon = PhotoImage(data=icons.getEditIcon()) filemenu.add_command(label="Επεξεργασία Υπηρεσίας", image=self.editIcon, compound='left', command=self.getEditServiceForm) self.deleteIcon = PhotoImage(data=icons.getDeleteIcon()) filemenu.add_command(label="Διαγραφή Υπηρεσίας", image=self.deleteIcon, compound='left', command=self.deleteService) filemenu.add_separator() self.excelIcon = PhotoImage(data=icons.getExcelIcon()) filemenu.add_command(label="Εξαγωγή σε Excel", image=self.excelIcon, compound='left', command=self.checkPasswordToExportToCSV) filemenu.add_separator() self.exitIcon = PhotoImage(data=icons.getExitIcon()) filemenu.add_command(label="Έξοδος", image=self.exitIcon, compound='left', command=self.exitApp) settingsMenu = Menu(self.menubar, tearoff=0) self.menubar.add_cascade(label="Ρυθμίσεις", menu=settingsMenu) self.settingsIcon = PhotoImage(data=icons.getSettingsIcon()) settingsMenu.add_command(label="Επεξεργασία Στοιχείων", image=self.settingsIcon, compound='left') #command=self.getSettingsForm) aboutMenu = Menu(self.menubar, tearoff=0) self.menubar.add_cascade(label="Βοήθεια", menu=aboutMenu) self.infoIcon = PhotoImage(data=icons.getInfoIcon()) aboutMenu.add_command(label="Περί", image=self.infoIcon, compound='left', command=self.getAboutAppForm) self.master.config(menu=self.menubar) self.copyIcon = PhotoImage(data=icons.getCopyIcon()) self.popup = Menu(root, tearoff=0) self.popup.add_command(label=" Αντιγραφή Email", image=self.copyIcon, compound='left', command=self.copyEmail) self.popup.add_command(label=" Αντιγραφή Username", image=self.copyIcon, compound='left', command=self.copyUsername) self.popup.add_command(label=" Αντιγραφή Κωδικού", image=self.copyIcon, compound='left', command=self.copyPasswd) self.popup.add_command(label=" Αντιγραφή ID", image=self.copyIcon, compound='left', command=self.copyID) self.popup.add_separator() self.popup.add_command(label=" Επεξεργασία Υπηρεσίας", image=self.editIcon, compound='left', command=self.getEditServiceForm) self.popup.add_command(label=" Διαγραφή Υπηρεσίας", image=self.deleteIcon, compound='left', command=self.deleteService) self.popup.add_separator() self.popup.add_command(label=" Έξοδος", image=self.exitIcon, compound='left', command=self.exitApp) self.frame = Frame(self.master, background="white", borderwidth=1, relief="sunken", highlightthickness=1) self.frame.pack(side="top", fill="x", padx=4, pady=4) self.search = StringVar() self.searchEntry = Entry(self.frame, textvariable=self.search, borderwidth=0, highlightthickness=0, background="white") self.searchEntry.insert(0, 'Αναζήτηση Υπηρεσίας') self.searchEntry['fg'] = 'grey' self.search.trace( "w", lambda name, index, mode, sv=self.search: self.searchService()) self.searchEntry.image = PhotoImage(data=icons.getSearchIcon()) imageLabel = Label(self.frame, image=self.searchEntry.image) imageLabel.pack(side="left") imageLabel['bg'] = 'white' self.searchEntry.pack(side="left", fill="both", expand=True) # Fix BUG with Treeview colors in Python3.7 def fixed_map(option): return [ elm for elm in style.map('Treeview', query_opt=option) if elm[:2] != ('!disabled', '!selected') ] style = ttk.Style(root) style.map('Treeview', foreground=fixed_map('foreground'), background=fixed_map('background')) # Fix BUG with Treeview colors in Python3.7 self.table = Treeview(self.master) self.table['show'] = 'headings' self.table['columns'] = ('Services', 'email', 'username', 'passwd', 'id', 'category', 'url', 'ID') self.table["displaycolumns"] = ('Services', 'email', 'username', 'passwd', 'id', 'category', 'url') for col in self.table['columns']: self.table.heading( col, command=lambda c=col: self.sortby(self.table, c, 0)) self.table.heading('Services', text='Services') self.table.column('Services', anchor='center', width=200) self.table.heading('email', text='Email') self.table.column('email', anchor='center', width=200) self.table.heading('username', text='Username') self.table.column('username', anchor='center', width=100) self.table.heading('passwd', text='Password') self.table.column('passwd', anchor='center', width=100) self.table.heading('url', text='URL') self.table.column('url', anchor='center', width=120) self.table.heading('id', text='ID') self.table.column('id', anchor='center', width=100) self.table.heading('category', text='Category') self.table.column('category', anchor='center', width=100) self.table.heading('ID', text='ID') self.table.column('ID', anchor='center', width=200) self.table.tag_configure('oddrow', background='#e6eef2') self.table.tag_configure('evenrow', background='#b3cfdd') self.table.tag_configure('focus', background='#c6b6b4') self.last_focus = None self.last_focus_tag = None self.table.focus() self.table.pack(fill=BOTH, expand=1) self.table.bind("<<TreeviewSelect>>", self.onTableSelect) self.table.bind("<ButtonRelease-1>", self.openURLService) self.table.bind("<Motion>", self.changePointerOnHover) self.table.bind("<Button-3>", self.popupMenu) self.searchEntry.bind("<FocusIn>", self.foc_in) self.searchEntry.bind("<FocusOut>", self.foc_out) self.popup.bind("<FocusOut>", self.popupFocusOut) self.master.protocol("WM_DELETE_WINDOW", self.exitApp) self.loadTable(self) self.master.bind("<Escape>", self.exitApp)
def sendPasswdToEmail(): import sendEmail sendEmail.sendEmail() root = Tk() windowWidth = 720 windowHeight = 300 screenWidth = root.winfo_screenwidth() screenHeight = root.winfo_screenheight() positionRight = int(screenWidth / 2 - windowWidth / 2) positionDown = int(screenHeight / 3 - windowHeight / 2) root.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown)) img = PhotoImage(data=icons.getAppIcon()) root.wm_iconphoto(True, img) root.wait_visibility(root) root.wm_attributes('-alpha', 0.98) root.title('Cerberus - Εισαγωγή Κωδικού') welcomeFrame = Frame(root, height=130, bg='#1e1e2f') welcomeFrame.pack(side="top", fill=BOTH) appIcon = PhotoImage(data=icons.getLogoIcon()) panel = Label(root, image=appIcon, bg='#1e1e2f').place(x=20, y=20) Label(welcomeFrame, text="Καλώς ορίσατε στον", font=("Comic Sans MS", 32), fg='white', bg='#1e1e2f').place(x=110, y=20)
def editServiceForm(self, service): try: conn = sqlite3.connect('cerberus.db') except sqlite3.Error as e: print(e) def onDestory(event=NONE): master.destroy() self.master.deiconify() self.master.lift() self.master.focus_force() self.master.grab_set() mainForm.Cerberus.loadTable(self) def editService(event=NONE): if eCategory.get() != '': category = eCategory.get() else: category = '---' if eService.get() != '': service = eService.get() else: service = '---' if eServiceUrl.get() != '': serviceUrl = eServiceUrl.get() else: serviceUrl = '---' if eEmail.get() != '': email = eEmail.get() else: email = '---' if eUsername.get() != '': username = eUsername.get() else: username = '******' if ePassword.get() != '': password = ePassword.get() else: password = '******' if eValue.get() != '': value = eValue.get() else: value = '---' email = cipher_suite.encrypt(bytes(email, encoding="UTF-8")) username = cipher_suite.encrypt(bytes(username, encoding="UTF-8")) password = cipher_suite.encrypt(bytes(password, encoding="UTF-8")) value = cipher_suite.encrypt(bytes(value, encoding="UTF-8")) category = cipher_suite.encrypt(bytes(category, encoding="UTF-8")) serviceUrl = cipher_suite.encrypt(bytes(serviceUrl, encoding="UTF-8")) cursor = conn.cursor() cursor.execute( '''Update service set name=?, email=?, username=?, password=?, value=?, category=?, url=? where id=?''', (service, email, username, password, value, category, serviceUrl, id)) conn.commit() conn.close() onDestory() master = Toplevel() windowWidth = 385 windowHeight = 280 screenWidth = master.winfo_screenwidth() screenHeight = master.winfo_screenheight() positionRight = int(screenWidth / 2 - windowWidth / 2) positionDown = int(screenHeight / 3 - windowHeight / 2) master.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown)) master.lift() master.focus_force() master.grab_set() master.title('Cerberus - Επεξεργασία Υπηρεσίας: ' + service[0]) img = PhotoImage(data=icons.getAppIcon()) master.wm_iconphoto(True, img) master.resizable(0, 0) Label(master, text="Κατηγορία:").grid(row=0, sticky="W", padx=5, pady=5) Label(master, text="Υπηρεσία:").grid(row=1, sticky="W", padx=5, pady=5) Label(master, text="URL:").grid(row=2, sticky="W", padx=5, pady=5) Label(master, text="Email:").grid(row=3, sticky="W", padx=5, pady=5) Label(master, text="Username:"******"W", padx=5, pady=5) Label(master, text="Password:"******"W", padx=5, pady=5) Label(master, text="ID:").grid(row=6, sticky="W", padx=5, pady=5) id = service[-1] categories = categoriesList.getCategoriesList() eCategory = Combobox(master, width=33, values=categories) eCategory.insert(0, service[5]) eCategory.focus() eService = Entry(master, width=35) eService.insert(0, service[0]) eServiceUrl = Entry(master, width=35) eServiceUrl.insert(0, service[6]) eEmail = Entry(master, width=35) eEmail.insert(0, service[1]) eUsername = Entry(master, width=35) eUsername.insert(0, service[2]) ePassword = Entry(master, width=35) ePassword.insert(0, service[3]) eValue = Entry(master, width=35) eValue.insert(0, service[4]) eCategory.grid(row=0, column=1, pady=5, padx=5) eService.grid(row=1, column=1, pady=5, padx=5) eServiceUrl.grid(row=2, column=1, pady=5, padx=5) eEmail.grid(row=3, column=1, pady=5, padx=5) eUsername.grid(row=4, column=1, pady=5, padx=5) ePassword.grid(row=5, column=1, pady=5, padx=5) eValue.grid(row=6, column=1, pady=5, padx=5) enterButton = Button(master, text="Αποθήκευση", command=editService) enterButton.grid(row=7, column=0, columnspan=2, sticky="we", padx=5, pady=5) master.bind("<Escape>", onDestory) master.bind("<Return>", editService) master.protocol("WM_DELETE_WINDOW", onDestory)
def logIn(self): def check_password(failures=[1]): try: conn = sqlite3.connect('cerberus.db') except sqlite3.Error as e: print(e) cur = conn.cursor() cur.execute( "SELECT masterToken, salt FROM cerberusParameters") row = cur.fetchone() cur.close() salt = row[1] import cerberusCryptography cerberusCryptography.salt = salt cerberusCryptography.password = entry.get() password = cerberusCryptography.decrypt(row[0]) if entry.get() == password: failures.clear() print('Logged in') onDestroy() mainForm.Cerberus.exportToCSV() else: failures.append(1) if sum(failures) > 3: master.destroy() raise SystemExit('Unauthorized login attempt') else: entry.delete(0, 'end') master.title('Λάθος Κωδικός, παρακαλώ δοκιμάστε ξανά. Προσπάθεια %i/%i' % (sum(failures), 3)) def onDestroy(): master.destroy() self.master.deiconify() self.master.lift() self.master.focus_force() self.master.grab_set() master = Toplevel() windowWidth = 720 windowHeight = 280 screenWidth = master.winfo_screenwidth() screenHeight = master.winfo_screenheight() positionRight = int(screenWidth / 2 - windowWidth / 2) positionDown = int(screenHeight / 3 - windowHeight / 2) master.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown)) master.lift() master.focus_force() master.grab_set() img = PhotoImage(data=icons.getAppIcon()) master.wm_iconphoto(True, img) master.wait_visibility(master) master.wm_attributes('-alpha', 0.98) master.title('Cerberus - Εισαγωγή Κωδικού') welcomeFrame = Frame(master, height=125, bg='#1e1e2f') welcomeFrame.pack(side="top", fill=BOTH) appIcon = PhotoImage(data=icons.getLogoIcon()) panel = Label(master, image=appIcon, bg='#1e1e2f').place(x=20, y=20) Label(welcomeFrame, text="Καλώς ορίσατε στον", font=("Comic Sans MS", 32), fg='white', bg='#1e1e2f').place(x=110, y=20) Label(welcomeFrame, text="Cerberus", font=("Helvetica", 32), fg='#d9ddff', bg='#1e1e2f').place(x=380, y=72) parent = Frame(master, bg='lightgrey') parent.pack(side="top", fill=BOTH, expand=True) Label(parent, text="Παρακαλώ εισάγεται τον Κωδικό σας:", bg='lightgrey').pack(pady=(25, 0), side=TOP) entry = Entry(parent, show="*", width=40) entry.pack(side=TOP, pady=(0, 15)) enterIcon = PhotoImage(data=icons.getEnterIcon()) b = Button(parent, borderwidth=1, text="Είσοδος", image=enterIcon, compound=LEFT, pady=8, width=120, command=check_password) b.pack(pady="7") entry.focus_set() master.resizable(0, 0) entry.bind('<Return>', lambda x: check_password()) master.bind("<Escape>", lambda x: onDestroy()) master.mainloop()
def addNewServiceForm(self): try: conn = sqlite3.connect('cerberus.db') except sqlite3.Error as e: print(e) def onDestory(event=NONE): master.destroy() self.master.deiconify() self.master.lift() self.master.focus_force() self.master.grab_set() mainForm.Cerberus.loadTable(self) def insertNewService(event=NONE): key = cerberusCryptography.getMasterKey() cipher_suite = Fernet(key) if eCategory.get() != '': category = eCategory.get() else: category = '---' if eService.get() != '': name = eService.get() else: name = '---' if eServiceUrl.get() != '': serviceUrl = eServiceUrl.get() else: serviceUrl = '---' if eEmail.get() != '': email = eEmail.get() else: email = '---' if eUsername.get() != '': username = eUsername.get() else: username = '******' if ePassword.get() != '': password = ePassword.get() else: password = '******' if eValue.get() != '': value = eValue.get() else: value = '---' email = cipher_suite.encrypt(bytes(email, encoding="UTF-8")) username = cipher_suite.encrypt(bytes(username, encoding="UTF-8")) password = cipher_suite.encrypt(bytes(password, encoding="UTF-8")) value = cipher_suite.encrypt(bytes(value, encoding="UTF-8")) category = cipher_suite.encrypt(bytes(category, encoding="UTF-8")) serviceUrl = cipher_suite.encrypt(bytes(serviceUrl, encoding="UTF-8")) cursor = conn.cursor() try: cursor.execute('''INSERT INTO service(name, email, username, password, value, category, url) VALUES(?,?,?,?,?,?,?)''', (name, email, username, password, value, category, serviceUrl)) conn.commit() conn.close() onDestory() except sqlite3.IntegrityError as e: from tkinter import messagebox messagebox.showerror("Μήνυμα Σφάλματος", "Η Υπηρεσία υπάρχει ήδη.") master = Toplevel() windowWidth = 385 windowHeight = 280 screenWidth = master.winfo_screenwidth() screenHeight = master.winfo_screenheight() positionRight = int(screenWidth / 2 - windowWidth / 2) positionDown = int(screenHeight / 3 - windowHeight / 2) master.geometry("{}x{}+{}+{}".format(windowWidth, windowHeight, positionRight, positionDown)) master.lift() master.focus_force() master.grab_set() master.title('Cerberus - Εισαγωγή Νέας Υπηρεσίας') img = PhotoImage(data=icons.getAppIcon()) master.wm_iconphoto(True, img) master.resizable(0, 0) Label(master, text="Κατηγορία:").grid(row=0, sticky="W", padx=5, pady=5) Label(master, text="Υπηρεσία:").grid(row=1, sticky="W", padx=5, pady=5) Label(master, text="URL:").grid(row=2, sticky="W", padx=5, pady=5) Label(master, text="Email:").grid(row=3, sticky="W", padx=5, pady=5) Label(master, text="Username:"******"W", padx=5, pady=5) Label(master, text="Password:"******"W", padx=5, pady=5) Label(master, text="ID:").grid(row=6, sticky="W", padx=5, pady=5) categoryExamples = ["Προσωπικά Στοιχεία", "Κοινωνική Δικτύωση", "Email", "Banking"] categories = categoriesList.getCategoriesList() for cat in categories: if cat not in categoryExamples: categoryExamples.append(cat) eCategory = Combobox(master, width=33, values=categoryExamples) eCategory.focus() eService = Entry(master, width=35) eServiceUrl = Entry(master, width=35) eEmail = Entry(master, width=35) eUsername = Entry(master, width=35) ePassword = Entry(master, width=35) eValue = Entry(master, width=35) eCategory.grid(row=0, column=1, pady=5, padx=5) eService.grid(row=1, column=1, pady=5, padx=5) eServiceUrl.grid(row=2, column=1, pady=5, padx=5) eEmail.grid(row=3, column=1, pady=5, padx=5) eUsername.grid(row=4, column=1, pady=5, padx=5) ePassword.grid(row=5, column=1, pady=5, padx=5) eValue.grid(row=6, column=1, pady=5, padx=5) enterButton = Button(master, text="Εισαγωγή Στοιχείων", command=insertNewService) enterButton.grid(row=7, column=0, columnspan=2, sticky="we", padx=5, pady=5) master.bind("<Escape>", onDestory) master.bind("<Return>", insertNewService) master.protocol("WM_DELETE_WINDOW", onDestory)