Skip to content

Commit cf53528

Browse files
committed
Render HTML inputs for a DN with language tags - work for #16
1 parent 633513d commit cf53528

25 files changed

+244
-200
lines changed

app/Classes/LDAP/Attribute.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Collection;
88

99
use App\Classes\LDAP\Schema\AttributeType;
10+
use App\Ldap\Entry;
1011

1112
/**
1213
* Represents an attribute of an LDAP Object
@@ -100,9 +101,9 @@ public function __construct(string $dn,string $name,array $values,array $oc=[])
100101
{
101102
$this->dn = $dn;
102103
$this->name = $name;
103-
$this->values_old = collect($values);
104+
$this->_values = collect($values);
105+
$this->_values_old = collect($values);
104106

105-
$this->values = collect();
106107
$this->oc = collect($oc);
107108

108109
$this->schema = (new Server)
@@ -149,15 +150,15 @@ public function __get(string $key): mixed
149150
// Used in Object Classes
150151
'used_in' => $this->schema?->used_in_object_classes ?: collect(),
151152
// The current attribute values
152-
'values' => $this->no_attr_tags ? collect($this->_values->first()) : $this->_values,
153+
'values' => $this->no_attr_tags ? $this->tagValues() : $this->_values,
153154
// The original attribute values
154-
'values_old' => $this->no_attr_tags ? collect($this->_values_old->first()) : $this->_values_old,
155+
'values_old' => $this->no_attr_tags ? $this->tagValuesOld() : $this->_values_old,
155156

156157
default => throw new \Exception('Unknown key:' . $key),
157158
};
158159
}
159160

160-
public function __set(string $key,mixed $values)
161+
public function __set(string $key,mixed $values): void
161162
{
162163
switch ($key) {
163164
case 'values':
@@ -320,14 +321,14 @@ public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
320321
->with('new',$new);
321322
}
322323

323-
public function render_item_old(int $key): ?string
324+
public function render_item_old(string $dotkey): ?string
324325
{
325-
return Arr::get($this->values_old,$key);
326+
return Arr::get($this->_values_old->dot(),$dotkey);
326327
}
327328

328-
public function render_item_new(int $key): ?string
329+
public function render_item_new(string $dotkey): ?string
329330
{
330-
return Arr::get($this->values,$key);
331+
return Arr::get($this->_values->dot(),$dotkey);
331332
}
332333

333334
/**
@@ -343,17 +344,17 @@ public function required(): Collection
343344
: collect();
344345
}
345346

346-
public function tagValues(string $tag=''): Collection
347+
public function tagValues(string $tag=Entry::TAG_NOTAG): Collection
347348
{
348-
return $this->_values
349-
->filter(fn($item,$key)=>($key === $tag))
350-
->values();
349+
return collect($this->_values
350+
->filter(fn($item,$key)=>($key===$tag))
351+
->get($tag,[]));
351352
}
352353

353-
public function tagValuesOld(string $tag=''): Collection
354+
public function tagValuesOld(string $tag=Entry::TAG_NOTAG): Collection
354355
{
355-
return $this->_values_old
356-
->filter(fn($item,$key)=>($key === $tag))
357-
->values();
356+
return collect($this->_values_old
357+
->filter(fn($item,$key)=>($key===$tag))
358+
->get($tag,[]));
358359
}
359360
}

app/Classes/LDAP/Attribute/Binary/JpegPhoto.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Contracts\View\View;
66

77
use App\Classes\LDAP\Attribute\Binary;
8+
use App\Ldap\Entry;
89
use App\Traits\MD5Updates;
910

1011
/**
@@ -14,13 +15,14 @@ final class JpegPhoto extends Binary
1415
{
1516
use MD5Updates;
1617

17-
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
18+
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE,string $langtag=Entry::TAG_NOTAG): View
1819
{
1920
return view('components.attribute.binary.jpegphoto')
2021
->with('o',$this)
2122
->with('edit',$edit)
2223
->with('old',$old)
2324
->with('new',$new)
25+
->with('langtag',$langtag)
2426
->with('f',new \finfo);
2527
}
2628
}

app/Classes/LDAP/Attribute/KrbPrincipalKey.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
2626
->with('new',$new);
2727
}
2828

29-
public function render_item_old(int $key): ?string
29+
public function render_item_old(string $dotkey): ?string
3030
{
31-
$pw = Arr::get($this->values_old,$key);
32-
return $pw
31+
return parent::render_item_old($dotkey)
3332
? str_repeat('*',16)
3433
: NULL;
3534
}
3635

37-
public function render_item_new(int $key): ?string
36+
public function render_item_new(string $dotkey): ?string
3837
{
39-
$pw = Arr::get($this->values,$key);
40-
return $pw
38+
return parent::render_item_new($dotkey)
4139
? str_repeat('*',16)
4240
: NULL;
4341
}

app/Classes/LDAP/Attribute/KrbTicketFlags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace App\Classes\LDAP\Attribute;
44

55
use Illuminate\Contracts\View\View;
6+
use Illuminate\Support\Collection;
67

78
use App\Classes\LDAP\Attribute;
8-
use Illuminate\Support\Collection;
99

1010
/**
1111
* Represents an attribute whose value is a Kerberos Ticket Flag

app/Classes/LDAP/Attribute/ObjectClass.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,33 @@ public function __construct(string $dn,string $name,array $values,array $oc=[])
2929
{
3030
parent::__construct($dn,$name,$values,['top']);
3131

32-
$this->oc_schema = config('server')
33-
->schema('objectclasses')
34-
->filter(fn($item)=>$this->values_old->contains($item->name));
32+
$this->set_oc_schema($this->tagValuesOld());
3533
}
3634

3735
public function __get(string $key): mixed
3836
{
3937
return match ($key) {
40-
'structural' => $this->oc_schema->filter(fn($item) => $item->isStructural()),
38+
'structural' => $this->oc_schema->filter(fn($item)=>$item->isStructural()),
4139
default => parent::__get($key),
4240
};
4341
}
4442

43+
public function __set(string $key,mixed $values): void
44+
{
45+
switch ($key) {
46+
case 'values':
47+
parent::__set($key,$values);
48+
49+
// We need to populate oc_schema, if we are a new OC and thus dont have any old values
50+
if (! $this->values_old->count() && $this->values->count())
51+
$this->set_oc_schema($this->tagValues());
52+
53+
break;
54+
55+
default: parent::__set($key,$values);
56+
}
57+
}
58+
4559
/**
4660
* Is a specific value the structural objectclass
4761
*
@@ -63,4 +77,11 @@ public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
6377
->with('old',$old)
6478
->with('new',$new);
6579
}
80+
81+
private function set_oc_schema(Collection $tv): void
82+
{
83+
$this->oc_schema = config('server')
84+
->schema('objectclasses')
85+
->filter(fn($item)=>$tv->contains($item->name));
86+
}
6687
}

app/Classes/LDAP/Attribute/Password.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,23 @@ public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
8888
->with('helpers',static::helpers()->map(fn($item,$key)=>['id'=>$key,'value'=>$key])->sort());
8989
}
9090

91-
public function render_item_old(int $key): ?string
91+
public function render_item_old(string $dotkey): ?string
9292
{
93-
$pw = Arr::get($this->values_old,$key);
93+
$pw = parent::render_item_old($dotkey);
94+
9495
return $pw
95-
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16))
96+
? (((($x=$this->hash($pw)) && ($x::id() === '*clear*')) ? sprintf('{%s}',$x::shortid()) : '')
97+
.str_repeat('*',16))
9698
: NULL;
9799
}
98100

99-
public function render_item_new(int $key): ?string
101+
public function render_item_new(string $dotkey): ?string
100102
{
101-
$pw = Arr::get($this->values,$key);
103+
$pw = parent::render_item_new($dotkey);
104+
102105
return $pw
103-
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '').str_repeat('*',16))
106+
? (((($x=$this->hash($pw)) && ($x::id() !== '*clear*')) ? sprintf('{%s}',$x::shortid()) : '')
107+
.str_repeat('*',16))
104108
: NULL;
105109
}
106110
}

app/Classes/LDAP/Export/LDIF.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Str;
66

77
use App\Classes\LDAP\Export;
8+
use App\Ldap\Entry;
89

910
/**
1011
* Export from LDAP using an LDIF format
@@ -55,8 +56,8 @@ public function __toString(): string
5556
foreach ($tagvalues as $value) {
5657
$result .= $this->multiLineDisplay(
5758
Str::isAscii($value)
58-
? sprintf('%s: %s',$ao->name.($tag ? ';'.$tag : ''),$value)
59-
: sprintf('%s:: %s',$ao->name.($tag ? ';'.$tag : ''),base64_encode($value))
59+
? sprintf('%s: %s',$ao->name.(($tag !== Entry::TAG_NOTAG) ? ';'.$tag : ''),$value)
60+
: sprintf('%s:: %s',$ao->name.(($tag !== Entry::TAG_NOTAG) ? ';'.$tag : ''),base64_encode($value))
6061
,$this->br);
6162
}
6263
}

app/Http/Controllers/HomeController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public function entry_add(EntryAddRequest $request): \Illuminate\View\View
5858
$o = new Entry;
5959

6060
if (count(array_filter($x=old('objectclass',$request->objectclass)))) {
61-
$o->objectclass = $x;
61+
$o->objectclass = [Entry::TAG_NOTAG=>$x];
6262

6363
foreach($o->getAvailableAttributes()->filter(fn($item)=>$item->required) as $ao)
64-
$o->{$ao->name} = '';
64+
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
6565

6666
$o->setRDNBase($key['dn']);
6767
}
@@ -188,8 +188,6 @@ public function entry_export(Request $request,string $id): \Illuminate\View\View
188188

189189
$result = (new Entry)
190190
->query()
191-
//->cache(Carbon::now()->addSeconds(Config::get('ldap.cache.time')))
192-
//->select(['*'])
193191
->setDn($dn)
194192
->recursive()
195193
->get();

0 commit comments

Comments
 (0)