Render HTML inputs for a DN with language tags - work for #16
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Classes\LDAP\Schema\AttributeType;
|
||||
use App\Ldap\Entry;
|
||||
|
||||
/**
|
||||
* Represents an attribute of an LDAP Object
|
||||
@@ -100,9 +101,9 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
{
|
||||
$this->dn = $dn;
|
||||
$this->name = $name;
|
||||
$this->values_old = collect($values);
|
||||
$this->_values = collect($values);
|
||||
$this->_values_old = collect($values);
|
||||
|
||||
$this->values = collect();
|
||||
$this->oc = collect($oc);
|
||||
|
||||
$this->schema = (new Server)
|
||||
@@ -149,15 +150,15 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
// Used in Object Classes
|
||||
'used_in' => $this->schema?->used_in_object_classes ?: collect(),
|
||||
// The current attribute values
|
||||
'values' => $this->no_attr_tags ? collect($this->_values->first()) : $this->_values,
|
||||
'values' => $this->no_attr_tags ? $this->tagValues() : $this->_values,
|
||||
// The original attribute values
|
||||
'values_old' => $this->no_attr_tags ? collect($this->_values_old->first()) : $this->_values_old,
|
||||
'values_old' => $this->no_attr_tags ? $this->tagValuesOld() : $this->_values_old,
|
||||
|
||||
default => throw new \Exception('Unknown key:' . $key),
|
||||
};
|
||||
}
|
||||
|
||||
public function __set(string $key,mixed $values)
|
||||
public function __set(string $key,mixed $values): void
|
||||
{
|
||||
switch ($key) {
|
||||
case 'values':
|
||||
@@ -320,14 +321,14 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
->with('new',$new);
|
||||
}
|
||||
|
||||
public function render_item_old(int $key): ?string
|
||||
public function render_item_old(string $dotkey): ?string
|
||||
{
|
||||
return Arr::get($this->values_old,$key);
|
||||
return Arr::get($this->_values_old->dot(),$dotkey);
|
||||
}
|
||||
|
||||
public function render_item_new(int $key): ?string
|
||||
public function render_item_new(string $dotkey): ?string
|
||||
{
|
||||
return Arr::get($this->values,$key);
|
||||
return Arr::get($this->_values->dot(),$dotkey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,17 +344,17 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
: collect();
|
||||
}
|
||||
|
||||
public function tagValues(string $tag=''): Collection
|
||||
public function tagValues(string $tag=Entry::TAG_NOTAG): Collection
|
||||
{
|
||||
return $this->_values
|
||||
->filter(fn($item,$key)=>($key === $tag))
|
||||
->values();
|
||||
return collect($this->_values
|
||||
->filter(fn($item,$key)=>($key===$tag))
|
||||
->get($tag,[]));
|
||||
}
|
||||
|
||||
public function tagValuesOld(string $tag=''): Collection
|
||||
public function tagValuesOld(string $tag=Entry::TAG_NOTAG): Collection
|
||||
{
|
||||
return $this->_values_old
|
||||
->filter(fn($item,$key)=>($key === $tag))
|
||||
->values();
|
||||
return collect($this->_values_old
|
||||
->filter(fn($item,$key)=>($key===$tag))
|
||||
->get($tag,[]));
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ namespace App\Classes\LDAP\Attribute\Binary;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Binary;
|
||||
use App\Ldap\Entry;
|
||||
use App\Traits\MD5Updates;
|
||||
|
||||
/**
|
||||
@@ -14,13 +15,14 @@ final class JpegPhoto extends Binary
|
||||
{
|
||||
use MD5Updates;
|
||||
|
||||
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
|
||||
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE,string $langtag=Entry::TAG_NOTAG): View
|
||||
{
|
||||
return view('components.attribute.binary.jpegphoto')
|
||||
->with('o',$this)
|
||||
->with('edit',$edit)
|
||||
->with('old',$old)
|
||||
->with('new',$new)
|
||||
->with('langtag',$langtag)
|
||||
->with('f',new \finfo);
|
||||
}
|
||||
}
|
@@ -26,18 +26,16 @@ final class KrbPrincipalKey extends Attribute
|
||||
->with('new',$new);
|
||||
}
|
||||
|
||||
public function render_item_old(int $key): ?string
|
||||
public function render_item_old(string $dotkey): ?string
|
||||
{
|
||||
$pw = Arr::get($this->values_old,$key);
|
||||
return $pw
|
||||
return parent::render_item_old($dotkey)
|
||||
? str_repeat('*',16)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
public function render_item_new(int $key): ?string
|
||||
public function render_item_new(string $dotkey): ?string
|
||||
{
|
||||
$pw = Arr::get($this->values,$key);
|
||||
return $pw
|
||||
return parent::render_item_new($dotkey)
|
||||
? str_repeat('*',16)
|
||||
: NULL;
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose value is a Kerberos Ticket Flag
|
||||
|
@@ -29,19 +29,33 @@ final class ObjectClass extends Attribute
|
||||
{
|
||||
parent::__construct($dn,$name,$values,['top']);
|
||||
|
||||
$this->oc_schema = config('server')
|
||||
->schema('objectclasses')
|
||||
->filter(fn($item)=>$this->values_old->contains($item->name));
|
||||
$this->set_oc_schema($this->tagValuesOld());
|
||||
}
|
||||
|
||||
public function __get(string $key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'structural' => $this->oc_schema->filter(fn($item) => $item->isStructural()),
|
||||
'structural' => $this->oc_schema->filter(fn($item)=>$item->isStructural()),
|
||||
default => parent::__get($key),
|
||||
};
|
||||
}
|
||||
|
||||
public function __set(string $key,mixed $values): void
|
||||
{
|
||||
switch ($key) {
|
||||
case 'values':
|
||||
parent::__set($key,$values);
|
||||
|
||||
// We need to populate oc_schema, if we are a new OC and thus dont have any old values
|
||||
if (! $this->values_old->count() && $this->values->count())
|
||||
$this->set_oc_schema($this->tagValues());
|
||||
|
||||
break;
|
||||
|
||||
default: parent::__set($key,$values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a specific value the structural objectclass
|
||||
*
|
||||
@@ -63,4 +77,11 @@ final class ObjectClass extends Attribute
|
||||
->with('old',$old)
|
||||
->with('new',$new);
|
||||
}
|
||||
|
||||
private function set_oc_schema(Collection $tv): void
|
||||
{
|
||||
$this->oc_schema = config('server')
|
||||
->schema('objectclasses')
|
||||
->filter(fn($item)=>$tv->contains($item->name));
|
||||
}
|
||||
}
|
@@ -88,19 +88,23 @@ final class Password extends Attribute
|
||||
->with('helpers',static::helpers()->map(fn($item,$key)=>['id'=>$key,'value'=>$key])->sort());
|
||||
}
|
||||
|
||||
public function render_item_old(int $key): ?string
|
||||
public function render_item_old(string $dotkey): ?string
|
||||
{
|
||||
$pw = Arr::get($this->values_old,$key);
|
||||
$pw = parent::render_item_old($dotkey);
|
||||
|
||||
return $pw
|
||||
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16))
|
||||
? (((($x=$this->hash($pw)) && ($x::id() === '*clear*')) ? sprintf('{%s}',$x::shortid()) : '')
|
||||
.str_repeat('*',16))
|
||||
: NULL;
|
||||
}
|
||||
|
||||
public function render_item_new(int $key): ?string
|
||||
public function render_item_new(string $dotkey): ?string
|
||||
{
|
||||
$pw = Arr::get($this->values,$key);
|
||||
$pw = parent::render_item_new($dotkey);
|
||||
|
||||
return $pw
|
||||
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16))
|
||||
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '')
|
||||
.str_repeat('*',16))
|
||||
: NULL;
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ namespace App\Classes\LDAP\Export;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Classes\LDAP\Export;
|
||||
use App\Ldap\Entry;
|
||||
|
||||
/**
|
||||
* Export from LDAP using an LDIF format
|
||||
@@ -55,8 +56,8 @@ class LDIF extends Export
|
||||
foreach ($tagvalues as $value) {
|
||||
$result .= $this->multiLineDisplay(
|
||||
Str::isAscii($value)
|
||||
? sprintf('%s: %s',$ao->name.($tag ? ';'.$tag : ''),$value)
|
||||
: sprintf('%s:: %s',$ao->name.($tag ? ';'.$tag : ''),base64_encode($value))
|
||||
? sprintf('%s: %s',$ao->name.(($tag !== Entry::TAG_NOTAG) ? ';'.$tag : ''),$value)
|
||||
: sprintf('%s:: %s',$ao->name.(($tag !== Entry::TAG_NOTAG) ? ';'.$tag : ''),base64_encode($value))
|
||||
,$this->br);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user