add redirect from old /wap to new /web/wap
[enigma2-plugins.git] / webinterface / src / WebChilds / Toplevel.py
1 from twisted.web2 import resource, static, responsecode, http, http_headers
2 from twisted.python import util
3
4 from Components.config import config
5
6 from Plugins.Extensions import WebInterface
7 from Screenpage import ScreenPage
8 from MovieStreamer import MovieStreamer
9 from Screengrab import GrabResource
10 from IPKG import IPKGResource
11
12 class Toplevel(resource.Resource):
13     addSlash = True
14     def __init__(self,session):
15         self.session = session
16         resource.Resource.__init__(self)
17         
18         self.putChild("web",ScreenPage(self.session,util.sibpath(WebInterface.__file__, "web"))) # "/web/*"
19         self.putChild("webdata",static.File(util.sibpath(WebInterface.__file__, "web-data"))) # FIXME: web-data appears as webdata
20         self.putChild("movie",MovieStreamer())
21         self.putChild("grab",GrabResource())
22         self.putChild("ipkg",IPKGResource())
23         self.putChild("wap",RedirectorResource("/web/wap/"))# shorten and simplify url to wap-pages
24         
25         if config.plugins.Webinterface.includehdd.value:
26             self.putChild("hdd",static.File("/hdd"))
27         
28     def render(self, req):
29         fp = open(util.sibpath(WebInterface.__file__, "web-data")+"/index.html")
30         s = fp.read()
31         fp.close()
32         return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},stream=s)
33
34     def locateChild(self, request, segments):
35         print "[WebIf]",request.remoteAddr.host,request.method,request.path,request.args
36         return resource.Resource.locateChild(self, request, segments)
37
38 class RedirectorResource(resource.Resource):
39     """ 
40         this class can be used to redirect a request to a specified uri
41     """
42     def __init__(self,uri):
43         self.uri = uri
44         resource.Resource.__init__(self)
45     def render(self, req):
46         return http.RedirectResponse(self.uri)
47