<?
########## 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");
include("../languages/".$shortlang."/scripts.inc.php");

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

$id = safe_query( "select cssl from anbieter where anbieter = ? ", TRUE, new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$skssl = $werte["cssl"];

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

## prüfen, ob kunde eigene ip adresse hat
$id = safe_query( "select * from ipadressen where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
if (db_num_rows($id) < 1)
	{
	 $fehlertext = ltext("kusser_error2", array($kunde));
	 db_close();
	 include("kunden_ssl.php");
	 exit();
	}
## //

## daten in Datenbank schreiben
$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, aendern, countrycode, state, city, firm, unit, email, common) ".
							"VALUES (  ? ,  ? ,  1,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ?  )", TRUE, 
							new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ), new SQLString( $countrycode ), 
							new SQLString( $state ), new SQLString( $city ), new SQLString( $firm ), new SQLString( $unit ), 
							new SQLString( $email ), new SQLString( $common ) );
} else {
	safe_query( "update cssl set aendern=1, loeschen=0, countrycode = ? , state = ? , city = ? , firm = ? , ".
							"unit = ? , email = ? , common = ?  where kunde = ?  AND anbieter = ? ", TRUE, 
							new SQLString( $countrycode ), new SQLString( $state ), new SQLString( $city ), 
							new SQLString( $firm ), new SQLString( $unit ), new SQLString( $email ), new SQLString( $common ), 
							new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
}

$cmd = $bindir."/sslgen.pl $kunde $selfsigned";
exec($cmd, $crs, $status);

if ( $status != 0 )	{
	 db_close();
	 $fehlertext = mlf_text($crs[0]);
	 include("kunden_ssl_erstellen2.php");
	 exit();
}

if ( $selfsigned ) {
	db_close();
	include( "kunden_ssl_erstellen.php" );
	exit();
}


$id = safe_query( "select privatekey, csr from cssl where kunde = ?  and anbieter = ? ", TRUE, new SQLString( $kunde ), new SQLString( $PHP_AUTH_USER ) );
$werte = db_fetch_array($id);
$privatekey = $werte["privatekey"];
$csr = $werte["csr"];
?>
<HTML>
<HEAD>
<META content="text/html; charset=<? echo $lang_html_charset; ?>" http-equiv=Content-Type>
<LINK href="<?=$strSkinName?>/style.css" rel=stylesheet type=text/css>
</HEAD>

<BODY bgColor=#ffffff bottomMargin=0 leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<br><? include("../fehler.inc.php"); ?>
<script>
<?
echo js_f_call_help('', 'kusser3_title1');
?>
function doChange()
{
document.forms[0].submit();
}
</script>
<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
      <form action="kunden_ssl_senden.php" method="post">
          <tr>
            <td class="titel-3" >
              <? echo ltext("kusser3_cell_privatekey"); ?>
              </td>
          </tr>
          <tr>
            <td>
              <? echo nl2br($privatekey); ?>
              <input type="hidden" value="$privatekey" name="privatekey">
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td class="titel-3" >
              <? echo ltext("kusser3_cell_crs"); ?>
              </td>
          </tr>
          <tr bgcolor="<? echo $color_light_grey; ?>"> 
            <td height="15">
              <? echo nl2br($csr); ?>
              <input type="hidden" value="$csr" name="csr">
              </td>
          </tr>
      </form>
</TABLE>
</BODY>
</HTML>
<?
db_close();
?>
