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;
}
/**
* Checks that the directories Piwik needs write access are actually writable
* Displays a nice error page if permissions are missing on some directories
*
* @param array $directoriesToCheck Array of directory names to check
*/
public static function dieIfDirectoriesNotWritable($directoriesToCheck = null)
{
$resultCheck = self::checkDirectoriesWritable($directoriesToCheck);
if (array_search(false, $resultCheck) === false) {
return;
}
$directoryList = '';
foreach ($resultCheck as $dir => $bool) {
$realpath = Filesystem::realpath($dir);
if (!empty($realpath) && $bool === false) {
$directoryList .= self::getMakeWritableCommand($realpath);
}
}
// Also give the chown since the chmod is only 755
if (!SettingsServer::isWindows()) {
$realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/');
$directoryList = "chown -R ". self::getUserAndGroup() ." " . $realpath . "
" . $directoryList;
}
if (function_exists('shell_exec')) {
$currentUser = self::getUser();
if (!empty($currentUser)) {
$optionalUserInfo = " (running as user '" . $currentUser . "')";
}
}
$directoryMessage = "
Matomo couldn't write to some directories $optionalUserInfo.
"; $directoryMessage .= "Try to Execute the following commands on your server, to allow Write access on these directories" . ":
" . "$directoryList" . "
If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.
" . "After applying the modifications, you can refresh the page.
" . "If you need more help, try Matomo.org.
"; $ex = new MissingFilePermissionException($directoryMessage); $ex->setIsHtmlMessage(); throw $ex; } /** * Returns the help message when the auto update can't run because of missing permissions * * @return string */ public static function getAutoUpdateMakeWritableMessage() { $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/'); $message = ''; $message .= "" . self::getCommandToChangeOwnerOfPiwikFiles() . "
chmod -R 0755 " . $realpath . "
chown -R ". Common::sanitizeInputValue(self::getUserAndGroup()) ." " . Common::sanitizeInputValue($path) . "
cacls $realpath /t /g " . Common::sanitizeInputValue(self::getUser()) . ":f
chmod -R 0755 $realpath