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