Thanks to visit codestin.com
Credit goes to github.com

Skip to content

run_in_sandbox data language checking handling update #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions classes/external/run_in_sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public static function execute($contextid, $sourcecode, $language='python3',
throw new qtype_coderunner_exception(get_string('wsnoaccess', 'qtype_coderunner'));
}

$sandbox = qtype_coderunner_sandbox::get_best_sandbox($language);
$sandbox = qtype_coderunner_sandbox::get_best_sandbox($language, true);
if ($sandbox === null) {
throw new qtype_coderunner_exception("Language {$language} is not available on this system");
throw new qtype_coderunner_exception(get_string('wsnolanguage', 'qtype_coderunner', $language));
}

if (get_config('qtype_coderunner', 'wsloggingenabled')) {
Expand All @@ -139,8 +139,13 @@ public static function execute($contextid, $sourcecode, $language='python3',
}

try {
$filesarray = $files ? json_decode($files, true) : null;
$filesarray = $files ? json_decode($files, true) : array();
$paramsarray = $params ? json_decode($params, true) : array();

// Throws error for incorrect JSON formatting
if ($filesarray === null || $paramsarray === null) {
throw new qtype_coderunner_exception(get_string('wsbadjson', 'qtype_coderunner'));
}
$maxcputime = intval(get_config('qtype_coderunner', 'wsmaxcputime')); // Limit CPU time through this service.
if (isset($paramsarray['cputime'])) {
$paramsarray['cputime'] = min($paramsarray['cputime'], $maxcputime);
Expand Down
4 changes: 3 additions & 1 deletion lang/en/qtype_coderunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,14 +1221,16 @@ function should be applied, e.g. <code>{{STUDENT_ANSWER | e(\'py\')}}</code> is
$string['validateonsave'] = 'Validate on save';

$string['wrongnumberofformats'] = 'Wrong number of test results column formats. Expected {$a->expected}, got {$a->got}';
$string['wsbadjson'] = 'params and file parameters must be blank or a valid JSON record';
$string['wsdisabled'] = 'Sandbox web service disabled. Talk to a sysadmin';
$string['wsloggingenable'] = 'Log sandbox web service usage';
$string['wsloggingenable_desc'] = 'If this option is checked, every code execution via the sandbox web service will be logged. This option must be enabled if user rate throttling is to work.';
$string['wsnoaccess'] = 'Only logged-in non-guest users can access this functionality';
$string['wsmaxcputime'] = 'Max CPU time (secs)';
$string['wsmaxcputime_desc'] = 'Limits the maximum CPU time that a web service job can use, even if it explicitly sets the CPU time sandbox parameter.';
$string['wsmaxhourlyrate'] = 'Max hourly rate of submissions';
$string['wsmaxhourlyrate_desc'] = 'If a user attempts to exceed this rate of submissions in any given hour their submissions will be disallowed. 0 for no rate throttling. Requires that logging of web service usage be enabled.';
$string['wsnoaccess'] = 'Only logged-in non-guest users can access this functionality';
$string['wsnolanguage'] = 'Language "{$a}" is not known';
$string['wssubmissionrateexceeded'] = 'You have exceeded the maximum hourly \'Try it!\' submission rate. Request denied.';

$string['xmlcoderunnerformaterror'] = 'XML format error in coderunner question';