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
|
<?php
# This file is part of BBClone (A PHP web counter on steroids)
# $Header: /cvs/bbclone/mark_page.php,v 1.88 2005/02/24 11:44:19 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
if (!defined("_MARK_PAGE")) define("_MARK_PAGE", "1");
else return;
if ((!defined("_BBCLONE_DIR")) || (!is_readable(_BBCLONE_DIR."constants.php"))) return;
else require_once(_BBCLONE_DIR."constants.php");
if ((_BBC_PHP < 404) || !extension_loaded("pcre")) {
exit("<hr /><b>Error:</b> Your PHP installation doesn't meet the minimum requirements for running BBClone.");
}
foreach (array($BBC_LIB_PATH."io.php", $BBC_LIB_PATH."marker.php", $BBC_CONFIG_FILE) as $i) {
if (is_readable($i)) require_once($i);
else {
if (empty($BBC_DEBUG)) return;
else exit(bbc_msg($i));
}
}
if (extension_loaded("sysvsem") && (_BBC_PHP > 409) && stristr("sem", $BBC_USE_LOCK)) define("_BBC_SEM", 1);
if (extension_loaded("dio") && stristr("dio", $BBC_USE_LOCK)) define("_BBC_DIO", 1);
if (!defined("_BBC_SEM") && !defined("_BBC_DIO") || stristr("flk", $BBC_USE_LOCK)) define("_BBC_FLK", 1);
if (!function_exists("flock") && (stristr("flk", $BBC_USE_LOCK) !== false)) {
if (empty($BBC_DEBUG)) return;
else exit(bbc_msg("", "l"));
}
if (!is_readable($BBC_CACHE_PATH)) {
if (empty($BBC_DEBUG)) return;
else exit(bbc_msg($BBC_CACHE_PATH));
}
ignore_user_abort(1);
# Don't write to counter files if we want to reset stats
if (empty($BBC_KILL_STATS)) {
# needs to be always executed because otherwise our counter wouldn't work
# any longer by the time $BBC_DEBUG was activated
$i = bbc_exec_marker();
# Don't process anything unless we are told to do so
if (!defined("_OK")) {
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit($i);
}
else !empty($BBC_DEBUG) ? print($i) : "";
}
foreach (array("ACCESS_FILE", "LAST_FILE", "LOCK") as $i) {
if (!is_readable(${"BBC_".$i})) {
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit(bbc_msg(${"BBC_".$i}));
}
if (!is_writable(${"BBC_".$i})) {
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit(bbc_msg(${"BBC_".$i}, "w"));
}
}
# Kill'em all if requested and return
if (!empty($BBC_KILL_STATS)) {
bbc_kill_stats();
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit(bbc_msg("", "k"));
}
if (filesize($BBC_LOCK) !== 0) {
($BBC_TIMESTAMP - filemtime($BBC_LOCK) > 30) ? fclose(fopen($BBC_LOCK, "wb")) : "";
return ignore_user_abort(0);
}
if ($BBC_TIMESTAMP <= filemtime($BBC_ACCESS_FILE)) return ignore_user_abort(0);
foreach (array("log_processor", "new_connect", "timecalc", "referrer", "charconv") as $i) {
if (!is_readable($BBC_LIB_PATH.$i.".php")) {
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit(bbc_msg($BBC_LIB_PATH.$i.".php"));
}
require_once($BBC_LIB_PATH.$i.".php");
}
foreach (array("robot", "browser", "os") as $i) {
if (!is_readable($BBC_LIB_PATH.$i.".php")) {
if (empty($BBC_DEBUG)) return ignore_user_abort(0);
else exit(bbc_msg($BBC_LIB_PATH.$i.".php"));
}
}
# write to lockfile
if (($a = bbc_aquire_lock($BBC_LOCK)) && bbc_write_data($a, "1")) {
clearstatcache();
require($BBC_ACCESS_FILE);
require($BBC_LAST_FILE);
# cleanup if requested
if (!empty($BBC_PURGE_SINGLE)) bbc_purge_single();
# reset ranking if it's set to "0"
foreach (array("HOST" => "host", "KEY" => "key", "ORIGIN" => "referer", "PAGE" => "page") as $i => $j) {
if (empty(${"BBC_MAX".$i}) && isset($access)) {
$access[$j] = array();
if (isset($last)) unset($last);
}
}
if (isset($access)) {
# updates
if (isset($access['time']) && is_array($access['time'])) bbc_time_offset();
if (!isset($access['bbc0501'])) bbc_update();
}
# global and time stats
if (($b = bbc_aquire_lock($BBC_ACCESS_FILE)) && ($c = bbc_aquire_lock($BBC_LAST_FILE)) &&
($new_access = bbc_counter_to_array())) {
bbc_add_new_connections($new_access);
bbc_update_last();
if (bbc_write_data($b, "<?php\n\$access =\n".bbc_array_to_str($access).";\n?>")) bbc_release_lock($b);
if (!empty($BBC_DEBUG)) print(bbc_msg(basename($BBC_ACCESS_FILE), "o"));
if (bbc_write_data($c, "<?php\n\$last =\n".bbc_array_to_str($last).";\n?>")) bbc_release_lock($c);
if (!empty($BBC_DEBUG)) print(bbc_msg(basename($BBC_LAST_FILE), "o"));
}
}
else (!empty($BBC_DEBUG) ? print(bbc_msg("", "l")) : "");
# once we've finished we unlock and truncate the lock file
if (bbc_write_data($a)) bbc_release_lock($a);
ignore_user_abort(0);
# Exit if debug mode is turned on.
if (!empty($BBC_DEBUG)) exit();
?>
|