Start of implementation of Import and Export using LDIF

This commit is contained in:
2024-01-11 08:59:40 +11:00
parent ded1f74285
commit 4c8bd1c81f
30 changed files with 1118 additions and 925 deletions

View File

@@ -3,7 +3,7 @@
@section('page_title')
<table class="table table-borderless">
<tr>
<td class="{{ ($x=Arr::get($o->getAttributes(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="{{ ($x=$o->getObject('jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td>
</tr>
<tr>
@@ -11,11 +11,11 @@
<table>
<tr>
<td class="p-1 m-1">Created</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x->render() : __('Unknown') }}]</th>
<th class="p-1 m-1">{{ ($x=$o->getObject('createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=$o->getObject('creatorsname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">Modified</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x->render() : __('Unknown') }}]</th>
<th class="p-1 m-1">{{ ($x=$o->getObject('modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=$o->getObject('modifiersname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">UUID</td>
@@ -168,8 +168,43 @@
</div>
@endsection
@section('page-modals')
<!-- Modal -->
<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-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="entry-export-label">LDIF for {{ $dn }}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="entry-export"><div class="fa-3x"><i class="fas fa-spinner fa-pulse fa-sm"></i></div></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Close</button>
<button id="entry-export-download" type="button" class="btn btn-primary btn-sm">Download</button>
</div>
</div>
</div>
</div>
@endsection
@section('page-scripts')
<script type="text/javascript">
function download(filename,text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function editmode() {
$('button[id=entry-edit]').addClass('active').removeClass('btn-outline-dark').addClass('btn-outline-light');
@@ -190,17 +225,16 @@
$(document).ready(function() {
$('#form-reset').click(function() {
$('#dn-edit')[0].reset();
})
});
$('#form-submit').click(function() {
$('#dn-edit')[0].submit();
})
});
$('#newattr').on('change',function(item) {
$.ajax({
type: 'GET',
beforeSend: function() {
},
beforeSend: function() {},
success: function(data) {
$('#newattrs').append(data);
},
@@ -210,7 +244,7 @@
},
url: '{{ url('entry/newattr') }}/'+item.target.value,
cache: false
})
});
// Remove the option from the list
$(this).find('[value="'+item.target.value+'"]').remove()
@@ -229,6 +263,29 @@
editmode();
});
$('#entry-export-download').on('click',function(item) {
item.preventDefault();
let ldif = $('#entry-export').find('pre:first'); // update this selector in your local version
download('ldap-export.ldif',ldif.html());
});
$('#entry-export-modal').on('shown.bs.modal', function () {
$.ajax({
type: 'GET',
beforeSend: function() {},
success: function(data) {
$('#entry-export').empty().append(data);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/export',$o->getDNSecure()) }}/',
cache: false
})
})
@if(old())
editmode();
@endif

View File

@@ -0,0 +1,65 @@
@extends('layouts.dn')
@section('page_title')
<table class="table table-borderless">
<tr>
<td style="border-radius: 5px;"><div class="page-title-icon f32"><i class="fas fa-upload"></i></div></td>
<td class="top text-start align-text-top p-0 pt-2"><strong>@lang('LDIF Import')</strong><br><small>To Server XXX</small></td>
</tr>
</table>
@endsection
@section('main-content')
<div class="row">
<div class="offset-1 col-10">
<div class="main-card mb-3 card">
<form id="import-form" action="{{ url('import/process/ldif') }}" method="POST" enctype="multipart/form-data">
@csrf
<input type="hidden" name="frame" value="import">
<div class="card-header">
@lang('LDIF Import')
</div>
<div class="card-body">
<div class="row">
<div class="col">
<div class="form-group">
<label for="ldif-text" class="pb-2"><strong>@lang('Paste in your LDIF here')</strong></label>
<textarea class="form-control text-monospace @error('text') is-invalid @enderror" name="text" rows="10">{{ old('text') }}</textarea>
<div class="invalid-feedback pb-2">
@error('text')
{{ $message }}
@enderror
</div>
</div>
</div>
</div>
<div class="row pt-5">
<div class="col">
<div class="form-group">
<label for="ldif-file" class="pb-2"><strong>@lang('Or upload LDIF file')</strong></label><br>
<input type="file" class="form-control-file @error('file') is-invalid @enderror" name="file" accept=".ldif"><br>
<small class="form-text text-muted @error('file') is-invalid @enderror">@lang('Maximum file size') <strong>{{ ini_get('upload_max_filesize') }}</strong></small>
<div class="invalid-feedback pb-2">
@error('file')
{{ $message }}
@enderror
</div>
</div>
</div>
</div>
</div>
<div class="card-footer">
<span class="ms-auto">
<button type="submit" class="btn btn-success btn-sm">Process</button>
</span>
</div>
</form>
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,60 @@
@section('page_title')
<table class="table table-borderless">
<tr>
<td style="border-radius: 5px;"><div class="page-title-icon f32"><i class="fas fa-upload"></i></div></td>
<td class="top text-start align-text-top p-0 pt-2"><strong>@lang('LDIF Import Result')</strong><br><small>To Server XXX</small></td>
</tr>
</table>
@endsection
@section('main-content')
<div class="row">
<div class="offset col-12">
<div class="main-card mb-3 card">
<div class="card-body">
<div class="card-header-tabs">
<ul class="nav nav-tabs">
<li class="nav-item"><a data-bs-toggle="tab" href="#result" class="nav-link active">@lang('Import Result')</a></li>
<li class="nav-item"><a data-bs-toggle="tab" href="#ldif" class="nav-link">@lang('LDIF')</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="result" role="tabpanel">
<table class="table table-borderless">
<thead>
<tr>
<th>@lang('DN')</th>
<th>@lang('Result')</th>
<th class="text-end">@lang('Line')</th>
</tr>
</thead>
@foreach ($result as $item)
<tr>
<td>{{ $item->get('dn') }}</td>
<td>{{ $item->get('result') }}</td>
<td class="text-end">{{ $item->get('line') }}</td>
</tr>
@endforeach
</table>
</div>
<div class="tab-pane" id="ldif" role="tabpanel">
<pre class="code"><code>{{ $ldif }}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('page-scripts')
<script type="text/javascript">
$(document).ready(function() {
$('pre code').html(function(index, html) {
return html.trim().replace(/^(.*)$/mg, "<span class=\"line\">$1</span>");
});
});
</script>
@append

View File

@@ -4,26 +4,28 @@
<table class="table table-borderless">
<tr>
<td style="border-radius: 5px;"><div class="page-title-icon f32"><i class="fas fa-info"></i></div></td>
<td class="top text-end align-text-top p-0 pt-2 }}"><strong>@lang('Server Info')</strong><br><small>{{ $s->rootDSE()->entryuuid[0] ?? '' }}</small></td>
<td class="top text-end align-text-top p-0 pt-2"><strong>@lang('Server Info')</strong><br><small>{{ $s->rootDSE()->entryuuid[0] ?? '' }}</small></td>
</tr>
</table>
@endsection
@section('main-content')
<div class="bg-white p-3">
<table class="table">
@foreach ($s->rootDSE()->getAttributes() as $attribute => $ao)
<tr>
<th class="w-25">
{!! ($x=$s->schema('attributetypes',$attribute))
? sprintf('<a class="attributetype" id="strtolower(%s)" href="%s">%s</a>',$x->name_lc,url('schema/attributetypes',$x->name_lc),$x->name)
: $attribute !!}
</th>
<td>
<x-attribute :edit="false" :o="$ao"/>
</td>
</tr>
@endforeach
</table>
<div class="main-card mb-3 card">
<div class="card-body">
<table class="table">
@foreach ($s->rootDSE()->getObjects() as $attribute => $ao)
<tr>
<th class="w-25">
{!! ($x=$s->schema('attributetypes',$attribute))
? sprintf('<a class="attributetype" id="strtolower(%s)" href="%s">%s</a>',$x->name_lc,url('schema/attributetypes',$x->name_lc),$x->name)
: $attribute !!}
</th>
<td>
<x-attribute :edit="false" :o="$ao"/>
</td>
</tr>
@endforeach
</table>
</div>
</div>
@endsection

View File

@@ -1,111 +0,0 @@
@extends('dn')
@section('page_title')
<table class="table table-borderless">
<tr>
<td class="{{ ($x=Arr::get($o->getOriginal(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td>
</tr>
<tr>
<td class="line-height-1" style="font-size: 55%;vertical-align: bottom;" colspan="2">
<table>
<tr>
<td class="p-1 m-1">Created</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">Modified</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">UUID</td>
<th class="p-1 m-1">{{ $o->entryuuid[0] ?? '' }}</th>
</tr>
</table>
</td>
</tr>
</table>
@endsection
@section('main-content')
@if(session()->has('note'))
<div class="alert alert-info">
<h4 class="alert-heading"><i class="fas fa-fw fa-note-sticky"></i> Note:</h4>
<hr>
<p>{{ session()->pull('note') }}</p>
</div>
@endif
@if(session()->has('success'))
<div class="alert alert-success">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-up"></i> Success!</h4>
<hr>
<p>{{ session()->pull('success') }}</p>
<ul style="list-style-type: square;">
@foreach (session()->pull('updated') as $key => $values)
<li>{{ $key }}: {{ join(',',$values) }}</li>
@endforeach
</ul>
</div>
@endif
@if($errors->any())
<div class="alert alert-danger">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4>
<hr>
<ul style="list-style-type: square;">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="main-card mb-3 card">
<div class="card-body">
<div class="row">
<div class="col-12 col-lg-6 col-xl-4 mx-auto pt-3">
<form id="dn-edit" method="POST" class="needs-validation" action="{{ url('entry/update/commit') }}" novalidate>
@csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Attribute</th>
<th>OLD</th>
<th>NEW</th>
</tr>
</thead>
<tbody>
@foreach ($o->getDirty() as $key => $value)
<tr>
<th rowspan="{{ $x=max(count($value),count(Arr::get($o->getOriginal(),$key,[])))}}">{{ $key }}</th>
@for($xx=0;$xx<$x;$xx++)
@if($xx)
</tr><tr>
@endif
<td>{{ Arr::get(Arr::get($o->getOriginal(),$key),$xx,'['.strtoupper(__('New Value')).']') }}</td>
<td>{{ ($y=Arr::get($value,$xx)) ?: '['.strtoupper(__('Deleted')).']' }}<input type="hidden" name="{{ $key }}[]" value="{{ $y }}"></td>
@endfor
</tr>
@endforeach
</tbody>
</table>
</form>
</div>
<div class="row pt-3">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2 mx-auto">
<span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span>
</div>
</div>
</div>
</div>
</div>
@endsection