From 1e685ca8354e9fa5752f47ed4f9004f886644ac0 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 14 Jun 2022 12:18:42 -0700 Subject: [PATCH 1/4] Fixed SC-19104 - fixes to ldap:troubleshoot artisan command --- app/Console/Commands/LdapTroubleshooter.php | 110 +++++++++++--------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/app/Console/Commands/LdapTroubleshooter.php b/app/Console/Commands/LdapTroubleshooter.php index 0c74ef5707..8c28318866 100644 --- a/app/Console/Commands/LdapTroubleshooter.php +++ b/app/Console/Commands/LdapTroubleshooter.php @@ -27,6 +27,19 @@ function ip_in_range( $ip, $range ) { } // NOTE - this function was shamelessly stolen from this gist: https://gist.github.com/tott/7684443 +/** + * Ensure LDAP filters are parentheses-wrapped + */ +function parenthesized_filter($filter) +{ + if(substr($filter,0,1) == "(" ) { + return $filter; + } else { + return "(".$filter.")"; + } + +} + class LdapTroubleshooter extends Command { /** @@ -70,6 +83,47 @@ class LdapTroubleshooter extends Command } } + /** + * Clean the results from ldap_get_entries into something useful + * @param array $array + * @return array + */ + public function ldap_results_cleaner ($array) { + $cleaned = []; + for($i = 0; $i < $array['count']; $i++) { + $row = $array[$i]; + $clean_row = []; + foreach($row AS $key => $val ) { + $this->debugout("Key is: ".$key); + if($key == "count" || is_int($key) || $key == "dn") { + $this->debugout(" and we're gonna skip it\n"); + continue; + } + $this->debugout(" And that seems fine.\n"); + if(array_key_exists('count',$val)) { + if($val['count'] == 1) { + $clean_row[$key] = $val[0]; + } else { + unset($val['count']); //these counts are annoying + $elements = []; + foreach($val as $entry) { + if(isset($ldap_constants[$entry])) { + $elements[] = $ldap_constants[$entry]; + } else { + $elements[] = $entry; + } + } + $clean_row[$key] = $elements; + } + } else { + $clean_row[$key] = $val; + } + } + $cleaned[$i] = $clean_row; + } + return $cleaned; + } + /** * Execute the console command. * @@ -102,16 +156,12 @@ class LdapTroubleshooter extends Command $output[] = "LDAPTLS_KEY=storage/ldap_client_tls.key"; } $output[] = "ldapsearch"; - $output[] = $settings->ldap_server; + $output[] = "-H ".$settings->ldap_server; $output[] = "-x"; $output[] = "-b ".escapeshellarg($settings->ldap_basedn); $output[] = "-D ".escapeshellarg($settings->ldap_uname); $output[] = "-w ".escapeshellarg(\Crypt::Decrypt($settings->ldap_pword)); - if(substr($settings->ldap_filter,0,1) == "(" ) { - $output[] = escapeshellarg($settings->ldap_filter); - } else { - $output[] = escapeshellarg("(".$settings->ldap_filter.")"); - } + $output[] = escapeshellarg(parenthesized_filter($settings->ldap_filter)); if($settings->ldap_tls) { $this->line("# adding STARTTLS option"); $output[] = "-Z"; @@ -290,45 +340,8 @@ class LdapTroubleshooter extends Command } $this->debugout("LDAP constants are: ".print_r($ldap_constants,true)); - // recursive function that 'cleans' the returned array from ldap_get_entries which are formatted awfully - $cleaner = function ($array) { - $cleaned = []; - for($i = 0; $i < $array['count']; $i++) { - $row = $array[$i]; - $clean_row = []; - foreach($row AS $key => $val ) { - $this->debugout("Key is: ".$key); - if($key == "count" || is_int($key) || $key == "dn") { - $this->debugout(" and we're gonna skip it\n"); - continue; - } - $this->debugout(" And that seems fine.\n"); - if(array_key_exists('count',$val)) { - if($val['count'] == 1) { - $clean_row[$key] = $val[0]; - } else { - unset($val['count']); //these counts are annoying - $elements = []; - foreach($val as $entry) { - if(isset($ldap_constants[$entry])) { - $elements[] = $ldap_constants[$entry]; - } else { - $elements[] = $entry; - } - } - $clean_row[$key] = $elements; - } - } else { - $clean_row[$key] = $val; - } - } - $cleaned[$i] = $clean_row; - } - return $cleaned; - }; - foreach($ldap_urls AS $ldap_url) { - if($this->test_informational_bind($ldap_url[0],$ldap_url[1],$ldap_url[2],$settings->ldap_uname,Crypt::decrypt($settings->ldap_pword))) { + if($this->test_informational_bind($ldap_url[0],$ldap_url[1],$ldap_url[2],$settings->ldap_uname,Crypt::decrypt($settings->ldap_pword),$settings)) { $this->info("Success getting informational bind!"); } else { $this->error("Unable to get information from bind."); @@ -422,9 +435,9 @@ class LdapTroubleshooter extends Command }); } - public function test_informational_bind($ldap_url, $check_cert, $start_tls, $username, $password) + public function test_informational_bind($ldap_url, $check_cert, $start_tls, $username, $password,$settings) { - return $this->timed_boolean_execute(function () use ($ldap_url, $check_cert, $start_tls, $username, $password) { + return $this->timed_boolean_execute(function () use ($ldap_url, $check_cert, $start_tls, $username, $password, $settings) { try { // TODO - copypasta'ed from test_authed_bind $conn = $this->connect_to_ldap($ldap_url, $check_cert, $start_tls); $bind_results = ldap_bind($conn, $username, $password); @@ -435,12 +448,13 @@ class LdapTroubleshooter extends Command $this->info("SUCCESS - Able to bind to $ldap_url as $username"); $result = ldap_read($conn, '', '(objectClass=*)'/* , ['supportedControl']*/); $results = ldap_get_entries($conn, $result); - $cleaned_results = $cleaner($results); + $cleaned_results = $this->ldap_results_cleaner($results); $this->line(print_r($cleaned_results,true)); //okay, great - now how do we display those results? I have no idea. // I don't see why this throws an Exception for Google LDAP, but I guess we ought to try and catch it? $this->comment("I guess we're trying to do the ldap search here, but sometimes it takes too long?"); - $search_results = ldap_search($conn, $settings->base_dn, $settings->filter); + $this->debugout("Base DN is: ".$settings->ldap_basedn." and filter is: ".parenthesized_filter($settings->ldap_filter)); + $search_results = ldap_search($conn, $settings->ldap_basedn, parenthesized_filter($settings->ldap_filter)); $this->info("Printing first 10 results: "); for($i=0;$i<10;$i++) { $this->info($search_results[$i]); From 9072f7c6c9e10081ab0323abab3b9d37879b9a18 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 14 Jun 2022 12:49:50 -0700 Subject: [PATCH 2/4] Added click-to-select to tables Signed-off-by: snipe --- resources/views/categories/view.blade.php | 1 + resources/views/locations/view.blade.php | 4 +++- resources/views/models/view.blade.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.php index da37e49914..b32bb8df06 100644 --- a/resources/views/categories/view.blade.php +++ b/resources/views/categories/view.blade.php @@ -71,6 +71,7 @@ data-toolbar="#assetsBulkEditToolbar" data-bulk-button-id="#bulkAssetEditButton" data-bulk-form-id="#assetsBulkForm" + data-click-to-select="true" data-export-options='{ "fileName": "export-{{ str_slug($category->name) }}-assets-{{ date('Y-m-d') }}", "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index cd203fb909..b548062b4b 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -90,7 +90,7 @@ data-columns="{{ \App\Presenters\UserPresenter::dataTableLayout() }}" data-cookie-id-table="usersTable" data-pagination="true" - data-id-table="#usersTable" + data-id-table="usersTable" data-search="true" data-side-pagination="server" data-show-columns="true" @@ -100,6 +100,7 @@ data-toolbar="#userBulkEditToolbar" data-bulk-button-id="#bulkUserEditButton" data-bulk-form-id="#usersBulkForm" + data-click-to-select="true" id="usersTable" class="table table-striped snipe-table" data-url="{{route('api.users.index', ['location_id' => $location->id])}}" @@ -131,6 +132,7 @@ data-toolbar="#assetsBulkEditToolbar" data-bulk-button-id="#bulkAssetEditButton" data-bulk-form-id="#assetsBulkForm" + data-click-to-select="true" id="assetsListingTable" class="table table-striped snipe-table" data-url="{{route('api.assets.index', ['location_id' => $location->id]) }}" diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index 0027f61cd2..b52805d15b 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -59,6 +59,7 @@ data-toolbar="#assetsBulkEditToolbar" data-bulk-button-id="#bulkAssetEditButton" data-bulk-form-id="#assetsBulkForm" + data-click-to-select="true" data-show-export="true" data-show-refresh="true" data-sort-order="asc" From 88dfdb753852a7fa070ddadfdce1cf9739412dff Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 14 Jun 2022 12:50:10 -0700 Subject: [PATCH 3/4] Fixed bug in uncheck Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index f0bebb4bb2..d71fe32539 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -124,8 +124,7 @@ $('.snipe-table').on('uncheck.bs.table .btSelectItem', function (row, $element) { var tableId = $(this).data('id-table'); - $( "#" + tableId + "checkbox_" + $element.id).remove(); - console.log("#" + tableId + "checkbox_" + $element.id); + $( "#" + tableId + "_checkbox_" + $element.id).remove(); }); From f1a63f25e72e6ef19b425e045017f2236c7db50e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 14 Jun 2022 12:50:26 -0700 Subject: [PATCH 4/4] Partialize and add data atributes to statuslabel bulk Signed-off-by: snipe --- resources/views/statuslabels/view.blade.php | 22 +++++---------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/resources/views/statuslabels/view.blade.php b/resources/views/statuslabels/view.blade.php index c7c7716b52..3ddacd1471 100644 --- a/resources/views/statuslabels/view.blade.php +++ b/resources/views/statuslabels/view.blade.php @@ -12,23 +12,7 @@
- {{ Form::open([ - 'method' => 'POST', - 'route' => ['hardware/bulkedit'], - 'class' => 'form-inline', - 'id' => 'bulkForm']) }} -
-
- @if (Request::get('status')!='Deleted') -
- - -
- @endif + @include('partials.asset-bulk-actions')