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