Start on fetching DN from server

This commit is contained in:
Deon George
2020-09-13 21:30:04 +10:00
parent 130ae005a3
commit f323be3d7f
10 changed files with 162 additions and 52 deletions

View File

@@ -54,6 +54,27 @@ class Server
}
}
/**
* Fetch a DN from the server
*
* @param $dn
* @return |null
*/
public function fetch(string $dn,array $attributes=['*'])
{
try {
return ($x=(new Adldap)
->addProvider(config('ldap.connections.default.settings'))
->search()
->select($attributes)
->findByDn($dn)) ? $x : NULL;
// @todo Tidy up this exception
} catch (\Exception $e) {
dd(['e'=>$e]);
}
}
/**
* Query the server for a DN
*

View File

@@ -26,6 +26,7 @@ class APIController extends Controller
'item'=>Crypt::encryptString($item),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item,
];
});
}
@@ -39,12 +40,12 @@ class APIController extends Controller
return (new Server())
->query($dn)
->transform(function($item) {
//dd($item->getDistinguishedName(),$item);
return [
'title'=>$item->getDistinguishedName(),
'item'=>Crypt::encryptString($item->getDistinguishedName()),
'icon'=>'fa-fw fas fa-sitemap',
'lazy'=>TRUE,
'tooltip'=>$item->getDistinguishedName(),
];
});

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use App\Classes\LDAP\Server;
@@ -12,7 +13,23 @@ class HomeController extends Controller
$o = new Server;
return view('home')
->with('server',config('ldap.connections.default.name')) // @todo This connection name should be a config item
->with('bases',$o->getBaseDN());
->with('server',config('ldap.connections.default.name'))
->with('bases',$o->getBaseDN()->transform(function($item) {
return [
'title'=>$item,
'item'=>Crypt::encryptString($item),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item,
];
}));
}
public function render(Request $request) {
$dn = Crypt::decryptString($request->post('key'));
return view('widgets.dn')
->with('dn',$dn)
->with('leaf',(new Server())->fetch($dn));
}
}