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