Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block account #169

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@

$use_searchlocked = true;

$use_searchdisabled = true;

$use_searchexpired = true;

$use_searchwillexpire = true;
Expand All @@ -149,6 +151,12 @@
$use_disableaccount = false;
$show_enablestatus = false;

$use_enablecomment = false;
$use_enablecomment_required = false;
$use_disablecomment = false;
$use_disablecomment_required = false;


# Local password policy
# This is applied before directory password policy
# Minimal length
Expand Down
22 changes: 22 additions & 0 deletions docs/enableaccount.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ To enable this feature:
.. code-block:: php

$use_disableaccount = true;

Insert comment
--------------

This feature displays a comment pop-up when enabling and disabling user accounts.

To enable this feature:

.. code-block:: php

$use_enablecomment = true;
$use_disablecomment = true;

Comment required
----------------

This feature ensures a comment is required before enabling/disabling a user.

.. code-block:: php

$use_enablecomment_required = true;
$use_disablecomment_required = true;
8 changes: 7 additions & 1 deletion htdocs/disableaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
$result = "";
$dn = "";
$password = "";
$comment = "";

if (isset($_POST["dn"]) and $_POST["dn"]) {
$dn = $_POST["dn"];
} else {
$result = "dnrequired";
}

if (isset($_POST["comment"]) and $_POST["comment"]) {
$comment = $_POST["comment"];
}


if (!$use_disableaccount) {
$result = "actionforbidden";
}
Expand All @@ -38,7 +44,7 @@
}

if ($audit_log_file) {
auditlog($audit_log_file, $dn, $audit_admin, "disableaccount", $result);
auditlog($audit_log_file, $dn, $audit_admin, "disableaccount", $result, $comment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment modal is only defined for now in lock/unlock panel in the HTML template.

We may add comment for all action, but this should maybe done in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll do another PR for the comment feature...

Anyway, the last argument of the function auditlog is needed, else Service-Desk crashes.

}

header('Location: index.php?page=display&dn='.$dn.'&disableaccountresult='.$result);
17 changes: 12 additions & 5 deletions htdocs/enableaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@

$result = "";
$dn = "";
$password = "";
$comment = "";
$returnto = "display";

if (isset($_POST["dn"]) and $_POST["dn"]) {
$dn = $_POST["dn"];
} else if (isset($_GET["dn"]) and $_GET["dn"]) {
$dn = $_GET["dn"];
} else {
$result = "dnrequired";
}

if (!$use_enableaccount) {
$result = "actionforbidden";
if (isset($_GET["returnto"]) and $_GET["returnto"]) {
$returnto = $_GET["returnto"];
}

if (isset($_POST["comment"]) and $_POST["comment"]) {
$comment = $_POST["comment"];
}

if ($result === "") {
Expand All @@ -38,7 +45,7 @@
}

if ($audit_log_file) {
auditlog($audit_log_file, $dn, $audit_admin, "enableaccount", $result);
auditlog($audit_log_file, $dn, $audit_admin, "enableaccount", $result, $comment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same than previous comment, this need an adaptation of HTML template,

}

header('Location: index.php?page=display&dn='.$dn.'&enableaccountresult='.$result);
header('Location: index.php?page='.$returnto.'&dn='.$dn.'&enableaccountresult='.$result);
7 changes: 7 additions & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
$smarty->assign('show_expirestatus',$show_expirestatus);
$smarty->assign('display_password_expiration_date',$display_password_expiration_date);
$smarty->assign('use_searchlocked',$use_searchlocked);
$smarty->assign('use_searchdisabled',$use_searchdisabled);
$smarty->assign('use_searchexpired',$use_searchexpired);
$smarty->assign('use_searchwillexpire',$use_searchwillexpire);
$smarty->assign('use_searchidle',$use_searchidle);
Expand All @@ -187,6 +188,10 @@
$smarty->assign('use_enableaccount',$use_enableaccount);
$smarty->assign('use_disableaccount',$use_disableaccount);
$smarty->assign('show_enablestatus',$show_enablestatus);
$smarty->assign('use_enablecomment',$use_enablecomment);
$smarty->assign('use_enablecomment_required',$use_enablecomment_required);
$smarty->assign('use_disablecomment',$use_disablecomment);
$smarty->assign('use_disablecomment_required',$use_disablecomment_required);


# Assign messages
Expand Down Expand Up @@ -241,7 +246,9 @@
if ( $page === "checkpassword" and !$use_checkpassword ) { $page = "welcome"; }
if ( $page === "resetpassword" and !$use_resetpassword ) { $page = "welcome"; }
if ( $page === "unlockaccount" and !$use_unlockaccount ) { $page = "welcome"; }
if ( $page === "enableaccount" and !$use_enableaccount ) { $page = "welcome"; }
if ( $page === "searchlocked" and !$use_searchlocked ) { $page = "welcome"; }
if ( $page === "searchdisabled" and !$use_searchdisabled ) { $page = "welcome"; }
if ( $page === "searchexpired" and !$use_searchexpired ) { $page = "welcome"; }
if ( $page === "searchwillexpire" and !$use_searchwillexpire ) { $page = "welcome"; }
if ( $page === "searchidle" and !$use_searchidle ) { $page = "welcome"; }
Expand Down
45 changes: 45 additions & 0 deletions htdocs/searchdisabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* Search disabled entries in LDAP directory
*/

require_once("../conf/config.inc.php");
require __DIR__ . '/../vendor/autoload.php';

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

if ( !empty($entries) )
{

# Check if entry is still locked
foreach($entries as $entry_key => $entry) {

$isEnabled = $directory->isAccountEnabled($ldap, $entry['dn']);

if ( $isEnabled === true ) {
unset($entries[$entry_key]);
$nb_entries--;
}

}

$smarty->assign("page_title", "disabledaccounts");
if ($nb_entries === 0) {
$result = "noentriesfound";
} else {
$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);
if ($use_enableaccount) { $smarty->assign("display_enable_button", true); }
}
}

?>
1 change: 1 addition & 0 deletions lang/en.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$messages['currentpassword'] = "Current password";
$messages['dashboards'] = "Dashboards";
$messages['disableaccount'] = "Disable account";
$messages['disabledaccounts'] = "Disabled accounts";
$messages['displayentry'] = "Display entry";
$messages['dnrequired'] = "Entry identifier required";
$messages['editentry'] = "Edit entry";
Expand Down
17 changes: 9 additions & 8 deletions lang/fr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
$messages['accountdisabled'] = "Le compte est désactivé";
$messages['auditlogs'] = "Audit";
$messages['auditlogtitle'] = "Traces d'audit pour les $audit_log_days derniers jours";
$messages['accountlocked'] = "Le compte est bloqué";
$messages['accountlocked'] = "Le compte est verrouillé";
$messages['accountnotdisabled'] = "Échec de la désactivation du compte";
$messages['accountnotenabled'] = "Échec de l'activation du compte";
$messages['accountnotlocked'] = "Échec de blocage du compte";
$messages['accountnotunlocked'] = "Échec de déblocage du compte";
$messages['accountnotlocked'] = "Échec de verrouillage du compte";
$messages['accountnotunlocked'] = "Échec de déverrouillage du compte";
$messages['accountstatus'] = "Statut du compte";
$messages['accountunlocked'] = "Le compte n'est pas bloqué";
$messages['accountunlocked'] = "Le compte n'est pas verrouillé";
$messages['actionforbidden'] = "Action interdite";
$messages['changesubject'] = "Votre mot de passe a été changé";
$messages['changesubjectforadmin'] = "Le mot de passe d'un utilisateur a été changé";
Expand All @@ -26,6 +26,7 @@
$messages['currentpassword'] = "Mot de passe actuel";
$messages['dashboards'] = "Tableaux de bord";
$messages['disableaccount'] = "Désactiver le compte";
$messages['disabledaccounts'] = "Comptes désactivés";
$messages['displayentry'] = "Afficher l'entrée";
$messages['dnrequired'] = "L'identifiant de l'entrée est requis";
$messages['editentry'] = "Modifier l'entrée";
Expand Down Expand Up @@ -74,7 +75,7 @@
$messages['label_phone'] = "Téléphone";
$messages['label_postaladdress'] = "Adresse";
$messages['label_postalcode'] = "Code postal";
$messages['label_pwdaccountlockedtime'] = "Date de blocage";
$messages['label_pwdaccountlockedtime'] = "Date de verrouillage";
$messages['label_pwdchangedtime'] = "Dernier changement de mot de passe";
$messages['label_pwdfailuretime'] = "Derniers échecs d'authentification";
$messages['label_pwdpolicysubentry'] = "Politique des mots de passe associée";
Expand All @@ -86,8 +87,8 @@
$messages['label_title'] = "Titre";
$messages['label_user_dn'] = "Utilisateur";
$messages['ldaperror'] = "Erreur de communication avec l'annuaire LDAP";
$messages['lockaccount'] = "Bloquer le compte";
$messages['lockedaccounts'] = "Comptes bloqués";
$messages['lockaccount'] = "Verrouiller le compte";
$messages['lockedaccounts'] = "Comptes verrouillés";
$messages['logout'] = "Déconnexion";
$messages['newpassword'] = "Nouveau mot de passe";
$messages['noentriesfound'] = "Aucune entrée trouvée";
Expand All @@ -111,7 +112,7 @@
$messages['tooltip_emailto'] = "Envoyer un email";
$messages['tooltip_phoneto'] = "Composer ce numéro";
$messages['true'] = "Oui";
$messages['unlockaccount'] = "Débloquer le compte";
$messages['unlockaccount'] = "Déverrouiller le compte";
$messages['unlockdate'] = "Date de déblocage automatique :";
$messages['welcome'] = "Bienvenue sur le guichet de service LDAP Tool Box";
$messages['willexpireaccounts'] = "Mots de passe bientôt expirés";
Expand Down
8 changes: 7 additions & 1 deletion templates/comment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
<h1 class="modal-title fs-5" id="CommentModal">{$title}</h1>
</div>
<div class="modal-body">
<textarea class="form-control" name="comment" id="comment-{$method}" rows="3" placeholder="{$msg_insert_comment}"{if $use_lockcomment_required || $use_unlockcomment_required}required{/if}></textarea>
<textarea class="form-control" name="comment" id="comment-{$method}" rows="3" placeholder="{$msg_insert_comment}"
{if $method eq 'lock' || $method eq 'unlock'}
{if $use_lockcomment_required || $use_unlockcomment_required}required{/if}
{elseif $method eq 'enable' || $method eq 'disable'}
{if $use_disablecomment_required || $use_enablecomment_required}required{/if}
{/if}
></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Expand Down
52 changes: 36 additions & 16 deletions templates/display.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,25 @@
</div>
{if $use_disableaccount}
<div class="card-body">
<form id="disableaccount" method="post" action="index.php?page=disableaccount">
{if $disableaccountresult eq 'ldaperror' or $disableaccountresult eq 'actionforbidden'}
<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_accountnotdisabled}</div>
{/if}
<input type="hidden" name="dn" value="{$dn}" />
<button type="submit" class="btn btn-success">
<i class="fa fa-fw fa-user-slash"></i> {$msg_disableaccount}
{if $disableaccountresult eq 'ldaperror' or $disableaccountresult eq 'actionforbidden'}
<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_accountnotdisabled}</div>
{/if}
{if $use_disablecomment}
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#commentModal">
<i class="fa fa-fw fa-user-slash me-2"></i>{$msg_disableaccount}
<i class="fa fa-fw fa-info-circle text-body-tertiary ms-2" title="{$msg_comment_needed}"></i>
</button>
</form>
<div>
{include 'comment.tpl' method=disable page=disableaccount title=$msg_lockaccount}
</div>
{else}
<form id="disableaccount" method="post" action="index.php?page=disableaccount">
<input type="hidden" name="dn" value="{$dn}" />
<button type="submit" class="btn btn-success">
<i class="fa fa-fw fa-user-slash"></i> {$msg_disableaccount}
</button>
</form>
{/if}
</div>
{/if}
</div>
Expand All @@ -344,15 +354,25 @@
</div>
{if $use_enableaccount}
<div class="card-body">
<form id="disableaccount" method="post" action="index.php?page=enableaccount">
{if $enableaccountresult eq 'ldaperror' or $enableaccountresult eq 'actionforbidden'}
<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_accountnotenabled}</div>
{/if}
<input type="hidden" name="dn" value="{$dn}" />
<button type="submit" class="btn btn-success">
<i class="fa fa-fw fa-user-check"></i> {$msg_enableaccount}
{if $enableaccountresult eq 'ldaperror' or $enableaccountresult eq 'actionforbidden'}
<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_accountnotenabled}</div>
{/if}
{if $use_enablecomment}
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#commentModal">
<i class="fa fa-fw fa-user-check me-2"></i>{$msg_enableaccount}
<i class="fa fa-fw fa-info-circle text-body-tertiary ms-2" title="{$msg_comment_needed}"></i>
</button>
</form>
<div>
{include 'comment.tpl' method=enable page=enableaccount title=$msg_enableaccount}
</div>
{else}
<form id="disableaccount" method="post" action="index.php?page=enableaccount">
<input type="hidden" name="dn" value="{$dn}" />
<button type="submit" class="btn btn-success">
<i class="fa fa-fw fa-user-check"></i> {$msg_enableaccount}
</button>
</form>
{/if}
</div>
{/if}
</div>
Expand Down
12 changes: 12 additions & 0 deletions templates/listing_table.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<i class="fa fa-fw fa-unlock"></i>
</a>
{/if}
{if $display_enable_button}
<a href="index.php?page=enableaccount&dn={$entry.dn|escape:'url'}&returnto=searchdisabled"
class="btn btn-success btn-sm" role="button" title="{$msg_enableaccount}">
<i class="fa fa-fw fa-user-check"></i>
</a>
{/if}
</th>
{foreach $listing_columns as $column}
<td>
Expand Down Expand Up @@ -59,6 +65,12 @@
<i class="fa fa-fw fa-unlock"></i>
</a>
{/if}
{if $display_enable_button}
<a href="index.php?page=enableaccount&dn={$event.dn|escape:'url'}&returnto=searchdisabled"
class="btn btn-success btn-sm" role="button" title="{$msg_enableaccount}">
<i class="fa fa-fw fa-person-circle-check"></i>
</a>
{/if}
</th>
{foreach $listing_columns as $column}
<td>
Expand Down
5 changes: 4 additions & 1 deletion templates/menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

<div class="navbar-collapse collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav me-auto mb-2 mb-lg-0">
{if $use_searchlocked or $use_searchwillexpire or $use_searchexpired or $use_searchidle}
{if $use_searchlocked or $use_searchdisabled or $use_searchwillexpire or $use_searchexpired or $use_searchidle}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-fw fa-dashboard"></i> {$msg_dashboards}<span class="caret"></span></a>
<ul class="dropdown-menu">
{if $use_searchlocked}
<li><a href="index.php?page=searchlocked" class="dropdown-item"><i class="fa fa-fw fa-lock"></i> {$msg_lockedaccounts}</a></li>
{/if}
{if $use_searchdisabled}
<li><a href="index.php?page=searchdisabled" class="dropdown-item"><i class="fa fa-fw fa-user-slash"></i> {$msg_disabledaccounts}</a></li>
{/if}
{if $use_searchwillexpire}
<li><a href="index.php?page=searchwillexpire" class="dropdown-item"><i class="fa fa-fw fa-hourglass-half"></i> {$msg_willexpireaccounts}</a></li>
{/if}
Expand Down
11 changes: 11 additions & 0 deletions templates/searchdisabled.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="alert alert-warning">
{$nb_entries} {if $nb_entries==1}{$msg_entryfound}{else}{$msg_entriesfound}{/if}
</div>

{if {$size_limit_reached}}
<div class="alert alert-warning"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_sizelimit}</div>
{/if}

<table id="search-listing" class="table table-striped table-hover table-condensed dataTable">
{include 'listing_table.tpl' display="search"}
</table>
Loading