/** * Constructs a new LocalFileSystem. * * @param string $scheme File scheme. * @param MOXMAN_Util_Config $config Config instance for file system. * @param string $root Root path for file system. */ public function __construct($scheme, MOXMAN_Util_Config $config, $root) { parent::__construct($scheme, $config, $root); // Force the root path to an absolute path $this->rootPath = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $this->rootPath); // Get wwwroot from config or resolve it, remove trailing slash. $wwwroot = preg_replace('/\\/$/', '', $config->get("filesystem.local.wwwroot")); if (!$wwwroot) { $sitePaths = MOXMAN_Util_PathUtils::getSitePaths(); $wwwroot = $sitePaths["wwwroot"]; } // If rootpath isn't within the resolved wwwroot then resolve the rootpath if (!MOXMAN_Util_PathUtils::isChildOf($this->rootPath, $wwwroot)) { $this->rootPath = realpath($this->rootPath); if (!$this->rootPath) { throw new MOXMAN_Exception("Configured filesystem.rootpath doesn't exist or couldn't be resolved."); } else { if (!MOXMAN_Util_PathUtils::isChildOf($this->rootPath, $wwwroot)) { throw new MOXMAN_Exception("The filesystem.rootpath isn't within the auto detected wwwroot." . "You need to configure filesystem.local.wwwroot."); } } } $this->setFileConfigProvider(new MOXMAN_Vfs_Local_FileConfigProvider($this, $config)); $this->setFileUrlProvider(new MOXMAN_Vfs_Local_FileUrlProvider()); $this->setFileUrlResolver(new MOXMAN_Vfs_Local_FileUrlResolver($this)); }
/** * Process a request using the specified context. * * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler. */ public function processRequest(MOXMAN_Http_Context $httpContext) { $config = MOXMAN::getConfig(); $response = $httpContext->getResponse(); $response->disableCache(); $response->setHeader('Content-type', 'text/html'); if (!$config->get("general.debug")) { $response->sendContent("Debugging not configured, you need to set general.debug to true in config.php file."); return; } $request = $httpContext->getRequest(); if ($request->get("info")) { phpinfo(); return; } $sitepaths = MOXMAN_Util_PathUtils::getSitePaths(); $scriptFilename = $_SERVER["SCRIPT_FILENAME"]; if (realpath($scriptFilename) != $scriptFilename) { $scriptFilename = $scriptFilename . "<br />(" . realpath($scriptFilename) . ")"; } if (function_exists("imagecreatefromjpeg")) { $gdInfo = gd_info(); $outInfo = "Ver:" . $gdInfo["GD Version"]; $outInfo .= " GIF:" . ($gdInfo["GIF Create Support"] ? "Y" : "N"); $outInfo .= " PNG:" . ($gdInfo["PNG Support"] ? "Y" : "N"); $outInfo .= " JPEG:" . ($gdInfo["JPEG Support"] ? "Y" : "N"); } else { $outInfo = "N/A"; $gdInfo = array(); } $user = MOXMAN::getAuthManager()->getUser(); $result = array("MOXMAN_ROOT" => MOXMAN_ROOT, "realpath('.')" => realpath("."), "Config.php rootpath" => $config->get("filesystem.rootpath"), "Config.php wwwroot" => $config->get("filesystem.local.wwwroot"), "wwwroot resolve" => $sitepaths["wwwroot"], "wwwroot realpath" => realpath($sitepaths["wwwroot"]), "prefix resolve" => $sitepaths["prefix"], "storage path" => MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path")), "storage writable" => is_writable(MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path"))), "script filename" => $scriptFilename, "script name" => $_SERVER["SCRIPT_NAME"], "GD" => $outInfo, "memory_limit" => @ini_get("memory_limit"), "upload_max_filesize" => @ini_get("upload_max_filesize"), "post_max_size" => @ini_get("post_max_size"), "file_uploads" => @ini_get("file_uploads") ? "Yes" : "No", "PHP Version" => phpversion(), "Time" => date('Y-m-d H:i:s', time()), "Time UTC" => date('Y-m-d H:i:s', time() - date("Z")), "Authenticated" => MOXMAN::getAuthManager()->isAuthenticated(), "User" => $user ? $user->getName() : "N/A"); $out = "<html><body><table border='1'>"; foreach ($result as $name => $value) { if ($value === true) { $value = "True"; } else { if ($value === false) { $value = "False"; } } $out .= "<tr>"; $out .= "<td>" . $name . " </td><td>" . $value . " </td>"; $out .= "</tr>"; } $out .= "</table><a href='?action=debug&info=true'>Show phpinfo</a>"; $out .= "</body></html>"; $response->sendContent($out); }
/** * Returns a file object out of the specified URL. * * @param string Absolute URL for the specified file. * @return MOXMAN_Vfs_IFile File that got resolved or null if it wasn't found. */ public function getFile($url) { $config = $this->fileSystem->getConfig(); $file = null; // Get config items $wwwroot = $config->get("filesystem.local.wwwroot"); $prefix = $config->get("filesystem.local.urlprefix"); $paths = MOXMAN_Util_PathUtils::getSitePaths(); // No wwwroot specified try to figure out a wwwroot if (!$wwwroot) { $wwwroot = $paths["wwwroot"]; } else { // Force the www root to an absolute file system path $wwwroot = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $wwwroot); } // Add prefix to URL if ($prefix == "") { $prefix = MOXMAN_Util_PathUtils::combine("{proto}://{host}", $paths["prefix"]); } // Replace protocol if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $prefix = str_replace("{proto}", "https", $prefix); } else { $prefix = str_replace("{proto}", "http", $prefix); } // Replace host/port $prefix = str_replace("{host}", $_SERVER['HTTP_HOST'], $prefix); $prefix = str_replace("{port}", $_SERVER['SERVER_PORT'], $prefix); // Remove prefix from url if ($prefix && strpos($url, $prefix) === 0) { $url = substr($url, strlen($prefix)); } // Parse url and check if path part of the URL is within the root of the file system $url = parse_url($url); if (isset($url["path"])) { $path = MOXMAN_Util_PathUtils::combine($wwwroot, $url["path"]); if (MOXMAN_Util_PathUtils::isChildOf($path, $this->fileSystem->getRootPath())) { // Crop away root path part and glue it back on again since the case might be different // For example: c:/inetpub/wwwroot and C:/InetPub/WWWRoot this will force it into the // valid fileSystem root path prefix $path = substr($path, strlen($this->fileSystem->getRootPath())); $path = MOXMAN_Util_PathUtils::combine($this->fileSystem->getRootPath(), $path); $file = $this->fileSystem->getFile($path); } } return $file; }
/** * Returns an URL for the specified file object. * * @param MOXMAN_Vfs_IFile $file File to get the absolute URL for. * @return String Absolute URL for the specified file. */ public function getUrl(MOXMAN_Vfs_IFile $file) { $config = $file->getConfig(); // Get config items $wwwroot = $config->get("filesystem.local.wwwroot"); $prefix = $config->get("filesystem.local.urlprefix"); $suffix = $config->get("filesystem.local.urlsuffix"); $paths = MOXMAN_Util_PathUtils::getSitePaths(); // No wwwroot specified try to figure out a wwwroot if (!$wwwroot) { $wwwroot = $paths["wwwroot"]; } else { // Force the www root to an absolute file system path $wwwroot = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $wwwroot); } // Add prefix to URL if ($prefix == "") { $prefix = MOXMAN_Util_PathUtils::combine("{proto}://{host}", $paths["prefix"]); } // Replace protocol if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $prefix = str_replace("{proto}", "https", $prefix); } else { $prefix = str_replace("{proto}", "http", $prefix); } // Replace host/port $prefix = str_replace("{host}", $_SERVER['HTTP_HOST'], $prefix); $prefix = str_replace("{port}", $_SERVER['SERVER_PORT'], $prefix); // Insert path into URL $url = substr($file->getPath(), strlen($wwwroot)); $url = MOXMAN_Util_PathUtils::combine($prefix, $url); // Add suffix to URL if ($suffix) { $url .= $suffix; } return $url; }
/** * Process a request using the specified context. * * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler. */ public function processRequest(MOXMAN_Http_Context $httpContext) { $config = MOXMAN::getConfig(); if (!$config->get("general.debug")) { return; } $request = $httpContext->getRequest(); if ($request->get("info")) { phpinfo(); die; } $response = $httpContext->getResponse(); $response->disableCache(); $response->setHeader('Content-type', 'text/html'); $sitepaths = MOXMAN_Util_PathUtils::getSitePaths(); $scriptFilename = $_SERVER["SCRIPT_FILENAME"]; if (realpath($scriptFilename) != $scriptFilename) { $scriptFilename = $scriptFilename . "<br />(" . realpath($scriptFilename) . ")"; } $result = array("MOXMAN_ROOT" => MOXMAN_ROOT, "realpath('.')" => realpath("."), "Config.php rootpath" => $config->get("filesystem.rootpath"), "Config.php wwwroot" => $config->get("filesystem.local.wwwroot"), "wwwroot resolve" => $sitepaths["wwwroot"], "wwwroot realpath" => realpath($sitepaths["wwwroot"]), "prefix resolve" => $sitepaths["prefix"], "storage path" => MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path")), "storage writable" => is_writable(MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path"))), "script filename" => $scriptFilename, "script name" => $_SERVER["SCRIPT_NAME"]); $out = "<html><body><table border='1'>"; foreach ($result as $name => $value) { if ($value === true) { $value = "True"; } else { if ($value === false) { $value = "False"; } } $out .= "<tr>"; $out .= "<td>" . $name . " </td><td>" . $value . " </td>"; $out .= "</tr>"; } $out .= "</table><a href='?action=debug&info=true'>Show phpinfo</a>"; $out .= "</body></html>"; $response->sendContent($out); }
/** * Returns an URL for the specified file object. * * @param MOXMAN_Vfs_IFile $file File to get the absolute URL for. * @return String Absolute URL for the specified file. */ public function getUrl(MOXMAN_Vfs_IFile $file) { $config = $file->getConfig(); // Get config items $wwwroot = $config->get("filesystem.local.wwwroot"); $prefix = $config->get("filesystem.local.urlprefix"); $suffix = $config->get("filesystem.local.urlsuffix"); // Map to wwwroot array if (is_array($wwwroot)) { foreach ($wwwroot as $rootPath => $rootConfig) { $rootPath = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $rootPath); if (strpos($file->getPath(), $rootPath) === 0) { $wwwroot = $rootPath; if (isset($rootConfig["wwwroot"])) { $wwwroot = $rootConfig["wwwroot"]; } if (isset($rootConfig["urlprefix"])) { $prefix = $rootConfig["urlprefix"]; } if (isset($rootConfig["urlsuffix"])) { $suffix = $rootConfig["urlsuffix"]; } break; } } if (is_array($wwwroot)) { $wwwroot = ""; } } $paths = MOXMAN_Util_PathUtils::getSitePaths(); // No wwwroot specified try to figure out a wwwroot if (!$wwwroot) { $wwwroot = $paths["wwwroot"]; } else { // Force the www root to an absolute file system path $wwwroot = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $wwwroot); } // Add prefix to URL if ($prefix == "") { $prefix = MOXMAN_Util_PathUtils::combine("{proto}://{host}", $paths["prefix"]); } // Replace protocol if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $prefix = str_replace("{proto}", "https", $prefix); } else { $prefix = str_replace("{proto}", "http", $prefix); } // Replace host/port $prefix = str_replace("{host}", $_SERVER['HTTP_HOST'], $prefix); $prefix = str_replace("{port}", $_SERVER['SERVER_PORT'], $prefix); // Insert path into URL if (stripos($file->getPath(), $wwwroot) === 0) { $url = substr($file->getPath(), strlen($wwwroot)); $url = MOXMAN_Util_PathUtils::combine($prefix, MOXMAN_Http_Uri::escapeUriString($url)); // Add suffix to URL if ($suffix) { $url .= $suffix; } return $url; } return ""; }