diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index 370d16f..a63ebf1 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -20,6 +20,12 @@ class Attribute // Current and Old Values protected Collection $values; + // Can this attribute be deleted + protected bool $deletable = FALSE; + + // Is this attribute an internal attribute + protected bool $internal; + /* protected $oldvalues = array(); @@ -27,8 +33,6 @@ class Attribute protected $min_value_count = -1; protected $max_value_count = -1; - # Is the attribute internal - protected $internal = false; # Has the attribute been modified protected $modified = false; # Is the attribute being deleted because of an object class removal @@ -100,6 +104,20 @@ class Attribute */ } + public function __get(string $key): mixed + { + switch ($key) { + case 'name': + return $this->{$key}; + + case 'internal': return isset($this->{$key}) && $this->{$key}; + case 'name_lc': return strtolower($this->name); + + default: + throw new \Exception('Unknown key:'.$key); + } + } + /** * Determine how we render this attribute's value * @@ -903,4 +921,18 @@ class Attribute debug_dump_backtrace(sprintf('Unknown JS request %s',$type),1); } */ + + /** + * Return an instance of this attribute that is deletable. + * This is primarily used for rendering to know if to render delete options. + * + * @return Attribute + */ + public function deletable(): self + { + $clone = clone $this; + $clone->deletable = TRUE; + + return $clone; + } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Binary.php b/app/Classes/LDAP/Attribute/Binary.php index 4f84e14..56be884 100644 --- a/app/Classes/LDAP/Attribute/Binary.php +++ b/app/Classes/LDAP/Attribute/Binary.php @@ -7,6 +7,6 @@ use App\Classes\LDAP\Attribute; /** * Represents an attribute whose values are binary */ -class Binary extends Attribute +abstract class Binary extends Attribute { } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php index 4572eb0..4c56af4 100644 --- a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php +++ b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php @@ -9,20 +9,33 @@ use App\Classes\LDAP\Attribute\Binary; */ final class JpegPhoto extends Binary { + public function __construct(string $name,array $values) + { + parent::__construct($name,$values); + + $this->internal = FALSE; + } + public function __toString(): string { - $result = ''; // We'll use finfo to try and figure out what type of image is stored $f = new \finfo; + $result = ''; + foreach ($this->values as $value) { switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) { case 'image/jpeg': default: - $result .= sprintf('',$x,base64_encode($value)); + $result .= sprintf('', + $x, + base64_encode($value), + $this->deletable ? sprintf('
%s',__('Delete')) : ''); } } + $result .= '
%s
'; + return $result; } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Factory.php b/app/Classes/LDAP/Attribute/Factory.php index 8d45d10..0f9419d 100644 --- a/app/Classes/LDAP/Attribute/Factory.php +++ b/app/Classes/LDAP/Attribute/Factory.php @@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; -use App\Classes\LDAP\{Attribute}; +use App\Classes\LDAP\Attribute; /** * This factory is used to return LDAP attributes as an object @@ -20,11 +20,13 @@ class Factory * Map of attributes to appropriate class */ public const map = [ + 'entryuuid' => Internal\EntryUUID::class, 'jpegphoto' => Binary\JpegPhoto::class, - 'supportedcontrol' => OID::class, - 'supportedextension' => OID::class, - 'supportedfeatures' => OID::class, - 'supportedsaslmechanisms' => Mechanisms::class, + 'objectclass' => ObjectClass::class, + 'supportedcontrol' => Schema\OID::class, + 'supportedextension' => Schema\OID::class, + 'supportedfeatures' => Schema\OID::class, + 'supportedsaslmechanisms' => Schema\Mechanisms::class, ]; /** @@ -36,7 +38,7 @@ class Factory */ public static function create(string $attribute,array $values): Attribute { - $class = Arr::get(self::map,strtolower($attribute),Attribute::class); + $class = Arr::get(self::map,$attribute,Attribute::class); Log::debug(sprintf('%s:Creating LDAP Attribute [%s] as [%s]',static::LOGKEY,$attribute,$class)); return new $class($attribute,$values); diff --git a/app/Classes/LDAP/Attribute/Internal.php b/app/Classes/LDAP/Attribute/Internal.php new file mode 100644 index 0000000..5f94089 --- /dev/null +++ b/app/Classes/LDAP/Attribute/Internal.php @@ -0,0 +1,13 @@ +values->sort()->join('
'); + } +} \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Schema.php b/app/Classes/LDAP/Attribute/Schema.php new file mode 100644 index 0000000..533c4f5 --- /dev/null +++ b/app/Classes/LDAP/Attribute/Schema.php @@ -0,0 +1,50 @@ +put($x=Arr::get($fields,0),[ + 'title'=>Arr::get($fields,1,$x), + 'ref'=>Arr::get($fields,2), + 'desc'=>Arr::get($fields,3,__('No description available, can you help with one?')), + ]); + } + fclose($f); + + return $result; + }); + + return Arr::get(($array ? $array->get($string) : []),$key); + } +} \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Mechanisms.php b/app/Classes/LDAP/Attribute/Schema/Mechanisms.php similarity index 58% rename from app/Classes/LDAP/Attribute/Mechanisms.php rename to app/Classes/LDAP/Attribute/Schema/Mechanisms.php index 099af52..51474ae 100644 --- a/app/Classes/LDAP/Attribute/Mechanisms.php +++ b/app/Classes/LDAP/Attribute/Schema/Mechanisms.php @@ -1,16 +1,13 @@ put($x=Arr::get($fields,0),[ - 'title'=>Arr::get($fields,1,$x), - 'ref'=>Arr::get($fields,2), - 'desc'=>Arr::get($fields,3,__('No description available, can you help with one?')), - ]); - } - fclose($f); - - return $result; - }); - - return Arr::get(($array ? $array->get($string) : []),$key); + return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key); } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/OID.php b/app/Classes/LDAP/Attribute/Schema/OID.php similarity index 55% rename from app/Classes/LDAP/Attribute/OID.php rename to app/Classes/LDAP/Attribute/Schema/OID.php index 6adb410..1b202d7 100644 --- a/app/Classes/LDAP/Attribute/OID.php +++ b/app/Classes/LDAP/Attribute/Schema/OID.php @@ -1,16 +1,13 @@ * - * @param string $oid The OID number (ie, "1.3.6.1.4.1.4203.1.5.1") of the OID of interest. + * @param string $string The OID number (ie, "1.3.6.1.4.1.4203.1.5.1") of the OID of interest. * @param string $key The title|ref|desc to return * @return string|null * @testedby TranslateOidTest::testRootDSE() */ - private static function get(string $string,string $key): ?string + protected static function get(string $string,string $key): ?string { - $array = Cache::remember('oids',86400,function() { - try { - $f = fopen(config_path('ldap_supported_oids.txt'),'r'); - - } catch (\Exception $e) { - return NULL; - } - - $result = collect(); - - while (! feof($f)) { - $line = trim(fgets($f)); - - if (! $line OR preg_match('/^#/',$line)) - continue; - - $fields = explode(':',$line); - - $result->put($x=Arr::get($fields,0),[ - 'title'=>Arr::get($fields,1,$x), - 'ref'=>Arr::get($fields,2), - 'desc'=>Arr::get($fields,3,__('No description available, can you help with one?')), - ]); - } - fclose($f); - - return $result; - }); - - return Arr::get(($array ? $array->get($string) : []),$key); + return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key); } } \ No newline at end of file diff --git a/app/Classes/LDAP/Schema/Base.php b/app/Classes/LDAP/Schema/Base.php index a835e2f..d97ef6c 100644 --- a/app/Classes/LDAP/Schema/Base.php +++ b/app/Classes/LDAP/Schema/Base.php @@ -42,7 +42,7 @@ abstract class Base { case 'oid': return $this->oid; default: - throw new InvalidUsage('Unknown key: '.$key); + throw new InvalidUsage('Unknown key:'.$key); } } diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index b05dfda..80acb51 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -3,6 +3,7 @@ namespace App\Ldap; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use LdapRecord\Models\Model; use App\Classes\LDAP\Attribute\Factory; @@ -14,6 +15,7 @@ class Entry extends Model public function getAttributes(): array { $result = collect(); + foreach (parent::getAttributes() as $attribute => $value) { $result->put($attribute,Factory::create($attribute,$value)); } @@ -36,6 +38,13 @@ class Entry extends Model /* METHODS */ + public function getVisibleAttributes(): Collection + { + return collect($this->getAttributes())->filter(function($item) { + return ! $item->internal; + }); + } + /** * Return an icon for a DN based on objectClass * diff --git a/resources/views/frames/dn.blade.php b/resources/views/frames/dn.blade.php index 9a474a9..dba7e57 100644 --- a/resources/views/frames/dn.blade.php +++ b/resources/views/frames/dn.blade.php @@ -10,14 +10,64 @@ @endsection @section('main-content') -
- - @foreach ($o->getAttributes() as $attribute => $value) - - - - - @endforeach -
{{ $attribute }}{!! $value !!}
+
+
+
+ + +
+ +
+
+
+ + @foreach ($o->getVisibleAttributes() as $ao) + + + + + + {{-- + + --}} + + @endforeach +
+ {{ $ao->name }} + + +
+ {!! $ao->deletable() !!}
+ + {{ __('Add Value') }} +
@dump($ao)
+
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+
+
+
+ + @endsection diff --git a/resources/views/frames/info.blade.php b/resources/views/frames/info.blade.php index b8d7e4b..775aad3 100644 --- a/resources/views/frames/info.blade.php +++ b/resources/views/frames/info.blade.php @@ -12,14 +12,14 @@ @section('main-content')
- @foreach ($s->rootDSE()->getAttributes() as $attribute => $value) + @foreach ($s->rootDSE()->getAttributes() as $attribute => $ao) - + @endforeach
{!! ($x=$s->schema('attributetypes',$attribute)) ? sprintf('%s',$x->name_lc,url('schema/attributetypes',$x->name_lc),$x->name) : $attribute !!} {!! $value !!}{!! $ao !!}
diff --git a/resources/views/frames/schema.blade.php b/resources/views/frames/schema.blade.php index 5279ad7..71201e2 100644 --- a/resources/views/frames/schema.blade.php +++ b/resources/views/frames/schema.blade.php @@ -11,7 +11,9 @@ @section('main-content')
-
{{ __('Schema Information') }}
+
+
{{ __('Schema Information') }}
+