getErrorMessageMissingPermissions() public static method

Returns friendly error message explaining how to fix permissions
public static getErrorMessageMissingPermissions ( string $path ) : string
$path string to the directory missing permissions
return string Error message
コード例 #1
0
 protected function write(array $record)
 {
     try {
         parent::write($record);
     } catch (\UnexpectedValueException $e) {
         throw new \Exception(Filechecks::getErrorMessageMissingPermissions($this->url));
     }
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: dorelljames/piwik
 public function uninstall($redirectAfter = true)
 {
     $pluginName = $this->initPluginModification(static::UNINSTALL_NONCE);
     $this->dieIfPluginsAdminIsDisabled();
     $uninstalled = \Piwik\Plugin\Manager::getInstance()->uninstallPlugin($pluginName);
     if (!$uninstalled) {
         $path = Filesystem::getPathToPiwikRoot() . '/plugins/' . $pluginName . '/';
         $messagePermissions = Filechecks::getErrorMessageMissingPermissions($path);
         $messageIntro = $this->translator->translate("Warning: \"%s\" could not be uninstalled. Piwik did not have enough permission to delete the files in {$path}. ", $pluginName);
         $exitMessage = $messageIntro . "<br/><br/>" . $messagePermissions;
         $exitMessage .= "<br> Or manually delete this directory (using FTP or SSH access)";
         $ex = new MissingFilePermissionException($exitMessage);
         $ex->setIsHtmlMessage();
         throw $ex;
     }
     $this->redirectAfterModification($redirectAfter);
 }
コード例 #3
0
 /**
  * Copies a file from `$source` to `$dest`.
  *
  * @param string $source A path to a file, eg. './tmp/latest/index.php'. The file must exist.
  * @param string $dest A path to a file, eg. './index.php'. The file does not have to exist.
  * @param bool $excludePhp Whether to avoid copying files if the file is related to PHP
  *                         (includes .php, .tpl, .twig files).
  * @throws Exception If the file cannot be copied.
  * @return true
  * @api
  */
 public static function copy($source, $dest, $excludePhp = false)
 {
     static $phpExtensions = array('php', 'tpl', 'twig');
     if ($excludePhp) {
         $path_parts = pathinfo($source);
         if (in_array($path_parts['extension'], $phpExtensions)) {
             return true;
         }
     }
     if (!@copy($source, $dest)) {
         @chmod($dest, 0755);
         if (!@copy($source, $dest)) {
             $message = "Error while creating/copying file to <code>{$dest}</code>. <br />" . Filechecks::getErrorMessageMissingPermissions(self::getPathToPiwikRoot());
             throw new Exception($message);
         }
     }
     return true;
 }
コード例 #4
0
 private static function tryToCopyFileAndVerifyItWasCopied($source, $dest)
 {
     if (!@copy($source, $dest)) {
         @chmod($dest, 0755);
         if (!@copy($source, $dest)) {
             $message = "Error while creating/copying file to <code>{$dest}</code>. <br />" . Filechecks::getErrorMessageMissingPermissions(self::getPathToPiwikRoot());
             throw new Exception($message);
         }
     }
     if (file_exists($source) && file_exists($dest)) {
         return self::havePhpFilesSameContent($source, $dest);
     }
     return true;
 }
コード例 #5
0
ファイル: Log.php プロジェクト: brienomatty/elmsln
 private function logToFile($level, $tag, $datetime, $message)
 {
     $message = $this->getMessageFormattedFile($level, $tag, $datetime, $message);
     if (empty($message)) {
         return;
     }
     if (!file_put_contents($this->logToFilePath, $message, FILE_APPEND)) {
         $message = Filechecks::getErrorMessageMissingPermissions($this->logToFilePath);
         throw new \Exception($message);
     }
 }
コード例 #6
0
ファイル: Log.php プロジェクト: KiwiJuicer/handball-dachau
 private function logToFile($level, $tag, $datetime, $message)
 {
     if (is_string($message)) {
         $message = $this->formatMessage($level, $tag, $datetime, $message);
     } else {
         $logger = $this;
         /**
          * Triggered when trying to log an object to a file. Plugins can use
          * this event to convert objects to strings before they are logged.
          *
          * **Example**
          * 
          *     public function formatFileMessage(&$message, $level, $tag, $datetime, $logger) {
          *         if ($message instanceof MyCustomDebugInfo) {
          *             $message = $message->formatForFile();
          *         }
          *     }
          * 
          * @param mixed &$message The object that is being logged. Event handlers should
          *                        check if the object is of a certain type and if it is,
          *                        set `$message` to the string that should be logged.
          * @param int $level The log level used with this log entry.
          * @param string $tag The current plugin that started logging (or if no plugin,
          *                    the current class).
          * @param string $datetime Datetime of the logging call.
          * @param Log $logger The Log singleton.
          */
         Piwik::postEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
     }
     if (empty($message)) {
         return;
     }
     if (!file_put_contents($this->logToFilePath, $message . "\n", FILE_APPEND)) {
         $message = Filechecks::getErrorMessageMissingPermissions($this->logToFilePath);
         throw new \Exception($message);
     }
 }
コード例 #7
0
ファイル: Session.php プロジェクト: FluentDevelopment/piwik
 /**
  * Start the session
  *
  * @param array|bool $options An array of configuration options; the auto-start (bool) setting is ignored
  * @return void
  * @throws Exception if starting a session fails
  */
 public static function start($options = false)
 {
     if (headers_sent() || self::$sessionStarted || defined('PIWIK_ENABLE_SESSION_START') && !PIWIK_ENABLE_SESSION_START) {
         return;
     }
     self::$sessionStarted = true;
     // use cookies to store session id on the client side
     @ini_set('session.use_cookies', '1');
     // prevent attacks involving session ids passed in URLs
     @ini_set('session.use_only_cookies', '1');
     // advise browser that session cookie should only be sent over secure connection
     if (ProxyHttp::isHttps()) {
         @ini_set('session.cookie_secure', '1');
     }
     // advise browser that session cookie should only be accessible through the HTTP protocol (i.e., not JavaScript)
     @ini_set('session.cookie_httponly', '1');
     // don't use the default: PHPSESSID
     @ini_set('session.name', self::SESSION_NAME);
     // proxies may cause the referer check to fail and
     // incorrectly invalidate the session
     @ini_set('session.referer_check', '');
     $currentSaveHandler = ini_get('session.save_handler');
     $config = Config::getInstance();
     if (self::isFileBasedSessions()) {
         // Note: this handler doesn't work well in load-balanced environments and may have a concurrency issue with locked session files
         // for "files", use our own folder to prevent local session file hijacking
         $sessionPath = self::getSessionsDirectory();
         // We always call mkdir since it also chmods the directory which might help when permissions were reverted for some reasons
         Filesystem::mkdir($sessionPath);
         @ini_set('session.save_handler', 'files');
         @ini_set('session.save_path', $sessionPath);
     } elseif ($config->General['session_save_handler'] === 'dbtable' || in_array($currentSaveHandler, array('user', 'mm'))) {
         // We consider these to be misconfigurations, in that:
         // - user  - we can't verify that user-defined session handler functions have already been set via session_set_save_handler()
         // - mm    - this handler is not recommended, unsupported, not available for Windows, and has a potential concurrency issue
         $config = array('name' => Common::prefixTable('session'), 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
         $saveHandler = new DbTable($config);
         if ($saveHandler) {
             self::setSaveHandler($saveHandler);
         }
     }
     // garbage collection may disabled by default (e.g., Debian)
     if (ini_get('session.gc_probability') == 0) {
         @ini_set('session.gc_probability', 1);
     }
     try {
         parent::start();
         register_shutdown_function(array('Zend_Session', 'writeClose'), true);
     } catch (Exception $e) {
         Log::error('Unable to start session: ' . $e->getMessage());
         $enableDbSessions = '';
         if (DbHelper::isInstalled()) {
             $enableDbSessions = "<br/>If you still experience issues after trying these changes,\n\t\t\t            \t\t\twe recommend that you <a href='http://piwik.org/faq/how-to-install/#faq_133' rel='noreferrer' target='_blank'>enable database session storage</a>.";
         }
         $pathToSessions = Filechecks::getErrorMessageMissingPermissions(self::getSessionsDirectory());
         $message = sprintf("Error: %s %s %s\n<pre>Debug: the original error was \n%s</pre>", Piwik::translate('General_ExceptionUnableToStartSession'), $pathToSessions, $enableDbSessions, $e->getMessage());
         $ex = new MissingFilePermissionException($message, $e->getCode(), $e);
         $ex->setIsHtmlMessage();
         throw $ex;
     }
 }