Missing SVN properties set
[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  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 }
43
44 // "Getter" for anonymous remote IP number
45 function getAnonymousRemoteAddress ($remoteAddr) {
46         // Is config enabled?
47         if (getConfig('removeip_anon_ip') == 'Y') {
48                 // Switch way do we like?
49                 switch (getConfig('anonymous_ip')) {
50                         case 'LOCAL': // localhost
51                                 $remoteAddr = '127.0.0.1';
52                                 break;
53
54                         case 'ZERO': // All four numbers zero
55                                 $remoteAddr = '0.0.0.0';
56                                 break;
57
58                         case 'RANDOM': // Generate random ip
59                                 $remoteAddr = mt_rand(1, 254) . '.' . mt_rand(0, 254) . '.'.mt_rand(0, 254) . '.' . mt_rand(1, 254);
60                                 break;
61                 } // END - switch
62         } // END - if
63
64         // Return it
65         return $remoteAddr;
66 }
67
68 // "Getter" for anonymous remote hostname
69 function getAnonymousRemoteHost ($remoteHost) {
70         // Is config enabled?
71         if (getConfig('removeip_anon_host') == 'Y') {
72                 // Set anon hostname
73                 $remoteHost = 'localhost.localnet';
74         } // END - if
75
76         // Return it
77         return $remoteHost;
78 }
79
80 // "Getter" for anonymous user agent
81 function getAnonymousUserAgent ($userAgent) {
82         // Is config enabled?
83         if (getConfig('removeip_anon_ua') == 'Y') {
84                 // Set anon user agent
85                 $userAgent = '-';
86         } // END - if
87
88         // Return it
89         return $userAgent;
90 }
91
92 // "Getter" for anonymous referer
93 function getAnonymousReferer ($referer) {
94         // Is config enabled?
95         if (getConfig('removeip_anon_ref') == 'Y') {
96                 // Set anon user agent
97                 $referer = '-';
98         } // END - if
99
100         // Return it
101         return $referer;
102 }
103
104 // Adds informations about anonymity/privacy to the menu
105 function addAnonymityLevel () {
106         // "Base-privacy" is by default low (we add more later)
107         $anonymity = '0';
108
109         // Is some data anonymized?
110         if (getConfig('removeip_anon_ip')   == 'Y') $anonymity++;
111         if (getConfig('removeip_anon_host') == 'Y') $anonymity++;
112         if (getConfig('removeip_anon_ua')   == 'Y') $anonymity++;
113         if (getConfig('removeip_anon_ref')  == 'Y') $anonymity++;
114
115         // Calculate anonymity level
116         $level = round($anonymity / 4 * 3);
117
118         // Set constant name suffix depending on that level
119         $suffix = 'unsupported_' . $level;
120         switch ($level) {
121                 case '0':
122                         $suffix = 'none';
123                         break;
124
125                 case '1':
126                         $suffix = 'low';
127                         break;
128
129                 case '2':
130                         $suffix = 'medium';
131                         break;
132
133                 case '3': // High level
134                         $suffix = 'high';
135                         break;
136         } // END - while
137
138         // Construct constant name
139         $constantName = sprintf("REMOVEIP_LEVEL_%s", strtoupper($suffix));
140
141         // Default message
142         $message = sprintf(getMessage('REMOVEIP_UNKNOWN_LEVEL'), $suffix);
143
144         // Is that constant there?
145         if (isMessageIdValid($constantName)) {
146                 // Use that string
147                 $message = getMessage($constantName);
148         } // END - if
149
150         // Output message in template
151         return loadTemplate('removeip_level', true, $message);
152 }
153
154 // Filter for adding anonymity notice to the output stream
155 function FILTER_ADD_ANONYMITY_NOTICE ($data) {
156         // Init content
157         $content = $data;
158
159         // Extension removeip activated?
160         if ((isExtensionActive('removeip')) && (getConfig('removeip_'.strtolower($data['access_level']).'_show') == 'Y')) {
161                 // Add anoymity/privacy infos
162                 $content['content'] .= addAnonymityLevel() . "<br />\n";
163         } // END - if
164
165         // Return it
166         return $content;
167 }
168
169 // [EOF]
170 ?>