]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/base.py
5 import tornado
.httpclient
9 from . import campaigns
10 from . import database
12 from . import fireinfo
14 from . import memcached
15 from . import messages
19 from . import ratelimit
20 from . import releases
21 from . import settings
25 from . import zeiterfassung
26 from .decorators
import *
28 DEFAULT_CONFIG
= io
.StringIO("""
33 static_dir = %(data_dir)s/static
34 templates_dir = %(data_dir)s/templates
37 class Backend(object):
38 def __init__(self
, configfile
, debug
=False):
39 # Read configuration file.
40 self
.config
= self
.read_config(configfile
)
42 # Enable debug logging if configured
43 self
.debug
= debug
or self
.config
.getboolean("global", "debug")
49 self
.http_client
= tornado
.httpclient
.AsyncHTTPClient(
51 "User-Agent" : "IPFireWebApp",
54 # Initialize settings first.
55 self
.settings
= settings
.Settings(self
)
56 self
.memcache
= memcached
.Memcached(self
)
58 # Initialize backend modules.
59 self
.accounts
= accounts
.Accounts(self
)
60 self
.geoip
= geoip
.GeoIP(self
)
61 self
.fireinfo
= fireinfo
.Fireinfo(self
)
62 self
.iuse
= iuse
.IUse(self
)
63 self
.mirrors
= mirrors
.Mirrors(self
)
64 self
.netboot
= netboot
.NetBoot(self
)
65 self
.nopaste
= nopaste
.Nopaste(self
)
66 self
.releases
= releases
.Releases(self
)
67 self
.talk
= talk
.Talk(self
)
69 self
.blog
= blog
.Blog(self
)
70 self
.wiki
= wiki
.Wiki(self
)
71 self
.zeiterfassung
= zeiterfassung
.ZeiterfassungClient(self
)
73 def read_config(self
, configfile
):
74 cp
= configparser
.ConfigParser()
76 # Initialize configuration with some sensible defaults
77 cp
.readfp(DEFAULT_CONFIG
)
84 def setup_database(self
):
86 Sets up the database connection.
89 "host" : self
.config
.get("database", "server"),
90 "database" : self
.config
.get("database", "database"),
91 "user" : self
.config
.get("database", "username"),
92 "password" : self
.config
.get("database", "password"),
95 self
.db
= database
.Connection(**credentials
)
97 async def run_task(self
, task
, *args
, **kwargs
):
99 "check-mirrors" : self
.mirrors
.check_all
,
100 "check-spam" : self
.accounts
.check_spam
,
101 "cleanup" : self
.cleanup
,
102 "launch-campaigns" : self
.campaigns
.launch_manually
,
103 "run-campaigns" : self
.campaigns
.run
,
104 "scan-files" : self
.releases
.scan_files
,
105 "send-message" : self
.messages
.send_cli
,
106 "send-all-messages" : self
.messages
.queue
.send_all
,
107 "test-blacklist" : self
.geoip
.test_blacklist
,
108 "test-ldap" : self
.accounts
.test_ldap
,
109 "tweet" : self
.tweets
.tweet
,
110 "update-blog-feeds" : self
.blog
.update_feeds
,
113 # Get the task from the list of all tasks
114 func
= tasks
.get(task
, None)
116 raise ValueError("Unknown task: %s" % task
)
119 r
= await func(*args
, **kwargs
)
121 # If any error code has been returned,
122 # we will end the program
128 return campaigns
.Campaigns(self
)
132 return accounts
.Groups(self
)
136 return messages
.Messages(self
)
139 def ratelimiter(self
):
140 return ratelimit
.RateLimiter(self
)
144 return tweets
.Tweets(self
)
146 async def cleanup(self
):
147 # Cleanup message queue
148 with self
.db
.transaction():
149 self
.messages
.queue
.cleanup()
151 # Cleanup in accounts
152 with self
.db
.transaction():
153 self
.accounts
.cleanup()