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