From 811ca51c4f591895e14e5e2829a09fa1cf62847a Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 16:59:44 -0600 Subject: [PATCH 1/6] Wipe database before restoration --- app/Http/Controllers/SettingsController.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 28c56dabff..9fd4ace5e6 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1202,11 +1202,10 @@ class SettingsController extends Controller // grab the user's info so we can make sure they exist in the system $user = User::find(Auth::user()->id); + // TODO: run a backup - // TODO: run a backup - - // TODO: add db:wipe + Artisan::call('db:wipe'); // run the restore command Artisan::call('snipeit:restore', @@ -1216,10 +1215,8 @@ class SettingsController extends Controller 'filename' => storage_path($path).'/'.$filename ]); - $output = Artisan::output(); - - // If it's greater than 300, it probably worked + $output = Artisan::output(); if (strlen($output) > 300) { \Auth::logout(); return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.'); From 263893b3c6abdf08cc45323902d88de6bf19c8de Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 17:42:06 -0600 Subject: [PATCH 2/6] Search logged in user that made the restore, if they doesn't exist in the restored system, add it again --- app/Http/Controllers/SettingsController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 9fd4ace5e6..bc741f846b 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1218,6 +1218,12 @@ class SettingsController extends Controller // If it's greater than 300, it probably worked $output = Artisan::output(); if (strlen($output) > 300) { + $find_user = DB::table('users')->where('first_name', $user->first_name)->where('last_name', $user->last_name)->exists(); + if(!$find_user){ + \Log::warning('Attempting to restore user: ' . $user->first_name . ' ' . $user->last_name); + $new_user = $user->replicate(); + $new_user->push(); + } \Auth::logout(); return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.'); } else { From 548b1727442c42e1f1412ef2018684af32c0d5f4 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 18:00:24 -0600 Subject: [PATCH 3/6] Logout every connected user --- app/Http/Controllers/SettingsController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index bc741f846b..ab247dda2b 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1224,7 +1224,14 @@ class SettingsController extends Controller $new_user = $user->replicate(); $new_user->push(); } + + $session_files = glob(storage_path("framework/sessions/*")); + foreach ($session_files as $file) { + if (is_file($file)) + unlink($file); + } \Auth::logout(); + return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.'); } else { return redirect()->route('settings.backups.index')->with('error', $output); From 5b2a5ff124dae750169fa356b0218d48bb6c0561 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 18:03:00 -0600 Subject: [PATCH 4/6] Put the 'remember_token' column as null in the users table --- app/Http/Controllers/SettingsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index ab247dda2b..31ece50829 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1230,6 +1230,7 @@ class SettingsController extends Controller if (is_file($file)) unlink($file); } + DB::table('users')->update(['remember_token' => null]); \Auth::logout(); return redirect()->route('login')->with('success', 'Your system has been restored. Please login again.'); From 23a6907975bd922e0d3cd86c1f15680541e460de Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 18:05:06 -0600 Subject: [PATCH 5/6] Some minor stylistic changes --- app/Http/Controllers/SettingsController.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 31ece50829..27fd8236ad 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1238,16 +1238,6 @@ class SettingsController extends Controller return redirect()->route('settings.backups.index')->with('error', $output); } - //dd($output); - - // TODO: insert the user if they are not there in the old one - - - - - // log the user out - - } else { return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found')); From f1ba5c77423293b8e436c0dedb79088f9ba3607f Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 17 Feb 2022 22:47:35 -0600 Subject: [PATCH 6/6] Changed the warning message in the Backups page --- resources/lang/en/admin/settings/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index d5044c3811..f4e8cc57bb 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -32,7 +32,7 @@ return [ 'backups_upload' => 'Upload Backup', 'backups_path' => 'Backups on the server are stored in :path', 'backups_restore_warning' => 'Use the restore button to restore from a previous backup. (This does not currently work with S3 file storage or Docker.

Your entire :app_name database and any uploaded files will be completely replaced by what\'s in the backup file. ', - 'backups_logged_out' => 'You will be logged out once your restore is complete.', + 'backups_logged_out' => 'All existing users, including you, will be logged out once your restore is complete.', 'backups_large' => 'Very large backups may time out on the restore attempt and may still need to be run via command line. ', 'barcode_settings' => 'Barcode Settings', 'confirm_purge' => 'Confirm Purge',