Load the rootDSE in Server::__construct(), remove basedn from views, and rely on the javascript to get the basedns

This commit is contained in:
Deon George 2025-06-11 23:08:24 +09:30
parent d61f6168a4
commit 56fcd729e7
8 changed files with 32 additions and 72 deletions

View File

@ -30,6 +30,8 @@ final class Server
private Collection $matchingrules; private Collection $matchingrules;
private Collection $objectclasses; private Collection $objectclasses;
private Entry $rootDSE;
/* ObjectClass Types */ /* ObjectClass Types */
public const OC_STRUCTURAL = 0x01; public const OC_STRUCTURAL = 0x01;
public const OC_ABSTRACT = 0x02; public const OC_ABSTRACT = 0x02;
@ -37,6 +39,8 @@ final class Server
public function __construct() public function __construct()
{ {
$this->rootDSE = self::rootDSE();
$this->attributetypes = collect(); $this->attributetypes = collect();
$this->ldapsyntaxes = collect(); $this->ldapsyntaxes = collect();
$this->matchingrules = collect(); $this->matchingrules = collect();
@ -66,7 +70,7 @@ final class Server
* @return Collection * @return Collection
* @testedin GetBaseDNTest::testBaseDNExists(); * @testedin GetBaseDNTest::testBaseDNExists();
*/ */
public static function baseDNs(bool $objects=FALSE): Collection public static function baseDNs(bool $objects=TRUE): Collection
{ {
try { try {
$rootdse = self::rootDSE(); $rootdse = self::rootDSE();
@ -184,7 +188,7 @@ final class Server
foreach (($rootdse->namingcontexts ?: []) as $dn) foreach (($rootdse->namingcontexts ?: []) as $dn)
$result->push(self::get($dn)->read()->find($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; return $rootdse;
} }
/**
* Get the Schema DN
*
* @return string
* @throws ObjectNotFoundException
*/
public static function schemaDN(): string
{
return collect(self::rootDSE()->subschemasubentry)
->first();
}
/* METHODS */ /* METHODS */
/** /**
@ -512,6 +504,17 @@ final class Server
return is_null($key) ? $result : $result->get($key); 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 * Given an OID, return the ldapsyntax for the OID
* *

View File

@ -17,21 +17,17 @@ class AjaxController extends Controller
* *
* @return Collection * @return Collection
* @throws \LdapRecord\Query\ObjectNotFoundException * @throws \LdapRecord\Query\ObjectNotFoundException
* @todo This should be consolidated with HomeController
*/ */
public function bases(): Collection public function bases(): Collection
{ {
$base = Server::baseDNs(TRUE) ?: collect(); return Server::baseDNs()
->map(fn($item)=> [
return $base 'title'=>$item->getRdn(),
->transform(fn($item)=> 'item'=>$item->getDNSecure(),
[ 'lazy'=>TRUE,
'title'=>$item->getRdn(), 'icon'=>'fa-fw fas fa-sitemap',
'item'=>$item->getDNSecure(), 'tooltip'=>$item->getDn(),
'lazy'=>TRUE, ]);
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
]);
} }
/** /**

View File

@ -26,21 +26,6 @@ use App\Ldap\Entry;
class HomeController extends Controller 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 * Create a new object in the LDAP server
* *
@ -79,7 +64,6 @@ class HomeController extends Controller
return view('frame') return view('frame')
->with('subframe','create') ->with('subframe','create')
->with('bases',$this->bases())
->with('o',$o) ->with('o',$o)
->with('step',$step) ->with('step',$step)
->with('template',$template) ->with('template',$template)
@ -307,7 +291,6 @@ class HomeController extends Controller
->with('note',__('No attributes changed')); ->with('note',__('No attributes changed'));
return view('update') return view('update')
->with('bases',$this->bases())
->with('dn',$dn) ->with('dn',$dn)
->with('o',$o); ->with('o',$o);
} }
@ -386,10 +369,9 @@ class HomeController extends Controller
$key = $this->request_key($request,$old); $key = $this->request_key($request,$old);
$view = ($old $view = $old
? view('frame')->with('subframe',$key['cmd']) ? view('frame')->with('subframe',$key['cmd'])
: view('frames.'.$key['cmd'])) : view('frames.'.$key['cmd']);
->with('bases',$this->bases());
// If we are rendering a DN, rebuild our object // If we are rendering a DN, rebuild our object
if ($key['cmd'] === 'create') { if ($key['cmd'] === 'create') {
@ -436,8 +418,7 @@ class HomeController extends Controller
// Did we come here as a result of a redirect // Did we come here as a result of a redirect
return count(old()) return count(old())
? $this->frame($request,collect(old())) ? $this->frame($request,collect(old()))
: view('home') : view('home');
->with('bases',$this->bases());
} }
/** /**
@ -473,7 +454,6 @@ class HomeController extends Controller
return view('frame') return view('frame')
->with('subframe','import_result') ->with('subframe','import_result')
->with('bases',$this->bases())
->with('result',$result) ->with('result',$result)
->with('ldif',htmlspecialchars($x)); ->with('ldif',htmlspecialchars($x));
} }

View File

@ -22,7 +22,7 @@ class SearchController extends Controller
$result = collect(); $result = collect();
foreach ($so->baseDNs() as $base) { foreach ($so->baseDNs(FALSE) as $base) {
$search = (new Entry) $search = (new Entry)
->in($base); ->in($base);

2
public/js/custom.js vendored
View File

@ -59,7 +59,7 @@ $(document).ready(function() {
if (typeof basedn !== 'undefined') { if (typeof basedn !== 'undefined') {
sources = basedn; sources = basedn;
} else { } else {
sources = { url: 'ajax/bases' }; sources = { url: '/ajax/bases' };
} }
// Attach the fancytree widget to an existing <div id="tree"> element // Attach the fancytree widget to an existing <div id="tree"> element

View File

@ -24,7 +24,7 @@
<td>BaseDN(s)</td> <td>BaseDN(s)</td>
<td> <td>
<table class="table table-sm table-borderless"> <table class="table table-sm table-borderless">
@foreach($server->baseDNs(TRUE)->sort(fn($item)=>$item->sort_key) as $item) @foreach($server->baseDNs() as $item)
<tr> <tr>
<td class="ps-0">{{ $item->getDn() }}</td> <td class="ps-0">{{ $item->getDn() }}</td>
</tr> </tr>

View File

@ -2,10 +2,4 @@
@section('main-content') @section('main-content')
@include('frames.'.$subframe) @include('frames.'.$subframe)
@endsection @endsection
@section('page-scripts')
<script type="text/javascript">
var basedn = {!! $bases->toJson() !!};
</script>
@append

View File

@ -1,16 +1,5 @@
@extends('architect::layouts.app') @extends('architect::layouts.app')
{{--
@section('htmlheader_title')
@lang('Home')
@endsection
@section('page_title')
@endsection
@section('page_icon')
@endsection
--}}
@section('main-content') @section('main-content')
<x-success/> <x-success/>
@ -78,8 +67,6 @@
@section('page-scripts') @section('page-scripts')
<script type="text/javascript"> <script type="text/javascript">
var basedn = {!! $bases->toJson() !!};
var subpage = window.location.hash; var subpage = window.location.hash;
$(document).ready(function() { $(document).ready(function() {