]>
Commit | Line | Data |
---|---|---|
81675874 | 1 | #/usr/bin/python |
2 | ||
feb02477 | 3 | import logging |
e6d36e0a | 4 | import multiprocessing |
81675874 | 5 | import os.path |
8ccd2ff0 | 6 | import simplejson |
feb02477 | 7 | import tornado.httpserver |
81675874 | 8 | import tornado.locale |
81675874 | 9 | import tornado.web |
10 | ||
18e60079 MT |
11 | from tornado.options import options |
12 | ||
940227cb | 13 | import backend |
feb02477 | 14 | |
8ccd2ff0 MT |
15 | from handlers import * |
16 | from ui_modules import * | |
81675874 | 17 | |
18 | BASEDIR = os.path.join(os.path.dirname(__file__), "..") | |
19 | ||
60024cc8 MT |
20 | # Load translations. |
21 | tornado.locale.load_gettext_translations(os.path.join(BASEDIR, "translations"), "webapp") | |
81675874 | 22 | |
23 | class Application(tornado.web.Application): | |
24 | def __init__(self): | |
81675874 | 25 | settings = dict( |
26 | cookie_secret = "aXBmaXJlY29va2llc2VjcmV0Cg==", | |
18e60079 | 27 | debug = options.debug, |
81675874 | 28 | gzip = True, |
d0d074e0 | 29 | login_url = "/login", |
81675874 | 30 | template_path = os.path.join(BASEDIR, "templates"), |
31 | ui_modules = { | |
a0048e66 | 32 | "Advertisement" : AdvertisementModule, |
7771acea | 33 | "DonationBox" : DonationBoxModule, |
60024cc8 | 34 | "DownloadButton" : DownloadButtonModule, |
81675874 | 35 | "Menu" : MenuModule, |
940227cb | 36 | "MirrorItem" : MirrorItemModule, |
0673d1b0 | 37 | "MirrorsTable" : MirrorsTableModule, |
81675874 | 38 | "NewsItem" : NewsItemModule, |
940227cb | 39 | "NewsLine" : NewsLineModule, |
7771acea MT |
40 | "NewsTable" : NewsTableModule, |
41 | "NewsYearNavigation": NewsYearNavigationModule, | |
d0d074e0 | 42 | "PlanetEntry" : PlanetEntryModule, |
81675874 | 43 | "ReleaseItem" : ReleaseItemModule, |
44 | "SidebarBanner" : SidebarBannerModule, | |
81675874 | 45 | "SidebarRelease" : SidebarReleaseModule, |
372efc19 | 46 | "StasyTable" : StasyTableModule, |
62c3fa48 | 47 | "StasyCPUCoreTable" : StasyCPUCoreTableModule, |
91a446f0 | 48 | "StasyDeviceTable" : StasyDeviceTableModule, |
638e9782 | 49 | "StasyGeoTable" : StasyGeoTableModule, |
940227cb | 50 | "TrackerPeerList": TrackerPeerListModule, |
7771acea MT |
51 | "Wish" : WishModule, |
52 | "Wishlist" : WishlistModule, | |
81675874 | 53 | }, |
54 | xsrf_cookies = True, | |
55 | ) | |
5cf160e0 | 56 | |
ae0228e1 MT |
57 | tornado.web.Application.__init__(self, **settings) |
58 | ||
59 | self.settings["static_path"] = static_path = os.path.join(BASEDIR, "static") | |
60 | static_handlers = [ | |
61 | (r"/static/(.*)", tornado.web.StaticFileHandler, dict(path = static_path)), | |
62 | (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = static_path)), | |
63 | (r"/(robots\.txt)", tornado.web.StaticFileHandler, dict(path = static_path)), | |
64 | ] | |
65 | ||
d4dc517c | 66 | self.add_handlers(r"(dev|www)\.ipfire\.(at|org)", [ |
940227cb MT |
67 | # Entry site that lead the user to index |
68 | (r"/", IndexHandler), | |
69 | (r"/index\.?(s?html?)?", RootHandler), | |
70 | ||
71 | # Handle news items | |
940227cb | 72 | (r"/news", NewsIndexHandler), |
7771acea | 73 | (r"/news/year/([0-9]*)", NewsYearHandler), |
940227cb MT |
74 | (r"/news/(.*)", NewsItemHandler), |
75 | (r"/author/(.*)", NewsAuthorHandler), | |
76 | ||
81675874 | 77 | # Download sites |
60024cc8 MT |
78 | (r"/download", DownloadHandler), |
79 | (r"/downloads", tornado.web.RedirectHandler, { "url" : "/download" }), | |
940227cb | 80 | |
8d48f4ef MT |
81 | # Handle old pages that have moved elsewhere |
82 | (r"/screenshots", tornado.web.RedirectHandler, { "url" : "/about" }), | |
60024cc8 MT |
83 | (r"/about", tornado.web.RedirectHandler, { "url" : "/features" }), |
84 | (r"/support", tornado.web.RedirectHandler, { "url" : "/getinvolved" }), | |
85 | ||
86 | (r"/donate", tornado.web.RedirectHandler, { "url" : "/donation" }), | |
8d48f4ef | 87 | |
de683d7c | 88 | # RSS feed |
bcc3ed4d | 89 | (r"/news.rss", RSSNewsHandler), |
de683d7c MT |
90 | |
91 | # Redirection for bookmarks, etc. | |
940227cb MT |
92 | (r"/(de|en)/(.*)", LangCompatHandler) |
93 | ||
94 | ] + static_handlers + [ | |
81675874 | 95 | # Always the last rule |
940227cb MT |
96 | (r"/(.*)", StaticHandler), |
97 | ]) | |
98 | ||
940227cb | 99 | # downloads.ipfire.org |
2db02063 | 100 | self.add_handlers(r"downloads?\.ipfire\.org", [ |
940227cb MT |
101 | (r"/", DownloadsIndexHandler), |
102 | (r"/latest", DownloadsLatestHandler), | |
103 | (r"/release/([0-9]+)", DownloadsReleaseHandler), | |
104 | (r"/older", DownloadsOlderHandler), | |
105 | (r"/development", DownloadsDevelopmentHandler), | |
106 | (r"/mirrors", tornado.web.RedirectHandler, { "url" : "http://mirrors.ipfire.org/" }), | |
107 | (r"/source", tornado.web.RedirectHandler, { "url" : "http://source.ipfire.org/" }), | |
60024cc8 | 108 | (r"/download-splash", DownloadSplashHandler), |
54af860e | 109 | ] + static_handlers + [ |
edd297c4 | 110 | (r"/(iso|torrent)/(.*)", DownloadCompatHandler), |
54af860e MT |
111 | (r"/(.*)", DownloadFileHandler), |
112 | ]) | |
940227cb MT |
113 | |
114 | # mirrors.ipfire.org | |
115 | self.add_handlers(r"mirrors\.ipfire\.org", [ | |
116 | (r"/", MirrorIndexHandler), | |
117 | (r"/mirror/([0-9]+)", MirrorItemHandler), | |
118 | ] + static_handlers) | |
119 | ||
d0d074e0 MT |
120 | # planet.ipfire.org |
121 | self.add_handlers(r"planet\.ipfire\.org", [ | |
940227cb | 122 | (r"/", PlanetMainHandler), |
d0d074e0 | 123 | (r"/post/([A-Za-z0-9_-]+)", PlanetPostingHandler), |
27066195 | 124 | (r"/user/([a-z0-9_-]+)", PlanetUserHandler), |
2bdd073f | 125 | (r"/search", PlanetSearchHandler), |
bcc3ed4d MT |
126 | |
127 | # RSS | |
128 | (r"/rss", RSSPlanetAllHandler), | |
129 | (r"/user/([a-z0-9_-]+)/rss", RSSPlanetUserHandler), | |
d0d074e0 MT |
130 | ] + static_handlers) |
131 | ||
940227cb | 132 | # stasy.ipfire.org |
60024cc8 | 133 | self.add_handlers(r"fireinfo\.ipfire\.org", [ |
940227cb | 134 | (r"/", StasyIndexHandler), |
91a446f0 MT |
135 | (r"/profile/([a-z0-9]{40})", StasyProfileDetailHandler), |
136 | (r"/vendor/(pci|usb)/([0-9a-f]{4})", StasyStatsVendorDetail), | |
137 | (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", StasyStatsModelDetail), | |
138 | ||
30852a9e MT |
139 | # Send profiles. |
140 | (r"/send/([a-z0-9]+)", StasyProfileSendHandler), | |
141 | ||
91a446f0 MT |
142 | # Stats handlers |
143 | (r"/stats", StasyStatsHandler), | |
144 | (r"/stats/cpus", StasyStatsCPUHandler), | |
145 | (r"/stats/cpuflags", StasyStatsCPUFlagsHandler), | |
146 | (r"/stats/geo", StasyStatsGeoHandler), | |
147 | (r"/stats/memory", StasyStatsMemoryHandler), | |
54af860e | 148 | (r"/stats/network", StasyStatsNetworkHandler), |
91a446f0 MT |
149 | (r"/stats/oses", StasyStatsOSesHandler), |
150 | (r"/stats/virtual", StasyStatsVirtualHandler), | |
ae0228e1 | 151 | ] + static_handlers) |
5cf160e0 | 152 | |
c37ec602 MT |
153 | # i-use.ipfire.org |
154 | self.add_handlers(r"i-use\.ipfire\.org", [ | |
155 | (r"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage), | |
156 | ]) | |
157 | ||
5cf160e0 | 158 | # tracker.ipfire.org |
940227cb MT |
159 | self.add_handlers(r"(torrent|tracker)\.ipfire\.org", [ |
160 | (r"/", TrackerIndexHandler), | |
344a3d62 | 161 | (r"/announce.*", TrackerAnnounceHandler), |
e2afbd6a | 162 | (r"/scrape", TrackerScrapeHandler), |
940227cb | 163 | (r"/torrent/([0-9a-f]+)", TrackerDetailHandler), |
fadcfd00 MT |
164 | (r"/([0-9a-f]{40})", TrackerDetailHandler), |
165 | (r"/([0-9a-f]{40})/download", TrackerDownloadHandler), | |
ae0228e1 MT |
166 | ] + static_handlers) |
167 | ||
8e2e1261 MT |
168 | # boot.ipfire.org |
169 | BOOT_STATIC_PATH = os.path.join(self.settings["static_path"], "netboot") | |
170 | self.add_handlers(r"boot\.ipfire\.org", [ | |
171 | (r"/", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org/download" }), | |
172 | ||
173 | # Configurations | |
174 | (r"/menu.gpxe", MenuGPXEHandler), | |
175 | (r"/menu.cfg", MenuCfgHandler), | |
176 | (r"/config/([0-9]+)/boot.gpxe", BootGPXEHandler), | |
177 | ||
178 | # Static files | |
179 | (r"/(boot.png|custom.gpxe|premenu.cfg|vesamenu.c32|menu.c32)", | |
180 | tornado.web.StaticFileHandler, { "path" : BOOT_STATIC_PATH }), | |
181 | ]) | |
182 | ||
60024cc8 MT |
183 | # nopaste.ipfire.org |
184 | self.add_handlers(r"nopaste\.ipfire\.org", [ | |
185 | (r"/", NopasteIndexHandler), | |
186 | (r"/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", NopasteEntryHandler), | |
187 | ] + static_handlers) | |
188 | ||
7771acea MT |
189 | # wishlist.ipfire.org |
190 | self.add_handlers(r"wishlist\.ipfire\.org", [ | |
191 | (r"/", WishlistIndexHandler), | |
1bf8d482 | 192 | (r"/closed", WishlistClosedHandler), |
7771acea MT |
193 | (r"/wish/(.*)/donate", WishDonateHandler), |
194 | (r"/wish/(.*)", WishHandler), | |
195 | (r"/terms", WishlistTermsHandler), | |
196 | ] + static_handlers) | |
197 | ||
d0d074e0 MT |
198 | # admin.ipfire.org |
199 | self.add_handlers(r"admin\.ipfire\.org", [ | |
200 | (r"/", AdminIndexHandler), | |
940227cb MT |
201 | (r"/login", AdminLoginHandler), |
202 | (r"/logout", AdminLogoutHandler), | |
d0d074e0 MT |
203 | # Accounts |
204 | (r"/accounts", AdminAccountsHandler), | |
940227cb MT |
205 | #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler), |
206 | #(r"/accounts/edit/([0-9]+)", AdminAccountsEditHandler), | |
d0d074e0 MT |
207 | # Planet |
208 | (r"/planet", AdminPlanetHandler), | |
209 | (r"/planet/compose", AdminPlanetComposeHandler), | |
210 | (r"/planet/edit/([0-9]+)", AdminPlanetEditHandler), | |
940227cb MT |
211 | # Mirrors |
212 | (r"/mirrors", AdminMirrorsHandler), | |
213 | (r"/mirrors/create", AdminMirrorsCreateHandler), | |
214 | (r"/mirrors/delete/([0-9]+)", AdminMirrorsDeleteHandler), | |
215 | (r"/mirrors/edit/([0-9]+)", AdminMirrorsEditHandler), | |
216 | (r"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler), | |
217 | (r"/mirrors/update", AdminMirrorsUpdateHandler), | |
71e1ece7 MT |
218 | # Fireinfo |
219 | (r"/fireinfo/stats", AdminFireinfoStatsHandler), | |
60024cc8 MT |
220 | # Downloads |
221 | (r"/downloads", AdminDownloadsHandler), | |
222 | (r"/downloads/mirrors", AdminDownloadsMirrorsHandler), | |
d0d074e0 MT |
223 | # API |
224 | (r"/api/planet/render", AdminApiPlanetRenderMarkupHandler) | |
225 | ] + static_handlers) | |
226 | ||
ae0228e1 | 227 | # ipfire.org |
3add293a | 228 | self.add_handlers(r".*", [ |
ae0228e1 | 229 | (r".*", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org" }) |
5cf160e0 | 230 | ]) |
3add293a | 231 | |
feb02477 MT |
232 | logging.info("Successfully initialied application") |
233 | ||
234 | self.__running = True | |
235 | ||
3add293a | 236 | def __del__(self): |
feb02477 MT |
237 | logging.info("Shutting down application") |
238 | ||
feb02477 MT |
239 | @property |
240 | def ioloop(self): | |
241 | return tornado.ioloop.IOLoop.instance() | |
242 | ||
940227cb | 243 | def shutdown(self, *args): |
feb02477 MT |
244 | logging.debug("Caught shutdown signal") |
245 | self.ioloop.stop() | |
246 | ||
247 | self.__running = False | |
248 | ||
249 | def run(self, port=8001): | |
250 | logging.debug("Going to background") | |
251 | ||
252 | http_server = tornado.httpserver.HTTPServer(self, xheaders=True) | |
feb02477 | 253 | |
940227cb MT |
254 | # If we are not running in debug mode, we can actually run multiple |
255 | # frontends to get best performance out of our service. | |
256 | if not self.settings["debug"]: | |
257 | http_server.bind(port) | |
e6d36e0a | 258 | http_server.start(num_processes=multiprocessing.cpu_count()) |
940227cb MT |
259 | else: |
260 | http_server.listen(port) | |
de683d7c MT |
261 | |
262 | # All requests should be done after 30 seconds or they will be killed. | |
263 | self.ioloop.set_blocking_log_threshold(30) | |
feb02477 | 264 | |
940227cb | 265 | self.ioloop.start() |
feb02477 MT |
266 | |
267 | def reload(self): | |
268 | logging.debug("Caught reload signal") |