Implemented DN delete

This commit is contained in:
Deon George 2025-03-06 19:11:14 +11:00
parent c8c3939d59
commit d97087b83f
7 changed files with 115 additions and 3 deletions

View File

@ -156,6 +156,46 @@ class HomeController extends Controller
->withFragment($o->getDNSecure()); ->withFragment($o->getDNSecure());
} }
public function entry_delete(Request $request)
{
$dn = Crypt::decryptString($request->dn);
$o = config('server')->fetch($dn);
try {
$o->delete();
} catch (InsufficientAccessException $e) {
$request->flash();
switch ($x=$e->getDetailedError()->getErrorCode()) {
case 50:
return Redirect::to('/')
->withInput()
->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 Redirect::to('/')
->withInput()
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default:
abort(599,$e->getDetailedError()->getErrorMessage());
}
}
return Redirect::to('/')
->with('success',[sprintf('%s: %s',__('Deleted'),$dn)]);
}
public function entry_export(Request $request,string $id) public function entry_export(Request $request,string $id)
{ {
$dn = Crypt::decryptString($id); $dn = Crypt::decryptString($id);

View File

@ -35,9 +35,12 @@
<button class="btn btn-outline-dark p-1 m-1" id="entry-edit" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Edit Entry')"><i class="fas fa-fw fa-edit fs-5"></i></button> <button class="btn btn-outline-dark p-1 m-1" id="entry-edit" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Edit Entry')"><i class="fas fa-fw fa-edit fs-5"></i></button>
</li> </li>
@endif @endif
<!-- @todo Dont offer the delete button for an entry with children -->
@if(isset($page_actions) && $page_actions->contains('delete')) @if(isset($page_actions) && $page_actions->contains('delete'))
<li> <li>
<button class="btn btn-outline-danger p-1 m-1" id="entry-delete" data-bs-custom-class="custom-tooltip-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Delete Entry')"><i class="fas fa-fw fa-trash-can fs-5"></i></button> <span id="entry-delete" data-bs-toggle="modal" data-bs-target="#page-modal">
<button class="btn btn-outline-danger p-1 m-1" data-bs-custom-class="custom-tooltip-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Delete Entry')"><i class="fas fa-fw fa-trash-can fs-5"></i></button>
</span>
</li> </li>
@endif @endif
</ul> </ul>
@ -51,7 +54,6 @@
@section('page-scripts') @section('page-scripts')
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
console.log($('button[id=entry-edit]'));
$('button[id=entry-edit]').on('click',function(item) { $('button[id=entry-edit]').on('click',function(item) {
item.preventDefault(); item.preventDefault();

View File

@ -0,0 +1 @@
<button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">@lang('Close')</button>

View File

@ -71,9 +71,16 @@
@endsection @endsection
@section('page-modals') @section('page-modals')
<!-- Frame Modals -->
<div class="modal fade" id="page-modal" tabindex="-1" aria-labelledby="label" aria-hidden="true">
<div class="modal-dialog modal-lg modal-fullscreen-lg-down">
<div class="modal-content"></div>
</div>
</div>
<!-- EXPORT --> <!-- EXPORT -->
<div class="modal fade" id="entry_export-modal" tabindex="-1" aria-labelledby="entry_export-label" aria-hidden="true"> <div class="modal fade" id="entry_export-modal" tabindex="-1" aria-labelledby="entry_export-label" aria-hidden="true">
<div class="modal-dialog modal-lg modal-fullscreen-xl-down"> <div class="modal-dialog modal-lg modal-fullscreen-lg-down">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h1 class="modal-title fs-5" id="entry_export-label">LDIF for {{ $dn }}</h1> <h1 class="modal-title fs-5" id="entry_export-label">LDIF for {{ $dn }}</h1>
@ -210,6 +217,34 @@
download('ldap-export.ldif',ldif.html()); download('ldap-export.ldif',ldif.html());
}); });
$('#page-modal').on('shown.bs.modal',function(item) {
var that = $(this).find('.modal-content');
switch ($(item.relatedTarget).attr('id')) {
case 'entry-delete':
$.ajax({
method: 'GET',
url: '{{ url('modal/delete') }}/'+dn,
dataType: 'html',
cache: false,
beforeSend: function() {
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
},
success: function(data) {
that.empty().html(data);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
})
break;
default:
console.log('No action for button:'+$(item.relatedTarget).attr('id'));
}
});
$('#entry_export-modal').on('shown.bs.modal',function() { $('#entry_export-modal').on('shown.bs.modal',function() {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',

View File

@ -12,6 +12,8 @@
--}} --}}
@section('main-content') @section('main-content')
<x-success/>
<div class="card card-solid mb-3"> <div class="card card-solid mb-3">
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">

View File

@ -0,0 +1,29 @@
<div class="modal-header bg-danger text-white">
<h1 class="modal-title fs-5" id="entry_export-label">
<i class="fas fa-fw fa-exclamation-triangle"></i> <strong>@lang('WARNING')</strong>: @lang('Delete') <strong>{{ Crypt::decryptString($dn) }}</strong>
</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
@lang('Deleting this DN will permanently delete it from your LDAP server.')
</div>
<div class="modal-footer">
<x-modal.close/>
<button id="entry-delete" type="button" class="btn btn-sm btn-danger">@lang('Delete')</button>
</div>
<form id="entry-delete-form" method="POST" action="{{ url('entry/delete') }}">
@csrf
<input type="hidden" name="dn" value="{{ $dn }}">
</form>
<script type="text/javascript">
$(document).ready(function() {
$('button[id=entry-delete]').on('click',function(item) {
$('form#entry-delete-form').submit();
});
});
</script>

View File

@ -43,6 +43,7 @@ Route::controller(HomeController::class)->group(function() {
Route::match(['get','post'],'entry/add','entry_add'); Route::match(['get','post'],'entry/add','entry_add');
Route::post('entry/create','entry_create'); Route::post('entry/create','entry_create');
Route::post('entry/delete','entry_delete');
Route::get('entry/export/{id}','entry_export'); Route::get('entry/export/{id}','entry_export');
Route::post('entry/password/check/','entry_password_check'); Route::post('entry/password/check/','entry_password_check');
Route::post('entry/attr/add/{id}','entry_attr_add'); Route::post('entry/attr/add/{id}','entry_attr_add');
@ -51,5 +52,7 @@ Route::controller(HomeController::class)->group(function() {
Route::post('entry/update/pending','entry_pending_update'); Route::post('entry/update/pending','entry_pending_update');
Route::post('import/process/{type}','import'); Route::post('import/process/{type}','import');
Route::view('modal/delete/{dn}','modals.entry-delete');
}); });
}); });