phpldapadmin/app/Http/Controllers/APIController.php
Deon George 6620b9147e API query and CI to build the docker demo image
Remove unused CI, removed some debugging for the demo
2021-12-10 23:51:48 +11:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use App\Classes\LDAP\Server;
class APIController extends Controller
{
/**
* Get the LDAP server BASE DNs
*
* @return array|null
*/
public function bases(): Collection
{
return (new Server())
->getBaseDN()
->transform(function($item) {
return [
'title'=>$item,
'item'=>Crypt::encryptString($item),
//'folder'=>TRUE,
'lazy'=>TRUE,
//'key'=>0,
//'autoexpand'=>TRUE,
];
});
}
public function query(Request $request): Collection
{
$levels = $request->query('depth',1);
$dn = Crypt::decryptString($request->query('key'));
Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels));
return (new Server())
->query($dn)
->transform(function($item) {
//dd($item->getDistinguishedName(),$item);
return [
'title'=>$item->getDistinguishedName(),
'item'=>Crypt::encryptString($item->getDistinguishedName()),
//'folder'=>TRUE,
'lazy'=>TRUE,
//'key'=>0,
//'autoexpand'=>TRUE,
];
});
Log::debug(sprintf('%s: Query [%s] - Levels [%d]: %s',__METHOD__,$dn,$levels,serialize($x)));
}
}