Code: Select all
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$dir = $uname;
$user = $_POST['user'];
$pass = $_POST['pass'];
// current list
$thisdir = str_replace(strrchr($_SERVER['SCRIPT_FILENAME'],'/'), '', $_SERVER['SCRIPT_FILENAME']);
// What the list should provide
$oldumask = umask(0);
mkdir($dir,0777);
umask($oldumask);
// Daten für .htaccess erstellen
$htaccess = 'AuthType Basic
AuthUserFile '.$thisdir.'/'.$dir.'/.htpasswd
AuthName "Geschuetzer Bereich"
order deny,allow
allow from all
require valid-user';
// data for htpassword
$htpasswd = $uname.':'.crypt($pw, substr(md5(uniqid(rand())), 0, 2));
// Testdatei erstellen (wird angezeigt beim erfolgreichen Login)
$handle = fopen($dir.'/index.php', 'w');
fwrite($handle, '
<?
echo "Hier sind die Bereitgestellten Dateien<br><br>";
$action=opendir("./");
while($datei=readdir($action)){
if(!preg_match("!(\.|\..)$!", $datei)){
if ($datei!="index.php" && $datei!=".htaccess" && $datei!=".htpasswd" ) {
echo "
<a href=\"$datei\">
$datei</a><br>"; } } } ?>');
fclose($handle);
// .htaccess data
$handle = fopen($dir.'/.htaccess', 'w');
fwrite($handle, $htaccess);
fclose($handle);
// .htpasswd data
$handle = fopen($dir.'/.htpasswd', 'w');
fwrite($handle, $htpasswd);
fclose($handle);
?>
</body>
</html>
ps. I didnt write this code... a contractor before I arrived did