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

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

$timestamp = time();
## mysql verbindung aufbauen
db_connect($db_host, $db_user, $db_pass);
## /mysql verbindung aufbauen

$prefix = strtolower($prefix);
$domain = strtolower($domain);

$neuedomain = $prefix . "." . $domain;

## Richtige Eingabe?


## so viel darf noch eingerichtet werden
$id = safe_query( "select maxsubdomains, anbieter, wildcard, httpdspezial from kunden where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$maxsubdomains = $werte["maxsubdomains"];
$anbieter = $werte["anbieter"];
$wildcard = $werte["wildcard"];
$httpdspezial = $werte["httpdspezial"];

$id = safe_query( "select domain from domains where richtigedomain='0' and kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$genutztesubdomains = db_num_rows($id);
if ($maxsubdomains != "-1") { $freiesubdomains = $maxsubdomains - $genutztesubdomains; }
else { $freiesubdomains = -1; }
## /so viel darf noch eingerichtet werden

## wildcard schon eingerichtet?
if ($wildcard > 0)
	{
	 $id = safe_query( "select domain from domains where domain like '*.%' and kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
	 $wildcards = db_num_rows($id);
	}
##/

if (($freiesubdomains < 1) && ($freiesubdomains != "-1"))
	{
	 $fehlertext = ltext("todone_error1");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (((istleer($prefix)) || (ereg("[.-]$", $prefix)) || (ereg("^[.-]", $prefix)) || (ereg("[.]{2}", $prefix)) || (ereg("[^a-zA-Z0-9.-]", $prefix))) && ($prefix != "*"))
	{
	 $fehlertext = ltext("todone_error2");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (($prefix == "*") && (($wildcard == 0) || ($wildcards >= $wildcard)) && ($wildcard != -1))
	{
	 $fehlertext = ltext("todone_error3");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (istleer($domain))
	{
	 $fehlertext = ltext("todone_error4");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if ((ereg(" ", $domain)) || (ereg(" ", $pfad)))
	{
	 $fehlertext = ltext("todone_error5");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (istleer($pfad))
	{
	 $fehlertext = ltext("todone_error6");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}
	
if ( ereg("[\n\t\r]", $pfad) )
	{
	 $fehlertext = ltext("todone_error8");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}
		
if (((!ereg("^/", $pfad)) && (!ereg("^http[s]?://", $pfad))) || (ereg("/\.\.", $pfad)))
	{
	 $fehlertext = ltext("todone_error7");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (((ereg("[.]{2}", $pfad)) || (ereg("[^a-zA-Z0-9./~-]", $pfad))) && (!ereg("^http[s]?://", $pfad)))
	{
	 $fehlertext = ltext("todone_error8");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

if (ereg("[\\]", $pfad))
	{
	 $fehlertext = ltext("todone_error9");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}

# existiert die domain
$id = safe_query( "select domain from domains where domain = ?  and kunde = ? ", TRUE, new SQLString( $domain ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)
	{
	 $fehlertext = ltext("todone_error10", array($domain));
	 db_close();
	 include("tools_domains.php");
	 exit();
	}
# /existiert die domain?

# sub-domain schon da?
$id = safe_query( "select domain from domains where domain = ? ", TRUE, new SQLString( $neuedomain ) );
if (db_num_rows($id) > 0) 
	{
	 $fehlertext = ltext("todone_error11");
	 db_close();
	 include("tools_domains.php");
	 exit();
	}
# /sub-domain schon da?

## //

if ((ereg("/$",$pfad)) && ($pfad != "/") && (ereg("^/", $pfad))) { $pfad = substr($pfad,0,-1); }

safe_query( "insert into domains (domain, kunde, anbieter, pfad, richtigedomain, zusatz) VALUES (  ? ,  ? ,  ? ,  ? ,  0,  ?  )", TRUE, new SQLString( $neuedomain ), new SQLString( $PHP_AUTH_USER ), new SQLString( $anbieter ), new SQLString( $pfad ), new SQLString( $httpdspezial ) );

## lastchange für hauptdomain ändern
$timestamp = time();
safe_query( "update domains set lastchange = ?  where domain = ?  and richtigedomain='1' and kunde = ? ", TRUE, new SQLInteger( $timestamp ), new SQLString( $domain ), new SQLString( $PHP_AUTH_USER ) );
## // lastchange für hauptdomain ändern

domain_aendern($neuedomain, "anlegen", $PHP_AUTH_USER);
fpalias_aendern($neuedomain, "anlegen", $PHP_AUTH_USER);

safe_query( "update allgemein set httpd='1'", TRUE );
safe_query( "update kunden set changedomains='1' where kunde = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );

set_countdomains($PHP_AUTH_USER);

$pfad = ""; ##reset für tools_domain.php
$prefix = "";

$fehlertext = ltext("todone_error12", array($neuedomain));
$fehlertitel = ltext("todone_error13");
db_close();
include("tools_domains.php");

?>
