Mahor rewrite:
[mailer.git] / inc / libs / removeip_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/01/2008 *
4  * ===============                              Last change: 10/01/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : removeip_functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for removeip extension         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezielle Funktion fuer removeip-Erweiterung     *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // "Getter" for anonymous remote IP number
41 function GET_ANONYMOUS_REMOTE_ADDR ($remoteAddr) {
42         // Is config enabled?
43         if (getConfig('removeip_anon_ip') == "Y") {
44                 // Switch way do we like?
45                 switch (getConfig('anonymous_ip')) {
46                         case "127.0.0.1": // mod_removeip style
47                         case "0.0.0.0": // Some people may prefer this...
48                                 $remoteAddr = getConfig('anonymous_ip');
49                                 break;
50
51                         case "RANDOM": // Pseudo-random IP number
52                                 $remoteAddr = mt_rand(1,254).".".mt_rand(0,254).".".mt_rand(0,254).".".mt_rand(1,254);
53                                 break;
54                 } // END - switch
55         } // END - if
56
57         // Return it
58         return $remoteAddr;
59 }
60 // "Getter" for anonymous remote hostname
61 function GET_ANONYMOUS_REMOTE_HOST ($remoteHost) {
62         // Is config enabled?
63         if (getConfig('removeip_anon_host') == "Y") {
64                 // Set anon hostname
65                 $remoteHost = "localhost.localnet";
66         } // END - if
67
68         // Return it
69         return $remoteHost;
70 }
71 // "Getter" for anonymous user agent
72 function GET_ANONYMOUS_USER_AGENT ($userAgent) {
73         // Is config enabled?
74         if (getConfig('removeip_anon_ua') == "Y") {
75                 // Set anon user agent
76                 $userAgent = "-";
77         } // END - if
78
79         // Return it
80         return $userAgent;
81 }
82 // "Getter" for anonymous referer
83 function GET_ANONYMOUS_REFERER ($referer) {
84         // Is config enabled?
85         if (getConfig('removeip_anon_ref') == "Y") {
86                 // Set anon user agent
87                 $referer = "-";
88         } // END - if
89
90         // Return it
91         return $referer;
92 }
93 // Adds informations about anonymity/privacy to the menu
94 function REMOVEIP_ADD_INFOS () {
95         // "Base-privacy" is by default low (we add more later)
96         $anonymity = 0;
97
98         // Is some data anonymized?
99         if (getConfig('removeip_anon_ip')   == "Y") $anonymity++;
100         if (getConfig('removeip_anon_host') == "Y") $anonymity++;
101         if (getConfig('removeip_anon_ua')   == "Y") $anonymity++;
102         if (getConfig('removeip_anon_ref')  == "Y") $anonymity++;
103
104         // Calculate anonymity level
105         $level = round($anonymity / 4 * 3);
106
107         // Set constant name suffix depending on that level
108         $suffix = "unsupported_{$level}";
109         switch ($level) {
110                 case 0:
111                         $suffix = "none";
112                         break;
113
114                 case 1:
115                         $suffix = "low";
116                         break;
117
118                 case 2:
119                         $suffix = "medium";
120                         break;
121
122                 case 3: // High level
123                         $suffix = "high";
124                         break;
125         } // END - while
126
127         // Construct constant name
128         $constantName = strtoupper(sprintf("REMOVEIP_LEVEL_%s", $suffix));
129
130         // Default message
131         $message = sprintf(REMOVEIP_UNKNOWN_LEVEL, $suffix);
132
133         // Is that constant there?
134         if (defined($constantName)) {
135                 // Use that string
136                 $message = constant($constantName);
137         } // END - if
138
139         // Output message in template
140         return LOAD_TEMPLATE("removeip_level", true, $message);
141 }
142
143 //
144 ?>