private function _detect($assignment_id = FALSE) { if ($assignment_id === FALSE) { show_404(); } $this->load->model('submit_model'); $assignments_path = rtrim($this->settings_model->get_setting('assignments_root'), '/'); $tester_path = rtrim($this->settings_model->get_setting('tester_path'), '/'); shell_exec("chmod +x {$tester_path}/moss"); $items = $this->submit_model->get_final_submissions($assignment_id, $this->user->level, $this->user->username); $groups = array(); foreach ($items as $item) { if (!isset($groups[$item['problem']])) { $groups[$item['problem']] = array($item); } else { array_push($groups[$item['problem']], $item); } } foreach ($groups as $problem_id => $group) { $list = ''; $assignment_path = $assignments_path . "/assignment_{$assignment_id}"; foreach ($group as $item) { if ($item['file_type'] !== 'zip' && $item['file_type'] !== 'pdf') { $list .= "p{$problem_id}/{$item['username']}/{$item['file_name']}" . '.' . filetype_to_extension($item['file_type']) . " "; } } shell_exec("list='{$list}'; cd {$assignment_path}; {$tester_path}/moss \$list | grep http >p{$problem_id}/moss_link.txt;"); } $this->assignment_model->set_moss_time($assignment_id); }
public function download_file() { $username = $this->uri->segment(3); $problem = $this->uri->segment(4); $submit_id = $this->uri->segment(5); $submission = $this->submit_model->get_submission($username, $problem, $submit_id); if ($submission === FALSE) { show_404(); } if ($this->user->level === 0 && $this->user->username != $submission['username']) { exit('Don\'t try to see submitted codes :)'); } $file_path = rtrim($this->settings_model->get_setting('problems_root'), '/') . "/p{$submission['problem']}/user/{$submission['username']}/{$submission['file_name']}." . filetype_to_extension($submission['file_type']); $this->load->helper('download'); force_download("{$submission['file_name']}." . filetype_to_extension($submission['file_type']), file_get_contents($file_path)); }
/** * Compressing and downloading final codes of an assignment to the browser */ public function download_submissions($type = FALSE, $assignment_id = FALSE) { if ($type !== 'by_user' && $type !== 'by_problem') { show_404(); } if ($assignment_id === FALSE || !is_numeric($assignment_id)) { show_404(); } if ($this->user->level == 0) { // permission denied show_404(); } $this->load->model('submit_model'); $items = $this->submit_model->get_final_submissions($assignment_id, $this->user->level, $this->user->username); $this->load->library('zip'); $assignments_root = rtrim($this->settings_model->get_setting('assignments_root'), '/'); foreach ($items as $item) { $file_path = $assignments_root . "/assignment_{$item['assignment']}/p{$item['problem']}/{$item['username']}/{$item['file_name']}." . filetype_to_extension($item['file_type']); if (!file_exists($file_path)) { continue; } $file = file_get_contents($file_path); if ($type === 'by_user') { $this->zip->add_data("{$item['username']}/p{$item['problem']}." . filetype_to_extension($item['file_type']), $file); } elseif ($type === 'by_problem') { $this->zip->add_data("problem_{$item['problem']}/{$item['username']}." . filetype_to_extension($item['file_type']), $file); } } $this->zip->download("assignment{$assignment_id}_submissions_{$type}_" . date('Y-m-d_H-i', shj_now()) . '.zip'); }
/** * This is the main function for processing the queue * This function judges queue items one by one */ public function run() { // Set correct base_url // Because we are in cli mode, base_url is not available, and we get // it from an environment variable that we have set in shj_helper.php $this->config->set_item('base_url', getenv('SHJ_BASE_URL')); $queue_item = $this->queue_model->get_first_item(); if ($queue_item === NULL) { $this->settings_model->set_setting('queue_is_working', '0'); exit; } if ($this->settings_model->get_setting('queue_is_working')) { exit; } $this->settings_model->set_setting('queue_is_working', '1'); do { // loop over queue items $submit_id = $queue_item['submit_id']; $username = $queue_item['username']; $assignment = $queue_item['assignment']; $assignment_info = $this->assignment_model->assignment_info($assignment); $problem = $this->assignment_model->problem_info($assignment, $queue_item['problem']); $type = $queue_item['type']; // $type can be 'judge' or 'rejudge' $submission = $this->submit_model->get_submission($username, $assignment, $problem['id'], $submit_id); $file_type = $submission['file_type']; $file_extension = filetype_to_extension($file_type); $raw_filename = $submission['file_name']; $main_filename = $submission['main_file_name']; $assignments_dir = rtrim($this->settings_model->get_setting('assignments_root'), '/'); $tester_path = rtrim($this->settings_model->get_setting('tester_path'), '/'); $problemdir = $assignments_dir . "/assignment_{$assignment}/p" . $problem['id']; $userdir = "{$problemdir}/{$username}"; //$the_file = "$userdir/$raw_filename.$file_extension"; $op1 = $this->settings_model->get_setting('enable_log'); $op2 = $this->settings_model->get_setting('enable_easysandbox'); $op3 = 0; if ($file_type === 'c') { $op3 = $this->settings_model->get_setting('enable_c_shield'); } elseif ($file_type === 'cpp') { $op3 = $this->settings_model->get_setting('enable_cpp_shield'); } $op4 = 0; if ($file_type === 'py2') { $op4 = $this->settings_model->get_setting('enable_py2_shield'); } elseif ($file_type === 'py3') { $op4 = $this->settings_model->get_setting('enable_py3_shield'); } $op5 = $this->settings_model->get_setting('enable_java_policy'); $op6 = $assignment_info['javaexceptions']; if ($file_type === 'c' or $file_type === 'cpp') { $time_limit = $problem['c_time_limit'] / 1000; } elseif ($file_type === 'java') { $time_limit = $problem['java_time_limit'] / 1000; } elseif ($file_extension === 'py') { $time_limit = $problem['python_time_limit'] / 1000; } $time_limit = round($time_limit, 3); $time_limit_int = floor($time_limit) + 1; $memory_limit = $problem['memory_limit']; $diff_cmd = $problem['diff_cmd']; $diff_arg = $problem['diff_arg']; $output_size_limit = $this->settings_model->get_setting('output_size_limit') * 1024; $cmd = "cd {$tester_path};\n./tester.sh {$problemdir} " . escapeshellarg($username) . ' ' . escapeshellarg($main_filename) . ' ' . escapeshellarg($raw_filename) . " {$file_type} {$time_limit} {$time_limit_int} {$memory_limit} {$output_size_limit} {$diff_cmd} {$diff_arg} {$op1} {$op2} {$op3} {$op4} {$op5} {$op6}"; file_put_contents($userdir . '/log', $cmd); /////////////////////////////////////// // Running tester (judging the code) // /////////////////////////////////////// putenv('LANG=en_US.UTF-8'); $output = trim(shell_exec($cmd)); // Deleting the jail folder, if still exists shell_exec("cd {$tester_path}; rm -rf jail*"); // Saving judge result if (true || is_numeric($output) || $output === 'Compilation Error' || $output === 'Syntax Error') { shell_exec("mv {$userdir}/result.html {$userdir}/result-{$submit_id}.html"); shell_exec("mv {$userdir}/log {$userdir}/log-{$submit_id}"); shell_exec("mv {$userdir}/out {$userdir}/out-{$submit_id}"); } if (is_numeric($output)) { $submission['pre_score'] = $output; $submission['status'] = 'SCORE'; $submission['wrong_at'] = 0; } else { $output = explode(" ", $output); $submission['pre_score'] = 0; $submission['status'] = $output[0]; $submission['wrong_at'] = $output[1]; } // Save the result $this->queue_model->save_judge_result_in_db($submission, $type); // Remove the judged item from queue $this->queue_model->remove_item($username, $assignment, $problem['id'], $submit_id); // Get next item from queue $queue_item = $this->queue_model->get_first_item(); } while ($queue_item !== NULL && $this->settings_model->get_setting('queue_is_working')); $this->settings_model->set_setting('queue_is_working', '0'); }