source: extensions/Mail_supervisor/mail_super.inc.php @ 11835

Last change on this file since 11835 was 11835, checked in by cljosse, 13 years ago

[extensions] mail_supervisor cleaning of the programs

File size: 14.1 KB
Line 
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
23class 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,$page;
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 ;
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        //====== par defaut =======================
242         $new_val=false;
243        $def_para->check_mailto="on";
244        $def_para->check_header_carbon="on";
245        $def_para->check_send_webmaster="off";
246        $def_para->no_ipaddress="off";  // interdiction adresse ip
247
248        $def_para->no_mail_list="on";
249        $def_para->no_connect="on"; // empeche l'ip de se connecter au site.
250        $def_para->set_auto="on";       // Test a l'ouverture et enregistrement
251        $def_para->ip="127.0.0.1";      // derniére adresse IP
252        $def_para->set_id="on";       // enregistrment nouvel
253        $def_para->debug_mail="off";       // debogage
254
255        foreach ($def_para as $key => $value) {
256          if(isset($parametres[$key])){
257              $value=$parametres[$key];
258           } else {
259              $new_val=true;
260        }
261           $new_val= isset($_POST[$key]) && $new_val ;
262            unset( $parametres[$key]) ;
263            $parametres[$key]= (isset($_POST[$key]))? "on" : $value ;       
264        }
265
266        if($new_val){
267            sauve_options();
268      }
269    return $parametres ;
270  }
271  //==========================================================
272  function Set_Options($parametres,$str_index){
273  global $infos_message,$conf;
274      foreach ($parametres as $key => $value) {
275       $parametres[$key]=(isset($_POST[$key]))? "on" : $value ;
276      }
277      $parametres['no_connect']= 'off' ;
278     return $parametres ;
279  }
280  //==========================================================
281function sauve_options(){
282  global $options,$infos_message,$conf,$mails_options  ;
283  $infos_message .=l10n("save_config")."<br>";
284  $mails_parametres=mail_supervisor::Set_Options($mails_options,"mail_superv");
285
286 if ( isset($mails_parametres) )
287    {       $query = '
288            UPDATE '.CONFIG_TABLE.'
289            SET value="'.addslashes(serialize($mails_parametres)).'"
290            WHERE param = "mail_superv"
291            LIMIT 1';
292            pwg_query($query);
293      }
294
295 }
296
297 /****************************************
298 * sauve_donnees()
299 ****************************************/
300  function sauve_donnees(){
301  global $mails_donnees,$superv_champs,$superv_type,$erreur_message ;
302  //=====================================================================
303  $clefs = $superv_champs ;
304  $valeurs = array();
305  foreach ( $clefs as $champ){
306     $champ = trim($champ);
307        if($champ !="id")
308        if ( isset($mails_donnees[  $champ ]) ) {
309          $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ;
310          array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[  $champ ] . $sep)  ;
311        }else{
312          array_push($valeurs , "`".$champ."`" . ' = ' .  "0"  )  ;
313        }
314      }
315
316  $valeurs = implode(", ",$valeurs) ;
317  //=====================================================================
318  $query = '
319          UPDATE '.mail_superv_TABLE.'
320          SET '. $valeurs .'
321          WHERE `id` = 1 LIMIT 1 ';
322          ;
323  ob_start();
324      $ret=  pwg_query($query)    ;
325      $m= ob_get_contents();
326      if($m!="") $m="Mail_super.inc.php sauve_donnees() l:323<br />".$m;
327  ob_end_clean() ;
328  $erreur_message .= $m ;
329  }
330//=================================================================================
331  function Get_Datas(){
332    global $superv_champs ;
333     verif_base();
334    $champs = implode(",",$superv_champs );
335      $query = "SELECT ".$champs."
336      FROM ".mail_superv_TABLE."
337      ;";
338        $result = @pwg_query($query);
339           
340    if (!$result) {
341            verif_base();
342            $result = @pwg_query($query);
343        }
344    $data = mysql_fetch_array($result,MYSQL_ASSOC);
345    //====================================================================================
346    $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] );
347    $next_day = ($next_day >0) ? $next_day :  (604800  + time()) ;
348    $data['rest_mail'] =    $next_day - time() ;
349    $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']);
350    $next_day = ($next_day >0) ? $next_day :  (172800  + time()) ;
351    $data['rest_spam'] =  $next_day - time() ;
352    $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']);
353    $next_day = ($next_day >0) ? $next_day :  (172800 + time()) ;
354    //====================================================================================
355    if ($data['quarantaine'] == 'true' ) {
356            $data['reste'] =   ( $next_day )-time() ;
357    }else{
358            $data['reste'] = 0;
359    }
360
361        return $data;
362  }
363 }
364?>
Note: See TracBrowser for help on using the repository browser.