Exemplo n.º 1
0
 function testCheckModified()
 {
     $f = new \jf\DownloadManager();
     $_SERVER['http_if_modified_since'] = "Sat, 06 Apr 2013 10:23:21 GMT";
     $this->assertTrue($f->IsModifiedSince(__FILE__));
 }
Exemplo n.º 2
0
    jf\ErrorHandler::$Enabled = false;
    //disable it if embedded or CLI because another system is handling it.
} else {
    jf\ErrorHandler::$Enabled = true;
    //Enables jframework's built-in error handler
}
jf::$ErrorHandler->SetErrorHandler();
if (jf::$RunMode->IsDevelop()) {
    jf\ErrorHandler::$PresentErrors = true;
} else {
    jf\ErrorHandler::$PresentErrors = false;
}
/**
 * Bandwidth Management
 *
 * jframework handles all file feeds and downloads manually.
 * Its FileManager has the ability to limit download speed of files larger than a specific size.
 * Set both the initial size and the limit here.
 */
jf\DownloadManager::$BandwidthLimitInitialSize = -1;
# negative number disables it
jf\DownloadManager::$BandwidthLimitSpeed = 1024 * 1024;
/**
 * Iterative Templates
 *
 * If this is set, jframework viewer would look into the view folder and all its ancestor folders
 * to find a template folder, and would display the first template it finds.
 * Otherwise only the same folder is checked for templates.
 */
jf\View::$IterativeTemplates = true;
jf::import("config/more");
Exemplo n.º 3
0
 public function Handle($request)
 {
     // This gives complete request path
     $request = jf::$BaseRequest;
     //FIXME: Fix JCatchControl so that this is not required
     if (jf::CurrentUser()) {
         // If user is logged in
         // Check if the user has permissions
         // to view the challenges
         if (jf::Check('view_single_chal')) {
             // Extract the relative request path
             // i.e the path after the controller URL
             // Ex: If request is http://localhost/webgoatphp/mode/single/challenges/HTTPBasics/static/test
             // $request will be mode/single/challenges/HTTPBasics/static/test
             // $relativePath will be HTTPBasics/static/test
             $relativePath = $this->getRelativePath($request);
             $absolutePath = LESSON_PATH . $relativePath;
             if (strpos($relativePath, "/static/") !== false) {
                 if (file_exists($absolutePath)) {
                     $FileMan = new \jf\DownloadManager();
                     return $FileMan->Feed($absolutePath);
                 }
             } else {
                 $nameOfLesson = stristr($relativePath, "/", true);
                 \webgoat\LessonScanner::loadClasses();
                 if (strpos($relativePath, "reset/") !== false) {
                     $lessonNameWithNS = "\\webgoat\\" . $nameOfLesson;
                     $obj = new $lessonNameWithNS();
                     $obj->reset();
                     echo json_encode(array("status" => true));
                     return true;
                 } else {
                     if (isset($_GET['refresh']) || !jf::LoadGeneralSetting("categoryLessons")) {
                         \webgoat\LessonScanner::run();
                     }
                     $this->allCategoryLesson = jf::LoadGeneralSetting("categoryLessons");
                     try {
                         $lessonObj = \webgoat\LessonScanner::getLessonObject($nameOfLesson);
                         $lessonObj->start();
                         $this->lessonTitle = $lessonObj->getTitle();
                         $this->hints = $lessonObj->getHints();
                         $this->htmlContent = $lessonObj->getContent();
                         $this->nameOfLesson = $nameOfLesson;
                         $secureCoding = $lessonObj->isSecureCodingAllowed();
                         $sourceCodeToDisplay = "";
                         if ($secureCoding['status'] === true) {
                             $sourceCode = file($absolutePath . "index.php");
                             $firstLine = $sourceCode[$secureCoding['start']];
                             $this->indentSize = strlen($firstLine) - strlen(ltrim($firstLine));
                             for ($i = $secureCoding['start']; $i < $secureCoding['end']; $i++) {
                                 $sourceCodeToDisplay .= $this->removeWhitespaces($sourceCode[$i]) . "\n";
                             }
                             $this->sourceCode = $sourceCodeToDisplay;
                         }
                         // To show complete PHP Code
                         $sourceCode = file_get_contents($absolutePath . "index.php");
                         $this->completeSourceCode = htmlentities($sourceCode);
                         if (isset($_POST['sourceCode'])) {
                             // Code to handle source code evaluation
                         }
                     } catch (Exception $e) {
                         //$this->error = "Lesson Not found. Please select a lesson.";
                         $this->error = $e->getMessage();
                     }
                     header("X-XSS-Protection: 0");
                     // Disable XSS protection
                     return $this->Present();
                 }
             }
         } else {
             // Not sufficient permissions, redirect
             // to home page of the application
             $this->Redirect(SiteRoot);
         }
     } else {
         // User not logged in
         $this->Redirect(jf::url() . "/user/login?return=/{$request}");
     }
 }
Exemplo n.º 4
0
session_write_close();
$id = $_GET['id'] * 1;
$isAdmin = $_SESSION['user']['access'];
$initial_time = time();
function timeout()
{
    global $initial_time;
    static $timeout = null;
    if ($timeout === null) {
        $timeout = rand(3, 10);
    }
    if (time() - $initial_time > $timeout) {
        flush();
        die;
    }
}
if (!$isAdmin) {
    declare (ticks=1);
}
lib("download");
if (!$isAdmin) {
    register_tick_function("timeout");
}
$dl = new \jf\DownloadManager();
if (!$isAdmin) {
    $dl::$BandwidthLimitSpeed = 1024 / 8;
    //128 bytes
    $dl::$BandwidthLimitInitialSize = 1024;
    //1KB
}
$dl->Feed(AvatarFile($id));
Exemplo n.º 5
0
<?php

function do404()
{
    header("404 Not Found");
    echo "<h1>404 Not Found</h1>";
    echo "<p>The requested URL " . htmlspecialchars($_SERVER['REQUEST_URI']) . " not found.</p>";
    exit(0);
}
$request = $_GET['__r'];
unset($_GET['__r']);
$parts = explode("/", $request);
if ($parts[count($parts) - 1] == "") {
    $parts[count($parts)] = "index";
}
$file = realpath(__DIR__ . "/static/" . implode("/", $parts));
if ($file and is_file($file)) {
    if (!$file) {
        do404();
    }
    require_once __DIR__ . "/lib/download.php";
    $x = new \jf\DownloadManager();
    $x->Feed($file);
} else {
    $file = realpath(__DIR__ . "/app/" . implode("/", $parts) . ".php");
    if (!$file) {
        do404();
    }
    require_once __DIR__ . "/load.php";
    require $file;
}