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

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

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

$id = safe_query( "select frontpage, cssl, maxmysql from anbieter where anbieter = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$skfrontpage = $werte["frontpage"];
$skssl = $werte["cssl"];
$maxmysql = $werte["maxmysql"];
if ($maxmysql != 0) $skmysql = 1;

if ($skssl < 1)
	{
	 $fehlertext = ltext("kussak_error1");
	 db_close();
	 include("kunden_start.php");
	 exit();
	}

$id = safe_query( "select ip from ipadressen where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)
	{
	 $fehlertext = ltext("kussak_error2");
	 db_close();
	 include("kunden_ssl.php");
	 exit();
	}

$id = safe_query( "select domain from domains where kunde = ?  and anbieter = ?  and domain = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ), new SQLString( $domain ) );
if (db_num_rows($id) < 1)
	{
	 $fehlertext = ltext("kussak_error3",array($domain));
	 db_close();
	 include("kunden_ssl_erstellen.php");
	 exit();
	}
$id = safe_query( "select * from cssl where kunde = ? ", TRUE, new SQLString( $kunde ) );
if (db_num_rows($id) < 1)
	{
	 safe_query( "insert into cssl (kunde, anbieter, crt, privatekey, aendern) VALUES (  ? ,  ? ,  ? ,  ? ,  0 )", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ), new SQLString( $crt ), new SQLString( $privatekey ) );
	} else
	{
	 safe_query( "update cssl set crt = ? , privatekey = ? , aendern = 0, loeschen = 0 where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $crt ), new SQLString( $privatekey ), new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
	}
exec($bindir."/sslgen.pl $kunde match", $devnull, $status);
if ($status != 0) {
 $fehlertext = ltext("kussak_error5");
 db_close();
 include("kunden_ssl_erstellen.php");
 exit();
}
safe_query( "update cssl set aendern = 1 where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );

$id = safe_query( "select domain from domains where cssl=1 and kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$altedomain = $werte["domain"];
fpalias_aendern($altedomain, "loeschen", $kunde); # ok
safe_query( "update domains set cssl='0' where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
fpalias_aendern($altedomain, "anlegen", $kunde); #ok
fpalias_aendern($domain, "loeschen", $kunde);
safe_query( "update domains set cssl='1' where domain = ?  and kunde = ?  and anbieter = ? ", TRUE, new SQLString( $domain ), new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
fpalias_aendern($domain, "anlegen", $kunde);
safe_query( "update allgemein set httpd='1', cssl='1'", TRUE );
$fehlertext = ltext("kussak_error4",array($domain));

$fehlertitel = ltext("kussak_errortitle");
db_close();
include("kunden_ssl.php");
?>
