Exemplo n.º 1
0
def makeService(config):
    if config['logfile']:
        logObserver = log.FileAccessLoggingObserver(config['logfile'])
    else:
        logObserver = log.DefaultCommonAccessLoggingObserver()

    if config['root']:
        if config['indexes']:
            config['root'].indexNames = config['indexes']

        root = log.LogWrapperResource(config['root'])

    s = Web2Service(logObserver)

    site = server.Site(root)
    chan = channel.HTTPFactory(site)

    if config['https']:
        from twisted.internet.ssl import DefaultOpenSSLContextFactory
        i = internet.SSLServer(
            int(config['https']), chan,
            DefaultOpenSSLContextFactory(config['privkey'],
                                         config['certificate']))
        i.setServiceParent(s)

    strports.service(config['port'], chan).setServiceParent(s)

    return s
Exemplo n.º 2
0
    def setUp(self):
        self.blo = BufferingLogObserver()
        tlog.addObserver(self.blo.emit)

        # some default resource setup
        self.resrc = BaseTestResource()
        self.resrc.child_emptystream = NoneStreamResource()

        self.root = SetDateWrapperResource(log.LogWrapperResource(self.resrc))
Exemplo n.º 3
0
def run(engine):
    "Gateway´s Runloop"
    config = engine.config

    #os.environ['DJANGO_SETTINGS_MODULE'] = 'pyisis.web.settings'
    # needed to use django templates
    if config.HTTP_PORT:
        from twisted.web2 import server, vhost, channel
        from twisted.web2 import wsgi, log
        from django.core.handlers.wsgi import WSGIHandler
        from django.core.servers.basehttp import AdminMediaHandler
        from django.conf import settings

        settings.configure(
            DEBUG=True,
            TEMPLATE_DEBUG=config.HTML_DEBUG,
            DEFAULT_CHARSET=config.OUTPUT_ENCODING,
            DEFAULT_CONTENT_TYPE='text/html',
            ROOT_URLCONF='pyisis.web.urls',
            INSTALLED_APPS=(
                #'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.sites',
                #'django.contrib.admin',
                'pyisis.web.isis'),
            MIDDLEWARE_CLASSES=(
                'django.middleware.common.CommonMiddleware',
                'django.contrib.sessions.middleware.SessionMiddleware',
                'django.contrib.auth.middleware.AuthenticationMiddleware',
                'django.middleware.doc.XViewMiddleware',
            ),
            TEMPLATE_LOADERS=(
                'django.template.loaders.filesystem.load_template_source',
                'django.template.loaders.app_directories.load_template_source',
            ),
            SECRET_KEY='b(+ukc38349u0reu_8j)@iwpm017e(c#=0nmdn%s2u=$+*t@vo',
            MEDIA_URL='',
            MEDIA_ROOT=config.MEDIA_ROOT,
            USE_I18N=False,
            LANGUAGE_CODE='en-us',
            SITE_ID=1,
            TIME_ZONE='America/Sao_Paulo',
            TEMPLATE_CONTEXT_PROCESSORS=(
                "django.core.context_processors.debug",
                #"django.core.context_processors.i18n",
                "django.core.context_processors.media",
            ),
            TEMPLATE_DIRS=config.HTML_TEMPLATE_DIRS)

        # Glue code to plug Django into Twisted
        wsgires = wsgi.WSGIResource(AdminMediaHandler(WSGIHandler()))
        res = log.LogWrapperResource(wsgires)
        log.FileAccessLoggingObserver(config.WEB_LOG).start()
        site = server.Site(res)

        reactor.listenTCP(config.HTTP_PORT, channel.HTTPFactory(site))

    if config.SSH_PORT:
        from twisted.cred import portal, checkers
        from twisted.conch import manhole, manhole_ssh

        def getManholeFactory(namespace):
            realm = manhole_ssh.TerminalRealm()

            def getManhole(_):
                return manhole.Manhole(namespace)

            realm.chainedProtocolFactory.protocolFactory = getManhole
            p = portal.Portal(realm)
            checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
            checker.addUser(config.USERNAME, config.PASSWORD)
            p.registerChecker(checker)
            f = manhole_ssh.ConchFactory(p)
            return f

        reactor.listenTCP(config.SSH_PORT,
                          getManholeFactory(engine.collection))

    def showBanner(config):
        print "PyISIS Cell", __version__
        print "Python", sys.version
        if config.HTTP_PORT:
            print _("Gateway ready to handle HTTP requests at port %s"
                    ) % config.HTTP_PORT
        if config.SSH_PORT:
            print _("Gateway ready to handle SSH requests at port %s"
                    ) % config.SSH_PORT

    reactor.callWhenRunning(showBanner, config)
    reactor.run()
Exemplo n.º 4
0
######## Demonstrate a bunch of different deployment options ########
### You likely only want one of these for your app.


# This part gets run when you run this file via: "twistd -noy demo.py"
if __name__ == '__builtin__':
    from twisted.application import service, strports
    from twisted.web2 import server, vhost, channel
    from twisted.python import util

    # Create the resource we will be serving
    test = Toplevel()

    # Setup default common access logging
    res = log.LogWrapperResource(test)
    log.DefaultCommonAccessLoggingObserver().start()

    # Create the site and application objects
    site = server.Site(res)
    application = service.Application("demo")

    # Serve it via standard HTTP on port 8080
    s = strports.service('tcp:8080', channel.HTTPFactory(site))
    s.setServiceParent(application)

    # Serve it via HTTPs on port 8081
    certPath = util.sibpath(__file__, os.path.join("..", "..", "core", "examples", "server.pem"))
    s = strports.service('ssl:8081:privateKey=%s' % certPath, channel.HTTPFactory(site))
    s.setServiceParent(application)
Exemplo n.º 5
0
                        request.headers.getHeader("user-agent", "-"),
                        request.headers.getHeader("referer", "-"),
                    )
                )


# This part gets run when you run this file via: "twistd -noy demo.py"
if __name__ == "__builtin__":
    from twisted.application import service, strports
    from twisted.web2 import server, vhost
    from twisted.web2 import channel

    __port = os.getenv("ENV_WWW_PORT", "8000")

    choose_site = ArbitrarySettingsDecide()
    res = log.LogWrapperResource(choose_site)
    AccessLoggingObserver().start(LOG_STYLE)

    # Create the site and application objects
    site = server.Site(res)
    application = service.Application("test:%s" % __port)

    ##################################################
    # HTTP FastCGI, Serve it via standard HTTP on port 1026
    #s = strports.service("tcp:%s" % __port, channel.FastCGIFactory(site))
    #s.setServiceParent(application)

    # HTTPs, Serve it via standard HTTP on port 8081
    if not SSL_PRIVATE_KEY_PATH:
        # HTTP, Serve it via standard HTTP on port 8000
        s = strports.service("tcp:%s" % __port, channel.HTTPFactory(site))