public function testProtectAgainsRelativePaths_3() { $path = "/somedir/./subdir/../test.php"; $expected = "/somedir/test.php"; $res = FilesystemHelper::protectAgainsRelativePaths($path); $this->assertEquals($expected, $res); }
public function process() { $eg_node = $this->PWE->getNode(); //var_dump($eg_node); if (!isset($eg_node['!a']['src'])) { throw new HTTP4xxException("File to display not specified", HTTP4xxException::NOT_FOUND); } if (!$this->isHTMfile($eg_node['!a']['src'])) { throw new HTTP4xxException("File is not HTML: " . $eg_node['!a']['src'], HTTP4xxException::PRECONDITION_FAILED); } // файл с содержимым $src = self::getHTMLDirectory($this->PWE) . '/' . FilesystemHelper::protectAgainsRelativePaths($eg_node['!a']['src']); // если таковой есть if (is_file($src)) { PWELogger::debug("HTML File: %s", $src); // показываем его $smarty = $this->PWE->getSmarty(); $smarty->assign('content', file_get_contents($src)); $smarty->setTemplateFile(__DIR__ . "/HTMLPage.tpl"); $this->PWE->addContent($smarty); } else { // иначе пишем во внутренний лог // и культурно ругаемся PWELogger::warn("File not found: %s", $src); throw new HTTP4xxException("This page is not ready yet", HTTP4xxException::NOT_FOUND); } }
public static function setup(PWECore $pwe, array &$registerData) { if (is_writable($pwe->getStaticDirectory())) { PWELogger::debug("Copying into %s/design", $pwe->getStaticDirectory()); FilesystemHelper::fsys_copydir(__DIR__ . '/../../design', $pwe->getStaticDirectory() . '/design'); } else { PWELogger::warn("Can't copy resources to %s, it's not writable"); } }
static function utGetCleanTMP() { $tmpdir = "/tmp/pwe-test"; if (!is_dir($tmpdir)) { mkdir($tmpdir, 0777, true); } $tmp = tempnam($tmpdir, "pwe-"); unlink($tmp); FilesystemHelper::fsys_mkdir($tmp); return $tmp; }
public function __construct() { $this->modulesManager = new PWEModulesManager($this); $this->setRootDirectory(FilesystemHelper::protectAgainsRelativePaths(__DIR__ . '/../../')); $this->errorsTemplate = 'error.tpl'; }
public function getFileBlock($orig_file, $comment) { $orig_file = FilesystemHelper::protectAgainsRelativePaths($orig_file); $basename = basename($orig_file); $file = $this->getRealFile($orig_file); if (!is_file($file)) { PWELogger::warn("Broken download: %s", $file); return '[broken download: ' . $basename . ']'; } $size = FilesystemHelper::fsys_kbytes(filesize($file)); $date = date('M d, Y', filemtime($file)); $link = $this->link_base . '/' . $orig_file; $res = "<span class='file_download'>"; $res .= "<a href='{$link}'><b>{$basename}</b></a>"; $res .= ", <span class='filesize'>{$size}</span>"; $res .= ", <span class='filedate'>{$date}</span>"; $cnt = $this->getDownloadCount($file); if ($cnt) { $res .= ", <span class='count'>Download count: {$cnt}</span>"; } $res .= "<br/><i>{$comment}</i></span>"; return $res; }