Changeset 517

Show
Ignore:
Timestamp:
03/31/08 23:28:57 (8 months ago)
Author:
sidtheduck
Message:

Workaround for safe_mode enabled hosts. Asks users for FTP login information

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/plog-admin-functions.php

    r509 r517  
    1212                // Make sure the file exists 
    1313                if($file != "." && $file != ".." && $file[0] != '.') { 
    14                         // If it's a directiry, list all files within it 
     14                        // If it's a directory, list all files within it 
    1515                        if(is_dir($directory . "/" . $file)) { 
    1616                                $tmp2 = get_files($directory . "/" . $file); 
     
    308308        // a new row into collections table, otherwise the collection will not be usable 
    309309        // anyway 
    310         $create_path = $config["basedir"] . "/images/".$collection_folder; 
     310        $create_path = $config["basedir"] . "images/".$collection_folder; 
    311311 
    312312        // create directory 
     
    513513        // first try to create the directory to hold the images, if that fails, then the album 
    514514        // will be unusable anyway 
    515         $create_path = $config["basedir"] . "/images/".$row["collection_path"]."/".$album_folder; 
     515        $create_path = $config["basedir"] . "images/".$row["collection_path"]."/".$album_folder; 
    516516 
    517517        if (!makeDirs($create_path, 0777)) { 
     
    878878function makeDirs($strPath, $mode = 0777) //creates directory tree recursively 
    879879{ 
    880    return is_dir($strPath) or ( makeDirs(dirname($strPath), $mode) and mkdir($strPath, $mode) ); 
     880   if (ini_get('safe_mode')==1){ 
     881      return is_dir($strPath) or ( makeDirs(dirname($strPath), $mode) and FTP_makeDirs($strPath) ); 
     882   }else{ 
     883      return is_dir($strPath) or ( makeDirs(dirname($strPath), $mode) and mkdir($strPath, $mode) ); 
     884   } 
     885} 
     886 
     887function FTP_makeDirs($strPath){ 
     888   global $config; 
     889    
     890   $ftpserver = PLOGGER_FTP_HOST; 
     891   $ftpuser = PLOGGER_FTP_USER; 
     892   $ftppass = PLOGGER_FTP_PW; 
     893    
     894   $ftppath = str_replace($config["basedir"], '', $strPath); 
     895   $ftpDir = dirname($ftppath); 
     896   $ftpnewDir = str_replace($ftpDir."/", '', $ftppath); 
     897    
     898   // create connection 
     899   $ftpconnection = ftp_connect($ftpserver);  
     900   // login to ftp server 
     901   $ftpresult = ftp_login($ftpconnection, $ftpuser, $ftppass); 
     902 
     903   // check if connection was made 
     904   if ((!$ftpconnection) || (!$ftpresult)) { 
     905      return false; 
     906   }else{ 
     907      ftp_chdir($ftpconnection, PLOGGER_FTP_PATH.$ftpDir); // go to destination dir 
     908      $ftpcreatedir = @ftp_mkdir($ftpconnection, $ftpnewDir); // create directory 
     909      if ($ftpcreatedir == true){ 
     910         $ftpexecdir = @ftp_site($ftpconnection, 'chmod 0777 '.$ftpnewDir.'/'); 
     911      }else{ 
     912         return false; 
     913      } 
     914      if ($ftpexecdir == true){ 
     915         return true; 
     916      }else{ 
     917         return false; 
     918      } 
     919      ftp_close($ftpconnection); // close connection 
     920   } 
    881921} 
    882922 
  • trunk/lib/plogger/form_setup.php

    r433 r517  
    1313                <div id="navcontainer"> 
    1414                        <h1>Database Setup</h1> 
     15                </div> 
    1516                </td> 
    1617        </tr> 
     
    4849                <td class="form_input"><input type="text" name="admin_email" id="email" value="<?=$form['admin_email']?>" /></td> 
    4950        </tr> 
     51   <?php 
     52   //if server is safe_mode enabled, prompt user for FTP info for FTP workaround 
     53   if (ini_get('safe_mode')==1){?> 
     54   <tr> 
     55        <td colspan="2"> 
     56                <div id="navcontainer"> 
     57                        <h1>Safe_mode FTP workaround</h1> 
     58         <br/>Safe mode has been detected on your server.  FTP access is needed to allow Plogger to work correctly with safe_mode=on. 
     59      </div> 
     60                </td> 
     61        </tr> 
    5062        <tr> 
     63                <td class="form_label"><label for="ftp_host">FTP Host:</label></td> 
     64                <td class="form_input"><input type="text" name="ftp_host" id="ftp_host" value="<?=$form['ftp_host']?>" /></td> 
     65        </tr> 
     66        <tr> 
     67                <td class="form_label"><label for="ftp_user">FTP Username:</label></td> 
     68                <td class="form_input"><input type="text" name="ftp_user" id="ftp_user" value="<?=$form['ftp_user']?>" /></td> 
     69        </tr> 
     70        <tr> 
     71                <td class="form_label"><label for="ftp_password">FTP Password:</label></td> 
     72                <td class="form_input"><input type="password" name="ftp_pass" id="ftp_pass" value="<?=$form['ftp_pass']?>" /></td> 
     73        </tr> 
     74        <tr> 
     75                <td class="form_label"><label for="ftp_name">FTP Path to Plogger Folder (from FTP login):</label></td> 
     76                <td class="form_input"><input type="text" name="ftp_path" id="ftp_path" value="<?=$form['ftp_path']?>" /></td> 
     77        </tr> 
     78   <?php } //end safe_mode workaround ?> 
     79   <tr> 
    5180                <td class="submitButtonRow" colspan="2"> 
    5281                        <input type="submit" name="submit" id="submit" value="Install" /> 
  • trunk/lib/plogger/install_functions.php

    r509 r517  
    5454                if (empty($form['admin_email'])) { 
    5555                        $errors[] = 'Please enter your e-mail address.'; 
     56                }; 
     57       
     58      if (ini_get('safe_mode')==1) { 
     59      //if safe_mode enabled, check the FTP information form inputs 
     60                        if (empty($form['ftp_host'])) { 
     61                           $errors[] = 'Please enter the name of your FTP host.'; 
     62                   }; 
     63 
     64                   if (empty($form['ftp_user'])) { 
     65                           $errors[] = 'Please enter the FTP username.'; 
     66                   }; 
     67 
     68                   if (empty($form['ftp_pass'])) { 
     69            $errors[] = 'Please enter the FTP password.'; 
     70         } 
     71          
     72         if (!empty($form['ftp_path'])) { 
     73            if (substr($form['ftp_path'],0,1)!="/"){ 
     74               $form['ftp_path']="/".$form['ftp_path']; 
     75            }; 
     76            if (substr($form['ftp_path'],-1)!="/"){ 
     77               $form['ftp_path']=$form['ftp_path']."/"; 
     78            }; 
     79         } 
    5680                }; 
    5781 
     
    7498                        ); 
    7599                                 
    76                         $conf = create_config_file($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name']); 
     100                        $conf = create_config_file($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name'],$form['ftp_host'],$form['ftp_user'],$form['ftp_pass'],$form['ftp_path']); 
    77101                        // if configuration file is writable, then set the values 
    78102                        // otherwise serve the config file to user and ask her to 
     
    92116                $form['db_host'] = 'localhost'; 
    93117        }; 
    94  
    95         $init_vars = array('db_user','db_pass','db_name','gallery_name','admin_email'); 
     118   if (empty($form['ftp_host'])) { 
     119                $form['ftp_host'] = 'localhost'; 
     120        }; 
     121 
     122        $init_vars = array('db_user','db_pass','db_name','gallery_name','admin_email','ftp_user','ftp_pass','ftp_path'); 
    96123        foreach($init_vars as $var) { 
    97124                if (empty($form[$var])) { 
     
    299326} 
    300327 
    301 function create_config_file($db_host,$db_user,$db_pass,$db_name) { 
     328function create_config_file($db_host,$db_user,$db_pass,$db_name,$ftp_host,$ftp_user,$ftp_pass,$ftp_path) { 
    302329        $cfg_file = "<?php\n"; 
    303330        $cfg_file .= '// this is the file used to connect to your database.'."\n"; 
     
    310337        $cfg_file .= '// define("PLOGGER_EMBEDDED","");        // 1/0 (True/False) if set will overrule automatic check'."\n"; 
    311338        $cfg_file .= '// define("PLOGGER_LOCALE","");         // da_DK de et fr pl ro_RO tr ...etc.'."\n"; 
     339    if (ini_get('safe_mode')==1) { 
     340    //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information 
     341       $cfg_file .= "\n"; 
     342       $cfg_file .= '// these values are used to connect via FTP.'."\n"; 
     343       $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n"; 
     344           $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n"; 
     345           $cfg_file .= 'define("PLOGGER_FTP_PW","'.$ftp_pass.'");'."\n"; 
     346           $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n"; 
     347   }; 
    312348 
    313349        $cfg_file .= "?>\n";