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

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

[extensions] mail_supervisor compatibility with piwigo 2.2 ,cluetip

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