not previous included files added
[curl-de-sac.git] / web / Obj / proxy_detector.phh
1 <?php
2 /*
3  *      Proxy Detector v0.1 with curl-de-sac 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 ProxyDetector {
21     
22     /**
23      * CONSTRUCTOR
24      *  Set defaults...
25      */
26     function ProxyDetector(){
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         if ($this->exists_in_rbl($addr) == TRUE)
58             return (TRUE);
59
60         //nope, no proxy was logged...
61         return FALSE;
62     }
63 }
64
65 //init class
66 function is_proxy($addr)
67 {
68     $proxy = new ProxyDetector();
69     
70     //start detect
71     return ($proxy->detect($addr));
72 }
73
74 ?>