Generácia súboru .htaccess
v 1.0
Kód:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
<title>HTACCES</title>
<style>
body {
font-family: Arial, Helvetica;
color: #000000;
font-size: 12px;
}
TD {
font-size: 12px;
}
</style>
</head>
<body>
<h3>Generování .htaccess a .htpasswd</h3>
<?php
$submit = $_REQUEST['submit'];
if (isset ($submit)) {
$nazev = $_REQUEST['nazev'];
$jmeno = $_REQUEST['jmeno'];
$heslo = $_REQUEST['heslo'];
$heslo_crp = crypt($heslo);
$cesta = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - strlen($PHP_SELF));
if (crypt($heslo, $heslo_crp) == $heslo_crp) {
$hta = 'AuthUserFile '.$cesta.'/.htpasswd'."\n".'AuthName "'.$nazev.'"'."\n".'AuthType Basic'."\n".'require valid-user';
?>
<p>Přihlašovací jméno: <strong><?php echo $jmeno; ?></strong><br />
Přihlašovací heslo: <strong><?php echo $heslo; ?></strong></p>
<p>
Obsah souboru <strong>.htaccess</strong><br />
<textarea cols="50" rows="5"><?php echo $hta; ?></textarea>
</p>
<p>
Obsah souboru <strong>.htpasswd</strong><br />
<textarea cols="50" rows="2"><?php echo $jmeno.':'.$heslo_crp; ?></textarea>
</p>
<?php
} else {
echo '<p>Došlo k chybě při šifrování hesla.</p>';
}
echo '<hr />';
}
?>
<form action="<?php echo $PHP_SELF ?>" method="post">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Přihlašovací hlavička: </td>
<td><input type="text" name="nazev" value="Administrace" /></td>
</tr>
<tr>
<td>Jméno:</td>
<td><input type="text" name="jmeno" value="admin" /></td>
</tr>
<tr>
<td>Heslo:</td>
<td><input type="text" name="heslo" value="" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Odeslat" /></td>
</tr>
<table>
</form>
</body>
</html>
Generácia súboru .htaccess
v2.0Kód:
<?php
// Userliste
$userlist = ( isset($_POST['userlist']) ) ? $_POST['userlist'] : '';
if ( isset( $_POST['add'] ) && $_POST['name'] != '' && $_POST['pw'] != '' )
{
$userlist.= $_POST['name'] . ":" . crypt( $_POST['pw'] ) . "\n";
}
// htpasswd
$pw_file = ".htpasswd";
// htaccess
$path = $_SERVER['SCRIPT_FILENAME'];
$path = ereg_replace('/access.php', '', $path);
$acc_start = "AuthUserFile $path/$pw_file\nAuthName Privat\nAuthType Basic\nrequire valid-user";
$acc_file = "./.htaccess";
$access = ( isset($_POST['access']) ) ? $_POST['access'] : $acc_start;
if ( isset( $_POST['save'] ) && $userlist != '' && $access != '' && !( file_exists("./$pw_file") ) && !( file_exists($acc_file) ) )
{
// htpasswd
$file = fopen("./$pw_file", "w+");
if(!fwrite($file, $userlist)) $error = TRUE;
fclose($file);
// htaccess
$file = fopen($acc_file, "w+");
if(!fwrite($file, $access)) $error = TRUE;
fclose($file);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>htaccess Creator</title>
</head>
<body>
<form method="post" action="access.php" name="post">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td><b>.htaccess</b>:</td>
</tr>
<tr>
<td colspan="5"><textarea name="access" rows="7" cols="35" wrap="virtual" style="width:100%" class="post"><?php echo($access) ?></textarea></td>
</tr>
<tr>
<td><b>.htpasswd</b>:</td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" maxlength="80" style="width:200px" /></td>
<td>Passwort:</td>
<td><input type="text" name="pw" maxlength="80" style="width:200px" /></td>
<td><input type="submit" name="add" value="Hinzufügen" /></td>
</tr>
<tr>
<td colspan="5"><textarea name="userlist" rows="7" cols="35" wrap="virtual" style="width:100%" class="post"><?php echo($userlist) ?></textarea></td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Speichern" /></td>
</tr>
</table>
</form>