More work on displaying and editing an LDAP entry
This commit is contained in:
parent
d6f833f6eb
commit
4fd51abcb1
@ -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
|
||||
*
|
||||
@ -182,7 +172,13 @@ class Attribute
|
||||
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')
|
||||
->with('edit',$edit)
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Binary;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Binary;
|
||||
|
||||
/**
|
||||
@ -16,26 +18,11 @@ final class JpegPhoto extends Binary
|
||||
$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
|
||||
$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('<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;
|
||||
return view('components.attribute.binary.jpegphoto')
|
||||
->with('edit',$edit)
|
||||
->with('o',$this)
|
||||
->with('f',new \finfo);
|
||||
}
|
||||
}
|
@ -21,15 +21,16 @@ class Factory
|
||||
*/
|
||||
public const map = [
|
||||
'createtimestamp' => Internal\Timestamp::class,
|
||||
'creatorsname' => Internal\EntryDN::class,
|
||||
'entrycsn' => Internal\EntryCSN::class,
|
||||
'entrydn' => Internal\EntryDN::class,
|
||||
'entryuuid' => Internal\EntryUUID::class,
|
||||
'creatorsname' => Internal\DN::class,
|
||||
'contextcsn' => Internal\CSN::class,
|
||||
'entrycsn' => Internal\CSN::class,
|
||||
'entrydn' => Internal\DN::class,
|
||||
'entryuuid' => Internal\UUID::class,
|
||||
'gidnumber' => GidNumber::class,
|
||||
'hassubordinates' => Internal\HasSubordinates::class,
|
||||
'jpegphoto' => Binary\JpegPhoto::class,
|
||||
'modifytimestamp' => Internal\Timestamp::class,
|
||||
'modifiersname' => Internal\EntryDN::class,
|
||||
'modifiersname' => Internal\DN::class,
|
||||
'objectclass' => ObjectClass::class,
|
||||
'structuralobjectclass' => Internal\StructuralObjectClass::class,
|
||||
'subschemasubentry' => Internal\SubschemaSubentry::class,
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
@ -10,4 +12,11 @@ use App\Classes\LDAP\Attribute;
|
||||
abstract class Internal extends Attribute
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@ namespace 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
|
||||
{
|
||||
}
|
@ -5,8 +5,8 @@ namespace 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
|
||||
{
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
@ -11,8 +11,10 @@ use App\Classes\LDAP\Attribute\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);
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@ namespace 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
|
||||
{
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
@ -9,8 +11,19 @@ use App\Classes\LDAP\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);
|
||||
}
|
||||
}
|
@ -2,16 +2,19 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
.sprintf('<br><span class="btn btn-sm btn-outline-dark"><i class="fas fa-user-check"></i> %s</span>',__('Check Password'));
|
||||
return view('components.attribute.password')
|
||||
->with('edit',$edit)
|
||||
->with('o',$this);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
@ -47,4 +48,11 @@ abstract class Schema extends Attribute
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
@ -9,21 +11,6 @@ use App\Classes\LDAP\Attribute\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.
|
||||
* 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
|
||||
* @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);
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
{
|
||||
// @note Schema attributes cannot be edited
|
||||
return view('components.attribute.schema.mechanisms')
|
||||
->with('o',$this);
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
@ -9,25 +11,6 @@ use App\Classes\LDAP\Attribute\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.
|
||||
* This function parses ldap_supported_oids.txt and looks up the specified
|
||||
@ -46,8 +29,15 @@ final class OID extends Schema
|
||||
* @return string|null
|
||||
* @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);
|
||||
}
|
||||
|
||||
public function render(bool $edit=FALSE): View
|
||||
{
|
||||
// @note Schema attributes cannot be edited
|
||||
return view('components.attribute.schema.oid')
|
||||
->with('o',$this);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
"keywords": ["framework","laravel"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"ext-fileinfo": "*",
|
||||
"php": "^8.0.2",
|
||||
"directorytree/ldaprecord-laravel": "^2",
|
||||
"fideloper/proxy": "^4.4",
|
||||
|
6
resources/lang/README.md
Normal file
6
resources/lang/README.md
Normal 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
|
@ -1,3 +1,4 @@
|
||||
<!-- $o=Attribute::class -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div id="{{ $o->name_lc }}">
|
||||
|
@ -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>
|
5
resources/views/components/attribute/internal.blade.php
Normal file
5
resources/views/components/attribute/internal.blade.php
Normal 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
|
@ -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
|
24
resources/views/components/attribute/objectclass.blade.php
Normal file
24
resources/views/components/attribute/objectclass.blade.php
Normal 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>
|
18
resources/views/components/attribute/password.blade.php
Normal file
18
resources/views/components/attribute/password.blade.php
Normal 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>
|
@ -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>') !!}
|
11
resources/views/components/attribute/schema/oid.blade.php
Normal file
11
resources/views/components/attribute/schema/oid.blade.php
Normal 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>') !!}
|
@ -3,7 +3,7 @@
|
||||
@section('page_title')
|
||||
<table class="table table-borderless">
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -11,11 +11,11 @@
|
||||
<table>
|
||||
<tr>
|
||||
<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>
|
||||
<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>
|
||||
<td class="p-1 m-1">UUID</td>
|
||||
|
@ -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)
|
||||
: $attribute !!}
|
||||
</th>
|
||||
<td>{!! $ao !!}</td>
|
||||
<td>
|
||||
<x-attribute :edit="false" :o="$ao"/>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user