diff --git a/app/Classes/LDAP/Export/LDIF.php b/app/Classes/LDAP/Export/LDIF.php index 873f37fd..3e37517e 100644 --- a/app/Classes/LDAP/Export/LDIF.php +++ b/app/Classes/LDAP/Export/LDIF.php @@ -41,12 +41,14 @@ class LDIF extends Export // Display Attributes foreach ($o->getObjects() as $ao) { - foreach ($ao->values as $value) { - $result .= $this->multiLineDisplay( - Str::isAscii($value) - ? sprintf('%s: %s',$ao->name,$value) - : sprintf('%s:: %s',$ao->name,base64_encode($value)) - ,$this->br); + foreach ($ao->values as $tag => $tagvalues) { + 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)) + ,$this->br); + } } } } diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index e9653785..2cdd05ba 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -179,34 +179,34 @@ class Entry extends Model $result = collect(); $entry_oc = Arr::get($this->attributes,'objectclass',[]); - foreach ($this->attributes as $attribute => $values) { + foreach ($this->attributes as $attrtag => $values) { // If the attribute name has tags $matches = []; - if (preg_match('/^([a-zA-Z]+)(;([a-zA-Z-;]+))+/',$attribute,$matches)) { + if (preg_match('/^([a-zA-Z]+);+([a-zA-Z-;]+)/',$attrtag,$matches)) { $attribute = $matches[1]; - - // If the attribute doesnt exist we'll create it - $o = Arr::get( - $result, - $attribute, - Factory::create( - $this->dn, - $attribute, - Arr::get($this->original,$attribute,[]), - $entry_oc, - )); - $o->setLangTag($matches[3],$values); + $tags = $matches[2]; } else { - $o = Factory::create($this->dn,$attribute,Arr::get($this->original,$attribute,[]),$entry_oc); + $attribute = $attrtag; + $tags = NULL; } - if (! $result->has($attribute)) { - // Store our new values to know if this attribute has changed - $o->values = collect($values); + $orig = Arr::get($this->original,$attrtag,[]); - $result->put($attribute,$o); - } + // If the attribute doesnt exist we'll create it + $o = Arr::get( + $result, + $attribute, + Factory::create( + $this->dn, + $attribute, + [$tags=>$orig], + $entry_oc, + )); + + $o->values = $o->values->merge([$tags=>$values]); + + $result->put($attribute,$o); } $sort = collect(config('pla.attr_display_order',[]))->map(fn($item)=>strtolower($item)); @@ -274,6 +274,35 @@ class Entry extends Model ->filter(fn($item)=>$item->is_internal); } + /** + * Identify the language tags (RFC 3866) used by this entry + * + * @return Collection + */ + public function getLangTags(): Collection + { + return $this->getObjects() + ->map(fn($item)=>$item + ->values + ->keys() + ->filter(fn($item)=>preg_match('/lang-[A-Za-z0-9-]+;?/',$item))) + ->filter(fn($item)=>$item->count()); + } + + /** + * Of all the items with lang tags, which ones have more than 1 lang tag + * + * @return Collection + */ + public function getLangMultiTags(): Collection + { + return $this->getLangTags() + ->map(fn($item)=>$item->values() + ->map(fn($item)=>explode(';',$item)) + ->filter(fn($item)=>count($item) > 1)) + ->filter(fn($item)=>$item->count()); + } + /** * Get an attribute as an object * @@ -299,6 +328,28 @@ class Entry extends Model return $this->objects; } + /** + * Find other attribute tags used by this entry + * + * @return Collection + */ + public function getOtherTags(): Collection + { + return $this->getObjects() + ->map(fn($item)=>$item + ->values + ->keys() + ->filter(fn($item)=> + $item && collect(explode(';',$item))->filter( + fn($item)=> + (! preg_match('/^lang-[A-Za-z0-9-]+$/',$item)) + && (! preg_match('/^binary$/',$item)) + ) + ->count()) + ) + ->filter(fn($item)=>$item->count()); + } + /** * Return a list of attributes without any values * diff --git a/resources/views/components/alert/attribute_tags_cant_manage.blade.php b/resources/views/components/alert/attribute_tags_cant_manage.blade.php new file mode 100644 index 00000000..6c61b07b --- /dev/null +++ b/resources/views/components/alert/attribute_tags_cant_manage.blade.php @@ -0,0 +1,9 @@ +
+ | Unable to display this attribute as it has attribute tags [{!! $tags->join(', ') !!}]. + You can manage it with an LDIF import. |
+