overload();
} catch (\Exception $e) {
// Do nothing
}
if (!empty($_ENV['APP_KEY'])) {
return $_ENV['APP_KEY'];
} else {
return '';
}
}
function clearCache($root_dir)
{
if (file_exists($root_dir.'bootstrap/cache/config.php')) {
unlink($root_dir.'bootstrap/cache/config.php');
}
}
function showError($msg)
{
echo <<
FreeScout Installer
FreeScout Installer
$msg
HTML;
}
function showPermissionsError()
{
$root_dir_no_slash = realpath(__DIR__.'/..');
showError('Web installer could not write data into '.$root_dir_no_slash.'/.env file. Please give your web server user ('.get_current_user().') write permissions in '.$root_dir_no_slash.' folder:
If it does not help, please follow Manual installation instructions.');
}
function getSubdirectory()
{
$subdirectory = $_SERVER['PHP_SELF'];
$filename = basename($_SERVER['SCRIPT_FILENAME']);
if (basename($_SERVER['SCRIPT_NAME']) === $filename) {
$subdirectory = $_SERVER['SCRIPT_NAME'];
} elseif (basename($_SERVER['PHP_SELF']) === $filename) {
$subdirectory = $_SERVER['PHP_SELF'];
} elseif (basename($_SERVER['ORIG_SCRIPT_NAME']) === $filename) {
$subdirectory = $_SERVER['ORIG_SCRIPT_NAME']; // 1and1 shared hosting compatibility
} else {
// Backtrack up the script_filename to find the portion matching
// php_self
$path = $_SERVER['PHP_SELF'];
$file = $_SERVER['SCRIPT_FILENAME'];
$segs = explode('/', trim($file, '/'));
$segs = array_reverse($segs);
$index = 0;
$last = \count($segs);
$subdirectory = '';
do {
$seg = $segs[$index];
$subdirectory = '/'.$seg.$subdirectory;
++$index;
} while ($last > $index && (false !== $pos = strpos($path, $subdirectory)) && 0 != $pos);
}
$subdirectory = str_replace('public/install.php', '', $subdirectory);
$subdirectory = str_replace('install.php', '', $subdirectory);
if (!$subdirectory) {
$subdirectory = '/';
}
return $subdirectory;
}
$app_key = getAppKey($root_dir);
// Generate APP_KEY
if (empty($app_key)) {
// Copy .env.example
if (!file_exists($root_dir.'.env')) {
// Check if .env.example eixists
if (!file_exists($root_dir.'.env.example')) {
showError('File '.$root_dir.'.env.example not found. Please make sure to copy this file from the application dist.');
exit();
}
copy($root_dir.'.env.example', $root_dir.'.env');
if (!file_exists($root_dir.'.env')) {
//echo 'Please copy .env.example file to .env and reload this page.';
showPermissionsError();
exit();
}
}
// Add APP_KEY= to the .env file if needed
// Without APP_KEY= the key will not be generated
if (!preg_match('/^APP_KEY=/m', file_get_contents($root_dir.'.env'))) {
$append_result = file_put_contents($root_dir.'.env', PHP_EOL.'APP_KEY=', FILE_APPEND);
if (!$append_result) {
//showError('Could not write APP_KEY to .env file. Please run the following commands in SSH console: php artisan key:generate php artisan freescout:clear-cache');
showPermissionsError();
exit();
}
}
writeNewEnvironmentFileWith(generateRandomKey(), $root_dir.'.env');
// Clear cache
// We have to clear cache to avoid infinite redirects
clearCache($root_dir);
$app_key = getAppKey($root_dir, false);
}
if (!empty($app_key)) {
// When APP_KEY generated, redirect to /install
header('Location: '.getSubdirectory().'install');
} else {
showPermissionsError();
}
exit();