From 0df539c261160c39585fb289e051424585a6001d Mon Sep 17 00:00:00 2001
From: Julian Prieber <60265788+JulianPrieber@users.noreply.github.com>
Date: Thu, 30 Jun 2022 10:39:40 +0200
Subject: [PATCH] Added HTTPS redirection to env config
---
.env | 4 +-
.../views/components/finishing.blade.php | 39 +++++++++++++++++++
resources/views/layouts/lang.blade.php | 2 +-
resources/views/update.blade.php | 37 +-----------------
routes/web.php | 4 +-
storage/backups/default_settings | 4 +-
.../templates/advanced-config-update-1.php | 2 -
7 files changed, 49 insertions(+), 43 deletions(-)
create mode 100644 resources/views/components/finishing.blade.php
diff --git a/.env b/.env
index 4a46ba5..8f58637 100644
--- a/.env
+++ b/.env
@@ -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
\ No newline at end of file
+CUSTOM_META_TAGS=false
+
+FORCE_HTTPS=true
\ No newline at end of file
diff --git a/resources/views/components/finishing.blade.php b/resources/views/components/finishing.blade.php
new file mode 100644
index 0000000..e6179c0
--- /dev/null
+++ b/resources/views/components/finishing.blade.php
@@ -0,0 +1,39 @@
+ 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 "current() . "?success\" />";
+ ?>
\ No newline at end of file
diff --git a/resources/views/layouts/lang.blade.php b/resources/views/layouts/lang.blade.php
index 11ff14c..05a064f 100644
--- a/resources/views/layouts/lang.blade.php
+++ b/resources/views/layouts/lang.blade.php
@@ -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'];
diff --git a/resources/views/update.blade.php b/resources/views/update.blade.php
index 4d9b78e..ec4ddda 100644
--- a/resources/views/update.blade.php
+++ b/resources/views/update.blade.php
@@ -99,42 +99,7 @@ exit(); ?>
Finishing up
- 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 "current() . "?success\" />";
- ?>
+ @include('components.finishing')
@endif
@if($_SERVER['QUERY_STRING'] === 'success')
diff --git a/routes/web.php b/routes/web.php
index 7cd5691..d5ec3ca 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -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');
diff --git a/storage/backups/default_settings b/storage/backups/default_settings
index 3bdb72b..d38173e 100644
--- a/storage/backups/default_settings
+++ b/storage/backups/default_settings
@@ -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
\ No newline at end of file
+CUSTOM_META_TAGS=false
+
+FORCE_HTTPS=false
\ No newline at end of file
diff --git a/storage/templates/advanced-config-update-1.php b/storage/templates/advanced-config-update-1.php
index d3aebdc..6f66651 100644
--- a/storage/templates/advanced-config-update-1.php
+++ b/storage/templates/advanced-config-update-1.php
@@ -9,8 +9,6 @@
'expand_panel_admin_menu_permanently' => 'false',
- 'redirect_https' => 'false',
-
'disable_default_password_notice' => 'false',
];
\ No newline at end of file