Warning: fopen(logv.txt): failed to open stream: Permission denied in /home/keonox/www/pyg/ganesha/inc.php on line 61

Warning: fputs(): supplied argument is not a valid stream resource in /home/keonox/www/pyg/ganesha/inc.php on line 62

Warning: fclose(): supplied argument is not a valid stream resource in /home/keonox/www/pyg/ganesha/inc.php on line 63
Addon ProtegeRep
Accueil > Addons > ProtegeRep Contact  | Imprimer  | English translation
Addons ProtegeRep 

(c) PyG : dev@cornalys.com -- v0.1 20/11/2003
Code sous licence GNU/GPL

Objectif

Permet de protéger un repertoire existant par un couple login/pass.

Screenshots / Démonstration

Capture

Procédure d'installation  

INSTALLATION

Copiez le code source (ci-dessous) de la fonction dans un fichier protegerep.php (où tout autre nom) placé dans un dossier /addons/protegeRep/ (vous pouvez utilisez un autre nom par sécurité).

UTILISATION

Appelez la page où vous avez installé l'addon (par ex : http://www.monganesha.com/addons/protegerep/protegerep.php )

Normalement, vous n'avez pas à modifier les 2 premiers champs ("nom de fichier" et "Message").
1- Choisissez le répertoire à protéger dans la liste
2- Entrez un login et un mot passe
3- Cliquez sur "Générer"
4- C'est fait ! Le dossier devrait être protégé.
5- Pour supprimer la protection, supprimez via FTP les 2 fichiers .htaccess et .htpassword dans le dossier incriminé.

Si le dossier est protégé en écriture, une procédure vous explique comment utiliser le contenu des fichiers générés.

LIMITATIONS ET MISE EN GARDE

- ne fonctionne pas sur tous les serveurs : utilise les fonctionnalités .htaccess d'Apache. Par conséquent, votre hébergement doit utiliser Apache comme serveur web.
- cet addon n'a été testé que sur hebergement web linux, il est possible (probable ?) qu'il ne fonctionne pas sur windows (avec easyPHP par exemple). Ne fonctionnera pas non plus sur hébergement Lycos/Multimania.
- un seul couple log/pass maximum (pas de possibilité d'avoir plusieurs utilisateurs avec des logs/pass différents).
- la suppression de la protection doit être faite manuellement.

Aucune garantie n'est fournie quant au bon fonctionnement de cet addon, vous l'utilisez à vos risques et périls.

Bonne utilisation !
Pierre-Yves

 Source  

Téléchargez la source :

<?php
/*
Addon ProtegeRep : Permet de protéger un repertoire existant par login/pass
 
Version 0.1 : 20/11/2003
Licence : GNU/GPL
Auteur : Pierre-Yves Gosset (dev@cornalys.com)
Crédits : cet addon se base sur l'adaptation du code de 2 applications GPL :
    - "Liste répertoire et sous-répertoires" - CILLIER Christophe <c.cillier@snpe.com> - http://www.phpinfo.net/?p=prog&rub=scripts&id=82&src=1
    - "htaccess_generator.php" - laurent goussard <support@phptools4u.com> - http://www.phptools4u.com

Utilisation :
Normalement, vous n'avez pas à modifier les 2 premiers champs ("nom de fichier" et "Message").
1- Choisissez le répertoire à protéger dans la liste
2- Entrez un login et un mot passe
3- Cliquez sur "Générer"
4- C'est fait ! Le dossier devrait être protégé.
5- Pour supprimer la protection, supprimez via FTP les 2 fichiers .htaccess et .htpassword dans le dossier incriminé.

Si le dossier est protégé en écriture, une procédure vous explique comment utiliser le contenu des fichiers générés
Limitations : 
- ne fonctionne pas sur tous les serveurs : utilise les fonctionnalités .htaccess d'Apache. Par conséquent, votre hébergement doit 
  utiliser Apache comme serveur web.
-cet addon n'a été testé que sur hebergement web linux, il est possible (probable ?) qu'il ne fonctionne 
  pas sur windows (avec easyPHP par exemple). Ne fonctionnera pas non plus sur 
  hébergement Lycos/Multimania.
- un seul couple log/pass maximum (pas de possibilité d'avoir plusieurs utilisateurs avec des logs/pass différents).
- la suppression de la protection doit être faite manuellement.

*/


// ------------------------------------------------------------------------- //
// Liste répertoire et sous-répertoire                                       //
// ------------------------------------------------------------------------- //
// Auteur: CILLIER Christophe <c.cillier@snpe.com>                           //
// Web:                                                                      //
// ------------------------------------------------------------------------- //

/*
Modification du script de François BAUD de ce site :
  
  http://www.phpinfo.net/?p=prog&rub=scripts&id=82&src=1

Evolution : correction de certains petits bugs, notamment si un répertoire 
contient des fichiers et des répertoires certains fichiers n'étaient pas affichés
dans le bon répertoire.
De plus maintenant repertoires et fichiers sont par ordre alphabetique.
*/

$VAL 0;

function 
space ($VAL) {
    for (
$i $i <= $VAL $i++) {
        print (
"\t") ;
    }
}

function 
recurse_dir ($DIR$CORE)
{
    global 
$VAL ;
    
space ($VAL) ;
        global 
$Arrayrep;
    global 
$urllook;
    
$urllooklong=strlen $urllook);

    if (
$ODIR opendir($DIR))
    {
        while (
$FILE readdir($ODIR))
        {
            if ( (
$FILE != ".") && ($FILE != "..") )
            {
                
$TMP $DIR."/".$FILE ;
                if (
is_dir($TMP))
                {
                    
$VAL++ ;
                    
recurse_dir ($TMP$FILE) ;
                    
$fullurl=$DIR."/".$FILE;
                    
$Arrayrep[]= $fullurl;
                    
$VAL-- ;
                }
                else
                {
                    
space ($VAL+1) ;
                    if (
substr($FILE,0,4)=="thm_") {
                    }
                }
            }
        }
    }
    else
    {
        
printf ("Unable to open directory") ;
    }
}

$urllook=$_SERVER['DOCUMENT_ROOT'];
recurse_dir($urllook"") ;

sort($Arrayrep); 
$Max count($Arrayrep);

// ------------------------------------------------------------------------- //
// Fin Liste répertoire et sous-répertoire                                       //
// ------------------------------------------------------------------------- //

/***************************************************************************
             ____  _   _ ____  _              _     _  _   _   _
            |  _ \| | | |  _ \| |_ ___   ___ | |___| || | | | | |
            | |_) | |_| | |_) | __/ _ \ / _ \| / __| || |_| | | |
            |  __/|  _  |  __/| || (_) | (_) | \__ \__   _| |_| |
            |_|   |_| |_|_|    \__\___/ \___/|_|___/  |_|  \___/
            
                       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['papath'].$vars['htpasswd']."\n";
    
    
$out .= 'AuthName "'.$vars['domaine'].'"'."\n";
    
$out .= 'AuthType Basic'."\n\n";

    
$out .= '<limit GET POST>'."\n";
    
$out .= 'require valid-user'."\n";
    
$out .= '</limit>';

    return 
$out;
}

function 
display_file($pass){
    Global 
$_POST;
    
    
$out 'Il semble que l\'écriture soit vérouillée sur ce serveur...<br>PHP n\'a pas pu écrire les fichier et vous allez devoir le faire vous-même :<br><br>';
    
$out .= 'Enregistrez le contenu ci-dessous dans un fichier nommé .htaccess';
    
$out .= ' et placez ce fichier dans le dossier '.$_POST['papath'].' via FTP<br>';
    
$out .= '<p>NB : sous Windows, il est possible que vous ne puissiez pas cr&eacute;er un 
  fichier commencant par un point.<br>  Dans ce cas, nommez les fichiers &quot;htpassword.txt&quot; et &quot;htaccess.txt&quot;, 
  copiez-y les contenus, puis renommez-le en &quot;.htpassword&quot; et &quot;.htaccess&quot; 
  avec votre soft FTP une fois en ligne. Faites tr&egrave;s attention &agrave; 
  l\'orthographe et n\'oubliez pas le point pr&eacute;c&eacute;dant le nom de fichier !!</p>'
;
    
$out .= '<textarea name="access" cols="80" rows="10" class="trou">';
    
$out .= gen_htaccess($_POST);
    
$out .= '</textarea>';
    
$out .= '<br><br>';
    
$out .= 'Enregistrez le contenu ci-dessous dans un fichier '.$_POST['papath'].$_POST['htpasswd'].'<br>';
    
$out .= '<textarea name="passwd" cols="80" rows="10" class="trou">';
    
$out .= $_POST['login'].':'.$pass['pwd'];
    
$out .= '</textarea><br>';
    
    return 
$out;
}

function 
save_file($fichier$contenu){
    
$fp = @fopen($fichier"w+");
    if(!
$fp){
        
$out FALSE;
    }else{
        
fputs($fp$contenu);
        
fclose($fp); 
        
$out $fichier.' enregistr&eacute;';
    }
    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;
}

?> 
<html>
<head>
<title>.htaccess</title>
<style type="text/css">
<!--
.titre {
    border: 2px groove #FFFFFF;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #3C466F;
    text-align: center;
}
.normal {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    background-color: #B8C8FF;
    border: 2px groove #FFFFFF;
}
input {
    border: 1px solid #999999;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
}
.msg {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    background-color: #B8C8FF;
    border: 2px groove #FFFFFF;
}
.trou {
    border: 1px solid #999999;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
}
-->
</style>
<script language="JavaScript">
    function valide() {
            if (generateur.papath.options[generateur.papath.options.selectedIndex].value == "---" )   {       
                alert ("Vous devez choisir un chemin !");              
                return false;   
            } 
            if (generateur.login.value == "" )   {       
                alert ("Vous devez choisir un login !");              
                return false;   
            }
            if (generateur.passwd.value == "" )   {       
                alert ("Le mot de passe ne peut être vide !");              
                return false;   
            } 
        return true;
    }
</script>
</head>
<body bgcolor="#5A6BA5" text="#333333">
<form action="<? echo $_SERVER['REQUEST_URI'?>" method="POST" name="generateur">
  <table width="400" border="0" align="center" cellpadding="5" cellspacing="0" class="titre">
    <tr> 
      <td>ProtegeRep :<br>
        G&eacute;n&eacute;rateur de fichier .htaccess/.htpasswd</td>
    </tr>
  </table>  <br>
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="30%">nom du fichier de mot de passe </td>
      <td width="70%" align="center"> <div align="right">
          <input name="htpasswd" type="text" value=".htpasswd" size="30">
        </div></td>
    </tr>
  </table>
  <br>
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="12%">Message</td>
      <td width="88%" align="center"> <div align="right">
          <input name="domaine" type="text" value="Authentification" size="30">
        </div></td>
    </tr>
  </table>
  <br>
  <!--
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="16%">Chemin de base<br>
      </td>
      <td width="84%" align="center"> <div align="right">
          <input name="base_path" type="text" id="base_path" value="<?php echo $_SERVER['DOCUMENT_ROOT']."/"?>" size="60" disabled>
        </div></td>
    </tr>
  </table>
  <br>
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="18%">Chemin &agrave; prot&eacute;ger<br> </td>
      <td width="82%" align="center"> <div align="right">
          <input name="protect_path" type="text" id="protect_path" value="addons" size="60" disabled>
        </div></td>
    </tr>
  </table>
  <br>
  -->
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="18%">Chemin &agrave; prot&eacute;ger<br> </td>
      <td width="82%" align="center"> <div align="right">

            <select name="papath">
                <option value="---" selected>Choisissez un dossier à protéger</option>
            <?php
                
for($i 0$i <$Max$i++) {
                        
$urlpath=$Arrayrep[$i];
                    echo 
"<option value=\"".$urlpath."/"."\">".$urlpath."/"."</option>";
                }        
            
?>
          </select>

        </div></td>
    </tr>
  </table>
  <br>
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="6%">login</td>
      <td width="94%" align="center"> <div align="right">
          <input name="login" type="text" size="30">
        </div></td>
    </tr>
  </table>
  <br>
  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="normal">
    <tr> 
      <td width="15%">mot de passe </td>
      <td width="85%" align="center"> <div align="right">
          <input name="passwd" type="text" size="30">
        </div></td>
    </tr>
  </table>
  <br>
  <center>
    <input name="Submit" type="reset" value="R&eacute;tablir" id="Submit2">
    <input name="Submit" type="submit" value="G&eacute;n&eacute;rer" id="Submit2" onclick="return valide()">
  </center>
</form>
<?php
/*
if(isset($_GET['rep'])){
    $_POST['path'] = $_GET['rep'];
}else{
    //$nom = 'export_htaccess';
    $nom_path = $_POST['base_path'];
    if( ereg('win', strtolower($_SERVER['SERVER_SOFTWARE']) ) ){
        $_POST['path'] = getcwd().'\\'.$nom.'\\';
    }else{
        $_POST['path'] = getcwd().'/'.$nom.'/';
    }
    if(!is_dir($_POST['path'])){
        @mkdir($_POST['path']);
    }
}
*/

if ( (isset($_POST['login'])) && ($_POST['papath']!="---") ) {
    
$pass set_pass();
    
    
$res_htac save_file($_POST['papath'].'.htaccess'gen_htaccess($_POST));
    
$res_htpa save_file($_POST['papath'].$_POST['htpasswd'], $_POST['login'].':'.$pass['pwd']);
    
    if(
$res_htac == FALSE){
        
$res_htac display_file($pass);
    }

    
    echo 
'  <table width="640" border="0" align="center" cellpadding="2" cellspacing="0" class="msg">'."\n";
    echo 
'    <tr> '."\n";
    echo 
'      <td colspan="2">'."\n";
    echo 
$res_htac;
    echo 
'<br>';
    echo 
$res_htpa;
    echo 
'<br>';
    echo 
'<i>'.$pass['msg'].'</i>';
    echo 
'<br>';
    echo 
'      </td>'."\n";
    echo 
'    </tr>'."\n";
    echo 
'  </table>'."\n";

}else{
    
$_POST['login'] = '';
    
$_POST['passwd'] = '';
}
?> 
</body>
</html>

Accueil > Addons > ProtegeRep Contact  | Imprimer  | English translation