1<?php if (!defined('BB2_CWD')) die("I said no cheating!");
2
3// Bad Behavior browser screener
4
5function bb2_screener_cookie($settings, $package, $cookie_name, $cookie_value)
6{
7	// FIXME: Set the real cookie
8	if (!$settings['eu_cookie']) {
9		setcookie($cookie_name, $cookie_value, 0, bb2_relative_path());
10	}
11}
12
13function bb2_screener_javascript($settings, $package, $cookie_name, $cookie_value)
14{
15	global $bb2_javascript;
16
17	// FIXME: do something
18	$bb2_javascript = "<script type=\"text/javascript\">
19<!--
20function bb2_addLoadEvent(func) {
21	var oldonload = window.onload;
22	if (typeof window.onload != 'function') {
23		window.onload = func;
24	} else {
25		window.onload = function() {
26			oldonload();
27			func();
28		}
29	}
30}
31
32bb2_addLoadEvent(function() {
33	for ( i=0; i < document.forms.length; i++ ) {
34		if (document.forms[i].method == 'post') {
35			var myElement = document.createElement('input');
36			myElement.setAttribute('type', 'hidden');
37			myElement.name = '$cookie_name';
38			myElement.value = '$cookie_value';
39			document.forms[i].appendChild(myElement);
40		}
41	}
42});
43// --></script>
44		";
45}
46
47function bb2_screener($settings, $package)
48{
49	$cookie_name = BB2_COOKIE;
50
51	// Set up a simple cookie
52	$screener = array(time(), $package['ip']);
53	if (isset($package['headers_mixed']['X-Forwarded-For'])) {
54		array_push($screener, $package['headers_mixed']['X-Forwarded-For']);
55	}
56	if (isset($package['headers_mixed']['Client-Ip'])) {
57		array_push($screener, $package['headers_mixed']['Client-Ip']);
58	}
59
60	$cookie_value = implode(" ", $screener);
61
62	bb2_screener_cookie($settings, $package, BB2_COOKIE, $cookie_value);
63	bb2_screener_javascript($settings, $package, BB2_COOKIE, $cookie_value);
64}
65?>
66