/***************************************************************************
____ _ _ ____ _ _ _ _ _ _
| _ \| | | | _ \| |_ ___ ___ | |___| || | | | | |
| |_) | |_| | |_) | __/ _ \ / _ \| / __| || |_| | | |
| __/| _ | __/| || (_) | (_) | \__ \__ _| |_| |
|_| |_| |_|_| \__\___/ \___/|_|___/ |_| \___/
htaccess_generator.php - An .htaccess/ htpasswd counter
-------------------
begin : Fri Feb 21 2003
copyright : (C) 2001 PHPtools4U.com - laurent goussard
email : support@phptools4u.com
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
//error_reporting(E_ALL);
function gen_htaccess($vars){
Global $_SERVER;
$vars['htpasswd'] = (isset($vars['htpasswd'])) ? $vars['htpasswd'] : '.htpasswd';
$vars['domaine'] = (isset($vars['domaine'])) ? stripslashes($vars['domaine']) : 'Oui, qui c\'est ?';
$out = 'AuthUserFile ';
$out .= $vars['path'].$vars['htpasswd']."\n";
$out .= 'AuthName "'.$vars['domaine'].'"'."\n";
$out .= 'AuthType Basic'."\n\n";
$out .= '
PHP n\'a pas pu écrire les fichier et vous allez devoir le faire vous-même :
';
$out .= 'Enregistrer le contenu ci-dessous dans un fichier .htaccess
(attention, le chemin vers le fichier '.$_POST['htpasswd'].' pointe vers un répertoire "export_htaccess" qui n\'existe surement pas... Il faudra modifier ce chemin...)
';
$out .= '';
$out .= '
';
$out .= 'Enregistrer le contenu ci-dessous dans un fichier '.$_POST['htpasswd'].'
';
$out .= '
';
return $out;
}
function save_file($fichier, $contenu){
$fp = @fopen($fichier, "w+");
if(!$fp){
$out = FALSE;
}else{
fputs($fp, $contenu);
fclose($fp);
$out = $fichier.' enregistré';
}
return $out;
}
function set_pass(){
Global $_SERVER,$_POST;
if( ereg('win', strtolower($_SERVER['SERVER_SOFTWARE']) ) ){ // Windows
$pass['pwd'] = $_POST['passwd'];
$pass['msg'] = 'Mot de passe non encrypté (incompatibilité d\'encryption entre PHP et Apache sous Windows®...)';
}else{ // DES
$salt = substr($_POST['passwd'],0,2);
$pass['pwd'] = crypt($_POST['passwd'], $salt);
$pass['msg'] = 'Mot de passe encrypté en DES (serveur Unix)';
}
return $pass;
}
?>
|
Fichier : Fichier .htaccess: |