Created
May 30, 2011 19:10
-
-
Save kennydude/999337 to your computer and use it in GitHub Desktop.
FailProxy
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
''' | |
FailProxy | |
created by @kennydude | |
You need a failproxy.txt in the same directory as this script. | |
Then launch, configure your browser to connect here. | |
Now put something in failproxy.txt, save and reload. | |
Whoops! You just cut off access, remove contents of that file to restore access | |
''' | |
FAIL_PAGE = ''' | |
<html> | |
<head><title>FailProxy</title></head> | |
<body><h1>FailProxy</h1><p>The FailProxy has been told to stop this!</p> | |
<p>Re-enable access by editing failproxy.txt to equal blank</p> | |
</body> | |
</html> | |
''' | |
print "FAILSERVER STARTING" | |
import SimpleHTTPServer | |
import SocketServer, urllib | |
PORT = 8001 | |
class FailHandler( SimpleHTTPServer.SimpleHTTPRequestHandler ): | |
def req(self): | |
f_lock = open("failproxy.txt", "r") | |
f = f_lock.read() | |
f_lock.close() | |
if(f == ""): | |
# proxy page | |
self.copyfile(urllib.urlopen(self.path), self.wfile) | |
else: | |
self.send_response(503, "FAILSERVER") | |
self.send_header("Content-type", "text/html") | |
self.end_headers() | |
self.wfile.write(FAIL_PAGE) | |
def do_GET(self): | |
self.req() | |
def do_POST(self): | |
self.req() | |
Handler = FailHandler | |
httpd = SocketServer.ForkingTCPServer(("", PORT), Handler) | |
print "serving at port", PORT | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
print "finish" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment