Beispiel #1
0
    $size = $DB->q("MAYBEVALUE SELECT OCTET_LENGTH(zipfile)\n\t                FROM executable WHERE execid = %s", $id);
    // sanity check before we start to output headers
    if ($size === NULL || !is_numeric($size)) {
        error("Problem while fetching executable");
    }
    header("Content-Type: application/zip; name=\"{$filename}\"");
    header("Content-Disposition: attachment; filename=\"{$filename}\"");
    header("Content-Length: {$size}");
    echo $DB->q("VALUE SELECT SQL_NO_CACHE zipfile FROM executable\n\t             WHERE execid = %s", $id);
    exit(0);
}
if (isset($_POST['upload'])) {
    if (!empty($_FILES['executable_archive']['tmp_name'][0])) {
        foreach ($_FILES['executable_archive']['tmp_name'] as $fileid => $tmpname) {
            checkFileUpload($_FILES['executable_archive']['error'][$fileid]);
            $zip = openZipFile($_FILES['executable_archive']['tmp_name'][$fileid]);
            $prop_file = 'domjudge-executable.ini';
            $newid = $_FILES['executable_archive']['name'][$fileid];
            $newid = substr($newid, 0, strlen($newid) - strlen(".zip"));
            $desc = $newid;
            $type = 'unknown';
            if (isset($_POST['type'])) {
                $type = $_POST['type'];
            }
            if (!empty($id)) {
                $desc = $DB->q('VALUE SELECT description FROM executable WHERE execid=%s', $id);
                $type = $DB->q('VALUE SELECT type FROM executable WHERE execid=%s', $id);
            }
            $ini_array = parse_ini_string($zip->getFromName($prop_file));
            if (!empty($ini_array)) {
                $newid = $ini_array['execid'];
Beispiel #2
0
    if ($current_cid !== null) {
        $extra = '&cid=' . urlencode($current_cid);
    }
    $refresh = array('after' => 15, 'url' => $pagename . '?id=' . urlencode($id) . $extra);
}
// This doesn't return, call before sending headers
if (isset($cmd) && $cmd == 'viewtext') {
    putProblemText($id);
}
require LIBWWWDIR . '/header.php';
if (isset($_POST['upload'])) {
    if (!empty($_FILES['problem_archive']['tmp_name'][0])) {
        foreach ($_FILES['problem_archive']['tmp_name'] as $fileid => $tmpname) {
            $cid = $_POST['contest'];
            checkFileUpload($_FILES['problem_archive']['error'][$fileid]);
            $zip = openZipFile($_FILES['problem_archive']['tmp_name'][$fileid]);
            $newid = importZippedProblem($zip, empty($id) ? NULL : $id, $cid);
            $zip->close();
            auditlog('problem', $newid, 'upload zip', $_FILES['problem_archive']['name'][$fileid]);
        }
        if (count($_FILES['problem_archive']['tmp_name']) == 1) {
            $probid = empty($newid) ? $id : $newid;
            $probname = $DB->q('VALUE SELECT name FROM problem
			                    WHERE probid = %i', $probid);
            echo '<p><a href="' . $pagename . '?id=' . urlencode($probid) . '">Return to problem p' . specialchars($probid) . ': ' . specialchars($probname) . ".</a></p>\n";
        }
        echo "<p><a href=\"problems.php\">Return to problems overview.</a></p>\n";
    } else {
        error("Missing filename for problem upload. Maybe you have to increase upload_max_filesize, see config checker.");
    }
    require LIBWWWDIR . '/footer.php';
Beispiel #3
0
}
$title = "Executable: {$id}";
require LIBWWWDIR . '/header.php';
$edit_mode = isset($_GET['edit_source']);
echo '<h2>' . ($edit_mode ? 'Edit content of e' : 'E') . "xecutable " . htmlspecialchars($id) . "</h2>\n\n";
if ($edit_mode) {
    echo addForm($pagename, 'post', null, 'multipart/form-data');
}
$html = '<script type="text/javascript" src="../js/tabber.js"></script>' . '<script src="../js/ace/ace.js" type="text/javascript" charset="utf-8"></script>' . '<script src="../js/ace/ext-modelist.js" type="text/javascript" charset="utf-8"></script>' . '<div class="tabber">';
if (!($tmpfname = tempnam(TMPDIR, "/executable-"))) {
    error("failed to create temporary file");
}
if (FALSE === file_put_contents($tmpfname, $executable['zipfile'])) {
    error("failed to write zip file to temporary file");
}
$zip = openZipFile($tmpfname);
$skippedBinary = array();
for ($j = 0; $j < $zip->numFiles; $j++) {
    $filename = $zip->getNameIndex($j);
    if ($filename[strlen($filename) - 1] == "/") {
        if ($edit_mode) {
            echo addHidden("skipped[{$j}]", 1);
        }
        continue;
        // skip directory entries
    }
    $content = $zip->getFromIndex($j);
    if (!mb_check_encoding($content, 'ASCII')) {
        $skippedBinary[] = $filename;
        if ($edit_mode) {
            echo addHidden("skipped[{$j}]", 1);