Esempio n. 1
0
 public static function call($method, $args)
 {
     if ($method === 'info') {
         list($dirname, $fname, $protocol) = getRealPath($args['filename']);
         if (!class_exists('SimpleXMLElement')) {
             throw new Exception("Cannot get media information -- No XML parser found");
         }
         if (!function_exists('exec')) {
             throw new Exception("Cannot get media information -- Exec not allowed");
         }
         $cmd = sprintf("%s --Output=XML %s", MusicPlayerCommand, escapeshellcmd($fname));
         @exec($cmd, $content);
         if (!$content) {
             throw new Exception("Cannot get media information -- Query failed");
         }
         try {
             $xml = new SimpleXMLElement(implode("\n", preg_replace("/_+/", "", $content)));
         } catch (Exception $e) {
             $xml = $e;
         }
         if ($xml !== null) {
             if (isset($xml->File[0]) && isset($xml->File[0]->track) && ($node = $xml->File->track)) {
                 return array('Artist' => isset($node->Performer) ? htmlspecialchars($node->Performer) : null, 'Album' => isset($node->Album) ? htmlspecialchars($node->Album) : null, 'Track' => isset($node->Track_name) ? htmlspecialchars($node->Track_name) : null);
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Returns a new file instance of a absolute path.
  * 
  * @param String $abs_path Absolute file path.
  * @param String $file_name Optional file name.
  * @param String $type Optional file type.
  * @return File File object instance based on absolute path.
  */
 function &getFile($abs_path, $file_name = "", $type = MC_IS_FILE)
 {
     $rootPath = removeTrailingSlash(toUnixPath(getRealPath($this->_config, 'filesystem.rootpath')));
     if (!$this->verifyPath($abs_path)) {
         trigger_error("Trying to get out of defined root path. Root: " . $rootPath . ", Path: " . $abs_path, E_USER_ERROR);
         die;
     }
     // Fix the absolute path
     $abs_path = removeTrailingSlash(toUnixPath($abs_path));
     $abs_path = $abs_path == "" ? "/" : $abs_path;
     $file =& new $this->_config['filesystem']($this, $abs_path, $file_name, $type);
     return $file;
 }
 /**
  * Initializes the FileEventListener by the specified config.
  *
  * @param Array name/value array of config data.
  */
 function init(&$config)
 {
     // Setup logger
     $this->_logPath = getRealPath($config, "LoggingFileEventListener.path");
     $this->_logPrefix = getConfigParam($config, "LoggingFileEventListener.prefix", "mcfilemanager");
     $this->_logMaxSize = getConfigParam($config, "LoggingFileEventListener.max_size", "100k");
     $this->_logMaxFiles = getConfigParam($config, "LoggingFileEventListener.max_files", "10");
     // Fix log max size
     $logMaxSizeBytes = intval(preg_replace("/[^0-9]/", "", $this->_logMaxSize));
     // Is KB
     if (strpos(strtolower($this->_logMaxSize), "k") > 0) {
         $logMaxSizeBytes *= 1024;
     }
     // Is MB
     if (strpos(strtolower($this->_logMaxSize), "m") > 0) {
         $logMaxSizeBytes *= 1024 * 1024;
     }
     $this->_logMaxSizeBytes = $logMaxSizeBytes;
 }
Esempio n. 4
0
 $selectedDocuments = $sessionAction->get();
 $destFolderPath = addTrailingSlash(backslashToSlash($_GET['current_folder_path']));
 if (sizeof($selectedDocuments)) {
     //get all files within the destination folder
     $allDocs = array();
     if ($fh = @opendir($_GET['current_folder_path'])) {
         while (($file = readdir($fh)) && $file != '.' && $file != '..') {
             $allDocs[] = getRealPath($destFolderPath . $file);
         }
     }
     include_once CLASS_FILE;
     $file = new file();
     //check if all files are allowed to cut or copy
     foreach ($selectedDocuments as $doc) {
         if (file_exists($doc) && isUnderRoot($doc)) {
             if (array_search(getRealPath($doc), $allDocs) === false || CONFIG_OVERWRITTEN) {
                 if (CONFIG_OVERWRITTEN) {
                     $file->delete($doc);
                 }
                 if ($file->copyTo($doc, $_GET['current_folder_path'])) {
                     $finalPath = $destFolderPath . basename($doc);
                     $objFile = new file($finalPath);
                     $tem = $objFile->getFileInfo();
                     $obj = new manager($finalPath, false);
                     $fileType = $obj->getFileType($finalPath, is_dir($finalPath) ? true : false);
                     foreach ($fileType as $k => $v) {
                         $tem[$k] = $v;
                     }
                     /*								foreach ($folderInfo as $k=>$v)
                     								{
                     									$tem['i_' . $k] = $v;
Esempio n. 5
0
 public static function exists($fname)
 {
     list($dirname, $root, $protocol, $fname) = getRealPath($fname);
     return file_exists($fname);
 }
<?php

/**
 * ajax preview
 * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn)
 * @link www.phpletter.com
 * @since 22/April/2007
 *
 */
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php";
echo getRealPath($_GET['path']);
if (!empty($_GET['path']) && file_exists($_GET['path']) && is_file($_GET['path'])) {
    include_once CLASS_MANAGER;
    $manager = new manager($_GET['path'], false);
    $fileTypes = $manager->getFileType(basename($_GET['path']));
    if ($fileTypes['preview']) {
        switch ($fileTypes['fileType']) {
            case "image":
                $imageInfo = @getimagesize($_GET['path']);
                if (!empty($imageInfo[0]) && !empty($imageInfo[1])) {
                    $thumInfo = getThumbWidthHeight($imageInfo[0], $imageInfo[1], 400, 135);
                    printf("<img src=\"%s\" width=\"%s\" height=\"%s\" />", getFileUrl($_GET['path']), $thumInfo['width'], $thumInfo['height']);
                } else {
                    echo PREVIEW_IMAGE_LOAD_FAILED;
                }
                break;
            case "txt":
                if ($fp = @fopen($_GET['path'], 'r')) {
                    echo @fread($fp, @filesize($_GET['path']));
                    @fclose($fp);
                } else {
Esempio n. 7
0
/**
 * fileprops.php
 *
 * @package MCFileManager.pages
 * @author Moxiecode
 * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved.
 */
require_once "includes/general.php";
require_once "classes/FileSystems/FileFactory.php";
require_once "classes/FileSystems/LocalFileImpl.php";
require_once "classes/pclzip/pclzip.lib.php";
$data = array();
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();
addFileEventListeners($fileFactory);
$filename = getRequestParam("filename", false);
$submitted = getRequestParam("submitted", false);
$data['path'] = $path;
$data['submitted'] = $submitted;
$data['short_path'] = getUserFriendlyPath($path, 30);
$data['full_path'] = getUserFriendlyPath($path);
$data['errorMsg'] = "";
$data['filename'] = "";
$data['demo'] = checkBool($config['general.demo']) ? "true" : "false";
$data['demo_msg'] = $config['general.demo_msg'];
// Create zip
Esempio n. 8
0
$orgHeight = getRequestParam("orgheight");
$newWidth = getRequestParam("newwidth");
$newHeight = getRequestParam("newheight");
$left = getRequestParam("left");
$top = getRequestParam("top");
$action = getRequestParam("action");
$path = getRequestParam("path");
$orgpath = getRequestParam("orgpath", "");
$filename = getRequestParam("filename", "");
$msg = "";
if ($orgpath == "") {
    $orgpath = $path;
}
$temp_image = "mcic_" . session_id() . "";
verifyAccess($mcImageManagerConfig);
$rootpath = removeTrailingSlash(getRequestParam("rootpath", toUnixPath(getRealPath($mcImageManagerConfig, 'filesystem.rootpath'))));
$fileFactory =& new FileFactory($mcImageManagerConfig, $rootPath);
addFileEventListeners($fileFactory);
$file =& $fileFactory->getFile($path);
$config = $file->getConfig();
$demo = checkBool($config['general.demo']) ? "true" : "false";
$imageutils = new $config['thumbnail']();
$tools = explode(',', $config['thumbnail.image_tools']);
if (!in_array("edit", $tools)) {
    trigger_error("The thumbnail.image_tools needs to include edit.", WARNING);
}
// File info
$fileInfo = getFileType($file->getAbsolutePath());
$file_icon = $fileInfo['icon'];
$file_type = $fileInfo['type'];
$file_ext = $fileInfo['ext'];
Esempio n. 9
0
/**
 * edit_image.php
 *
 * @package MCImageManager.pages
 * @author Moxiecode
 * @copyright Copyright © 2006, Moxiecode Systems AB, All rights reserved.
 */
require_once "includes/general.php";
$data = array();
verifyAccess($mcImageManagerConfig);
$path = getRequestParam("path", "");
$orgpath = getRequestParam("orgpath", "");
$action = getRequestParam("action", "");
$status = getRequestParam("status", "");
$msg = getRequestParam("msg", "");
$rootpath = toUnixPath(getRealPath($mcImageManagerConfig, 'filesystem.rootpath'));
$fileFactory =& new FileFactory($mcImageManagerConfig, $rootpath);
$targetFile =& $fileFactory->getFile($path);
$config = $targetFile->getConfig();
$wwwroot = removeTrailingSlash(toUnixPath(getWWWRoot($config)));
$tools = explode(',', $config['thumbnail.image_tools']);
if (!in_array("edit", $tools)) {
    trigger_error("The thumbnail.image_tools needs to include edit.", FATAL);
}
if ($targetFile->isDirectory()) {
    trigger_error("You may not edit directories.", WARNING);
}
$dir = $targetFile->getParentFile();
if (!$dir->canWrite()) {
    trigger_error("You don't have write access to the directory.", FATAL);
}
Esempio n. 10
0
 /**
  * Returns a merged name/value array of config elements.
  *
  * @return Array Merged name/value array of config elements.
  */
 function getConfig()
 {
     $globalConf = $this->_fileFactory->getConfig();
     $rootpath = $this->_fileFactory->getRootPath();
     // Not cached config
     if (!$this->_config) {
         $localConfig = array();
         $this->_config = $globalConf;
         // Get files up the tree
         $accessFiles = array();
         $file =& $this;
         if ($file->isFile()) {
             $file =& $file->getParentFile();
         }
         while ($file->exists() && $file->getAbsolutePath() != "/") {
             $accessFile =& new LocalFileImpl($this->_fileFactory, $file->getAbsolutePath(), $globalConf["filesystem.local.access_file_name"]);
             if ($accessFile->exists()) {
                 $accessFiles[] = $accessFile;
             }
             if (strpos(strtolower(toOSPath($file->getParent())), strtolower(toOSPath($rootpath))) === false) {
                 break;
             }
             $file =& $file->getParentFile();
         }
         // Parse and merge
         $allowoverrideKeys = array();
         foreach ($this->_config as $key => $value) {
             $keyChunks = explode('.', $key);
             if ($keyChunks[count($keyChunks) - 1] == "allow_override") {
                 foreach (explode(',', $value) as $keySuffix) {
                     $keyChunks[count($keyChunks) - 1] = $keySuffix;
                     $allowoverrideKeys[] = implode('.', $keyChunks);
                 }
             }
         }
         foreach (array_reverse($accessFiles) as $accessFile) {
             $config = array();
             // Parse ini file
             if ($fp = fopen(toOSPath($accessFile->getAbsolutePath()), "r")) {
                 while (!feof($fp)) {
                     $line = trim(fgets($fp));
                     // Skip comments
                     if (substr($line, 0, 1) == "#") {
                         continue;
                     }
                     // Split rows
                     if (($pos = strpos($line, "=")) !== FALSE) {
                         $config[substr($line, 0, $pos)] = substr($line, $pos + 1);
                     }
                 }
                 fclose($fp);
             }
             // Handle local config values
             $curDir = $this->isFile() ? $this->getParent() : $this->getAbsolutePath();
             if ($accessFile->getParent() == $curDir) {
                 foreach ($config as $key => $value) {
                     if (substr($key, 0, 1) == '_') {
                         $localConfig[substr($key, 1)] = $value;
                     }
                 }
             }
             // Parse allow keys and deny keys
             $denyOverrideKeys = array();
             foreach ($config as $key => $value) {
                 $keyChunks = explode('.', $key);
                 $lastChunk = $keyChunks[count($keyChunks) - 1];
                 if ($lastChunk == "allow_override" || $lastChunk == "deny_override") {
                     foreach (explode(',', $value) as $keySuffix) {
                         $keyChunks[count($keyChunks) - 1] = $keySuffix;
                         $allowDenyKey = implode('.', $keyChunks);
                         if (in_array($allowDenyKey, $allowoverrideKeys)) {
                             if ($lastChunk == "allow_override") {
                                 $allowoverrideKeys[] = $allowDenyKey;
                             } else {
                                 $denyOverrideKeys[] = $allowDenyKey;
                             }
                         }
                     }
                 }
             }
             // Remove the denied keys from the allow list
             /*				foreach ($denyOverrideKeys as $denyKey) {
             					for ($i=0; $i<count($allowoverrideKeys); $i++) {
             						if ($denyKey == $allowoverrideKeys[$i])
             							unset($allowoverrideKeys[$i]);
             					}
             				}*/
             // Add all overriden values
             foreach ($config as $key => $value) {
                 $validAllKey = false;
                 foreach ($allowoverrideKeys as $allowkey) {
                     if (strpos($allowkey, "*") > 0) {
                         $allowkey = str_replace("*", "", $allowkey);
                         // echo $allowkey . "," . $key . strpos($allowkey, $key) . "<br>";
                         if (strpos($key, $allowkey) === 0) {
                             $validAllKey = true;
                             break;
                         }
                     }
                 }
                 if ((in_array($key, $allowoverrideKeys) || $validAllKey) && !in_array($key, $denyOverrideKeys)) {
                     if (strpos($value, '${') !== false) {
                         $value = str_replace('${configpath}', $accessFile->getParent(), $value);
                     }
                     $this->_config[$key] = $value;
                 }
             }
         }
         // Variable substitute the values
         foreach ($this->_config as $key => $value) {
             if (!is_array($value) && strpos($value, '${') !== false) {
                 if ($this->isFile()) {
                     $path = $this->getAbsolutePath();
                 } else {
                     $path = $this->getParent();
                 }
                 $this->_config[$key] = str_replace('${path}', $path, $value);
                 $this->_config[$key] = str_replace('${rootpath}', toUnixPath(getRealPath($this->_config, 'filesystem.rootpath')), $value);
             }
         }
         // Force local config
         foreach ($localConfig as $key => $value) {
             $this->_config[$key] = $value;
         }
         /*			foreach ($this->_config as $key => $value) {
         				if (in_array($key, $allowoverrideKeys)) {
         					// Seems to be a variable
         					if (strpos($value, '${') !== false) {
         						$matches = array();
         						preg_match_all('/\${(.*)}/i', $value, $matches);
         						var_dump($matches);
         						foreach ($matches as $match)
         							$this->_config[$key] = str_replace('${' . $match . '}', $this->_config[$match], $this->_config[$key]);
         					}
         				}
         			}*/
     }
     return $this->_config;
 }
Esempio n. 11
0
function main()
{
    global $indexStyle;
    $dir = $_SERVER['PATH_ROOT'] . $_SERVER['PATH_INFO'];
    $files = array_diff(scandir($dir), array('.', '..'));
    $files = filesGroupDir($dir, $files);
    $html = "";
    $html .= "<!DOCTYPE html>\n";
    $html .= "<html>\n";
    $html .= "<head>\n";
    $html .= "<meta charset=\"UTF-8\">\n";
    $html .= "<style>" . $indexStyle . "</style>\n";
    $html .= "</head>\n";
    $html .= "<body>\n";
    $html .= "<h2>Index of " . $_SERVER['PATH_INFO'] . "</h2>\n";
    $html .= "<table>\n";
    $html .= "<tr>\n";
    $html .= "<th>Name</th>\n";
    $html .= "<th>Size</th>\n";
    $html .= "<th>Time</th>\n";
    $html .= "</tr>\n";
    $html .= "<tr>\n";
    $html .= '<td><a href="..">..</a></td>' . "\n";
    $html .= "<td></td>\n";
    $html .= "<td></td>\n";
    $html .= "</tr>\n";
    foreach ($files as $k => $v) {
        $name = $v;
        if (strlen($name) > 30) {
            $name = substr($name, 0, 27) . '...';
        }
        $path = getRealPath($dir . $v);
        $datemodified = date('Y\\-m\\-d H:i', getFileMTime($path));
        $size = sizeFilter(getFileSize($path));
        $hrefSuffix = '';
        if (filetype($path) == 'dir') {
            $hrefSuffix = '/';
            $size = "-";
        }
        $html .= "<tr>\n";
        $html .= '<td><a href="' . $v . $hrefSuffix . '">' . $name . $hrefSuffix . '</a></td>' . "\n";
        $html .= "<td>" . $size . "</td>\n";
        $html .= "<td>" . $datemodified . "</td>\n";
        $html .= "</tr>\n";
    }
    $html .= "</table>\n";
    $html .= "</body>\n";
    $html .= "</html>\n";
    echo $html;
}
Esempio n. 12
0
// Invalid path, use root path
if (!$fileFactory->verifyPath($path)) {
    $path = $rootPath;
}
// Get file and config
$targetFile =& $fileFactory->getFile($path);
$config = $targetFile->getConfig();
addFileEventListeners($fileFactory);
$previewpath = $path;
// Get parent dir if path points to a file
$fileFactory =& new FileFactory($mcFileManagerConfig, $rootPath);
$file =& $fileFactory->getFile($path);
if ($file->exists()) {
    if ($file->isFile()) {
        $path = $file->getParent();
    }
    $previewpath = $file->getAbsolutePath();
} else {
    $path = toUnixPath(getRealPath($mcFileManagerConfig, 'filesystem.path'));
    $previewpath = toUnixPath(getRealPath($mcFileManagerConfig, 'filesystem.path'));
}
$data['path'] = $path;
$data['previewpath'] = $previewpath;
$data['previewfilename'] = basename($previewpath);
$data['rootpath'] = $rootPath;
$data['showpreview'] = checkBool($mcFileManagerConfig['preview']);
$data['formname'] = getRequestParam("formname", "");
$data['elementnames'] = getRequestParam("elementnames", "");
$data['js'] = getRequestParam("js", "");
// Render output
renderPage("frameset.tpl.php", $data);
Esempio n. 13
0
 /**
  * File Download Request
  */
 public static function FileGET(APIRequest $req)
 {
     $result = false;
     $error = false;
     $headers = array();
     $code = 0;
     $root = "/";
     if (($settings = Settings::get()) && !empty($settings['rooturi'])) {
         $root = $settings['rooturi'];
     }
     $root = preg_quote($root, '/');
     $url = preg_replace(sprintf("/^%sFS/", $root), "", urldecode($req->data));
     call_user_func_array(array(API::$Handler, 'checkPrivilege'), array(APIUser::GROUP_VFS));
     try {
         if ($url) {
             list($dirname, $root, $protocol, $file) = getRealPath($url);
             if (file_exists($file)) {
                 session_write_close();
                 if ($data = FS::read($url, array("raw" => true))) {
                     list($mime, $etag, $length, $result) = $data;
                     $headers[] = "Etag: {$etag}";
                     $headers[] = "Content-type: {$mime}; charset=utf-8";
                     $headers[] = "Content-length: {$length}";
                 } else {
                     $code = 500;
                     $error = "File read error";
                 }
             } else {
                 $code = 404;
                 $error = "File not found";
             }
         }
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     return new APIResponse(false, $result, $error, $code, $headers);
 }
Esempio n. 14
0
 /**
  * File Download Request
  */
 public static function FileGET(APIRequest $req)
 {
     $result = false;
     $error = false;
     $headers = array();
     $code = 0;
     $settings = Settings::get();
     $url = preg_replace('/\\/(([^\\/]+\\/)+)?(FS)/', "", urldecode($req->data));
     call_user_func_array(array(API::$Handler, 'checkPrivilege'), array(APIUser::GROUP_VFS));
     try {
         if ($url) {
             if (preg_match('/^(ftp|https?)\\:\\/\\//', $url)) {
                 if (empty($settings['vfs']['proxy']) || $settings['vfs']['proxy'] == false) {
                     $error = "VFS Proxy is disabled";
                     $code = 500;
                 } else {
                     $result = file_get_contents($url);
                 }
             } else {
                 list($dirname, $req->uri, $protocol, $file) = getRealPath($url);
                 if (file_exists($file)) {
                     session_write_close();
                     if (FS::read($url, array("raw" => true))) {
                         exit;
                     } else {
                         $code = 500;
                         $error = "File read error";
                     }
                 } else {
                     $code = 404;
                     $error = "File not found";
                 }
             }
         }
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     return new APIResponse(false, $result, $error, $code, $headers);
 }
Esempio n. 15
0
 /**
  * File Download Request
  */
 public static function FileGET(APIRequest $req)
 {
     $result = false;
     $error = false;
     $headers = array();
     $code = 0;
     $url = preg_replace('/\\/(([^\\/]+\\/)+)?(FS)/', "", urldecode($req->data));
     call_user_func_array(array(API::$Handler, 'checkPrivilege'), array(APIUser::GROUP_VFS));
     try {
         if ($url) {
             list($dirname, $req->uri, $protocol, $file) = getRealPath($url);
             if (file_exists($file)) {
                 session_write_close();
                 if (FS::read($url, array("raw" => true))) {
                     exit;
                 } else {
                     $code = 500;
                     $error = "File read error";
                 }
             } else {
                 $code = 404;
                 $error = "File not found";
             }
         }
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     return new APIResponse(false, $result, $error, $code, $headers);
 }
Esempio n. 16
0
 /**
  * get the parent path of the specified path
  *
  * @param string $path
  * @return string 
  */
 function getParentFolderPath($path)
 {
 	$realPath = addTrailingSlash(backslashToSlash(getRealPath($path)));
 	$parentRealPath =  addTrailingSlash(backslashToSlash(dirname($realPath)));
 	$differentPath = addTrailingSlash(substr($realPath, strlen($parentRealPath)));
 	$parentPath = substr($path, 0, strlen(addTrailingSlash(backslashToSlash($path))) - strlen($differentPath));
 	if(isUnderRoot($parentPath))
 	{
 		return $parentPath;
 	}else 
 	{
 		return CONFIG_SYS_DEFAULT_PATH;
 	}
 }
Esempio n. 17
0
/**
 * Returns the wwwroot or null string if it was impossible to get.
 *
 * @return String wwwroot or null string if it was impossible to get.
 */
function getWWWRoot($config)
{
    if (isset($config['preview.wwwroot']) && $config['preview.wwwroot']) {
        return getRealPath($config, 'preview.wwwroot');
    }
    // Check document root
    if (isset($_SERVER['DOCUMENT_ROOT'])) {
        return resolvePath($_SERVER['DOCUMENT_ROOT']);
    }
    // Try script file
    if (isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["SCRIPT_FILENAME"])) {
        $path = str_replace(toUnixPath($_SERVER["SCRIPT_NAME"]), "", toUnixPath($_SERVER["SCRIPT_FILENAME"]));
        if (is_dir($path)) {
            return toOSPath($path);
        }
    }
    // If all else fails, try this.
    if (isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["PATH_TRANSLATED"])) {
        $path = str_replace(toUnixPath($_SERVER["SCRIPT_NAME"]), "", str_replace("//", "/", toUnixPath($_SERVER["PATH_TRANSLATED"])));
        if (is_dir($path)) {
            return toOSPath($path);
        }
    }
    die("Could not resolve WWWROOT path, please set an absolute path in preview.wwwroot config option.");
    return null;
}