Ejemplo n.º 1
0
 def sendNewLocation(self, location):
     response = '<h1>301 Moved Permanently</h1>'
     return 'HTTP/1.1 %s\r\n' % (movedPerm) + \
             'Date: %s\r\n' % (TimeHandler().getGMTime()) + \
             'Server: kHTTPd Mini Build %i\r\n' % (httpConstants().getBuild()) + \
             'Content-Type: text/html\r\n' + \
             'Content-Length: %i\r\n' % (len(response)) + \
             'Location: %s\r\n\r\n' % (location) + response
Ejemplo n.º 2
0
class httpFactory(protocol.Factory):
    protocol = httpHandler
    ### Loading settings from configuration file ###
    port = conf.getPort()
    docuroot = conf.getDocRoot()
    debug = conf.getDebug()
    index = conf.getIndexFile()
    phpenabled = conf.getPhpEnabled()
    phpexec = conf.getPhpExec()
    errorpage = httpConstants().getNotFoundPage()
    reqHandler = handleRequest(docuroot, index, errorpage, phpenabled, phpexec)
    if debug is True:
        log.output('kHTTPd Mini is starting in debug mode.')
        debuglog = LogDebug(log, index)
Ejemplo n.º 3
0
 def output(self, data):
     out = '['+ TimeHandler().getLocalTime() +'] '+ data
     print out
     with open(httpConstants().getLog(), 'a') as logfile:
         logfile.write(out + '\n')
Ejemplo n.º 4
0
 def output(self, data):
     out = '[' + TimeHandler().getLocalTime() + '] ' + data
     print out
     with open(httpConstants().getLog(), 'a') as logfile:
         logfile.write(out + '\n')
Ejemplo n.º 5
0
    def connectionMade(self):
        log.output('Connection made from '+ self.transport.getPeer().host + '.')
        
    def connectionLost(self, reason):
        log.output('Connection from '+ self.transport.getPeer().host +' lost.')
    
    def dataReceived(self, data):
        if httpFactory.debug is True:
            httpFactory.debuglog.output(data, self.transport.getPeer().host)
            self.transport.write(httpFactory.reqHandler.handle(data, self.transport.getPeer().host))
        else:
            self.transport.write(httpFactory.reqHandler.handle(data, self.transport.getPeer().host))
            
class httpFactory(protocol.Factory):
    protocol = httpHandler
    ### Loading settings from configuration file ###
    port = conf.getPort()
    docuroot = conf.getDocRoot()
    debug = conf.getDebug()
    index = conf.getIndexFile()
    phpenabled = conf.getPhpEnabled()
    phpexec = conf.getPhpExec()
    errorpage = httpConstants().getNotFoundPage()
    reqHandler = handleRequest(docuroot, index, errorpage, phpenabled, phpexec)
    if debug is True:
        log.output('kHTTPd Mini is starting in debug mode.')
        debuglog = LogDebug(log, index)

log.output('kHTTPd Mini Build '+ str(httpConstants().getBuild()) +' has started on port '+ str(httpFactory.port) + '.')
reactor.listenTCP(httpFactory.port, httpFactory())
reactor.run()    
Ejemplo n.º 6
0
 def phpCreate(self, code, headers, data):
     return 'HTTP/1.1 %s\r\n' % (code) + \
             'Date: %s\r\n' % (TimeHandler().getGMTime()) + \
             'Server: kHTTPd Mini Build %i\r\n' % (httpConstants().getBuild()) + \
             '%s\r\n' % (headers) + \
             'Content-Length: %i\r\n\r\n' % (len(data)) + data
Ejemplo n.º 7
0
 def create(self, code, mimetype, data):
     return 'HTTP/1.1 %s\r\n' % (code) + \
             'Date: %s\r\n' % (TimeHandler().getGMTime()) + \
             'Server: kHTTPd Mini Build %i\r\n' % (httpConstants().getBuild()) + \
             'Content-Type: %s\r\n' % (mimetype) + \
             'Content-Length: %i\r\n\r\n' % (len(data)) + data