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

@@ -35,6 +35,8 @@
</div>
</div>
@yield('page-modals')
@section('scripts')
@include('architect::layouts.partials.scripts')

View File

@@ -27,23 +27,31 @@
<div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu dropdown-menu-right">
<ul class="nav flex-column">
@if ((isset($page_actions) && $page_actions->search('edit') !== FALSE) || old())
@if ((isset($page_actions) && ($page_actions->search('edit') !== FALSE)) || old())
<li class="nav-item">
<span class="nav-link pt-0 pb-1">
<button id="entry-edit" class="p-2 m-0 border-0 btn-transition btn btn-outline-dark w-100 text-start">
<i class="fas fa-fw fa-edit me-2"></i>
@lang('Edit')
<i class="fas fa-fw fa-edit me-2"></i> @lang('Edit')
</button>
</span>
</li>
@endif
@if (isset($page_actions) && $page_actions->search('copy') !== FALSE)
@if (isset($page_actions) && ($page_actions->search('export') !== FALSE))
<li class="nav-item">
<a class="nav-link pt-0 pb-1">
<button type="button" class="p-2 m-0 border-0 btn-transition btn btn-outline-dark w-100 text-start" data-bs-toggle="modal" data-bs-target="#entry-export-modal" {{--data-bs-whatever="ldif"--}}>
<i class="fas fa-fw fa-file-export me-2"></i> @lang('Export')
</button>
</a>
</li>
@endif
@if (isset($page_actions) && ($page_actions->search('copy') !== FALSE))
<li class="nav-item">
<a class="nav-link pt-0 pb-1">
<button class="p-2 m-0 border-0 btn-transition btn btn-outline-dark w-100 text-start">
<i class="fas fa-fw fa-truck-moving me-2"></i>
@lang('Copy or Move')
<i class="fas fa-fw fa-truck-moving me-2"></i> @lang('Copy or Move')
</button>
</a>
</li>

View File

@@ -40,6 +40,9 @@
<div class="font-icon-wrapper float-start ms-1 me-1 server-icon">
<a class="p-0 m-0" href="{{ LaravelLocalization::localizeUrl('schema') }}" onclick="return false;" style="display: contents;"><i class="fas fa-fw fa-fingerprint"></i></a>
</div>
<div class="font-icon-wrapper float-start ms-1 me-1 server-icon">
<a class="p-0 m-0" href="{{ LaravelLocalization::localizeUrl('import') }}" onclick="return false;" style="display: contents;"><i class="fas fa-fw fa-upload"></i></a>
</div>
@env(['local'])
<div class="font-icon-wrapper float-end ms-1 server-icon">
<a class="p-0 m-0" href="{{ LaravelLocalization::localizeUrl('debug') }}" onclick="return false;" style="display: contents;"><i class="fas fa-fw fa-toolbox"></i></a>

View File

@@ -0,0 +1,9 @@
@extends('architect::layouts.error')
@section('title')
@lang('Not Implemented') <small>(555)</small>
@endsection
@section('content')
{{ $exception->getMessage() }}
@endsection

View File

@@ -0,0 +1,9 @@
@extends('architect::layouts.error')
@section('title')
@lang('Error') <small>(598)</small>
@endsection
@section('content')
{{ $exception->getMessage() }}
@endsection

View File

@@ -0,0 +1,3 @@
<pre>
{{ $result }}
</pre>

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

@@ -10,4 +10,5 @@
</div>
</div>
@yield('page-modals')
@yield('page-scripts')

View File

@@ -1,9 +1,11 @@
@extends('dn')
@extends('home')
@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="{{ ($x=$o->getObject('jpegphoto')) ? 'border' : '' }}" rowspan="2">
{!! $x ? $x->render(FALSE,TRUE) : 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 +13,15 @@
<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>
@@ -62,13 +68,13 @@
@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
<form id="dn-update" method="POST" class="needs-validation" action="{{ url('entry/update/commit') }}" novalidate>
@csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="card-body">
<div class="row">
<div class="col-12 col-lg-6 col-xl-4 mx-auto pt-3">
<div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div>
<table class="table table-bordered table-striped">
@@ -96,7 +102,7 @@
@endforeach
</tbody>
</table>
</form>
</div>
</div>
<div class="row pt-3">
@@ -106,6 +112,20 @@
</div>
</div>
</div>
</div>
</form>
</div>
@endsection
@endsection
@section('page-scripts')
<script type="text/javascript">
$(document).ready(function() {
$('#form-reset').click(function() {
$('#dn-update')[0].reset();
});
$('#form-submit').click(function() {
$('#dn-update')[0].submit();
});
});
</script>
@append