Exemple #1
0
function dumpWithEtag($path)
{
    $path = urldecode($path);
    $qIndex = strpos($path, '?');
    if ($qIndex !== false) {
        $path = substr($path, 0, $qIndex);
    }
    /* I think, it is a bad idea to check '..' and skip.
       but this is an annoyance to solve gracefully about whole HTTP request */
    /* Kill them all requests with referencing parent directory */
    if (strpos($path, "/..") !== false || strpos($path, "\\..") !== false || strcasecmp(substr($path, -3), "php") == 0 || !file_exists($path)) {
        header("HTTP/1.0 404 Not found");
        exit;
    }
    $fs = stat($path);
    if (!$fs || !$fs['size']) {
        header('HTTP/1.1 404 Not Found');
        exit;
    }
    $etag = sprintf("textcube-%x", 0x1234 * $fs['size'] ^ $fs['mtime']);
    $lastmodified = gmdate("D, j M Y H:i:s ", $fs['mtime']) . "GMT";
    $length = $fs['size'];
    if (!headerEtag($etag, $length, $lastmodified)) {
        header('Content-type: ' . getMIMEType(null, $path));
        $f = fopen($path, "r");
        if (!$f) {
            header("HTTP/1.0 404 Not found");
            exit;
        }
        while ($content = fread($f, 8192)) {
            echo $content;
        }
        fclose($f);
    }
}
Exemple #2
0
    define('__TEXTCUBE_ATTACH_DIR__', 'gs://' . $_SERVER['blog_fs_bucket'] . '/attach');
    define('__TEXTCUBE_SKIN_STORAGE__', 'gs://' . $_SERVER['blog_fs_bucket'] . '/skin');
}
if (!array_key_exists('blog_fs_bucket', $_SERVER)) {
    syslog('Missing a blog_fs_bucket env variable in app.yaml');
    header("HTTP/1.0 404 Not Found");
    exit;
}
// Modify SCRIPT_NAME for other codes.
$_SERVER["SCRIPT_NAME"] = str_replace('gae.php', '', $_SERVER["SCRIPT_NAME"]);
// Handles $blogURL/attach/... for attachment files.
if (substr($_SERVER["REQUEST_URI"], 0, 8) == '/attach/') {
    $requestFilename = strtok(substr($_SERVER["REQUEST_URI"], 7), '?#');
    if (file_exists(__TEXTCUBE_ATTACH_DIR__ . $requestFilename)) {
        require 'library/function/file.php';
        $option = ['content_type' => getMIMEType('', $requestFilename)];
        CloudStorageTools::serve(__TEXTCUBE_ATTACH_DIR__ . $requestFilename, $option);
        exit;
    }
}
// Handles $blogURL/blog/skin/customize... for custom skin files.
if (substr($_SERVER["REQUEST_URI"], 0, 21) == '/skin/blog/customize/') {
    $requestFilename = strtok(substr($_SERVER["REQUEST_URI"], 5), '?#');
    if (file_exists(__TEXTCUBE_SKIN_STORAGE__ . $requestFilename)) {
        require 'library/function/file.php';
        $option = ['content_type' => getMIMEType('', $requestFilename)];
        CloudStorageTools::serve(__TEXTCUBE_SKIN_STORAGE__ . $requestFilename, $option);
        exit;
    }
}
require_once 'rewrite.php';