Beispiel #1
0
if ($S->myUri) {
    if (is_array($S->myUri)) {
        foreach ($S->myUri as $v) {
            if ($ip == gethostbyname($v)) {
                return;
            }
        }
    } else {
        if ($ip == gethostbyname($S->myUri)) {
            return;
        }
    }
}
$agent = $S->escape($_SERVER['HTTP_USER_AGENT']);
$S->query("select count(*) from information_schema.tables " . "where (table_schema = '{$S->masterdb}') and (table_name = 'bots')");
list($ok) = $S->fetchrow('num');
if ($ok == 1) {
    try {
        //error_log("robots: $S->siteName, $ip, $agent");
        $S->query("insert into {$S->masterdb}.bots (ip, agent, count, robots, who, creation_time, lasttime) " . "values('{$ip}', '{$agent}', 1, 1, '{$S->siteName}', now(), now())");
    } catch (Exception $e) {
        if ($e->getCode() == 1062) {
            // duplicate key
            $S->query("select who from {$S->masterdb}.bots where ip='{$ip}'");
            list($who) = $S->fetchrow('num');
            if (!$who) {
                $who = $S->siteName;
            }
            if (strpos($who, $S->siteName) === false) {
                $who .= ", {$S->siteName}";
            }
Beispiel #2
0
// BLP 2014-03-06 -- ajax for tracker.js
$_site = (require_once getenv("SITELOAD") . "/siteload.php");
$dbinfo = $_site->dbinfo;
$_site = (array) $_site;
$S = new Database($_site);
$agent = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];
$data = file_get_contents('php://input');
$data = json_decode($data, true);
$id = $data['id'];
if (!$id) {
    error_log("beacon: {$S->siteName}: NO ID, {$ip}, {$agent}");
    exit;
} else {
    $S->query("select isJavaScript from {$S->masterdb}.tracker where id={$id}");
    list($js) = $S->fetchrow('num');
    // 4127 is 0x101F or 0x1000 timer, 0x10 noscript, 0xf start|load|script|normal
    // So if js is zero after the &~ then we do not have a (32|64|128) beacon,
    // or (256|512|1024) tracker:pagehide/beforeunload/unload. We should update.
    if (($js & ~4127) == 0) {
        // 'which' can be 1, 2, or 4
        $beacon = $data['which'] * 32;
        // 0x20, 0x40 or 0x80
        $S->query("update {$S->masterdb}.tracker set endtime=now(), difftime=timediff(now(),starttime), " . "isJavaScript=isJavaScript|{$beacon}, lasttime=now() where id={$id}");
    }
    echo "Beacon OK: {$data['which']}";
    exit;
}
echo <<<EOF
<!DOCTYPE html>
<html>
Beispiel #3
0
$S = new Database($_site);
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
//error_log("tracker: ". print_r($_REQUEST, true));
// Post an ajax error message
if ($_POST['page'] == 'ajaxmsg') {
    $msg = $_POST['msg'];
    // NOTE: $_POST['ipagent'] is a string not a boolian! So === true does NOT work but == true
    // or == 'true' does work.
    $ipagent = $_POST['ipagent'] == 'true' ? ": {$ip}, {$agent}" : '';
    error_log("tracker: AJAXMSG, {$S->siteName}, '{$msg}'" . $ipagent);
    echo "AJAXMSG OK";
    exit;
}
$S->query("select count(*) from information_schema.tables " . "where (table_schema = '{$S->masterdb}') and (table_name = 'tracker')");
list($ok) = $S->fetchrow('num');
if ($ok != 1) {
    error_log("No tracker in {$S->masterdb}");
    exit;
}
// start is an ajax call
if ($_POST['page'] == 'start') {
    $id = $_POST['id'];
    if (!$id) {
        error_log("tracker: {$S->siteName}: START NO ID, {$ip}, {$agent}");
        exit;
    }
    //error_log("tracker: start,    $S->siteName, $id, $ip, $agent");
    $S->query("update {$S->masterdb}.tracker set isJavaScript=isJavaScript|1, lasttime=now() where id='{$id}'");
    echo "Start OK";
    exit;