File: log-header.php3

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (212 lines) | stat: -rw-r--r-- 5,199 bytes parent folder | download | duplicates (4)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/* $Id: log-header.php3,v 1.4 1998/06/14 02:40:39 jim Exp $ */

/* These are global variables. You should use the setshowinfo(),
   setlogging(), and setlogsuccessive() functions to change these
   values. */

$_log_showinfo = 1;	# show log info at the bottom of the page
$_log_dologging = 1;	# log the page hit
$_log_logsuccessive = 1;# log successive hits from the same host

/* This is the name to log the page as. You can change this using the
   LogAs() function. */
$_log_logas = ereg_replace("^/~[^/]+/", "", $GLOBALS['SCRIPT_NAME']);

/* These are essentially function pointers that should get overridden
   by the logging module that gets loaded. */

function log_undefined() {
	echo "<P><B>Fatal error:</B> No logging module loaded. Make sure that logging.method is set in your php3.ini file.\n";
}

$_log_getlastfunc = 'log_undefined';	# function to get last info
$_log_setlastfunc = 'log_undefined';	# function to set last info
$_log_loghitfunc = 'log_undefined';	# function to log an individual hit

$_log_last_hit = 0;			# will be the object for the last hit

/* A "log_hit" object is saved on every page load. */
class log_hit {
	var $filename, $time, $host, $email, $referrer, $browser;

	cfunction as_string() {
		return  $this->host . ' ' . $this->email .  ' ' .
			$this->referrer . ' ' . $this->browser;
	}

	cfunction as_update_query() {
	}
};

/* A "log_last_hit" is an entry saved to the log table that stores
   information about the last hit received. */
class log_last_hit {
	var $filename, $started, $time, $total, $today, $host,
	    $email, $referrer, $browser;

	cfunction set_from_string($string) {
		$temp = explode(' ', $string);
		if (count($temp) != 9) {
			echo "<!-- error setting log info from '$string' -->";
		}
		else {
			$this->filename = $temp[0];
			$this->time = $temp[1];
			$this->started = $temp[2];
			$this->total = $temp[3];
			$this->today = $temp[4];
			$this->host = ereg_replace("^-\$", "", $temp[5]);
			$this->email = ereg_replace("^-\$", "", $temp[6]);
			$this->referrer = ereg_replace("^-\$", "", $temp[7]);
			/* need to use urldecode() because of note below */
			$this->browser = urldecode(ereg_replace("^-\$", "", $temp[8]));
		}
	}

	cfunction as_string() {
		return $this->filename . ' ' . $this->time . ' ' .
			$this->started . ' ' .
			$this->total .  ' ' . $this->today . ' ' .
			$this->host . ' ' . $this->email .  ' ' .
			$this->referrer . ' ' . $this->browser;
	}

	cfunction as_update_query() {
	}

	cfunction update_counts() {
		$this->total += 1;
		$last_date = Date("Ymd", $this->time);
		if ($last_date != Date("Ymd")) {
			$this->today = 1;
		}
		else {
			$this->today += 1;
		}
	}

	cfunction update() {
		$this->filename = $GLOBALS['SCRIPT_NAME'];
		$this->update_counts();
		$this->time = time();
		if ($GLOBALS['REMOTE_HOST']) {
			$this->host = $GLOBALS['REMOTE_HOST'];
		}
		else {
			$this->host = "-";
		}
		if ($GLOBALS['HTTP_EMAIL']) {
			$this->email = $GLOBALS['HTTP_EMAIL'];
		}
		else {
			$this->email = "-";
		}

		/* earlier versions of Apache spelled this one wrong */
		if ($GLOBALS['HTTP_REFERRER'] || $GLOBALS['HTTP_REFERER']) {
			$this->referrer = $GLOBALS['HTTP_REFERRER'] || $GLOBALS['$HTTP_REFERER'];
		}
		else {
			$this->referrer = "-";
		}
		if ($GLOBALS['HTTP_USER_AGENT']) {
			/* we use urlencode() because the agent may have a
			   space in it, which would screw up set_from_string()
			*/
			$this->browser = urlencode($GLOBALS['HTTP_USER_AGENT']);
		}
		else {
			$this->browser = "-";
		}

		if (!$this->started) {
			$this->started = time();
		}
	}
};

/* figure out what sort of logging to do */
if ($_log_method = get_cfg_var("logging.method")) {
	include ("log-$_log_method.php3");
}

function setshowinfo($value) {
	$GLOBALS['_log_showinfo'] = $value;
	return $value;
}

function setlogging($value) {
	$GLOBALS['_log_dologging'] = $value;
	return $value;
}

function setlogsuccessive($value) {
	$GLOBALS['_log_successive'] = $value;
	return $value;
}

function get_current_hit() {
	$hit = new log_hit;
	$hit->filename = $GLOBALS['SCRIPT_NAME'];
	$hit->time = time();
	$hit->host = $GLOBALS['HTTP_REQUEST_HOST'];
	$hit->email = $GLOBALS['HTTP_EMAIL'];
	$hit->referrer = $GLOBALS['HTTP_REFERRER'] || $GLOBALS['$HTTP_REFERER'];
	$hit->browser = $GLOBALS['HTTP_USER_AGENT'];
	return $hit;
}

function get_last_hit() {
	global $_log_getlastfunc;
	if (gettype($GLOBALS['_log_last_hit']) != 'object') {
		$GLOBALS['_log_last_hit'] = $_log_getlastfunc();
	}
	return $GLOBALS['_log_last_hit'];
}

function getlastaccess() {
	$last = get_last_hit();
	return $last->time;
}

function getlastbrowser() {
	$last = get_last_hit();
	return $last->browser;
}

function getlastemail() {
	$last = get_last_hit();
	return $last->email;
}

function getlasthost() {
	$last = get_last_hit();
	return $last->host;
}

function getlastref() {
	$last = get_last_hit();
	return $last->referrer;
}

function getstartlogging() {
	$last = get_last_hit();
	return $last->started;
}

function gettoday() {
	$last = get_last_hit();
	return $last->today;
}

function gettotal() {
	$last = get_last_hit();
	return $last->total;
}

function logas($filename) {
	$GLOBALS['_log_logas'] = $filename;
}

?>