Added HTTPS redirection to env config

This commit is contained in:
Julian Prieber 2022-06-30 10:39:40 +02:00
parent 64c1fafeb0
commit 0df539c261
7 changed files with 49 additions and 43 deletions

4
.env
View File

@ -74,4 +74,6 @@ SKIP_UPDATE_BACKUP=false
#=CUSTOM_META_TAGS either true or false. Used to enable setting in advanced config file (config/advanced-config.php).
#=You can read more about this config at https://llc.bio/advanced-config.
CUSTOM_META_TAGS=false
CUSTOM_META_TAGS=false
FORCE_HTTPS=true

View File

@ -0,0 +1,39 @@
<?php
//run before finishing:
if(EnvEditor::keyExists('JOIN_BETA')){ /* Do nothing if key already exists */
} else { EnvEditor::addKey('JOIN_BETA', 'false');} // Adds key to .env file
if(EnvEditor::keyExists('SKIP_UPDATE_BACKUP')){ /* Do nothing if key already exists */
} else { EnvEditor::addKey('SKIP_UPDATE_BACKUP', 'false');} // Adds key to .env file
if(EnvEditor::keyExists('CUSTOM_META_TAGS')){ /* Do nothing if key already exists */
} else {EnvEditor::addKey('CUSTOM_META_TAGS', 'false');}
if (!config()->has('advanced-config.expand_panel_admin_menu_permanently') and !config()->has('disable_default_password_notice')) {
function getStringBetween($string, $start, $end) {
$lastStartIndex = strrpos($string, $start);
$lastEndIndex = strrpos($string, $end);
$substringStartIndex = $lastStartIndex + strlen($start);
$substringSize = $lastStartIndex - $lastEndIndex - 1;
return substr($string, $substringStartIndex, $substringSize);
}
$subject = file_get_contents('config/advanced-config.php');
$search = ")";
$replace = "),";
file_put_contents('config/advanced-config.php', str_replace('),,', '),', strrev(implode(strrev($replace), explode(strrev($search), strrev($subject), 2)))));
$replace = "];";
file_put_contents('config/advanced-config.php', str_replace($replace, file_get_contents('storage/templates/advanced-config-update-1.php'), file_get_contents('config/advanced-config.php')));
}
if(EnvEditor::keyExists('FORCE_HTTPS')){ /* Do nothing if key already exists */
} else {EnvEditor::addKey('FORCE_HTTPS', 'false');}
echo "<meta http-equiv=\"refresh\" content=\"0; " . url()->current() . "?success\" />";
?>

View File

@ -6,7 +6,7 @@
{{-- Redirects to https if enabled in the advanced-config --}}
@if(config('advanced-config.redirect_https') == 'true')
@if(env('FORCE_HTTPS') == 'true')
@php
if (! isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off' ) {
$redirect_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

View File

@ -99,42 +99,7 @@ exit(); ?>
</div>
<h1 class="loadingtxt">Finishing up</h1>
<?php
//run before finishing:
if(EnvEditor::keyExists('JOIN_BETA')){ /* Do nothing if key already exists */
} else { EnvEditor::addKey('JOIN_BETA', 'false');} // Adds key to .env file
if(EnvEditor::keyExists('SKIP_UPDATE_BACKUP')){ /* Do nothing if key already exists */
} else { EnvEditor::addKey('SKIP_UPDATE_BACKUP', 'false');} // Adds key to .env file
if(EnvEditor::keyExists('CUSTOM_META_TAGS')){ /* Do nothing if key already exists */
} else {EnvEditor::addKey('CUSTOM_META_TAGS', 'false');}
if (!config()->has('advanced-config.expand_panel_admin_menu_permanently') and !config()->has('advanced-config.redirect_https')) {
function getStringBetween($string, $start, $end) {
$lastStartIndex = strrpos($string, $start);
$lastEndIndex = strrpos($string, $end);
$substringStartIndex = $lastStartIndex + strlen($start);
$substringSize = $lastStartIndex - $lastEndIndex - 1;
return substr($string, $substringStartIndex, $substringSize);
}
$subject = file_get_contents('config/advanced-config.php');
$search = ")";
$replace = "),";
file_put_contents('config/advanced-config.php', str_replace('),,', '),', strrev(implode(strrev($replace), explode(strrev($search), strrev($subject), 2)))));
$replace = "];";
file_put_contents('config/advanced-config.php', str_replace($replace, file_get_contents('storage/templates/advanced-config-update-1.php'), file_get_contents('config/advanced-config.php')));
}
echo "<meta http-equiv=\"refresh\" content=\"0; " . url()->current() . "?success\" />";
?>
@include('components.finishing')
@endif
@if($_SERVER['QUERY_STRING'] === 'success')

View File

@ -67,7 +67,7 @@ Route::get('/theme/@{littlelink}', [UserController::class, 'theme'])->name('them
Route::group([
'middleware' => env('REGISTER_AUTH'),
], function () {
if(config('advanced-config.redirect_https') == 'true'){URL::forceScheme('https');}
if(env('FORCE_HTTPS') == 'true'){URL::forceScheme('https');}
Route::get('/studio/index', [UserController::class, 'index'])->name('studioIndex');
Route::get('/studio/add-link', [UserController::class, 'showButtons'])->name('showButtons');
Route::post('/studio/add-link', [UserController::class, 'addLink'])->name('addLink');
@ -91,7 +91,7 @@ Route::post('/studio/profile', [UserController::class, 'editProfile'])->name('ed
Route::group([
'middleware' => 'admin',
], function () {
if(config('advanced-config.redirect_https') == 'true'){URL::forceScheme('https');}
if(env('FORCE_HTTPS') == 'true'){URL::forceScheme('https');}
Route::get('/panel/index', [AdminController::class, 'index'])->name('panelIndex');
Route::get('/panel/users/{type}', [AdminController::class, 'users'])->name('showUsers');
Route::post('/panel/users/{name?}', [AdminController::class, 'searchUser'])->name('searchUser');

View File

@ -74,4 +74,6 @@ SKIP_UPDATE_BACKUP=false
#=CUSTOM_META_TAGS either true or false. Used to enable setting in advanced config file (config/advanced-config.php).
#=You can read more about this config at https://llc.bio/advanced-config.
CUSTOM_META_TAGS=false
CUSTOM_META_TAGS=false
FORCE_HTTPS=false

View File

@ -9,8 +9,6 @@
'expand_panel_admin_menu_permanently' => 'false',
'redirect_https' => 'false',
'disable_default_password_notice' => 'false',
];