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

216 by mattgiuca
Added new app "consoleservice", ajax back end which runs the console daemon.
1
# IVLE
2
# Copyright (C) 2007-2008 The University of Melbourne
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# App: consoleservice
19
# Author: Matt Giuca, Tom Conway
20
# Date: 14/1/2008
21
22
import os
23
24
import cjson
25
26
from common import (util, studpath)
27
import conf
28
29
def handle(req):
30
    """Handler for the Console Service AJAX backend application."""
31
32
    # Set request attributes
33
    req.content_type = "text/plain"
34
    req.write_html_head_foot = False
35
36
    # TODO: Figure out the host name the console server is running on.
37
    host = "localhost"
38
39
    # Find an available port on the server.
40
    # TODO
41
    port = 1025
42
43
    # Create magic
44
    # TODO
45
    magic = "xyzzy"
46
47
    # 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)
54
        + " > /home/mgiuca/Desktop/python_console_log 2>&1 &")
55
56
    # Return port, magic
57
    req.write(cjson.encode({"host": host, "port": port, "magic": magic}))