Example #1
0
/**
* Show error log @ingroup pages
*/
function showLog()
{
    global $PH;
    echo "<pre>";
    ### get contents of a file into a string
    $filename = "_tmp/errors.log.php";
    $handle = fopen($filename, "r");
    $last_error_time = NULL;
    $hide_errors = get('hide_errors');
    $hide_error_hash = array();
    foreach (explode(',', $hide_errors) as $error) {
        if ($error) {
            $hide_error_hash[$error] = true;
        }
    }
    if ($hide_error_hash) {
        echo "hidden:<br>";
        foreach ($hide_error_hash as $key => $value) {
            $list = '';
            foreach ($hide_error_hash as $key2 => $value2) {
                if ($key2 != $key) {
                    $list .= "," . $key2;
                }
            }
            echo "{$key} (" . $PH->getLink('showLog', 'show', array('hide_errors' => $list));
            echo ")<br>";
        }
    }
    echo $PH->getLink('systemInfo', 'back to sysInfo') . " | ";
    echo $PH->getLink('showLog', 'log', array('showlog' => 1)) . " | ";
    echo $PH->getLink('showLog', 'errors', array()) . " | ";
    echo $PH->getLink('showLog', 'newbots', array('newbots' => 1)) . " | ";
    echo "<hr>";
    $count_requests = 0;
    $count_requests_by_crawlers = 0;
    $new_bots = array();
    while (!feof($handle)) {
        $line = fgets($handle);
        #echo asHtml($line) . "<br>";
        if (preg_match("/(\\w+) (\\d+)\\s*(.*)/", $line, $matches)) {
            $cat = $matches[1];
            $time = $matches[2];
            $rest = $matches[3];
            if (get('newbots')) {
                if ($cat == 'Log') {
                    $count_requests++;
                    if (preg_match("/\\((.*)\\)/", $rest, $matches_bot)) {
                        $agent_string = $matches_bot[1];
                        ### skip known crawlers.
                        if (!Auth::agentStringMatchesCrawler($agent_string)) {
                            if (preg_match("/bot|crawler|spider/i", $agent_string)) {
                                if (!isset($new_bots[$agent_string])) {
                                    $new_bots[$agent_string] = 1;
                                    #echo asHtml($agent_string) . "<br>";
                                } else {
                                    $new_bots[$agent_string]++;
                                }
                            }
                        } else {
                            $count_requests_by_crawlers++;
                        }
                    }
                }
            } else {
                if (get('time')) {
                    if ($time && $time == get('time')) {
                        echo asHtml($line);
                    }
                } else {
                    if ($cat == 'Error') {
                        if (preg_match("/(\\w+):\\s*([^\\:\\s]+)\\s*:\\s*(\\d+)(.*)/", $rest, $matches)) {
                            $type = $matches[1];
                            $file = trim($matches[2]);
                            $line = $matches[3];
                            $rest = $matches[4];
                            if (!isset($hide_error_hash[$file . ':' . $line])) {
                                if ($time != $last_error_time) {
                                    echo $PH->getLink('showLog', $time, array('time' => $time));
                                    echo " {$type}: <b>{$file}:{$line}</b> -  {$rest} (";
                                    echo $PH->getLink('showLog', __('hide'), array('hide_errors' => $hide_errors . ',' . $file . ':' . $line));
                                    echo ")<br>";
                                    $last_error_time = $time;
                                }
                            }
                        }
                    } else {
                        if (get('showlog')) {
                            echo "{$line}";
                        }
                    }
                }
            }
        }
    }
    fclose($handle);
    if (get('newbots')) {
        foreach ($new_bots as $bot => $count) {
            printf("%6d  %s<br>", $count, $bot);
        }
    }
}
Example #2
0
 /**
  * detects if current user is a web-crawler
  *
  * If ANONYMOUS_USER is allowed, web crawlers will cause heavy traffic
  * because for testing all availble links on the page, include history,
  * difference-pages, view toggles, etc.
  *
  * To avoid this Page handles can be disabled for crawlers.
  */
 public static function isCrawler()
 {
     if (!Auth::isAnonymousUser()) {
         return false;
     }
     return Auth::agentStringMatchesCrawler(getServerVar('HTTP_USER_AGENT'));
 }