#!/usr/bin/python

# cgiserver.py
#   A simple cgi-capable HTTP server using the HTTPServer module
#      provided by the Python library.

# The default port is 2080
#    CGI programs must be in a directory called either cgi-bin or ht-bin

import sys, os, socket, BaseHTTPServer, CGIHTTPServer

PORT = 2080

def start_server(port):
    server_address = (socket.gethostname(), port)
    httpd = BaseHTTPServer.HTTPServer(server_address,
                                      CGIHTTPServer.CGIHTTPRequestHandler)
    print "Serving HTTP on port", port, "..."
    httpd.serve_forever()

if __name__ == "__main__":
    if len(sys.argv) > 1:
        port = int(sys.argv[1])
    else:
        port = PORT
    start_server(port)
    
