1 from twisted.web2 import resource, static, responsecode, http, http_headers
2 from twisted.python import util
4 from Components.config import config
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 from ServiceListSave import ServiceList
14 from RedirecToCurrentStream import RedirecToCurrentStreamResource
16 class Toplevel(resource.Resource):
18 def __init__(self,session):
19 self.session = session
20 resource.Resource.__init__(self)
22 self.putChild("web",ScreenPage(self.session,util.sibpath(WebInterface.__file__, "web"))) # "/web/*"
23 self.putChild("web-data",static.File(util.sibpath(WebInterface.__file__, "web-data"))) # FIXME: web-data appears as webdata
24 self.putChild("file",FileStreamer())
25 self.putChild("grab",GrabResource())
26 self.putChild("ipkg",IPKGResource())
27 self.putChild("play",ServiceplayerResource(self.session))
28 self.putChild("wap",RedirectorResource("/web/wap/"))# shorten and simplify url to wap-pages
29 self.putChild("upload",UploadResource())
30 self.putChild("servicelist",ServiceList(self.session))
31 self.putChild("streamcurrent",RedirecToCurrentStreamResource(session))
33 if config.plugins.Webinterface.includehdd.value is True:
34 self.putChild("hdd",static.File("/hdd"))
36 def render(self, req):
37 fp = open(util.sibpath(WebInterface.__file__, "web-data/tpl/default")+"/index.html")
40 return http.Response(responsecode.OK, {'Content-type': http_headers.MimeType('text', 'html')},stream=s)
42 def locateChild(self, request, segments):
43 print "[WebIf]",request.remoteAddr.host,request.method,request.path,request.args
44 return resource.Resource.locateChild(self, request, segments)
46 class RedirectorResource(resource.Resource):
48 this class can be used to redirect a request to a specified uri
50 def __init__(self,uri):
52 resource.Resource.__init__(self)
53 def render(self, req):
54 return http.RedirectResponse(self.uri)