X-Git-Url: http://git.ipfire.org/?p=people%2Fshoehn%2Fipfire.org.git;a=blobdiff_plain;f=webapp%2F__init__.py;h=a6d380baf082e8a06ef7d216b8c527acc8b74ade;hp=a2477a39d6f0465f02ae8d1632441a002d7e40d9;hb=37b5c0cfad98b9520eca5d21d9bcb5eac039204f;hpb=14f8eb86f3524c479ddcf625150565b98d35afac diff --git a/webapp/__init__.py b/webapp/__init__.py index a2477a3..a6d380b 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -1,6 +1,7 @@ #/usr/bin/python import logging +import multiprocessing import os.path import simplejson import tornado.httpserver @@ -20,38 +21,57 @@ BASEDIR = os.path.join(os.path.dirname(__file__), "..") tornado.locale.load_gettext_translations(os.path.join(BASEDIR, "translations"), "webapp") class Application(tornado.web.Application): - def __init__(self): + def __init__(self, **kwargs): + self.__backend = None + settings = dict( cookie_secret = "aXBmaXJlY29va2llc2VjcmV0Cg==", debug = options.debug, gzip = True, login_url = "/login", template_path = os.path.join(BASEDIR, "templates"), + ui_methods = { + "format_month_name" : self.format_month_name, + }, ui_modules = { - "Advertisement" : AdvertisementModule, - "DonationBox" : DonationBoxModule, - "DownloadButton" : DownloadButtonModule, - "Menu" : MenuModule, - "MirrorItem" : MirrorItemModule, - "MirrorsTable" : MirrorsTableModule, - "NewsItem" : NewsItemModule, - "NewsLine" : NewsLineModule, - "NewsTable" : NewsTableModule, - "NewsYearNavigation": NewsYearNavigationModule, - "PlanetEntry" : PlanetEntryModule, - "ReleaseItem" : ReleaseItemModule, - "SidebarBanner" : SidebarBannerModule, - "SidebarRelease" : SidebarReleaseModule, - "StasyTable" : StasyTableModule, - "StasyCPUCoreTable" : StasyCPUCoreTableModule, - "StasyDeviceTable" : StasyDeviceTableModule, - "StasyGeoTable" : StasyGeoTableModule, - "TrackerPeerList": TrackerPeerListModule, - "Wish" : WishModule, - "Wishlist" : WishlistModule, + "Advertisement" : AdvertisementModule, + "DonationBox" : DonationBoxModule, + "DonationButton" : DonationButtonModule, + "DonationInputBox" : DonationInputBoxModule, + "DownloadButton" : DownloadButtonModule, + "LanguageName" : LanguageNameModule, + "Map" : MapModule, + "Menu" : MenuModule, + "MirrorItem" : MirrorItemModule, + "MirrorsTable" : MirrorsTableModule, + "NetBootMenuConfig" : NetBootMenuConfigModule, + "NetBootMenuHeader" : NetBootMenuHeaderModule, + "NetBootMenuSeparator" : NetBootMenuSeparatorModule, + "NewsItem" : NewsItemModule, + "NewsLine" : NewsLineModule, + "NewsTable" : NewsTableModule, + "NewsYearNavigation" : NewsYearNavigationModule, + "PlanetAuthorBox" : PlanetAuthorBoxModule, + "PlanetEntry" : PlanetEntryModule, + "PlanetSearchBox" : PlanetSearchBoxModule, + "ProgressBar" : ProgressBarModule, + "ReleaseItem" : ReleaseItemModule, + "SidebarBanner" : SidebarBannerModule, + "SidebarRelease" : SidebarReleaseModule, + "FireinfoDeviceTable" : FireinfoDeviceTableModule, + "FireinfoDeviceAndGroupsTable" : FireinfoDeviceAndGroupsTableModule, + "FireinfoGeoTable" : FireinfoGeoTableModule, + "TalkCallLog" : TalkCallLogModule, + "TalkLines" : TalkLinesModule, + "TalkOngoingCalls" : TalkOngoingCallsModule, + "TrackerPeerList" : TrackerPeerListModule, + "Wish" : WishModule, + "Wishlist" : WishlistModule, + "WishlistItems" : WishlistItemsModule, }, xsrf_cookies = True, ) + settings.update(kwargs) tornado.web.Application.__init__(self, **settings) @@ -62,6 +82,11 @@ class Application(tornado.web.Application): (r"/(robots\.txt)", tornado.web.StaticFileHandler, dict(path = static_path)), ] + authentication_handlers = [ + (r"/login", LoginHandler), + (r"/logout", LogoutHandler), + ] + self.add_handlers(r"(dev|www)\.ipfire\.(at|org)", [ # Entry site that lead the user to index (r"/", IndexHandler), @@ -71,7 +96,6 @@ class Application(tornado.web.Application): (r"/news", NewsIndexHandler), (r"/news/year/([0-9]*)", NewsYearHandler), (r"/news/(.*)", NewsItemHandler), - (r"/author/(.*)", NewsAuthorHandler), # Download sites (r"/download", DownloadHandler), @@ -80,9 +104,12 @@ class Application(tornado.web.Application): # Handle old pages that have moved elsewhere (r"/screenshots", tornado.web.RedirectHandler, { "url" : "/about" }), (r"/about", tornado.web.RedirectHandler, { "url" : "/features" }), - (r"/support", tornado.web.RedirectHandler, { "url" : "/getinvolved" }), + (r"/features/.*", tornado.web.RedirectHandler, { "url" : "/features" }), + (r"/getinvolved", tornado.web.RedirectHandler, { "url" : "/get-involved" }), - (r"/donate", tornado.web.RedirectHandler, { "url" : "/donation" }), + # Donate + (r"/donate", DonateHandler), + (r"/donation", tornado.web.RedirectHandler, { "url" : "/donate" }), # RSS feed (r"/news.rss", RSSNewsHandler), @@ -96,10 +123,11 @@ class Application(tornado.web.Application): ]) # downloads.ipfire.org - self.add_handlers(r"downloads?\.ipfire\.org", [ + self.add_handlers(r"downloads?(\.dev)?\.ipfire\.org", [ (r"/", DownloadsIndexHandler), (r"/latest", DownloadsLatestHandler), - (r"/release/([0-9]+)", DownloadsReleaseHandler), + (r"/release/(\d)", DownloadsReleaseHandler), + (r"/release/([\w\.\-]*)", DownloadsReleaseHandler), (r"/older", DownloadsOlderHandler), (r"/development", DownloadsDevelopmentHandler), (r"/mirrors", tornado.web.RedirectHandler, { "url" : "http://mirrors.ipfire.org/" }), @@ -111,50 +139,71 @@ class Application(tornado.web.Application): ]) # mirrors.ipfire.org - self.add_handlers(r"mirrors\.ipfire\.org", [ + self.add_handlers(r"mirrors(\.dev)?\.ipfire\.org", [ (r"/", MirrorIndexHandler), - (r"/mirror/([0-9]+)", MirrorItemHandler), + (r"/mirror/(.*)", MirrorItemHandler), + (r"/lists/pakfire2", MirrorListPakfire2Handler), ] + static_handlers) # planet.ipfire.org - self.add_handlers(r"planet\.ipfire\.org", [ + self.add_handlers(r"planet(\.dev)?\.ipfire\.org", [ (r"/", PlanetMainHandler), + (r"/hottest", PlanetHotEntriesHandler), (r"/post/([A-Za-z0-9_-]+)", PlanetPostingHandler), (r"/user/([a-z0-9_-]+)", PlanetUserHandler), + (r"/search", PlanetSearchHandler), + (r"/year/(\d+)", PlanetYearHandler), # RSS (r"/rss", RSSPlanetAllHandler), (r"/user/([a-z0-9_-]+)/rss", RSSPlanetUserHandler), + (r"/news.rss", tornado.web.RedirectHandler, { "url" : "/rss" }), ] + static_handlers) - # stasy.ipfire.org - self.add_handlers(r"fireinfo\.ipfire\.org", [ - (r"/", StasyIndexHandler), - (r"/profile/([a-z0-9]{40})", StasyProfileDetailHandler), - (r"/vendor/(pci|usb)/([0-9a-f]{4})", StasyStatsVendorDetail), - (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", StasyStatsModelDetail), + # fireinfo.ipfire.org + self.add_handlers(r"fireinfo(\.dev)?\.ipfire\.org", [ + (r"/", FireinfoIndexHandler), + (r"/device/driver/(.*)", FireinfoDeviceDriverDetail), + (r"/device/vendors", FireinfoDeviceVendorsHandler), + (r"/device/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorHandler), + (r"/device/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelHandler), + + # Show profiles + (r"/profile/random", FireinfoRandomProfileHandler), + (r"/profile/([a-z0-9]{40})", FireinfoProfileDetailHandler), # Send profiles. - (r"/send/([a-z0-9]+)", StasyProfileSendHandler), - - # Stats handlers - (r"/stats", StasyStatsHandler), - (r"/stats/cpus", StasyStatsCPUHandler), - (r"/stats/cpuflags", StasyStatsCPUFlagsHandler), - (r"/stats/geo", StasyStatsGeoHandler), - (r"/stats/memory", StasyStatsMemoryHandler), - (r"/stats/network", StasyStatsNetworkHandler), - (r"/stats/oses", StasyStatsOSesHandler), - (r"/stats/virtual", StasyStatsVirtualHandler), + (r"/send/([a-z0-9]+)", FireinfoProfileSendHandler), + + # Stats handlers + (r"/statistics", FireinfoStatsHandler), + (r"/statistics/processors", FireinfoStatsProcessorsHandler), + (r"/statistics/processors/(arm|x86)", FireinfoStatsProcessorDetailHandler), + (r"/statistics/geo-locations", FireinfoStatsGeoHandler), + (r"/statistics/languages", FireinfoStatsLanguagesHandler), + (r"/statistics/memory", FireinfoStatsMemoryHandler), + (r"/statistics/networking", FireinfoStatsNetworkingHandler), + (r"/statistics/releases", FireinfoStatsReleasesHandler), + (r"/statistics/virtualization", FireinfoStatsVirtualHandler), + + # Compat handlers + (r"/stats", tornado.web.RedirectHandler, { "url" : "/statistics" }), + (r"/stats/cpus", tornado.web.RedirectHandler, { "url" : "/statistics/processors" }), + (r"/stats/geo", tornado.web.RedirectHandler, { "url" : "/statistics/geo-locations" }), + (r"/stats/network", tornado.web.RedirectHandler, { "url" : "/statistics/networking" }), + (r"/stats/oses", tornado.web.RedirectHandler, { "url" : "/statistics/releases" }), + (r"/stats/virtual", tornado.web.RedirectHandler, { "url" : "/statistics/virtualization" }), + (r"/vendor/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorCompatHandler), + (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelCompatHandler), ] + static_handlers) # i-use.ipfire.org - self.add_handlers(r"i-use\.ipfire\.org", [ + self.add_handlers(r"i-use(\.dev)?\.ipfire\.org", [ (r"/profile/([a-f0-9]{40})/([0-9]+).png", IUseImage), ]) # tracker.ipfire.org - self.add_handlers(r"(torrent|tracker)\.ipfire\.org", [ + self.add_handlers(r"(torrent|tracker)(\.dev)?\.ipfire\.org", [ (r"/", TrackerIndexHandler), (r"/announce.*", TrackerAnnounceHandler), (r"/scrape", TrackerScrapeHandler), @@ -165,27 +214,28 @@ class Application(tornado.web.Application): # boot.ipfire.org BOOT_STATIC_PATH = os.path.join(self.settings["static_path"], "netboot") - self.add_handlers(r"boot\.ipfire\.org", [ + self.add_handlers(r"boot(\.dev)?\.ipfire\.org", [ (r"/", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org/download" }), # Configurations + (r"/premenu.cfg", PremenuCfgHandler), (r"/menu.gpxe", MenuGPXEHandler), (r"/menu.cfg", MenuCfgHandler), - (r"/config/([0-9]+)/boot.gpxe", BootGPXEHandler), # Static files - (r"/(boot.png|custom.gpxe|premenu.cfg|vesamenu.c32|menu.c32)", + (r"/(boot\.png|pxelinux\.0|menu\.c32|vesamenu\.c32)", tornado.web.StaticFileHandler, { "path" : BOOT_STATIC_PATH }), ]) # nopaste.ipfire.org - self.add_handlers(r"nopaste\.ipfire\.org", [ - (r"/", NopasteIndexHandler), - (r"/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", NopasteEntryHandler), - ] + static_handlers) + self.add_handlers(r"nopaste(\.dev)?\.ipfire\.org", [ + (r"/", NopasteCreateHandler), + (r"/raw/(.*)", NopasteRawHandler), + (r"/view/(.*)", NopasteViewHandler), + ] + authentication_handlers + static_handlers) # wishlist.ipfire.org - self.add_handlers(r"wishlist\.ipfire\.org", [ + self.add_handlers(r"wishlist(\.dev)?\.ipfire\.org", [ (r"/", WishlistIndexHandler), (r"/closed", WishlistClosedHandler), (r"/wish/(.*)/donate", WishDonateHandler), @@ -193,11 +243,31 @@ class Application(tornado.web.Application): (r"/terms", WishlistTermsHandler), ] + static_handlers) + # geoip.ipfire.org + self.add_handlers(r"geoip(\.dev)?\.ipfire\.org", [ + (r"/", GeoIPHandler), + ] + static_handlers) + + # talk.ipfire.org + self.add_handlers(r"talk(\.dev)?\.ipfire\.org", [ + (r"/", TalkIndexHandler), + (r"/call/(\d+)", TalkInitiateCallHandler), + (r"/conferences", TalkConferencesHandler), + (r"/conferences/(\d+)/invite/(\d+)", TalkConferencesInviteHandler), + (r"/diagnosis", TalkDiagnosisHandler), + (r"/phonebook/(\w+)", TalkPhonebookAccountHandler), + (r"/phonebook", TalkPhonebookHandler), + (r"/profile", TalkProfileHandler), + ] + authentication_handlers + static_handlers) + + # accounts.ipfire.org + self.add_handlers(r"accounts(\.dev)?\.ipfire\.org", [ + (r"/avatar/(\w+)\.jpg", AccountsAvatarHandler), + ] + static_handlers) + # admin.ipfire.org - self.add_handlers(r"admin\.ipfire\.org", [ + self.add_handlers(r"admin(\.dev)?\.ipfire\.org", [ (r"/", AdminIndexHandler), - (r"/login", AdminLoginHandler), - (r"/logout", AdminLogoutHandler), # Accounts (r"/accounts", AdminAccountsHandler), #(r"/accounts/delete/([0-9]+)", AdminAccountsDeleteHandler), @@ -205,7 +275,8 @@ class Application(tornado.web.Application): # Planet (r"/planet", AdminPlanetHandler), (r"/planet/compose", AdminPlanetComposeHandler), - (r"/planet/edit/([0-9]+)", AdminPlanetEditHandler), + (r"/planet/edit/(.*)", AdminPlanetEditHandler), + (r"/planet/publish/(.*)", AdminPlanetPublishHandler), # Mirrors (r"/mirrors", AdminMirrorsHandler), (r"/mirrors/create", AdminMirrorsCreateHandler), @@ -214,13 +285,13 @@ class Application(tornado.web.Application): (r"/mirrors/details/([0-9]+)", AdminMirrorsDetailsHandler), (r"/mirrors/update", AdminMirrorsUpdateHandler), # Fireinfo - (r"/fireinfo/stats", AdminFireinfoStatsHandler), + (r"/fireinfo", AdminFireinfoHandler), # Downloads (r"/downloads", AdminDownloadsHandler), (r"/downloads/mirrors", AdminDownloadsMirrorsHandler), # API (r"/api/planet/render", AdminApiPlanetRenderMarkupHandler) - ] + static_handlers) + ] + authentication_handlers + static_handlers) # ipfire.org self.add_handlers(r".*", [ @@ -234,6 +305,18 @@ class Application(tornado.web.Application): def __del__(self): logging.info("Shutting down application") + @property + def backend(self): + if self.__backend is None: + configfile = self.settings.get("configfile", None) + if not configfile: + raise RuntimeException("Could not find configuration file") + + self.__backend = backend.Backend(configfile=configfile, + debug=self.settings.get("debug", False)) + + return self.__backend + @property def ioloop(self): return tornado.ioloop.IOLoop.instance() @@ -249,11 +332,13 @@ class Application(tornado.web.Application): http_server = tornado.httpserver.HTTPServer(self, xheaders=True) + num_processes = multiprocessing.cpu_count() / 2 + # If we are not running in debug mode, we can actually run multiple # frontends to get best performance out of our service. if not self.settings["debug"]: http_server.bind(port) - http_server.start(num_processes=4) + http_server.start(num_processes=num_processes) else: http_server.listen(port) @@ -264,3 +349,33 @@ class Application(tornado.web.Application): def reload(self): logging.debug("Caught reload signal") + + def format_month_name(self, handler, month): + _ = handler.locale.translate + + if month == 1: + return _("January") + elif month == 2: + return _("February") + elif month == 3: + return _("March") + elif month == 4: + return _("April") + elif month == 5: + return _("May") + elif month == 6: + return _("June") + elif month == 7: + return _("July") + elif month == 8: + return _("August") + elif month == 9: + return _("September") + elif month == 10: + return _("October") + elif month == 11: + return _("November") + elif month == 12: + return _("December") + + return month