]> git.ipfire.org Git - ipfire.org.git/blame - www/webapp/__init__.py
Fix wrong slogan on index page.
[ipfire.org.git] / www / webapp / __init__.py
CommitLineData
81675874 1#/usr/bin/python
2
feb02477 3import logging
81675874 4import os.path
8ccd2ff0 5import simplejson
feb02477 6import tornado.httpserver
81675874 7import tornado.locale
8import tornado.options
9import tornado.web
10
940227cb 11import backend
feb02477 12
8ccd2ff0
MT
13from handlers import *
14from ui_modules import *
81675874 15
16BASEDIR = os.path.join(os.path.dirname(__file__), "..")
17
940227cb
MT
18# Enable logging
19tornado.options.enable_pretty_logging()
20tornado.options.parse_command_line()
21
81675874 22tornado.locale.load_translations(os.path.join(BASEDIR, "translations"))
81675874 23
24class Application(tornado.web.Application):
25 def __init__(self):
81675874 26 settings = dict(
27 cookie_secret = "aXBmaXJlY29va2llc2VjcmV0Cg==",
940227cb 28 debug = True,
81675874 29 gzip = True,
d0d074e0 30 login_url = "/login",
81675874 31 template_path = os.path.join(BASEDIR, "templates"),
32 ui_modules = {
81675874 33 "Menu" : MenuModule,
940227cb 34 "MirrorItem" : MirrorItemModule,
81675874 35 "NewsItem" : NewsItemModule,
940227cb 36 "NewsLine" : NewsLineModule,
d0d074e0 37 "PlanetEntry" : PlanetEntryModule,
81675874 38 "ReleaseItem" : ReleaseItemModule,
39 "SidebarBanner" : SidebarBannerModule,
81675874 40 "SidebarRelease" : SidebarReleaseModule,
372efc19 41 "StasyTable" : StasyTableModule,
940227cb 42 "TrackerPeerList": TrackerPeerListModule,
81675874 43 },
44 xsrf_cookies = True,
45 )
5cf160e0 46
ae0228e1
MT
47 tornado.web.Application.__init__(self, **settings)
48
49 self.settings["static_path"] = static_path = os.path.join(BASEDIR, "static")
50 static_handlers = [
51 (r"/static/(.*)", tornado.web.StaticFileHandler, dict(path = static_path)),
52 (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = static_path)),
53 (r"/(robots\.txt)", tornado.web.StaticFileHandler, dict(path = static_path)),
54 ]
55
d4dc517c 56 self.add_handlers(r"(dev|www)\.ipfire\.(at|org)", [
940227cb
MT
57 # Entry site that lead the user to index
58 (r"/", IndexHandler),
59 (r"/index\.?(s?html?)?", RootHandler),
60
61 # Handle news items
62 #(r"/news/(.*)", NewsRedirectHandler),
63 (r"/news", NewsIndexHandler),
64 (r"/news/(.*)", NewsItemHandler),
65 (r"/author/(.*)", NewsAuthorHandler),
66
81675874 67 # Download sites
940227cb
MT
68 (r"/downloads?", DownloadHandler),
69# # RSS feed
70# (r"/([A-Za-z]{2})/news.rss", RSSHandler),
71# (r"/data/feeds/main-([A-Za-z]{2}).rss", RSSHandler),
72
73 (r"/(de|en)/(.*)", LangCompatHandler)
74
75 ] + static_handlers + [
81675874 76 # Always the last rule
940227cb
MT
77 (r"/(.*)", StaticHandler),
78 ])
79
80 # news.ipfire.org
81 #self.add_handlers(r"news\.ipfire\.org", [
82 # (r"/", NewsIndexHandler),
83 # (r"/news/(.*)", NewsItemHandler),
84 # (r"/author/(.*)", NewsAuthorHandler),
85 #] + static_handlers)
81675874 86
5cf160e0 87 # download.ipfire.org
ae0228e1 88 self.add_handlers(r"download\.ipfire\.org", [
3add293a
MT
89 (r"/", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org/" }),
90 (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = static_path)),
91 (r"/(.*)", DownloadFileHandler),
92 ])
5cf160e0 93
940227cb
MT
94 # downloads.ipfire.org
95 self.add_handlers(r"downloads\.ipfire\.org", [
96 (r"/", DownloadsIndexHandler),
97 (r"/latest", DownloadsLatestHandler),
98 (r"/release/([0-9]+)", DownloadsReleaseHandler),
99 (r"/older", DownloadsOlderHandler),
100 (r"/development", DownloadsDevelopmentHandler),
101 (r"/mirrors", tornado.web.RedirectHandler, { "url" : "http://mirrors.ipfire.org/" }),
102 (r"/source", tornado.web.RedirectHandler, { "url" : "http://source.ipfire.org/" }),
103 ] + static_handlers)
104
105 # mirrors.ipfire.org
106 self.add_handlers(r"mirrors\.ipfire\.org", [
107 (r"/", MirrorIndexHandler),
108 (r"/mirror/([0-9]+)", MirrorItemHandler),
109 ] + static_handlers)
110
d0d074e0
MT
111 # planet.ipfire.org
112 self.add_handlers(r"planet\.ipfire\.org", [
940227cb 113 (r"/", PlanetMainHandler),
d0d074e0
MT
114 (r"/post/([A-Za-z0-9_-]+)", PlanetPostingHandler),
115 (r"/user/([a-z0-9]+)", PlanetUserHandler),
116 ] + static_handlers)
117
940227cb
MT
118 # stasy.ipfire.org
119 self.add_handlers(r"stasy\.ipfire\.org", [
120 (r"/", StasyIndexHandler),
121 (r"/profile/([a-z0-9]{40})", StasyProfileHandler),
372efc19
MT
122 (r"/statistics/cpu", StasyStatsCPUHandler),
123 (r"/statistics/virtual", StasyStatsVirtualHandler),
ae0228e1 124 ] + static_handlers)
5cf160e0 125
c37ec602
MT
126 # i-use.ipfire.org
127 self.add_handlers(r"i-use\.ipfire\.org", [
128 (r"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage),
129 ])
130
940227cb
MT
131 # source.ipfire.org
132# self.add_handlers(r"source\.ipfire\.org", [
133# (r"/", MainHandler),
134# (r"/[A-Za-z]{2}/?", MainHandler),
135# (r"/[A-Za-z]{2}/index", SourceHandler),
136# (r"(/source.*|/toolchains/.*)", SourceDownloadHandler),
137# ] + static_handlers)
5cf160e0
MT
138
139 # tracker.ipfire.org
940227cb
MT
140 self.add_handlers(r"(torrent|tracker)\.ipfire\.org", [
141 (r"/", TrackerIndexHandler),
43d991f6 142 (r"/a.*", TrackerAnnounceHandler),
e2afbd6a 143 (r"/scrape", TrackerScrapeHandler),
940227cb 144 (r"/torrent/([0-9a-f]+)", TrackerDetailHandler),
ae0228e1
MT
145 ] + static_handlers)
146
d0d074e0
MT
147 # admin.ipfire.org
148 self.add_handlers(r"admin\.ipfire\.org", [
149 (r"/", AdminIndexHandler),
940227cb
MT
150 (r"/login", AdminLoginHandler),
151 (r"/logout", AdminLogoutHandler),
d0d074e0
MT
152 # Accounts
153 (r"/accounts", AdminAccountsHandler),
940227cb
MT
154 #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler),
155 #(r"/accounts/edit/([0-9]+)", AdminAccountsEditHandler),
d0d074e0
MT
156 # Planet
157 (r"/planet", AdminPlanetHandler),
158 (r"/planet/compose", AdminPlanetComposeHandler),
159 (r"/planet/edit/([0-9]+)", AdminPlanetEditHandler),
940227cb
MT
160 # Mirrors
161 (r"/mirrors", AdminMirrorsHandler),
162 (r"/mirrors/create", AdminMirrorsCreateHandler),
163 (r"/mirrors/delete/([0-9]+)", AdminMirrorsDeleteHandler),
164 (r"/mirrors/edit/([0-9]+)", AdminMirrorsEditHandler),
165 (r"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler),
166 (r"/mirrors/update", AdminMirrorsUpdateHandler),
d0d074e0
MT
167 # API
168 (r"/api/planet/render", AdminApiPlanetRenderMarkupHandler)
169 ] + static_handlers)
170
ae0228e1 171 # ipfire.org
3add293a 172 self.add_handlers(r".*", [
ae0228e1 173 (r".*", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org" })
5cf160e0 174 ])
3add293a 175
feb02477
MT
176 logging.info("Successfully initialied application")
177
178 self.__running = True
179
3add293a 180 def __del__(self):
feb02477
MT
181 logging.info("Shutting down application")
182
feb02477
MT
183 @property
184 def ioloop(self):
185 return tornado.ioloop.IOLoop.instance()
186
940227cb 187 def shutdown(self, *args):
feb02477
MT
188 logging.debug("Caught shutdown signal")
189 self.ioloop.stop()
190
191 self.__running = False
192
193 def run(self, port=8001):
194 logging.debug("Going to background")
940227cb
MT
195
196 # All requests should be done after 30 seconds or they will be killed.
197 self.ioloop.set_blocking_log_threshold(30)
feb02477
MT
198
199 http_server = tornado.httpserver.HTTPServer(self, xheaders=True)
feb02477 200
940227cb
MT
201 # If we are not running in debug mode, we can actually run multiple
202 # frontends to get best performance out of our service.
203 if not self.settings["debug"]:
204 http_server.bind(port)
205 http_server.start(num_processes=4)
206 else:
207 http_server.listen(port)
feb02477 208
940227cb 209 self.ioloop.start()
feb02477
MT
210
211 def reload(self):
212 logging.debug("Caught reload signal")