mailer project continued:
[mailer.git] / inc / libs / removeip_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // "Getter" for anonymous remote IP number
44 function getAnonymousRemoteAddress ($remoteAddr) {
45         // Is config enabled?
46         if (getConfig('removeip_anon_ip') == 'Y') {
47                 // Switch way do we like?
48                 switch (getConfig('anonymous_ip')) {
49                         case 'LOCAL': // localhost
50                                 $remoteAddr = '127.0.0.1';
51                                 break;
52
53                         case 'ZERO': // All four numbers zero
54                                 $remoteAddr = '0.0.0.0';
55                                 break;
56
57                         case 'RANDOM': // Generate random ip
58                                 $remoteAddr = mt_rand(1, 254) . '.' . mt_rand(0, 254) . '.'.mt_rand(0, 254) . '.' . mt_rand(1, 254);
59                                 break;
60                 } // END - switch
61         } // END - if
62
63         // Return it
64         return $remoteAddr;
65 }
66
67 // "Getter" for anonymous remote hostname
68 function getAnonymousRemoteHost ($remoteHost) {
69         // Is config enabled?
70         if (getConfig('removeip_anon_host') == 'Y') {
71                 // Set anon hostname
72                 $remoteHost = 'localhost.localnet';
73         } // END - if
74
75         // Return it
76         return $remoteHost;
77 }
78
79 // "Getter" for anonymous user agent
80 function getAnonymousUserAgent ($userAgent) {
81         // Is config enabled?
82         if (getConfig('removeip_anon_ua') == 'Y') {
83                 // Set anon user agent
84                 $userAgent = '-';
85         } // END - if
86
87         // Return it
88         return $userAgent;
89 }
90
91 // "Getter" for anonymous referer
92 function getAnonymousReferer ($referer) {
93         // Is config enabled?
94         if (getConfig('removeip_anon_ref') == 'Y') {
95                 // Set anon user agent
96                 $referer = '-';
97         } // END - if
98
99         // Return it
100         return $referer;
101 }
102
103 // Adds informations about anonymity/privacy to the menu
104 function addAnonymityLevel () {
105         // "Base-privacy" is by default low (we add more later)
106         $anonymity = '0';
107
108         // Is some data anonymized?
109         if (getConfig('removeip_anon_ip')   == 'Y') $anonymity++;
110         if (getConfig('removeip_anon_host') == 'Y') $anonymity++;
111         if (getConfig('removeip_anon_ua')   == 'Y') $anonymity++;
112         if (getConfig('removeip_anon_ref')  == 'Y') $anonymity++;
113
114         // Calculate anonymity level
115         $level = round($anonymity / 4 * 3);
116
117         // Set constant name suffix depending on that level
118         $suffix = 'unsupported_' . $level;
119         switch ($level) {
120                 case '0':
121                         $suffix = 'none';
122                         break;
123
124                 case '1':
125                         $suffix = 'low';
126                         break;
127
128                 case '2':
129                         $suffix = 'medium';
130                         break;
131
132                 case '3': // High level
133                         $suffix = 'high';
134                         break;
135         } // END - while
136
137         // Default message
138         $message = sprintf("{--REMOVEIP_LEVEL_%s--}", strtoupper($suffix));
139
140         // Output message in template
141         return loadTemplate('removeip_level', true, $message);
142 }
143
144 // [EOF]
145 ?>