Exemplo n.º 1
0
def assemble_tree(tree, resource):
    for i in tree.keys():
        if type(tree[i]) == tuple:
            resource.putChild(i, tree[i][0])
            assemble_tree(tree[i][1], tree[i][0])
        else:
            resource.putChild(i, tree[i])
Exemplo n.º 2
0
 def create(self, service, project, config, observer):
     message_format = string.Template(config["message"])
     resource = service.get_resource_for_project(project)
     child = WebhookListener(
         project, observer, message_format, self.commit_extractor,
         config.get("max commit messages per push"))
     resource.putChild(self.name, child)
Exemplo n.º 3
0
 def create(self, service, project, config, observer):
     message_format = string.Template(config["message"])
     travis_token = config["token"]
     resource = service.get_resource_for_project(project)
     child = TravisCIWebhookListener(project, observer, message_format,
                                     travis_token)
     resource.putChild(self.name, child)
Exemplo n.º 4
0
 def __init__(self, service):
     Resource.__init__(self)
     self.service = service
 	resource = File('web')
 	resource.putChild("ajax", self)
 	factory = server.Site(resource)
 	service.reactor.listenTCP(8888, factory)
Exemplo n.º 5
0
 def __init_service(self):
     resource = Service(self.node_manager)
     resource.putChild('cluster', ClusterService(self.node_manager))
     resource.putChild('node', NodeService(self.node_manager))
     resource.putChild('spider_list', SpiderListService(self.node_manager))
     resource.putChild('crawl', CrawlService(self.node_manager))
     resource.putChild('crawl_status',
                       CrawlStatusService(self.node_manager))
     self.service = server.Site(resource)
 def run(self):
     """
     :param static_file_path: The dir you want to display all the files in it on the web page.
     :param port: Web server port.
     """
     resource = CustomiseFile(self.static_file_path)
     resource.putChild(
         STATIC_RESOURCE_PATH.split(os.sep)[-1],
         CustomiseFile(STATIC_RESOURCE_PATH))
     site = server.Site(resource)
     reactor.listenTCP(self.port, site)
     reactor.run()
Exemplo n.º 7
0
def _build_site():
    '''Lazy site initialization for site'''
    # Lazy is needed to prevent greedyness event-loop issues

    from twisted.application import internet, service
    from twisted.web.server import Site
    from twisted.web.static import File
    from twisted.web.wsgi import WSGIResource
    from app import app
    resource = Root(app)
    resource.putChild('static', File('static'))
    site = Site(resource)
    return site
Exemplo n.º 8
0
Arquivo: JAP.py Projeto: web883/jap
def createSite(configuration):
    resource = static.File("./WWW")
    resource.putChild("API", API())

    if configuration["LOCAL_SERVER"]["AUTHENTICATION"]["USERNAME"] != "":
        realm = HTTPRealm(resource)

        checkers = [HTTPUsernamePasswordCredentialsChecker(configuration)]

        credentialFactories = [guard.BasicCredentialFactory("JAP")]

        resource = guard.HTTPAuthSessionWrapper(portal.Portal(realm, checkers),
                                                credentialFactories)

    site = server.Site(resource)

    return site
Exemplo n.º 9
0
def createSite(configuration):
    resource = static.File("./WWW")
    resource.putChild("API", API())
    
    if configuration["LOCAL_SERVER"]["AUTHENTICATION"]["USERNAME"] != "":
        realm = HTTPRealm(resource)
        
        checkers = [
            HTTPUsernamePasswordCredentialsChecker(configuration)
        ]
        
        credentialFactories = [
            guard.BasicCredentialFactory("JAP")
        ]
        
        resource = guard.HTTPAuthSessionWrapper(portal.Portal(realm, checkers), credentialFactories)
    
    site = server.Site(resource)
    
    return site
Exemplo n.º 10
0
    def enable(self):
        self.config = deluge.configmanager.ConfigManager("streaming.conf", DEFAULT_PREFS)

        try:
            session = component.get("Core").session
            settings = session.get_settings()
            settings['prioritize_partial_pieces'] = True
            session.set_settings(settings)
        except AttributeError:
            logger.warning('Unable to exclude partial pieces')

        self.fsr = FileServeResource()
        resource = Resource()
        resource.putChild('file', self.fsr)
        if self.config['allow_remote']:
            resource.putChild('stream', StreamResource(username=self.config['remote_username'],
                                                       password=self.config['remote_password'],
                                                       client=self))

        base_resource = Resource()
        base_resource.putChild('streaming', resource)
        self.site = server.Site(base_resource)

        self.torrent_handler = TorrentHandler(self.config)

        plugin_manager = component.get("CorePluginManager")
        logger.warning('plugins %s' % (plugin_manager.get_enabled_plugins(), ))

        self.base_url = 'http'
        if self.config['serve_method'] == 'standalone':
            if self.config['use_ssl'] and self.check_ssl():  # use default deluge (or webui), input custom
                if self.config['ssl_source'] == 'daemon':
                    web_config = configmanager.ConfigManager("web.conf", {"pkey": "ssl/daemon.pkey",
                                                                          "cert": "ssl/daemon.cert"})

                    context = ServerContextFactory(configmanager.get_config_dir(web_config['cert']),
                                                   configmanager.get_config_dir(web_config['pkey']))
                elif self.config['ssl_source'] == 'custom':
                    context = ServerContextFactory(self.config['ssl_cert_path'],
                                                   self.config['ssl_priv_key_path'])

                try:
                    self.listening = reactor.listenSSL(self.config['port'], self.site, context, interface=self.config['ip'])
                except:
                    self.listening = reactor.listenSSL(self.config['port'], self.site, context, interface='0.0.0.0')
                self.base_url += 's'
            else:
                try:
                    self.listening = reactor.listenTCP(self.config['port'], self.site, interface=self.config['ip'])
                except:
                    self.listening = reactor.listenTCP(self.config['port'], self.site, interface='0.0.0.0')

            port = self.config['port']
            ip = self.config['ip']
        elif self.config['serve_method'] == 'webui' and self.check_webui():  # this webserver is fubar
            plugin_manager = component.get("CorePluginManager")

            webui_plugin = plugin_manager['WebUi'].plugin
            webui_plugin.server.top_level.putChild('streaming', resource)

            port = webui_plugin.server.port
            ip = getattr(webui_plugin.server, 'interface', None) or self.config['ip']
            if webui_plugin.server.https:
                self.base_url += 's'
        else:
            raise NotImplementedError()

        self.base_url += '://'
        if ':' in ip:
            self.base_url += ip
        else:
            self.base_url += '%s:%s' % (ip, port)
Exemplo n.º 11
0
class ResponseResource(resource.Resource):
    isLeaf = True

    def __init__(self, collector):
        self.collector = collector

    def render_GET(self, request):
        if len(request.postpath) == 0:
            return respond(request, {})
        else:
            name = '/'.join(request.postpath)
            data = self.collector.responses.get(name, [])
            return respond(request, {'name': name, 'responses': data})

collector = Collector()
udpCollector = UDPCollector(collector)
tcpCollector = TCPCollectorFactory(collector)

resource = StatsTimeSeriesResource()
resource.putChild('responses', ResponseResource(collector))

root = static.File(settings.STATIC_DIR)
root.putChild('statsny', resource)

application = service.Application("Statsny")
site = server.Site(root)
internet.TCPServer(settings.HTTP_PORT, site, interface=settings.HTTP_INTERFACE).setServiceParent(application)
internet.TCPServer(settings.TCP_PORT, tcpCollector, interface=settings.TCP_INTERFACE).setServiceParent(application)
internet.UDPServer(settings.UDP_PORT, udpCollector, interface=settings.UDP_INTERFACE).setServiceParent(application)
Exemplo n.º 12
0
#!/usr/bin/env python2.7

""" Controls, configures, and monitors pet feeders.

An application that receives connection requests from the PiFeed control
or PiFeed feeders and sends an image retrieved from the Raspberry Pi
camera to the Twisted web server.
"""

__author__ = 'Danny Duangphachanh, Igor Janjic, Daniel Friedman'

from twisted.web import server, resource
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.static import File

resource = File('/home/pi/PiFeed/src/')
resource.putChild('', resource)
factory = Site(resource)
reactor.listenTCP(8000, factory)
reactor.run()