proxyscan.phh moved from curl-de-sac to brisk
[brisk.git] / web / Obj / proxyscan.phh
1 <?php
2 /*
3  *      Proxy Detector v0.1 with brisk customizations
4  *              copyrights by: Daantje Eeltink (me@daantje.nl)
5  *                                              http://www.daantje.nl
6  *
7  *              first build: Mon Sep 18 21:43:48 CEST 2006
8  *              last build: Tue Sep 19 10:37:12 CEST 2006
9  *
10  *      Description:
11  *              This class can detect if a visitor uses a proxy server by scanning the
12  *              headers returned by the user client. When the user uses a proxy server,
13  *              most of the proxy servers alter the header. The header is returned to
14  *              PHP in the array $_SERVER.
15  *
16  *      License:
17  *              GPL v2 licence. (http://www.gnu.org/copyleft/gpl.txt)
18  */
19
20 class proxy_detector {
21
22     /**
23      * CONSTRUCTOR
24      *  Set defaults...
25      */
26     function proxy_detector(){
27     }
28
29     /*
30       function exists_in_rbl($remote)
31       verify if an host is into a proxy black list or not
32     */
33     function exists_in_rbl($remote) {
34         $rbls = array('http.dnsbl.sorbs.net', 'misc.dnsbl.sorbs.net');
35     
36         if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/",
37                        $remote, $matches)) {
38             foreach ($rbls as $rbl) {
39                 $rblhost = $matches[4] . "." . $matches[3] . "." .
40                     $matches[2] . "." . $matches[1] . "." . $rbl;
41         
42                 $resolved = gethostbyname($rblhost);
43                 // echo "RBL ".$rblhost."<br>";
44                 if ($resolved != $rblhost) {
45                     return TRUE;
46                 }
47             }
48         }
49         return FALSE;
50     }
51
52     /**
53      * BOOL $proxy = detect( $addr )
54      *  Start detection and return TRUE if a proxy server is detected...
55      */
56     function detect($addr){
57         GLOBAL $G_proxy_white_list;
58
59         foreach($G_proxy_white_list as $authproxy) {
60             if ($addr == $authproxy)
61                 return (FALSE);
62         }
63
64         if ($this->exists_in_rbl($addr) == TRUE)
65             return (TRUE);
66
67         //nope, no proxy was logged...
68         return FALSE;
69     }
70 }
71
72 //init class
73 function is_proxy($addr)
74 {
75     $proxy = new proxy_detector();
76   
77     //start detect
78     return ($proxy->detect($addr));
79 }
80
81 ?>