11 from handlers
import *
14 from . import download
15 from . import location
16 from . import ui_modules
18 class Application(tornado
.web
.Application
):
19 def __init__(self
, config
, **kwargs
):
21 self
.backend
= ipfire
.Backend(config
)
24 # Do not compress responses
28 "xsrf_cookies" : True,
31 "login_url" : "/login",
33 # Setup directory structure
34 "static_path" : self
.backend
.config
.get("global", "static_dir"),
35 "template_path" : self
.backend
.config
.get("global", "templates_dir"),
39 "format_month_name" : self
.format_month_name
,
42 "Menu" : ui_modules
.MenuModule
,
45 "BlogHistoryNavigation": blog
.HistoryNavigationModule
,
46 "BlogList" : blog
.ListModule
,
47 "BlogPost" : blog
.PostModule
,
48 "BlogPosts" : blog
.PostsModule
,
51 "DownloadButton" : download
.ButtonModule
,
54 "Map" : ui_modules
.MapModule
,
57 "LanguageName" : ui_modules
.LanguageNameModule
,
59 "MirrorItem" : ui_modules
.MirrorItemModule
,
60 "MirrorsTable" : ui_modules
.MirrorsTableModule
,
61 "NetBootMenuConfig" : ui_modules
.NetBootMenuConfigModule
,
62 "NetBootMenuHeader" : ui_modules
.NetBootMenuHeaderModule
,
63 "NetBootMenuSeparator" : ui_modules
.NetBootMenuSeparatorModule
,
64 "ProgressBar" : ui_modules
.ProgressBarModule
,
65 "FireinfoDeviceTable" : ui_modules
.FireinfoDeviceTableModule
,
66 "FireinfoDeviceAndGroupsTable" : ui_modules
.FireinfoDeviceAndGroupsTableModule
,
67 "FireinfoGeoTable" : ui_modules
.FireinfoGeoTableModule
,
68 "TalkContact" : ui_modules
.TalkContactModule
,
69 "TalkCallLog" : ui_modules
.TalkCallLogModule
,
70 "TalkLines" : ui_modules
.TalkLinesModule
,
71 "TalkOngoingCalls" : ui_modules
.TalkOngoingCallsModule
,
74 # Call this when a page wasn't found
75 "default_handler_class" : NotFoundHandler
,
77 settings
.update(kwargs
)
79 tornado
.web
.Application
.__init
__(self
, **settings
)
81 authentication_handlers
= [
82 (r
"/login", LoginHandler
),
83 (r
"/logout", LogoutHandler
),
86 self
.add_handlers(r
"(dev|www)\.ipfire\.(at|org)", [
87 # Entry site that lead the user to index
91 (r
"/downloads", tornado
.web
.RedirectHandler
, { "url" : "/download" }),
92 (r
"/download", download
.IndexHandler
),
93 (r
"/download/([0-9a-z\-\.]+)", download
.ReleaseHandler
),
96 (r
"/donate", DonateHandler
),
97 (r
"/donation", tornado
.web
.RedirectHandler
, { "url" : "/donate" }),
100 (r
"/news.rss", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/feed.xml" }),
102 # Redirect news articles to blog
103 (r
"/news/(.*)", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/posts/{1}" }),
106 (r
"/chat", StaticHandler
, { "template" : "chat.html" }),
107 (r
"/features", StaticHandler
, { "template" : "features.html" }),
108 (r
"/get-involved", StaticHandler
, { "template" : "get-involved.html" }),
109 (r
"/get-started", StaticHandler
, { "template" : "get-started.html" }),
110 (r
"/get-support", StaticHandler
, { "template" : "get-support.html" }),
111 (r
"/hardware", StaticHandler
, { "template" : "hardware.html" }),
112 (r
"/legal", StaticHandler
, { "template" : "legal.html" }),
114 # Handle old pages that have moved elsewhere
115 (r
"/imprint", tornado
.web
.RedirectHandler
, { "url" : "/legal" }),
116 (r
"/(de|en)/(.*)", LangCompatHandler
),
118 # Export arbitrary error pages
119 (r
"/error/([45][0-9]{2})", ErrorHandler
),
123 self
.add_handlers(r
"blog(\.dev)?\.ipfire\.org", [
124 (r
"/", blog
.IndexHandler
),
125 (r
"/authors/(\w+)", blog
.AuthorHandler
),
126 (r
"/post/(.*)", blog
.PostHandler
),
127 (r
"/search", blog
.SearchHandler
),
128 (r
"/tags/([0-9a-z\-\.]+)", blog
.TagHandler
),
129 (r
"/years/([0-9]+)", blog
.YearHandler
),
132 (r
"/feed.xml", blog
.FeedHandler
),
135 # downloads.ipfire.org
136 self
.add_handlers(r
"downloads?(\.dev)?\.ipfire\.org", [
137 (r
"/", tornado
.web
.RedirectHandler
, { "url" : "https://www.ipfire.org/" }),
138 (r
"/(.*)", download
.FileHandler
),
142 self
.add_handlers(r
"mirrors(\.dev)?\.ipfire\.org", [
143 (r
"/", MirrorIndexHandler
),
144 (r
"/mirror/(.*)", MirrorItemHandler
),
148 self
.add_handlers(r
"planet(\.dev)?\.ipfire\.org", [
149 (r
"/", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/" }),
150 (r
"/post/([A-Za-z0-9_-]+)", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/posts/{1}" }),
151 (r
"/user/([a-z0-9_-]+)", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/authors/{1}" }),
154 (r
"/rss", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/feed.xml" }),
155 (r
"/user/([a-z0-9_-]+)/rss", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/authors/{1}.rss" }),
156 (r
"/news.rss", tornado
.web
.RedirectHandler
, { "url" : "https://blog.ipfire.org/feed.xml" }),
159 # fireinfo.ipfire.org
160 self
.add_handlers(r
"fireinfo(\.dev)?\.ipfire\.org", [
161 (r
"/", FireinfoIndexHandler
),
162 (r
"/device/driver/(.*)", FireinfoDeviceDriverDetail
),
163 (r
"/device/vendors", FireinfoDeviceVendorsHandler
),
164 (r
"/device/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorHandler
),
165 (r
"/device/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelHandler
),
168 (r
"/profile/random", FireinfoRandomProfileHandler
),
169 (r
"/profile/([a-z0-9]{40})", FireinfoProfileDetailHandler
),
172 (r
"/send/([a-z0-9]+)", FireinfoProfileSendHandler
),
175 (r
"/statistics", FireinfoStatsHandler
),
176 (r
"/statistics/processors", FireinfoStatsProcessorsHandler
),
177 (r
"/statistics/processors/(arm|x86)", FireinfoStatsProcessorDetailHandler
),
178 (r
"/statistics/geo-locations", FireinfoStatsGeoHandler
),
179 (r
"/statistics/languages", FireinfoStatsLanguagesHandler
),
180 (r
"/statistics/memory", FireinfoStatsMemoryHandler
),
181 (r
"/statistics/networking", FireinfoStatsNetworkingHandler
),
182 (r
"/statistics/releases", FireinfoStatsReleasesHandler
),
183 (r
"/statistics/virtualization", FireinfoStatsVirtualHandler
),
186 (r
"/stats", tornado
.web
.RedirectHandler
, { "url" : "/statistics" }),
187 (r
"/stats/cpus", tornado
.web
.RedirectHandler
, { "url" : "/statistics/processors" }),
188 (r
"/stats/geo", tornado
.web
.RedirectHandler
, { "url" : "/statistics/geo-locations" }),
189 (r
"/stats/network", tornado
.web
.RedirectHandler
, { "url" : "/statistics/networking" }),
190 (r
"/stats/oses", tornado
.web
.RedirectHandler
, { "url" : "/statistics/releases" }),
191 (r
"/stats/virtual", tornado
.web
.RedirectHandler
, { "url" : "/statistics/virtualization" }),
192 (r
"/vendor/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorCompatHandler
),
193 (r
"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelCompatHandler
),
197 self
.add_handlers(r
"i-use(\.dev)?\.ipfire\.org", [
198 (r
"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage
),
202 BOOT_STATIC_PATH
= os
.path
.join(self
.settings
["static_path"], "netboot")
203 self
.add_handlers(r
"boot(\.dev)?\.ipfire\.org", [
204 (r
"/", tornado
.web
.RedirectHandler
, { "url" : "https://www.ipfire.org/download" }),
207 (r
"/premenu.cfg", PremenuCfgHandler
),
208 (r
"/menu.gpxe", MenuGPXEHandler
),
209 (r
"/menu.cfg", MenuCfgHandler
),
212 (r
"/(boot\.png|pxelinux\.0|menu\.c32|vesamenu\.c32)",
213 tornado
.web
.StaticFileHandler
, { "path" : BOOT_STATIC_PATH
}),
217 self
.add_handlers(r
"nopaste(\.dev)?\.ipfire\.org", [
218 (r
"/", NopasteCreateHandler
),
219 (r
"/raw/(.*)", NopasteRawHandler
),
220 (r
"/view/(.*)", NopasteViewHandler
),
221 ] + authentication_handlers
)
223 # location.ipfire.org
224 self
.add_handlers(r
"location(\.dev)?\.ipfire\.org", [
225 (r
"/", location
.IndexHandler
),
226 (r
"/lookup/(.+)", location
.LookupHandler
),
230 self
.add_handlers(r
"geoip(\.dev)?\.ipfire\.org", [
231 (r
"/", tornado
.web
.RedirectHandler
, { "url" : "https://location.ipfire.org/" }),
235 self
.add_handlers(r
"talk(\.dev)?\.ipfire\.org", [
236 (r
"/", TalkIndexHandler
),
237 (r
"/conferences", TalkConferencesHandler
),
238 (r
"/diagnosis", TalkDiagnosisHandler
),
239 (r
"/hangup/(.*)", TalkHangupChannelHandler
),
240 (r
"/phonebook/(\w+)", TalkPhonebookAccountHandler
),
241 (r
"/phonebook", TalkPhonebookHandler
),
242 (r
"/profile", TalkProfileHandler
),
243 ] + authentication_handlers
)
245 # accounts.ipfire.org
246 self
.add_handlers(r
"accounts(\.dev)?\.ipfire\.org", [
247 (r
"/avatar/(\w+)\.jpg", AccountsAvatarHandler
),
251 self
.add_handlers(r
"admin(\.dev)?\.ipfire\.org", [
252 (r
"/", AdminIndexHandler
),
254 (r
"/accounts", AdminAccountsHandler
),
255 #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler),
256 #(r"/accounts/edit/([0-9]+)", AdminAccountsEditHandler),
258 (r
"/planet", AdminPlanetHandler
),
259 (r
"/planet/compose", AdminPlanetComposeHandler
),
260 (r
"/planet/edit/(.*)", AdminPlanetEditHandler
),
261 (r
"/planet/publish/(.*)", AdminPlanetPublishHandler
),
263 (r
"/mirrors", AdminMirrorsHandler
),
264 (r
"/mirrors/create", AdminMirrorsCreateHandler
),
265 (r
"/mirrors/delete/([0-9]+)", AdminMirrorsDeleteHandler
),
266 (r
"/mirrors/edit/([0-9]+)", AdminMirrorsEditHandler
),
267 (r
"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler
),
268 (r
"/mirrors/update", AdminMirrorsUpdateHandler
),
270 (r
"/fireinfo", AdminFireinfoHandler
),
272 (r
"/downloads", AdminDownloadsHandler
),
273 (r
"/downloads/mirrors", AdminDownloadsMirrorsHandler
),
275 (r
"/api/planet/render", AdminApiPlanetRenderMarkupHandler
)
276 ] + authentication_handlers
)
279 self
.add_handlers(r
"ipfire\.org", [
280 (r
".*", tornado
.web
.RedirectHandler
, { "url" : "https://www.ipfire.org" })
283 logging
.info("Successfully initialied application")
285 def format_month_name(self
, handler
, month
):
286 _
= handler
.locale
.translate
305 return _("September")