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 $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
*

View File

@ -17,15 +17,11 @@ 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)=>
[
return Server::baseDNs()
->map(fn($item)=> [
'title'=>$item->getRdn(),
'item'=>$item->getDNSecure(),
'lazy'=>TRUE,

View File

@ -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));
}

View File

@ -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);

2
public/js/custom.js vendored
View File

@ -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 <div id="tree"> element

View File

@ -24,7 +24,7 @@
<td>BaseDN(s)</td>
<td>
<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>
<td class="ps-0">{{ $item->getDn() }}</td>
</tr>

View File

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

View File

@ -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')
<x-success/>
@ -78,8 +67,6 @@
@section('page-scripts')
<script type="text/javascript">
var basedn = {!! $bases->toJson() !!};
var subpage = window.location.hash;
$(document).ready(function() {