X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=f4fa1f7e6ae4d055188c7dc025d8476a9dc4a5d9;hb=328a783eb2966228d7d7d9f0293280619aa655af;hp=8875dc134d41276bbe3eadd43b56c92eea7db455;hpb=c45b1827a16928c65ecc1aea6a9d7a504c4874d4;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 8875dc134d..f4fa1f7e6a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -198,6 +198,9 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { // Add more variables which you want to use in your template files global $DATA, $_CONFIG, $username; + // Make all template names lowercase + $template = strtolower($template); + // Count the template load if (!isset($_CONFIG['num_templates'])) $_CONFIG['num_templates'] = 0; $_CONFIG['num_templates']++; @@ -338,7 +341,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") { $SUBJECT = html_entity_decode($SUBJECT); // Set from header - if (!eregi("@", $TO)) { + if ((!eregi("@", $TO)) && ($TO > 0)) { // Value detected, load email from database if (EXT_IS_ACTIVE("msg")) { ADD_MESSAGE_TO_BOX($TO, $SUBJECT, $MSG, $HTML); @@ -348,6 +351,9 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") { list($TO) = SQL_FETCHROW($result_email); SQL_FREERESULT($result_email); } + } elseif ($TO == 0) { + // Is the webmaster! + $TO = WEBMASTER; } // Not in PHPMailer-Mode @@ -550,7 +556,7 @@ function TRANSLATE_COMMA ($dotted, $cut=true) { // function DEREFERER ($URL) { - $URL = URL."/modules.php?module=loader&url=".urlencode(base64_encode(gzcompress(COMPILE_CODE($URL)))); + $URL = URL."/modules.php?module=loader&url=".urlencode(base64_encode(gzcompress($URL))); return $URL; } @@ -667,6 +673,9 @@ function SET_LANGUAGE($lang) { function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") { global $DATA, $_CONFIG, $REPLACER; + // Make sure all template names are lowercase! + $template = strtolower($template); + // Keept for backward-compatiblity (please replace these variables against our new {--CONST--} syntax!) $MAIN_TITLE = MAIN_TITLE; $URL = URL; $WEBMASTER = WEBMASTER; $surname = ""; $family = ""; $nick = ""; $sex = "N"; @@ -1646,25 +1655,12 @@ function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) { } } -// -function MXCHANGE_OPEN ($script) { - global $_CONFIG; - // Default is not to use proxy - $useProxy = true; - - // Are proxy settins set? - if ((!empty($_CONFIG['proxy_host'])) && ($_CONFIG['proxy_port'] > 0)) { - // Then use it - $useProxy = true; - } - - //* DEBUG */ print("SCRIPT=".$script."
\n"); - // Compile the script name - $script = COMPILE_CODE($script); - //* DEBUG */ print("SCRIPT=".$script."
\n"); - +// Extract host from script name +function EXTRACT_HOST (&$script) { // Use default SERVER_URL by default... ;) So? $url = SERVER_URL; + + // Is this URL valid? if (substr($script, 0, 7) == "http://") { // Use the hostname from script URL as new hostname $url = substr($script, 7); @@ -1690,6 +1686,85 @@ function MXCHANGE_OPEN ($script) { //* DEBUG */ print("SCRIPT=".$script."
\n"); if (substr($script, 0, 1) == "/") $script = substr($script, 1); + // Return host name + return $host; +} + +// Send a GET request +function GET_URL ($script) { + // Compile the script name + $script = COMPILE_CODE($script); + + // Extract host name from script + $host = EXTRACT_HOST($script); + + // Generate GET request header + $request = "GET /" . trim($script) . " HTTP/1.1\r\n"; + $request .= "Host: " . $host . "\r\n"; + $request .= "Referer: " . URL . "/admin.php\r\n"; + $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n"; + $request .= "Content-Type: text/plain\r\n"; + $request .= "Cache-Control: no-cache\r\n"; + $request .= "Connection: Close\r\n\r\n"; + + // Send the raw request + $response = SEND_RAW_REQUEST($host, $request); + + // Return the result to the caller function + return $response; +} + +// Send a POST request +function POST_URL ($script, $postData) { + // Is postData an array? + if (!is_array($postData)) { + // Abort here + return array("", "", ""); + } // END - if + + // Compile the script name + $script = COMPILE_CODE($script); + + // Extract host name from script + $host = EXTRACT_HOST($script); + + // Construct request + $data = http_build_query($postData, '', '&'); + + // Generate POST request header + $request = "POST /" . trim($script) . " HTTP/1.1\r\n"; + $request .= "Host: " . $host . "\r\n"; + $request .= "Referer: " . URL . "/admin.php\r\n"; + $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n"; + $request .= "Content-type: application/x-www-form-urlencoded\r\n"; + $request .= "Content-length: " . strlen($data) . "\r\n"; + $request .= "Cache-Control: no-cache\r\n"; + $request .= "Connection: Close\r\n\r\n"; + $request .= $data; + + // Send the raw request + $response = SEND_RAW_REQUEST($host, $request); + + // Return the result to the caller function + return $response; +} + +// Sends a raw request to another host +function SEND_RAW_REQUEST ($host, $request) { + global $_CONFIG; + + // Initialize array + $response = array("", "", ""); + + // Default is not to use proxy + $useProxy = false; + + // Are proxy settins set? + if ((!empty($_CONFIG['proxy_host'])) && ($_CONFIG['proxy_port'] > 0)) { + // Then use it + $useProxy = true; + } // END - if + // Open connection //* DEBUG */ die("SCRIPT=".$script."
\n"); if ($useProxy) { @@ -1701,33 +1776,33 @@ function MXCHANGE_OPEN ($script) { // Is there a link? if (!is_resource($fp)) { // Failed! - return array("", "", ""); + return $response; } // END - if // Do we use proxy? if ($useProxy) { // Generate CONNECT request header - $request = "CONNECT ".$host.":80 HTTP/1.1\r\n"; - $request .= "Host: ".$host."\r\n"; + $proxyTunnel = "CONNECT ".$host.":80 HTTP/1.1\r\n"; + $proxyTunnel .= "Host: ".$host."\r\n"; // Use login data to proxy? (username at least!) if (!empty($_CONFIG['proxy_username'])) { // Add it as well $encodedAuth = base64_encode(COMPILE_CODE($_CONFIG['proxy_username']).":".COMPILE_CODE($_CONFIG['proxy_password'])); - $request .= "Proxy-Authorization: Basic ".$encodedAuth."\r\n"; + $proxyTunnel .= "Proxy-Authorization: Basic ".$encodedAuth."\r\n"; } // END - if // Add last new-line - $request .= "\r\n"; - //* DEBUG: */ print("Request:
".$request."
"); + $proxyTunnel .= "\r\n"; + //* DEBUG: */ print("proxyTunnel=
".$proxyTunnel."
"); // Write request - fputs($fp, $request); + fputs($fp, $proxyTunnel); // Got response? if (feof($fp)) { // No response received - return array("", "", ""); + return $response; } // END - if // Read the first line @@ -1735,22 +1810,9 @@ function MXCHANGE_OPEN ($script) { $respArray = explode(" ", $resp); if ((strtolower($respArray[0]) !== "http/1.0") || ($respArray[1] != "200")) { // Invalid response! - return array("", "", ""); + return $response; } // END - if } // END - if - - // Generate GET request header - $request = "GET /".trim($script)." HTTP/1.1\r\n"; - $request .= "Host: ".$host."\r\n"; - $request .= "Referer: ".URL."/admin.php\r\n"; - $request .= "User-Agent: ".TITLE."/".FULL_VERSION."\r\n"; - $request .= "Content-Type: text/plain\r\n"; - $request .= "Cache-Control: no-cache\r\n"; - $request .= "Connection: Close\r\n\r\n"; - //* DEBUG: */ print("Request:
".$request."
"); - - // Initialize array - $response = array(); // Write request fputs($fp, $request); @@ -1763,6 +1825,22 @@ function MXCHANGE_OPEN ($script) { // Close socket fclose($fp); + // Skip first empty lines + $resp = $response; + foreach ($resp as $idx => $line) { + // Trim space away + $line = trim($line); + + // Is this line empty? + if (empty($line)) { + // Then remove it + array_shift($response); + } else { + // Abort on first non-empty line + break; + } + } // END - foreach + //* DEBUG: */ print("Response:
".print_r($response, true)."
"); // Proxy agent found?