]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/webapp/__init__.py
fireinfo: Fix 8GB on memory chart.
[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
8import tornado.options
9import tornado.web
10
940227cb 11import backend
feb02477 12
8ccd2ff0
MT
13from handlers import *
14from ui_modules import *
81675874 15
16BASEDIR = os.path.join(os.path.dirname(__file__), "..")
17
18tornado.locale.load_translations(os.path.join(BASEDIR, "translations"))
81675874 19
20class 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 66 # RSS feed
bcc3ed4d 67 (r"/news.rss", RSSNewsHandler),
de683d7c
MT
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),
bcc3ed4d
MT
101
102 # RSS
103 (r"/rss", RSSPlanetAllHandler),
104 (r"/user/([a-z0-9_-]+)/rss", RSSPlanetUserHandler),
d0d074e0
MT
105 ] + static_handlers)
106
940227cb 107 # stasy.ipfire.org
91a446f0 108 self.add_handlers(r"(fireinfo|stasy)\.ipfire\.org", [
940227cb 109 (r"/", StasyIndexHandler),
91a446f0
MT
110 (r"/profile/([a-z0-9]{40})", StasyProfileDetailHandler),
111 (r"/vendor/(pci|usb)/([0-9a-f]{4})", StasyStatsVendorDetail),
112 (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", StasyStatsModelDetail),
113
114 # Stats handlers
115 (r"/stats", StasyStatsHandler),
116 (r"/stats/cpus", StasyStatsCPUHandler),
117 (r"/stats/cpuflags", StasyStatsCPUFlagsHandler),
118 (r"/stats/geo", StasyStatsGeoHandler),
119 (r"/stats/memory", StasyStatsMemoryHandler),
54af860e 120 (r"/stats/network", StasyStatsNetworkHandler),
91a446f0
MT
121 (r"/stats/oses", StasyStatsOSesHandler),
122 (r"/stats/virtual", StasyStatsVirtualHandler),
ae0228e1 123 ] + static_handlers)
5cf160e0 124
c37ec602
MT
125 # i-use.ipfire.org
126 self.add_handlers(r"i-use\.ipfire\.org", [
127 (r"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage),
128 ])
129
5cf160e0 130 # tracker.ipfire.org
940227cb
MT
131 self.add_handlers(r"(torrent|tracker)\.ipfire\.org", [
132 (r"/", TrackerIndexHandler),
43d991f6 133 (r"/a.*", TrackerAnnounceHandler),
e2afbd6a 134 (r"/scrape", TrackerScrapeHandler),
940227cb 135 (r"/torrent/([0-9a-f]+)", TrackerDetailHandler),
ae0228e1
MT
136 ] + static_handlers)
137
d0d074e0
MT
138 # admin.ipfire.org
139 self.add_handlers(r"admin\.ipfire\.org", [
140 (r"/", AdminIndexHandler),
940227cb
MT
141 (r"/login", AdminLoginHandler),
142 (r"/logout", AdminLogoutHandler),
d0d074e0
MT
143 # Accounts
144 (r"/accounts", AdminAccountsHandler),
940227cb
MT
145 #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler),
146 #(r"/accounts/edit/([0-9]+)", AdminAccountsEditHandler),
d0d074e0
MT
147 # Planet
148 (r"/planet", AdminPlanetHandler),
149 (r"/planet/compose", AdminPlanetComposeHandler),
150 (r"/planet/edit/([0-9]+)", AdminPlanetEditHandler),
940227cb
MT
151 # Mirrors
152 (r"/mirrors", AdminMirrorsHandler),
153 (r"/mirrors/create", AdminMirrorsCreateHandler),
154 (r"/mirrors/delete/([0-9]+)", AdminMirrorsDeleteHandler),
155 (r"/mirrors/edit/([0-9]+)", AdminMirrorsEditHandler),
156 (r"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler),
157 (r"/mirrors/update", AdminMirrorsUpdateHandler),
d0d074e0
MT
158 # API
159 (r"/api/planet/render", AdminApiPlanetRenderMarkupHandler)
160 ] + static_handlers)
161
ae0228e1 162 # ipfire.org
3add293a 163 self.add_handlers(r".*", [
ae0228e1 164 (r".*", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org" })
5cf160e0 165 ])
3add293a 166
feb02477
MT
167 logging.info("Successfully initialied application")
168
169 self.__running = True
170
3add293a 171 def __del__(self):
feb02477
MT
172 logging.info("Shutting down application")
173
feb02477
MT
174 @property
175 def ioloop(self):
176 return tornado.ioloop.IOLoop.instance()
177
940227cb 178 def shutdown(self, *args):
feb02477
MT
179 logging.debug("Caught shutdown signal")
180 self.ioloop.stop()
181
182 self.__running = False
183
184 def run(self, port=8001):
185 logging.debug("Going to background")
186
187 http_server = tornado.httpserver.HTTPServer(self, xheaders=True)
feb02477 188
940227cb
MT
189 # If we are not running in debug mode, we can actually run multiple
190 # frontends to get best performance out of our service.
191 if not self.settings["debug"]:
192 http_server.bind(port)
193 http_server.start(num_processes=4)
194 else:
195 http_server.listen(port)
de683d7c
MT
196
197 # All requests should be done after 30 seconds or they will be killed.
198 self.ioloop.set_blocking_log_threshold(30)
feb02477 199
940227cb 200 self.ioloop.start()
feb02477
MT
201
202 def reload(self):
203 logging.debug("Caught reload signal")