1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // | Mail supervisor | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | Copyright(C) 2010 cljosse | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | This program is free software; you can redistribute it and/or modify | |
---|
9 | // | it under the terms of the GNU General Public License as published by | |
---|
10 | // | the Free Software Foundation | |
---|
11 | // | | |
---|
12 | // | This program is distributed in the hope that it will be useful, but | |
---|
13 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
14 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
15 | // | General Public License for more details. | |
---|
16 | // | | |
---|
17 | // | You should have received a copy of the GNU General Public License | |
---|
18 | // | along with this program; if not, write to the Free Software | |
---|
19 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
20 | // | USA. | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | |
---|
23 | class mail_supervisor { |
---|
24 | //============================================================ |
---|
25 | /* |
---|
26 | * admin_menu |
---|
27 | */ |
---|
28 | static public function admin_menu($menu) { |
---|
29 | array_push($menu, |
---|
30 | array( 'NAME' => 'Mail supervisor', |
---|
31 | 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php') |
---|
32 | ) |
---|
33 | ); |
---|
34 | return $menu; |
---|
35 | } |
---|
36 | //============================================================ |
---|
37 | /* |
---|
38 | * init |
---|
39 | */ |
---|
40 | static public function init() { |
---|
41 | global $template,$version,$icon_path; |
---|
42 | $action_spam = pwg_get_session_var('action_spam') ; |
---|
43 | $theme="default"; |
---|
44 | $themeconf=$template->get_template_vars('themeconf'); |
---|
45 | $theme=$themeconf['id']; |
---|
46 | if (file_exists ( 'admin/themes/clear/icon/help.png')) $icon_path = 'themes/default/icon/help.png'; |
---|
47 | else $icon_path = "admin/template/goto/theme/clear/icon/help.png"; |
---|
48 | if (PHPWG_VERSION < 2.2 ) { |
---|
49 | $file =MAIL_SUPERV_PATH_ABS.'admin/header_2_1.tpl' ; |
---|
50 | |
---|
51 | } else { |
---|
52 | $file = MAIL_SUPERV_PATH_ABS.'admin/header_2_2.tpl' ; |
---|
53 | |
---|
54 | } |
---|
55 | if(isset($_GET['action_spam']) and $_GET['action_spam']=="no"){ |
---|
56 | pwg_set_session_var('action_spam', "false"); |
---|
57 | unset ($_SESSION['pwg_'.'action_spam']); |
---|
58 | } |
---|
59 | $action_spam=pwg_get_session_var('action_spam'); |
---|
60 | $template->set_filenames(array('mail_superv_init'=> $file )); |
---|
61 | $MAIL_SUPERV_PATH=str_replace(PHPWG_ROOT_PATH,"",MAIL_SUPERV_PATH) ; |
---|
62 | $profile=array('theme' => $theme, |
---|
63 | 'PHPWG_VERSION' => PHPWG_VERSION , |
---|
64 | 'MAIL_SUPERV_PATH' => $MAIL_SUPERV_PATH , |
---|
65 | 'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS |
---|
66 | ); |
---|
67 | |
---|
68 | $template->assign( $profile ); |
---|
69 | $template->append('footer_elements', '<input id="action_spam" name="action_spam" type="hidden" value="'.$action_spam.'" />'); |
---|
70 | $template->parse( 'mail_superv_init', false); |
---|
71 | return ;// |
---|
72 | }// function init |
---|
73 | //============================================================ |
---|
74 | /* |
---|
75 | * affiche_message |
---|
76 | */ |
---|
77 | //============================================================ |
---|
78 | static public function affiche_message(){ |
---|
79 | global $template,$infos_message,$erreur_message, $user ,$ip; |
---|
80 | global $mails_options,$conf,$lang,$page ; |
---|
81 | global $action_spam ; |
---|
82 | if (!isset($ip)) { |
---|
83 | if (getenv("HTTP_CLIENT_IP")) { |
---|
84 | $ip=getenv("HTTP_CLIENT_IP"); |
---|
85 | }else{ |
---|
86 | $ip=getenv("REMOTE_ADDR"); |
---|
87 | } |
---|
88 | } |
---|
89 | // unset ($_SESSION['pwg_'.'action_spam']); |
---|
90 | $action_spam = pwg_get_session_var('action_spam') ; |
---|
91 | |
---|
92 | if ($action_spam == null or $action_spam == 'false') { |
---|
93 | $action_spam = kill_list(); |
---|
94 | } |
---|
95 | |
---|
96 | if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ; |
---|
97 | if ($action_spam == "true" ) { |
---|
98 | $erreur_message .= $ip . " " . $action_spam ; |
---|
99 | pwg_set_session_var('action_spam', "true"); |
---|
100 | $erreur_message .= "<br />".l10n('Sv_is_a_spam') ; |
---|
101 | if ($mails_options['no_connect'] == 'on1' ){ |
---|
102 | //[status] => guest |
---|
103 | //[status] => normal |
---|
104 | //[status] => webmaster |
---|
105 | if ($user['status'] != 'webmaster' ) |
---|
106 | if (!isset($_GET['admin'])) { |
---|
107 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
108 | }elseif ($_GET['admin'] != 'piwigo'){ |
---|
109 | die('blacklist Hacking attempt!'); |
---|
110 | } |
---|
111 | unset ($_SESSION['pwg_'.'action_spam']); |
---|
112 | } |
---|
113 | }else{ |
---|
114 | pwg_set_session_var('action_spam', "false"); |
---|
115 | } |
---|
116 | |
---|
117 | if (isset($infos_message)) |
---|
118 | if ($infos_message != "") { |
---|
119 | $infos_message = str_replace("\n",'<br />',$infos_message) ; |
---|
120 | if (!isset($page['infos'])) $page['infos']=Array($infos_message); |
---|
121 | else if(is_array($page['infos'])) array_push($page['infos'], $infos_message); |
---|
122 | else $page['infos']=Array($infos_message); |
---|
123 | $infos_message=""; |
---|
124 | } |
---|
125 | if (isset($erreur_message)) |
---|
126 | if ($erreur_message != "") { |
---|
127 | $erreur_message = str_replace("\n",'<br />',$erreur_message) ; |
---|
128 | if (!isset($page['errors'])) $page['errors']=Array($erreur_message); |
---|
129 | else if(is_array($page['errors'])) array_push($page['errors'], $erreur_message); |
---|
130 | else $page['errors']=Array($erreur_message); |
---|
131 | $erreur_message =""; |
---|
132 | } |
---|
133 | return $action_spam; |
---|
134 | } //fin Affiche_message |
---|
135 | |
---|
136 | //============================================================ |
---|
137 | /* |
---|
138 | * Get_geo |
---|
139 | */ |
---|
140 | static public function Get_geo() { |
---|
141 | global $info_geo,$ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options; |
---|
142 | //=================================================================================== |
---|
143 | $info_geo = pwg_get_session_var('info_geo'); |
---|
144 | if (count($info_geo) > 0){ |
---|
145 | $pays = $info_geo[0]; |
---|
146 | $region = $info_geo[1]; |
---|
147 | $ville = $info_geo[2]; |
---|
148 | $latitude = $info_geo[3]; |
---|
149 | $longitude = $info_geo[4]; |
---|
150 | $ip = $info_geo[5]; |
---|
151 | return true; |
---|
152 | } |
---|
153 | //======================================================================= |
---|
154 | if (isset($_POST['pays'])) { |
---|
155 | $pays = isset($_POST['pays']) ? $_POST['pays'] : ""; |
---|
156 | $region = isset($_POST['region']) ? $_POST['region'] :""; |
---|
157 | $ville = (isset($_POST['ville'])) ? $_POST['ville']: ""; |
---|
158 | $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : ""; |
---|
159 | $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : ""; |
---|
160 | $info_geo = array( $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR'] ); |
---|
161 | pwg_set_session_var('info_geo', $info_geo); |
---|
162 | return true; |
---|
163 | }else{ |
---|
164 | |
---|
165 | $result=""; |
---|
166 | echo '<script type="text/javascript">get_script_geo();</script>'; |
---|
167 | return true; |
---|
168 | } |
---|
169 | } // fin get_geo |
---|
170 | //===================================================================================== |
---|
171 | /* |
---|
172 | * Memo_Var |
---|
173 | */ |
---|
174 | static public function Memo_Var($variables) { |
---|
175 | ob_start(); |
---|
176 | echo '<pre>'; |
---|
177 | if(count($variables)>1){ |
---|
178 | foreach($variables as $key => $line){ |
---|
179 | echo $key . " => " . $line ; |
---|
180 | echo "<br />"; |
---|
181 | } |
---|
182 | }else{ |
---|
183 | echo "<i>".$variables."</i><br />"; |
---|
184 | } |
---|
185 | |
---|
186 | $m= ob_get_contents(); |
---|
187 | ob_end_clean(); |
---|
188 | return $m; |
---|
189 | } |
---|
190 | //====================================================================================== |
---|
191 | static public function Get_Version_plugins($dir){ |
---|
192 | $path = $dir; |
---|
193 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
194 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
195 | { |
---|
196 | $plugin['name'] = trim( $val[1] ); |
---|
197 | } |
---|
198 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
199 | { |
---|
200 | $plugin['version'] = trim($val[1]); |
---|
201 | } |
---|
202 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
203 | { |
---|
204 | $plugin['uri'] = trim($val[1]); |
---|
205 | } |
---|
206 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
207 | { |
---|
208 | $plugin['description'] = trim($desc); |
---|
209 | } |
---|
210 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
211 | { |
---|
212 | $plugin['description'] = trim($val[1]); |
---|
213 | } |
---|
214 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
215 | { |
---|
216 | $plugin['author'] = trim($val[1]); |
---|
217 | } |
---|
218 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
219 | { |
---|
220 | $plugin['author uri'] = trim($val[1]); |
---|
221 | } |
---|
222 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
223 | { |
---|
224 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
225 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
226 | } |
---|
227 | // IMPORTANT SECURITY ! |
---|
228 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
229 | return $plugin ; |
---|
230 | } |
---|
231 | //========================================================== |
---|
232 | function Get_Options($parametres,$str_index){ |
---|
233 | global $conf,$mails_options ; |
---|
234 | $mails_options= $conf[$str_index]; |
---|
235 | if(isset($mails_options)) |
---|
236 | if ( preg_match("|s:(.*)|", $mails_options, $val) ) |
---|
237 | $parametres = unserialize($conf['mail_superv']); |
---|
238 | else{ |
---|
239 | $parametres=explode(",",$mails_options); |
---|
240 | |
---|
241 | $def_para->check_mailto="on"; |
---|
242 | $def_para->check_header_carbon="on"; |
---|
243 | $def_para->check_header_text="on"; |
---|
244 | $def_para->no_mail_list="on"; |
---|
245 | $def_para->no_connect="on"; // empeche l'ip de se connecter au site. |
---|
246 | $def_para->set_auto="on"; // Test a l'ouverture et enregistrement |
---|
247 | $def_para->ip="127.0.0.1"; // dernièrre adresse IP |
---|
248 | $def_para->set_id="on"; // enregistrment nouvel |
---|
249 | $def_para->debug_mail="off"; // debogage |
---|
250 | $i=0; |
---|
251 | foreach ($def_para as $key => $value) { |
---|
252 | $value=$parametres[$i]; |
---|
253 | unset( $parametres[$i]) ; |
---|
254 | $parametres[$key]= $value ; |
---|
255 | $i++; |
---|
256 | } |
---|
257 | } |
---|
258 | return mail_supervisor::Set_Options($parametres,$str_index); |
---|
259 | } |
---|
260 | //========================================================== |
---|
261 | function Set_Options($parametres,$str_index){ |
---|
262 | global $infos_message,$conf; |
---|
263 | foreach ($parametres as $key => $value) { |
---|
264 | $parametres[$key]=(isset($_POST[$key]))? "on" : $value ; |
---|
265 | } |
---|
266 | $parametres['no_connect']= 'off' ; |
---|
267 | return $parametres ; |
---|
268 | } |
---|
269 | //========================================================== |
---|
270 | function sauve_options(){ |
---|
271 | global $options,$infos_message,$conf,$mails_options ; |
---|
272 | $infos_message .=l10n("save_config")."<br>"; |
---|
273 | $mails_parametres=mail_supervisor::Set_Options($mails_options,"mail_superv"); |
---|
274 | |
---|
275 | if ( isset($mails_parametres) ) |
---|
276 | { $query = ' |
---|
277 | UPDATE '.CONFIG_TABLE.' |
---|
278 | SET value="'.addslashes(serialize($mails_parametres)).'" |
---|
279 | WHERE param = "mail_superv" |
---|
280 | LIMIT 1'; |
---|
281 | pwg_query($query); |
---|
282 | } |
---|
283 | |
---|
284 | } |
---|
285 | |
---|
286 | //================================================================================= |
---|
287 | function sauve_donnees(){ |
---|
288 | global $mails_donnees,$superv_champs,$superv_type,$erreur_message ; |
---|
289 | //===================================================================== |
---|
290 | $clefs = $superv_champs ; |
---|
291 | $valeurs = array(); |
---|
292 | foreach ( $clefs as $champ){ |
---|
293 | $champ = trim($champ); |
---|
294 | if ( isset($mails_donnees[ $champ ]) ) { |
---|
295 | $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ; |
---|
296 | array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[ $champ ] . $sep) ; |
---|
297 | }else{ |
---|
298 | array_push($valeurs , "`".$champ."`" . ' = ' . "0" ) ; |
---|
299 | } |
---|
300 | } |
---|
301 | $valeurs = implode(", ",$valeurs) ; |
---|
302 | //===================================================================== |
---|
303 | $query = ' |
---|
304 | UPDATE '.mail_superv_TABLE.' |
---|
305 | SET '. $valeurs .' |
---|
306 | WHERE `id` = 1 LIMIT 1 '; |
---|
307 | ; |
---|
308 | ob_start(); |
---|
309 | $ret= pwg_query($query) ; |
---|
310 | $m= ob_get_contents(); |
---|
311 | ob_end_clean() ; |
---|
312 | $erreur_message .= $m ; |
---|
313 | } |
---|
314 | //================================================================================= |
---|
315 | function Get_Datas(){ |
---|
316 | global $superv_champs ; |
---|
317 | $champs = implode(",",$superv_champs ); |
---|
318 | $query = "SELECT ".$champs." |
---|
319 | FROM ".mail_superv_TABLE." |
---|
320 | ;"; |
---|
321 | $result = @pwg_query($query); |
---|
322 | if (!$result) { |
---|
323 | verif_base(); |
---|
324 | $result = @pwg_query($query); |
---|
325 | } |
---|
326 | $data = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
327 | //==================================================================================== |
---|
328 | $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] ); |
---|
329 | $next_day = ($next_day >0) ? $next_day : (604800 + time()) ; |
---|
330 | $data['rest_mail'] = $next_day - time() ; |
---|
331 | $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']); |
---|
332 | $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; |
---|
333 | $data['rest_spam'] = $next_day - time() ; |
---|
334 | $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']); |
---|
335 | $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; |
---|
336 | |
---|
337 | if ($data['quarantaine'] == 'true' ) { |
---|
338 | $data['reste'] = ( $next_day )-time() ; |
---|
339 | }else{ |
---|
340 | $data['reste'] = 0; |
---|
341 | } |
---|
342 | |
---|
343 | return $data; |
---|
344 | } |
---|
345 | } |
---|
346 | ?> |
---|