More work on displaying and editing an LDAP entry

This commit is contained in:
Deon George 2023-04-02 22:07:15 +10:00
parent d6f833f6eb
commit 4fd51abcb1
25 changed files with 194 additions and 91 deletions

View File

@ -144,16 +144,6 @@ class Attribute
}; };
} }
/**
* Determine how we render this attribute's value
*
* @return string
*/
public function __toString(): string
{
return $this->values->join('<br>');
}
/** /**
* Return the hints about this attribute, ie: RDN, Required, etc * Return the hints about this attribute, ie: RDN, Required, etc
* *
@ -182,7 +172,13 @@ class Attribute
return $result->toArray(); return $result->toArray();
} }
public function render(bool $edit): View /**
* Display the attribute value
*
* @param bool $edit
* @return View
*/
public function render(bool $edit=FALSE): View
{ {
return view('components.attribute') return view('components.attribute')
->with('edit',$edit) ->with('edit',$edit)

View File

@ -2,6 +2,8 @@
namespace App\Classes\LDAP\Attribute\Binary; namespace App\Classes\LDAP\Attribute\Binary;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute\Binary; use App\Classes\LDAP\Attribute\Binary;
/** /**
@ -16,26 +18,11 @@ final class JpegPhoto extends Binary
$this->internal = FALSE; $this->internal = FALSE;
} }
public function __toString(): string public function render(bool $edit=FALSE): View
{ {
// We'll use finfo to try and figure out what type of image is stored return view('components.attribute.binary.jpegphoto')
$f = new \finfo; ->with('edit',$edit)
->with('o',$this)
$result = '<table class="table table-borderless p-0 m-0"><tr>'; ->with('f',new \finfo);
foreach ($this->values as $value) {
switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) {
case 'image/jpeg':
default:
$result .= sprintf('<td><img class="jpegphoto" src="data:%s;base64, %s" />%s</td>',
$x,
base64_encode($value),
$this->is_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;
} }
} }

View File

@ -21,15 +21,16 @@ class Factory
*/ */
public const map = [ public const map = [
'createtimestamp' => Internal\Timestamp::class, 'createtimestamp' => Internal\Timestamp::class,
'creatorsname' => Internal\EntryDN::class, 'creatorsname' => Internal\DN::class,
'entrycsn' => Internal\EntryCSN::class, 'contextcsn' => Internal\CSN::class,
'entrydn' => Internal\EntryDN::class, 'entrycsn' => Internal\CSN::class,
'entryuuid' => Internal\EntryUUID::class, 'entrydn' => Internal\DN::class,
'entryuuid' => Internal\UUID::class,
'gidnumber' => GidNumber::class, 'gidnumber' => GidNumber::class,
'hassubordinates' => Internal\HasSubordinates::class, 'hassubordinates' => Internal\HasSubordinates::class,
'jpegphoto' => Binary\JpegPhoto::class, 'jpegphoto' => Binary\JpegPhoto::class,
'modifytimestamp' => Internal\Timestamp::class, 'modifytimestamp' => Internal\Timestamp::class,
'modifiersname' => Internal\EntryDN::class, 'modifiersname' => Internal\DN::class,
'objectclass' => ObjectClass::class, 'objectclass' => ObjectClass::class,
'structuralobjectclass' => Internal\StructuralObjectClass::class, 'structuralobjectclass' => Internal\StructuralObjectClass::class,
'subschemasubentry' => Internal\SubschemaSubentry::class, 'subschemasubentry' => Internal\SubschemaSubentry::class,

View File

@ -2,6 +2,8 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
/** /**
@ -10,4 +12,11 @@ use App\Classes\LDAP\Attribute;
abstract class Internal extends Attribute abstract class Internal extends Attribute
{ {
protected bool $is_internal = TRUE; protected bool $is_internal = TRUE;
public function render(bool $edit=FALSE): View
{
// @note Internal attributes cannot be edited
return view('components.attribute.internal')
->with('o',$this);
}
} }

View File

@ -5,8 +5,8 @@ namespace App\Classes\LDAP\Attribute\Internal;
use App\Classes\LDAP\Attribute\Internal; use App\Classes\LDAP\Attribute\Internal;
/** /**
* Represents an EntryDN Attribute * Represents an CSN Attribute
*/ */
final class EntryDN extends Internal final class CSN extends Internal
{ {
} }

View File

@ -5,8 +5,8 @@ namespace App\Classes\LDAP\Attribute\Internal;
use App\Classes\LDAP\Attribute\Internal; use App\Classes\LDAP\Attribute\Internal;
/** /**
* Represents an EntryCSN Attribute * Represents an DN Attribute
*/ */
final class EntryCSN extends Internal final class DN extends Internal
{ {
} }

View File

@ -2,7 +2,7 @@
namespace App\Classes\LDAP\Attribute\Internal; namespace App\Classes\LDAP\Attribute\Internal;
use Carbon\Carbon; use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute\Internal; use App\Classes\LDAP\Attribute\Internal;
@ -11,8 +11,10 @@ use App\Classes\LDAP\Attribute\Internal;
*/ */
final class Timestamp extends Internal final class Timestamp extends Internal
{ {
public function __toString(): string public function render(bool $edit=FALSE): View
{ {
return Carbon::createFromTimestamp(strtotime($this->values[0]))->format(config('ldap.datetime_format','Y-m-d H:i:s')); // @note Internal attributes cannot be edited
return view('components.attribute.internal.timestamp')
->with('o',$this);
} }
} }

View File

@ -5,8 +5,8 @@ namespace App\Classes\LDAP\Attribute\Internal;
use App\Classes\LDAP\Attribute\Internal; use App\Classes\LDAP\Attribute\Internal;
/** /**
* Represents an EntryUUID Attribute * Represents an UUID Attribute
*/ */
final class EntryUUID extends Internal final class UUID extends Internal
{ {
} }

View File

@ -2,6 +2,8 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
/** /**
@ -9,8 +11,19 @@ use App\Classes\LDAP\Attribute;
*/ */
final class ObjectClass extends Attribute final class ObjectClass extends Attribute
{ {
public function __toString(): string public function __get(string $key): mixed
{ {
return $this->values->sort()->join('<br>'); switch ($key) {
case 'is_structural': return FALSE; // @todo - need to determine which of the values is the structural objectclass value(s)
default:
return parent::__get($key);
}
}
public function render(bool $edit=FALSE): View
{
return view('components.attribute.objectclass')
->with('edit',$edit)
->with('o',$this);
} }
} }

View File

@ -2,16 +2,19 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute; use App\Classes\LDAP\Attribute;
/** /**
* Represents an attribute whose values are passwords * Represents an attribute whose values are passwords
*/ */
class Password extends Attribute final class Password extends Attribute
{ {
public function __toString(): string public function render(bool $edit=FALSE): View
{ {
return str_repeat('*',10) return view('components.attribute.password')
.sprintf('<br><span class="btn btn-sm btn-outline-dark"><i class="fas fa-user-check"></i> %s</span>',__('Check Password')); ->with('edit',$edit)
->with('o',$this);
} }
} }

View File

@ -2,6 +2,7 @@
namespace App\Classes\LDAP\Attribute; namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
@ -47,4 +48,11 @@ abstract class Schema extends Attribute
return Arr::get(($array ? $array->get($string) : []),$key); return Arr::get(($array ? $array->get($string) : []),$key);
} }
public function render(bool $edit=FALSE): View
{
// @note Schema attributes cannot be edited
return view('components.attribute.internal')
->with('o',$this);
}
} }

View File

@ -2,6 +2,8 @@
namespace App\Classes\LDAP\Attribute\Schema; namespace App\Classes\LDAP\Attribute\Schema;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute\Schema; use App\Classes\LDAP\Attribute\Schema;
/** /**
@ -9,21 +11,6 @@ use App\Classes\LDAP\Attribute\Schema;
*/ */
final class Mechanisms extends Schema final class Mechanisms extends Schema
{ {
public function __toString(): string
{
return $this->values
->transform(function($item) {
$format = sprintf('<abbr class="pb-1" title="%s"><i class="fas fa-book pe-2"></i>%s</abbr>%s<p class="mb-0">%s</p>',
$item,
static::get($item,'title'),
($x=static::get($item,'ref')) ? sprintf('<abbr class="ps-2" title="%s"><i class="fas fa-comment-dots"></i></abbr>',$x) : '',
static::get($item,'desc'),
);
return $format;
})->join('<br>');
}
/** /**
* Given an SASL Mechanism name, returns a verbose description of the Mechanism. * Given an SASL Mechanism name, returns a verbose description of the Mechanism.
* This function parses ldap_supported_saslmechanisms.txt and looks up the specified * This function parses ldap_supported_saslmechanisms.txt and looks up the specified
@ -41,8 +28,15 @@ final class Mechanisms extends Schema
* @param string $key The title|ref|desc to return * @param string $key The title|ref|desc to return
* @return string|NULL * @return string|NULL
*/ */
protected static function get(string $string,string $key): ?string public static function get(string $string,string $key): ?string
{ {
return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key); return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key);
} }
public function render(bool $edit=FALSE): View
{
// @note Schema attributes cannot be edited
return view('components.attribute.schema.mechanisms')
->with('o',$this);
}
} }

View File

@ -2,6 +2,8 @@
namespace App\Classes\LDAP\Attribute\Schema; namespace App\Classes\LDAP\Attribute\Schema;
use Illuminate\Contracts\View\View;
use App\Classes\LDAP\Attribute\Schema; use App\Classes\LDAP\Attribute\Schema;
/** /**
@ -9,25 +11,6 @@ use App\Classes\LDAP\Attribute\Schema;
*/ */
final class OID extends Schema final class OID extends Schema
{ {
public function __toString(): string
{
return $this->values
->transform(function($item) {
if (preg_match('/[0-9]+\.[0-9]+\.[0-9]+/',$item)) {
$format = sprintf('<abbr class="pb-1" title="%s"><i class="fas fa-list-ol pe-2"></i>%s</abbr>%s<p class="mb-0">%s</p>',
$item,
static::get($item,'title'),
($x=static::get($item,'ref')) ? sprintf('<abbr class="ps-2" title="%s"><i class="fas fa-comment-dots"></i></abbr>',$x) : '',
static::get($item,'desc'),
);
return $format;
} else
return $item;
})->join('<br>');
}
/** /**
* Given an LDAP OID number, returns a verbose description of the OID. * Given an LDAP OID number, returns a verbose description of the OID.
* This function parses ldap_supported_oids.txt and looks up the specified * This function parses ldap_supported_oids.txt and looks up the specified
@ -46,8 +29,15 @@ final class OID extends Schema
* @return string|null * @return string|null
* @testedby TranslateOidTest::testRootDSE() * @testedby TranslateOidTest::testRootDSE()
*/ */
protected static function get(string $string,string $key): ?string public static function get(string $string,string $key): ?string
{ {
return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key); return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key);
} }
public function render(bool $edit=FALSE): View
{
// @note Schema attributes cannot be edited
return view('components.attribute.schema.oid')
->with('o',$this);
}
} }

View File

@ -5,6 +5,7 @@
"keywords": ["framework","laravel"], "keywords": ["framework","laravel"],
"license": "MIT", "license": "MIT",
"require": { "require": {
"ext-fileinfo": "*",
"php": "^8.0.2", "php": "^8.0.2",
"directorytree/ldaprecord-laravel": "^2", "directorytree/ldaprecord-laravel": "^2",
"fideloper/proxy": "^4.4", "fideloper/proxy": "^4.4",

6
resources/lang/README.md Normal file
View File

@ -0,0 +1,6 @@
This directory contains language translation files for PLA.
Language files named by 2 letter iso language name (suffixed with .json)
represent the translations for that language.
eg: en.json

View File

@ -1,3 +1,4 @@
<!-- $o=Attribute::class -->
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">

View File

@ -0,0 +1,18 @@
<!-- $o=Binary\JpegPhoto::class -->
<table class="table table-borderless p-0 m-0">
<tr>
@foreach ($o->values as $value)
@switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE))
@case('image/jpeg')
@default
<td>
<img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" />
@if($edit)
<br><span class="btn btn-sm btn-danger"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
@endif
</td>
@endswitch
@endforeach
</tr>
</table>

View File

@ -0,0 +1,5 @@
<!-- $o=Internal\Timestamp::class -->
@foreach (old($o->name_lc,$o->values) as $value)
@if($loop->index)<br>@endif
{{ $value }}
@endforeach

View File

@ -0,0 +1,5 @@
<!-- $o=Internal\Timestamp::class -->
@foreach (old($o->name_lc,$o->values) as $value)
@if($loop->index)<br>@endif
{{ \Carbon\Carbon::createFromTimestamp(strtotime($value))->format(config('ldap.datetime_format','Y-m-d H:i:s')) }}
@endforeach

View File

@ -0,0 +1,24 @@
<!-- $o=Attribute::class -->
<div class="row">
<div class="col-12">
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_structural)
<input class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-danger @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" @if($x)placeholder="{{ Arr::get($o->values,$loop->index) }}"@endif>
@else
{{ $value }}@if ($o->is_structural)@lang('structural')@endif<br>
@endif
@endforeach
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4">
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3 mb-3"><i class="fas fa-fw fa-exchange"></i> {{ __('Rename') }}</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0 addable" id="{{ $o->name_lc }}">
<span class="btn btn-sm btn-outline-primary mt-3 mb-3"><i class="fas fa-fw fa-plus"></i> {{ __('Add Value') }}</span>
</div>
@endif
</div>
</div>

View File

@ -0,0 +1,18 @@
<!-- $o=Password::class -->
<div class="row">
<div class="col-12">
<div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value)
@if ($edit)
<input type="password" class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-danger @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ str_repeat('*',10) }}">
@else
{{ $value }}<br>
@endif
@endforeach
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4">
<span class="btn btn-sm btn-outline-dark mt-3 mb-3"><i class="fas fa-user-check"></i> @lang('Check Password')</span>
</div>
</div>

View File

@ -0,0 +1,9 @@
{!! $o->values
->transform(function($item) use ($o) {
return sprintf('<abbr class="pb-1" title="%s"><i class="fas fa-book pe-2"></i>%s</abbr>%s<p class="mb-0">%s</p>',
$item,
$o->get($item,'title'),
($x=$o->get($item,'ref')) ? sprintf('<abbr class="ps-2" title="%s"><i class="fas fa-comment-dots"></i></abbr>',$x) : '',
$o->get($item,'desc'),
);
})->join('<br>') !!}

View File

@ -0,0 +1,11 @@
{!! $o->values
->transform(function($item) use ($o) {
return preg_match('/[0-9]+\.[0-9]+\.[0-9]+/',$item)
? sprintf('<abbr class="pb-1" title="%s"><i class="fas fa-list-ol pe-2"></i>%s</abbr>%s<p class="mb-0">%s</p>',
$item,
$o->get($item,'title'),
($x=$o->get($item,'ref')) ? sprintf('<abbr class="ps-2" title="%s"><i class="fas fa-comment-dots"></i></abbr>',$x) : '',
$o->get($item,'desc'),
)
: $item;
})->join('<br>') !!}

View File

@ -3,7 +3,7 @@
@section('page_title') @section('page_title')
<table class="table table-borderless"> <table class="table table-borderless">
<tr> <tr>
<td class="{{ ($x=Arr::get($o->getAttributes(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ?: sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td> <td class="{{ ($x=Arr::get($o->getAttributes(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td> <td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td>
</tr> </tr>
<tr> <tr>
@ -11,11 +11,11 @@
<table> <table>
<tr> <tr>
<td class="p-1 m-1">Created</td> <td class="p-1 m-1">Created</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x : __('Unknown') }}]</th> <th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x->render() : __('Unknown') }}]</th>
</tr> </tr>
<tr> <tr>
<td class="p-1 m-1">Modified</td> <td class="p-1 m-1">Modified</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x : __('Unknown') }}]</th> <th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x->render() : __('Unknown') }}]</th>
</tr> </tr>
<tr> <tr>
<td class="p-1 m-1">UUID</td> <td class="p-1 m-1">UUID</td>

View File

@ -19,7 +19,9 @@
? sprintf('<a class="attributetype" id="strtolower(%s)" href="%s">%s</a>',$x->name_lc,url('schema/attributetypes',$x->name_lc),$x->name) ? sprintf('<a class="attributetype" id="strtolower(%s)" href="%s">%s</a>',$x->name_lc,url('schema/attributetypes',$x->name_lc),$x->name)
: $attribute !!} : $attribute !!}
</th> </th>
<td>{!! $ao !!}</td> <td>
<x-attribute :edit="false" :o="$ao"/>
</td>
</tr> </tr>
@endforeach @endforeach
</table> </table>