def __init__(self, router): self.router = router viewsDir = Router.getConfig("templateDir") templateCacheDir = Router.getConfig("templateCacheDir") AppController.__init__(self, viewsDir=viewsDir, templateCacheDir=templateCacheDir) # these are extra view dirs that controllers should be able to see viewsDirs = ["common"] self.addController(FilesController, paths=["static"]) self.addController(SubscriptionController, paths=["subscription", ""], viewDirs=viewsDirs) self.addController(NodeController, paths=["node"], viewDirs=viewsDirs) self.addController(HumanController, paths=["human", ""], viewDirs=viewsDirs)
def __init__(self, router): self.router = router viewsDir = Router.getConfig('templateDir') templateCacheDir = Router.getConfig('templateCacheDir') AppController.__init__(self, viewsDir=viewsDir, templateCacheDir=templateCacheDir) # these are extra view dirs that controllers should be able to see viewsDirs = ['common'] self.addController(FilesController, paths=['static']) self.addController(SubscriptionController, paths=['subscription', ''], viewDirs=viewsDirs) self.addController(NodeController, paths=['node'], viewDirs=viewsDirs) self.addController(HumanController, paths=['human', ''], viewDirs=viewsDirs)
from pubsubin.utils import sendEmail class EMailSubscriptionType(SubscriptionType): def __init__(self, router, application): SubscriptionType.__init__(self, 'email', router, application) self.fields = {'to_address': "Address to send emails to."} self.requiredFields = ['to_address'] self.name = "Email" self.description = "Send an email to a given address each time a message is posted." def send(self, msg, subscriber): def doSend(node): toaddy = subscriber.config['to_address'] fromaddy = "%s-%s@%s" % (node.shortname, node.access_key, self.router.getConfig('domain')) sendEmail(fromaddy, toaddy, msg.body, msg.title) return subscriber.node.get().addCallback(doSend) def toString(self, emailsub): return "send emails to %s" % emailsub.config['to_address'] Router.addSubscriber(EMailSubscriptionType)
def start(self): site = appserver.NevowSite(routes.WebRoot(self.router)) sslContext = ssl.DefaultOpenSSLContextFactory(Router.getConfig('sslkey'), Router.getConfig('sslcrt')) webServerSSL = internet.SSLServer(Router.getConfig('webportssl'), site, sslContext) webServerSSL.setServiceParent(self.application)
from twisted.application import internet # the following try/except/if has been taken per recommendation from # http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.0.0//twisted/internet/ssl.py try: from twisted.internet import ssl except ImportError: ssl = None if ssl and not ssl.supported: ssl = None from pubsubin.web import routes from pubsubin.control import Router, PublisherType from nevow import appserver class WebSSLPublisher(PublisherType): def __init__(self, router, application): PublisherType.__init__(self, 'webssl', router, application) def start(self): site = appserver.NevowSite(routes.WebRoot(self.router)) sslContext = ssl.DefaultOpenSSLContextFactory(Router.getConfig('sslkey'), Router.getConfig('sslcrt')) webServerSSL = internet.SSLServer(Router.getConfig('webportssl'), site, sslContext) webServerSSL.setServiceParent(self.application) Router.addPublisher(WebSSLPublisher)
def start(self): site = appserver.NevowSite(routes.WebRoot(self.router)) webServer = internet.TCPServer(Router.getConfig('webport'), site) webServer.setServiceParent(self.application)
from twisted.application import internet from pubsubin.web import routes from pubsubin.control import Router, PublisherType from nevow import appserver class WebPublisher(PublisherType): def __init__(self, router, application): PublisherType.__init__(self, 'web', router, application) def start(self): site = appserver.NevowSite(routes.WebRoot(self.router)) webServer = internet.TCPServer(Router.getConfig('webport'), site) webServer.setServiceParent(self.application) Router.addPublisher(WebPublisher)
def start(self): smtpserver = internet.TCPServer(Router.getConfig('smtpport'), SMTPFactory(self.router)) smtpserver.setServiceParent(self.application)
def validateTo(self, user): if not user.dest.domain.lower().endswith(Router.getConfig('domain')): log.err("attempt to send message to an unknown destination: \"%s\"" % str(user.dest)) raise smtp.SMTPBadRcpt(user) return lambda: Message(self.router)
return emailToUsername(self.dbpool, msg['from'].lower()).addCallback(doSend) """ def connectionLost(self): self.lines = None class SMTPFactory(smtp.SMTPFactory): def __init__(self, router): smtp.SMTPFactory.__init__(self) self.delivery = MessageDelivery(router) def buildProtocol(self, addr): p = smtp.SMTPFactory.buildProtocol(self, addr) p.delivery = self.delivery return p class EMailPublisher(PublisherType): def __init__(self, router, application): PublisherType.__init__(self, 'email', router, application) def start(self): smtpserver = internet.TCPServer(Router.getConfig('smtpport'), SMTPFactory(self.router)) smtpserver.setServiceParent(self.application) Router.addPublisher(EMailPublisher)