示例#1
0
 /**
  * Construct and initilize
  */
 public function __construct()
 {
     $this->config = MDL_Config::getInstance();
     $this->acl = MDL_ACL::getInstance();
     $this->locator = MDL_Locator::getInstance();
     $this->view = MDL_View::getInstance();
     $this->view->setTheme($this->config->getVar('theme'));
     $this->path_option = BFL_PathOption::getInstance();
 }
示例#2
0
 private function __construct()
 {
     $this->locator = MDL_Locator::getInstance();
     $this->header['javascript'] = $this->header['stylesheet'] = array();
     //設置默認時區
     date_default_timezone_set(MDL_Config::getInstance()->getVar('time_zone'));
 }
示例#3
0
 /**
  * getInstance
  * @return MDL_Config
  */
 public static function getInstance()
 {
     if (NULL === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#4
0
文件: Share.php 项目: thezawad/vakuum
 public static function uploadTestdata($judger, $data_config)
 {
     $prob_name = $data_config['name'];
     $testdata_path = MDL_Config::getInstance()->getVar('judger_testdata') . $prob_name . '/';
     $dest_path = $judger->getConfig()->getTestdataPath() . $prob_name . '/';
     if (!file_exists($dest_path) || !is_dir($dest_path)) {
         if (@mkdir($dest_path) === false) {
             throw new MDL_Exception_Judge_Share(MDL_Exception_Judge_Share::TESTDATA_UPLOAD);
         }
         chmod($dest_path, 0755);
     }
     unset($data_config['id']);
     unset($data_config['title']);
     $xml = BFL_XML::Array2XML($data_config);
     if (file_put_contents($dest_path . "config.xml", $xml) === false) {
         throw new MDL_Exception_Judge_Share(MDL_Exception_Judge_Share::TESTDATA_UPLOAD);
     }
     if ($testdata_path == $dest_path) {
         return;
     }
     if ($data_config['checker']['type'] == 'custom') {
         //Upload checker
         $checker_source = $data_config['checker']['custom']['source'];
         $checker_file = $testdata_path . $checker_source;
         $this->copy_file($dest_path . $checker_source, $checker_file);
     }
     //Upload testdatas
     foreach ($data_config['case'] as $item) {
         foreach (array('input', 'output') as $key) {
             $testdata_file = $testdata_path . $item[$key];
             $this->copy_file($dest_path . $item[$key], $testdata_file);
         }
     }
 }
示例#5
0
 public static function processTaskQueue()
 {
     set_time_limit(0);
     ignore_user_abort(1);
     $db = BFL_Database::getInstance();
     $lock_tables = array(DB_TABLE_JUDGER . ' write', DB_TABLE_RECORD . ' write', DB_TABLE_RECORDMETA . ' write', DB_TABLE_PROB . ' read');
     $db->lock($lock_tables, true);
     //Get Available Judger
     $judger = MDL_Judger_Set::getAvailableJudger();
     if ($judger == NULL) {
         $db->unlock();
         return 'nojudger';
     }
     $judger_id = $judger->getID();
     $task = self::getTask();
     if (!$task) {
         $db->unlock();
         return 'notask';
     }
     //Pend task
     MDL_Judge_Record::pend($task['record_id'], $judger_id);
     //lock judger
     $judger->lock();
     $db->unlock();
     //upload source
     $task['src_name'] = self::getSrcname($task['task_name'], $task['language']);
     MDL_Judger_Transmit::sendTask($judger, $task['task_name'], $task['source'], $task['src_name']);
     //send judge request
     $config = MDL_Config::getInstance();
     MDL_Judger_Access::sendRequest($judger, $task);
 }
示例#6
0
 private static function upload()
 {
     if (MDL_Config::getInstance()->getVar('plugin_NicEdit_upload_allow') == 0) {
         exit;
     }
     //TODO forbidden upload
     $upload_path = MDL_Config::getInstance()->getVar('plugin_NicEdit_upload_path');
     $upload_uri = MDL_Config::getInstance()->getVar('root_path') . $upload_path;
     require self::$plugin_file . 'nicUpload.php';
 }
示例#7
0
文件: List.php 项目: thezawad/vakuum
 public function __construct($page = 0, $page_size = 0)
 {
     if ($page_size == 0) {
         $page_size = MDL_Config::getInstance()->problem_list_page_size;
     }
     $this->setPageSize($page_size);
     $this->setCurrentPage($page);
     $sql = 'select * from ' . DB_TABLE_CONTEST;
     $this->setSQLPrefix($sql);
     parent::__construct();
 }
示例#8
0
文件: List.php 项目: thezawad/vakuum
 public function __construct($page = 0, $page_size = 0)
 {
     if ($page_size == 0) {
         $page_size = MDL_Config::getInstance()->user_list_page_size;
     }
     $this->setPageSize($page_size);
     $this->setCurrentPage($page);
     $sql = 'select `user_id`,`user_name`,`user_nickname` from ' . DB_TABLE_USER;
     $this->setSQLPrefix($sql);
     parent::__construct();
 }
示例#9
0
 public static function makeURL($base, $path_options = array(), $qs_options = array())
 {
     $config = MDL_Config::getInstance();
     $path = $config->getVar('root_path') . $config->getVar('root_path_prefix') . $base;
     $bind_address = $config->getVar('site_address');
     if ($bind_address != '') {
         $path = $bind_address . $path;
     }
     $path .= self::makeOptions($path_options, $qs_options);
     return $path;
 }
示例#10
0
 public static function verify($data_config)
 {
     $verify_result['testdata_path'] = MDL_Config::getInstance()->getVar('judger_testdata') . $data_config['name'] . '/';
     $verify_result['overall'] = '';
     if (!file_exists($verify_result['testdata_path'])) {
         //testdata_path not exist
         $verify_result['overall'] = 'testdata_path';
         return $verify_result;
     }
     $hash_code = '';
     $verify_result['checker'] = true;
     if ($data_config['checker']['type'] == 'custom') {
         $checker_file = $verify_result['testdata_path'] . $data_config['checker']['custom']['source'];
         if (file_exists($checker_file)) {
             $hash_code .= sha1_file($checker_file, true);
         } else {
             $verify_result['checker'] = false;
             $verify_result['overall'] = 'checker';
         }
     }
     $success = true;
     $case_id = 0;
     foreach ($data_config['case'] as $item) {
         $input_file = $verify_result['testdata_path'] . $item['input'];
         $output_file = $verify_result['testdata_path'] . $item['output'];
         if (file_exists($input_file)) {
             $verify_result['case'][$case_id]['input'] = true;
             $hash_code .= sha1_file($input_file, true);
         } else {
             $verify_result['case'][$case_id]['input'] = false;
             $success = false;
         }
         if (file_exists($output_file)) {
             $verify_result['case'][$case_id]['output'] = true;
             $hash_code .= sha1_file($output_file, true);
         } else {
             $verify_result['case'][$case_id]['output'] = false;
             $success = false;
         }
         ++$case_id;
     }
     $hash_code = sha1($hash_code);
     if (!$success) {
         $verify_result['overall'] = 'case';
     } else {
         $verify_result['hash_code'] = $hash_code;
         $problem_meta = new MDL_Problem_Meta($data_config['id']);
         $problem_meta->setVar('verified', 1);
     }
     return $verify_result;
 }
示例#11
0
文件: Edit.php 项目: thezawad/vakuum
 public static function sendValidationCode($user_name, $email, $validation_code)
 {
     $server_name = BFL_General::getServerName();
     $site_address = BFL_General::getServerAddress();
     $options = array('user_name' => $user_name, 'code' => $validation_code);
     $validation_address = MDL_Locator::getInstance()->getURL('passport_dovalidation', $options);
     if (strpos($validation_address, $site_address) !== 0) {
         $validation_address = $site_address . $validation_address;
     }
     $site_name = MDL_Config::getInstance()->getVar('site_name');
     $view = MDL_View::getInstance();
     $view->validation = array('user_name' => $user_name, 'site_name' => $site_name, 'site_address' => $site_address, 'validation_address' => $validation_address);
     $message = $view->render('text/email_validation.php');
     $mail_sender = new BFL_Mail($email, $site_name, $message);
     $mail_sender->setFrom($site_name . " <vakuum@{$server_name}>");
     return $mail_sender->send();
 }
示例#12
0
 public static function submit($user_id, $prob_id, $lang, $source, $display)
 {
     //TODO verify problem allowence
     $problem = MDL_Problem_Show::getProblem($prob_id);
     if ($problem['verified'] != 1) {
         throw new MDL_Exception_Problem(MDL_Exception_Problem::UNVALIDATED_PROBLEM);
     }
     //check length
     $config = MDL_Config::getInstance();
     $smaxlen = $config->getVar('judge_source_length_max');
     if (strlen($source) > $smaxlen) {
         throw new MDL_Exception_Judge(MDL_Exception_Judge::INVALID_SOURCE_LENGTH);
     }
     //encode source
     $source = self::convertEncode($source);
     //create new record
     $record_id = MDL_Judge_Record::createRecord($user_id, $prob_id, $lang, $source, $display);
     return $record_id;
 }
示例#13
0
文件: FTP.php 项目: thezawad/vakuum
 public static function uploadTestdata($judger, $data_config)
 {
     $prob_name = $data_config['name'];
     $testdata_path = MDL_Config::getInstance()->getVar('judger_testdata') . $prob_name . '/';
     $temp_file = tempnam(sys_get_temp_dir(), 'Vakuum');
     unset($data_config['id']);
     unset($data_config['title']);
     $xml = BFL_XML::Array2XML($data_config);
     file_put_contents($temp_file, $xml);
     $pftp = self::connect($judger);
     if (ftp_chdir($pftp, $judger->getConfig()->getTestdataPath()) === false) {
         throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD);
     }
     if (@ftp_chdir($pftp, $prob_name) === false) {
         ftp_mkdir($pftp, $prob_name);
         ftp_chmod($pftp, 0755, $prob_name);
         ftp_chdir($pftp, $prob_name);
     }
     //Upload config.xml
     if (ftp_put($pftp, 'config.xml', $temp_file, FTP_BINARY) === false) {
         throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD);
     }
     if ($data_config['checker']['type'] == 'custom') {
         //Upload checker
         $checker_source = $data_config['checker']['custom']['source'];
         $checker_file = $testdata_path . $checker_source;
         if (ftp_put($pftp, $checker_source, $checker_file, FTP_BINARY) === false) {
             throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD);
         }
     }
     //Upload testdatas
     foreach ($data_config['case'] as $item) {
         foreach (array('input', 'output') as $key) {
             $testdata_file = $testdata_path . $item[$key];
             if (ftp_put($pftp, $item[$key], $testdata_file, FTP_BINARY) === false) {
                 throw new MDL_Exception_Judge_FTP(MDL_Exception_Judge_FTP::TESTDATA_UPLOAD);
             }
         }
     }
     ftp_close($pftp);
 }
示例#14
0
 public function ACT_submit()
 {
     if (!$this->acl->check('general')) {
         $this->deny();
     }
     if ($this->config->getVar('judge_allowed') != 1) {
         $this->deny();
     }
     $user_id = $this->acl->getUser()->getID();
     $prob_id = $_POST['prob_id'];
     $lang = $_POST['lang'];
     $source = file_get_contents($_FILES['source']['tmp_name']);
     $problem = new MDL_Problem($prob_id);
     if (!$problem->getProblemMeta()->display || !$problem->getProblemMeta()->verified) {
         $this->deny();
     }
     $default_display = MDL_Config::getInstance()->getVar('record_display_default');
     $display = new MDL_Record_Display($default_display);
     $record_id = MDL_Judge_Single::submit($user_id, $prob_id, $lang, $source, $display);
     MDL_Judger_Process::processTaskQueue();
     $this->locator->redirect('record_detail', array(), '/' . $record_id);
 }
示例#15
0
 public static function editPreferences($preferences)
 {
     $config = MDL_Config::getInstance();
     $config->setVars($preferences);
 }
示例#16
0
 /**
  * Initialize
  */
 public static function initialize()
 {
     $config = MDL_Config::getInstance();
     self::$private_key = $config->getVar('plugin_ReCaptcha_private_key');
     self::$public_key = $config->getVar('plugin_ReCaptcha_public_key');
 }
示例#17
0
 protected function formatTime($time)
 {
     $config = MDL_Config::getInstance();
     return date($config->getVar('time_format'), $time);
 }
示例#18
0
$input = $prob_info['data_config']['input'];
$output = $prob_info['data_config']['output'];
$checker = $prob_info['data_config']['checker'];
$time_limit = $prob_info['data_config']['time_limit'];
$memory_limit = $prob_info['data_config']['memory_limit'];
$output_limit = $prob_info['data_config']['output_limit'];
$case_count = count($prob_info['data_config']['case']);
$judge_source_length_max = MDL_Config::getInstance()->getVar('judge_source_length_max');
if ($time_limit == 0) {
    $time_limit = MDL_Config::getInstance()->getVar('judge_default_time_limit');
}
if ($memory_limit == 0) {
    $memory_limit = MDL_Config::getInstance()->getVar('judge_default_memory_limit');
}
if ($output_limit == 0) {
    $output_limit = MDL_Config::getInstance()->getVar('judge_default_output_limit');
}
$checker = $checker['type'] == 'standard' ? '' : '特殊检查器';
?>

<?php 
$this->title = $prob_title;
$this->display('header.php');
?>

<h2><?php 
echo $this->escape($prob_title);
?>
</h2>

<table>
示例#19
0
 public static function getRestrict()
 {
     $config = MDL_Config::getInstance();
     $restrict = unserialize($config->getVar('register_form_restrict'));
     return $restrict;
 }
示例#20
0
require_once 'library/global.php';
require_once 'library/BFL/BFL_Loader.php';
//初始化自動加載器
BFL_Loader::setBFLPath('./library/BFL/');
BFL_Loader::setControllerPath('./library/application/controller/');
BFL_Loader::setModelPath('./library/application/model/');
//初始化計時器
BFL_Timer::initialize();
//設置運行時全局變量
BFL_Register::setVar('password_encode_word', PWD_ENCWORD);
BFL_Register::setVar('db_info', getDBInfo());
//初始化數據庫事務處理
$db = BFL_Database::getInstance();
$db->beginTransaction();
//初始化參數表
$config = MDL_Config::getInstance();
//設置全局異常捕捉函數
set_exception_handler(array('MDL_GlobalControl', 'exceptionHandler'));
//設置退出回調函數
register_shutdown_function(array('MDL_GlobalControl', 'shutdownHandler'));
//檢查地址綁定
$bind_address = $config->getVar('site_address');
if ($bind_address != '' && $bind_address != BFL_General::getServerAddress()) {
    BFL_Controller::redirect($bind_address);
}
//初始化用戶會話
MDL_ACL::getInstance()->initialize(SESSION_PREFIX, 'guest');
MDL_User_Auth::getLoginedUserInformation();
//加載插件
MDL_Plugin::load_plugins(MDL_Locator::getInstance()->getFilePath('plugins'));
//初始化前端控制器
示例#21
0
 public static function getPublicKey()
 {
     return BFL_RemoteAccess_Common::keyhash(MDL_Config::getInstance()->getVar('judge_return_key'));
 }