extensions = $extensions; foreach ($this->extensions as $extension) { $file = ROOT_PATH . $extension . '/.htaccess'; if (file_exists($file)) { if (!is_readable($file)) { throw new tao_install_utils_Exception("Unable to read .htaccess file of extension '" . $extension . " while Production Mode activation'."); } $this->accessFiles[] = $file; } } } public function disableRewritePattern(array $patterns) { $globalPattern = ''; $size = count($patterns) - 1; foreach ($patterns as $i => $pattern) { $globalPattern .= preg_quote($pattern, '/'); if ($i < $size) { $globalPattern .= '|'; } } if (!empty($globalPattern)) { foreach ($this->accessFiles as $file) { $lines = explode("\n", file_get_contents($file)); $updated = 0; foreach ($lines as $i => $line) { if (preg_match("/" . $globalPattern . "/", $line)) { $lines[$i] = '#' . $line; $updated++; } } if ($updated > 0) { if (!is_writable($file)) { throw new tao_install_utils_Exception("Unable to write .htaccess file : ${file}."); } file_put_contents($file, implode("\n", $lines)); } } } } public function protectInstall() { foreach ($this->extensions as $extension) { $installDir = ROOT_PATH . $extension . '/install/'; if (file_exists($installDir) && is_dir($installDir)) { if (!is_writable($installDir) || (file_exists($installDir . '.htaccess' && !is_writable($installDir . '.htaccess')))) { throw new tao_install_utils_Exception("Unable to write .htaccess file into : ${installDir}."); } file_put_contents($installDir . '.htaccess', "Options +FollowSymLinks\n" . "\n" . "RewriteEngine On\n" . "RewriteCond %{REQUEST_URI} !/css/ [NC]\n" . "RewriteCond %{REQUEST_URI} !/js/ [NC]\n" . "RewriteCond %{REQUEST_URI} !/images/ [NC]\n" . "RewriteCond %{REQUEST_URI} !/production.html [NC]\n" . "RewriteRule ^.*$ " . ROOT_URL . "tao/install/production.html\n" . ""); } } } public function denyAccessTo($paths) { foreach ($this->extensions as $extension) { foreach ($paths as $path) { if (!preg_match("/^\\" . DIRECTORY_SEPARATOR . "/", $path)) { $path = DIRECTORY_SEPARATOR . $path; } $denied = ROOT_PATH . $extension . $path; if (file_exists($denied) && is_dir($denied)) { $accessFile = $denied . DIRECTORY_SEPARATOR . '.htaccess'; if (!is_writable($denied) || (file_exists($accessFile && !is_writable($accessFile)))) { throw new tao_install_utils_Exception("Unable to write .htaccess file into : ${denied}."); } file_put_contents($accessFile, "\n" . "RewriteEngine On\n" . "RewriteRule ^.*$ - [F]\n" . ""); } } } } }