self._cp_config['tools.mako.imports'] = ['from invirt.config import structs as config',
'from invirt import database']
+ def __getattr__(self, name):
+ if name in ("admin", "overlord"):
+ if not cherrypy.request.login in getAfsGroupMembers(config.adminacl, config.authz[0].cell):
+ raise InvalidInput('username', cherrypy.request.login,
+ 'Not in admin group %s.' % config.adminacl)
+ cherrypy.request.state = State(cherrypy.request.login, isadmin=True)
+ return self
+ else:
+ return super(InvirtWeb, self).__getattr__(name)
@cherrypy.expose
@cherrypy.tools.mako(filename="/list.mako")
return templates.unauth(searchList=[{'simple' : True,
'hostname' : socket.getfqdn()}])
-def admin(username, state, path, fields):
- if path == '':
- return ({'Status': '303 See Other',
- 'Location': 'admin/'},
- "You shouldn't see this message.")
- if not username in getAfsGroupMembers(config.adminacl, 'athena.mit.edu'):
- raise InvalidInput('username', username,
- 'Not in admin group %s.' % config.adminacl)
- newstate = State(username, isadmin=True)
- newstate.environ = state.environ
- return handler(username, newstate, path, fields)
-
mapping = dict(
modify=modify,
- unauth=unauthFront,
- admin=admin,
- overlord=admin)
+ unauth=unauthFront)
def printHeaders(headers):
"""Print a dictionary as HTTP headers."""
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>${self.title()} — XVM</title>
- <base href="${cherrypy.request.base}" />
- <link href="static/favicon.ico" type="image/x-icon" rel="shortcut icon">
- <link rel="stylesheet" href="static/style.css" type="text/css" />
- <link rel="stylesheet" href="static/layout.css" type="text/css" media="screen" />
- <script type="text/javascript" src="static/prototype.js"></script>
+ <base href="${cherrypy.request.base}${"/admin/" if cherrypy.request.state.isadmin else ""}" />
+ <link href="/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
+ <link rel="stylesheet" href="/static/style.css" type="text/css" />
+ <link rel="stylesheet" href="/static/layout.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="/static/prototype.js"></script>
<script type="text/javascript">
var helpWin = null;
function closeWin(){
% if not simple:
% if cherrypy.request.login:
-<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.</p>
+<p class="loggedin">Welcome, <span class="name">${cherrypy.request.login}</span>.
+% if cherrypy.request.state.isadmin:
+You are currently authenticated as an administrator.
+% endif
+</p>
% endif
<ul class="navigation">
def invirtwebstate_init():
"""Initialize the cherrypy.request.state object from Invirt"""
- cherrypy.request.state = State(cherrypy.request.login)
+ if not hasattr(cherrypy.request, "state"):
+ cherrypy.request.state = State(cherrypy.request.login)
cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)