]>
Commit | Line | Data |
---|---|---|
1 | #/usr/bin/python | |
2 | ||
3 | import logging | |
4 | import os.path | |
5 | import tornado.locale | |
6 | import tornado.options | |
7 | import tornado.web | |
8 | ||
9 | import ipfire | |
10 | ||
11 | from handlers import * | |
12 | from ui_modules import * | |
13 | ||
14 | from . import blog | |
15 | ||
16 | BASEDIR = os.path.join(os.path.dirname(__file__), "..") | |
17 | ||
18 | class Application(tornado.web.Application): | |
19 | def __init__(self, config, **kwargs): | |
20 | # Initialize backend | |
21 | self.backend = ipfire.Backend(config) | |
22 | ||
23 | settings = { | |
24 | # Do not compress responses | |
25 | "gzip" : False, | |
26 | ||
27 | # Enable XSRF cookies | |
28 | "xsrf_cookies" : True, | |
29 | ||
30 | # Login | |
31 | "login_url" : "/login", | |
32 | ||
33 | # Setup directory structure | |
34 | "static_path" : self.backend.config.get("global", "static_dir"), | |
35 | "template_path" : self.backend.config.get("global", "templates_dir"), | |
36 | ||
37 | # UI Modules | |
38 | "ui_methods" : { | |
39 | "format_month_name" : self.format_month_name, | |
40 | }, | |
41 | "ui_modules" : { | |
42 | "BlogPost" : blog.PostModule, | |
43 | "BlogPosts" : blog.PostsModule, | |
44 | ||
45 | # Old modules | |
46 | "Advertisement" : AdvertisementModule, | |
47 | "DonationBox" : DonationBoxModule, | |
48 | "DonationButton" : DonationButtonModule, | |
49 | "DonationInputBox" : DonationInputBoxModule, | |
50 | "DownloadButton" : DownloadButtonModule, | |
51 | "LanguageName" : LanguageNameModule, | |
52 | "Map" : MapModule, | |
53 | "Menu" : MenuModule, | |
54 | "MirrorItem" : MirrorItemModule, | |
55 | "MirrorsTable" : MirrorsTableModule, | |
56 | "NetBootMenuConfig" : NetBootMenuConfigModule, | |
57 | "NetBootMenuHeader" : NetBootMenuHeaderModule, | |
58 | "NetBootMenuSeparator" : NetBootMenuSeparatorModule, | |
59 | "ProgressBar" : ProgressBarModule, | |
60 | "ReleaseItem" : ReleaseItemModule, | |
61 | "SidebarBanner" : SidebarBannerModule, | |
62 | "SidebarRelease" : SidebarReleaseModule, | |
63 | "FireinfoDeviceTable" : FireinfoDeviceTableModule, | |
64 | "FireinfoDeviceAndGroupsTable" : FireinfoDeviceAndGroupsTableModule, | |
65 | "FireinfoGeoTable" : FireinfoGeoTableModule, | |
66 | "TalkContact" : TalkContactModule, | |
67 | "TalkCallLog" : TalkCallLogModule, | |
68 | "TalkLines" : TalkLinesModule, | |
69 | "TalkOngoingCalls" : TalkOngoingCallsModule, | |
70 | }, | |
71 | ||
72 | # Call this when a page wasn't found | |
73 | "default_handler_class" : NotFoundHandler, | |
74 | } | |
75 | settings.update(kwargs) | |
76 | ||
77 | tornado.web.Application.__init__(self, **settings) | |
78 | ||
79 | authentication_handlers = [ | |
80 | (r"/login", LoginHandler), | |
81 | (r"/logout", LogoutHandler), | |
82 | ] | |
83 | ||
84 | self.add_handlers(r"(dev|www)\.ipfire\.(at|org)", [ | |
85 | # Entry site that lead the user to index | |
86 | (r"/", IndexHandler), | |
87 | ||
88 | # Download sites | |
89 | (r"/download", DownloadHandler), | |
90 | (r"/downloads", tornado.web.RedirectHandler, { "url" : "/download" }), | |
91 | ||
92 | # Donate | |
93 | (r"/donate", DonateHandler), | |
94 | (r"/donation", tornado.web.RedirectHandler, { "url" : "/donate" }), | |
95 | ||
96 | # RSS feed | |
97 | (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }), | |
98 | ||
99 | # Redirect news articles to blog | |
100 | (r"/news/(.*)", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/posts/{1}" }), | |
101 | ||
102 | # Static Pages | |
103 | (r"/artwork", StaticHandler, { "template" : "artwork.html" }), | |
104 | (r"/chat", StaticHandler, { "template" : "chat.html" }), | |
105 | (r"/features", StaticHandler, { "template" : "features.html" }), | |
106 | (r"/get-involved", StaticHandler, { "template" : "get-involved.html" }), | |
107 | (r"/get-started", StaticHandler, { "template" : "get-started.html" }), | |
108 | (r"/get-support", StaticHandler, { "template" : "get-support.html" }), | |
109 | (r"/hardware", StaticHandler, { "template" : "hardware.html" }), | |
110 | (r"/legal", StaticHandler, { "template" : "legal.html" }), | |
111 | ||
112 | # Handle old pages that have moved elsewhere | |
113 | (r"/imprint", tornado.web.RedirectHandler, { "url" : "/legal" }), | |
114 | (r"/(de|en)/(.*)", LangCompatHandler), | |
115 | ]) | |
116 | ||
117 | # blog.ipfire.org | |
118 | self.add_handlers(r"blog(\.dev)?\.ipfire\.org", [ | |
119 | (r"/", blog.IndexHandler), | |
120 | (r"/authors/(\w+)", blog.AuthorHandler), | |
121 | (r"/post/(.*)", blog.PostHandler), | |
122 | (r"/search", blog.SearchHandler), | |
123 | (r"/tags/([0-9a-z\-]+)", blog.TagHandler), | |
124 | ||
125 | # RSS Feed | |
126 | (r"/feed.xml", blog.FeedHandler), | |
127 | ]) | |
128 | ||
129 | # downloads.ipfire.org | |
130 | self.add_handlers(r"downloads?(\.dev)?\.ipfire\.org", [ | |
131 | (r"/", DownloadsIndexHandler), | |
132 | (r"/latest", DownloadsLatestHandler), | |
133 | (r"/release/(\d)", DownloadsReleaseHandler), | |
134 | (r"/release/([\w\.\-]*)", DownloadsReleaseHandler), | |
135 | (r"/older", DownloadsOlderHandler), | |
136 | (r"/development", DownloadsDevelopmentHandler), | |
137 | (r"/mirrors", tornado.web.RedirectHandler, { "url" : "https://mirrors.ipfire.org/" }), | |
138 | (r"/source", tornado.web.RedirectHandler, { "url" : "https://source.ipfire.org/" }), | |
139 | (r"/download-splash", DownloadSplashHandler), | |
140 | (r"/(iso|torrent)/(.*)", DownloadCompatHandler), | |
141 | (r"/(.*)", DownloadFileHandler), | |
142 | ]) | |
143 | ||
144 | # mirrors.ipfire.org | |
145 | self.add_handlers(r"mirrors(\.dev)?\.ipfire\.org", [ | |
146 | (r"/", MirrorIndexHandler), | |
147 | (r"/mirror/(.*)", MirrorItemHandler), | |
148 | ]) | |
149 | ||
150 | # planet.ipfire.org | |
151 | self.add_handlers(r"planet(\.dev)?\.ipfire\.org", [ | |
152 | (r"/", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/" }), | |
153 | (r"/post/([A-Za-z0-9_-]+)", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/posts/{1}" }), | |
154 | (r"/user/([a-z0-9_-]+)", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/authors/{1}" }), | |
155 | ||
156 | # RSS | |
157 | (r"/rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }), | |
158 | (r"/user/([a-z0-9_-]+)/rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/authors/{1}.rss" }), | |
159 | (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }), | |
160 | ]) | |
161 | ||
162 | # fireinfo.ipfire.org | |
163 | self.add_handlers(r"fireinfo(\.dev)?\.ipfire\.org", [ | |
164 | (r"/", FireinfoIndexHandler), | |
165 | (r"/device/driver/(.*)", FireinfoDeviceDriverDetail), | |
166 | (r"/device/vendors", FireinfoDeviceVendorsHandler), | |
167 | (r"/device/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorHandler), | |
168 | (r"/device/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelHandler), | |
169 | ||
170 | # Show profiles | |
171 | (r"/profile/random", FireinfoRandomProfileHandler), | |
172 | (r"/profile/([a-z0-9]{40})", FireinfoProfileDetailHandler), | |
173 | ||
174 | # Send profiles. | |
175 | (r"/send/([a-z0-9]+)", FireinfoProfileSendHandler), | |
176 | ||
177 | # Stats handlers | |
178 | (r"/statistics", FireinfoStatsHandler), | |
179 | (r"/statistics/processors", FireinfoStatsProcessorsHandler), | |
180 | (r"/statistics/processors/(arm|x86)", FireinfoStatsProcessorDetailHandler), | |
181 | (r"/statistics/geo-locations", FireinfoStatsGeoHandler), | |
182 | (r"/statistics/languages", FireinfoStatsLanguagesHandler), | |
183 | (r"/statistics/memory", FireinfoStatsMemoryHandler), | |
184 | (r"/statistics/networking", FireinfoStatsNetworkingHandler), | |
185 | (r"/statistics/releases", FireinfoStatsReleasesHandler), | |
186 | (r"/statistics/virtualization", FireinfoStatsVirtualHandler), | |
187 | ||
188 | # Compat handlers | |
189 | (r"/stats", tornado.web.RedirectHandler, { "url" : "/statistics" }), | |
190 | (r"/stats/cpus", tornado.web.RedirectHandler, { "url" : "/statistics/processors" }), | |
191 | (r"/stats/geo", tornado.web.RedirectHandler, { "url" : "/statistics/geo-locations" }), | |
192 | (r"/stats/network", tornado.web.RedirectHandler, { "url" : "/statistics/networking" }), | |
193 | (r"/stats/oses", tornado.web.RedirectHandler, { "url" : "/statistics/releases" }), | |
194 | (r"/stats/virtual", tornado.web.RedirectHandler, { "url" : "/statistics/virtualization" }), | |
195 | (r"/vendor/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorCompatHandler), | |
196 | (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelCompatHandler), | |
197 | ]) | |
198 | ||
199 | # i-use.ipfire.org | |
200 | self.add_handlers(r"i-use(\.dev)?\.ipfire\.org", [ | |
201 | (r"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage), | |
202 | ]) | |
203 | ||
204 | # boot.ipfire.org | |
205 | BOOT_STATIC_PATH = os.path.join(self.settings["static_path"], "netboot") | |
206 | self.add_handlers(r"boot(\.dev)?\.ipfire\.org", [ | |
207 | (r"/", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org/download" }), | |
208 | ||
209 | # Configurations | |
210 | (r"/premenu.cfg", PremenuCfgHandler), | |
211 | (r"/menu.gpxe", MenuGPXEHandler), | |
212 | (r"/menu.cfg", MenuCfgHandler), | |
213 | ||
214 | # Static files | |
215 | (r"/(boot\.png|pxelinux\.0|menu\.c32|vesamenu\.c32)", | |
216 | tornado.web.StaticFileHandler, { "path" : BOOT_STATIC_PATH }), | |
217 | ]) | |
218 | ||
219 | # nopaste.ipfire.org | |
220 | self.add_handlers(r"nopaste(\.dev)?\.ipfire\.org", [ | |
221 | (r"/", NopasteCreateHandler), | |
222 | (r"/raw/(.*)", NopasteRawHandler), | |
223 | (r"/view/(.*)", NopasteViewHandler), | |
224 | ] + authentication_handlers) | |
225 | ||
226 | # geoip.ipfire.org | |
227 | self.add_handlers(r"geoip(\.dev)?\.ipfire\.org", [ | |
228 | (r"/", GeoIPHandler), | |
229 | ]) | |
230 | ||
231 | # talk.ipfire.org | |
232 | self.add_handlers(r"talk(\.dev)?\.ipfire\.org", [ | |
233 | (r"/", TalkIndexHandler), | |
234 | (r"/conferences", TalkConferencesHandler), | |
235 | (r"/diagnosis", TalkDiagnosisHandler), | |
236 | (r"/hangup/(.*)", TalkHangupChannelHandler), | |
237 | (r"/phonebook/(\w+)", TalkPhonebookAccountHandler), | |
238 | (r"/phonebook", TalkPhonebookHandler), | |
239 | (r"/profile", TalkProfileHandler), | |
240 | ] + authentication_handlers) | |
241 | ||
242 | # accounts.ipfire.org | |
243 | self.add_handlers(r"accounts(\.dev)?\.ipfire\.org", [ | |
244 | (r"/avatar/(\w+)\.jpg", AccountsAvatarHandler), | |
245 | ]) | |
246 | ||
247 | # admin.ipfire.org | |
248 | self.add_handlers(r"admin(\.dev)?\.ipfire\.org", [ | |
249 | (r"/", AdminIndexHandler), | |
250 | # Accounts | |
251 | (r"/accounts", AdminAccountsHandler), | |
252 | #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler), | |
253 | #(r"/accounts/edit/([0-9]+)", AdminAccountsEditHandler), | |
254 | # Planet | |
255 | (r"/planet", AdminPlanetHandler), | |
256 | (r"/planet/compose", AdminPlanetComposeHandler), | |
257 | (r"/planet/edit/(.*)", AdminPlanetEditHandler), | |
258 | (r"/planet/publish/(.*)", AdminPlanetPublishHandler), | |
259 | # Mirrors | |
260 | (r"/mirrors", AdminMirrorsHandler), | |
261 | (r"/mirrors/create", AdminMirrorsCreateHandler), | |
262 | (r"/mirrors/delete/([0-9]+)", AdminMirrorsDeleteHandler), | |
263 | (r"/mirrors/edit/([0-9]+)", AdminMirrorsEditHandler), | |
264 | (r"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler), | |
265 | (r"/mirrors/update", AdminMirrorsUpdateHandler), | |
266 | # Fireinfo | |
267 | (r"/fireinfo", AdminFireinfoHandler), | |
268 | # Downloads | |
269 | (r"/downloads", AdminDownloadsHandler), | |
270 | (r"/downloads/mirrors", AdminDownloadsMirrorsHandler), | |
271 | # API | |
272 | (r"/api/planet/render", AdminApiPlanetRenderMarkupHandler) | |
273 | ] + authentication_handlers) | |
274 | ||
275 | # ipfire.org | |
276 | self.add_handlers(r"ipfire\.org", [ | |
277 | (r".*", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org" }) | |
278 | ]) | |
279 | ||
280 | logging.info("Successfully initialied application") | |
281 | ||
282 | def format_month_name(self, handler, month): | |
283 | _ = handler.locale.translate | |
284 | ||
285 | if month == 1: | |
286 | return _("January") | |
287 | elif month == 2: | |
288 | return _("February") | |
289 | elif month == 3: | |
290 | return _("March") | |
291 | elif month == 4: | |
292 | return _("April") | |
293 | elif month == 5: | |
294 | return _("May") | |
295 | elif month == 6: | |
296 | return _("June") | |
297 | elif month == 7: | |
298 | return _("July") | |
299 | elif month == 8: | |
300 | return _("August") | |
301 | elif month == 9: | |
302 | return _("September") | |
303 | elif month == 10: | |
304 | return _("October") | |
305 | elif month == 11: | |
306 | return _("November") | |
307 | elif month == 12: | |
308 | return _("December") | |
309 | ||
310 | return month |