hash = $CryptKey;

if ( (!isset($Action)) || ($Action == “”) ) {
print “Es wurde das Feld Action nicht übermittelt!”;
exit;
}

if (($EMailText == “”) || ($EMailSubject == “”)) {
print “Fehler es ist kein E-Mail-Text oder kein Betreff für die Bestätigungs-E-Mail vorhanden.”;
exit;
}

if ( (isset($EMail)) && ($Action==”confirmation”) ) {

if(isset($CryptKeyFile) && $CryptKeyFile != “”) {
$crypt->hash = GetCryptKey($CryptKeyFile, $EMail);
if(!$crypt->hash) {
if ($CryptKeyErrorPage != “”)
header(“Location: $CryptKeyErrorPage”);
else
print “Die uebergebene E-Mai-Adresse befindet sich nicht (mehr) zur Bestätigung im Verteiler.“;
exit;
}
}

$EMail = $crypt->phpDecrypt($EMail);
}

if ( (!isset($EMail)) || ($EMail == “”) || ( !CheckEMail($EMail) ) ) {
if ($ErrorPage != “”)
header(“Location: $ErrorPage”);
else
print “Es wurde keine E-Mail-Adresse angegeben oder die E-Mail-Adresse liegt nicht im korrekten Format vor!“;
exit;
}

if ($Action==”edit”) {
if(!isset($NewEMail))
$NewEMail = $EMail; // alte E-Mail
else {
if ( ($NewEMail == “”) || ( !CheckEMail($NewEMail) ) ) {
if ($ErrorPage != “”)
header(“Location: $ErrorPage”);
else
print “Die E-Mail-Adresse liegt nicht im korrekten Format vor!“;
exit;
}
}
}

##################################### Spam test
$teststring=””;
reset ($_GET);
while (list ($key, $val) = each ($_GET)) {
$teststring .= “$key=$val”;
}

reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
$teststring .= “$key=$val”;
}

if (CheckForSpam($teststring) == 1) {
print “Error processing form data”;
exit;
}
#####################################

if ($Action == “unsubscribe” && !empty($UnsubscribeConfirmationPage)) {
$page = join(“”, file($UnsubscribeConfirmationPage));

if(!empty($page)){
$var = array_merge($_GET, $_POST);

$html = “”;
$var[“Action”] = “unsubscribe_confirm”;
foreach($var as $key => $value) {
if ($key == “SubmitBtn”) continue;
$html .= ‘‘;
}

if(function_exists(“str_ireplace”))
$page = str_ireplace(“

“, $html.”

“, $page);
else
$page = str_replace(“

“, $html.”

“, $page);

if (empty($SERVER_NAME)) {
$SERVER_NAME = $_SERVER[‘SERVER_NAME’];
}

if (empty($SCRIPT_NAME)) {
$SCRIPT_NAME = $_SERVER[‘SCRIPT_NAME’];
}

$Script = “http://”.$SERVER_NAME.$SCRIPT_NAME;
$page = str_replace(‘action=””‘, ‘action=”‘.$Script.'”‘, $page);

print $page;
exit;
}

}

if ($Action == “subscribe”) {
$headers = “From: $Recipient”.$CRLF;
$headers .= “Return-Path: <$Recipient>“.$CRLF;

if (empty($SERVER_NAME)) {
$SERVER_NAME = $_SERVER[‘SERVER_NAME’];
}

if (empty($SCRIPT_NAME)) {
$SCRIPT_NAME = $_SERVER[‘SCRIPT_NAME’];
}

$message = join(“”, file($EMailText));

if($message == “”) {
$s = substr (strrchr ($EMailText, “/”), 1);
$message = join(“”, file($s));
}

$isUTF8 = IsUTF8String($message);

if(isset($CryptKeyFile) && $CryptKeyFile != “”) {
if(!AddNewCryptKey($CryptKeyFile, $EMail, $CryptKey))
exit;
}

$Link = “http://”.$SERVER_NAME.$SCRIPT_NAME.”?Action=confirmation&EMail=”.urlencode($crypt->phpEncrypt($EMail));

#Fuer weitere Felder, diesen muessen im HTML-Formular und im SuperMailer angelegt werden!

$s=””;
reset ($_GET);
while (list ($key, $val) = each ($_GET)) {
if ($key == “EMail”) continue;
if ($key == “Action”) continue;
if ($key == “SubmitBtn”) continue;

$pos = strpos ($key, “[]”);
if ($pos !== false) {
$key = substr($key, 0, $pos – 1);
}

if (is_array($val)) { # RG as array?
if($s == “”)
$s = “$key=”.urlencode($crypt->phpEncrypt(join(“;”, $val)));
else
$s .= “&$key=”.urlencode($crypt->phpEncrypt(join(“;”, $val)));
} else {
if($s == “”)
$s = “$key=”.urlencode($crypt->phpEncrypt($val));
else
$s .= “&$key=”.urlencode($crypt->phpEncrypt($val));
}
}

reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
if ($key == “EMail”) continue;
if ($key == “Action”) continue;
if ($key == “SubmitBtn”) continue;

$pos = strpos ($key, “[]”);
if ($pos !== false) {
$key = substr($key, 0, $pos – 1);
}

if (is_array($val)) { # RG as array?
if($s == “”)
$s = “$key=”.urlencode($crypt->phpEncrypt(join(“;”, $val)));
else
$s .= “&$key=”.urlencode($crypt->phpEncrypt(join(“;”, $val)));
} else {
if($s == “”)
$s = “$key=”.urlencode($crypt->phpEncrypt($val));
else
$s .= “&$key=”.urlencode($crypt->phpEncrypt($val));
}
}

if($s != “”)
$Link .= “&”.$s;

if(!$isUTF8)
$headers .= “Content-type: text/plain; charset=$WebsiteContentCharset”.$CRLF;
else
$headers .= “Content-type: text/plain; charset=utf-8”.$CRLF;

$message = str_replace (“[BESTAETIGUNGSLINK]”, $Link, $message);
$message = str_replace (“[CONFIRMATIONLINK]”, $Link, $message);
if(!@mail($EMail, $EMailSubject, $message, $headers)){
print “Can’t send email, PHP mail() must be configured properly.”;
exit;
}

if ($ConfirmationMailSendOKPage != “”)
header(“Location: $ConfirmationMailSendOKPage”);
else
print “Ihnen wurde eine E-Mail an die E-Mail-Adresse $EMail mit einem Bestätigungslink zur Aufnahme in unseren Newsletter gesendet.
Bitte klicken Sie in dieser E-Mail auf den Bestätigungslink, damit Ihre E-Mail-Adresse in unseren Newsletter aufgenommen wird.
“;

exit;
}

# Aufruf ueber Bestaetigungs-E-Mail
if ($Action==”confirmation”) {
$Action=”subscribe”;
}

# Aufruf ueber Abmeldebestaetigungsseite
if ($Action==”unsubscribe_confirm”) {
$Action=”unsubscribe”;
}

$headers = “From: $EMail”.$CRLF;
$headers .= “Return-Path: <$EMail>“.$CRLF;
$headers .= “Content-type: text/plain; charset=$WebsiteContentCharset”.$CRLF;

# Alle uebergebenen Werte in die Nachricht uebernehmen
$message = “”;

reset ($_GET);
while (list ($key, $val) = each ($_GET)) {
if ($key == “Action”) continue;
if ($key == “SubmitBtn”) continue;
if ($Action == “subscribe”)
$message .= “$key: “.$crypt->phpDecrypt($val).”n”;
else {

if (is_array($val)) # RG as array?
$message .= “$key: “.join(“;”, $val).”n”;
else
$message .= “$key: “.$val.”n”;
}
}

reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
if ($key == “Action”) continue;
if ($key == “SubmitBtn”) continue;
if ($Action == “subscribe”)
$message .= “$key: “.$crypt->phpDecrypt($val).”n”;
else {

if (is_array($val)) # RG as array?
$message .= “$key: “.join(“;”, $val).”n”;
else
$message .= “$key: “.$val.”n”;
}
}
$message .= “IP: “.$REMOTE_ADDR.”n”;
$message .= “DateTime: “.strftime(“%x %X”).”n”;

# Versenden der Mail
if(!@mail($Recipient, $Action, $message, $headers)) {
print “Can’t send email {2}, PHP mail() must be configured properly.”;
exit;
}

if ($Action == “edit”)
if ($EditOKPage != “”)
header(“Location: $EditOKPage”);
else
print “Vielen Dank für die Mitteilung der Änderungen!“;
else
if ($Action == “subscribe”)
if ($SubscribeOKPage != “”)
header(“Location: $SubscribeOKPage”);
else
print “Ihre E-Mail-Adresse $EMail wurde zu unserer Newsletterliste hinzugefügt!“;
else
if ($UnsubscribeOKPage != “”)
header(“Location: $UnsubscribeOKPage”);
else
print “Ihre E-Mail-Adresse $EMail wurde aus unserer Newsletterliste entfernt!“;

// ##################################################################################

function IsUTF8String($str) {
$len = strlen($str);
for($i = 0; $i < $len; $i++){ $c = ord($str[$i]); if ($c > 128) {
if (($c > 247)) return false;
elseif ($c > 239) $bytes = 4;
elseif ($c > 223) $bytes = 3;
elseif ($c > 191) $bytes = 2;
else return false;
if (($i + $bytes) > $len) return false;
while ($bytes > 1) {
$i++;
$b = ord($str[$i]);
if ($b < 128 || $b > 191) return false;
$bytes–;
}
}
}
return true;
}

class EncDec{

var $hash;

function hexToInt($s, $i)
{

(int)$j = $i * 2;
(string)$s1 = $s;
(string)$c = substr($s1, $j, 1); // get the char at position $j, length 1
(string)$c1 = substr($s1, $j+1, 1); // get the char at postion $j + 1, length 1
(int)$k = 0;

switch ($c)
{

case “A”:
$k += 160;
break;

case “B”:
$k += 176;
break;

case “C”:
$k += 192;
break;

case “D”:
$k += 208;
break;

case “E”:
$k += 224;
break;

case “F”:
$k += 240;
break;

case ” “:
$k += 0;
break;

default:

(int)$k = $k + (16 * (int)$c);
break;
}

switch ($c1)
{

case “A”:
$k += 10;
break;

case “B”:
$k += 11;
break;

case “C”:
$k += 12;
break;

case “D”:
$k += 13;
break;

case “E”:
$k += 14;
break;

case “F”:
$k += 15;
break;

case ” “:
$k += 0;
break;

default:

$k += (int)$c1;
break;
}

return $k;
}

function hexToIntArray($s)
{
(string)$s1 = $s;
(int)$i = strlen($s1);
(int)$j = $i / 2;
for($l = 0; $l < $j; $l++) { (int)$k = $this->hexToInt($s1,$l);
$ai[$l] = $k;
}

return $ai;
}

function charToInt($c)
{
$ac[0] = $c;
return $ac;
}

function xorString($ai)
{
$s = $this->hash; //
(int)$i = strlen($s);
$ai1 = $ai;
(int)$j = count($ai1);
for($i = 0; $i < $j; $i = strlen($s)) $s = $s.$s; for($k = 0; $k < $j; $k++) { (string)$c = substr($s,$k,1); $ac[$k] = chr($ai1[$k] ^ ord($c)); } (string)$s1 = implode('', $ac); return $s1; } function phpDecrypt($s) { { $ai = $this->hexToIntArray($s);
(string)$s1 = $this->xorString($ai);
return $s1;
}
}

function intToHex($i)
{
(int)$j = (int)$i / 16;
if ((int)$j == 0) {
(string)$s = ” “;
}
else
{
(string)$s = strtoupper(dechex($j));
}
(int)$k = (int)$i – (int)$j * 16;
(string)$s = $s.strtoupper(dechex($k));

return $s;
}

function xorCharString($s)
{
$ac = preg_split(‘//’, $s, -1, PREG_SPLIT_NO_EMPTY);
(string)$s1 = $this->hash;
(int)$i = strlen($s1);
(int)$j = count($ac);
for($i=0; $i < $j; $i = strlen($s1)) { $s1 = $s1.$s1; } for($k = 0; $k < $j; $k++) { $c = substr($s1,$k,1); $ai[$k] = ord($c) ^ ord($ac[$k]); } return $ai; } function phpEncrypt($s) { $ai = $this->xorCharString($s);
$s1 = “”;
for($i = 0; $i < count($ai); $i++) $s1 = $s1.$this->intToHex((int)$ai[$i]);
return $s1;
}

}

function GetCryptKey($CryptKeyFile, $EncryptedEMail) {
global $CryptKey, $CryptKeyExpiresInterval;
$EncryptedEMail = urlencode($EncryptedEMail);
if($CryptKeyFile == “”)
return $CryptKey;
$fp = fopen($CryptKeyFile, “r”);
if(!$fp)
return “”;

$contents = “”;
while (!feof($fp)) {
$buffer = fgets($fp, 4096);
$contents .= $buffer;
}

$a = split(“n”, $contents);
$key = “”;
$expiredItems = false;
for($i=count($a) – 1; $i>=0; $i–) {
if(trim($a[$i]) == “”) {
continue;
}
$b = split(“|”, $a[$i]);
if(count($b) < 3) { unset($a[$i]); $expiredItems = true; continue; } if($b[0] == $EncryptedEMail) { $key = $b[1]; unset($a[$i]); $expiredItems = true; continue; } if( time() >= $b[2] + ($CryptKeyExpiresInterval * 24 * 60 * 60) ) {
unset($a[$i]);
$expiredItems = true;
}
}

fclose($fp);
if($expiredItems) {
$fp = fopen($CryptKeyFile, “w”);
if($fp) {
fwrite($fp, join(“n”, $a));
fclose($fp);
}
}

return $key;
}

function AddNewCryptKey($CryptKeyFile, $EMail, &$CryptKey) {
global $crypt;
$fp = fopen($CryptKeyFile, “a”);
if(!$fp) {
print “Kann in Datei $CryptKeyFile nicht schreiben.
Can’t write to file $CryptKeyFile.”;
return false;
}

srand ((double)microtime()*1000000);
$CryptKey = strftime(rand().”%D%H%I%j%m%M%p%S%u”);
$CryptKey = str_replace(“|”, “-“, $CryptKey);
$CryptKey = str_replace(“n”, “-“, $CryptKey);
$crypt->hash = $CryptKey;

flock($fp, LOCK_EX);
fwrite($fp, urlencode($crypt->phpEncrypt($EMail)).”|”.$CryptKey.”|”.time().”n”);
fclose($fp);

return true;
}

?>