10 from invirt.vnc import getTokenKey
11 from invirt.config import structs as config
13 def getAuthToken(username, machine, lifetime=5*60):
15 data['user'] = username
16 data['machine'] = machine
17 data['expires'] = time.time() + lifetime
18 data['connect_host'] = config.web.hostname
20 data['connect_port'] = 10003 + [h.hostname for h in
21 config.hosts].index(os.uname()[1])
23 data['connect_port'] = 5900
24 pickled_data = cPickle.dumps(data)
25 m = hmac.new(getTokenKey(), digestmod=sha)
26 m.update(pickled_data)
27 token = ".".join(map(base64.urlsafe_b64encode, (pickled_data, m.digest())))
32 username = os.environ['REMOTE_USER']
36 print getAuthToken(username, machine)
38 if __name__ == '__main__':