function judge($task) { writelog($task); $path = Config::getInstance()->getVar('path'); $original_cd = getcwd(); chdir($path['task'] . $task['task_name']); $judge = new Judge($task['task_name'], $task['prob_name'], $task['source_file'], $task['language'], $task['return_url'], $task['public_key']); try { $result = $judge->compile(); if ($result == 0) { $info = $judge->run(); if (!is_array($info)) { writelog('ERROR: ' . $info); switch ($info) { case 'testdata': case 'checker': default: //Run failed $info = array('fatal' => Judge::RESULT_EXECUTOR_ERROR, 'time' => 0, 'memory' => 0, 'score' => 0.0); } } } else { //Compile failed $info = array('fatal' => Judge::RESULT_COMILATION_ERROR, 'time' => 0, 'memory' => 0, 'score' => 0.0); } $judge->complete($info); } catch (Exception $e) { writelog("Stopped"); } $judge->clear(); chdir($original_cd); }
public function testExecute_PlainSystemCommand() { $submission = new Submission(); $submission->setWorkDir('/home/guilherme/Documentos/PHP_Projeto/'); $gcccompiler = new GccCompiler(); $runner = new Runner(); $judge = new Judge($gcccompiler, $runner); $judge->judge('/home/guilherme/Documentos/PHP_Projeto/', $submission, 'Prime'); }
/** * Create Exif class * * @param string $file * @author Thibaud Rohmer */ public function __construct($file = null) { /// No file given if (!isset($file)) { return; } /// File isn't an image if (is_array($file) || !File::Type($file) || File::Type($file) != "Image") { return; } /// No right to view if (!Judge::view($file)) { return; } /// No exif extension installed if (!in_array("exif", get_loaded_extensions())) { $infos[''] = "Exif extension is not installed on the server"; return; } /// Create wanted table $this->init_wanted(); /// Read exif $raw_exif = @exif_read_data($file); /// Parse exif foreach ($this->wanted as $name => $data) { foreach ($data as $d) { if (isset($raw_exif[$d])) { $this->exif[$name] = $this->parse_exif($d, $raw_exif); } } } $this->filename = basename($file); }
/** * Create Video * * @param string $file * @author Cédric Levasseur */ public function __construct($file = NULL, $forcebig = false) { if (!Judge::view($file)) { return; } /// Check file type if (!isset($file) || !File::Type($file) || File::Type($file) != "Video") { return; } /// File object $this->file = $file; /// Set relative path (url encoded) $this->fileweb = urlencode(File::a2r($file)); }
/** * Create Menu * * @param string $dir * @param int $level * @author Thibaud Rohmer */ public function __construct($dir = null, $level = 0) { /// Init Menu if ($dir == null) { $dir = Settings::$photos_dir; } /// Check rights if (!Judge::view($dir) || Judge::searchDir($dir) == NULL) { return; } if (!CurrentUser::$admin && !CurrentUser::$uploader && sizeof($this->list_files($dir, true, false, true)) == 0) { return; } /// Set variables $this->title = end(explode('/', $dir)); $this->webdir = urlencode(File::a2r($dir)); $this->path = File::a2r($dir); try { /// Check if selected dir is in $dir File::a2r(CurrentUser::$path, $dir); $this->selected = true; $this->class = "level-{$level} selected"; } catch (Exception $e) { /// Selected dir not in $dir, or nothing is selected $this->selected = false; $this->class = "level-{$level}"; } /// Create Menu for each directory $subdirs = $this->list_dirs($dir); if (Settings::$reverse_menu) { $subdirs = array_reverse($subdirs); } foreach ($subdirs as $d) { $this->items[] = new Menu($d, $level + 1); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Judge the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Judge::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function Zip($dir) { /// Check that user is allowed to acces this content if (!Judge::view($dir)) { return; } /// Prepare file $tmpfile = tempnam("tmp", "zip"); $zip = new ZipArchive(); $zip->open($tmpfile, ZipArchive::OVERWRITE); /// Staff with content $items = Menu::list_files($dir, true); foreach ($items as $item) { if (Judge::view($item)) { $zip->addFile($item, basename(dirname($item)) . "/" . basename($item)); } } // Close and send to user $fname = basename($dir); $zip->close(); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($tmpfile)); header("Content-Disposition: attachment; filename=\"" . htmlentities($fname, ENT_QUOTES, 'UTF-8') . ".zip\""); readfile($tmpfile); unlink($tmpfile); }
/** * Generates a zip. * * @param string $dir * @return void * @author Thibaud Rohmer */ public static function Zip($dir) { /// Check that user is allowed to acces this content if (!Judge::view($dir)) { return; } // Get the relative path of the files $delimPosition = strrpos($dir, '/'); if (strlen($dir) == $delimPosition) { echo "Error: Directory has a slash at the end"; return; } // Create list with all filenames $items = Menu::list_files($dir, true); $itemsString = ''; foreach ($items as $item) { if (Judge::view($item)) { // Use only the relative path of the filename $item = str_replace('//', '/', $item); $itemsString .= " '" . substr($item, $delimPosition + 1) . "'"; } } // Close and send to user header('Content-Type: application/zip'); header("Content-Disposition: attachment; filename=\"" . htmlentities(basename($dir), ENT_QUOTES, 'UTF-8') . ".zip\""); // Store the current working directory and change to the albums directory $cwd = getcwd(); chdir(substr($dir, 0, $delimPosition)); // ZIP-on-the-fly method copied from http://stackoverflow.com/questions/4357073 // // use popen to execute a unix command pipeline // and grab the stdout as a php stream $fp = popen('zip -n .jpg:.JPG:.jpeg:.JPEG -0 - ' . $itemsString, 'r'); // pick a bufsize that makes you happy (8192 has been suggested). $bufsize = 8192; $buff = ''; while (!feof($fp)) { $buff = fread($fp, $bufsize); echo $buff; /// flush(); } pclose($fp); // Chang to the previous working directory chdir($cwd); }
/** * Retrieves info for the current user account * * @author Thibaud Rohmer */ public static function init() { CurrentUser::$accounts_file = Settings::$conf_dir . "/accounts.xml"; CurrentUser::$groups_file = Settings::$conf_dir . "/groups.xml"; /// Set path if (isset($_GET['f'])) { CurrentUser::$path = stripslashes(File::r2a($_GET['f'])); if (isset($_GET['p'])) { switch ($_GET['p']) { case 'n': CurrentUser::$path = File::next(CurrentUser::$path); break; case 'p': CurrentUser::$path = File::prev(CurrentUser::$path); break; } } } else { /// Path not defined in URL CurrentUser::$path = Settings::$photos_dir; } /// Set CurrentUser account if (isset($_SESSION['login'])) { self::$account = new Account($_SESSION['login']); // groups sometimes can be null $groups = self::$account->groups === NULL ? array() : self::$account->groups; self::$admin = in_array("root", $groups); self::$uploader = in_array("uploaders", $groups); } /// Set action (needed for page layout) if (isset($_GET['t'])) { switch ($_GET['t']) { case "Page": case "Img": case "Thb": CurrentUser::$action = $_GET['t']; break; case "Big": case "BDl": case "Zip": if (!Settings::$nodownload) { CurrentUser::$action = $_GET['t']; } break; case "Reg": if (isset($_POST['login']) && isset($_POST['password'])) { if (!Account::create($_POST['login'], $_POST['password'], $_POST['verif'])) { echo "Error creating account."; } } case "Log": if (isset($_SESSION['login'])) { CurrentUser::logout(); echo "logged out"; break; } if (isset($_POST['login']) && isset($_POST['password'])) { try { if (!CurrentUser::login($_POST['login'], $_POST['password'])) { echo "Wrong password"; } } catch (Exception $e) { echo "Account not found"; } } if (!isset(CurrentUser::$account)) { CurrentUser::$action = $_GET['t']; } break; case "Acc": if (isset($_POST['old_password'])) { Account::edit($_POST['login'], $_POST['old_password'], $_POST['password'], $_POST['name'], $_POST['email']); } CurrentUser::$action = "Acc"; break; case "Adm": if (CurrentUser::$admin) { CurrentUser::$action = "Adm"; } break; case "Com": Comments::add(CurrentUser::$path, $_POST['content'], $_POST['login']); break; case "Rig": Judge::edit(CurrentUser::$path, $_POST['users'], $_POST['groups'], true); CurrentUser::$action = "Judge"; break; case "Pub": Judge::edit(CurrentUser::$path); CurrentUser::$action = "Judge"; break; case "Pri": Judge::edit(CurrentUser::$path, array(), array(), true); CurrentUser::$action = "Judge"; break; case "Inf": CurrentUser::$action = "Inf"; break; case "Fs": if (is_file(CurrentUser::$path)) { CurrentUser::$action = "Fs"; } break; default: CurrentUser::$action = "Page"; break; } } else { CurrentUser::$action = "Page"; } if (isset($_GET['a']) && CurrentUser::$action != "Adm") { if (CurrentUser::$admin || CurrentUser::$uploader) { new Admin(); } } if (isset($_GET['j'])) { CurrentUser::$action = "JS"; } /// Set default action if (!isset(CurrentUser::$action)) { CurrentUser::$action = "Page"; } /// Throw exception if accounts file is missing if (!file_exists(CurrentUser::$accounts_file)) { throw new Exception("Accounts file missing", 69); } /// Create Group File if it doesn't exist if (!file_exists(CurrentUser::$groups_file)) { Group::create_group_file(); } if (isset(CurrentUser::$account)) { CurrentUser::$admin = in_array("root", CurrentUser::$account->groups); } }
/** * Generate a foldergrid * * @return void * @author Thibaud Rohmer */ private function foldergrid() { foreach ($this->dirs as $d) { $firstImg = Judge::searchDir($d); if (!(Judge::view($d) || $firstImg)) { continue; } $f = Menu::list_files($d, true); if (CurrentUser::$admin || CurrentUser::$uploader || sizeof($f) > 0) { if ($firstImg) { $f[0] = $firstImg; } $item = new BoardDir($d, $f); $this->boardfolders[] = $item; } } }
<?php if (!isset($_SESSION)) { session_start(); } setlocale(LC_TIME, 'et_EE.UTF-8'); ini_set('display_errors', 1); if (defined('E_DEPRECATED')) { error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); } else { error_reporting(E_ALL & ~E_STRICT); } date_default_timezone_set('Europe/Tallinn'); require_once 'CommonPageView.php'; require_once dirname(__FILE__) . '/JudgeView.php'; require_once 'Judge.php'; if (isset($_GET['index']) && $_GET['index'] > -1) { $judge = new Judge(); $judge->setIdJudge($_GET['index']); $judge->setCompleteJudge(); $htmlOfJudges = JudgeView::buildJudge(array('judge' => $judge)); } else { $judges = Judge::getJudges(); $htmlOfJudges = JudgeView::buildJudges(array('judges' => $judges)); } $html = CommonPageView::buildPage(array('middle' => $htmlOfJudges)); echo $html;
/** * Return image(s) $img */ public static function get_img($key, $img, $t = 'large') { if (is_array($img)) { $res = array(); foreach ($img as $i) { $p = get_img($key, $i, $t); if (isset($p)) { $res[] = $p; } } return $res; } else { $i = File::r2a($img); if (Judge::view($i)) { switch ($t) { case "thumb": return file_get_contents(Provider::thumb($i)); case "small": return file_get_contents(Provider::small($i)); case "large": default: return file_get_contents($i); } } } }
/** * Display BoardItem on Website * * @return void * @author Thibaud Rohmer */ public function toHTML() { if (sizeof($this->images) > 0) { $getfile = "t=Thb&f=" . urlencode(File::a2r($this->images[0])); } else { $getfile = ""; } /// We display the image as a background echo "<div class='directory'>"; echo "<span class='name hidden'>" . htmlentities(basename($this->path), ENT_QUOTES, 'UTF-8') . "</span>"; echo "<span class='path hidden'>" . htmlentities(File::a2r($this->path), ENT_QUOTES, 'UTF-8') . "</span>"; echo "<div class='dir_img'"; echo " style='"; echo " background: \t\turl(\"?{$getfile}\") no-repeat center center;"; echo " -webkit-background-size: cover;"; echo " -moz-background-size: cover;"; echo " -o-background-size: cover;"; echo " background-size: \tcover;"; echo "'>\n"; echo "<span class='img_bg hidden'></span>"; /// Images in the directory if (sizeof($this->images) > Settings::$max_img_dir) { for ($i = 0; $i < Settings::$max_img_dir; $i++) { $pos = floor(sizeof($this->images) * $i / Settings::$max_img_dir); if (Judge::view($this->images[$pos])) { echo "<div class='alt_dir_img hidden'>" . urlencode(File::a2r($this->images[$pos])) . "</div>"; } } } else { foreach ($this->images as $img) { if (Judge::view($img)) { echo "<div class='alt_dir_img hidden'>" . urlencode(File::a2r($img)) . "</div>"; } } } echo "<a href='?f={$this->url}'>"; echo "<img src='./inc/img.png' width='100%' height='100%'>"; echo "</a>\n"; echo "</div>\n"; echo "<div class='dirname'>"; echo htmlentities(basename($this->path), ENT_QUOTES, 'UTF-8'); echo "</div>\n"; echo "</div>\n"; }
private function playerWins($board, $char) { $playerBoard = new PlayerBoard($board, $char); $judge = new Judge($playerBoard); return $judge->playerIsWinner(); }
/** * This function sets the complete judge. * * @access public * @author kalmer */ public function setCompleteJudge() { $judges = Judge::getJudges(); $this->firstName = $judges[$this->idJudge]->firstName; $this->lastName = $judges[$this->idJudge]->lastName; $this->emailAddress = $judges[$this->idJudge]->emailAddress; $this->phoneNumber = $judges[$this->idJudge]->phoneNumber; $this->image = $judges[$this->idJudge]->image; $this->width = $judges[$this->idJudge]->width; $this->height = $judges[$this->idJudge]->height; }
public function __construct() { /// Execute stuff automagically new Admin(); if (isset($_GET['j'])) { switch ($_GET['j']) { case "Pag": $m = new Menu(); $p = new Board(); $ap = new AdminPanel(); echo "<div id='menu' class='menu'>\n"; $m->toHTML(); echo "</div>\n"; echo "<div class='panel'>\n"; $p->toHTML(); echo "</div>\n"; echo "<div class='image_panel hidden'>\n"; echo "</div>\n"; if (CurrentUser::$admin) { echo "<div class='infos'>\n"; $ap->toHTML(); echo "</div>\n"; } break; case "Log": $p = new LoginPage(); $p->toHTML(); break; case "Reg": $p = new RegisterPage(); $p->toHTML(); break; case "Pan": if (is_file(CurrentUser::$path)) { $b = new ImagePanel(CurrentUser::$path); $b->toHTML(); } else { $b = new Board(CurrentUser::$path); $b->toHTML(); } break; case "Men": $m = new Menu(); $m->toHTML(); break; case "Pan": $f = new AdminPanel(); $f->toHTML(); break; case "Inf": $f = new Infos(); $f->toHTML(); break; case "Jud": $j = new Judge(CurrentUser::$path); $j->toHTML(); break; case "Acc": $f = new Group(); $f->toHTML(); break; case "Comm": $f = new Comments(CurrentUser::$path); $f->toHTML(); break; default: break; } } }
/** * Upload files on the server * * @author Thibaud Rohmer */ public function upload() { $allowedExtensions = array("tiff", "jpg", "jpeg", "gif", "png"); /// Just to be really sure ffmpeg enable - necessary generate thumbnail jpg and webm if (Settings::$encode_video) { array_push($allowedExtensions, "flv", "mov", "mpg", "mp4", "ogv", "mts", "3gp", "webm"); } $already_set_rights = false; /// Just to be really sure... if (!(CurrentUser::$admin || CurrentUser::$uploader)) { return; } /// Set upload path $path = stripslashes(File::r2a($_POST['path'])); /// Create dir and update upload path if required if (strlen(stripslashes($_POST['newdir'])) > 0 && !strpos(stripslashes($_POST['newdir']), '..')) { $path = $path . "/" . stripslashes($_POST['newdir']); if (!file_exists($path)) { @mkdir($path, 0750, true); @mkdir(File::r2a(File::a2r($path), Settings::$thumbs_dir), 0750, true); } /// Setup rights if (!isset($_POST['inherit'])) { if (isset($_POST['public'])) { Judge::edit($path); } else { Judge::edit($path, $_POST['users'], $_POST['groups']); } } $already_set_rights = true; } if (!isset($_FILES["images"])) { return; } /// Treat uploaded files foreach ($_FILES["images"]["error"] as $key => $error) { // Check that file is uploaded if ($error == UPLOAD_ERR_OK) { // Name of the stored file $tmp_name = $_FILES["images"]["tmp_name"][$key]; // Name on the website $name = $_FILES["images"]["name"][$key]; $info = pathinfo($name); $base_name = basename($name, '.' . $info['extension']); // Check filetype if (!in_array(strtolower($info['extension']), $allowedExtensions)) { continue; } // Rename until this name isn't taken $i = 1; while (file_exists("{$path}/{$name}")) { $name = $base_name . "-" . $i . "." . $info['extension']; $i++; } // Save the files if (move_uploaded_file($tmp_name, "{$path}/{$name}")) { // $done .= "Successfully uploaded $name"; Video::FastEncodeVideo("{$path}/{$name}"); } /// Setup rights if (!$already_set_rights && !isset($_POST['inherit'])) { if (isset($_POST['public'])) { Judge::edit($path); } else { Judge::edit($path, $_POST['users'], $_POST['groups']); } } } } }
<?php require_once __DIR__ . '/CreateVhdl.php'; require_once __DIR__ . '/Vhdl.class.php'; require_once __DIR__ . '/Unzip.class.php'; $teste = new Judge(); $teste->judgee(__DIR__, 'circuito.vhd'); //caminho atual, nome do arquivo principal
/** * Returns true if the current user may access this file * * @param string $f file to access * @return bool * @author Thibaud Rohmer */ public static function view($f) { // Check if user has an account if (!isset(CurrentUser::$account)) { // User is not logged in $judge = new Judge($f); return $judge->public; } if (!Judge::inGoodPlace($f)) { return false; } // No Judge required for the admin. This guy rocks. if (CurrentUser::$admin) { return true; } // Create Judge $judge = new Judge($f); // Public file if ($judge->public) { return true; } // User allowed if (in_array(CurrentUser::$account->login, $judge->users)) { return true; } // User in allowed group foreach (CurrentUser::$account->groups as $group) { if (in_array($group, $judge->groups)) { return true; } } return false; }
/** * Generate a foldergrid * * @return void * @author Thibaud Rohmer */ private function foldergrid() { foreach ($this->dirs as $d) { if (!Judge::view($d)) { //Dir is not accessible (rights) - ignore it for better performance continue; } $firstImg = Judge::searchDir($d); if (!$firstImg) { if (CurrentUser::$admin) { $firstImg = NULL; } else { continue; } } $item = new BoardDir($d, $firstImg); $this->boardfolders[] = $item; } if (Settings::$reverse_menu) { $this->boardfolders = array_reverse($this->boardfolders); } }
public function actionMasters() { //print_r($_POST);exit; if ($_POST['role'] == "Judicial Officer") { $data = Judge::model()->findAllByAttributes(array("district_id" => array($_POST['district']))); //print_r($data);exit; //$data=CHtml::listData($data,'id','name'); foreach ($data as $value => $name) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name->name . " - " . $name->judge_code), true); } } elseif ($_POST['role'] == "Police Official") { $data = ChallaningOfficer::model()->findAll(); $data = CHtml::listData($data, 'id', 'name'); foreach ($data as $value => $name) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true); } } elseif ($_POST['role'] == "Court Staff") { echo CHtml::tag('option', array('value' => ""), CHtml::encode("--Field is not required--"), true); } }
public static function Video($file, $width = '100%', $height = '100%', $control = false) { if (!Judge::view($file)) { return; } if (function_exists("error_reporting")) { error_reporting(0); } /// Check item if (!File::Type($file) || File::Type($file) != "Video") { return; } $basefile = new File($file); $basepath = File::a2r($file); $path_webm = Settings::$thumbs_dir . dirname($basepath) . "/" . $basefile->name . '.webm'; $c = null; Video::FastEncodeVideo($file); $wh = ' height="' . $height . '" width="' . $width . '"'; if ($control) { $c = ' controls="controls"'; } echo '<video' . $wh . $c . '><source src="' . $path_webm . '" type="video/webm" /></video>'; //echo 'Webm Video Codec not found.Plaese up to date the brower or Download the codec <a href="http://tools.google.com/dlpage/webmmf">Download</a>'; }
/** * @dataProvider positiveCases */ public function testPositives($value) { $j = new Judge(); $this->assertTrue($j->isValid($value)); }