From de3ebfecfe1668107aa58638314b87646112d840 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Thu, 6 Feb 2025 13:24:39 +0000 Subject: [PATCH 1/7] Ensure we don't call preg_split() with a null as the second parameter --- app/Http/Requests/SettingsSamlRequest.php | 2 +- app/Models/CustomField.php | 2 +- app/Services/Saml.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/SettingsSamlRequest.php b/app/Http/Requests/SettingsSamlRequest.php index 8f02d64f03..2ab876141a 100644 --- a/app/Http/Requests/SettingsSamlRequest.php +++ b/app/Http/Requests/SettingsSamlRequest.php @@ -62,7 +62,7 @@ class SettingsSamlRequest extends FormRequest $custom_privateKey = ''; $custom_x509certNew = ''; if (! empty($this->input('saml_custom_settings'))) { - $req_custom_settings = preg_split('/\r\n|\r|\n/', $this->input('saml_custom_settings')); + $req_custom_settings = preg_split('/\r\n|\r|\n/', $this->input('saml_custom_settings', '')); $custom_settings = []; foreach ($req_custom_settings as $custom_setting) { diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index dfa4971367..81eff9b4cd 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -307,7 +307,7 @@ class CustomField extends Model public function formatFieldValuesAsArray() { $result = []; - $arr = preg_split('/\\r\\n|\\r|\\n/', $this->field_values); + $arr = preg_split('/\\r\\n|\\r|\\n/', $this->field_values ?? ''); if (($this->element != 'checkbox') && ($this->element != 'radio')) { $result[''] = 'Select '.strtolower($this->format); diff --git a/app/Services/Saml.php b/app/Services/Saml.php index 860ec76171..222c2c2ea3 100644 --- a/app/Services/Saml.php +++ b/app/Services/Saml.php @@ -209,7 +209,7 @@ class Saml } } - $custom_settings = preg_split('/\r\n|\r|\n/', $setting->saml_custom_settings); + $custom_settings = preg_split('/\r\n|\r|\n/', $setting->saml_custom_settings ?? ''); if ($custom_settings) { foreach ($custom_settings as $custom_setting) { $split = explode('=', $custom_setting, 2); From f41583fd59eec20da07957089232165a45115981 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 6 Feb 2025 11:34:14 -0800 Subject: [PATCH 2/7] adds ternary checks on locations before pulling names in notifications --- app/Notifications/CheckinAssetNotification.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index fa4780c1fd..c6828ef8e9 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -79,7 +79,7 @@ class CheckinAssetNotification extends Notification $fields = [ trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', - trans('general.status') => $item->assetstatus->name, + trans('general.status') => $item->assetstatus?->name, trans('general.location') => ($item->location) ? $item->location->name : '', ]; @@ -106,9 +106,9 @@ class CheckinAssetNotification extends Notification ->title(trans('mail.Asset_Checkin_Notification')) ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '') + ->fact(trans('mail.checked_into'), ($item->location) ? $item->location->name : '') ->fact(trans('mail.Asset_Checkin_Notification') . " by ", $admin->present()->fullName()) - ->fact(trans('admin/hardware/form.status'), $item->assetstatus->name) + ->fact(trans('admin/hardware/form.status'), $item->assetstatus?->name) ->fact(trans('mail.notes'), $note ?: ''); } @@ -116,9 +116,9 @@ class CheckinAssetNotification extends Notification $message = trans('mail.Asset_Checkin_Notification'); $details = [ trans('mail.asset') => htmlspecialchars_decode($item->present()->name), - trans('mail.checked_into') => $item->location->name ? $item->location->name : '', + trans('mail.checked_into') => ($item->location) ? $item->location->name : '', trans('mail.Asset_Checkin_Notification')." by " => $admin->present()->fullName(), - trans('admin/hardware/form.status') => $item->assetstatus->name, + trans('admin/hardware/form.status') => $item->assetstatus?->name, trans('mail.notes') => $note ?: '', ]; @@ -142,8 +142,8 @@ class CheckinAssetNotification extends Notification Section::create( KeyValue::create( trans('mail.checked_into') ?: '', - $item->location->name ? $item->location->name : '', - trans('admin/hardware/form.status').": ".$item->assetstatus->name, + ($item->location) ? $item->location->name : '', + trans('admin/hardware/form.status').": ".$item->assetstatus?->name, ) ->onClick(route('hardware.show', $item->id)) ) From 42fa2e12db48ab52c4594b9601c00342116e6b9a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Feb 2025 13:55:33 -0800 Subject: [PATCH 3/7] Replace Form::checkbox --- resources/views/account/profile.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php index d27367192a..153492a3bf 100755 --- a/resources/views/account/profile.blade.php +++ b/resources/views/account/profile.blade.php @@ -128,7 +128,7 @@
{!! $errors->first('image_delete', ':message') !!} From 9559c5a0251e5cd335a698ea7522a4a9b8aad2ce Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Feb 2025 14:08:13 -0800 Subject: [PATCH 4/7] Replace Form::checkbox and inline label --- resources/views/account/profile.blade.php | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php index 153492a3bf..b745c19360 100755 --- a/resources/views/account/profile.blade.php +++ b/resources/views/account/profile.blade.php @@ -150,13 +150,23 @@ @if ($snipeSettings->two_factor_enabled=='1')
- @can('self.two_factor') -
@@ -66,7 +66,7 @@
@@ -85,7 +85,7 @@
@@ -103,7 +103,7 @@
@@ -112,7 +112,7 @@
@@ -215,7 +215,7 @@
From c420670ebbd5a68752501e7a65909052f19fa228 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 10 Feb 2025 22:26:00 +0000 Subject: [PATCH 7/7] Small fixes to accessories files handling Signed-off-by: snipe --- .../AccessoriesFilesController.php | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/Accessories/AccessoriesFilesController.php b/app/Http/Controllers/Accessories/AccessoriesFilesController.php index c251166ce2..9dbb16d83a 100644 --- a/app/Http/Controllers/Accessories/AccessoriesFilesController.php +++ b/app/Http/Controllers/Accessories/AccessoriesFilesController.php @@ -55,11 +55,11 @@ class AccessoriesFilesController extends Controller } - return redirect()->route('accessories.show', $accessory->id)->with('error', trans('general.no_files_uploaded')); + return redirect()->route('accessories.show', $accessory->id)->withFragment('files')->with('error', trans('general.no_files_uploaded')); } // Prepare the error message - return redirect()->route('accessories.index') - ->with('error', trans('general.file_does_not_exist')); + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + } /** @@ -72,29 +72,27 @@ class AccessoriesFilesController extends Controller */ public function destroy($accessoryId = null, $fileId = null) : RedirectResponse { - $accessory = Accessory::find($accessoryId); - - // the asset is valid - if (isset($accessory->id)) { + if ($accessory = Accessory::find($accessoryId)) { $this->authorize('update', $accessory); - $log = Actionlog::find($fileId); - // Remove the file if one exists - if (Storage::exists('accessories/'.$log->filename)) { - try { - Storage::delete('accessories/'.$log->filename); - } catch (\Exception $e) { - Log::debug($e); + if ($log = Actionlog::find($fileId)) { + + if (Storage::exists('private_uploads/accessories/'.$log->filename)) { + try { + Storage::delete('private_uploads/accessories/' . $log->filename); + $log->delete(); + return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); + } catch (\Exception $e) { + Log::debug($e); + return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist')); + } } + } - - $log->delete(); - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); + return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found')); } - // Redirect to the licence management page - return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist')); + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); } /** @@ -124,10 +122,11 @@ class AccessoriesFilesController extends Controller } } - return redirect()->route('accessories.show', ['accessory' => $accessory])->with('error', trans('general.log_record_not_found')); + return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found')); } - return redirect()->route('accessories.index')->with('error', trans('general.file_not_found')); + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + } }