Skip to content

Commit

Permalink
Install: Add check on .env.local writeability
Browse files Browse the repository at this point in the history
  • Loading branch information
ywarnier committed Aug 5, 2020
1 parent bd162c8 commit f452196
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions public/main/install/install.lib.php
Expand Up @@ -946,6 +946,10 @@ function display_requirements(
<td class="requirements-item">'.$basePath.'var/</td>
<td class="requirements-value">'.check_writable($basePath.'var').'</td>
</tr>
<tr>
<td class="requirements-item">'.$basePath.'.env.local</td>
<td class="requirements-value">'.checkCanCreateFile($basePath.'.env.local').'</td>
</tr>
<tr>
<td class="requirements-item">'.$basePath.'config/</td>
<td class="requirements-value">'.check_writable($basePath.'config').'</td>
Expand Down Expand Up @@ -3707,3 +3711,29 @@ function generateRandomToken()
{
return hash('sha1', uniqid(mt_rand(), true));
}

/**
* This function checks if the given file can be created or overwritten
*
* @param string $file Full path to a file
*
* @return string An HTML coloured label showing success or failure
*/
function checkCanCreateFile($file)
{
if (file_exists($file)) {
if (is_writeable($file)) {
return Display::label(get_lang('Writable'), 'success');
} else {
return Display::label(get_lang('Not writable'), 'important');
}
} else {
$write = @file_put_contents($file, '');
if ($write) {
unlink($file);
return Display::label(get_lang('Writable'), 'success');
} else {
return Display::label(get_lang('Not writable'), 'important');
}
}
}

0 comments on commit f452196

Please sign in to comment.