I have an issue with my php form. I have an application that manages users in a LDAP server so I want to give the possibility to users to change their password anytime they want to using a form.
In the form we need tree informations (old password, newwpassword and the uid of the concerned ldap entry). We extract the uid from the displayName which can be a complete name: we consider that the first word is always the uid (just to notice it but that's not much important here).
So i have the form with this following code:
<?php
// echo '<pre>';
// print_r($_POST);
// echo '</pre>';
function str_to_noaccent($str) {
$url = $str;
$url = preg_replace('#Ç#', 'C', $url);
$url = preg_replace('#ç#', 'c', $url);
$url = preg_replace('#è|é|ê|ë#', 'e', $url);
$url = preg_replace('#È|É|Ê|Ë#', 'E', $url);
$url = preg_replace('#à|á|â|ã|ä|å#', 'a', $url);
$url = preg_replace('#@|À|Á|Â|Ã|Ä|Å#', 'A', $url);
$url = preg_replace('#ì|í|î|ï#', 'i', $url);
$url = preg_replace('#Ì|Í|Î|Ï#', 'I', $url);
$url = preg_replace('#ð|ò|ó|ô|õ|ö#', 'o', $url);
$url = preg_replace('#Ò|Ó|Ô|Õ|Ö#', 'O', $url);
$url = preg_replace('#ù|ú|û|ü#', 'u', $url);
$url = preg_replace('#Ù|Ú|Û|Ü#', 'U', $url);
$url = preg_replace('#ý|ÿ#', 'y', $url);
$url = preg_replace('#Ý#', 'Y', $url);
return ($url);
}
if(isset($_POST['soumission']))
{
if(isset($_POST['oldpassword']) && isset($_POST['newpassword']) && isset($_POST['displayName']))
{
$oldpasswd = $_POST['oldpassword'];
$newpassd = $_POST['newpassword'];
$arr = explode('',$_POST['displayName']);
$user_uid = str_to_noaccent(strtolower($arr[0]));
$cmd = exec('script.sh '.$oldpasswd.' '.$newpassd.' '.$user_uid);
if($cmd)
{
echo '<script language="text/javascript">';
echo 'alert("Mot de passe changé avec succès!")';
echo '</script>';
}
else
{
echo '<script language="text/javascript">';
echo 'alert("Impossible de changer de mot de passe!")';
echo '</script>';
}
}
}
?>
<form class="section" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<h2>Mot de passe</h2>
<input type="password" name="oldpassword" placeholder="Ancien mot de passe" autocomplete="off" autocapitalize="off" autocorrect="off" />
<input type="password" id="pass2" data-typetoggle="#personal-show" name="newpassword" placeholder="Nouveau mot de passe" autocomplete="off" autocapitalize="off" autocorrect="off" />
<input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label>
<input type="hidden" id="displayName" name="displayName"
value="<?php p($_['displayName']) ?>"
autocomplete="on" autocapitalize="off" autocorrect="off" readonly />
<input type="submit" name="soumission" value="Changer le mot de passe"/>
<div class="strengthify-wrapper"></div>
</form>
<?php
?>
The content of the script.sh is as follows:
#! /bin/bash
/usr/bin/ldappasswd -h @IP_ldap_server -p 389 -x -D 'cn=admin,dc=xxxxx,dc=xxxxx,dc=xx' -w xxxxxx -a $1 -s $2 uid=$3,ou=xxxx,dc=xxxx,dc=xxxx,dc=xx
Everything like script.sh, str_to_noaccent, etc. have been tested individually and works perfectly. Even the print_r($_POST); shows that form values are well get.
But it seems that the php code is not executed (from the if(isset($_POST['soumission'])) to the end of the first php block). It's been days but I still can figure out why. Can sombebody here help to find what's wrong?
Thank you all very much in advance.