Ejemplo n.º 1
0
 function _streamThumb(&$man, $input)
 {
     if (!$man->verifyPath($input["path"]) < 0) {
         trigger_error("Path verification failed.", FATAL);
         die;
     }
     $path = $man->decryptPath($input["path"]);
     $file =& $man->getFile($path);
     $ext = getFileExt($file->getName());
     $config = $file->getConfig();
     $urlprefix = $man->toUnixPath($config['preview.urlprefix']);
     $urlsuffix = $man->toUnixPath($config['preview.urlsuffix']);
     // NOTE: Verify more stuff here before proceeding.
     if ($man->verifyFile($file, "thumbnail", $config) < 0) {
         trigger_error("Path verification failed.", FATAL);
         die;
     }
     //$imageutils = new $config['thumbnail'];
     //$canEdit = $imageutils->canEdit($ext);
     // Check if we have an EXIF JPG file.
     if ($config['thumbnail.use_exif'] == true && function_exists("exif_thumbnail") && (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg")) {
         $image = @exif_thumbnail($file->getAbsolutePath(), $exif_width, $exif_height, $exif_type);
         if ($image !== false) {
             header('Content-type: ' . image_type_to_mime_type($exif_type));
             echo $image;
             return null;
         }
     }
     $thumbnail = $this->_createThumb($man, $file);
     if ($thumbnail != false) {
         header('Content-type: ' . mapMimeTypeFromUrl($thumbnail->getName(), "../" . $config['stream.mimefile']));
         if (!readfile($thumbnail->getAbsolutePath())) {
             header("Location: " . $urlprefix . $man->convertPathToURI($thumbnail->getAbsolutePath()) . $urlsuffix);
         }
     } else {
         header('Content-type: ' . mapMimeTypeFromUrl($file->getName(), "../" . $config['stream.mimefile']));
         if (!readfile($file->getAbsolutePath())) {
             header("Location: " . $urlprefix . $man->convertPathToURI($file->getAbsolutePath()) . $urlsuffix);
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Gets called when data is streamed to client. This method should setup
  * HTTP headers, content type etc and simply send out the binary data to the client and the return false
  * ones that is done.
  *
  * @param MCManager $man MCManager reference that the plugin is assigned to.
  * @param string $cmd Stream command that is to be performed.
  * @param string $input Array of input arguments.
  * @return bool true/false if the execution of the event chain should continue.
  */
 function onStream(&$man, $cmd, $input)
 {
     $config = $man->getConfig();
     // Download stream
     if ($cmd == "download") {
         if ($man->verifyPath($input["path"])) {
             $file =& $man->getFile($input["path"]);
             $config = $file->getConfig();
             if ($man->verifyFile($file, "download") > 0 && $file->exists()) {
                 // Get the mimetype, need to go to ../ parent folder cause... well we have to.
                 //$mimeType = mapMimeTypeFromUrl($file->getAbsolutePath(), "../". $config['stream.mimefile']);
                 header("Content-type: application/octet-stream");
                 header("Content-Disposition: attachment; filename=" . $file->getName());
                 // Stream data
                 $stream =& $file->open('rb');
                 if ($stream) {
                     while (($buff = $stream->read()) != null) {
                         echo $buff;
                     }
                     $stream->close();
                 }
                 return false;
             }
         } else {
             header('HTTP/1.0 404 Not found');
             header('status: 404 Not found');
             echo "Requested resource could not be found. Or access was denied.";
             die;
         }
         // Do not pass to next
         return false;
     }
     // Normal stream
     if ($cmd == "streamFile") {
         if (!$man->verifyPath($input["path"]) < 0) {
             trigger_error("Path verification failed.", FATAL);
             die;
         }
         $file = $man->getFile($input["path"]);
         $config = $file->getConfig();
         if (!$file->exists()) {
             trigger_error("File not found.", FATAL);
             die;
         } else {
             if (getClassName($file) == 'moxiecode_localfileimpl') {
                 // Redirect to data
                 $url = $man->removeTrailingSlash($config['preview.urlprefix']) . $man->convertPathToURI($file->getParent() . "/" . str_replace("+", "%20", urlencode($file->getName()))) . $config['preview.urlsuffix'];
                 // Passthrough rnd
                 if (isset($input["rnd"])) {
                     $url .= (strpos($url, "?") === false ? "?" : "&") . "rnd=" . $input["rnd"];
                 }
                 header('location: ' . $url);
                 die;
             } else {
                 // Verify that we can stream this one
                 if ($man->verifyFile($file, "stream") < 0) {
                     header('HTTP/1.0 404 Not found');
                     header('status: 404 Not found');
                     echo "Requested resource could not be found. Or access was denied.";
                     die;
                 }
                 // Get the mimetype, need to go to ../ parent folder cause... well we have to.
                 $mimeType = mapMimeTypeFromUrl($file->getAbsolutePath(), "../" . $config['stream.mimefile']);
                 header("Content-type: " . $mimeType);
                 // Stream data
                 $stream =& $file->open('rb');
                 if ($stream) {
                     while (($buff = $stream->read()) != null) {
                         echo $buff;
                     }
                     $stream->close();
                 }
             }
             return false;
         }
     }
     // Devkit commands
     switch ($cmd) {
         case "viewServerInfo":
             if (!checkBool($config['general.debug'])) {
                 die("You have to enable debugging in config by setting general.debug to true.");
             }
             phpinfo();
             break;
         case "downloadServerInfo":
             if (!checkBool($config['general.debug'])) {
                 die("You have to enable debugging in config by setting general.debug to true.");
             }
             // Get all ini settings
             $data = ini_get_all();
             // Setup all headers
             header("Content-type: text/plain");
             header("Content-Disposition: attachment; filename=dump.txt");
             header('Content-Encoding: UTF-8');
             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
             header("Cache-Control: no-store, no-cache, must-revalidate");
             header("Cache-Control: post-check=0, pre-check=0", false);
             header("Pragma: no-cache");
             echo "# Config from config.php" . "\r\n\r\n";
             foreach ($config as $key => $value) {
                 if (is_bool($value)) {
                     echo $key . "=" . ($value ? "true" : "false") . "\r\n";
                 } else {
                     echo $key . "=" . $value . "\r\n";
                 }
             }
             // Dump INI settings
             echo "\r\n# PHP INI settings file\r\n\r\n";
             foreach ($data as $key => $value) {
                 echo $key . "=" . $value['local_value'] . "\r\n";
             }
             // Dump function support
             echo "\r\n# Function check" . "\r\n\r\n";
             $functions = array("ImagecreateFromJpeg", "ImageJpeg", "ImagecreateFromGif", "ImageGif", "ImagecreateFromPng", "ImagePng", "gzdeflate", "gzinflate");
             foreach ($functions as $function) {
                 echo $function . "=" . (function_exists($function) ? "ok" : "missing") . "\r\n";
             }
             // Dump rootpath access
             echo "\r\n# Rootpath access" . "\r\n\r\n";
             foreach ($man->getRootPaths() as $rootpath) {
                 $stat = stat($rootpath);
                 echo $rootpath . "\r\n";
                 echo "  is_readable=" . (is_readable($rootpath) ? "readable" : "not readable") . "\r\n";
                 echo "  is_writable=" . (is_writable($rootpath) ? "writable" : "not writable") . "\r\n";
                 foreach ($stat as $key => $value) {
                     echo "  " . $key . "=" . $value . "\r\n";
                 }
             }
             break;
         case "viewLog":
             if (!checkBool($config['general.debug'])) {
                 die("You have to enable debugging in config by setting general.debug to true.");
             }
             header('Content-type: text/plain');
             if ($input['level'] == "debug") {
                 echo @file_get_contents("../logs/debug.log");
             } else {
                 echo @file_get_contents("../logs/error.log");
             }
             break;
         case "clearLog":
             header('Content-type: text/plain');
             if (!checkBool($config['general.debug'])) {
                 die("You have to enable debugging in config by setting general.debug to true.");
             }
             if ($input['level'] == "debug") {
                 $log = "../logs/debug.log";
             } else {
                 $log = "../logs/error.log";
             }
             @unlink($log);
             for ($i = 0; $i < 10; $i++) {
                 @unlink($log . "." . $i);
             }
             echo "Logs cleared.";
             break;
     }
     // Pass to next
     return true;
 }
Ejemplo n.º 3
0
 * @package MCFileManager.pages
 * @author Moxiecode
 * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved.
 */
require_once "includes/general.php";
require_once "includes/stream.php";
require_once "classes/FileSystems/FileFactory.php";
require_once "classes/FileSystems/LocalFileImpl.php";
verifyAccess($mcFileManagerConfig);
$path = getRequestParam("path");
$rootpath = getRequestParam("rootpath", toUnixPath(getRealPath($mcFileManagerConfig, 'filesystem.rootpath')));
$fileFactory =& new FileFactory($mcFileManagerConfig, $rootpath);
$targetFile =& $fileFactory->getFile($path);
$config = $targetFile->getConfig();
$mode = getRequestParam("mode", "stream");
$mimeType = mapMimeTypeFromUrl($path, $config['stream.mimefile']);
$file =& $fileFactory->getFile($path);
// Setup first filter
$fileFilterA =& new BasicFileFilter();
$fileFilterA->setIncludeFilePattern($config['filesystem.include_file_pattern']);
$fileFilterA->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
$fileFilterA->setIncludeExtensions($config['filesystem.extensions']);
// Setup second filter
$fileFilterB =& new BasicFileFilter();
$fileFilterB->setIncludeFilePattern($config['download.include_file_pattern']);
$fileFilterB->setExcludeFilePattern($config['download.exclude_file_pattern']);
$fileFilterB->setIncludeExtensions($config['download.extensions']);
if (!$fileFilterA->accept($targetFile) || !$fileFilterB->accept($targetFile)) {
    trigger_error("Error: Requested file is not valid for download, check your config.", ERROR);
}
addFileEventListeners($fileFactory);