public function __construct($alias, $operation) { $this->log = Logger::getLogger('ProblemDeployer'); $this->alias = $alias; $this->tmpDir = FileHandler::TempDir('/tmp', 'ProblemDeployer', 0755); $this->targetDir = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $this->alias; $this->gitDir = PROBLEMS_GIT_PATH . DIRECTORY_SEPARATOR . $this->alias; $this->operation = $operation; if (!is_writable(PROBLEMS_GIT_PATH)) { $this->log->error('path is not writable:' . PROBLEMS_GIT_PATH); throw new ProblemDeploymentFailedException(); } if ($this->operation == ProblemDeployer::CREATE) { // Atomically try to create the bare repository. if (!@mkdir($this->gitDir, 0755)) { throw new InvalidParameterException('aliasInUse'); } $this->git('init -q --bare ' . escapeshellarg($this->gitDir), PROBLEMS_GIT_PATH); $this->created = true; } // Clone repository into tmp dir $this->git('clone ' . escapeshellarg($this->gitDir) . ' ' . escapeshellarg($this->tmpDir), '/tmp'); // Ensure .gitattributes flags all inputs/outputs as binaries so it does not // take several minutes diffing them to save a little space. if (!file_exists("{$this->tmpDir}/.gitattributes")) { FileHandler::CreateFile("{$this->tmpDir}/.gitattributes", "cases/in/* -diff -delta -merge -text -crlf\n" . 'cases/out/* -diff -delta -merge -text -crlf'); } if ($this->operation == ProblemDeployer::UPDATE_CASES) { $dh = opendir($this->tmpDir); while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..' || $file == '.git' || $file == 'statements' || $file == '.gitattributes') { continue; } $this->git('rm -rf ' . escapeshellarg($file), $this->tmpDir); } closedir($dh); } }
require_once '../../../server/bootstrap.php'; if ($_POST) { if (!in_array($_POST['language'], array('c', 'cpp', 'java'))) { $smarty->assign('error', $smarty->getConfigVars('parameterInvalid')); $smarty->assign('error_field', 'language'); } elseif (!in_array($_POST['os'], array('unix', 'windows'))) { $smarty->assign('error', $smarty->getConfigVars('parameterInvalid')); $smarty->assign('error_field', 'os'); } elseif (!preg_match('/^[a-z_][a-z0-9_]{0,31}$/i', $_POST['name'])) { $smarty->assign('error', $smarty->getConfigVars('parameterInvalid')); $smarty->assign('error_field', 'name'); } elseif (empty($_POST['idl'])) { $smarty->assign('error', $smarty->getConfigVars('parameterInvalid')); $smarty->assign('error_field', 'idl'); } else { $dirname = FileHandler::TempDir(sys_get_temp_dir(), 'libinteractive'); try { file_put_contents("{$dirname}/{$_POST['name']}.idl", $_POST['idl']); $args = array('/usr/bin/java', '-jar', '/opt/omegaup/bin/libinteractive.jar', 'generate', "{$_POST['name']}.idl", $_POST['language'], $_POST['language'], '--makefile', "--{$_POST['os']}"); $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $cmd = join(' ', array_map('escapeshellarg', $args)); $proc = proc_open($cmd, $descriptorspec, $pipes, $dirname, array('LANG' => 'en_US.UTF-8')); if (!is_resource($proc)) { $smarty->assign('error', error_get_last()); } else { fclose($pipes[0]); $output = stream_get_contents($pipes[1]); $err = stream_get_contents($pipes[2]); $retval = proc_close($proc); if ($retval != 0) { $smarty->assign('error', $output . $err);