X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=62aa009248af7c6c1c1b9d9140043c9aeb2ff6be;hp=267aa18fe387779e27ab8d990e9404f96e2e1be9;hb=ccf34a2a92d80d01debd84b4b6e1f294d8f90cce;hpb=f3d03c8c015fe8175b72a6a84c01a109622fa268
diff --git a/inc/functions.php b/inc/functions.php
index 267aa18fe3..62aa009248 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -150,6 +150,9 @@ function compileFinalOutput () {
// Init counter
$cnt = '0';
+ // Add page header and footer
+ addPageHeaderFooter();
+
// Compile all out
while (((strpos($GLOBALS['output'], '{--') > 0) || (strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) {
// Init common variables
@@ -1651,7 +1654,7 @@ function addEmailNavigation ($PAGES, $offset, $show_form, $colspan, $return=fals
$NAV = '';
for ($page = 1; $page <= $PAGES; $page++) {
// Is the page currently selected or shall we generate a link to it?
- if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
+ if (($page == getRequestParameter('page')) || ((!isGetRequestParameterSet('page')) && ($page == 1))) {
// Is currently selected, so only highlight it
$NAV .= '-';
} else {
@@ -1659,13 +1662,13 @@ function addEmailNavigation ($PAGES, $offset, $show_form, $colspan, $return=fals
$NAV .= '';
}
$NAV .= $page;
- if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
+ if (($page == getRequestParameter('page')) || ((!isGetRequestParameterSet('page')) && ($page == 1))) {
// Is currently selected, so only highlight it
$NAV .= '-';
} else {
@@ -1750,6 +1753,9 @@ function sendGetRequest ($script, $data = array()) {
// Add script data
$script .= $body;
+ // Remove trailed & to make it more conform
+ if (substr($script, -1, 1) == '&') $script = substr($script, 0, -1);
+
// Generate GET request header
$request = 'GET /' . trim($script) . ' HTTP/1.1' . getConfig('HTTP_EOL');
$request .= 'Host: ' . $host . getConfig('HTTP_EOL');
@@ -1763,8 +1769,9 @@ function sendGetRequest ($script, $data = array()) {
$request .= 'Accept-Charset: UTF-8,*' . getConfig('HTTP_EOL');
$request .= 'Cache-Control: no-cache' . getConfig('HTTP_EOL');
$request .= 'Content-Type: text/plain' . getConfig('HTTP_EOL');
- $request .= 'Content-Length: '.strlen($body) . getConfig('HTTP_EOL');
- $request .= 'Connection: close' . getConfig('HTTP_EOL') . getConfig('HTTP_EOL');
+ $request .= 'Content-Length: 0' . getConfig('HTTP_EOL');
+ $request .= 'Connection: close' . getConfig('HTTP_EOL');
+ $request .= getConfig('HTTP_EOL');
// Send the raw request
$response = sendRawRequest($host, $request);
@@ -1795,7 +1802,10 @@ function sendPostRequest ($script, $postData) {
$request .= 'User-Agent: ' . getConfig('TITLE') . '/' . getConfig('FULL_VERSION') . getConfig('HTTP_EOL');
$request .= 'Cache-Control: no-cache' . getConfig('HTTP_EOL');
$request .= 'Content-Type: application/x-www-form-urlencoded' . getConfig('HTTP_EOL');
- $request .= 'Connection: close' . getConfig('HTTP_EOL') . getConfig('HTTP_EOL');
+ $request .= 'Connection: close' . getConfig('HTTP_EOL');
+ $request .= getConfig('HTTP_EOL');
+
+ // Add body
$request .= $body;
// Send the raw request
@@ -1826,17 +1836,22 @@ function sendRawRequest ($host, $request) {
//* DEBUG: */ die("SCRIPT=" . $script.'
');
if ($useProxy === true) {
// Connect to host through proxy connection
- $fp = @fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
+ $fp = fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
} else {
// Connect to host directly
- $fp = @fsockopen($host, 80, $errno, $errdesc, 30);
+ $fp = fsockopen($host, 80, $errno, $errdesc, 30);
}
// Is there a link?
if (!is_resource($fp)) {
// Failed!
+ logDebugMessage(__FUNCTION__, __LINE__, $errdesc . ' (' . $errno . ')');
return $response;
- } // END - if
+ } elseif ((!stream_set_blocking($fp, 0)) || (!stream_set_timeout($fp, 1))) {
+ // Cannot set non-blocking mode or timeout
+ logDebugMessage(__FUNCTION__, __LINE__, socket_strerror(socket_last_error()));
+ return $response;
+ }
// Do we use proxy?
if ($useProxy === true) {
@@ -1856,7 +1871,7 @@ function sendRawRequest ($host, $request) {
//* DEBUG: */ print('proxyTunnel=
' . $proxyTunnel.''); // Write request - fputs($fp, $proxyTunnel); + fwrite($fp, $proxyTunnel); // Got response? if (feof($fp)) { @@ -1874,16 +1889,50 @@ function sendRawRequest ($host, $request) { } // END - if // Write request - fputs($fp, $request); + fwrite($fp, $request); + + // Start counting + $start = microtime(true); // Read response while (!feof($fp)) { - $response[] = trim(fgets($fp, 1024)); + // Get info from stream + $info = stream_get_meta_data($fp); + + // Is it timed out? 15 seconds is a really patient... + if (($info['timed_out'] == true) || (microtime(true) - $start) > 15) { + // Timeout + logDebugMessage(__FUNCTION__, __LINE__, 'Timed out to get data from host ' . $host); + + // Abort here + break; + } // END - if + + // Get line from stream + $line = fgets($fp, 128); + + // Ignore empty lines because of non-blocking mode + if (empty($line)) { + // uslepp a little to avoid 100% CPU load + usleep(10); + + // Skip this + continue; + } // END - if + + // Add it to response + $response[] = trim($line); } // END - while // Close socket fclose($fp); + // Time request if debug-mode is enabled + if (isDebugModeEnabled()) { + // Add debug message... + logDebugMessage(__FUNCTION__, __LINE__, 'Request took ' . (microtime(true) - $start) . ' seconds.'); + } // END - if + // Skip first empty lines $resp = $response; foreach ($resp as $idx => $line) { @@ -1902,8 +1951,11 @@ function sendRawRequest ($host, $request) { //* DEBUG: */ print('Response:
'.print_r($response, true).''); - // Proxy agent found? - if ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy === true)) { + // Proxy agent found or something went wrong? + if (!isset($response[0])) { + // No response, maybe timeout + $response = array('', '', ''); + } elseif ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy === true)) { // Proxy header detected, so remove two lines array_shift($response); array_shift($response); @@ -2262,7 +2314,7 @@ function displayParsingTime() { ); // Load the template - loadTemplate('show_timings', false, $content); + $GLOBALS['page_footer'] .= loadTemplate('show_timings', true, $content); } // Check wether a boolean constant is set @@ -2396,7 +2448,7 @@ function getActualVersion ($type = 'Revision') { $FQFN = sprintf("%s/.revision", getConfig('CACHE_PATH')); // Check if 'check_revision_data' is setted (switch for manually rewrite the .revision-File) - if ((isGetRequestElementSet('check_revision_data')) && (getRequestElement('check_revision_data') == 'yes')) { + if ((isGetRequestParameterSet('check_revision_data')) && (getRequestParameter('check_revision_data') == 'yes')) { // Forced rebuild of .revision file $new = true; } else { @@ -2631,11 +2683,11 @@ function getMessageFromErrorCode ($code) { case getCode('COOKIES_DISABLED') : $message = getMessage('LOGIN_COOKIES_DISABLED'); break; case getCode('BEG_SAME_AS_OWN') : $message = getMessage('BEG_SAME_UID_AS_OWN'); break; case getCode('LOGIN_FAILED') : $message = getMessage('LOGIN_FAILED_GENERAL'); break; - case getCode('MODULE_MEM_ONLY') : $message = getMaskedMessage('MODULE_MEM_ONLY', getRequestElement('mod')); break; + case getCode('MODULE_MEM_ONLY') : $message = getMaskedMessage('MODULE_MEM_ONLY', getRequestParameter('mod')); break; case getCode('OVERLENGTH') : $message = getMessage('MEMBER_TEXT_OVERLENGTH'); break; case getCode('URL_FOUND') : $message = getMessage('MEMBER_TEXT_CONTAINS_URL'); break; case getCode('SUBJ_URL') : $message = getMessage('MEMBER_SUBJ_CONTAINS_URL'); break; - case getCode('BLIST_URL') : $message = "{--MEMBER_URL_BLACK_LISTED--}