Print to server stdout/stderr from inside question template

Print to server stdout/stderr from inside question template

por James Ansley -
Número de respuestas: 1

I am currently using JobeInABox and was wondering if there was any way to print to the docker/server stdout/stderr?
This is mostly for the purposes of logging particular activities.

It seems like when the template code is run, anything printed to stdout/err is 'redirected' to show up in the 'Got' result column for the coderunner question and is not printed 'serverside' in the regular stdout/stderr.

Ideally, I would like something like this in the custom question template:

{{ STUDENT_ANSWER }}

__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""

SEPARATOR = "#<ab@17943918#@>#"
### SOME CODE ###
print_to_server_stdout(MESSAGE)  # is there anything that does this?
{% for TEST in TESTCASES %}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}

If anyone would know of any way to do this, advice would be greatly appreciated.

Thanks

En respuesta a James Ansley

Re: Print to server stdout/stderr from inside question template

por Richard Lobb -

Allowing jobs to output to the Jobe server itself rather goes against the design of Jobe, which is meant to be stateless, apart from the caching of files. If question authors are able to generate such output within the template code, students would also be able to generate it, potentially corrupting or overloading your logs. It would be a bit of a security flaw.

That said, most students aren't actually out to crash your system, especially when they know that all their CodeRunner actions are being logged and any attacks are likely to be sheeted back to them. So some things you could try are:

  1. Set up a special log file, writable by all, within JobeInAbox. Write your output to that instead of stdout. Use a script in the server running JobeInABox to download/sync the contents of that file to the server.
  2. Set up a directory on the server to contain the log file and mount it as a volume within jobeinabox. Then you don't have to do any syncing.
  3. Install a database server like mysql on your Jobe server and open a container port to allow JobeInABox to access it. Have your template add log records to the database. This is somewhat more secure than 1 and 2, because you would need a password to access the database. However, done simplistically, students' code would still be able to read the code that is being run and extract the password from it.
Of course, Apache's access.log file records all the runs, and Jobe has its own log files too. So if all you want to do is gather usage stats, you can get them from those files. But I'm assuming you want to log additional things, like the name of the user or information extracted from their submission?