diff --git a/app/Classes/LDAP/Server.php b/app/Classes/LDAP/Server.php index e5d36145..59aafb85 100644 --- a/app/Classes/LDAP/Server.php +++ b/app/Classes/LDAP/Server.php @@ -30,6 +30,8 @@ final class Server private Collection $matchingrules; private Collection $objectclasses; + private Entry $rootDSE; + /* ObjectClass Types */ public const OC_STRUCTURAL = 0x01; public const OC_ABSTRACT = 0x02; @@ -37,6 +39,8 @@ final class Server public function __construct() { + $this->rootDSE = self::rootDSE(); + $this->attributetypes = collect(); $this->ldapsyntaxes = collect(); $this->matchingrules = collect(); @@ -66,7 +70,7 @@ final class Server * @return Collection * @testedin GetBaseDNTest::testBaseDNExists(); */ - public static function baseDNs(bool $objects=FALSE): Collection + public static function baseDNs(bool $objects=TRUE): Collection { try { $rootdse = self::rootDSE(); @@ -184,7 +188,7 @@ final class Server foreach (($rootdse->namingcontexts ?: []) as $dn) $result->push(self::get($dn)->read()->find($dn)); - return $result->filter(); + return $result->filter()->sort(fn($item)=>$item->sort_key); }); } @@ -256,18 +260,6 @@ final class Server return $rootdse; } - /** - * Get the Schema DN - * - * @return string - * @throws ObjectNotFoundException - */ - public static function schemaDN(): string - { - return collect(self::rootDSE()->subschemasubentry) - ->first(); - } - /* METHODS */ /** @@ -512,6 +504,17 @@ final class Server return is_null($key) ? $result : $result->get($key); } + /** + * Get the Schema DN + * + * @return string + * @throws ObjectNotFoundException + */ + public function schemaDN(): string + { + return Arr::get($this->rootDSE->subschemasubentry,0); + } + /** * Given an OID, return the ldapsyntax for the OID * diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 10ba2a87..9c144e94 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -17,21 +17,17 @@ class AjaxController extends Controller * * @return Collection * @throws \LdapRecord\Query\ObjectNotFoundException - * @todo This should be consolidated with HomeController */ public function bases(): Collection { - $base = Server::baseDNs(TRUE) ?: collect(); - - return $base - ->transform(fn($item)=> - [ - 'title'=>$item->getRdn(), - 'item'=>$item->getDNSecure(), - 'lazy'=>TRUE, - 'icon'=>'fa-fw fas fa-sitemap', - 'tooltip'=>$item->getDn(), - ]); + return Server::baseDNs() + ->map(fn($item)=> [ + 'title'=>$item->getRdn(), + 'item'=>$item->getDNSecure(), + 'lazy'=>TRUE, + 'icon'=>'fa-fw fas fa-sitemap', + 'tooltip'=>$item->getDn(), + ]); } /** diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 89d71953..391e0079 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -26,21 +26,6 @@ use App\Ldap\Entry; class HomeController extends Controller { - private function bases(): Collection - { - $base = Server::baseDNs(TRUE) ?: collect(); - - return $base->transform(function($item) { - return [ - 'title'=>$item->getRdn(), - 'item'=>$item->getDNSecure(), - 'lazy'=>TRUE, - 'icon'=>'fa-fw fas fa-sitemap', - 'tooltip'=>$item->getDn(), - ]; - }); - } - /** * Create a new object in the LDAP server * @@ -79,7 +64,6 @@ class HomeController extends Controller return view('frame') ->with('subframe','create') - ->with('bases',$this->bases()) ->with('o',$o) ->with('step',$step) ->with('template',$template) @@ -307,7 +291,6 @@ class HomeController extends Controller ->with('note',__('No attributes changed')); return view('update') - ->with('bases',$this->bases()) ->with('dn',$dn) ->with('o',$o); } @@ -386,10 +369,9 @@ class HomeController extends Controller $key = $this->request_key($request,$old); - $view = ($old + $view = $old ? view('frame')->with('subframe',$key['cmd']) - : view('frames.'.$key['cmd'])) - ->with('bases',$this->bases()); + : view('frames.'.$key['cmd']); // If we are rendering a DN, rebuild our object if ($key['cmd'] === 'create') { @@ -436,8 +418,7 @@ class HomeController extends Controller // Did we come here as a result of a redirect return count(old()) ? $this->frame($request,collect(old())) - : view('home') - ->with('bases',$this->bases()); + : view('home'); } /** @@ -473,7 +454,6 @@ class HomeController extends Controller return view('frame') ->with('subframe','import_result') - ->with('bases',$this->bases()) ->with('result',$result) ->with('ldif',htmlspecialchars($x)); } diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index ae94ba5b..86c62e5b 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -22,7 +22,7 @@ class SearchController extends Controller $result = collect(); - foreach ($so->baseDNs() as $base) { + foreach ($so->baseDNs(FALSE) as $base) { $search = (new Entry) ->in($base); diff --git a/public/js/custom.js b/public/js/custom.js index 73187ac9..87795db4 100644 --- a/public/js/custom.js +++ b/public/js/custom.js @@ -59,7 +59,7 @@ $(document).ready(function() { if (typeof basedn !== 'undefined') { sources = basedn; } else { - sources = { url: 'ajax/bases' }; + sources = { url: '/ajax/bases' }; } // Attach the fancytree widget to an existing
element diff --git a/resources/views/debug.blade.php b/resources/views/debug.blade.php index a7e9d726..070cfb02 100644 --- a/resources/views/debug.blade.php +++ b/resources/views/debug.blade.php @@ -24,7 +24,7 @@ BaseDN(s) - @foreach($server->baseDNs(TRUE)->sort(fn($item)=>$item->sort_key) as $item) + @foreach($server->baseDNs() as $item) diff --git a/resources/views/frame.blade.php b/resources/views/frame.blade.php index 3b3c76af..e904b57c 100644 --- a/resources/views/frame.blade.php +++ b/resources/views/frame.blade.php @@ -2,10 +2,4 @@ @section('main-content') @include('frames.'.$subframe) -@endsection - -@section('page-scripts') - -@append \ No newline at end of file +@endsection \ No newline at end of file diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index d6dc30c6..a10f84e5 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -1,16 +1,5 @@ @extends('architect::layouts.app') -{{-- -@section('htmlheader_title') - @lang('Home') -@endsection - -@section('page_title') -@endsection -@section('page_icon') -@endsection ---}} - @section('main-content') @@ -78,8 +67,6 @@ @section('page-scripts')
{{ $item->getDn() }}