47
47
def start(self, req, cwd=''):
48
48
working_dir = os.path.join("/home", req.user.login, cwd)
51
53
jail_path = os.path.join(req.config['paths']['jails']['mounts'],
53
cons = ivle.console.Console(req.config, req.user, jail_path,
55
cons = ivle.console.Console(req.config, uid, jail_path, working_dir)
56
57
# Assemble the key and return it. Yes, it is double-encoded.
57
58
return {'key': cjson.encode({"host": cons.host,
87
88
msg = {'cmd':kind, 'text':text}
90
json_response = ivle.chat.chat(host, port, msg, magic,decode=False)
92
# Snoop the response from python-console to check that it's valid
90
json_response = ivle.chat.chat(host, port, msg, magic,decode=False)
91
# Snoop the response from python-console to check that it's valid
92
94
response = cjson.decode(json_response)
93
except (cjson.DecodeError, ivle.chat.ProtocolError):
95
except cjson.DecodeError:
94
96
# Could not decode the reply from the python-console server
95
97
response = {"terminate":
98
"Communication to console process lost"}
97
99
if "terminate" in response:
98
response = restart_console(req.config, req.user, jail_path,
100
response = restart_console(req.config, uid, jail_path,
99
101
working_dir, response["terminate"])
100
102
except socket.error, (enumber, estring):
101
103
if enumber == errno.ECONNREFUSED:
102
104
# Timeout: Restart the session
103
105
response = restart_console(req.config, uid, jail_path,
105
"Timed out due to inactivity")
107
"The IVLE console has timed out due to inactivity")
106
108
elif enumber == errno.ECONNRESET:
107
109
# Communication issue: Restart the session
108
110
response = restart_console(req.config, uid, jail_path,
112
"Connection with the console has been reset")
112
114
# Some other error - probably serious
113
115
raise socket.error, (enumber, estring)
117
def restart_console(config, user, jail_path, working_dir, reason):
119
def restart_console(config, uid, jail_path, working_dir, reason):
118
120
"""Tells the client that it must be issued a new console since the old
119
121
console is no longer availible. The client must accept the new key.
120
122
Returns the JSON response to be given to the client.
122
124
# Start a new console server console
123
cons = ivle.console.Console(config, user, jail_path, working_dir)
125
cons = ivle.console.Console(config, uid, jail_path, working_dir)
125
127
# Make a JSON object to tell the browser to restart its console client
126
128
new_key = cjson.encode(