Some extra debug logging to help with fixes testing

This commit is contained in:
Deon George 2025-05-24 12:37:12 +10:00
parent 6c501cc29d
commit 148d19bbce
5 changed files with 20 additions and 11 deletions

View File

@ -3,6 +3,7 @@
namespace App\Classes\LDAP; namespace App\Classes\LDAP;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use LdapRecord\LdapRecordException; use LdapRecord\LdapRecordException;
use App\Exceptions\Import\GeneralException; use App\Exceptions\Import\GeneralException;
@ -16,6 +17,8 @@ use App\Ldap\Entry;
*/ */
abstract class Import abstract class Import
{ {
private const LOGKEY = 'aI-';
// Valid LDIF commands // Valid LDIF commands
protected const LDAP_IMPORT_ADD = 1; protected const LDAP_IMPORT_ADD = 1;
protected const LDAP_IMPORT_DELETE = 2; protected const LDAP_IMPORT_DELETE = 2;
@ -57,6 +60,8 @@ abstract class Import
$o->save(); $o->save();
} catch (LdapRecordException $e) { } catch (LdapRecordException $e) {
Log::error(sprintf('%s:Import Commit Error',self::LOGKEY),['e'=>$e->getMessage(),'detailed'=>$e->getDetailedError()]);
if ($e->getDetailedError()) if ($e->getDetailedError())
return collect([ return collect([
'dn'=>$o->getDN(), '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')]); return collect(['dn'=>$o->getDN(),'result'=>__('Created')]);
default: default:

View File

@ -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. // @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) { foreach (preg_split('/(\r?\n|\r)/',$this->input) as $line) {
$c++; $c++;
Log::debug(sprintf('%s: LDIF Line [%s]',self::LOGKEY,$line)); Log::debug(sprintf('%s:LDIF Line [%s]',self::LOGKEY,$line));
$line = trim($line); $line = trim($line);
// If the line starts with a comment, ignore it // If the line starts with a comment, ignore it
@ -48,7 +48,7 @@ class LDIF extends Import
// Add the last attribute; // Add the last attribute;
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); $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 // Commit
$result->push($this->commit($o,$action)); $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 is NULL, then this is the 2nd (or more) line of a base64 encoded value
if (! $m) { if (! $m) {
$value .= $line; $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 // add to last attr value
continue 2; continue 2;
@ -108,7 +108,7 @@ class LDIF extends Import
throw new GeneralException(sprintf('Previous Entry not complete? (line %d)',$c)); throw new GeneralException(sprintf('Previous Entry not complete? (line %d)',$c));
$dn = $base64encoded ? base64_decode($value) : $value; $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); //$o = Entry::find($dn);
// If it doesnt exist, we'll create it // If it doesnt exist, we'll create it
@ -120,7 +120,7 @@ class LDIF extends Import
$action = self::LDAP_IMPORT_ADD; $action = self::LDAP_IMPORT_ADD;
} else { } 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) if ($value)
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); $o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
@ -134,7 +134,7 @@ class LDIF extends Import
$attribute = $m[1]; $attribute = $m[1];
$value = $m[3]; $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) if ($version !== 1)
@ -146,7 +146,7 @@ class LDIF extends Import
// Add the last attribute; // Add the last attribute;
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value); $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 // Commit
$result->push($this->commit($o,$action)); $result->push($this->commit($o,$action));

View File

@ -204,7 +204,7 @@ final class Server
default => TRUE, 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; return $cache;
} }
@ -216,7 +216,7 @@ final class Server
private static function cachetime(): Carbon private static function cachetime(): Carbon
{ {
return Carbon::now() 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) ->setDN($dn)
->cache( ->cache(
until: self::cachetime(), until: self::cachetime(),
flush: self::cacheflush($dn)) flush: self::cacheflush($dn)
)
->select($attrs); ->select($attrs);
} }

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use LdapRecord\Exceptions\InsufficientAccessException; use LdapRecord\Exceptions\InsufficientAccessException;
use LdapRecord\LdapRecordException; use LdapRecord\LdapRecordException;
@ -435,6 +436,7 @@ class HomeController extends Controller
switch ($type) { switch ($type) {
case 'ldif': case 'ldif':
$import = new LDIFImport($x=($request->text ?: $request->file->get())); $import = new LDIFImport($x=($request->text ?: $request->file->get()));
Log::debug('Processing LDIF import',['data'=>$x,'import'=>$import]);
break; break;
default: default:

View File

@ -6,7 +6,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use LdapRecord\Support\Arr; use LdapRecord\Support\Arr;
use LdapRecord\Models\Model; use LdapRecord\Models\Model;
use LdapRecord\Query\Model\Builder;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
use App\Classes\LDAP\Attribute\Factory; use App\Classes\LDAP\Attribute\Factory;