Example #1
0
            try:
                import crossbarmanual
                root.putChild(
                    "manual",
                    File(
                        pkg_resources.resource_filename(
                            "crossbarmanual", "web")))
            except ImportError, e:
                log.msg("Crossbar.io Manual not installed [%s]" % e)
            else:
                log.msg("Found Crossbar.io Manual package v%s" %
                        crossbarmanual.__version__)

        ## REST interface to get config values
        ##
        addPortConfigResource(self.services["config"], root, "config")

        ## API Documentation
        ##
        root.putChild("apidoc", ApiHelpResource())

        ## Database Export
        ##
        dbexp = File(str(self.services["config"].get("export-dir")))
        root.putChild(str(self.services["config"].get("export-url")), dbexp)

        ## Database Import
        ##
        dbimp = UploadDatabaseDump(
            str(self.services["config"].get("import-dir")))
        root.putChild(str(self.services["config"].get("import-url")), dbimp)
Example #2
0
   def startService(self):
      log.msg("Starting %s service ..." % self.SERVICENAME)

      issecure = self.services["config"]["hub-websocket-tls"]
      port = self.services["config"]["hub-websocket-port"]
      acceptqueue = self.services["config"]["ws-accept-queue-size"]

      if issecure:
         contextFactory = TlsContextFactory(self.services["config"]["hub-websocket-tlskey-pem"],
                                            self.services["config"]["hub-websocket-tlscert-pem"],
                                            dhParamFilename = self.services['master'].dhParamFilename)

         uri = "wss://localhost:%d" % port
      else:
         contextFactory = None

         uri = "ws://localhost:%d" % port

      self.wsfactory = HubWebSocketFactory(uri, self.dbpool, self.services)
      #self.wsfactory.trackTimings = True

      self.enableAppWeb = self.services["config"]["service-enable-appweb"]

      if self.enableAppWeb:
         ## FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
         self.wsfactory.startFactory()
         resource = WebSocketResource(self.wsfactory)
         appwebDir = self.services["master"].webdata
         root = File(appwebDir)
         root.putChild(self.services["config"]["ws-websocket-path"], resource)

         ## CGI
         ##
         cgienable = self.services["config"]["appweb-cgi-enable"]
         cgipath = self.services["config"]["appweb-cgi-path"]
         cgiprocessor = self.services["config"]["appweb-cgi-processor"]
         if cgienable and cgipath is not None and cgipath.strip() != "" and cgiprocessor is not None and cgiprocessor.strip() != "":
            cgipath = cgipath.strip()
            cgidir = os.path.join(appwebDir, cgipath)
            cgiprocessor = cgiprocessor.strip()
            cgiresource = CgiDirectory(cgidir, cgiprocessor)
            root.putChild(cgipath, cgiresource)
            log.msg("CGI configured on path '%s' using processor '%s'" % (cgipath, cgiprocessor))
         else:
            log.msg("No CGI configured")

         factory = Site(root)
         factory.log = lambda _: None # disable any logging
         factory.protocol = HTTPChannelHixie76Aware # needed if Hixie76 is to be supported

         ## REST interface to get config values
         ##
         configPath = self.services["config"]["ws-websocket-path"] + "config"
         addPortConfigResource(self.services["config"], root, configPath)
      else:
         factory = self.wsfactory

      self.factory = factory

      if issecure:
         self.listener = reactor.listenSSL(port, factory, contextFactory, backlog = acceptqueue)
      else:
         self.listener = reactor.listenTCP(port, factory, backlog = acceptqueue)

      self.isRunning = True
            log.msg("Found Crossbar.io CodeLab package v%s" % crossbarcodelab.__version__)

         ## Crossbar.io Manual
         ##
         try:
            import crossbarmanual
            root.putChild("manual", File(pkg_resources.resource_filename("crossbarmanual", "web")))
         except ImportError, e:
            log.msg("Crossbar.io Manual not installed [%s]" % e)
         else:
            log.msg("Found Crossbar.io Manual package v%s" % crossbarmanual.__version__)


      ## REST interface to get config values
      ##
      addPortConfigResource(self.services["config"], root, "config")

      ## API Documentation
      ##
      root.putChild("apidoc", ApiHelpResource())

      ## Database Export
      ##
      dbexp = File(str(self.services["config"].get("export-dir")))
      root.putChild(str(self.services["config"].get("export-url")), dbexp)

      ## Database Import
      ##
      dbimp = UploadDatabaseDump(str(self.services["config"].get("import-dir")))
      root.putChild(str(self.services["config"].get("import-url")), dbimp)