Ejemplo n.º 1
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.º 2
0
 /**
  * Gets called when custom data is to be added for a file custom data can for example be
  * plugin specific name value items that should get added into a file listning.
  *
  * @param MCManager $man MCManager reference that the plugin is assigned to.
  * @param BaseFile $file File reference to add custom info/data to.
  * @param string $type Where is the info needed for example list or info.
  * @param Array $custom Name/Value array to add custom items to.
  * @return bool true/false if the execution of the event chain should continue.
  */
 function onCustomInfo(&$man, &$file, $type, &$input)
 {
     // Is file and image
     $config = $file->getConfig();
     $input["editable"] = false;
     if ($file->isFile() && ($type == "list" || $type == "insert" || $type == "info")) {
         // Should we get config on each file here?
         //$config = $file->getConfig();
         $ext = getFileExt($file->getName());
         if (!in_array($ext, array('gif', 'jpeg', 'jpg', 'png', 'bmp'))) {
             return true;
         }
         $imageutils = new $config['thumbnail']();
         $canEdit = $imageutils->canEdit($ext);
         $imageInfo = @getimagesize($file->getAbsolutePath());
         $fileWidth = $imageInfo[0];
         $fileHeight = $imageInfo[1];
         $targetWidth = $config['thumbnail.width'];
         $targetHeight = $config['thumbnail.height'];
         // Check thumnail size
         if ($config['thumbnail.scale_mode'] == "percentage") {
             if ($config['thumbnail.height'] > $config['thumbnail.width']) {
                 $target = $config['thumbnail.width'];
             } else {
                 $target = $config['thumbnail.height'];
             }
             $percentage = 0;
             if ($fileWidth > $fileHeight) {
                 $percentage = $target / $fileWidth;
             } else {
                 $percentage = $target / $fileHeight;
             }
             if ($percentage <= 1) {
                 $targetWidth = round($fileWidth * $percentage);
                 $targetHeight = round($fileHeight * $percentage);
             } else {
                 $targetWidth = $fileWidth;
                 $targetHeight = $fileHeight;
             }
         }
         $input["thumbnail"] = true;
         // Check against config.
         if ($config["thumbnail.max_width"] != "" && $fileWidth > $config["thumbnail.max_width"] || $config["thumbnail.max_height"] != "" && $fileHeight > $config["thumbnail.max_height"]) {
             $input["thumbnail"] = false;
         } else {
             $input["twidth"] = $targetWidth;
             $input["theight"] = $targetHeight;
         }
         // Get thumbnail URL
         if ($type == "insert") {
             $thumbFile = $man->getFile($file->getParent() . "/" . $config['thumbnail.folder'] . "/" . $config['thumbnail.prefix'] . $file->getName());
             if ($thumbFile->exists()) {
                 $input["thumbnail_url"] = $man->convertPathToURI($thumbFile->getAbsolutePath());
             }
         }
         $input["width"] = $fileWidth;
         $input["height"] = $fileHeight;
         $input["editable"] = $canEdit;
     }
     return true;
 }