~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/consoleservice/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-21 06:32:46 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:257
consoleservice: Rewrote this so it runs the console inside the jail (using the
    trampoline to load the console).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# Date: 14/1/2008
21
21
 
22
22
import os
 
23
import pwd
23
24
 
24
25
import cjson
25
26
 
26
27
from common import (util, studpath)
27
28
import conf
28
29
 
 
30
trampoline_path = os.path.join(conf.ivle_install_dir, "bin/trampoline")
 
31
python_path = "/usr/bin/python"                     # Within jail
 
32
console_dir = "/opt/ivle/console"                   # Within jail
 
33
console_path = "/opt/ivle/console/python-console"   # Within jail
 
34
 
29
35
def handle(req):
30
36
    """Handler for the Console Service AJAX backend application."""
 
37
    jail_path = os.path.join(conf.jail_base, req.username)
 
38
    working_dir = os.path.join("/home", req.username)   # Within jail
 
39
 
 
40
    # Get the UID of the logged-in user
 
41
    try:
 
42
        (_,_,uid,_,_,_,_) = pwd.getpwnam(req.username)
 
43
    except KeyError:
 
44
        # The user does not exist. This should have already failed the
 
45
        # previous test.
 
46
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR)
31
47
 
32
48
    # Set request attributes
33
49
    req.content_type = "text/plain"
45
61
    magic = "xyzzy"
46
62
 
47
63
    # Start the console server (port, magic)
48
 
    # TODO: Trampoline into the jail, and run it as a background process
49
 
    jail = os.path.join(conf.jail_base, req.username)
50
 
    console_dir = os.path.join(jail, "opt/ivle/console/")
51
 
    console_path = os.path.join(console_dir, "python-console")
52
 
    os.system("cd " + console_dir + "; "
53
 
        + console_path + " " + str(port) + " " + str(magic) + " &")
 
64
    # trampoline usage: tramp uid jail_dir working_dir script_path args
 
65
    # console usage:    python-console port magic
 
66
    # TODO: Cleanup (don't use os.system)
 
67
    # TODO: Pass working_dir as argument, let console cd to it
 
68
    # Use "&" to run as a background process
 
69
    cmd = ' '.join([trampoline_path, str(uid), jail_path, console_dir,
 
70
        python_path, console_path, str(port), str(magic), "&"])
 
71
    #req.write(cmd + '\n')
 
72
    os.system(cmd)
54
73
 
55
74
    # Return port, magic
56
75
    req.write(cjson.encode({"host": host, "port": port, "magic": magic}))