Files can now be downloaded
[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 FileStreamer import FileStreamer
9 from Screengrab import GrabResource
10 from IPKG import IPKGResource
11 from PlayService import ServiceplayerResource
12 from Uploader import UploadResource
13
14 class Toplevel(resource.Resource):
15     addSlash = True
16     def __init__(self,session):
17         self.session = session
18         resource.Resource.__init__(self)
19         
20         self.putChild("web",ScreenPage(self.session,util.sibpath(WebInterface.__file__, "web"))) # "/web/*"
21         self.putChild("webdata",static.File(util.sibpath(WebInterface.__file__, "web-data"))) # FIXME: web-data appears as webdata
22         self.putChild("file",FileStreamer())
23         self.putChild("grab",GrabResource())
24         self.putChild("ipkg",IPKGResource())
25         self.putChild("play",ServiceplayerResource(self.session))
26         self.putChild("wap",RedirectorResource("/web/wap/"))# shorten and simplify url to wap-pages
27         self.putChild("upload",UploadResource())
28         
29         if config.plugins.Webinterface.includehdd.value:
30             self.putChild("hdd",static.File("/hdd"))
31         
32     def render(self, req):
33         fp = open(util.sibpath(WebInterface.__file__, "web-data")+"/index.html")
34         s = fp.read()
35         fp.close()
36         return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},stream=s)
37
38     def locateChild(self, request, segments):
39         print "[WebIf]",request.remoteAddr.host,request.method,request.path,request.args
40         return resource.Resource.locateChild(self, request, segments)
41
42 class RedirectorResource(resource.Resource):
43     """ 
44         this class can be used to redirect a request to a specified uri
45     """
46     def __init__(self,uri):
47         self.uri = uri
48         resource.Resource.__init__(self)
49     def render(self, req):
50         return http.RedirectResponse(self.uri)
51
52