mirror of https://github.com/sloumdrone/burrow
commit
3615d47282
12
connect.py
12
connect.py
|
@ -8,6 +8,7 @@ class connect:
|
|||
def request(self, resource, host, itemtype, port=70):
|
||||
#connects to server and returns list with response type and body
|
||||
socket_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
socket_conn.settimeout(5.0)
|
||||
|
||||
try:
|
||||
socket_conn.connect((host, port))
|
||||
|
@ -17,15 +18,20 @@ class connect:
|
|||
response = socket_conn.makefile(mode = 'rb', errors = 'ignore')
|
||||
else:
|
||||
response = socket_conn.makefile(mode = 'r', errors = 'ignore')
|
||||
except:
|
||||
except socket.timeout:
|
||||
print('Socket timeout')
|
||||
socket_conn.close()
|
||||
return False
|
||||
return {'type': '3', 'body': '3ERROR: Server request timed out\tfalse\tnull.host\t1'}
|
||||
except Exception as e:
|
||||
print('Misc socket error: ', e)
|
||||
socket_conn.close()
|
||||
return {'type': '3', 'body': '3ERROR: Unable to communicate with remote server\tfalse\tnull.host\t1'}
|
||||
|
||||
try:
|
||||
self.raw_response = response.read()
|
||||
self.filetype = itemtype
|
||||
except UnicodeDecodeError:
|
||||
self.raw_response = '3Error decoding server response\tfalse\tnull.host\t1'
|
||||
self.raw_response = '3ERROR: Unable to decode server response\tfalse\tnull.host\t1'
|
||||
self.filetype = '3'
|
||||
|
||||
socket_conn.close()
|
||||
|
|
30
gui.py
30
gui.py
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import tkinter as tk
|
||||
import tkinter.simpledialog as dialog
|
||||
from connect import connect as conn
|
||||
from parser import parser
|
||||
import time
|
||||
|
@ -102,6 +103,7 @@ class GUI:
|
|||
self.site_display.bind("<Button-1>", lambda event: self.site_display.focus_set())
|
||||
self.entry_url.bind("<Button-1>", lambda event: self.entry_url.focus_set())
|
||||
self.root.protocol('WM_DELETE_WINDOW', self.close_window)
|
||||
self.btn_favorite.bind("<Button-1>", self.add_to_favorites)
|
||||
|
||||
|
||||
def pack_geometry(self):
|
||||
|
@ -220,6 +222,7 @@ class GUI:
|
|||
self.entry_url.insert(tk.END, 'home')
|
||||
if event:
|
||||
self.add_to_history('home')
|
||||
data += self.load_favorites()
|
||||
self.send_to_screen(data, '1')
|
||||
|
||||
|
||||
|
@ -241,13 +244,31 @@ class GUI:
|
|||
self.handle_request(False, href, False)
|
||||
|
||||
|
||||
def add_to_favorites(self, event):
|
||||
favorite_name = dialog.askstring("Add to favorites", "What would you like to title this favorite?")
|
||||
url = self.entry_url.get()
|
||||
if not favorite_name or not url:
|
||||
return False
|
||||
favorite = {"url": url, "name": favorite_name}
|
||||
self.config["favorites"].append(favorite)
|
||||
self.write_config(self.config)
|
||||
|
||||
|
||||
|
||||
#-------------Start view methods----------------
|
||||
|
||||
|
||||
def load_favorites(self):
|
||||
header = 'i#############\tfalse\tnull.host\t1\r\ni manually edit in go.config.json\tfalse\tnull.host\t1\r\n or add using the favorites button\tfalse\tnull.host\t1\r\ni\tfalse\tnull.host\t1\r\n'
|
||||
header = ''
|
||||
#soon add code to load in favorites here
|
||||
self.send_to_screen(data=header, clear=False)
|
||||
for x in self.config["favorites"]:
|
||||
url = self.parser.parse_url(x["url"])
|
||||
if not url:
|
||||
continue
|
||||
entry = '{}{}\t{}\t{}\t{}\n'.format(url['type'], x['name'], url['resource'], url['host'], url['port'])
|
||||
header += entry
|
||||
return header
|
||||
# self.send_to_screen(data=header, clear=False)
|
||||
|
||||
def show_search(self):
|
||||
text1 = ' __ ___ __ __\n/__` |__ /\ |__) / ` |__|\n.__/ |___ /~~\ | \ \__, | |\n\n\nPlease enter your search terms and press the enter key:\n\n'
|
||||
|
@ -303,7 +324,6 @@ class GUI:
|
|||
elif x['type'] == '3':
|
||||
self.site_display.insert(tk.END,' \t\t{}\n'.format(x['description']))
|
||||
elif x['type'] in types:
|
||||
|
||||
# adapted from:
|
||||
# https://stackoverflow.com/questions/27760561/tkinter-and-hyperlinks
|
||||
if x['port'] and x['port'][0] != ':':
|
||||
|
@ -334,9 +354,11 @@ class GUI:
|
|||
|
||||
|
||||
def show_text(self, data):
|
||||
if data[-2:] == '\n.':
|
||||
data = data[:-2]
|
||||
self.site_display.config(state=tk.NORMAL)
|
||||
self.site_display.delete(1.0, tk.END)
|
||||
self.site_display.insert(tk.END, data[:-2])
|
||||
self.site_display.insert(tk.END, data)
|
||||
self.site_display.config(state=tk.DISABLED)
|
||||
|
||||
|
||||
|
|
16
parser.py
16
parser.py
|
@ -15,6 +15,8 @@ class parser:
|
|||
|
||||
def parse_url(self, url):
|
||||
# Take in a URL and output a dict of the url parts
|
||||
if url == 'home':
|
||||
return False
|
||||
|
||||
regex = r'^(?P<protocol>(?:(gopher|http):\/\/)?)?(?P<host>[\w\.\d]+)(?P<port>(?::\d+)?)?(?P<type>(?:\/[\dgIp])?)?(?P<resource>(?:\/.*)?)?$'
|
||||
|
||||
|
@ -23,13 +25,13 @@ class parser:
|
|||
if not match:
|
||||
return False
|
||||
|
||||
protocol = match.group('protocol')
|
||||
itemtype = match.group('type')
|
||||
host = match.group('host')
|
||||
port = match.group('port')
|
||||
resource = match.group('resource')
|
||||
|
||||
if not host:
|
||||
try:
|
||||
protocol = match.group('protocol')
|
||||
itemtype = match.group('type')
|
||||
host = match.group('host')
|
||||
port = match.group('port')
|
||||
resource = match.group('resource')
|
||||
except:
|
||||
return False
|
||||
|
||||
if not resource:
|
||||
|
|
Loading…
Reference in New Issue