Web gui organization

parent da92a8ad
...@@ -88,6 +88,7 @@ class RootPage(rend.Page): ...@@ -88,6 +88,7 @@ class RootPage(rend.Page):
self.avatarId=avatarId self.avatarId=avatarId
self.putChild('favicon.ico', static.File(curdir+'/Web/resources/img/favicon.ico')) self.putChild('favicon.ico', static.File(curdir+'/Web/resources/img/favicon.ico'))
self.putChild('crossdomain.xml', static.File(curdir+'/Web/resources/xml/crossdomain.xml')) self.putChild('crossdomain.xml', static.File(curdir+'/Web/resources/xml/crossdomain.xml'))
self.putChild('sockjs.min.js', static.File(curdir+'/Web/resources/js/sockjs.min.js'))
def renderHTML(self, ctx): def renderHTML(self, ctx):
request = inevow.IRequest(ctx) request = inevow.IRequest(ctx)
...@@ -103,11 +104,9 @@ class RootPage(rend.Page): ...@@ -103,11 +104,9 @@ class RootPage(rend.Page):
def child_rest(self, ctx): def child_rest(self, ctx):
if str(self.core.configGet('web', 'enablerestgui')).lower() in ['yes', '1', 'y','true']: self.rest = rest.RestPages()
self.rest = rest.RestPages() self.rest.core = self.core
self.rest.core = self.core return self.rest
return self.rest
return self.childFactory(ctx, 'rest')
def child_rawplugin(self, ctx): def child_rawplugin(self, ctx):
request = inevow.IRequest(ctx) request = inevow.IRequest(ctx)
...@@ -134,71 +133,9 @@ class RootPage(rend.Page): ...@@ -134,71 +133,9 @@ class RootPage(rend.Page):
log.debug("no plugin name in request") log.debug("no plugin name in request")
return self.childFactory(ctx, 'rawplugin') return self.childFactory(ctx, 'rawplugin')
def _addPermissions(self, ctx, name, session, request):
def addPerms(dbres, ctx, name, session, request):
try:
log.info(dbres)
if dbres and len(dbres)>0:
session.dmpermissions[request.path]=dbres[0][0]
if neededPermission(request.method) in session.dmpermissions[request.path]:
log.info("PERMISSION DB OK, USER: "+session.mind.perms.username+" SESSION: "+str(session.uid)) #+" ARGS: "+str(request.args)+" REQ "+str(request))
self.core.updateSession(session.uid, session, self)
return rend.Page.locateChild(self, ctx, name)
except:
try:
log.info("Error getting permission from DB USER: "+session.mind.perms.username+" SESSION: "+str(session.uid)+" ARGS: "+str(request.args)+" REQ "+str(request))
except:
log.info("Error getting permission from DB USER: GUEST SESSION: "+str(session.uid)+" ARGS: "+str(request.args)+" REQ "+str(request))
try:
log.info("PERMISSION DB DENIED, USER: "+session.mind.perms.username+" SESSION: "+str(session.uid)+" ARGS: "+str(request.args)+" REQ "+str(request))
except:
log.info("PERMISSION DB DENIED, USER: GUEST SESSION: "+str(session.uid)+" ARGS: "+str(request.args)+" REQ "+str(request))
return permissionDenied(), ()
if not 'dmpermissions' in dir(session):
session.dmpermissions={}
if not request.path in session.dmpermissions.keys():
session.dmpermissions[request.path] = 'none'
try:
log.info("SESS: "+str(session.uid)+" MIND: "+str(session.mind.perms)+" DMPERMS "+str(session.dmpermissions))
return self.core.getPermissionForPath(session.mind.perms.username, request.path).addCallback(
addPerms, ctx, name, session, request
)
except:
log.info("USERS HAS NO MIND??? "+str(request.path)+" "+str(session.uid)+" "+str(request.args)+" REQ "+str(request)+" "+str(session.dmpermissions))
if 'username' in session.dmpermissions.keys():
log.debug("BUT IT HAS DMPERMISSION... "+str(session.dmpermissions))
return self.core.getPermissionForPath(session.dmpermissions['username'], request.path).addCallback(
addPerms, ctx, name, session, request
)
else:
log.debug("ALSO NO USERNAME IN DMPERMISSION "+str(session.uid))
return self.core.getPermissionForPath('guest', request.path).addCallback(
addPerms, ctx, name, session, request
)
def locateChild(self, ctx, name): def locateChild(self, ctx, name):
session = inevow.ISession(ctx) return rend.Page.locateChild(self, ctx, name)
request = inevow.IRequest(ctx)
try:
uname = session.mind.perms.username
except:
uname = 'guest'
if not 'sse' in dir(session):
session.sse = False
if not 'dmpermissions' in dir(session):
session.dmpermissions={}
if request.path in WEB_SYSTEM_PATHS:
log.info("WEB_SYSTEM_PATH: USER: "+uname+" SESSION: "+str(session.uid)) #+" ARGS: "+str(request.args)+" REQ "+str(request))
return rend.Page.locateChild(self, ctx, name)
if request.path in session.dmpermissions.keys():
if neededPermission(request.method) in session.dmpermissions[request.path]:
log.debug("PERMISSION OK, SESSION: "+str(session.uid)) #+" ARGS: "+str(request.args)+" REQ "+str(request))
self.core.updateSession(session.uid, session, self)
return rend.Page.locateChild(self, ctx, name)
else:
return self._addPermissions(ctx, name, session, request)
log.debug("PERMISSION DENIED, SESSION: "+str(session.uid)+" ARGS: "+str(request.args)+" REQ "+str(request))
return permissionDenied(), ()
def child_(self, ctx): def child_(self, ctx):
...@@ -206,22 +143,14 @@ class RootPage(rend.Page): ...@@ -206,22 +143,14 @@ class RootPage(rend.Page):
Redirecting... Redirecting...
""" """
request = inevow.IRequest(ctx) request = inevow.IRequest(ctx)
host=request.getHeader('host')
log.debug("HOST CALLED: "+str(host)) request.setHeader('Location', 'gui/');
if self.logged:
if(len(self.perms.homepath)) > 0:
request.setHeader('Location', self.perms.homepath);
else:
request.setHeader('Location', self.core.configGet('web', 'defaultpath'))
else:
request.setHeader('Location', self.core.configGet('web', 'defaultpath'))
request.setResponseCode(302) request.setResponseCode(302)
return html return html
def childFactory(self, ctx, name): def childFactory(self, ctx, name):
request = inevow.IRequest(ctx) request = inevow.IRequest(ctx)
host=request.getHeader('host')
log.debug("HOST CALLED: "+str(host))
log.debug("No child found (%s)" % name) log.debug("No child found (%s)" % name)
return permissionDenied() return permissionDenied()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment