:> � jean-luc.chretien@tice.ac-caen.fr * @Note: Ce fichier de fonction doit etre appele par un include * @Licence Distribue sous la licence GPL */ /** * file: jlcipher.inc.php * @Repertoire: includes/ */ // Constantes j-LCipher $MaxLifeTime = "5"; /* seconde */ # Messages d'erreur j-LCipher loges dans /var/log/se3/auth.log $MsgError[1]="Possible spoof IP source address"; $MsgError[2]="MaxTimeLife expire"; $MsgError[3]=$MsgError[1]." and ".$MsgError[2]; $MsgError[4]="Authentification error"; $logpath ="/var/log/se3/"; //================================================= /** * Affiche de la partie cryptage * @Parametres * @Return */ function header_crypto_html( $titre,$path) { global $login; ?> <?php echo $titre ?> Bonjour $login"; } //================================================= /** * Affiche le lien actif ou inactif pour le cryptage * @Parametres * @Return */ function crypto_nav($path) { global $HTTP_USER_AGENT; // Affichage logo crypto if (preg_match("#Mozilla/4.7#", $HTTP_USER_AGENT)) { echo " ".gettext("Attention, avec ce navigateur votre mot de passe va circuler en clair sur le réseau !").""; } else { echo " ".gettext("Cryptage du mot de passe actif !").""; } } //================================================= /** * Retourne l'IP distante * @Parametres * @Return */ function remote_ip() { if(getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } else { $ip = getenv("REMOTE_ADDR"); } return $ip; } //================================================= /** * Decode le mot de passe * @Parametres * @Return */ function decode_pass($string_auth) { global $MaxLifeTime,$path_to_wwwse3; $fpdebug=fopen("/var/log/se3/debug.log","a"); fputs($fpdebug,date("j/m/y:H:i").":function decode_pass():\$string_auth: ".$string_auth."\n"); //$argument=explode("\n", $string_auth); //fputs($fpdebug,date("j/m/y:H:i").":function decode_pass():\$argument: ".$argument[0]."\n"); //fputs($fpdebug,date("j/m/y:H:i").":function decode_pass():\$argument: ".$argument[1]."\n"); $string_auth_clean=str_replace(CHR(13).CHR(10),"",$string_auth); fputs($fpdebug,date("j/m/y:H:i").":function decode_pass():\$string_auth_clean: ".$string_auth_clean."\n"); // Decodage de la chaine d'authentification cote serveur avec une cle privee //$commande="/usr/bin/python ".$path_to_wwwse3."/includes/decode.py $string_auth"; $commande="(/usr/bin/python $path_to_wwwse3/includes/decode.py '$string_auth_clean')"; fputs($fpdebug,date("j/m/y:H:i")." : function decode_pass() : \$commande : ".$commande."\n"); unset($AllOutPut); exec ($commande,$AllOutPut,$ReturnValue); // Extraction des parametres //print_r($AllOutPut); $tmp = preg_split ("#\|#",$AllOutPut[0],4); $passwd = $tmp[0]; $ip_src = $tmp[1]; $timestamp = $tmp[2]; //$timestamp=time(); $timewait = $tmp[3]; fputs($fpdebug,date("j/m/y:H:i").":function decode_pass(".$string_auth_clean."):\n\$passwd : ".$passwd." | \$ip_src : ".$ip_src." | \$timestamp : ".$timestamp." | \$timewait : ".$timewait."\n"); $timetotal= $timewait+$timestamp+$MaxLifeTime; fputs($fpdebug,date("j/m/y:H:i").":function decode_pass():\$timetotal : ".$timetotal."\n"); // Interpretation des resultats if ( $ip_src != remote_ip() && time() < $timetotal ) { fputs($fpdebug,date("j/m/y:H:i").":function decode_pass(): ips differentes | ".time()." < timetotal => error=1\n"); $error = 1; } elseif ( time() > $timetotal && $ip_src == remote_ip() ) { fputs($fpdebug,date("j/m/y:H:i").":function decode_pass(): ips identiques | ".time()." > timetotal => error=2\n"); $error = 2; } elseif ( $ip_src != remote_ip() && time() > $timetotal ) { fputs($fpdebug,date("j/m/y:H:i").":function decode_pass(): ips differentes | ".time()." > timetotal => error=3\n"); $error = 3; } fclose($fpdebug); return array ($passwd, $error,$ip_src,$timetotal); } //================================================= /** * Detecte la cle * @Parametres * @Return */ function detect_key_orig() { $myFile = file( "public_key.js"); if ( preg_match("19281203,140977887,4051811,156855586,32904",$myFile[1])) return true; else return false; } ?>