<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once("auth.php");
include_once( "../include/class.SQLInteger.php" );
include_once( "../include/class.SQLString.php" );

if (istleer($pfad))	{
	$fehlertext = ltext("topwne2_error1");
	include("tools_pwschutz_neu.php");
	exit();
			}

while (ereg("/$", $pfad))
	{
	 $pfad = substr($pfad, 0, -1);
	}

while (ereg("^/", $pfad))
	{
	 $pfad = substr($pfad, 1, (strlen($pfad) -1));
	}

$pfad = ereg_replace("/+", "/", $pfad);

if (substr($pfad, 0, 1) != "/") $pfad = "/".$pfad;
$dir = "/$PHP_AUTH_USER/html".$pfad;
exec($bindir."/lsdir.pl ".$dir, $devnull, $status);

if (($status != 0) || (ereg("\.\./", $pfad)) || (ereg("\.\.$", $pfad)))
	{
	 $fehlertext = ltext("topwne2_error2", array($pfad));
	 include("tools_pwschutz_neu.php");
	 exit();
	}

if ((ereg("[^A-Za-z0-9 ]", $bereich)) || (strlen($bereich) > 20))	{
	$fehlertext = ltext("topwne2_error3");
	include("tools_pwschutz_neu.php");
	exit();
									}

if ($bereich == "") { // to prevent error500
    $bereich = "secure";
}

if ((ereg("[^A-Za-z0-9 ]", $login)) || (strlen($login) > 35))	{
	$fehlertext = ltext("topwne2_error4");
	include("tools_pwschutz_neu.php");
	exit();
								}

if (!valid_pw($pass1))	{
	$fehlertext = ltext("topwne2_error5");
	include("tools_pwschutz_neu.php");
	exit();
											}

if ($pass1 != $pass2)	{
	$fehlertext = ltext("topwne2_error6");
	include("tools_pwschutz_neu.php");
	exit();
			}


db_connect($db_host, $db_user, $db_pass);

## prüfen, ob verzeichnis schon mit pw geschützt
if ($db_type = 'mysql') {
	$sql = "select * from pwschutz where kunde = ? and BINARY pfad = ?";
} else {
	$sql = "select * from pwschutz where kunde = ? and pfad = ?";
}

$id = safe_query( $sql, TRUE, new SQLString( $PHP_AUTH_USER ), new SQLString( $pfad ) );
if (db_num_rows($id) > 0)	{
	$fehlertext = ltext("topwne2_error7");
	db_close();
	include("tools_pwschutz_neu.php");
	exit();
				}
## //

## anbieter ermitteln
$id = safe_query( "select anbieter from kunden where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$anbieter = $werte["anbieter"];

$id = safe_query( "insert into pwschutz (pfad, bereich, kunde, anbieter) VALUES (  ? ,  ? ,  ? ,  ?  )", TRUE, new SQLString( $pfad ), new SQLString( $bereich ), new SQLString( $PHP_AUTH_USER ), new SQLString( $anbieter ) );
$ident = db_insert_id($id, "seq_pwschutz");
$pass = crypt_pw($pass1);
safe_query( "insert into users (login, pass, longpw, parent, kunde) VALUES (  ? ,  '',  ? ,  ? ,  ?  )", TRUE, new SQLString( $login ), new SQLString( $pass ), new SQLInteger( $ident ), new SQLString( $PHP_AUTH_USER ) );
$id = safe_query( "select * from htaccess where pfad = ?  and kunde = ? ", TRUE, new SQLString( $pfad ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)	{
safe_query( "insert into htaccess (pfad, kunde) VALUES (  ? ,  ?  )", TRUE, new SQLString( $pfad ), new SQLString( $PHP_AUTH_USER ) );
				}

safe_query( "update allgemein set htaccess='1'", TRUE );
db_close();

$fehlertitel = ltext("topwne2_errortitle");
$fehlertext = ltext("topwne2_error8");
$pfad = "";
$bereich = "";
$login = "";
$pass = "";
include("tools_pwschutz.php");
exit();
?>
