Start of enabling DN update.

This commit is contained in:
2023-03-31 15:55:08 +11:00
parent a1a9b8ba76
commit c36383b0fc
13 changed files with 359 additions and 125 deletions

View File

@@ -27,7 +27,7 @@ class APIController extends Controller
->transform(function($item) {
return [
'title'=>$item->getRdn(),
'item'=>Crypt::encryptString($item->getDn()),
'item'=>$item->getDNSecure(),
'icon'=>$item->icon(),
'lazy'=>Arr::get($item->getAttribute('hassubordinates'),0) == 'TRUE',
'tooltip'=>$item->getDn(),

View File

@@ -8,10 +8,14 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Session;
use LdapRecord\Exceptions\InsufficientAccessException;
use LdapRecord\LdapRecordException;
use LdapRecord\Query\ObjectNotFoundException;
use App\Classes\LDAP\Server;
use App\Exceptions\InvalidUsage;
use App\Http\Requests\EntryRequest;
class HomeController extends Controller
{
@@ -25,6 +29,66 @@ class HomeController extends Controller
return view('debug');
}
/**
* Render a specific DN
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function dn_frame(Request $request)
{
$dn = Crypt::decryptString($request->post('key'));
return view('frames.dn')
->with('o',config('server')->fetch($dn))
->with('dn',$dn);
}
public function entry_update(EntryRequest $request)
{
$dn = Crypt::decryptString($request->dn);
$o = config('server')->fetch($dn);
foreach ($request->except(['_token','dn']) as $key => $value)
$o->{$key} = array_filter($value);
Session::put('dn',$request->dn);
if (! $dirty=$o->getDirty())
return back()->with(['note'=>__('No attributes changed')]);
try {
$o->update($request->except(['_token','dn']));
} catch (InsufficientAccessException $e) {
$request->flash();
switch ($x=$e->getDetailedError()->getErrorCode()) {
case 50:
return back()->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default:
abort(599,$e->getDetailedError()->getErrorMessage());
}
} catch (LdapRecordException $e) {
$request->flash();
switch ($x=$e->getDetailedError()->getErrorCode()) {
case 8:
return back()->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default:
abort(599,$e->getDetailedError()->getErrorMessage());
}
}
return back()
->with(['success'=>__('Entry updated')])
->with(['updated'=>$dirty]);
}
/**
* Application home page
*/
@@ -32,17 +96,25 @@ class HomeController extends Controller
{
$base = Server::baseDNs() ?: collect();
return view('home')
->with('server',config('ldap.connections.default.name'))
->with('bases',$base->transform(function($item) {
return [
'title'=>$item->getRdn(),
'item'=>Crypt::encryptString($item->getDn()),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
];
}));
$bases = $base->transform(function($item) {
return [
'title'=>$item->getRdn(),
'item'=>$item->getDNSecure(),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
];
});
if (Session::has('dn'))
return view('dn')
->with('bases',$bases)
->with('o',config('server')->fetch($dn=Crypt::decryptString(Session::pull('dn'))))
->with('dn',$dn);
else
return view('home')
->with('bases',$bases)
->with('server',config('ldap.connections.default.name'));
}
/**
@@ -62,21 +134,6 @@ class HomeController extends Controller
->with('s',$s);
}
/**
* Render a specific DN
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function dn_frame(Request $request)
{
$dn = Crypt::decryptString($request->post('key'));
return view('frames.dn')
->with('o',config('server')->fetch($dn))
->with('dn',$dn);
}
/**
* Show the Schema Viewer
*

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class EntryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return TRUE;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'dn'=>'string|min:3',
'objectclass'=>'array|min:1',
];
}
}