mkdir() public static method

_Note: This function does **not** create directories recursively._
public static mkdir ( string $path )
$path string The path of the directory to create.
 private function createFolderWithinPluginIfNotExists($pluginName, $folder)
 {
     $pluginPath = $this->getPluginPath($pluginName);
     if (!file_exists($pluginName . $folder)) {
         Filesystem::mkdir($pluginPath . $folder, true);
     }
 }
Exemplo n.º 2
0
 public function __construct($outputId)
 {
     if (!Filesystem::isValidFilename($outputId)) {
         throw new \Exception('The given output id has an invalid format');
     }
     $dir = CliMulti::getTmpPath();
     Filesystem::mkdir($dir);
     $this->tmpFile = $dir . '/' . $outputId . '.output';
 }
Exemplo n.º 3
0
 private function createFolderWithinPluginIfNotExists($pluginNameOrCore, $folder)
 {
     if ($pluginNameOrCore === 'core') {
         $pluginPath = $this->getPathToCore();
     } else {
         $pluginPath = $this->getPluginPath($pluginNameOrCore);
     }
     if (!file_exists($pluginPath . $folder)) {
         Filesystem::mkdir($pluginPath . $folder);
     }
 }
Exemplo n.º 4
0
 public function __construct($pid)
 {
     if (!Filesystem::isValidFilename($pid)) {
         throw new \Exception('The given pid has an invalid format');
     }
     $pidDir = CliMulti::getTmpPath();
     Filesystem::mkdir($pidDir);
     $this->isSupported = self::isSupported();
     $this->pidFile = $pidDir . '/' . $pid . '.pid';
     $this->timeCreation = time();
     $this->markAsNotStarted();
 }
Exemplo n.º 5
0
 /**
  * @return bool
  */
 public function isCustomLogoWritable()
 {
     $pathUserLogo = $this->getPathUserLogo();
     $directoryWritingTo = PIWIK_DOCUMENT_ROOT . '/' . dirname($pathUserLogo);
     // Create directory if not already created
     Filesystem::mkdir($directoryWritingTo, $denyAccess = false);
     $directoryWritable = is_writable($directoryWritingTo);
     $logoFilesWriteable = is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $pathUserLogo) && is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserSvgLogo()) && is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserLogoSmall());
     $serverUploadEnabled = ini_get('file_uploads') == 1;
     $isCustomLogoWritable = ($logoFilesWriteable || $directoryWritable) && $serverUploadEnabled;
     return $isCustomLogoWritable;
 }
Exemplo n.º 6
0
 /**
  * Sends an HTTP request using best available transport method.
  *
  * @param string $aUrl The target URL.
  * @param int $timeout The number of seconds to wait before aborting the HTTP request.
  * @param string|null $userAgent The user agent to use.
  * @param string|null $destinationPath If supplied, the HTTP response will be saved to the file specified by
  *                                     this path.
  * @param int|null $followDepth Internal redirect count. Should always pass `null` for this parameter.
  * @param bool $acceptLanguage The value to use for the `'Accept-Language'` HTTP request header.
  * @param array|bool $byteRange For `Range:` header. Should be two element array of bytes, eg, `array(0, 1024)`
  *                              Doesn't work w/ `fopen` transport method.
  * @param bool $getExtendedInfo If true returns the status code, headers & response, if false just the response.
  * @param string $httpMethod The HTTP method to use. Defaults to `'GET'`.
  * @throws Exception if the response cannot be saved to `$destinationPath`, if the HTTP response cannot be sent,
  *                   if there are more than 5 redirects or if the request times out.
  * @return bool|string If `$destinationPath` is not specified the HTTP response is returned on success. `false`
  *                     is returned on failure.
  *                     If `$getExtendedInfo` is `true` and `$destinationPath` is not specified an array with
  *                     the following information is returned on success:
  *
  *                     - **status**: the HTTP status code
  *                     - **headers**: the HTTP headers
  *                     - **data**: the HTTP response data
  *
  *                     `false` is still returned on failure.
  * @api
  */
 public static function sendHttpRequest($aUrl, $timeout, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'GET')
 {
     // create output file
     $file = null;
     if ($destinationPath) {
         // Ensure destination directory exists
         Filesystem::mkdir(dirname($destinationPath));
         if (($file = @fopen($destinationPath, 'wb')) === false || !is_resource($file)) {
             throw new Exception('Error while creating the file: ' . $destinationPath);
         }
     }
     $acceptLanguage = $acceptLanguage ? 'Accept-Language: ' . $acceptLanguage : '';
     return self::sendHttpRequestBy(self::getTransportMethod(), $aUrl, $timeout, $userAgent, $destinationPath, $file, $followDepth, $acceptLanguage, $acceptInvalidSslCertificate = false, $byteRange, $getExtendedInfo, $httpMethod);
 }
Exemplo n.º 7
0
 /**
  * @return bool
  */
 public function isCustomLogoWritable()
 {
     if (Config::getInstance()->General['enable_custom_logo_check'] == 0) {
         return true;
     }
     $pathUserLogo = $this->getPathUserLogo();
     $directoryWritingTo = PIWIK_DOCUMENT_ROOT . '/' . dirname($pathUserLogo);
     // Create directory if not already created
     Filesystem::mkdir($directoryWritingTo);
     $directoryWritable = is_writable($directoryWritingTo);
     $logoFilesWriteable = is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $pathUserLogo) && is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserSvgLogo()) && is_writeable(PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserLogoSmall());
     $isCustomLogoWritable = ($logoFilesWriteable || $directoryWritable) && $this->isFileUploadEnabled();
     return $isCustomLogoWritable;
 }
Exemplo n.º 8
0
 /**
  * Checks if directories are writable and create them if they do not exist.
  *
  * @param array $directoriesToCheck array of directories to check - if not given default Piwik directories that needs write permission are checked
  * @return array  directory name => true|false (is writable)
  */
 public static function checkDirectoriesWritable($directoriesToCheck)
 {
     $resultCheck = array();
     foreach ($directoriesToCheck as $directoryToCheck) {
         if (!preg_match('/^' . preg_quote(PIWIK_USER_PATH, '/') . '/', $directoryToCheck)) {
             $directoryToCheck = PIWIK_USER_PATH . $directoryToCheck;
         }
         Filesystem::mkdir($directoryToCheck);
         $directory = Filesystem::realpath($directoryToCheck);
         if ($directory !== false) {
             $resultCheck[$directory] = is_writable($directoryToCheck);
         }
     }
     return $resultCheck;
 }
Exemplo n.º 9
0
 /**
  * Check if the merged file directory exists and is writable.
  *
  * @return string The directory location
  * @throws Exception if directory is not writable.
  */
 public function getAssetDirectory()
 {
     $mergedFileDirectory = StaticContainer::get('path.tmp') . '/assets';
     if (!is_dir($mergedFileDirectory)) {
         Filesystem::mkdir($mergedFileDirectory);
     }
     if (!is_writable($mergedFileDirectory)) {
         throw new Exception("Directory " . $mergedFileDirectory . " has to be writable.");
     }
     return $mergedFileDirectory;
 }
Exemplo n.º 10
0
 /**
  * A function to store content a cache entry.
  *
  * @param string $id The cache entry ID
  * @param array $content The cache content
  * @throws \Exception
  * @return bool  True if the entry was succesfully stored
  */
 public function set($id, $content)
 {
     if (empty($id)) {
         return false;
     }
     if (!is_dir($this->cachePath)) {
         Filesystem::mkdir($this->cachePath);
     }
     if (!is_writable($this->cachePath)) {
         return false;
     }
     $id = $this->cleanupId($id);
     $id = $this->cachePath . $id . '.php';
     if (is_object($content)) {
         throw new \Exception('You cannot use the CacheFile to cache an object, only arrays, strings and numbers.');
     }
     $cache_literal = "<" . "?php\n";
     $cache_literal .= "\$" . "content   = " . var_export($content, true) . ";\n";
     $cache_literal .= "\$" . "expires_on   = " . $this->getExpiresTime() . ";\n";
     $cache_literal .= "\$" . "cache_complete   = true;\n";
     $cache_literal .= "?" . ">";
     // Write cache to a temp file, then rename it, overwriting the old cache
     // On *nix systems this should guarantee atomicity
     $tmp_filename = tempnam($this->cachePath, 'tmp_');
     @chmod($tmp_filename, 0640);
     if ($fp = @fopen($tmp_filename, 'wb')) {
         @fwrite($fp, $cache_literal, strlen($cache_literal));
         @fclose($fp);
         if (!@rename($tmp_filename, $id)) {
             // On some systems rename() doesn't overwrite destination
             @unlink($id);
             if (!@rename($tmp_filename, $id)) {
                 // Make sure that no temporary file is left over
                 // if the destination is not writable
                 @unlink($tmp_filename);
             }
         }
         $this->opCacheInvalidate($id);
         return true;
     }
     return false;
 }
Exemplo n.º 11
0
 protected function generatePluginFolder($pluginName)
 {
     $pluginPath = $this->getPluginPath($pluginName);
     Filesystem::mkdir($pluginPath);
 }
Exemplo n.º 12
0
 /**
  * Save translations to  temporary file; translations should already be cleansed.
  *
  * @throws \Exception
  * @return bool|int False if failure, or number of bytes written
  */
 public function saveTemporary()
 {
     $this->applyFilters();
     if (!$this->hasTranslations() || !$this->isValid()) {
         throw new Exception('unable to save empty or invalid translations');
     }
     $path = $this->getTemporaryTranslationPath();
     Filesystem::mkdir(dirname($path));
     return file_put_contents($path, $this->__toString());
 }
Exemplo n.º 13
0
 private function createEmptyTarget()
 {
     Filesystem::mkdir($this->testPath . '/target');
     return $this->testPath . '/target';
 }
Exemplo n.º 14
0
 /**
  * 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;
     }
 }
Exemplo n.º 15
0
 /**
  * Check if the merged file directory exists and is writable.
  *
  * @return string The directory location
  * @throws Exception if directory is not writable.
  */
 public function getAssetDirectory()
 {
     $mergedFileDirectory = PIWIK_USER_PATH . "/tmp/assets";
     $mergedFileDirectory = SettingsPiwik::rewriteTmpPathWithInstanceId($mergedFileDirectory);
     if (!is_dir($mergedFileDirectory)) {
         Filesystem::mkdir($mergedFileDirectory);
     }
     if (!is_writable($mergedFileDirectory)) {
         throw new Exception("Directory " . $mergedFileDirectory . " has to be writable.");
     }
     return $mergedFileDirectory;
 }
Exemplo n.º 16
0
Arquivo: Http.php Projeto: piwik/piwik
 public static function ensureDestinationDirectoryExists($destinationPath)
 {
     if ($destinationPath) {
         Filesystem::mkdir(dirname($destinationPath));
         if (($file = @fopen($destinationPath, 'wb')) === false || !is_resource($file)) {
             throw new Exception('Error while creating the file: ' . $destinationPath);
         }
         return $file;
     }
     return null;
 }