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