Skip to content

A free open source IT asset/license management system

Restrict manual sync to superusers

snipeae20155679e6
diff --git a/app/Http/Controllers/Users/LDAPImportController.php b/app/Http/Controllers/Users/LDAPImportController.php
index 84a2214942..48d2a15568 100644
--- a/app/Http/Controllers/Users/LDAPImportController.php
+++ b/app/Http/Controllers/Users/LDAPImportController.php
@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Users;
use App\Http\Controllers\Controller;
-use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
@@ -28,8 +27,13 @@ class LDAPImportController extends Controller
*/
public function create()
{
- // I guess this prolly oughtta... I dunno. Do something?
- $this->authorize('update', User::class);
+ // Superuser-only: a bulk LDAP sync surfaces users from across
+ // the entire directory (all companies, all OUs), so anyone with
+ // "users.edit" but no full-directory access shouldn't be able
+ // to run it or read the summary that lists them.
+ if (! auth()->user()?->isSuperUser()) {
+ abort(403);
+ }
try {
// $this->ldap->connect(); I don't think this actually exists in LdapAd.php, and we don't really 'persist' LDAP connections anyways...right?
} catch (\Exception $e) {
@@ -52,7 +56,10 @@ class LDAPImportController extends Controller
*/
public function store(Request $request)
{
- $this->authorize('update', User::class);
+ // See create() for the superuser-only rationale.
+ if (! auth()->user()?->isSuperUser()) {
+ abort(403);
+ }
// Call Artisan LDAP import command.
Artisan::call('snipeit:ldap-sync', ['--location_id' => $request->input('location_id'), '--json_summary' => true]);
diff --git a/resources/views/users/ldap.blade.php b/resources/views/users/ldap.blade.php
index dcec3060c1..eac9ec3a5a 100644
--- a/resources/views/users/ldap.blade.php
+++ b/resources/views/users/ldap.blade.php
@@ -8,110 +8,98 @@
{{-- Page content --}}
@section('content')
-<div class="row">
- <div class="col-md-8 col-md-offset-2">
- @if ($snipeSettings->ldap_enabled == 0)
- {{ trans('admin/users/message.ldap_not_configured') }}
- @else
-
- <div class="box box-default">
- <form class="form-horizontal" role="form" method="post" action="" id="ldap-form">
- {{csrf_field()}}
- <div class="box-body">
- <div class="callout callout-legend col-md-12">
- <p>
- <i class="fa-solid fa-lightbulb text-info"></i>
- <strong>
- {!! trans('admin/users/general.ldap_sync_intro', ['link' => 'https://snipe-it.readme.io/docs/ldap-sync#/']) !!}
- </strong>
- </p>
+<x-container columns="1" class="col-md-8 col-md-offset-2">
+ @if ($snipeSettings->ldap_enabled == 0)
+ {{ trans('admin/users/message.ldap_not_configured') }}
+ @else
+ <x-form id="ldap-form">
+ <x-box>
+ <x-callout type="legend" icon="tip" class="col-md-12">
+ <p>
+ <strong>
+ {!! trans('admin/users/general.ldap_sync_intro', ['link' => 'https://snipe-it.readme.io/docs/ldap-sync#/']) !!}
+ </strong>
+ </p>
+ </x-callout>
+
+ <x-input.location-select
+ :label="trans('general.ldap_sync_location')"
+ name="location_id[]"
+ :multiple="true"
+ :hide-new-button="true"
+ :help-text="trans('admin/users/general.ldap_config_text')"
+ />
+
+ <x-slot:customfooter>
+ <div class="box-footer">
+ <div class="text-left col-md-6">
+ <a class="btn btn-link" href="{{ route('users.index') }}">{{ trans('button.cancel') }}</a>
</div>
- <!-- Location -->
- @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.ldap_sync_location'), 'help_text' => trans('admin/users/general.ldap_config_text'), 'fieldname' => 'location_id[]', 'multiple' => true])
-
- </div><!-- ./box-body -->
-
- <div class="box-footer">
- <div class="text-left col-md-6">
- <a class="btn btn-link" href="{{ route('users.index') }}">{{ trans('button.cancel') }}</a>
- </div>
- <div class="text-right col-md-6">
- <button type="submit" class="btn btn-primary" id="sync">
- <i id="sync-button-icon" class="fas fa-sync-alt icon-white" aria-hidden="true"></i> <span id="sync-button-text">{{ trans('general.synchronize') }}</span>
- </button>
- </div>
- </div> <!-- ./box-footer -->
- </form>
- </div><!-- /.box -->
-
- @endif
- </div><!-- /.col-md-8 -->
-</div><!-- /.row -->
+ <div class="text-right col-md-6">
+ <x-input.button class="btn-primary" id="sync">
+ <i id="sync-button-icon" class="fas fa-sync-alt icon-white" aria-hidden="true"></i>
+ <span id="sync-button-text">{{ trans('general.synchronize') }}</span>
+ </x-input.button>
+ </div>
+ </div>
+ </x-slot:customfooter>
+ </x-box>
+ </x-form>
+ @endif
+</x-container>
@if (Session::get('summary'))
-<div class="row">
- <div class="col-md-8 col-md-offset-2">
-
- <div class="box box-default">
- <div class="box-header with-border">
- <h2 class="box-title">
- {{ trans('general.sync_results') }}
- </h2>
- </div><!-- /.box-header -->
-
- <div class="box-body"><!-- .box-body -->
- <table
- data-cookie-id-table="ldapUserSync"
- data-id-table="ldapUserSyncTable"
- data-side-pagination="client"
- data-sort-order="asc"
- data-sort-name="username"
- data-show-refresh="false"
- id="customFieldsTable"
- data-advanced-search="false"
- class="table table-striped snipe-table"
- data-export-options='{
- "fileName": "ldap-sync-results-{{ date('Y-m-d') }}"
- }'>
- <thead>
- <tr>
- <th scope="col" data-sortable="true" data-visible="false" data-searchable="true">{{ trans('general.id') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.username') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('admin/users/table.display_name') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.employee_number') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.first_name') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.last_name') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.email') }}</th>
- <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.notes') }}</th>
- </tr>
- </thead>
- <tbody>
-
- @foreach (Session::get('summary') as $entry)
- <tr>
- <td>{{ (array_key_exists('id', $entry)) ? $entry['id'] : '' }}</td>
- <td>{{ $entry['username'] }}</td>
- <td>{{ $entry['display_name'] }}</td>
- <td>{{ $entry['employee_number'] }}</td>
- <td>{{ $entry['firstname'] }}</td>
- <td>{{ $entry['lastname'] }}</td>
- <td>{{ $entry['email'] }}</td>
- <td>
- @if ($entry['status']=='success')
- <span class="text-success"><i class="fas fa-check"></i> {!! $entry['note'] !!}</span>
- @else
- <span class="alert-msg" role="alert" aria-live="assertive">{!! $entry['note'] !!}</span>
- @endif
- </td>
- </tr>
- @endforeach
- </tbody>
- </table>
- </div><!-- /.box-body -->
- </div><!-- /.box -->
- </div><!-- /.col-md-12 -->
-</div><!-- /.row -->
-
+<x-container columns="1" class="col-md-8 col-md-offset-2">
+ <x-box :header="trans('general.sync_results')">
+ <table
+ data-cookie-id-table="ldapUserSync"
+ data-id-table="ldapUserSyncTable"
+ data-side-pagination="client"
+ data-sort-order="asc"
+ data-sort-name="username"
+ data-show-refresh="false"
+ id="customFieldsTable"
+ data-advanced-search="false"
+ class="table table-striped snipe-table"
+ data-export-options='{
+ "fileName": "ldap-sync-results-{{ date('Y-m-d') }}"
+ }'>
+ <thead>
+ <tr>
+ <th scope="col" data-sortable="true" data-visible="false" data-searchable="true">{{ trans('general.id') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.username') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('admin/users/table.display_name') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.employee_number') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.first_name') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.last_name') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.email') }}</th>
+ <th scope="col" data-sortable="true" data-visible="true" data-searchable="true">{{ trans('general.notes') }}</th>
+ </tr>
+ </thead>
+ <tbody>
+
+ @foreach (Session::get('summary') as $entry)
+ <tr>
+ <td>{{ (array_key_exists('id', $entry)) ? $entry['id'] : '' }}</td>
+ <td>{{ $entry['username'] }}</td>
+ <td>{{ $entry['display_name'] }}</td>
+ <td>{{ $entry['employee_number'] }}</td>
+ <td>{{ $entry['first_name'] }}</td>
+ <td>{{ $entry['last_name'] }}</td>
+ <td>{{ $entry['email'] }}</td>
+ <td>
+ @if ($entry['status']=='success')
+ <span class="text-success"><i class="fas fa-check"></i> {!! $entry['note'] !!}</span>
+ @else
+ <span class="alert-msg" role="alert" aria-live="assertive">{!! $entry['note'] !!}</span>
+ @endif
+ </td>
+ </tr>
+ @endforeach
+ </tbody>
+ </table>
+ </x-box>
+</x-container>
@endif
@stop