Skip to content

Commit

Permalink
Use Directory interface for search idle accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Aug 23, 2024
1 parent 0c4ce50 commit 86de562
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
case "activedirectory":
$attributes_map = array_merge($attributes_map, $activedirectory_attributes_map);
$directory = new \Ltb\Directory\ActiveDirectory();
$ldap_lastauth_attribute = "lastLogon";
break;
}

Expand Down
35 changes: 15 additions & 20 deletions htdocs/searchidle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@
require __DIR__ . '/../vendor/autoload.php';
require_once("../lib/date.inc.php");



# Compute idle date
$dateIdle = new DateTime();
date_sub( $dateIdle, new DateInterval('P'.$idledays.'D') );
$dateIdleLdap = string2ldapDate( $dateIdle->format('d/m/Y') );
$dateIdleLdap = $directory->getLdapDate($dateIdle);

# Search filter
$ldap_filter = "(&".$ldap_user_filter."(|(!(".$ldap_lastauth_attribute."=*))(".$ldap_lastauth_attribute."<=".$dateIdleLdap.")))";

# Search attributes
$attributes = array();
[$ldap,$result,$nb_entries,$entries,$size_limit_reached] = $ldapInstance->search($ldap_filter, array(), $attributes_map, $search_result_title, $search_result_sortby, $search_result_items, $ldap_scope);

[$ldap,$result,$nb_entries,$entries,$size_limit_reached]=$ldapInstance->search($ldap_filter, $attributes, $attributes_map, $search_result_title, $search_result_sortby, $search_result_items, $ldap_scope);

if ( ! empty($entries) )
if ( !empty($entries) )
{
$smarty->assign("page_title", "idleaccountstitle");
$smarty->assign("nb_entries", $nb_entries);
$smarty->assign("entries", $entries);
$smarty->assign("size_limit_reached", $size_limit_reached);

$columns = $search_result_items;
if (! in_array($search_result_title, $columns)) array_unshift($columns, $search_result_title);
$smarty->assign("listing_columns", $columns);
$smarty->assign("listing_linkto", isset($search_result_linkto) ? $search_result_linkto : array($search_result_title));
$smarty->assign("listing_sortby", array_search($search_result_sortby, $columns));
$smarty->assign("show_undef", $search_result_show_undefined);
$smarty->assign("truncate_value_after", $search_result_truncate_value_after);
$smarty->assign("page_title", "idleaccountstitle");
$smarty->assign("nb_entries", $nb_entries);
$smarty->assign("entries", $entries);
$smarty->assign("size_limit_reached", $size_limit_reached);

$columns = $search_result_items;
if (! in_array($search_result_title, $columns)) array_unshift($columns, $search_result_title);
$smarty->assign("listing_columns", $columns);
$smarty->assign("listing_linkto", isset($search_result_linkto) ? $search_result_linkto : array($search_result_title));
$smarty->assign("listing_sortby", array_search($search_result_sortby, $columns));
$smarty->assign("show_undef", $search_result_show_undefined);
$smarty->assign("truncate_value_after", $search_result_truncate_value_after);
}

?>

0 comments on commit 86de562

Please sign in to comment.