]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/base.py
Support sending HTML emails
[ipfire.org.git] / src / backend / base.py
index 19e6384fc3daf96c89a753e03455848d47e225d3..1578a01544f9a44078f0a744b0e85c2b7f9682eb 100644 (file)
@@ -1,26 +1,31 @@
 #!/usr/bin/python
 
-import ConfigParser as configparser
-import StringIO
-
-import accounts
-import ads
-import database
-import geoip
-import fireinfo
-import iuse
-import memcached
-import mirrors
-import netboot
-import nopaste
-import releases
-import settings
-import talk
+import configparser
+import io
+import tornado.httpclient
 
+from . import accounts
 from . import blog
+from . import campaigns
+from . import database
+from . import geoip
+from . import fireinfo
+from . import iuse
+from . import memcached
+from . import messages
+from . import mirrors
+from . import netboot
+from . import nopaste
+from . import ratelimit
+from . import releases
+from . import settings
+from . import talk
+from . import tweets
+from . import wiki
 from . import zeiterfassung
+from .decorators import *
 
-DEFAULT_CONFIG = StringIO.StringIO("""
+DEFAULT_CONFIG = io.StringIO("""
 [global]
 debug = false
 
@@ -40,14 +45,18 @@ 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)
 
                # Initialize backend modules.
                self.accounts = accounts.Accounts(self)
-               self.advertisements = ads.Advertisements(self)
-               self.downloads = mirrors.Downloads(self)
                self.geoip = geoip.GeoIP(self)
                self.fireinfo = fireinfo.Fireinfo(self)
                self.iuse = iuse.IUse(self)
@@ -58,6 +67,7 @@ class Backend(object):
                self.talk = talk.Talk(self)
 
                self.blog = blog.Blog(self)
+               self.wiki = wiki.Wiki(self)
                self.zeiterfassung = zeiterfassung.ZeiterfassungClient(self)
 
        def read_config(self, configfile):
@@ -83,3 +93,61 @@ class Backend(object):
                }
 
                self.db = database.Connection(**credentials)
+
+       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,
+               }
+
+               # Get the task from the list of all tasks
+               func = tasks.get(task, None)
+               if not func:
+                       raise ValueError("Unknown task: %s" % task)
+
+               # Run the task
+               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)
+
+       @lazy_property
+       def ratelimiter(self):
+               return ratelimit.RateLimiter(self)
+
+       @lazy_property
+       def tweets(self):
+               return tweets.Tweets(self)
+
+       async def cleanup(self):
+               # Cleanup message queue
+               with self.db.transaction():
+                       self.messages.queue.cleanup()
+
+               # Cleanup in accounts
+               with self.db.transaction():
+                       self.accounts.cleanup()