-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More advanced GUI - Auth for password protected sites
New GUI Allows for browsable files, and asks the user for the authentication details if a password is required on a site. The results get outputted into a scrollable and selectable list. They are also saved to a text file (error_results.txt)
- Loading branch information
Showing
4 changed files
with
158 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Python files | ||
__pycache__ | ||
*.pyc | ||
*.xml | ||
|
||
# Application files | ||
error_results.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,107 @@ | ||
import linker | ||
import tkinter as tk | ||
from tkinter import filedialog, ttk | ||
|
||
class Application(tk.Frame): | ||
class AuthDialog(): | ||
auth = () | ||
def __init__(self, parent): | ||
self.win = tk.Toplevel(parent) | ||
self.win.wm_title("Authentication Required") | ||
|
||
self.u = tk.Label(self.win, text="Username") | ||
self.u.grid(row=0, column=0) | ||
|
||
self.auth_user = tk.Entry(self.win) | ||
self.auth_user.grid(row=0, column=1) | ||
|
||
self.p = tk.Label(self.win, text="Password") | ||
self.p.grid(row=1, column=0) | ||
|
||
self.auth_pass = tk.Entry(self.win) | ||
self.auth_pass.grid(row=1, column=1) | ||
|
||
self.b = ttk.Button(self.win, text="Enter", command=self.return_auth) | ||
self.b.grid(row=1, column=0) | ||
|
||
def return_auth(self): | ||
print("clicked") | ||
self.auth = self.auth_user.get(), self.auth_pass.get() | ||
self.win.destroy() | ||
|
||
|
||
class LinkerGUI(tk.Frame): | ||
PAD_X = 25 | ||
PAD_Y = 25 | ||
user = '' | ||
pswd = '' | ||
|
||
def __init__(self, master=None): | ||
tk.Frame.__init__(self, master) | ||
self.grid() | ||
self.createWidgets() | ||
|
||
def get_broken_links(self): | ||
self.results.delete(0,tk.END) | ||
filename = self.file_input.get() | ||
if filename != "": | ||
errors = linker.check_links(filename) | ||
if errors == 401: | ||
print("Auth required") | ||
popup = AuthDialog(self) | ||
self.wait_window(popup.win) | ||
auth = popup.auth | ||
|
||
print(auth) | ||
errors = linker.check_links(filename, auth) | ||
|
||
for url, error, location in errors: | ||
self.results.insert(tk.END, "===== BROKEN LINK DETECTED ======") | ||
self.results.insert(tk.END, "Broken Link path: ", url) | ||
self.results.insert(tk.END, "Error Code: ", error) | ||
self.results.insert(tk.END, "Location of broken URL: ",location) | ||
self.results.insert(tk.END, "================================") | ||
self.results.insert(tk.END, " ") | ||
|
||
else: | ||
print("No file specified!") | ||
|
||
def browse_file(self): | ||
self.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("XML Files","*.xml"),("all files","*.*"))) | ||
self.file_input.insert(0, self.filename) | ||
|
||
def createWidgets(self): | ||
self.filename = tk.Label(self,text="Filename") | ||
self.filename.grid(row=0) | ||
# Set title of window | ||
self.winfo_toplevel().title("Linker") | ||
|
||
self.filename_label = tk.Label(self,text="Filename") | ||
self.filename_label.grid(row=0) | ||
|
||
self.file_input = tk.Entry(self) | ||
self.file_input.grid(row=0, column=1) | ||
|
||
self.results = tk.Listbox(self) | ||
self.results.config(width=70) | ||
self.results.grid(row=1, column=0, columnspan=3) | ||
|
||
# ====== Buttons ====== # | ||
# Browse | ||
self.browse = tk.Button(self) | ||
self.browse["text"] = "Browse..." | ||
self.browse["command"] = self.browse_file | ||
self.browse.grid(row=0, column=2) | ||
|
||
# Quit | ||
self.QUIT = tk.Button(self, text="QUIT", fg="red", command=self.quit) | ||
self.QUIT.grid(row=3, column=0) | ||
|
||
# Enter | ||
self.enter = tk.Button(self) | ||
self.enter["text"] = "Enter" | ||
self.enter["command"] = lambda: linker.check_links(self.file_input.get()) | ||
self.enter.grid(row=1, column=0) | ||
self.enter["command"] = self.get_broken_links | ||
self.enter.grid(row=3, column=2) | ||
|
||
self.QUIT = tk.Button(self, text="QUIT", fg="red", | ||
command=self.quit) | ||
self.QUIT.grid(row=1, column=1) | ||
|
||
def run(): | ||
root = tk.Tk() | ||
app = Application(master=root) | ||
app = LinkerGUI(master=root) | ||
app.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import linker, gui | ||
import gui | ||
|
||
gui.run() | ||
linker.run() | ||
gui.run() |