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