Initial commit
This commit is contained in:
15
index.html
Normal file
15
index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>TextProxy</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>TextProxy</h1>
|
||||||
|
<form action="proxy.cgi" method="post">
|
||||||
|
<label for="u">Site: </label>
|
||||||
|
<input id="u" type="url" autofocus required>
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
39
proxy.cgi
Executable file
39
proxy.cgi
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import cgi
|
||||||
|
import cgitb
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
cgitb.enable()
|
||||||
|
|
||||||
|
def fetch_site(url):
|
||||||
|
data = subprocess.check_output(['w3m', '-dump', url])
|
||||||
|
return output.decode()
|
||||||
|
|
||||||
|
def format_output(url, data):
|
||||||
|
with open('template.html', 'r') as f:
|
||||||
|
template = f.read()
|
||||||
|
|
||||||
|
return template.format(url, data)
|
||||||
|
|
||||||
|
def print_headers():
|
||||||
|
print('Content-Type: text/html; charset=utf8')
|
||||||
|
print()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
form = cgi.FieldStorage()
|
||||||
|
|
||||||
|
if 'u' not in form or len(form['u']) == 0:
|
||||||
|
print('Status: 400 Bad Request')
|
||||||
|
print()
|
||||||
|
print('Missing required field')
|
||||||
|
print()
|
||||||
|
return
|
||||||
|
|
||||||
|
url = form['u']
|
||||||
|
data = fetch_site(url)
|
||||||
|
|
||||||
|
print(format_output(url, data))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
9
template.html
Normal file
9
template.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{} - TextProxy</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<pre>{}</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user