示例#1
0
 public function resume()
 {
     if (!$this->input->is_ajax_request()) {
         show_404();
     }
     process_the_queue();
     echo 'success';
 }
示例#2
0
文件: Rejudge.php 项目: aqover/Ojudge
 public function rejudge_single()
 {
     if (!$this->input->is_ajax_request()) {
         show_404();
     }
     $this->form_validation->set_rules('submit_id', 'submit id', 'required|integer');
     $this->form_validation->set_rules('username', 'username', 'required|alpha_numeric');
     $this->form_validation->set_rules('problem', 'problem', 'required|integer');
     if ($this->form_validation->run()) {
         $this->load->model('queue_model');
         $this->queue_model->rejudge_single(array('submit_id' => $this->input->post('submit_id'), 'username' => $this->input->post('username'), 'problem' => $this->input->post('problem')));
         process_the_queue();
         $json_result = array('done' => 1);
     } else {
         $json_result = array('done' => 0, 'message' => 'Input Error');
     }
     $this->output->set_header('Content-Type: application/json; charset=utf-8');
     echo json_encode($json_result);
 }
示例#3
0
文件: Submit.php 项目: aqover/Ojudge
 /**
  * Saves submitted code and adds it to queue for judging
  */
 private function _upload()
 {
     $now = shj_now();
     foreach ($this->problems as $item) {
         if ($item['id'] == $this->input->post('problem')) {
             $this->problem = $item;
             break;
         }
     }
     $this->filetype = $this->_language_to_type(strtolower(trim($this->input->post('language'))));
     $this->ext = substr(strrchr($_FILES['userfile']['name'], '.'), 1);
     // uploaded file extension
     $this->file_name = basename($_FILES['userfile']['name'], ".{$this->ext}");
     // uploaded file name without extension
     if ($this->queue_model->in_queue($this->user->username, $this->problem['id'])) {
         show_error('You have already submitted for this problem. Your last submission is still in queue.');
     }
     if ($this->user->level == 0 && !$this->problem['open']) {
         show_error('Selected problem has been closed.');
     }
     $filetypes = explode(",", $this->problem['allowed_languages']);
     foreach ($filetypes as &$filetype) {
         $filetype = $this->_language_to_type(strtolower(trim($filetype)));
     }
     if ($_FILES['userfile']['error'] == 4) {
         show_error('No file chosen.');
     }
     if (!in_array($this->filetype, $filetypes)) {
         show_error('This file type is not allowed for this problem.');
     }
     if (!$this->_match($this->filetype, $this->ext)) {
         show_error('This file type does not match your selected language.');
     }
     if (!preg_match('/^[a-zA-Z0-9_\\-()]+$/', $this->file_name)) {
         show_error('Invalid characters in file name.');
     }
     $user_dir = rtrim($this->problem_root, '/') . '/p' . $this->problem['id'] . '/user/';
     if (!file_exists($user_dir)) {
         mkdir($user_dir, 0700);
     }
     $user_dir = rtrim($this->problem_root, '/') . '/p' . $this->problem['id'] . '/user/' . $this->user->username;
     if (!file_exists($user_dir)) {
         mkdir($user_dir, 0700);
     }
     $config['upload_path'] = $user_dir;
     $config['allowed_types'] = '*';
     $config['max_size'] = $this->settings_model->get_setting('file_size_limit');
     $config['file_name'] = $this->file_name . "-" . ($this->problem['total_submits'] + 1) . "." . $this->ext;
     $config['max_file_name'] = 20;
     $config['remove_spaces'] = TRUE;
     $this->upload->initialize($config);
     if ($this->upload->do_upload('userfile')) {
         $result = $this->upload->data();
         $this->load->model('submit_model');
         $submit_info = array('submit_id' => $this->problem_model->increase_total_submits($this->problem['id']), 'username' => $this->user->username, 'problem' => $this->problem['id'], 'file_name' => $result['raw_name'], 'main_file_name' => $this->file_name, 'file_type' => $this->filetype, 'pre_score' => 0, 'time' => shj_now_str());
         $this->probleminfo_model->update_last_submissions($this->problem['id'], $submit_info['time']);
         $this->probleminfo_model->update_total_submissions($problem_id, 1);
         if ($this->problem['is_upload_only'] == 0) {
             $this->queue_model->add_to_queue($submit_info);
             process_the_queue();
         } else {
             $this->submit_model->add_upload_only($submit_info);
         }
         return TRUE;
     }
     return FALSE;
 }
示例#4
0
 /**
  * Saves submitted code and adds it to queue for judging
  */
 private function _upload()
 {
     $now = shj_now();
     foreach ($this->problems as $item) {
         if ($item['id'] == $this->input->post('problem')) {
             $this->problem = $item;
             break;
         }
     }
     $this->filetype = $this->_language_to_type(strtolower(trim($this->input->post('language'))));
     $submitcode = $this->input->post("submitcode");
     $this->ext = substr(strrchr($_FILES['userfile']['name'], '.'), 1);
     // uploaded file extension
     $this->file_name = basename($_FILES['userfile']['name'], ".{$this->ext}");
     // uploaded file name without extension
     if ($this->queue_model->in_queue($this->user->username, $this->user->selected_assignment['id'], $this->problem['id'])) {
         show_error('You have already submitted for this problem. Your last submission is still in queue.');
     }
     if ($this->user->level == 0 && !$this->user->selected_assignment['open']) {
         show_error('Selected assignment has been closed.');
     }
     if ($now < strtotime($this->user->selected_assignment['start_time'])) {
         show_error('Selected assignment has not started.');
     }
     if ($now > strtotime($this->user->selected_assignment['finish_time']) + $this->user->selected_assignment['extra_time']) {
         show_error('Selected assignment has finished.');
     }
     if (!$this->assignment_model->is_participant($this->user->selected_assignment['participants'], $this->user->username)) {
         show_error('You are not registered for submitting.');
     }
     $filetypes = explode(",", $this->problem['allowed_languages']);
     foreach ($filetypes as &$filetype) {
         $filetype = $this->_language_to_type(strtolower(trim($filetype)));
     }
     $user_dir = rtrim($this->assignment_root, '/') . '/assignment_' . $this->user->selected_assignment['id'] . '/p' . $this->problem['id'] . '/' . $this->user->username;
     if (!file_exists($user_dir)) {
         mkdir($user_dir, 0700);
     }
     $done = false;
     if ($submitcode == "" || $this->filetype == 'zip' || $this->filetype == 'pdf') {
         if ($_FILES['userfile']['error'] == 4) {
             show_error('No file chosen.');
         }
         if (!in_array($this->filetype, $filetypes)) {
             show_error('This file type is not allowed for this problem.');
         }
         if (!$this->_match($this->filetype, $this->ext)) {
             show_error('This file type does not match your selected language.');
         }
         if (!preg_match('/^[a-zA-Z0-9_\\-()]+$/', $this->file_name)) {
             show_error('Invalid characters in file name.');
         }
         $config['upload_path'] = $user_dir;
         $config['allowed_types'] = '*';
         $config['max_size'] = $this->settings_model->get_setting('file_size_limit');
         $config['file_name'] = $this->file_name . "-" . ($this->user->selected_assignment['total_submits'] + 1) . "." . $this->ext;
         $config['max_file_name'] = 20;
         $config['remove_spaces'] = TRUE;
         $this->upload->initialize($config);
         if ($this->upload->do_upload('userfile')) {
             $result = $this->upload->data();
             $done = true;
         }
     } else {
         $this->load->helper('file');
         $this->ext = $this->_retext($this->filetype);
         $this->file_name = "code";
         $file_name = "code-" . ($this->user->selected_assignment['total_submits'] + 1) . "." . $this->ext;
         $upload_path = $user_dir;
         $max_size = $this->settings_model->get_setting('file_size_limit');
         $fp = fopen($upload_path . "/" . $file_name, 'w');
         //show_error($max_size);
         $wr = fwrite($fp, $submitcode, $max_size * 1024);
         if (!$wr) {
             show_error("Code is too large");
         }
         fclose($fp);
         $result['raw_name'] = "code-" . ($this->user->selected_assignment['total_submits'] + 1);
         $done = true;
     }
     if ($done) {
         $this->load->model('submit_model');
         $submit_info = array('submit_id' => $this->assignment_model->increase_total_submits($this->user->selected_assignment['id']), 'username' => $this->user->username, 'assignment' => $this->user->selected_assignment['id'], 'problem' => $this->problem['id'], 'file_name' => $result['raw_name'], 'main_file_name' => $this->file_name, 'file_type' => $this->filetype, 'coefficient' => $this->coefficient, 'pre_score' => 0, 'time' => shj_now_str());
         if ($this->problem['is_upload_only'] == 0) {
             $this->queue_model->add_to_queue($submit_info);
             process_the_queue();
         } else {
             $this->submit_model->add_upload_only($submit_info);
         }
         $val = $submit_info;
         return $val;
     }
     return FALSE;
 }