]> git.mxchange.org Git - mailer.git/commitdiff
Broken mask fixed (%%) and request dispatcher sendRawRequest() rewritten to timeout...
authorRoland Häder <roland@mxchange.org>
Thu, 26 Nov 2009 00:32:00 +0000 (00:32 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 26 Nov 2009 00:32:00 +0000 (00:32 +0000)
inc/filter-functions.php
inc/functions.php
inc/language/de.php
inc/libs/yoomedia_functions.php

index e96ab005b547a10040be3c33188d53265b51db20..b797f90f15130559594b1710859f0950c6384d43 100644 (file)
@@ -247,7 +247,7 @@ function unregisterFilter ($filterName, $filterFunction, $force = false, $dry_ru
 // "Runs" the given filters, data is optional and can be any type of data
 function runFilterChain ($filterName, $data = null) {
        // Is that filter chain there?
-       if (!isset($GLOBALS['cache_array']['filter']['chains'][$filterName])) {
+       if ((!isset($GLOBALS['cache_array']['filter']['chains'][$filterName])) && (isDebugModeEnabled())) {
                // We should find all these non-existing filter chains
                //* Only for tracking: */ if ($filterName != 'sql_admin_extra_data') {
                //* Only for tracking: */ debug_report_bug('Filter chain <strong>' . $filterName . '</strong> not found!');
index 267aa18fe387779e27ab8d990e9404f96e2e1be9..aa691935e1f452796adb75cae04fdce88fbf1e81 100644 (file)
@@ -1750,6 +1750,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');
@@ -1826,17 +1829,22 @@ function sendRawRequest ($host, $request) {
        //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
        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 +1864,7 @@ function sendRawRequest ($host, $request) {
                //* DEBUG: */ print('<strong>proxyTunnel=</strong><pre>' . $proxyTunnel.'</pre>');
 
                // Write request
-               fputs($fp, $proxyTunnel);
+               fwrite($fp, $proxyTunnel);
 
                // Got response?
                if (feof($fp)) {
@@ -1874,11 +1882,39 @@ 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
@@ -1902,8 +1938,11 @@ function sendRawRequest ($host, $request) {
 
        //* DEBUG: */ print('<strong>Response:</strong><pre>'.print_r($response, true).'</pre>');
 
-       // 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);
@@ -2836,7 +2875,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
                                        } // END - if
 
                                        // Write to temp file
-                                       fputs($fp_tmp, $line);
+                                       fwrite($fp_tmp, $line);
                                } // END - while
 
                                // Close temp file
index 201ef9e1711fa6ab9135870a3ca43bf54a691c11..3bf2f049634825f7cdb9be731058d3e2a2d95e52 100644 (file)
@@ -1046,7 +1046,7 @@ addMessages(array(
        'EXTENSION_PROBLEM_EXT_INACTIVE' => "Kann nicht fortfahren! Fehler: Erweiterung <span class=\"data\">%s</span> deaktiviert.",
        'ADMIN_EXTENSION_PROBLEM_EXT_INACTIVE' => "Die Erweiterung <span class=\"data\">%s</span> ist derzeit deaktiviert. <a href=\"{%url=modules.php?module=admin&amp;what=extensions%}\">Hier</a> k&ouml;nnen Sie diese aktivieren.",
        'EXTENSION_PROBLEM_EXT_NOT_INSTALLED' => "Kann nicht fortfahren! Fehler: Erweiterung <span class=\"data\">%s</span> nicht installiert.",
-       'ADMIN_EXTENSION_PROBLEM_EXT_NOT_INSTALLED' => "Die Erweiterung <span class=\"data\">%s</span> ist derzeit nicht installiert. <a href=\"{%url=modules.php?module=admin&amp;what=extensions%}\">Hier</a> k&ouml;nnen Sie diese aktivieren.",
+       'ADMIN_EXTENSION_PROBLEM_EXT_NOT_INSTALLED' => "Die Erweiterung <span class=\"data\">%s</span> ist derzeit nicht installiert. <a href=\"{%%url=modules.php?module=admin&amp;what=extensions%%}\">Hier</a> k&ouml;nnen Sie diese aktivieren.",
        'EXTENSION_PROBLEM_NOT_INSTALLED' => "Erweiterung <span class=\"data\">%s</span> nicht installiert.",
        'EXTENSION_PROBLEM_UNSET_EXT' => "Skriptfehler: Parameter <strong>ext</strong> nicht gesetzt.",
        'EXTENSION_WARNING_EXT_INACTIVE' => "Die Erweiterung <span class=\"data\">%s</span> ist nicht aktiv. Dies kann zu St&ouml;rungen f&uuml;hren.<br />\nBitte aktivieren Sie diese unter <em>Verschiedenes-&gt;Erweiterungen</em>.",
index 75a0362ebc9b8350c9342ea5cd2b754d57bff618..a0e9c5a70fffe1b4d5f16bfd82e840b0d05b60d2 100644 (file)
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
+} // END - if
+
+// Queries the given Yoo!Media API 2.0 script
+function YOOMEDIA_QUERY_API ($script, $countQuery = true) {
+       // Init response array
+       $response = array();
+
+       // Enougth queries left?
+       if ((getConfig('yoomedia_requests_remain') > 0) || ($countQuery === false)) {
+               // Prepare the low-level request
+               $requestString = sprintf("http://www.yoomedia.de/interface_2.0/%s?id=%s&sid=%s&pw=%s&reload=%s&ma=%s&uebrig=%s&verguetung=%s&erotik=%s",
+                       $script,
+                       getConfig('yoomedia_id'),
+                       getConfig('yoomedia_sid'),
+                       getConfig('yoomedia_passwd'),
+                       getConfig('yoomedia_tm_max_reload'),
+                       getConfig('yoomedia_tm_min_wait'),
+                       getConfig('yoomedia_tm_clicks_remain'),
+                       getConfig('yoomedia_tm_min_pay'),
+                       getConfig('yoomedia_erotic_allowed')
+               );
+
+               // Run the query
+               $response = sendGetRequest($requestString);
+
+               // Convert from ISO to UTF-8 only if count is > 3 because <= 3 means timeout
+               if (count($response) > 3) {
+                       // Convert all lines to UTF-8
+                       foreach ($response as $k => $v) {
+                               // Convert the line
+                               $response[$k] = iconv('windows-1252', 'UTF-8//TRANSLIT', $v);
+                               /*
+                               // iconv()-less ISO-8859-1 -> UTF-8
+                               $response[$k] = preg_replace(
+                                       "/([\x80-\xFF])/e",
+                                       "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
+                                       $v
+                               );
+                               */
+                       } // END - foreach
+               } // END - if
+
+               // Shall we count the query as used?
+               if ($countQuery === true) {
+                       // Then update the config!
+                       updateConfiguration('yoomedia_requests_remain', 1, '-');
+               } // END - if
+       } // END - if
+
+       // Return the data
+       return $response;
 }
 
 // Test if the extension settings did work
@@ -91,53 +142,6 @@ function YOOMEDIA_TEST_CONFIG ($data) {
        return ($errorCode == '0');
 }
 
-// Queries the given Yoo!Media API 2.0 script
-function YOOMEDIA_QUERY_API ($script, $countQuery = true) {
-       // Init response array
-       $response = array();
-
-       // Enougth queries left?
-       if ((getConfig('yoomedia_requests_remain') > 0) || ($countQuery === false)) {
-               // Prepare the low-level request
-               $requestString = sprintf("http://www.yoomedia.de/interface_2.0/%s?id=%s&sid=%s&pw=%s&reload=%s&ma=%s&uebrig=%s&verguetung=%s&erotik=%s",
-                       $script,
-                       getConfig('yoomedia_id'),
-                       getConfig('yoomedia_sid'),
-                       getConfig('yoomedia_passwd'),
-                       getConfig('yoomedia_tm_max_reload'),
-                       getConfig('yoomedia_tm_min_wait'),
-                       getConfig('yoomedia_tm_clicks_remain'),
-                       getConfig('yoomedia_tm_min_pay'),
-                       getConfig('yoomedia_erotic_allowed')
-               );
-
-               // Run the query
-               $response = sendGetRequest($requestString);
-
-               // Convert from ISO to UTF-8
-               foreach ($response as $k => $v) {
-                       $response[$k] = iconv('windows-1252', 'UTF-8//TRANSLIT', $v);
-                       /*
-                       // iconv()-less ISO-8859-1 -> UTF-8
-                       $response[$k] = preg_replace(
-                               "/([\x80-\xFF])/e",
-                               "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
-                               $v
-                       );
-                       */
-               } // END - if
-
-               // Shall we count the query as used?
-               if ($countQuery === true) {
-                       // Then update the config!
-                       updateConfiguration('yoomedia_requests_remain', 1, '-');
-               } // END - if
-       } // END - if
-
-       // Return the data
-       return $response;
-}
-
 // "Getter" for a parsed result for all text mails. This means an array without
 // the header lines will be returned
 function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {