예제 #1
0
function initialise()
{
    // No config file, so this is a first run for install. Before creating the config file, check some
    // directory access
    $readonlyDirs = array();
    if (!is_writable(dirname(__FILE__) . "/application/config/")) {
        $readonlyDirs[] = "/application/config/";
    }
    if (!is_writable(dirname(__FILE__) . "/application/logs/")) {
        $readonlyDirs[] = "/application/logs/";
    }
    if (!is_writable(dirname(__FILE__) . "/application/cache/")) {
        $readonlyDirs[] = "/application/cache/";
    }
    if (count($readonlyDirs) > 0) {
        die('<div style="width:80%;margin:50px auto;text-align:center;">' . '<h3>Installation cannot proceed.</h3>' . '<p>The Warehouse installation needs write access priveleges to the following folders:</p>' . '<ul><li>' . implode('</li><li>', $readonlyDirs) . '</li></ul>' . '</div>');
    }
    $source = dirname(__FILE__) . "/application/config/config.php.example";
    $dest = dirname(__FILE__) . "/application/config/config.php";
    if (false === ($_source_content = file_get_contents($source))) {
        die('<div style="width:80%;margin:50px auto;text-align:center;">' . '<h3>Config file not found.</h3>' . '<p>The <code>' . APPPATH . 'config/config' . EXT . '.example</code> file does not exist or could not be accessed.</p>' . '</div>');
    }
    include dirname(__FILE__) . '/modules/indicia_setup/libraries/Zend_Controller_Request_Http.php';
    $zend_http = new Zend_Controller_Request_Http();
    $site_domain = preg_replace("/index\\.php.*\$/", "", $zend_http->getHttpHost() . $zend_http->getBaseUrl());
    $_source_content = str_replace("*site_domain*", $site_domain, $_source_content);
    if (false === file_put_contents($dest, $_source_content)) {
        die('<div style="width:80%;margin:50px auto;text-align:center;">' . '<h1>Indicia Installation</h1>' . '<h2>Config file cannot be written.</h2>' . '<p>The <code>' . APPPATH . 'config/config' . EXT . '</code> file cannot be created..</p>' . '</div>');
    }
}
예제 #2
0
 protected function _initStoreRoutes()
 {
     $request = new Zend_Controller_Request_Http();
     $path = explode('/', trim($request->getPathInfo(), '/'));
     $requestedPath = array_shift($path);
     $requestedHost = $request->getHttpHost();
     if ($store = Cosmos_Api::get()->cosmos->getStoreByHostPath($requestedHost, $requestedPath)) {
         $this->bootstrap('session');
         Zend_Registry::set('csession', new Zend_Session_Namespace("cosmos_{$store['group_id']}"));
         Zend_Registry::get('log')->info($store);
         if ($store['path']) {
             $this->bootstrap('frontcontroller');
             $front = Zend_Controller_Front::getInstance();
             $request = $front->getRequest();
             $dispatcher = $front->getDispatcher();
             $defaultRoute = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
             $front->getRouter()->removeDefaultRoutes();
             $defaults = array('path' => $store['path'], 'module' => $dispatcher->getDefaultModule());
             $pathRoute = new Zend_Controller_Router_Route(':path', $defaults);
             Zend_Registry::set('cosmosRoute', $pathRoute);
             // This is to catch empty requests because for some reason 'default' doesn't.
             $front->getRouter()->addRoute('default-empty', $pathRoute);
             $front->getRouter()->addRoute('default', $pathRoute->chain($defaultRoute));
             Zend_Registry::set('mode', 'path');
         } else {
             Zend_Registry::set('mode', 'host');
         }
     } else {
         die('fail');
         // no matching store?
     }
     Cosmos_Addon::getInstance($store['addons']);
 }
예제 #3
0
파일: General.php 프로젝트: carriercomm/NPG
 /**
  * get the base url
  * @return string $baseUrl 
  */
 public static function getBaseUrl()
 {
     if (!self::$baseUrl) {
         $uri = new Zend_Controller_Request_Http();
         self::$baseUrl = $uri->getScheme() . '://' . $uri->getHttpHost() . $uri->getBaseUrl();
     }
     return self::$baseUrl;
 }
예제 #4
0
 /**
  * Upgrade to the latest version.
  *
  * @param String $currentVersion Phprojekt version string indicating our
  *                               current version
  * @param Zend_Db_Adapter_Abstract $db The database to use
  *
  * @return void
  * @throws Exception On Errors
  */
 public function upgrade($currentVersion, Zend_Db_Adapter_Abstract $db)
 {
     date_default_timezone_set('utc');
     $this->_db = $db;
     $this->parseDbFile('Timecard');
     if (Phprojekt::compareVersion($currentVersion, '6.1.4') < 0) {
         $request = new Zend_Controller_Request_Http();
         $uidSuffix = "@phprojekt6-" . $request->getHttpHost();
         Phprojekt::getInstance()->getDB()->query("UPDATE timecard SET uri = id, uid = CONCAT(UUID(), \"{$uidSuffix}\");");
         // This is mysql-only. Not sure if this is the ultimate way to go here.
         Phprojekt::getInstance()->getDB()->query('ALTER TABLE timecard ADD UNIQUE (uri)');
     }
 }
예제 #5
0
 /**
  * 重載 繼承的 YUN_Controller_Action init 方法
  *
  */
 public function init()
 {
     parent::init();
     $http = new Zend_Controller_Request_Http();
     if (!$this->auth->isAllow('index.access')) {
         if ($this->auth->isLogined()) {
             $this->view->feedback(array('message' => '对不起,您没有权限执行该操作!', 'redirect' => $this->view->url(array('module' => 'default', 'controller' => 'user', 'action' => 'login')), 'linktext' => '点击继续'));
         } else {
             $this->view->Feedback(array('title' => '发生错误', 'message' => '对不起,您尚未登录', 'linktext' => '点击前往登录页面', 'redirect' => $this->view->url(array('module' => 'default', 'controller' => 'user', 'action' => 'login')) . '?u=' . urlencode('http://' . $http->getHttpHost() . $http->getRequestUri())));
         }
     }
     $this->config = Zend_Registry::get('config');
 }
예제 #6
0
 /**
  * Overrides match to detect port
  *
  * @param Zend_Controller_Request_Http $request
  * @return array|false
  */
 public function match($request)
 {
     if ($this->hasPort()) {
         // Check that the port matches the route port
         $host = $request->getHttpHost();
         if (preg_match(self::PORT_REGEXP, $host, $m)) {
             $port = (int) $m[1];
         } else {
             // Assign a default port according to the scheme
             $port = $request->isSecure() ? 443 : 80;
         }
         if ($port !== (int) $this->getPort()) {
             return false;
         }
     }
     // Default match
     return parent::match($request);
 }
예제 #7
0
 public function _initView()
 {
     // init view
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
     if (null == $viewRenderer->view) {
         $viewRenderer->initView();
     }
     $view = $viewRenderer->view;
     if (is_object($view)) {
         $view->doctype('XHTML1_STRICT');
         // set application charset
         $view->charset = 'UTF-8';
         // build the root url
         $request = new Zend_Controller_Request_Http();
         $siteUrl = $request->getScheme() . '://' . $request->getHttpHost();
         $view->host = $siteUrl;
         $basePath = $request->getBasePath();
         $siteUrl = $basePath == '' ? $siteUrl : $siteUrl . '/' . ltrim($basePath, '/');
         $view->baseUrl = $siteUrl;
         $siteUrl = $siteUrl . '/index.php';
         $view->rootUrl = $siteUrl;
     }
 }
예제 #8
0
 /**
  * Get Host
  * ex. azot.cherkassy.net
  *
  * @return string
  */
 static function getHttpHost()
 {
     $request = new Zend_Controller_Request_Http();
     $httpHost = $request->getHttpHost();
     $arr = explode(':', $httpHost);
     return $arr[0];
 }
예제 #9
0
 /**
  * @group ZF-9899
  */
 public function testHostNameShouldBeEmpty()
 {
     $request = new Zend_Controller_Request_Http();
     $this->assertEquals('', $request->getHttpHost(), 'HttpHost should be :');
 }
예제 #10
0
 /**
  * Do some checks before install.
  *
  * @throws Expeption If the server don't have the requirements.
  *
  * @return void
  */
 private function _checkServer()
 {
     // Check the server
     $checkServer = Phprojekt::checkExtensionsAndSettings();
     // Check the PHP version
     if (!$checkServer['requirements']['php']['checked']) {
         $missingRequirements[] = "You need the PHP Version " . $checkServer['requirements']['php']['required'] . " or newer. Follow this link for help: <a href=\"" . $checkServer['requirements']['php']['help'] . "\"" . " target=\"_new\">HELP</a>";
     }
     // Check required extension
     foreach ($checkServer['requirements']['extension'] as $name => $values) {
         if (!$values['checked']) {
             $missingRequirements[] = "The '" . $name . "' extension must be enabled. Follow this link for help: " . "<a href=\"" . $values['help'] . "\" target=\"_new\">HELP</a>";
         }
     }
     // Check required settings
     foreach ($checkServer['requirements']['settings'] as $name => $values) {
         if (!$values['checked']) {
             $missingRequirements[] = "The php.ini setting of '" . $name . "' has to be '" . $values['required'] . "'. Follow this link for help: <a href=\"" . $values['help'] . "\"" . " target=\"_new\">HELP</a>";
         }
     }
     // Checking if configuration.php exists
     $baseDir = str_replace('htdocs/setup.php', '', $_SERVER['SCRIPT_FILENAME']);
     if (file_exists($baseDir . "configuration.php")) {
         throw new Exception("Configuration file found. Please, delete it before run setup again.");
     }
     if (!empty($missingRequirements)) {
         $message = implode("\n", $missingRequirements);
         throw new Exception($message);
     }
     if (strncmp($_SERVER['SCRIPT_NAME'], '/setup.php', 10) != 0) {
         $this->_message[] = "It is recommend install PHProjekt 6 using a virtual host.<br />" . "You should try to generate an extra virtual host (or a sub-domain) to phprojekt/htdocs.";
         // Works the .htaccess?
         $response = new Zend_Controller_Request_Http();
         $webpath = $response->getHttpHost();
         $str = '';
         $sock = fsockopen($webpath, $response->getServer('SERVER_PORT'));
         $request = "GET " . str_replace('htdocs/setup.php', '', $response->getRequestUri()) . '/application/' . " HTTP/1.1\r\n" . "Host: " . $webpath . "\r\nConnection: close\r\n\r\n";
         fwrite($sock, $request);
         while ($buff = fread($sock, 1024)) {
             $str .= $buff;
         }
         $response = Zend_Http_Response::fromString($str);
         if ($response->getStatus() != '403') {
             $this->_message[] = "Please note that your webserver needs to support .htaccess files " . "to deny access to the configuration files.<br />" . "Running PHProjekt 6 without using the provided .htaccess files to deny access to " . "certain files and folders, might not be secure and is not recommended.";
         }
         fclose($sock);
     }
     foreach ($checkServer['recommendations']['settings'] as $name => $values) {
         if (!$values['checked']) {
             $this->_message[] = "It is recommend to have '" . $name . "' set to '" . $values['required'] . "', but it is not required to run PHProjekt. Follow this link for help: <a href=\"" . $values['help'] . "\" target=\"_new\">HELP</a>";
         }
     }
 }
예제 #11
0
 /**
  * Auto-redirect to base url (without SID) if the requested url doesn't match it.
  * By default this feature is enabled in configuration.
  *
  * @param Zend_Controller_Request_Http $request
  */
 protected function _checkBaseUrl($request)
 {
     if (!Mage::isInstalled() || $request->getPost()) {
         return;
     }
     if (!Mage::getStoreConfig('web/url/redirect_to_base')) {
         return;
     }
     $adminPath = (string) Mage::getConfig()->getNode(Mage_Adminhtml_Helper_Data::XML_PATH_CUSTOM_ADMIN_PATH);
     if (!$adminPath) {
         $adminPath = (string) Mage::getConfig()->getNode(Mage_Adminhtml_Helper_Data::XML_PATH_ADMINHTML_ROUTER_FRONTNAME);
     }
     if (preg_match('#^' . $adminPath . '(\\/.*)?$#', ltrim($request->getPathInfo(), '/')) && (string) Mage::getConfig()->getNode(Mage_Adminhtml_Helper_Data::XML_PATH_USE_CUSTOM_ADMIN_URL)) {
         return;
     }
     $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, Mage::app()->getStore()->isCurrentlySecure());
     if (!$baseUrl) {
         return;
     }
     $redirectCode = 302;
     if (Mage::getStoreConfig('web/url/redirect_to_base') == 301) {
         $redirectCode = 301;
     }
     $uri = @parse_url($baseUrl);
     $host = isset($uri['host']) ? $uri['host'] : '';
     $path = isset($uri['path']) ? $uri['path'] : '';
     $requestUri = $request->getRequestUri() ? $request->getRequestUri() : '/';
     if ($host && $host != $request->getHttpHost() || $path && strpos($requestUri, $path) === false) {
         Mage::app()->getFrontController()->getResponse()->setRedirect($baseUrl, $redirectCode)->sendResponse();
         exit;
     }
 }
예제 #12
0
 /**
  * Initialize the paths, the config values and all the render stuff.
  *
  * @return void
  */
 public function _initialize()
 {
     // Report all PHP errors
     error_reporting(-1);
     define('PHPR_CORE_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'application');
     define('PHPR_LIBRARY_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'library');
     if (!defined('PHPR_CONFIG_FILE')) {
         define('PHPR_CONFIG_FILE', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'configuration.php');
     }
     set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . get_include_path());
     require_once 'Zend/Loader/Autoloader.php';
     require_once 'Phprojekt/Loader.php';
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->pushAutoloader(array('Phprojekt_Loader', 'autoload'));
     // Read the config file, but only the production setting
     try {
         $this->_config = new Zend_Config_Ini(PHPR_CONFIG_FILE, PHPR_CONFIG_SECTION, true);
     } catch (Zend_Config_Exception $error) {
         $response = new Zend_Controller_Request_Http();
         $webPath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/';
         header("Location: " . $webPath . "setup.php");
         die('You need the file configuration.php to continue. Have you tried the <a href="' . $webPath . 'setup.php">setup</a> routine?' . "\n" . '<br />Original error: ' . $error->getMessage());
     }
     // Set webpath, tmpPath and applicationPath
     if (empty($this->_config->webpath)) {
         $response = new Zend_Controller_Request_Http();
         $this->_config->webpath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/';
     }
     define('PHPR_ROOT_WEB_PATH', $this->_config->webpath . 'index.php/');
     define('PHPR_TEMP_PATH', $this->_config->tmpPath);
     define('PHPR_USER_CORE_PATH', $this->_config->applicationPath);
     set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . PHPR_CORE_PATH . PATH_SEPARATOR . PHPR_USER_CORE_PATH . PATH_SEPARATOR . get_include_path());
     // Set the timezone to UTC
     date_default_timezone_set('UTC');
     // Start zend session to handle all session stuff
     try {
         Zend_Session::start();
     } catch (Zend_Session_Exception $error) {
         Zend_Session::writeClose();
         Zend_Session::start();
         Zend_Session::regenerateId();
         error_log($error);
     }
     // Set a metadata cache and clean it
     $frontendOptions = array('automatic_serialization' => true);
     $backendOptions = array('cache_dir' => PHPR_TEMP_PATH . 'zendCache' . DIRECTORY_SEPARATOR);
     try {
         $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     } catch (Exception $error) {
         die("The directory " . PHPR_TEMP_PATH . "zendCache do not exists or not have write access.");
     }
     Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
     // Use for Debug only
     //Zend_Db_Table_Abstract::getDefaultMetadataCache()->clean();
     // Check Logs
     $this->getLog();
     $missingRequirements = array();
     // The following extensions are either needed by components of the Zend Framework that are used
     // or by P6 components itself.
     $extensionsNeeded = array('mbstring', 'iconv', 'ctype', 'gd', 'pcre', 'pdo', 'Reflection', 'session', 'SPL', 'zlib');
     // These settings need to be properly configured by the admin
     $settingsNeeded = array('magic_quotes_gpc' => 0, 'magic_quotes_runtime' => 0, 'magic_quotes_sybase' => 0);
     // Check the PHP version
     $requiredPhpVersion = "5.2.4";
     if (version_compare(phpversion(), $requiredPhpVersion, '<')) {
         // This is a requirement of the Zend Framework
         $missingRequirements[] = "- PHP Version '" . $requiredPhpVersion . "' or newer";
     }
     foreach ($extensionsNeeded as $extension) {
         if (!extension_loaded($extension)) {
             $missingRequirements[] = "- The '" . $extension . "' extension must be enabled.";
         }
     }
     // Check pdo library
     $mysql = extension_loaded('pdo_mysql');
     $sqlite = extension_loaded('pdo_sqlite2');
     $pgsql = extension_loaded('pdo_pgsql');
     if (!$mysql && !$sqlite && !$pgsql) {
         $missingRequirements[] = "- You need one of these PDO extensions: pdo_mysql, pdo_pgsql or pdo_sqlite";
     }
     foreach ($settingsNeeded as $conf => $value) {
         if (ini_get($conf) != $value) {
             $missingRequirements[] = "- The php.ini setting of '" . $conf . "' has to be '" . $value . "'.";
         }
     }
     if (!empty($missingRequirements)) {
         $message = "Your PHP does not meet the requirements needed for P6.<br />" . implode("<br />", $missingRequirements);
         die($message);
     }
     $helperPaths = $this->_getHelperPaths();
     $view = $this->_setView($helperPaths);
     $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
     $viewRenderer->setViewBasePathSpec(':moduleDir/Views');
     $viewRenderer->setViewScriptPathSpec(':action.:suffix');
     Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
     foreach ($helperPaths as $helperPath) {
         Zend_Controller_Action_HelperBroker::addPath($helperPath['directory']);
     }
     $plugin = new Zend_Controller_Plugin_ErrorHandler();
     $plugin->setErrorHandlerModule('Default');
     $plugin->setErrorHandlerController('Error');
     $plugin->setErrorHandlerAction('error');
     $front = Zend_Controller_Front::getInstance();
     $front->setDispatcher(new Phprojekt_Dispatcher());
     $front->registerPlugin($plugin);
     $front->setDefaultModule('Default');
     $front->setModuleControllerDirectoryName('Controllers');
     $front->addModuleDirectory(PHPR_CORE_PATH);
     $front->addModuleDirectory(PHPR_USER_CORE_PATH);
     // Add SubModules directories with controlles
     $moduleDirectories = $this->_getControllersFolders($helperPaths);
     foreach ($moduleDirectories as $moduleDirectory) {
         $front->addModuleDirectory($moduleDirectory);
     }
     $front->setParam('useDefaultControllerAlways', true);
     // Define general error handler
     set_error_handler(array("Phprojekt", "errorHandler"));
 }
예제 #13
0
 /**
  * Auto-redirect to base url (without SID) if the requested url doesn't match it.
  * By default this feature is enabled in configuration.
  *
  * @param Zend_Controller_Request_Http $request
  */
 protected function _checkBaseUrl($request)
 {
     if (!Mage::isInstalled() || $request->getPost()) {
         return;
     }
     if (!Mage::getStoreConfig('web/url/redirect_to_base')) {
         return;
     }
     $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, Mage::app()->getStore()->isCurrentlySecure());
     if (!$baseUrl) {
         return;
     }
     $redirectCode = 302;
     if (Mage::getStoreConfig('web/url/redirect_to_base') == 301) {
         $redirectCode = 301;
     }
     $uri = @parse_url($baseUrl);
     $host = isset($uri['host']) ? $uri['host'] : '';
     $path = isset($uri['path']) ? $uri['path'] : '';
     $requestUri = $request->getRequestUri() ? $request->getRequestUri() : '/';
     if ($host && $host != $request->getHttpHost() || $path && strpos($requestUri, $path) === false) {
         Mage::app()->getFrontController()->getResponse()->setRedirect($baseUrl, $redirectCode)->sendResponse();
         exit;
     }
 }
예제 #14
0
 public function getRequestUri()
 {
     return $this->request->getScheme() . '://' . $this->request->getHttpHost() . rtrim($this->request->getRequestUri(), '?');
 }
 /**
  * returns requested url part
  *
  * @param string $part
  * @return string
  */
 public static function getUrl($part = 'full')
 {
     $request = new Zend_Controller_Request_Http();
     $pathname = $request->getBasePath();
     $hostname = $request->getHttpHost();
     $protocol = $request->getScheme();
     switch ($part) {
         case 'path':
             $url = $pathname;
             break;
         case 'host':
             $url = $hostname;
             break;
         case 'protocol':
             $url = $protocol;
             break;
         case 'full':
         default:
             $url = $protocol . '://' . $hostname . $pathname;
             break;
     }
     return $url;
 }
예제 #16
0
 /**
  * Validate signature
  *
  * @throws Mage_Oauth_Exception
  */
 protected function _validateSignature()
 {
     $util = new Zend_Oauth_Http_Utility();
     $calculatedSign = $util->sign(array_merge($this->_params, $this->_protocolParams), $this->_protocolParams['oauth_signature_method'], $this->_consumer->getSecret(), !is_null($this->_token) ? $this->_token->getSecret() : null, $this->_request->getMethod(), $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $this->_request->getRequestUri());
     if ($calculatedSign != $this->_protocolParams['oauth_signature']) {
         $this->_throwException('Invalid signature.', self::ERR_SIGNATURE_INVALID);
     }
 }
예제 #17
0
파일: Setup.php 프로젝트: joerch/PHProjekt
 /**
  * Do some checks before install.
  *
  * @throws Expeption If the server don't have the requirements.
  *
  * @return void
  */
 private function _checkServer()
 {
     $missingRequirements = array();
     // The following extensions are either needed by components of the Zend Framework that are used
     // or by P6 components itself.
     $extensionsNeeded = array('mbstring', 'iconv', 'ctype', 'gd', 'pcre', 'pdo', 'Reflection', 'session', 'SPL', 'zlib');
     // These settings need to be properly configured by the admin
     $settingsNeeded = array('magic_quotes_gpc' => 0, 'magic_quotes_runtime' => 0, 'magic_quotes_sybase' => 0);
     // These settings should be properly configured by the admin
     $settingsRecommended = array('register_globals' => 0, 'safe_mode' => 0);
     // Check the PHP version
     $requiredPhpVersion = "5.2.4";
     if (version_compare(phpversion(), $requiredPhpVersion, '<')) {
         // This is a requirement of the Zend Framework
         $missingRequirements[] = "PHP Version {$requiredPhpVersion} or newer";
     }
     foreach ($extensionsNeeded as $extension) {
         if (!extension_loaded($extension)) {
             $missingRequirements[] = "The {$extension} extension must be enabled.";
         }
     }
     // Check pdo library
     $mysql = extension_loaded('pdo_mysql');
     $sqlite = extension_loaded('pdo_sqlite2');
     $pgsql = extension_loaded('pdo_pgsql');
     if (!$mysql && !$sqlite && !$pgsql) {
         $missingRequirements[] = "You need one of these PDO extensions: pdo_mysql, pdo_pgsql or pdo_sqlite";
     }
     foreach ($settingsNeeded as $conf => $value) {
         if (ini_get($conf) != $value) {
             $missingRequirements[] = "The php.ini setting of \"{$conf}\" has to be \"{$value}\".";
         }
     }
     // Checking if configuration.php exists
     $baseDir = str_replace('htdocs/setup.php', '', $_SERVER['SCRIPT_FILENAME']);
     if (file_exists($baseDir . "configuration.php")) {
         throw new Exception("Configuration file found. Please, delete it before run setup again.");
     }
     if (!empty($missingRequirements)) {
         $message = implode("\n", $missingRequirements);
         throw new Exception($message);
     }
     if (strncmp($_SERVER['SCRIPT_NAME'], '/setup.php', 10) != 0) {
         $this->_message[] = "It is recommend install PHProjekt 6 using a virtual host.<br />" . "You should try to generate an extra virtual host (or a sub-domain) to phprojekt/htdocs.";
         // Works the .htaccess?
         $response = new Zend_Controller_Request_Http();
         $webpath = $response->getHttpHost();
         $str = '';
         $sock = fsockopen($webpath, $response->getServer('SERVER_PORT'));
         $request = "GET " . str_replace('htdocs/setup.php', '', $response->getRequestUri()) . '/application/' . " HTTP/1.1\r\n" . "Host: " . $webpath . "\r\nConnection: close\r\n\r\n";
         fwrite($sock, $request);
         while ($buff = fread($sock, 1024)) {
             $str .= $buff;
         }
         $response = Zend_Http_Response::fromString($str);
         if ($response->getStatus() != '403') {
             $this->_message[] = "Please note that your webserver needs to support .htaccess files " . "to deny access to the configuration files.<br />" . "Running PHProjekt 6 without using the provided .htaccess files to deny access to " . "certain files and folders, might not be secure and is not recommended.";
         }
         fclose($sock);
     }
     foreach ($settingsRecommended as $conf => $value) {
         if (ini_get($conf) != $value) {
             $this->_message[] = "It is recommend to have \"{$conf}\" set to \"{$value}\", but it is not required " . "to run PHProjekt.";
         }
     }
 }
 /**
  * @param \Zend_Controller_Request_Http $request
  * @return bool
  */
 public static function isDomainAllowedToAdminBackend($request)
 {
     $host = $request->getHttpHost();
     return $host === self::getAllowedDomain();
 }
예제 #19
0
 /**
  * Compute the request Url from the Http request
  *
  * @param \Zend_Controller_Request_Http $httpRequest
  * @return string
  */
 public function getRequestUrl($httpRequest)
 {
     // TODO: Fix needed for $this->getRequest()->getHttpHost(). Hosts with port are not covered.
     return $httpRequest->getScheme() . '://' . $httpRequest->getHttpHost() . $httpRequest->getRequestUri();
 }
예제 #20
0
 public static function buildCookie()
 {
     require_once 'app/Mage.php';
     $request = new Zend_Controller_Request_Http();
     session_set_cookie_params(self::getCookieLifetime(), self::getDefaultCookiePath(), $request->getHttpHost(), false, true);
     session_name('frontend');
     session_start();
 }
예제 #21
0
 function getHttpHost()
 {
     return $this->_host ? $this->_host : parent::getHttpHost();
 }
예제 #22
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param Zend_Controller_Request_Http $request Request to get the host from
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($request)
 {
     // Check the scheme if required
     if ($this->_scheme !== null) {
         $scheme = $request->getScheme();
         if ($scheme !== $this->_scheme) {
             return false;
         }
     }
     // Get the host and remove unnecessary port information
     $host = $request->getHttpHost();
     if (preg_match('#:\\d+$#', $host, $result) === 1) {
         $host = substr($host, 0, -strlen($result[0]));
     }
     $hostStaticCount = 0;
     $values = array();
     $host = trim($host, '.');
     if ($host != '') {
         $host = explode('.', $host);
         foreach ($host as $pos => $hostPart) {
             // Host is longer than a route, it's not a match
             if (!array_key_exists($pos, $this->_parts)) {
                 return false;
             }
             $name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
             $hostPart = urldecode($hostPart);
             // If it's a static part, match directly
             if ($name === null && $this->_parts[$pos] != $hostPart) {
                 return false;
             }
             // If it's a variable with requirement, match a regex. If not - everything matches
             if ($this->_parts[$pos] !== null && !preg_match($this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', $hostPart)) {
                 return false;
             }
             // If it's a variable store it's value for later
             if ($name !== null) {
                 $values[$name] = $hostPart;
             } else {
                 $hostStaticCount++;
             }
         }
     }
     // Check if all static mappings have been matched
     if ($this->_staticCount != $hostStaticCount) {
         return false;
     }
     $return = $values + $this->_defaults;
     // Check if all map variables have been initialized
     foreach ($this->_variables as $var) {
         if (!array_key_exists($var, $return)) {
             return false;
         }
     }
     $this->_values = $values;
     return $return;
 }
예제 #23
0
 /**
  * Initialize the paths, the config values and all the render stuff.
  *
  * @return void
  */
 public function _initialize()
 {
     // Report all PHP errors
     error_reporting(-1);
     define('PHPR_CORE_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'application');
     define('PHPR_LIBRARY_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'library');
     if (!defined('PHPR_CONFIG_FILE')) {
         define('PHPR_CONFIG_FILE', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'configuration.php');
     }
     set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . get_include_path());
     require_once 'Zend/Loader/Autoloader.php';
     require_once 'Phprojekt/Loader.php';
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->pushAutoloader(array('Phprojekt_Loader', 'autoload'));
     // Read the config file, but only the production setting
     try {
         $this->_config = new Zend_Config_Ini(PHPR_CONFIG_FILE, PHPR_CONFIG_SECTION, true);
     } catch (Zend_Config_Exception $error) {
         $response = new Zend_Controller_Request_Http();
         $webPath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/';
         header("Location: " . $webPath . "setup.php");
         die('You need the file configuration.php to continue. Have you tried the <a href="' . $webPath . 'setup.php">setup</a> routine?' . "\n" . '<br />Original error: ' . $error->getMessage());
     }
     // Set webpath, tmpPath and applicationPath
     if (empty($this->_config->webpath)) {
         $response = new Zend_Controller_Request_Http();
         $this->_config->webpath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/';
     }
     define('PHPR_ROOT_WEB_PATH', $this->_config->webpath . 'index.php/');
     define('PHPR_TEMP_PATH', $this->_config->tmpPath);
     define('PHPR_USER_CORE_PATH', $this->_config->applicationPath);
     set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . PHPR_CORE_PATH . PATH_SEPARATOR . PHPR_USER_CORE_PATH . PATH_SEPARATOR . get_include_path());
     // Set the timezone to UTC
     date_default_timezone_set('UTC');
     // Start zend session to handle all session stuff
     try {
         Zend_Session::start();
     } catch (Zend_Session_Exception $error) {
         Zend_Session::writeClose();
         Zend_Session::start();
         Zend_Session::regenerateId();
         error_log($error);
     }
     // Set a metadata cache and clean it
     $frontendOptions = array('automatic_serialization' => true);
     $backendOptions = array('cache_dir' => PHPR_TEMP_PATH . 'zendCache' . DIRECTORY_SEPARATOR);
     try {
         $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     } catch (Exception $error) {
         die("The directory " . PHPR_TEMP_PATH . "zendCache do not exists or not have write access.");
     }
     Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
     // Use for Debug only
     //Zend_Db_Table_Abstract::getDefaultMetadataCache()->clean();
     // Check Logs
     $this->getLog();
     // Check the server
     $checkServer = Phprojekt::checkExtensionsAndSettings();
     // Check the PHP version
     if (!$checkServer['requirements']['php']['checked']) {
         $missingRequirements[] = "- You need the PHP Version '" . $checkServer['requirements']['php']['required'] . "' or newer";
     }
     // Check required extension
     foreach ($checkServer['requirements']['extension'] as $name => $values) {
         if (!$values['checked']) {
             $missingRequirements[] = "- The '" . $name . "' extension must be enabled.";
         }
     }
     // Check required settings
     foreach ($checkServer['requirements']['settings'] as $name => $values) {
         if (!$values['checked']) {
             $missingRequirements[] = "- The php.ini setting of '" . $name . "' has to be '" . $values['required'] . "'.";
         }
     }
     // Show message
     if (!empty($missingRequirements)) {
         $message = "Your PHP does not meet the requirements needed for P6.<br />" . implode("<br />", $missingRequirements);
         die($message);
     }
     $helperPaths = $this->_getHelperPaths();
     $view = $this->_setView($helperPaths);
     $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
     $viewRenderer->setViewBasePathSpec(':moduleDir/Views');
     $viewRenderer->setViewScriptPathSpec(':action.:suffix');
     Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
     foreach ($helperPaths as $helperPath) {
         Zend_Controller_Action_HelperBroker::addPath($helperPath['directory']);
     }
     $plugin = new Zend_Controller_Plugin_ErrorHandler();
     $plugin->setErrorHandlerModule('Default');
     $plugin->setErrorHandlerController('Error');
     $plugin->setErrorHandlerAction('error');
     $front = Zend_Controller_Front::getInstance();
     $front->setDispatcher(new Phprojekt_Dispatcher());
     $front->registerPlugin($plugin);
     $front->setDefaultModule('Default');
     $front->setModuleControllerDirectoryName('Controllers');
     $front->addModuleDirectory(PHPR_CORE_PATH);
     $front->addModuleDirectory(PHPR_USER_CORE_PATH);
     // Add SubModules directories with controlles
     $moduleDirectories = $this->_getControllersFolders($helperPaths);
     foreach ($moduleDirectories as $moduleDirectory) {
         $front->addModuleDirectory($moduleDirectory);
     }
     $front->setParam('useDefaultControllerAlways', true);
     // Define general error handler
     set_error_handler(array("Phprojekt", "errorHandler"));
 }