Minor schema cosmetic code fixes, more Attribute implementation from old pla, start of LDAP DN view/edit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user