Skip to content

Commit

Permalink
Update validity dates
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Nov 27, 2024
1 parent 5faacfd commit 32ee346
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions htdocs/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$isAccountValid = "";
$startDate = "";
$endDate = "";
$updatevaliditydatesresult = "";

if (isset($_GET["dn"]) and $_GET["dn"]) {
$dn = $_GET["dn"];
Expand Down Expand Up @@ -63,6 +64,9 @@
$posthookresult = $_GET["posthookresult"];
}

if (isset($_GET["updatevaliditydatesresult"]) and $_GET["updatevaliditydatesresult"]) {
$updatevaliditydatesresult = $_GET["updatevaliditydatesresult"];
}
if ($result === "") {

require_once("../conf/config.inc.php");
Expand Down Expand Up @@ -224,5 +228,6 @@
$smarty->assign("isAccountValid", $isAccountValid);
$smarty->assign("startDate", $startDate);
$smarty->assign("endDate", $endDate);
$smarty->assign("updatevaliditydatesresult", $updatevaliditydatesresult);

?>
1 change: 1 addition & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function sha256($string)
if ( $page === "searchwillexpire" and !$use_searchwillexpire ) { $page = "welcome"; }
if ( $page === "searchidle" and !$use_searchidle ) { $page = "welcome"; }
if ( $page === "auditlog" and !$use_showauditlog ) { $page = "welcome"; }
if ( $page === "updatevaliditydates" and !($use_updatestarttime or $use_updateendtime) ) { $page = "welcome"; }
if ( file_exists($page.".php") ) { require_once($page.".php"); }
$smarty->assign('page',$page);

Expand Down
83 changes: 83 additions & 0 deletions htdocs/updatevaliditydates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
* Update start time and end time in LDAP directory
*/

$result = "";
$dn = "";
$start_date = "";
$end_date = "";
$comment = "";
$returnto = "display";

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

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

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

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

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

if (!($use_updatestarttime or $use_updateendtime)) {
$result = "actionforbidden";
}

if ($result === "") {

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


# Connect to LDAP
$ldap_connection = $ldapInstance->connect();

$ldap = $ldap_connection[0];
$result = $ldap_connection[1];

# DN match
if ( !$ldapInstance->matchDn($dn, $dnAttribute, $ldap_user_filter, $ldap_user_base, $ldap_scope) ) {
$result = "noentriesfound";
error_log("LDAP - $dn not found using the configured search settings, reject request");
} else {
if ($use_updatestarttime and $start_date) {
$startDate = new DateTime($start_date);
$ldapStartDate = $directory->getLdapDate($startDate);
$update = $ldapInstance->modify_attributes($dn, array( $attributes_map['starttime']['attribute'] => $ldapStartDate));
if ( $update[0] == 0 ) {
$result = "validiydatesupdated";
} else {
$result = "ldaperror";
}
}
if ($use_updateendtime and $end_date) {
$endDate = new DateTime($end_date);
$ldapEndDate = $directory->getLdapDate($endDate);
$update = $ldapInstance->modify_attributes($dn, array( $attributes_map['endtime']['attribute'] => $ldapEndDate));
if ( $update[0] == 0 and $result !== "ldaperror" ) {
$result = "validiydatesupdated";
} else {
$result = "ldaperror";
}
}
}
}

if ($audit_log_file) {
auditlog($audit_log_file, $dn, $audit_admin, "updatevaliditydates", $result, $comment);
}

header('Location: index.php?page='.$returnto.'&dn='.$dn.'&updatevaliditydatesresult='.$result);
2 changes: 2 additions & 0 deletions lang/en.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,7 @@
$messages['policyspecialatends'] = "Your new password may not have its only special character at the beginning or end";
$messages['policyentropy'] = "Password strength";
$messages['updatevaliditydates'] = "Update validity dates";
$messages['validitydatesnotupdated'] = "Error when updating validity dates";
$messages['validitydatesupdated'] = "Validity dates updated";

?>
2 changes: 2 additions & 0 deletions lang/fr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,7 @@
$messages['policyspecialatends'] = "Votre nouveau mot de passe ne doit pas avoir son seul caractère spécial en première ou dernière position.";
$messages['policyentropy'] = "Force du mot de passe";
$messages['updatevaliditydates'] = "Modifier les dates de validité";
$messages['validitydatesnotupdated'] = "Erreur lors de la mise à jour des dates de validité";
$messages['validitydatesupdated'] = "Dates de validité mises à jour";

?>
6 changes: 6 additions & 0 deletions templates/display.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@
</div>
{if $use_updatestarttime or $use_updateendtime}
<div class="card-body">
{if $updatevaliditydatesresult eq 'ldaperror' or $updatevaliditydatesresult eq 'actionforbidden'}
<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_validitydatesnotupdated}</div>
{/if}
{if $updatevaliditydatesresult eq 'validiydatesupdated'}
<div class="alert alert-success"><i class="fa fa-fw fa-check"></i> {$msg_validitydatesupdated}</div>
{/if}
<form id="updatevaliditydates" method="post" action="index.php?page=updatevaliditydates" class="row g-3">
<input type="hidden" name="dn" value="{$dn}" />
{if $use_updatestarttime}
Expand Down

0 comments on commit 32ee346

Please sign in to comment.