[Php-it] Errore con .htpasswd

Alessandro Marinuzzi alecos_net at libero.it
Wed Sep 5 17:51:53 CEST 2007


David Scatigna ha scritto:
> 1euro al giorno e questo spazio e' tuo. info a ziobudda.net
> ___________FINE_____SPONSOR_______________________________
>
> Cristiano Verondini wrote:
>
>   
>>> Ecco il file modificato ma anche così non funge ;-(
>>>       
>>     Controlla a mano che i file generati abbiano senso. Controlla che 
>> algoritmo di cifratura si aspetta apache e verifica che il tuo crypt() 
>> richieda quell'algoritmo.
>>     
>
> uhm... a memoria credo che su win le pass siano in chiaro
>   
Non criptate intendi? Ma io le genero criptate e quindi inserisco poi in
chiaro nella maschera di autenticazione la pass ma ho dovuto invece
inserire in chiaro la pass criptata... ma perchè succede tutto su win?!?!

Cmq ho aggiornato lo script che adesso genera anche opzionalmente anche
codice per proteggere singoli file...

<?php
if (($_POST['username']) && ($_POST['password'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];
  $denyfile = $_POST['denyfile'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html xml:lang="it" xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Questo script genera i file .htaccess e .htpasswd</title>
</head>
<body>
<?php
if ((substr($_SERVER['DOCUMENT_ROOT'],-1,1) == "/") && (substr($_SERVER['PHP_SELF'],0,1) =="/")) {
  $path = $_SERVER['DOCUMENT_ROOT'] . substr(dirname($_SERVER['PHP_SELF']),1) . "/.htpasswd";
} else {
  $path = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/.htpasswd";}
  if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) {
    $eol = "\r\n";
  } elseif (strtoupper(substr(PHP_OS,0,3) == 'MAC')) {
    $eol = "\r";
  } else {
    $eol = "\n";
  }
  if (!empty($denyfile)) {
    $tmp1 = fopen(".htaccess", "a+");
    $tmp2 .= "AuthType Basic" . $eol;
    $tmp2 .= "AuthName \"Area Protetta\"" . $eol;
    $tmp2 .= "AuthUserFile $path" . $eol;
    $tmp2 .= "<Files " . $denyfile . ">" . $eol;
    $tmp2 .= "Require valid-user" . $eol;
    $tmp2 .= "</Files>" . $eol;
    fwrite($tmp1, $tmp2);
    fclose($tmp1);
    unset($tmp1);
    unset($tmp2);
  } else {
    $tmp1 = fopen(".htaccess", "a+");
    $tmp2 .= "AuthType Basic" . $eol;
    $tmp2 .= "AuthName \"Area Protetta\"" . $eol;
    $tmp2 .= "AuthUserFile $path" . $eol;
    $tmp2 .= "Require valid-user" . $eol;
    fwrite($tmp1, $tmp2);
    fclose($tmp1);
    unset($tmp1);
    unset($tmp2);
  }
  $tmp1 = fopen(".htpasswd", "a+");
  $tmp2 = "$username:" . crypt($password,CRYPT_STD_DES) . $eol;
  fwrite($tmp1, $tmp2);
  fclose($tmp1);
  unset($tmp1);
  unset($tmp2);
  exit("<h2>.htaccess e .htpasswd generati correttamente!</h2>\n</body>\n</html>");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html xml:lang="it" xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Questo script genera i file .htaccess e .htpasswd</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="username">Username</label>: <input type="text" id="username" name="username" /> (Richiesta)</p>
<p><label for="password">Password</label>: <input type="text" id="password" name="password" /> (Richiesta)</p>
<p><label for="denyfile">Nega File</label>: <input type="text" id="denyfile" name="denyfile" /> (Opzionale)</p>
<p><input type="submit" value="Genera i file" /></p>
</form>
</body>
</html>

Spero che a qualcuno sia utile questo script... Ciao e fatemi sapere...

-- 
Alessandro Marinuzzi
--------------------
http://www.alecos.it
--------------------

-------------- parte successiva --------------
Un allegato HTML ? stato rimosso...
URL: http://lists.ziobudda.net/pipermail/php-it/attachments/20070905/72424d76/attachment.htm 


More information about the Php-it mailing list