/** * 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 direcory name => true|false (is writable) */ public static function checkDirectoriesWritable($directoriesToCheck = null) { if ($directoriesToCheck == null) { $directoriesToCheck = array('/config', '/tmp', '/tmp/templates_c', '/tmp/cache', '/tmp/latest'); } $resultCheck = array(); foreach ($directoriesToCheck as $directoryToCheck) { if (!preg_match('/^' . preg_quote(PIWIK_INCLUDE_PATH, '/') . '/', $directoryToCheck)) { $directoryToCheck = PIWIK_INCLUDE_PATH . $directoryToCheck; } if (!file_exists($directoryToCheck)) { Piwik_Common::mkdir($directoryToCheck, 0755, false); } $directory = Piwik_Common::realpath($directoryToCheck); $resultCheck[$directory] = false; if ($directory !== false && is_writable($directoryToCheck)) { $resultCheck[$directory] = true; } } return $resultCheck; }
public static function mkdir($path, $mode = 0755, $denyAccess = true) { if (!is_dir($path)) { $directoryParent = Piwik_Common::realpath(dirname($path)); if (is_writable($directoryParent)) { mkdir($path, $mode, true); } } if ($denyAccess) { self::createHtAccess($path); } }
/** * Returns the help message when the auto update can't run because of missing permissions * * @return string */ public static function getAutoUpdateMakeWritableMessage() { $realpath = Piwik_Common::realpath(PIWIK_INCLUDE_PATH . '/'); $message = ''; $message .= "<code>chown -R www-data:www-data " . $realpath . "</code><br />"; $message .= "<code>chmod -R 0755 " . $realpath . "</code><br />"; $message .= 'After you execute these commands (or change permissions via your FTP software), refresh the page and you should be able to use the "Automatic Update" feature.'; return $message; }
/** * 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) */ static public function checkDirectoriesWritable($directoriesToCheck = null) { if( $directoriesToCheck == null ) { $directoriesToCheck = array( '/config/', '/tmp/', '/tmp/templates_c/', '/tmp/cache/', '/tmp/assets/', '/tmp/latest/', '/tmp/tcpdf/', ); } $resultCheck = array(); foreach($directoriesToCheck as $directoryToCheck) { if( !preg_match('/^'.preg_quote(PIWIK_USER_PATH, '/').'/', $directoryToCheck) ) { $directoryToCheck = PIWIK_USER_PATH . $directoryToCheck; } if(!file_exists($directoryToCheck)) { Piwik_Common::mkdir($directoryToCheck); } $directory = Piwik_Common::realpath($directoryToCheck); $resultCheck[$directory] = false; if($directory !== false // realpath() returns FALSE on failure && is_writable($directoryToCheck)) { $resultCheck[$directory] = true; } } return $resultCheck; }