if __name__ == '__main__': import sys if len(sys.argv) < 2: print 'usage: %s <root> <port>' % (sys.argv[0]) else: import monitor import filesys import default_handler import status_handler import ftp_server import chat_server import resolver import logger rs = resolver.caching_resolver ('127.0.0.1') lg = logger.file_logger (sys.stdout) ms = monitor.secure_monitor_server ('fnord', '127.0.0.1', 9999) fs = filesys.os_filesystem (sys.argv[1]) dh = default_handler.default_handler (fs) hs = http_server ('', string.atoi (sys.argv[2]), rs, lg) hs.install_handler (dh) ftp = ftp_server.ftp_server ( ftp_server.dummy_authorizer(sys.argv[1]), port=8021, resolver=rs, logger_object=lg ) cs = chat_server.chat_server ('', 7777) sh = status_handler.status_extension([hs,ms,ftp,cs,rs]) hs.install_handler (sh) if ('-p' in sys.argv): def profile_loop ():
if len(sys.argv) < 2: print "usage: %s <root> <port>" % (sys.argv[0]) else: import monitor import filesys import default_handler import status_handler import ftp_server import chat_server import resolver import logger rs = resolver.caching_resolver("127.0.0.1") lg = logger.file_logger(sys.stdout) ms = monitor.secure_monitor_server("fnord", "127.0.0.1", 9999) fs = filesys.os_filesystem(sys.argv[1]) dh = default_handler.default_handler(fs) hs = http_server("", string.atoi(sys.argv[2]), rs, lg) hs.install_handler(dh) ftp = ftp_server.ftp_server(ftp_server.dummy_authorizer(sys.argv[1]), port=8021, resolver=rs, logger_object=lg) cs = chat_server.chat_server("", 7777) sh = status_handler.status_extension([hs, ms, ftp, cs, rs]) hs.install_handler(sh) if "-p" in sys.argv: def profile_loop(): try: asyncore.loop() except KeyboardInterrupt: pass
## ), ## port=FTP_PORT, ## resolver=rs, ## logger_object=lg ## ) # =========================================================================== # Monitor Server: # =========================================================================== # This creates a secure monitor server, binding to the loopback # address on port 9999, with password 'fnord'. The monitor server # can be used to examine and control the server while it is running. # If you wish to access the server from another machine, you will # need to use '' or some other IP instead of '127.0.0.1'. ms = monitor.secure_monitor_server ('fnord', '127.0.0.1', MONITOR_PORT) # =========================================================================== # Status Handler # =========================================================================== # These are objects that can report their status via the HTTP server. # You may comment out any of these, or add more of your own. The only # requirement for a 'status-reporting' object is that it have a method # 'status' that will return a producer, which will generate an HTML # description of the status of the object. status_objects = [ hs, # ftp, ms,
# Make logger accessLog = logger.rotating_file_logger( pycs_paths.ACCESSLOG, None, 1024*1024 ) print "logging to",pycs_paths.ACCESSLOG logger = status_handler.logger_for_status( accessLog ) # Make web server hs = http_server.http_server( '', set.ServerPort(), None, logger ) hs.server_name = set.conf['serverhostname'] ms = None if set.conf.has_key( 'monitorport' ): port = int( set.conf['monitorport'] ) if set.conf.has_key( 'monitorpassword' ): pwd = set.conf['monitorpassword'] ms = monitor.secure_monitor_server( pwd, '', port ) else: ms = monitor.monitor_server( '', port ) # become the PyCS user if os.name == 'posix': try: # look in ~medusa/patches for {set,get}euid. import pwd [uid, gid] = pwd.getpwnam( set.conf['serveruser'] )[2:4] os.setegid (gid) os.seteuid (uid) except: import traceback traceback.print_exc() print "WARNING: Can't reduce privileges; server is running as the superuser"
## ), ## port=FTP_PORT, ## resolver=rs, ## logger_object=lg ## ) # =========================================================================== # Monitor Server: # =========================================================================== # This creates a secure monitor server, binding to the loopback # address on port 9999, with password 'fnord'. The monitor server # can be used to examine and control the server while it is running. # If you wish to access the server from another machine, you will # need to use '' or some other IP instead of '127.0.0.1'. ms = monitor.secure_monitor_server('fnord', '127.0.0.1', MONITOR_PORT) # =========================================================================== # Status Handler # =========================================================================== # These are objects that can report their status via the HTTP server. # You may comment out any of these, or add more of your own. The only # requirement for a 'status-reporting' object is that it have a method # 'status' that will return a producer, which will generate an HTML # description of the status of the object. status_objects = [ hs, # ftp, ms,