1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
<?php
# This file is part of BBClone (The PHP web counter on steroids)
# $Header: /cvs/bbclone/show_views.php,v 1.25 2005/02/21 00:31:16 olliver Exp $
# Copyright (C) 2001-2005, the BBClone Team (see file doc/authors.txt
# distributed with this library)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See doc/copying.txt for details
# Check for PHP 4.0.3 or older
if (!function_exists("array_sum")) exit("<hr /><b>Error:</b> PHP ".PHP_VERSION." is too old for BBClone.");
elseif (is_readable("constants.php")) require_once("constants.php");
else return;
foreach (array($BBC_CONFIG_FILE, $BBC_LIB_PATH."selectlang.php", $BBC_LAST_FILE) as $i) {
if (is_readable($i)) require_once($i);
else exit(bbc_msg($i));
}
function bbc_visit_time($this_time, $next_time, $nr = 0) {
$diff = ($next_time !== false) ? ($next_time - $this_time) : 0;
if ($diff < 1) return false;
elseif ($diff >= 3600) {
$h = floor($diff / 3600);
$m = floor((($mod = $diff % 3600) / 60));
$s = $mod % 60;
return "$h h ".(($m < 10) ? "0".$m : $m)." m ".(($s < 10) ? "0".$s : $s)." s ";
}
elseif (($diff > 60) && ($diff < 3600)) {
return ((($rnd = floor(($diff / 60))) < 10) ? "0".$rnd : $rnd)." m ".((($mod = $diff % 60) < 10) ?
"0".$mod : $mod)." s";
}
else return (($diff < 10) ? "0".$diff : $diff)." s";
}
function bbc_which_whois($addr) {
# look up whether an address is registerred
global $BBC_IP2EXT_PATH;
$long = sprintf("%u", ip2long($addr));
$file = $BBC_IP2EXT_PATH."whois.inc";
if (!is_readable($file)) return false;
$fp = fopen($file, "rb");
while (($range = fgetcsv($fp, 64, "|")) !== false) {
if (($long >= $range[1]) && ($long < ($range[1] + $range[2]))) {
switch($range[0]) {
case "ap":
$url = rawurlencode("www.apnic.net/apnic-bin/whois.pl?searchtext=$addr");
break;
case "la":
$url = rawurlencode("lacnic.net/cgi-bin/lacnic/whois?query=$addr");
break;
case "ri":
$url = rawurlencode("www.ripe.net/fcgi-bin/whois?searchtext=$addr");
break;
# Don't return whois link for private or reserved ranges
default:
return false;
}
}
}
fclose($fp);
# Use ARIN as catch up for anything left
return "(<a href=\"redir.php?rd=".(empty($url) ? rawurlencode("ws.arin.net/cgi-bin/whois.pl?queryinput=$addr") :
$url)."\" rel=\"nofollow\" target=\"_blank\">Whois</a>) ";
}
function bbc_list_visits() {
if (_BBC_PHP < 410) global $HTTP_GET_VARS;
global $bbc_html, $last, $_, $BBC_MAXVISIBLE;
$is_id = 0;
if (((_BBC_PHP < 410) ? !isset($HTTP_GET_VARS['id']) : !isset($_GET['id'])) ||
!preg_match(":^[0-9]+$:", ((_BBC_PHP < 410) ? $HTTP_GET_VARS['id'] : $_GET['id'])) ||
!is_array($last['traffic']) || empty($last['traffic'])) {
return $_['dstat_no_data'].".";
}
reset($last['traffic']);
while (list(, $connect) = each($last['traffic'])) {
if ((isset($connect['id'])) && ($connect['id'] == ((_BBC_PHP < 410) ? $HTTP_GET_VARS['id'] : $_GET['id']))) {
$is_id = 1;
break;
}
}
if (!$is_id) return $_['dstat_no_data'].".";
$prx_ip = (($connect['prx_ip'] == "unknown") || ($connect['prx_ip'] == $connect['ip'])) ? $_['global_no'] :
$connect['prx_ip'];
$off = $connect['visits'] - ($BBC_MAXVISIBLE + (isset($connect['off']) ? $connect['off'] : 0));
$ip_whois = bbc_which_whois($connect['ip']);
$prx_whois = ($prx_ip == $_['global_no']) ? false : bbc_which_whois($prx_ip);
# hexcolor depending on the age of the selected connection
$hex = $bbc_html->connect_code_color($connect);
$str = "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n"
."<tr>\n"
."<td class=\"head\"> ".$_['dstat_id']."</td>\n"
."<td class=\"head\"> ".$_['dstat_prx']."</td>\n"
."<td class=\"head\"> ".$_['dstat_ip']."</td>\n"
."<td class=\"head\"> ".$_['dstat_user_agent']."</td>\n"
."<td class=\"head\"> ".$_['dstat_nr']."</td>\n"
."<td class=\"head\"> ".$_['dstat_pages']."</td>\n"
."<td class=\"head\"> ".$_['dstat_visit_length']."</td>\n"
."<td class=\"head\"> ".$_['dstat_reloads']."</td>\n"
."</tr>\n"
."<tr style=\"background-color: $hex\">\n";
for ($i = 0, $k = count($connect['views']); $i < $k; $i++) {
$page = substr($connect['views'][$i], (strpos($connect['views'][$i], "|") + 1));
$page = substr($page, 0, strpos($page, "|"));
$page = ($last['pages'][$page] == "index") ? $_['navbar_Main_Site'] : $last['pages'][$page];
$cnt = substr($connect['views'][$i], (strrpos($connect['views'][$i], "|") + 1)) - 1;
$this_time = substr($connect['views'][$i], 0, strpos($connect['views'][$i], "|"));
$next_time = !isset($connect['views'][($i + 1)]) ? $connect['time'] :
substr($connect['views'][($i + 1)], 0, strpos($connect['views'][($i + 1)], "|"));
$length = bbc_visit_time($this_time, $next_time, $i);
$length = (($i + 1 !== $k) && ($length === false)) ? "00 s" : $length;
if ($i === 0) {
$str .= "<td class=\"rows\" align=\"right\" rowspan=\"$k\">".$connect['id']." </td>\n"
."<td class=\"rows\" align=\"right\" rowspan=\"$k\">$prx_ip $prx_whois</td>\n"
."<td class=\"rows\" align=\"right\" rowspan=\"$k\">".$connect['ip']." $ip_whois</td>\n"
."<td class=\"rows\" align=\"left\" rowspan=\"$k\"> "
.(($connect['agent'] == "unknown") ? " " : $connect['agent'])."</td>\n";
}
$str .= "<td class=\"rows\" align=\"right\">".($i + (($off > 0) ? ($off + 1) : 1))." </td>\n"
."<td class=\"rows\" align=\"left\"> $page</td>"
."<td class=\"rows\" align=\"right\">".$length." </td>\n"
."<td class=\"rows\" align=\"right\">".(($cnt > 0) ? $cnt : "")." </td>"
."</tr>\n"
.(($i + 1 === $k) ? "</table>\n" : "<tr style=\"background-color: $hex\">\n");
}
return $str;
}
# Main
echo $bbc_html->html_begin()
.$bbc_html->topbar(0, 0)
.$bbc_html->color_explain()
."<table align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">"
."<tr>\n"
."<td class=\"detbox\" align=\"center\" valign=\"middle\">".bbc_list_visits()."</td>\n"
."</tr>\n"
."</table>\n"
.$bbc_html->copyright()
.$bbc_html->topbar(0, 1)
.$bbc_html->html_end();
?>
|