]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/base.py
Support sending HTML emails
[ipfire.org.git] / src / backend / base.py
index 19797edb58c507acfb423ff59444528764d9bd7b..1578a01544f9a44078f0a744b0e85c2b7f9682eb 100644 (file)
@@ -2,10 +2,11 @@
 
 import configparser
 import io
-import tornado.gen
+import tornado.httpclient
 
 from . import accounts
 from . import blog
+from . import campaigns
 from . import database
 from . import geoip
 from . import fireinfo
@@ -44,6 +45,12 @@ class Backend(object):
                # Setup database.
                self.setup_database()
 
+               # Create HTTPClient
+               self.http_client = tornado.httpclient.AsyncHTTPClient(
+                       defaults = {
+                               "User-Agent" : "IPFireWebApp",
+                       }
+               )
                # Initialize settings first.
                self.settings = settings.Settings(self)
                self.memcache = memcached.Memcached(self)
@@ -87,13 +94,17 @@ class Backend(object):
 
                self.db = database.Connection(**credentials)
 
-       @tornado.gen.coroutine
-       def run_task(self, task, *args, **kwargs):
+       async def run_task(self, task, *args, **kwargs):
                tasks = {
                        "check-mirrors"     : self.mirrors.check_all,
+                       "check-spam"        : self.accounts.check_spam,
                        "cleanup"           : self.cleanup,
+                       "launch-campaigns"  : self.campaigns.launch_manually,
+                       "run-campaigns"     : self.campaigns.run,
                        "scan-files"        : self.releases.scan_files,
+                       "send-message"      : self.messages.send_cli,
                        "send-all-messages" : self.messages.queue.send_all,
+                       "test-blacklist"    : self.geoip.test_blacklist,
                        "test-ldap"         : self.accounts.test_ldap,
                        "tweet"             : self.tweets.tweet,
                        "update-blog-feeds" : self.blog.update_feeds,
@@ -105,13 +116,21 @@ class Backend(object):
                        raise ValueError("Unknown task: %s" % task)
 
                # Run the task
-               r = yield func(*args, **kwargs)
+               r = await func(*args, **kwargs)
 
                # If any error code has been returned,
                # we will end the program
                if r:
                        raise SystemExit(r)
 
+       @lazy_property
+       def campaigns(self):
+               return campaigns.Campaigns(self)
+
+       @lazy_property
+       def groups(self):
+               return accounts.Groups(self)
+
        @lazy_property
        def messages(self):
                return messages.Messages(self)
@@ -124,8 +143,7 @@ class Backend(object):
        def tweets(self):
                return tweets.Tweets(self)
 
-       @tornado.gen.coroutine
-       def cleanup(self):
+       async def cleanup(self):
                # Cleanup message queue
                with self.db.transaction():
                        self.messages.queue.cleanup()