Egress-Assess/protocols/servers/http_server.py

40 lines
1.1 KiB
Python

'''
This is the code for the web server
'''
import socket
import sys
from protocols.servers.serverlibs import base_handler
from protocols.servers.serverlibs import threaded_http
from threading import Thread
class Server:
def __init__(self, cli_object):
self.protocol = "http"
def serve(self):
try:
print "[*] Starting web (http) server..."
# bind to all interfaces
Thread(target=self.serve_on_port).start()
print "[*] Web server is currently running"
print "[*] Type \"killall -9 python\" to stop the web server."
# handle keyboard interrupts
except KeyboardInterrupt:
print "[!] Rage quiting, and stopping the web server!"
def serve_on_port(self):
try:
server80 = threaded_http.ThreadingHTTPServer(
("0.0.0.0", 80), base_handler.GetHandler)
server80.serve_forever()
except socket.error:
print "[*][*] Error: Port 80 is currently in use!"
print "[*][*] Error: Please restart when port is free!\n"
sys.exit()
return