Sodele... nachdem Ihr ja nicht aus dem Quark gekommen seid...
(ich mach ja nur Spass... ist ja kein "Ich frag - Ihr hüpft" Forum...
)
Nochmal zur Sache...
Die generierte e-Mail aus einem Artikel konnte nicht zum Versand eingelesen werden da keine Socket Verbindung zustande kam.
Im Prinzip ist das (wenn man es weiss) recht schnell geklärt...
Durch das Load Balancing kann der Server nicht auf sich selbst zugreifen... naja... doch schon... aber nicht auf den Host selbst...
Also hab ich ein bischen rumgespielt und die "SERVER_ADDR" als Ziel für die Funktion fsockopen() angegeben...
Ich hab hier mal die Klasse mit allen Debug Infos usw zur Verfügung gestellt...
Meine Änderungen sind mit [GaMbIt] gekennzeichnet...
class.newsletter.php aus
contenido/classes/
Code: Alles auswählen
<?php
/*****************************************
* File : $RCSfile: class.newsletter.php,v $
* Project : Contenido
* Descr : Newsletter recipient class
* Modified : $Date: 2007/09/03 23:03:36 $
*
* © four for business AG, www.4fb.de, generated by HerrB (01.08.2004)
*
* $Id: class.newsletter.php,v 1.15 2007/09/03 23:03:36 bjoern.behrens Exp $
******************************************/
/**
* If newsletter is HTML newsletter and necessary data available
* returns final HTML message
* @return string HTML message
*/
function getHTMLMessage()
{
global $lang, $client, $cfgClient, $contenido;
if ($this->get("type") == "html" && $this->get("idart") > 0 && $this->htmlArticleExists()) {
cInclude("classes", "contenido/class.client.php");
cInclude("classes", "contenido/class.clientslang.php");
cInclude("classes", "contenido/class.articlelanguage.php");
// Article ID
$iIDArt = $this->get("idart");
// Category ID
$oClientLang = new cApiClientLanguage(false, $client, $lang);
$iIDCat = $oClientLang->getProperty("newsletter", "html_newsletter_idcat");
unset ($oClientLang);
// Get http username and password, if frontend is protected
$oClient = new cApiClient($client);
$sHTTPUserName = $oClient->getProperty("newsletter", "html_username");
$sHTTPPassword = $oClient->getProperty("newsletter", "html_password");
unset ($oClient);
// Get HTML
if ($iIDArt > 0 && $iIDCat > 0)
{
// Check, if newsletter is online and set temporarely online, otherwise
$bSetOffline = false;
$oArticles = new cApiArticleLanguageCollection;
$oArticles->setWhere("idlang", $this->get("idlang"));
$oArticles->setWhere("idart", $this->get("idart"));
$oArticles->query();
if ($oArticle = $oArticles->next())
{
if ($oArticle->get("online") == 0)
{
$bSetOffline = true;
$oArticle->set("online", 1);
$oArticle->store();
}
unset ($oArticle);
}
unset ($oArticles);
//$sFile = $cfgClient[$client]['path']['htmlpath']."front_content.php?idclient=$client&idlang=$lang&idcat=$iIDCat&idart=$iIDArt&noex=1&send=1";
$sFile = "front_content.php?idclient=$client&idlang=$lang&idcat=$iIDCat&idart=$iIDArt&noex=1&send=1";
$aURL = parse_url($cfgClient[$client]['path']['htmlpath']);
/**
* Ab hier sind Anpassungen enthalten [GaMbIt]
*/
// Path Ausgabe für den Newsletter DEBUG Info [GaMbIt]
echo '<div style="border:1px solid #666666; padding:4px; margin:0px 0px 5px 0px;"><b>Path :</b><br>' . $aURL["scheme"] . '://' . $aURL["host"] . $aURL["path"] . $sFile . '</div>';
// $aURL Dump [GaMbIt]
echo '<div style="border:1px solid #666666; padding:4px; margin:0px 0px 5px 0px;"><b>Var Dump für $aURL :</b><br><pre>';
var_dump($aURL) ;
echo '</pre></div>';
// TODO: Other schemes than http should be tested before use!
// TODO: Other Host and Address Methods to open the Connection [GaMbIt]
if ($aURL["scheme"] == "https") {
$iPort = 443;
$sTarget = "ssl://".$aURL["host"];
} else {
$iPort = 80;
// $sTarget = $aURL["host"]; // Herkömmliche Methode ausgehebelt [GaMbIt]
$sTarget = $_SERVER['SERVER_ADDR']; // Aufruf über die Server Adresse [GaMbIt]
}
if ($aURL["port"]) {
$iPort = $aURL["port"];
}
$iErrorNo = 0;
$sErrorMsg = "";
/**
* DEBUG Info für $sTarget !!! hier tritt wohl der Fehler bei verschiedenen Load Balancern auf,
* da der Hostname nicht automatisch der Server ist...
* Problematisch könnte der Aufruf ohne Host-Header sein ohne den der Apache den vHost nicht identifizieren kann...
*/
echo '<div style="border:1px solid #666666; background-color:#CCFFCC; padding:4px; margin:0px 0px 5px 0px;"><b>fsockopen() Hostname :</b><br>' . $sTarget . '</div>';
echo '<div style="border:1px solid #666666; background-color:#FFCCFF; padding:4px; margin:0px 0px 5px 0px;"><b>SERVER_NAME Variable :</b><br>' . $_SERVER['SERVER_NAME'] . '<br />';
echo '<b>HTTP_HOST Variable :</b><br /> ' . $_SERVER['HTTP_HOST'] . '<br />';
echo '<b>SERVER_ADDR Variable :</b><br /> ' . $_SERVER['SERVER_ADDR'] . '<br />';
echo '<b>REMOTE_ADDR Variable :</b><br /> ' . $_SERVER['REMOTE_ADDR'] . '<br />';
echo '<b>REMOTE_HOST Variable :</b><br /> ' . $_SERVER['REMOTE_HOST'] . '<br />';
echo 'gibt die Adresse des aufrufenden Computer aus. Da dieser in einer lokalen Entwicklungsumgebung der bereitstellende Server sein kann, könnte diese Information evtl nützlich sein.<br /><i>Für <b>REMOTE HOST</b> muss HostnameLookups auf On gestellt sein (httpd.conf)</i><br />!!! Hilft natürlich nicht in Clusterconfigurationen wo die Newsletterkomponenten auf einen anderen Server ausgelagert sind oder die Contenido Installation gesplittet ist!!!';
echo '</div>';
// Ende der Debug Ein, bzw. Ausgaben [GaMbIt]
if ($iHandler = fsockopen($sTarget, $iPort, $iErrorNo, $sErrorMsg, 30))
{
// If you use HTTP 1.1 you may get chunked data... you could solve
// this easily by using HTTP 1.0, but then you get a problem with
// virtual servers, as HTTP 1.0 doesn't use the host information...
fputs($iHandler, "GET ".$aURL["path"].$sFile." HTTP/1.1\r\n");
fputs($iHandler, "Host: ".$aURL["host"]."\r\n");
// Maybe the website has been protected using .htaccess, then login
if ($sHTTPUserName != "" && $sHTTPPassword != "")
{
fputs($iHandler, "Authorization: Basic " . base64_encode("$sHTTPUserName:$sHTTPPassword") . "\r\n");
}
fputs($iHandler, "Referer: http://".$aURL["host"]."\r\n");
fputs($iHandler, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n");
fputs($iHandler, "Connection: close\r\n\r\n");
// Get the HTTP header and body separately
$sHTML = "";
$sHeader = "";
$bBody = false;
while (!feof($iHandler))
{
// $sLine = fgets($iHandler, 4096);
$sLine = fgets($iHandler, 1024);
if ($bBody) {
$sHTML .= $sLine;
} else if ($sLine == "\r\n") {
$bBody = true;
} else {
$sHeader .= $sLine;
}
}
fclose ($iHandler);
$sHTML = $this->_deChunkHTTPBody($sHeader, $sHTML);
// If someone likes to use anchors in html newsletters (*sigh*)
// the base href tag has to be removed - that means, we have to fix
// all source paths manually...
if (getEffectiveSetting('newsletter', 'remove_base_tag', "false") == "true")
{
// Remove base tag
$sHTML = preg_replace('/<base href=(.*?)>/is', '', $sHTML, 1);
// Fix source path
// TODO: Test any URL specification that may exist under the sun...
$sHTML = preg_replace('/[sS[rR][cC][ ]*=[ ]*"([^h][^t][^t][^p][^:].*)"/', 'rc="'.$cfgClient[$client]['path']['htmlpath'].'$1"', $sHTML);
$sHTML = preg_replace('/[hH][rR][eE][fF][ ]*=[ ]*"([^h][^t][^t][^p][^:][A-Za-z0-9#\.?\-=_&]*)"/', 'href="'.$cfgClient[$client]['path']['htmlpath'].'$1"', $sHTML);
$sHTML = preg_replace('/url\((.*)\)/', 'url('.$cfgClient[$client]['path']['htmlpath'].'$1)', $sHTML);
// Now replace anchor tags to the newsletter article itself just by the anchor
$sHTML = str_replace($cfgClient[$client]['path']['htmlpath']."front_content.php?idart=".$iIDArt."#", "#", $sHTML);
}
/* The following is a bad idea, as all needed objects have to be globally
* available... (e.g. $db, $sess and so on) - but it may be a solution,
* if fsockopen is not available
# I don't know, why we should get idartlang...
# $idartlang = getArtLang ($iIDArt, $lang);
$sCode = conGenerateCode($iIDCat, $iIDArt, $lang, $client);
$db = new DB_Contenido;
ob_start();
eval("?>".stripslashes($sCode)."<?php\n");
$sHTMLMessage = ob_get_contents();
ob_end_clean();
unset ($sCode); */
$sReturn = $sHTML;
} else {
if ($contenido) { // Use i18n only in backend
$sErrorText = i18n("There was a problem getting the newsletter article using http. Error: %s (%s)");
} else {
$sErrorText = "There was a problem getting the newsletter article using http. Error: %s (%s)";
}
$this->_sError = sprintf($sErrorText, $sErrorMsg, $iErrorNo);
$sReturn = false;
}
// Set previously offline article back to offline
if ($bSetOffline)
{
$oArticles = new cApiArticleLanguageCollection;
$oArticles->setWhere("idlang", $this->get("idlang"));
$oArticles->setWhere("idart", $this->get("idart"));
$oArticles->query();
if ($oArticle = $oArticles->next())
{
$oArticle->set("online", 0);
$oArticle->store();
}
unset ($oArticle);
unset ($oArticles);
}
return $sReturn;
} else {
return false;
}
} else {
return false;
}
}
Ich hab die Klasse mal gekürzt...
Jetzt ist nur noch die Methode getHTMLMessage() gepostet...
Wenn ich die gesamte Klasse poste steigt das Forum aus