require('../conf.php');
//--- rendre les paramètres valides
if (! isset($conm)) $conm = '';
if (! isset($cnlogin) || ! is_string($cnlogin)) $cnlogin = '';
if (preg_match('/[^A-Za-z0-9àâçèéêëîïôùûü_ -]/', $cnlogin)) $cnlogin = '';
if (! isset($cnpassw) || ! is_string($cnpassw)) $cnpassw = '';
if (preg_match('/[^a-z0-9]/', $cnpassw)) $cnpassw = '';
if (! isset($cnmix) || ! is_numeric($cnmix)) $cnmix = 0;
//--- initialiser le message
$alerter = '';
if ($cnmix) {
//--- Connexion à la DB
$db_link = mysql_connect($sql_server, $sql_user, $sql_passw);
if (! $db_link) {
echo 'Connexion impossible à la base de données ',$sql_bdd,' sur le serveur ',$sql_server;
exit;
}
mysql_select_db($sql_bdd, $db_link);
}
$maintenant = time();
//***** encoder selon RFC2047 ******
function encodeHeader($chn) {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $chn, $tab);
while (list(, $s1) = each($tab[1])) {
$s2 = preg_replace('/([\x20\x80-\xFF])/e', '"=".strtoupper(dechex(ord("\1")))', $s1);
$chn = str_replace($s1, '=?ISO-8859-1?Q?'.$s2.'?=', $chn);
}
return $chn;
}
//***** encoder quoted-printable ******
function quotedPrintable(&$texte, $ncar=76) {
$tab = preg_split("/\r?\n/", $texte);
$chn = '';
while (list(, $ligne) = each($tab)) {
$g = strlen($ligne); $g--;
$lign2 = '';
for ($k = 0; $k <= $g; $k++) {
$car = substr($ligne, $k, 1);
$dec = ord($car);
if ($dec == 32 && $k == $g)
$car = '=20';
else if ($dec == 9)
;
elseif ($dec == 61 || $dec < 32 || $dec > 126)
$car = '='.strtoupper(sprintf('%02s', dechex($dec)));
if (strlen($lign2) + strlen($car) >= $ncar) {
$chn .= $lign2.'='."\n";
$lign2 = '';
}
$lign2 .= $car;
}
$chn .= $lign2."\n";
}
return substr($chn, 0, -1);
}
/****************************************
****** Limiter l'accès aux admins *******
****************************************/
if ($conm == 'y' && $maintenant < $cnmix + 300) {
$k = substr(md5($_SERVER['SERVER_NAME']), 0, 16);
$sql = "SELECT admid FROM cmsprotect WHERE login='$cnlogin' AND MD5(CONCAT(DECODE(passw,'pw'),'$cnmix'))='$cnpassw' AND acces & 2048<>0 OR protect='$k'";
$req = mysql_query($sql) or die('Erreur SQL: '.(DEBUGSQL ? $sql.'
'.mysql_error() : 'voir DEBUGSQL'));
if (mysql_num_rows($req) > 1) {
//--- Créer un identifiant aléatoire
for ($cnpassw = '', $k = 0; $k < 16; $k++)
$cnpassw .= substr('0123456789', rand(0, 9), 1);
$tci = $maintenant;
$chn = $_SERVER['REMOTE_ADDR'];
session_start();
$_SESSION['cnpromen'] = $cnpassw;
$sql = "UPDATE cmsprotect SET protect='$cnpassw',adrip='$chn',temps='$tci' WHERE login='$cnlogin'";
$req = mysql_query($sql) or die('Erreur SQL: '.(DEBUGSQL ? $sql.'
'.mysql_error() : 'voir DEBUGSQL'));
//--- Rediriger vers une page protégée
mysql_close($db_link);
header('Location:admMenu.php?tci='.$tci);
exit;
}
}
/************************************
****** Changer le mot de passe ******
************************************/
if ($conm == '1' && $maintenant < $cnmix + 300) {
if (! isset($motpas) || ! is_string($motpas)) $motpas = '';
$sql = "SELECT admid,DECODE(passw,'pw') AS passe FROM cmsprotect WHERE MD5(CONCAT(DECODE(passw,'pw'),'$cnmix'))='$cnpassw' AND login='$cnlogin'";
$req = mysql_query($sql) or die('Erreur SQL: '.(DEBUGSQL ? $sql.'
'.mysql_error() : 'voir DEBUGSQL'));
if ($data = mysql_fetch_array($req, MYSQL_ASSOC)) {
$tabpw = explode(',', $motpas);
$g = strlen($data['passe']); $g--;
$tabpw[0] = (ord($data['passe']{$g}) ^ $tabpw[0]) & 15;
$motpas = '';
$g = 0; $k = 1;
while ($k <= $tabpw[0] && isset($tabpw[$k])) {
$motpas .= chr(ord($data['passe']{$g}) ^ $tabpw[$k]);
$k++; $g++;
if ($g >= strlen($data['passe']))
$g = 0;
}
if (preg_match('/[^A-Za-z0-9]/', $motpas))
$alerter = 'Le nouveau mot de passe contient des caractères non autorisés';
if (strlen($motpas) < 6)
$alerter = 'Le nouveau mot de passe n\'est pas valide';
if ($tabpw[0] < 6)
$alerter = 'Le nouveau mot de passe doit contenir 6 caractères au minimum';
unset($tabpw);
}
else
$alerter = 'Le nom d\'utilisateur ou l\'ancien mot de passe n\'est pas reconnu';
if (! $alerter) {
$k = $data['admid'];
$sql = "UPDATE cmsprotect SET passw=ENCODE('$motpas','pw') WHERE admid=$k";
$req = mysql_query($sql) or die('Erreur SQL: '.(DEBUGSQL ? $sql.'
'.mysql_error() : 'voir DEBUGSQL'));
$alerter = 'Le changement de mot de passe est réussi';
$conm = '';
}
}
/************************************
****** Envoyer le mot de passe ******
************************************/
if ($conm == '2' && $cnmix) {
$sql = "SELECT admail,DECODE(passw,'pw') AS passe FROM cmsprotect WHERE login='$cnlogin'";
$req = mysql_query($sql) or die('Erreur SQL: '.(DEBUGSQL ? $sql.'
'.mysql_error() : 'voir DEBUGSQL'));
if ($data = mysql_fetch_array($req, MYSQL_ASSOC)) {
if ($data['admail']) {
$chn = 'Bonjour.'."\n\n".'Votre mot de passe est oublié ?'."\n\n";
$chn .= 'Pour pouvoir vous connecter à la gestion du site, vous aurez besoin des ces données:'."\n\n";
$chn .= 'Nom d\'utilisateur: '.$cnlogin."\n".'Mot de passe: '.$data['passe']."\n\n";
$k = strpos($_SERVER['PHP_SELF'], '/admintool/');
$chn .= 'Et l\'adresse pour vous connecter en tant qu\'administrateur:'."\n".'http://'.$_SERVER['SERVER_NAME'].($k !== false ? substr($_SERVER['PHP_SELF'], 0, $k).'/admintool/' : '/admintool/');
$k = 'From: '.NOMDUSITE.' <'.ADRDUSITE.'>'."\n";
$k .= 'Content-Type: text/plain; charset='.CHAR7MAIL."\n".'Content-Transfer-Encoding: quoted-printable'."\n";
if (@mail($data['admail'], encodeHeader(NOMDUSITE.' - gestion du site'), quotedPrintable($chn), $k, '-f '.ADRDUSITE))
$alerter = 'Votre mot de passe a été envoyé à votre adresse email';
else
$alerter = 'L\'envoi de votre mot de passe par email a échoué';
}
else
$alerter = 'Votre adresse email n\'a pas été trouvée';
$conm = '';
}
else
$alerter = 'Le nom d\'utilisateur n\'est pas reconnu';
}
echo '',"\n";
echo '
',ADMINENTETE,' |
|
• Changer le mot de passe
• Recevoir par email votre mot de passe oublié
Pour continuer, il faut activer Javascript svp |
| conception Vertige asbl |