1 |
joku |
63 |
<?php |
2 |
|
|
/* This file is part of BBClone (A PHP based Web Counter on Steroids) |
3 |
|
|
* |
4 |
|
|
* SVN FILE $Id$ |
5 |
|
|
* |
6 |
joku |
381 |
* Copyright (C) 2001-2018, the BBClone Team (see doc/authors.txt for details) |
7 |
joku |
63 |
* |
8 |
|
|
* This program is free software: you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* See doc/copying.txt for details |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
///////////////// |
22 |
|
|
// New Connect // |
23 |
|
|
///////////////// |
24 |
|
|
|
25 |
|
|
function bbc_get_extension($host, $addr) { |
26 |
|
|
global $BBC_EXT_LOOKUP; |
27 |
|
|
|
28 |
|
|
$ext = ""; |
29 |
|
|
if ($BBC_EXT_LOOKUP) { |
30 |
|
|
// if plugin is defined, then try lookup via plugin |
31 |
|
|
$ext = bbc_extension_plugin($host, $addr); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
if ($ext) { |
35 |
|
|
// plugin did find answer, so return it |
36 |
|
|
return $ext; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
// plugin did not find extention, try taking the last part of the hostname |
40 |
|
|
|
41 |
|
|
$ext = strtolower(substr($host, (strrpos($host, ".") + 1))); |
42 |
|
|
if (preg_match(":^[0-9]+$:", $ext)) { |
43 |
|
|
return "ipv4"; |
44 |
|
|
} else if (strpos($host, ":") >0) { |
45 |
|
|
return "ipv6"; |
46 |
|
|
} else if (strpos($host, ".") === false) { |
47 |
|
|
return "unknown"; |
48 |
|
|
} else { |
49 |
|
|
return $ext; |
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
function bbc_update_connect($connect) { |
55 |
|
|
global $BBC_LIB_PATH; |
56 |
|
|
|
57 |
|
|
// Sanity check has already been made in mark_page.php |
58 |
|
|
foreach (array("browser", "os", "robot") as $i) require($BBC_LIB_PATH.$i.".php"); |
59 |
|
|
|
60 |
|
|
$connect['visits'] = 1; |
61 |
|
|
|
62 |
|
|
// Detecting robots, browsers and os |
63 |
|
|
foreach (array("robot", "browser", "os") as $rule) { |
64 |
|
|
reset($$rule); |
65 |
|
|
|
66 |
|
|
while (list(${$rule."_name"}, ${$rule."_elem"}) = each($$rule)) { |
67 |
|
|
reset(${$rule."_elem"}['rule']); |
68 |
|
|
|
69 |
|
|
while (list($pattern, $note) = each(${$rule."_elem"}['rule'])) { |
70 |
|
|
if (!preg_match('~'.$pattern.'~i', $connect['agent'], $regs)) continue; |
71 |
|
|
$connect[$rule] = ${$rule."_name"}; |
72 |
|
|
|
73 |
|
|
if (preg_match(":\\\\[0-9]{1}:" ,$note)) { |
74 |
|
|
$str = preg_replace(":\\\\([0-9]{1}):", "\$regs[\\1]", $note); |
75 |
|
|
|
76 |
|
|
eval("\$str = \"$str\";"); |
77 |
|
|
|
78 |
|
|
$connect[$rule."_note"] = $str; |
79 |
|
|
} else if (preg_match(":^text\:.*:", $note)) { |
80 |
|
|
$connect[$rule."_note"] = substr($note, 5); |
81 |
|
|
} |
82 |
|
|
break 2; |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
if (!empty($connect['robot'])) break; |
86 |
|
|
} |
87 |
|
|
return $connect; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
function bbc_update_access($connect) { |
91 |
|
|
global $access; |
92 |
|
|
|
93 |
|
|
// Assign an identification number to the new connection |
94 |
|
|
$connect['id'] = isset($access['stat']['totalcount']) ? ($access['stat']['totalcount'] + 1) : 1; |
95 |
|
|
|
96 |
|
|
// Recording the detected extension in the global statistics |
97 |
|
|
$access['stat']['ext'][$connect['ext']] = !isset($access['stat']['ext'][$connect['ext']]) ? 1 : |
98 |
|
|
++$access['stat']['ext'][$connect['ext']]; |
99 |
|
|
|
100 |
|
|
foreach (array("robot", "browser", "os") as $type) { |
101 |
|
|
if (($type == "robot") && (empty($connect[$type]))) continue; |
102 |
|
|
|
103 |
|
|
if (isset($access['stat'][$type][$connect[$type]])) $access['stat'][$type][$connect[$type]]++; |
104 |
|
|
else $access['stat'][$type][$connect[$type]] = 1; |
105 |
|
|
|
106 |
|
|
if (($type == "robot") && (!empty($connect[$type]))) break; |
107 |
|
|
} |
108 |
|
|
return $connect; |
109 |
|
|
} |
110 |
matthys |
15 |
?> |