home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 139 / Exame Informatica 139.iso / Revista / Flash / Uniform Server / diskw / home / admin / www / phpMyBackupPro / config.php < prev    next >
Encoding:
PHP Script  |  2005-07-14  |  15.8 KB  |  313 lines

  1. <?php
  2. /*
  3.  +--------------------------------------------------------------------------+
  4.  | phpMyBackupPro                                                           |
  5.  +--------------------------------------------------------------------------+
  6.  | Copyright (c) 2004-2005 by Dirk Randhahn                                 |
  7.  | http://www.phpMyBackupPro.net                                            |
  8.  | version information can be found in definitions.php.                     |
  9.  |                                                                          |
  10.  | This program is free software; you can redistribute it and/or            |
  11.  | modify it under the terms of the GNU General Public License              |
  12.  | as published by the Free Software Foundation; either version 2           |
  13.  | of the License, or (at your option) any later version.                   |
  14.  |                                                                          |
  15.  | This program is distributed in the hope that it will be useful,          |
  16.  | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
  17.  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            |
  18.  | GNU General Public License for more details.                             |
  19.  |                                                                          |
  20.  | You should have received a copy of the GNU General Public License        |
  21.  | along with this program; if not, write to the Free Software              |
  22.  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.|
  23.  +--------------------------------------------------------------------------+
  24. */
  25.  
  26. require_once("login.php");
  27.  
  28. // items which are checkboxes and the config page basic(1) or ext(2)
  29. $checkbox=array("ftp_use"=>1,"ftp_pasv"=>1,"email_use"=>1,"import_error"=>2,"no_login"=>2,"ftp_del"=>1,"dir_backup"=>2,"dir_rec"=>2,"login"=>2);
  30.  
  31. // check if all configuration settings are available
  32. // login, stylesheet and lang are checked before
  33. if (!isset($CONF['sitename'])) $CONF['sitename']='';
  34. if (!isset($CONF['ftp_use'])) $CONF['ftp_use']='';
  35. if (!isset($CONF['ftp_server'])) $CONF['ftp_server']='';
  36. if (!isset($CONF['ftp_user'])) $CONF['ftp_user']='';
  37. if (!isset($CONF['sql_passwd'])) $CONF['sql_passwd']='';
  38. if (!isset($CONF['sql_host'])) $CONF['sql_host']='';
  39. if (!isset($CONF['sql_user'])) $CONF['sql_user']='';
  40. if (!isset($CONF['sql_db'])) $CONF['sql_db']='';
  41. if (!isset($CONF['ftp_passwd'])) $CONF['ftp_passwd']='';
  42. if (!isset($CONF['ftp_path'])) $CONF['ftp_path']='';
  43. if (!isset($CONF['ftp_pasv'])) $CONF['ftp_pasv']='';
  44. if (!isset($CONF['ftp_port'])) $CONF['ftp_port']='';
  45. if (!isset($CONF['ftp_del'])) $CONF['ftp_del']='';
  46. if (!isset($CONF['email_use'])) $CONF['email_use']='';
  47. if (!isset($CONF['email'])) $CONF['email']='';
  48. if (!isset($CONF['date'])) $CONF['date']='';
  49. if (!isset($CONF['del_time'])) $CONF['del_time']='';
  50. if (!isset($CONF['del_number'])) $CONF['del_number']='';
  51. if (!isset($CONF['timelimit'])) $CONF['timelimit']='';
  52. if (!isset($CONF['confirm'])) $CONF['confirm']='';
  53. if (!isset($CONF['import_error'])) $CONF['import_error']='';
  54. if (!isset($CONF['no_login'])) $CONF['no_loginxxxx']='';
  55. if (!isset($CONF['dir_backup'])) $CONF['dir_backup']='';
  56. if (!isset($CONF['dir_rec'])) $CONF['dir_rec']='';
  57.     
  58. // if data has been saved
  59. if (isset($_POST['submit'])) {
  60.  
  61.     // configurations
  62.     if (isset($_POST['sql_host']) || isset($_POST['del_time'])) {
  63.     
  64.         // first set all check boxes of the selected configuration tab to "0"
  65.         foreach ($checkbox as $item=>$page) {
  66.             // checkboxes on extended configurations
  67.             if ($page=="2" && isset($_GET['ext'])) $CONF[$item]="0";
  68.                 // checkboxes on basic configurations
  69.                 elseif($page=="1" && !isset($_GET['ext'])) $CONF[$item]="0";
  70.         }
  71.         
  72.         // update $CONF
  73.         foreach($CONF as $item=>$value) {
  74.             // don't save settings for several servers in conf.php
  75.             if ($item=="sql_host_s" || $item=="sql_user_s" || $item=="sql_passwd_s" || $item=="sql_db_s") continue;
  76.             
  77.             // check if the value was posted
  78.             if (isset($_POST[$item])) {
  79.                 if (isset($checkbox[$item])) {
  80.                     $CONF[$item]=1;
  81.                 } else {
  82.                     $CONF[$item]=$_POST[$item];
  83.                 }
  84.             }
  85.         }       
  86.            
  87.     // system variables
  88.     } else {
  89.         foreach($_POST as $key=>$value) {
  90.             if ($key!="submit") $PMBP_SYS_VAR[$key]=$value;
  91.         }
  92.     }
  93.     
  94.     // save $CONF to global_conf.php
  95.     if (PMBP_save_global_conf()) {
  96.         $out="<div class=\"green\">".C_SAVED."!</div>\n";
  97.     } else {
  98.         $out="<div class=\"red\">".PMBP_GLOBAL_CONF." ".C_WRITEABLE."!</div>\n";
  99.     }
  100. }
  101.  
  102.  
  103. PMBP_print_header(ereg_replace(".*/","",$_SERVER['SCRIPT_NAME']));
  104. if (isset($out)) echo $out;
  105.  
  106. // validation type of some variables
  107. $validate=array('timelimit'=>"int",'del_time'=>"float",'email'=>"email",'ftp_port'=>"int");
  108. $conf=array(C_TIMELIMIT=>"timelimit",C_FTP_PORT=>"ftp_port",C_DEL_TIME=>"del_time",C_EMAIL=>"email");
  109.  
  110. // validate
  111. foreach($CONF as $key=>$value) {
  112.     if (array_key_exists($key,$validate)) {
  113.         switch($validate[$key]) {
  114.             case "int": if (!eregi("^[0-9]*$",$value)) echo "<div class=\"red\">'".array_search($key,$conf)."' ".C_WRONG_TYPE."</div>\n";
  115.                 break;
  116.             case "float": if (!eregi("^[0-9]*\.?[0-9]*$",$value)) echo "<div class=\"red\">'".array_search($key,$conf)."' ".C_WRONG_TYPE."</div>\n";
  117.                 break;
  118.             case "email": if ($value||$CONF['email_use']) {
  119.                     foreach(explode(",",$value) as $value2) {
  120.                         if (!eregi("^\ *[Σ÷ⁿ─╓▄a-zA-Z0-9_-]+(\.[Σ÷ⁿ─╓▄a-zA-Z0-9\._-]+)*@([Σ÷ⁿ─╓▄a-zA-Z0-9-]+\.)+([a-z]{2,4})$",$value2)) {
  121.                             echo "<div class=\"red\">'".array_search($key,$conf)."' ".C_WRONG_TYPE."</div>\n";
  122.                             break;
  123.                         }
  124.                     }
  125.                 }
  126.                 break;
  127.         }
  128.     }
  129. }
  130.  
  131. // if no db connection possible
  132. if (isset($_SESSION['sql_host_org'])) {
  133.     if (!@mysql_connect($_SESSION['sql_host_org'],$_SESSION['sql_user_org'],$_SESSION['sql_passwd_org'])) echo "<div class=\"red\">".C_WRONG_SQL."</div>";     
  134.     if ($_SESSION['sql_db_org']) if (!@mysql_select_db($_SESSION['sql_db_org'])) echo "<div class=\"red\">".C_WRONG_DB."</div>";    
  135. } else {
  136.     if (!@mysql_connect($CONF['sql_host'],$CONF['sql_user'],$CONF['sql_passwd'])) echo "<div class=\"red\">".C_WRONG_SQL."</div>";
  137.     if ($CONF['sql_db']) if (!@mysql_select_db($CONF['sql_db'])) echo "<div class=\"red\">".C_WRONG_DB."</div>";
  138. }
  139.  
  140. // only if 'good internet connection' and if no ftp connection possible
  141. if ($CONF['ftp_use'] || $CONF['dir_backup']) {
  142.     if (!$CONF['ftp_server']) {
  143.         echo "<div class=\"red\">".C_WRONG_FTP."</div>";
  144.     // check onky if internet connections seems to be good
  145.     } elseif(!$_SESSION['PMBP_VERSION']) {
  146.         if (!$conn_id=@ftp_connect($CONF['ftp_server'],$CONF['ftp_port']))
  147.             echo "<div class=\"red\">".C_WRONG_FTP."</div>";
  148.     }
  149. }
  150.  
  151. // print configuration selection
  152. if (isset($_GET['ext'])) echo "<div class=\"bold\"><a href=\"config.php\">".C_BASIC_VAL."</a> | ".C_EXT_VAL." | <a href=\"config.php?sys=TRUE\">".PMBP_C_SYSTEM_VAL."</a></div>";
  153.     elseif(isset($_GET['sys'])) echo "<div class=\"bold\"><a href=\"config.php\">".C_BASIC_VAL."</a> | <a href=\"config.php?ext=TRUE\">".C_EXT_VAL."</a> | ".PMBP_C_SYSTEM_VAL."</div>\n";    
  154.         else echo "<div class=\"bold\">".C_BASIC_VAL." | <a href=\"config.php?ext=TRUE\">".C_EXT_VAL."</a> | <a href=\"config.php?sys=TRUE\">".PMBP_C_SYSTEM_VAL."</a></div>\n";
  155.  
  156. // print html code
  157. if (isset($_GET['ext'])) echo "<br><form action=\"config.php?ext=TRUE\" method=\"post\">\n";
  158.     elseif(isset($_GET['sys'])) echo "<br><form action=\"config.php?sys=TRUE\" method=\"post\">\n";
  159.         else echo "<br><form action=\"config.php\" method=\"post\">\n";
  160. echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"1\" width=\"100%\">\n";
  161.  
  162. if (isset($_GET['ext'])) {
  163.     echo "<tr>";
  164.     echo "<td><br><div class=\"bold_left\">".C_TITLE_STYLE."</div></td><td colspan=\"7\"><br><hr></td>\n";
  165.     echo "</tr><tr>";
  166.     echo "<td>".C_STYLESHEET."*:</td><td>".PMBP_config_print("stylesheet")."</td>\n";
  167.     echo "<td>".C_DATE."*:</td><td>".PMBP_config_print("date")."</td>\n";
  168.     echo "<td>".C_LOGIN."*:</td><td>".PMBP_config_print("login")."</td>\n";
  169.     echo "<td> </td><td> </td>\n";
  170.     echo "</tr><tr>";
  171.     echo "<td><br><div class=\"bold_left\">".C_TITLE_DELETE."</div></td><td colspan=\"7\"><br><hr></td>\n";
  172.     echo "</tr><tr>";
  173.     echo "<td>".C_DEL_TIME.":</td><td>".PMBP_config_print("del_time")."</td>\n";
  174.     echo "<td>".C_DEL_NUMBER.":</td><td>".PMBP_config_print("del_number")."</td>\n";
  175.     echo "<td> </td><td> </td>\n";
  176.     echo "<td> </td><td> </td>\n";
  177.     echo "</tr><tr>";
  178.     echo "<td><br><div class=\"bold_left\">".C_TITLE_CONFIG."</div></td><td colspan=\"7\"><br><hr></td>\n";
  179.     echo "</tr><tr>";
  180.     echo "<td>".C_TIMELIMIT."*:</td><td>".PMBP_config_print("timelimit")."</td>\n";
  181.     echo "<td>".C_CONFIRM."*:</td><td>".PMBP_config_print("confirm")."</td>\n";
  182.     echo "<td>".C_IMPORT_ERROR.":</td><td>".PMBP_config_print("import_error")."</td>\n";
  183.     echo "<td> </td><td> </td>\n";
  184.     echo "</tr><tr>";
  185.     echo "<td>".C_DIR_BACKUP.":</td><td>".PMBP_config_print("dir_backup")."</td>\n";
  186.     echo "<td>".C_DIR_REC.":</td><td>".PMBP_config_print("dir_rec")."</td>\n";
  187.     echo "<td>[".C_NO_LOGIN.":</td><td>".PMBP_config_print("no_login")."]</td>\n";
  188.     echo "<td> </td><td> </td>\n";
  189.     echo "</tr>";
  190. } elseif(isset($_GET['sys'])) {
  191.     echo "<div class=\"red\">".PMBP_C_SYS_WARNING."</div><br>";
  192.     $i=0;
  193.     foreach($PMBP_SYS_VAR as $key=>$value) {            
  194.         if ($i%2==0) echo "<tr>\n";
  195.         echo "<td colspan=\"2\">".$key.":</td><td colspan=\"2\"><input type=\"text\" size=\"20\" name=\"".$key."\" value=\"".$value."\"></td>\n";
  196.         if ($i%2==1) echo "</tr>";
  197.         $i++;
  198.     }
  199.     if ($i%2) echo "</tr>\n";
  200. } else {
  201.     echo "<tr>";
  202.     echo "<td colspan=\"8\"> </td></tr>";
  203.     echo "<tr><td>".C_SITENAME."*:</td><td>".PMBP_config_print("sitename")."</td>\n";
  204.     echo "<td>".C_LANG."*:</td><td>".PMBP_config_print("lang")."</td>\n";
  205.     echo "<td> </td><td> </td>\n";
  206.     echo "<td> </td><td> </td>\n";
  207.     echo "</tr><tr>";
  208.     echo "<td><br><div class=\"bold_left\">".C_TITLE_SQL."</div></td><td colspan=\"7\"><br><hr></td>\n";
  209.     echo "</tr><tr>";
  210.     echo "<td>".C_SQL_HOST."*:</td><td>".PMBP_config_print("sql_host")."</td>\n";
  211.     echo "<td>".C_SQL_USER."*:</td><td>".PMBP_config_print("sql_user")."</td>\n";
  212.     echo "<td>".C_SQL_PASSWD."*:</td><td>".PMBP_config_print("sql_passwd")."</td>\n";
  213.     echo "<td>".C_SQL_DB.":</td><td>".PMBP_config_print("sql_db")."</td>\n";
  214.     echo "</tr><tr>";
  215.     echo "<td><br><div class=\"bold_left\">".C_TITLE_FTP."</div></td><td colspan=\"7\"><br><hr></td>\n";
  216.     echo "</tr><tr>";
  217.     echo "<td>".C_FTP_USE.":</td><td>".PMBP_config_print("ftp_use")."</td>\n";
  218.     echo "<td>".C_FTP_SERVER.":</td><td>".PMBP_config_print("ftp_server")."</td>\n";
  219.     echo "<td>".C_FTP_USER.":</td><td>".PMBP_config_print("ftp_user")."</td>\n";
  220.     echo "<td>".C_FTP_PASSWD.":</td><td>".PMBP_config_print("ftp_passwd")."</td>\n";
  221.     echo "</tr><tr>";
  222.     echo "<td>".C_FTP_PATH.":</td><td>".PMBP_config_print("ftp_path")."</td>\n";
  223.     echo "<td>".C_FTP_PASV.":</td><td>".PMBP_config_print("ftp_pasv")."</td>\n";
  224.     echo "<td>".C_FTP_PORT.":</td><td>".PMBP_config_print("ftp_port")."</td>\n";
  225.     echo "<td>".C_FTP_DEL.":</td><td>".PMBP_config_print("ftp_del")."</td>\n";
  226.     echo "</tr><tr>";
  227.     echo "<td><br><div class=\"bold_left\">".C_TITLE_EMAIL."</div></td><td colspan=\"7\"><br><hr></td>\n";
  228.     echo "</tr><tr>";
  229.     echo "<td>".C_EMAIL_USE.":</td><td>".PMBP_config_print("email_use")."</td>\n";
  230.     echo "<td>".C_EMAIL.":</td><td>".PMBP_config_print("email")."</td>\n";
  231.     echo "<td> </td><td> </td>\n";
  232.     echo "<td> </td><td> </td>\n";
  233.     echo "</tr>";
  234. }
  235.  
  236. echo "<tr><td colspan=\"8\">\n<input name=\"submit\" type=\"submit\" value=\"".C_SAVE."\" class=\"button\"></td></tr>\n</table>\n</form>";
  237. PMBP_print_footer();
  238.  
  239.  
  240. // two functions only used in config.php
  241.  
  242. // returns the html code for the different configuration items and controls
  243. function PMBP_config_print($item) {
  244.     global $CONF;
  245.     
  246.     // vars whos type is checkbox, password, select or a filelist
  247.     global $checkbox;
  248.     $password=array("sql_passwd","ftp_passwd");
  249.     $select['confirm']=array(C_CONFIRM_1,C_CONFIRM_2,C_CONFIRM_3,C_CONFIRM_4);
  250.     $time=time();
  251.     $select['date']=array(BD_DATE_FORMAT=>strftime(BD_DATE_FORMAT,$time),
  252.         "%x %X"=>strftime("%x %X",$time),"%x %H:%M"=>strftime("%x %H:%M",$time),
  253.         "%m/%d/%y %X"=>strftime("%m/%d/%y %X",$time),"%m/%d/%y %H:%M"=>strftime("%m/%d/%y %H:%M",$time),
  254.         "%b %d %Y %X"=>strftime("%b %d %Y %X",$time),"%b %d %Y %H:%M"=>strftime("%b %d %Y %H:%M",$time),
  255.         "%Y/%m/%d %X"=>strftime("%Y/%m/%d %X",$time),"%Y/%m/%d %H:%M"=>strftime("%Y/%m/%d %H:%M",$time));
  256.     $filelist['lang']=array(PMBP_LANGUAGE_DIR,".inc.php");
  257.     $filelist['stylesheet']=array(PMBP_STYLESHEET_DIR,".css");
  258.  
  259.     // create the html code
  260.     if (isset($checkbox[$item])) {
  261.         if ($CONF[$item]) $status=" checked"; else $status=" ";
  262.         $out="<input type=\"checkbox\" name=\"".$item."\" value=\"".$CONF[$item]."\"".$status.PMBP_config_disable($item).">";
  263.     } elseif (in_array($item,$password)) {
  264.         $out="<input type=\"password\" size=\"10\" name=\"".$item."\" value=\"".$CONF[$item]."\"".PMBP_config_disable($item).">";
  265.     } elseif (isset($select[$item])) {
  266.         $out="<select name=\"".$item."\"".PMBP_config_disable($item).">\n";
  267.         foreach($select[$item] as $opt_no=>$print_value)
  268.             if ($opt_no==$CONF[$item]) $out.="<option value=\"".$opt_no."\" selected>".$print_value."</option>\n";
  269.                 else $out.="<option value=\"".$opt_no."\">".$print_value."</option>\n";
  270.         $out.="</select>";
  271.     } elseif(isset($filelist[$item])) {
  272.         $files=FALSE;
  273.         $handle=opendir("./".$filelist[$item][0]);
  274.         while ($file=readdir($handle))
  275.             if (substr($file,-(strlen($filelist[$item][1])),strlen($filelist[$item][1]))==$filelist[$item][1])
  276.                 $files[]=substr($file,0,strlen($file)-strlen($filelist[$item][1]));
  277.         $out="<select name=\"".$item."\">\n";
  278.         foreach($files as $file)
  279.             if ($file==$CONF[$item]) $out.="<option value=\"".$file."\" selected>".$file."</option>\n"; else $out.="<option value=\"".$file."\">".$file."</option>\n";
  280.         $out.="</select>";
  281.     } else {
  282.         $out="<input type=\"text\" size=\"10\" name=\"".$item."\" value=\"".$CONF[$item]."\"".PMBP_config_disable($item)."><br>";
  283.     }
  284.     return $out;
  285. }
  286.  
  287. // checks if a item should be disabled and returns the code to disable it
  288. function PMBP_config_disable($item) {
  289.     global $CONF;
  290.     // availability check for some functions
  291.     $disable=array('ftp_use'=>"!function_exists(\"ftp_connect\")",'ftp_server'=>"!function_exists(\"ftp_connect\")",
  292.         'ftp_user'=>"!function_exists(\"ftp_connect\")",'ftp_passwd'=>"!function_exists(\"ftp_connect\")",
  293.         'ftp_path'=>"!function_exists(\"ftp_connect\")",'ftp_pasv'=>"!function_exists(\"ftp_connect\")",
  294.         'ftp_port'=>"!function_exists(\"ftp_connect\")",'email_use'=>"!function_exists(\"mail\")",'email'=>"!function_exists(\"mail\")",
  295.         'timelimit'=>"ini_get(\"safe_mode\")");
  296.  
  297.     // disable selected items
  298.     $out="";
  299.     if (isset($disable[$item])) {
  300.         if (eval("return(".$disable[$item].");")) $out=" disabled";
  301.         // special case 'timelimit'
  302.         if ($item=="timelimit" && $out) {
  303.             $timelimit=ini_get("max_execution_time");
  304.             if ($CONF['timelimit']!=$timelimit) {
  305.                 $CONF['timelimit']=$timelimit;
  306.                 PMBP_save_global_conf();
  307.             }
  308.         }
  309.     }
  310.     return $out;
  311. }
  312. ?>
  313.