[Easymod-cvs] easymod2/mods/easymod/em_includes em_ftp.php,1.9,1.10
Status: Beta
Brought to you by:
wgeric
From: Markus P. <mar...@us...> - 2005-11-05 12:53:03
|
Update of /cvsroot/easymod/easymod2/mods/easymod/em_includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6111/mods/easymod/em_includes Modified Files: em_ftp.php Log Message: Chmod to 777 instead of 755 inside ftp_mkdir method. Changed the FTP method function so it can be invoked from the EM settings panel. =:-O Fixed semi-colons in language file. Index: em_ftp.php =================================================================== RCS file: /cvsroot/easymod/easymod2/mods/easymod/em_includes/em_ftp.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** em_ftp.php 4 Nov 2005 05:14:10 -0000 1.9 --- em_ftp.php 5 Nov 2005 12:52:51 -0000 1.10 *************** *** 30,61 **** ! // used in step 2 of the installer to test the connection and also used in the debug feature; could be ! // used in the main proggie to check settings some day; it will need to be de-HTML'ed though ;-) ! function test_ftp( $ftp_user, $ftp_pass, $ftp_dir, $ftp_host, $ftp_port, $ftp_debug, $ftp_type, $ftp_cache) { ! global $lang, $phpbb_root_path, $easymod_install_version ; ! echo '<h3>' . $lang['EM_ftp_testing'] . "</h3>\n" ; // create the emftp which will use either fsockopen or the PHP FTP extension ! $emftp = new emftp( $ftp_type, $ftp_debug) ; // connect to the FTP server ! if (!$emftp->ftp_connect( $ftp_host, $ftp_port)) { // failed to connect! ! echo "<br />\n" ; ! echo '<b>' . sprintf($lang['EM_ftp_fail_conn'], $ftp_host, $ftp_port) . "</b><br />\n" ; // they may need to specify the host ! if ($ftp_host == 'localhost') { ! echo $lang['EM_ftp_fail_conn_lh'] . "<br />\n" ; } // they may need to specify the port ! else if ($ftp_port == 21) { ! echo $lang['EM_ftp_fail_conn_21'] . "<br />\n"; } --- 30,63 ---- ! // used in step 2 of the installer to test the connection and also used in the debug feature; also ! // used in the main proggie to check settings ! function test_ftp($ftp_user, $ftp_pass, $ftp_dir, $ftp_host, $ftp_port, $ftp_debug, $ftp_type, $ftp_cache, &$test_report) { ! global $lang, $phpbb_root_path, $easymod_install_version; ! $test_report = array(); ! ! $test_report[] = '<h3>' . $lang['EM_ftp_testing'] . '</h3>'; // create the emftp which will use either fsockopen or the PHP FTP extension ! $emftp = new emftp($ftp_type, $ftp_debug); // connect to the FTP server ! if( !$emftp->ftp_connect( $ftp_host, $ftp_port) ) { // failed to connect! ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . sprintf($lang['EM_ftp_fail_conn'], $ftp_host, $ftp_port) . '</b><br />'; // they may need to specify the host ! if( $ftp_host == 'localhost' ) { ! $test_report[] = $lang['EM_ftp_fail_conn_lh'] . '<br />'; } // they may need to specify the port ! elseif( $ftp_port == 21 ) { ! $test_report[] = $lang['EM_ftp_fail_conn_21'] . '<br />'; } *************** *** 64,129 **** { // if they have / : or \ in the hostname then they are probably stupid and supplying invalid name ! if ((strstr($ftp_host, '/')) || (strstr($ftp_host, '\\')) || (strstr($ftp_host, ':'))) { ! echo $lang['EM_ftp_fail_conn_invalid'] . "<br />\n" ; ! echo "<br />\n" ; } // if they have anything other than an integer in the port then... ! else if (intval($ftp_port) == $ftp_port) { ! echo $lang['EM_ftp_fail_conn_invalid2'] . "<br />\n"; ! echo "<br />\n"; } // give them options ! echo $lang['EM_fail_conn_info'] . "<br /><ol>\n" ; ! echo '<li>' . $lang['EM_fail_conn_op1'] . "</li>\n" ; ! echo '<li>' . $lang['EM_fail_conn_op2'] . "</li>\n" ; ! echo '<li>' . $lang['EM_fail_conn_op3'] . "</li>\n" ; ! echo '<li>' . $lang['EM_fail_conn_op4'] . "</li>\n" ; ! echo "</ol>\n" ; } ! return false ; } - // connected to the FTP server, now send the user/pass ! if (!$emftp->ftp_login($ftp_user, $ftp_pass)) { // failed to login! Tell them they are stupid! Disconnect from server ! $emftp->ftp_quit() ; ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_fail_login'] . "</b><br />" ; // give them options ! echo $lang['EM_fail_login_info'] . "<br /><ol>\n" ; // check user/pass ! echo '<li>' . $lang['EM_fail_login_op1'] . "\n" ; ! if ( $ftp_host == 'localhost' || $ftp_port == 21) { // change from localhost ! echo '<li>' . $lang['EM_fail_login_op2a'] . "\n" ; } else { // change to localhost or something else ! echo '<li>' . $lang['EM_fail_login_op2b'] . "\n" ; } ! echo "</ol>\n" ; ! return false ; } - echo $lang['EM_test_ftp1']. "<br />\n" ; // if we are in debug mode, then get a dir listing before we start moving around ! if ($ftp_debug) { ! echo '<b>PWD:</b> ' . $emftp->ftp_pwd() . "<br />\n"; ////// --- 66,130 ---- { // if they have / : or \ in the hostname then they are probably stupid and supplying invalid name ! if( (strstr($ftp_host, '/')) || (strstr($ftp_host, '\\')) || (strstr($ftp_host, ':')) ) { ! $test_report[] = $lang['EM_ftp_fail_conn_invalid'] . '<br />'; ! $test_report[] = '<br />'; } // if they have anything other than an integer in the port then... ! elseif( intval($ftp_port) == $ftp_port ) { ! $test_report[] = $lang['EM_ftp_fail_conn_invalid2'] . '<br />'; ! $test_report[] = '<br />'; } // give them options ! $test_report[] = $lang['EM_fail_conn_info'] . '<br /><ol>'; ! $test_report[] = '<li>' . $lang['EM_fail_conn_op1'] . '</li>'; ! $test_report[] = '<li>' . $lang['EM_fail_conn_op2'] . '</li>'; ! $test_report[] = '<li>' . $lang['EM_fail_conn_op3'] . '</li>'; ! $test_report[] = '<li>' . $lang['EM_fail_conn_op4'] . '</li>'; ! $test_report[] = '</ol>'; } ! return false; } // connected to the FTP server, now send the user/pass ! if( !$emftp->ftp_login($ftp_user, $ftp_pass) ) { // failed to login! Tell them they are stupid! Disconnect from server ! $emftp->ftp_quit(); ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . $lang['EM_fail_login'] . '</b><br />'; // give them options ! $test_report[] = $lang['EM_fail_login_info'] . '<br /><ol>'; // check user/pass ! $test_report[] = '<li>' . $lang['EM_fail_login_op1'] . '</li>'; ! if( $ftp_host == 'localhost' || $ftp_port == 21 ) { // change from localhost ! $test_report[] = '<li>' . $lang['EM_fail_login_op2a'] . '</li>'; } else { // change to localhost or something else ! $test_report[] = '<li>' . $lang['EM_fail_login_op2b'] . '</li>'; } ! $test_report[] = '</ol>'; ! return false; } + $test_report[] = $lang['EM_test_ftp1']. '<br />'; // if we are in debug mode, then get a dir listing before we start moving around ! if( $ftp_debug ) { ! $test_report[] = '<b>PWD:</b> ' . $emftp->ftp_pwd() . '<br />'; ////// *************** *** 132,225 **** $list = $emftp->ftp_nlist(); ! echo '<b>Dir listing:</b> (' . count($list) . " files being listed)<br />\n"; ! for ($i=0; $i<count($list); $i++) { ! echo '[' . $list[$i] . "]<br />\n" ; } } // change directory to the EM dir ! if (!$pwd = $emftp->ftp_chdir( $ftp_dir . '/admin/mods/easymod')) { ! echo "<br />\n" ; ! echo '<b>' . sprintf($lang['EM_fail_cd'], $ftp_dir) . "</b><br />\n" ; ! echo $lang['EM_fail_cd_info'] . "<br /><ol><br />\n" ; // some dopes put the ftp server in the paths ! if ((strstr($ftp_dir, '.com')) || (strstr($ftp_dir, '.net')) || (strstr($ftp_dir, '.org'))) { ! echo '<li>' . $lang['EM_fail_cd_op1'] . "</li>\n" ; } // make sure there is no / at the end of the path ! if (substr($ftp_dir, strlen($ftp_dir)-1) == '/') { ! echo '<li>' . $lang['EM_fail_cd_op2'] . "</li>\n" ; } // everything else ! echo '<li>' . $lang['EM_fail_cd_op3'] . "</li>\n" ; ! echo '<li>' . $lang['EM_fail_cd_op4'] . "</li>\n" ; ! if ($ftp_host == 'localhost' || $ftp_port == 21) { ! echo '<li>' . $lang['EM_fail_cd_op5'] . "</li>\n" ; } ! echo '<li>' . $lang['EM_fail_cd_op6'] . "</li>\n" ; ! echo "</ol>\n" ; ! // print the working dir ! $emftp->set_debug( false) ; ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_ftp_root'] . "</b><br />\n" ; // if pwd fails then we know it is probably a passive mode problem ! if (!$emftp->ftp_pwd()) { ! echo $lang['EM_fail_cd_pwd'] . "\n" ; } else { ! echo $emftp->ftp_pwd() . "\n" ; } - // print directory listing ! echo '<br /><br />' . $lang['EM_dir_list'] . "<br />\n" ; ! $list = $emftp->ftp_nlist() ; // if the nlist command failed, then print an error ! if (!$list) { ! echo $lang['EM_fail_cd_nlist'] . "<br />\n" ; } // if there are no files then indicate there are none to print ! else if (count($list) == 0) { ! echo '--' . $lang['EM_fail_cd_nlist_no'] . "--<br />\n" ; } else { ! for ($i=0; $i<count($list); $i++) { ! echo $list[$i] . "<br />\n" ; } } $emftp->ftp_quit(); ! return false ; } ! if (!$pwd = $emftp->ftp_pwd()) { $emftp->ftp_quit(); ! echo $lang['EM_fail_pwd'] . "\n" ; ! return false ; } ! ! echo $lang['EM_test_ftp2'] . "<br />\n" ; --- 133,223 ---- $list = $emftp->ftp_nlist(); ! $test_report[] = '<b>Dir listing:</b> (' . count($list) . ' files being listed)<br />'; ! for( $i = 0; $i < count($list); $i++ ) { ! $test_report[] = '[' . $list[$i] . ']<br />'; } } // change directory to the EM dir ! if( !($pwd = $emftp->ftp_chdir($ftp_dir . '/admin/mods/easymod')) ) { ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . sprintf($lang['EM_fail_cd'], $ftp_dir) . '</b><br />'; ! $test_report[] = $lang['EM_fail_cd_info'] . '<br /><ol><br />'; // some dopes put the ftp server in the paths ! if( (strstr($ftp_dir, '.com')) || (strstr($ftp_dir, '.net')) || (strstr($ftp_dir, '.org')) ) { ! $test_report[] = '<li>' . $lang['EM_fail_cd_op1'] . '</li>'; } // make sure there is no / at the end of the path ! if( substr($ftp_dir, strlen($ftp_dir)-1) == '/' ) { ! $test_report[] = '<li>' . $lang['EM_fail_cd_op2'] . '</li>'; } // everything else ! $test_report[] = '<li>' . $lang['EM_fail_cd_op3'] . '</li>'; ! $test_report[] = '<li>' . $lang['EM_fail_cd_op4'] . '</li>'; ! if( $ftp_host == 'localhost' || $ftp_port == 21 ) { ! $test_report[] = '<li>' . $lang['EM_fail_cd_op5'] . '</li>'; } ! $test_report[] = '<li>' . $lang['EM_fail_cd_op6'] . '</li>'; ! $test_report[] = '</ol>'; // print the working dir ! $emftp->set_debug(false); ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . $lang['EM_ftp_root'] . '</b><br />'; // if pwd fails then we know it is probably a passive mode problem ! if( !$emftp->ftp_pwd() ) { ! $test_report[] = $lang['EM_fail_cd_pwd'] . '<br />'; } else { ! $test_report[] = $emftp->ftp_pwd() . '<br />'; } // print directory listing ! $test_report[] = '<br /><br />' . $lang['EM_dir_list'] . '<br />'; ! $list = $emftp->ftp_nlist(); // if the nlist command failed, then print an error ! if( !$list ) { ! $test_report[] = $lang['EM_fail_cd_nlist'] . '<br />'; } // if there are no files then indicate there are none to print ! elseif( count($list) == 0 ) { ! $test_report[] = '--' . $lang['EM_fail_cd_nlist_no'] . '--<br />'; } else { ! for( $i = 0; $i < count($list); $i++ ) { ! $test_report[] = $list[$i] . '<br />'; } } $emftp->ftp_quit(); ! return false; } ! if( !($pwd = $emftp->ftp_pwd()) ) { $emftp->ftp_quit(); ! $test_report[] = $lang['EM_fail_pwd'] . '<br />'; ! return false; } ! $test_report[] = $lang['EM_test_ftp2'] . '<br />'; *************** *** 227,329 **** ///// this looks like it could be a problem with the ../../../ on ftp ///// ! $local_filename = 'easymod.gif' ; ! $remote_filename = '../../../easymod.gif' ; ! // write to phpBB root ! if (!$emftp->ftp_put( $remote_filename, $local_filename, 1)) { ! $emftp->ftp_quit(); ! ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_fail_put'] . "</b><br />" ; ! echo sprintf($lang['EM_fail_put_info'], $ftp_user) . "<br />\n" ; ! ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_ftp_phpbb_root'] . "</b><br />\n" ; ! if ($dh = opendir('../../../')) { ! while (($file = readdir($dh)) !== false) ! { ! echo mfunGetPerms(fileperms( '../../../' . $file)) . " $file <br />\n"; ! } ! closedir($dh); ! } ! ! return false ; ! } ! ! // confirm we can overwrite so just do the same thing again ! if (!$emftp->ftp_put( $remote_filename, $local_filename, 1)) ! { ! $emftp->ftp_quit(); ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_fail_reput'] . "</b><br />" ; ! echo sprintf($lang['EM_fail_put_info'], $ftp_user) . "<br />\n" ; ! echo "<br />\n" ; ! echo '<b>' . $lang['EM_ftp_phpbb_root'] . "</b><br />\n" ; ! if ($dh = opendir('../../../')) ! { ! while (($file = readdir($dh)) !== false) { ! echo mfunGetPerms(fileperms( '../../../' . $file)) . " $file <br />\n"; } - closedir($dh); - } ! return false ; } - // cleanup ! if (!$emftp->ftp_delete($remote_filename)) { ! echo $lang['EM_fail_delete'] . "<br />\n" ; } // if we are using the FTP ext and the cache, then make sure the cache is created, otherwise create it ! if (($ftp_type == 'ext') && ($ftp_cache)) { // return the admin directory ! $emftp->ftp_cdup() ; ! $emftp->ftp_cdup() ; // see if the cache dir exists, otherwise create it put_array ! if (!file_exists( $phpbb_root_path . 'admin/em_includes/cache')) { ! $emftp->ftp_mkdir( 'em_includes') ; ! $emftp->ftp_chdir( 'em_includes') ; ! $emftp->ftp_mkdir( 'cache') ; ! if (!file_exists( $phpbb_root_path . 'admin/em_includes/cache')) { $emftp->ftp_quit(); ! echo 'Could not make the [admin/em_includes/cache] directory.' . "\n" ; ! return false ; } } // create a tmp file and write something out ! $tmpfname = @tempnam( $phpbb_root_path . 'admin/em_includes/cache', 'txt'); @unlink($tmpfname); // unlink for safety on php4.0.3+ ! if ($fp = @fopen($tmpfname, 'w')) { @fwrite($fp, ">>$easymod_install_version<<\n"); @fclose($fp); } else { ! echo 'Could not create the [$tmpfname] temporary file.' . "\n" ; } - } - ! echo $lang['EM_test_ftp3']. "<br />\n" ; // disconnect $emftp->ftp_quit(); ! return true ; } --- 225,321 ---- ///// this looks like it could be a problem with the ../../../ on ftp ///// ! $local_filename = 'easymod.gif'; ! $remote_filename = '../../../easymod.gif'; ! // write to phpBB root and then, confirm we can overwrite so just do the same thing again ! $test_twice = array('EM_fail_put', 'EM_fail_reput'); ! foreach( $test_twice as $langkey ) { ! if( !$emftp->ftp_put($remote_filename, $local_filename, 1) ) { ! $emftp->ftp_quit(); ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . $lang[$langkey] . '</b><br />'; ! $test_report[] = sprintf($lang['EM_fail_put_info'], $ftp_user) . '<br />'; ! $test_report[] = '<br />'; ! $test_report[] = '<b>' . $lang['EM_ftp_phpbb_root'] . '</b><br />'; ! if( $dh = opendir('../../../') ) { ! while( ($file = readdir($dh)) !== false ) ! { ! $test_report[] = mfunGetPerms(fileperms('../../../' . $file)) . " $file <br />"; ! } ! closedir($dh); } ! return false; ! } } // cleanup ! if( !$emftp->ftp_delete($remote_filename) ) { ! $test_report[] = $lang['EM_fail_delete'] . '<br />'; } + $test_report[] = $lang['EM_test_ftp3']. '<br />'; + // if we are using the FTP ext and the cache, then make sure the cache is created, otherwise create it ! if( ($ftp_type == 'ext') && ($ftp_cache) ) { // return the admin directory ! $emftp->ftp_cdup(); ! $emftp->ftp_cdup(); // see if the cache dir exists, otherwise create it put_array ! if( !file_exists($phpbb_root_path . 'admin/em_includes/cache') ) { ! $emftp->ftp_mkdir('em_includes'); ! $emftp->ftp_chdir('em_includes'); ! $emftp->ftp_mkdir('cache'); ! if( !file_exists($phpbb_root_path . 'admin/em_includes/cache') ) { $emftp->ftp_quit(); ! $test_report[] = 'Could not make the [admin/em_includes/cache] directory.' . '<br />'; ! return false; } } + // if it was there before (created from a previous EM install)... + // due to chmod 755 in previous versions, it might not be writable, try to fix this then + elseif( !is_writeable($phpbb_root_path . 'admin/em_includes/cache') ) + { + $emftp->ftp_chdir('em_includes'); + $emftp->emftp_chmod('em_includes', '0777'); + $emftp->ftp_chdir('cache'); + $emftp->emftp_chmod('cache', '0777'); + } + // create a tmp file and write something out ! $tmpfname = @tempnam($phpbb_root_path . 'admin/em_includes/cache', 'txt'); @unlink($tmpfname); // unlink for safety on php4.0.3+ ! if( $fp = @fopen($tmpfname, 'w') ) { @fwrite($fp, ">>$easymod_install_version<<\n"); @fclose($fp); + @unlink($tmpfname); // Delete the temporary file } else { ! $emftp->ftp_quit(); ! $test_report[] = "Could not create the [$tmpfname] temporary file.<br />"; ! return false; } ! $test_report[] = $lang['EM_test_ftp4']. '<br />'; ! } // disconnect $emftp->ftp_quit(); ! return true; } *************** *** 1144,1152 **** { // make sure the cache directory exists ! if (!file_exists( $phpbb_root_path . 'admin/em_includes/cache')) { ! return false ; } ! $tmpfname = @tempnam( $phpbb_root_path . 'admin/em_includes/cache', 'txt'); } // create in the tmp dir --- 1136,1144 ---- { // make sure the cache directory exists ! if (!file_exists($phpbb_root_path . 'admin/em_includes/cache')) { ! return false; } ! $tmpfname = @tempnam($phpbb_root_path . 'admin/em_includes/cache', 'txt'); } // create in the tmp dir *************** *** 1196,1200 **** if ( $result ) { ! $this->emftp_chmod($dir_name, '0755'); } return $result; --- 1188,1192 ---- if ( $result ) { ! $this->emftp_chmod($dir_name, '0777'); } return $result; *************** *** 1203,1207 **** { $result = @ftp_mkdir( $this->ftp_conn_id, $dir_name) ; ! $this->emftp_chmod($dir_name, '0755'); // return $result ; ///////////// --- 1195,1199 ---- { $result = @ftp_mkdir( $this->ftp_conn_id, $dir_name) ; ! $this->emftp_chmod($dir_name, '0777'); // return $result ; ///////////// |