Minor schema cosmetic code fixes, more Attribute implementation from old pla, start of LDAP DN view/edit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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
|
||||
{
|
||||
}
|
@@ -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 = '<table class="table table-borderless p-0 m-0"><tr>';
|
||||
|
||||
foreach ($this->values as $value) {
|
||||
switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) {
|
||||
case 'image/jpeg':
|
||||
default:
|
||||
$result .= sprintf('<img class="jpegphoto" src="data:%s;base64, %s" />',$x,base64_encode($value));
|
||||
$result .= sprintf('<td><img class="jpegphoto" src="data:%s;base64, %s" />%s</td>',
|
||||
$x,
|
||||
base64_encode($value),
|
||||
$this->deletable ? sprintf('<br><span class="btn btn-sm btn-danger"><i class="fas fa-trash-alt"></i> %s</span>',__('Delete')) : '');
|
||||
}
|
||||
}
|
||||
|
||||
$result .= '</tr></table>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
13
app/Classes/LDAP/Attribute/Internal.php
Normal file
13
app/Classes/LDAP/Attribute/Internal.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are internal
|
||||
*/
|
||||
abstract class Internal extends Attribute
|
||||
{
|
||||
protected bool $internal = TRUE;
|
||||
}
|
12
app/Classes/LDAP/Attribute/Internal/EntryUUID.php
Normal file
12
app/Classes/LDAP/Attribute/Internal/EntryUUID.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
*/
|
||||
final class EntryUUID extends Internal
|
||||
{
|
||||
}
|
16
app/Classes/LDAP/Attribute/ObjectClass.php
Normal file
16
app/Classes/LDAP/Attribute/ObjectClass.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are jpeg pictures
|
||||
*/
|
||||
final class ObjectClass extends Attribute
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->values->sort()->join('<br>');
|
||||
}
|
||||
}
|
50
app/Classes/LDAP/Attribute/Schema.php
Normal file
50
app/Classes/LDAP/Attribute/Schema.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are schema related
|
||||
*/
|
||||
abstract class Schema extends Attribute
|
||||
{
|
||||
protected bool $internal = TRUE;
|
||||
|
||||
protected static function _get(string $filename,string $string,string $key): ?string
|
||||
{
|
||||
$array = Cache::remember($filename,86400,function() use ($filename) {
|
||||
try {
|
||||
$f = fopen($filename,'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);
|
||||
}
|
||||
}
|
@@ -1,16 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
namespace App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
*/
|
||||
class Mechanisms extends Attribute
|
||||
final class Mechanisms extends Schema
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
@@ -44,37 +41,8 @@ class Mechanisms extends Attribute
|
||||
* @param string $key The title|ref|desc to return
|
||||
* @return string|NULL
|
||||
*/
|
||||
private static function get(string $string,string $key): ?string
|
||||
protected static function get(string $string,string $key): ?string
|
||||
{
|
||||
$array = Cache::remember('saslmechanisms',86400,function() {
|
||||
try {
|
||||
$f = fopen(config_path('ldap_supported_saslmechanisms.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_saslmechanisms.txt'),$string,$key);
|
||||
}
|
||||
}
|
@@ -1,16 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
namespace App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
*/
|
||||
class OID extends Attribute
|
||||
final class OID extends Schema
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
@@ -44,42 +41,13 @@ class OID extends Attribute
|
||||
* ]
|
||||
* </code>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user