From 148d19bbce81ace7d0a5031e18584a34b6d00975 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 24 May 2025 12:37:12 +1000 Subject: [PATCH] Some extra debug logging to help with fixes testing --- app/Classes/LDAP/Import.php | 7 +++++++ app/Classes/LDAP/Import/LDIF.php | 14 +++++++------- app/Classes/LDAP/Server.php | 7 ++++--- app/Http/Controllers/HomeController.php | 2 ++ app/Ldap/Entry.php | 1 - 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Classes/LDAP/Import.php b/app/Classes/LDAP/Import.php index 9008f3fe..61525508 100644 --- a/app/Classes/LDAP/Import.php +++ b/app/Classes/LDAP/Import.php @@ -3,6 +3,7 @@ namespace App\Classes\LDAP; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use LdapRecord\LdapRecordException; use App\Exceptions\Import\GeneralException; @@ -16,6 +17,8 @@ use App\Ldap\Entry; */ abstract class Import { + private const LOGKEY = 'aI-'; + // Valid LDIF commands protected const LDAP_IMPORT_ADD = 1; protected const LDAP_IMPORT_DELETE = 2; @@ -57,6 +60,8 @@ abstract class Import $o->save(); } catch (LdapRecordException $e) { + Log::error(sprintf('%s:Import Commit Error',self::LOGKEY),['e'=>$e->getMessage(),'detailed'=>$e->getDetailedError()]); + if ($e->getDetailedError()) return collect([ 'dn'=>$o->getDN(), @@ -76,6 +81,8 @@ abstract class Import ]); } + Log::debug(sprintf('%s:Import Commited',self::LOGKEY)); + return collect(['dn'=>$o->getDN(),'result'=>__('Created')]); default: diff --git a/app/Classes/LDAP/Import/LDIF.php b/app/Classes/LDAP/Import/LDIF.php index 5cde1527..fc4e5896 100644 --- a/app/Classes/LDAP/Import/LDIF.php +++ b/app/Classes/LDAP/Import/LDIF.php @@ -35,7 +35,7 @@ class LDIF extends Import // @todo When renaming DNs, the hotlink should point to the new entry on success, or the old entry on failure. foreach (preg_split('/(\r?\n|\r)/',$this->input) as $line) { $c++; - Log::debug(sprintf('%s: LDIF Line [%s]',self::LOGKEY,$line)); + Log::debug(sprintf('%s:LDIF Line [%s]',self::LOGKEY,$line)); $line = trim($line); // If the line starts with a comment, ignore it @@ -48,7 +48,7 @@ class LDIF extends Import // Add the last attribute; $o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); - Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN())); + Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN())); // Commit $result->push($this->commit($o,$action)); @@ -95,7 +95,7 @@ class LDIF extends Import // If $m is NULL, then this is the 2nd (or more) line of a base64 encoded value if (! $m) { $value .= $line; - Log::debug(sprintf('%s: Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c)); + Log::debug(sprintf('%s:- Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c)); // add to last attr value continue 2; @@ -108,7 +108,7 @@ class LDIF extends Import throw new GeneralException(sprintf('Previous Entry not complete? (line %d)',$c)); $dn = $base64encoded ? base64_decode($value) : $value; - Log::debug(sprintf('%s: Creating new entry:',self::LOGKEY,$dn)); + Log::debug(sprintf('%s:Creating new entry:',self::LOGKEY,$dn)); //$o = Entry::find($dn); // If it doesnt exist, we'll create it @@ -120,7 +120,7 @@ class LDIF extends Import $action = self::LDAP_IMPORT_ADD; } else { - Log::debug(sprintf('%s: Adding Attribute [%s] value [%s] (%d)',self::LOGKEY,$attribute,$value,$c)); + Log::debug(sprintf('%s:Adding Attribute [%s] value [%s] (%d)',self::LOGKEY,$attribute,$value,$c)); if ($value) $o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); @@ -134,7 +134,7 @@ class LDIF extends Import $attribute = $m[1]; $value = $m[3]; - Log::debug(sprintf('%s: New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c)); + Log::debug(sprintf('%s:- New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c)); } if ($version !== 1) @@ -146,7 +146,7 @@ class LDIF extends Import // Add the last attribute; $o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); - Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN())); + Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN())); // Commit $result->push($this->commit($o,$action)); diff --git a/app/Classes/LDAP/Server.php b/app/Classes/LDAP/Server.php index fe669339..3c2e8909 100644 --- a/app/Classes/LDAP/Server.php +++ b/app/Classes/LDAP/Server.php @@ -204,7 +204,7 @@ final class Server default => TRUE, }; - Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'Caching' : 'Not Cached',$dn)); + Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'DN CACHEABLE' : 'DN NOT cacheable',$dn)); return $cache; } @@ -216,7 +216,7 @@ final class Server private static function cachetime(): Carbon { return Carbon::now() - ->addSeconds(Config::get('ldap.cache.time')); + ->addSeconds(Config::get('ldap.cache.time') ?: 0); } /** @@ -232,7 +232,8 @@ final class Server ->setDN($dn) ->cache( until: self::cachetime(), - flush: self::cacheflush($dn)) + flush: self::cacheflush($dn) + ) ->select($attrs); } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 23e42c56..eee8c61e 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,6 +8,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Redirect; use LdapRecord\Exceptions\InsufficientAccessException; use LdapRecord\LdapRecordException; @@ -435,6 +436,7 @@ class HomeController extends Controller switch ($type) { case 'ldif': $import = new LDIFImport($x=($request->text ?: $request->file->get())); + Log::debug('Processing LDIF import',['data'=>$x,'import'=>$import]); break; default: diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index 3fc735fc..f8707fa8 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -6,7 +6,6 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Crypt; use LdapRecord\Support\Arr; use LdapRecord\Models\Model; -use LdapRecord\Query\Model\Builder; use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute\Factory;