示例#1
0
 static function GetFTPRoot($conn_id, $testDir)
 {
     $ftp_root = false;
     //attempt to find the ftp_root
     $testDir = $testDir . '/';
     $array = ftp_nlist($conn_id, '.');
     if (!$array) {
         return false;
     }
     $possible = array();
     foreach ($array as $file) {
         if ($file[0] == '.') {
             continue;
         }
         //is the $file within the $testDir.. not the best test..
         $pos = strpos($testDir, '/' . $file . '/');
         if ($pos === false) {
             continue;
         }
         $possible[] = substr($testDir, $pos);
     }
     $possible[] = '/';
     //test this too
     foreach ($possible as $file) {
         if (gpftp::TestFTPDir($conn_id, $file, $testDir)) {
             $ftp_root = $file;
             break;
         }
     }
     return $ftp_root;
 }
示例#2
0
 function Form_FTPDetails()
 {
     global $langmessage;
     $_POST += array('ftp_server' => gpftp::GetFTPServer(), 'ftp_user' => '');
     echo '<form action="' . common::GetUrl('') . '" method="post">';
     echo '<table class="padded_table">';
     echo '<tr><td align="left">' . $langmessage['FTP_Server'] . ' </td><td>';
     echo '<input type="text" class="text" size="20" name="ftp_server" value="' . htmlspecialchars($_POST['ftp_server']) . '" required />';
     echo '</td></tr>';
     echo '<tr><td align="left">' . $langmessage['FTP_Username'] . ' </td><td>';
     echo '<input type="text" class="text" size="20" name="ftp_user" value="' . htmlspecialchars($_POST['ftp_user']) . '" />';
     echo '</td></tr>';
     echo '<tr><td align="left">' . $langmessage['FTP_Password'] . ' </td><td>';
     echo '<input type="password" class="text" size="20" name="ftp_pass" value="" />';
     echo '</td></tr>';
     echo '<tr><td align="left">&nbsp;</td><td>';
     echo '<input type="hidden" name="cmd" value="Continue" />';
     echo '<input type="submit" class="submit" name="aaa" value="' . $langmessage['continue'] . '" />';
     echo '</td></tr>';
     echo '</table>';
     echo '</form>';
 }
示例#3
0
 function MakeDir($parent, $new_name)
 {
     global $config, $langmessage;
     $langmessage['not_created'] = 'Oops, the folder could not be created. ';
     $langmessage['not_created'] .= 'You may still be able to create it by doing one of the following: ';
     $langmessage['not_created'] .= '<ul>';
     $langmessage['not_created'] .= '<li>Make the parent folder writable by changing it\'s permissions.</li>';
     $langmessage['not_created'] .= '<li>Supply your server\'s <a href="%s">ftp information</a> to this plugin.</li>';
     $langmessage['not_created'] .= '</ul>';
     $langmessage['not_created'] = sprintf($langmessage['not_created'], common::GetUrl('Admin_Site_Setup', 'cmd=settings'));
     $new_folder = $parent . '/' . $new_name;
     if (mkdir($new_folder, 0755)) {
         chmod($new_folder, 0755);
         //some systems need more than just the 0755 in the mkdir() function
         return true;
     }
     if (empty($config['ftp_server'])) {
         message($langmessage['not_created']);
         return false;
     }
     $conn_id = gpFiles::FTPConnect();
     if (!$conn_id) {
         message($langmessage['not_created'] . ' (FTP Connection Failed)');
         return false;
     }
     $ftp_parent = gpftp::GetFTPRoot($conn_id, $parent);
     if (!$ftp_parent) {
         message('Oops, could not find the ftp location of <i>' . $parent . '</i> using the current ftp login.');
         return false;
     }
     $ftp_destination = $ftp_parent . '/' . $new_name;
     if (!ftp_mkdir($conn_id, $ftp_destination)) {
         message('Oops, could not create the folder using the current ftp login.');
         return false;
     }
     ftp_site($conn_id, 'CHMOD 0755 ' . $ftp_destination);
     return true;
 }
示例#4
0
 function connectForm($args = false)
 {
     if (!is_array($args)) {
         $args = $_POST;
     }
     $args += $this->connect_vars;
     if (empty($args['ftp_server'])) {
         $args['ftp_server'] = gpftp::GetFTPServer();
     }
     echo '<input type="hidden" name="filesystem_method" value="' . htmlspecialchars($this->method) . '" />';
     echo '<input type="hidden" name="connect_values_submitted" value="true" />';
     echo '<tr><td>';
     echo 'FTP Hostname';
     echo '</td><td>';
     echo '<input type="text" name="ftp_server" value="' . htmlspecialchars($args['ftp_server']) . '" class="gpinput"/>';
     echo '</td></tr>';
     echo '<tr><td>';
     echo 'FTP Username';
     echo '</td><td>';
     echo '<input type="text" name="ftp_user" value="' . htmlspecialchars($args['ftp_user']) . '" class="gpinput"/>';
     echo '</td></tr>';
     echo '<tr><td>';
     echo 'FTP Password';
     echo '</td><td>';
     echo '<input type="password" name="ftp_pass" value="" class="gpinput"/>';
     echo '</td></tr>';
     echo '<tr><td>';
     echo 'FTP Port';
     echo '</td><td>';
     echo '<input type="text" name="port" value="' . htmlspecialchars($args['port']) . '" class="gpinput"/>';
     echo '</td></tr>';
 }
示例#5
0
function Install_FTPConnection(&$ftp_root)
{
    global $dataDir, $langmessage, $install_ftp_connection;
    //test for functions
    echo '<li>';
    if (!function_exists('ftp_connect')) {
        echo '<span class="failed">';
        echo $langmessage['FTP_UNAVAILABLE'];
        echo '</span>';
        echo '</li></ul>';
        return false;
    } else {
        echo '<span class="passed">';
        echo $langmessage['FTP_AVAILABLE'];
        echo '</span>';
    }
    echo '</li>';
    //Try to connect
    echo '<li>';
    $install_ftp_connection = @ftp_connect($_POST['ftp_server'], 21, 6);
    if (!$install_ftp_connection) {
        echo '<span class="failed">';
        echo sprintf($langmessage['FAILED_TO_CONNECT'], '<em>' . htmlspecialchars($_POST['ftp_server']) . '</em>');
        echo '</span>';
        echo '</li></ul>';
        return false;
    } else {
        echo '<span class="passed">';
        echo sprintf($langmessage['CONNECTED_TO'], '<em>' . htmlspecialchars($_POST['ftp_server']) . '</em>');
        //echo 'Connected to <em>'.$_POST['ftp_server'].'</em>';
        echo '</span>';
    }
    echo '</li>';
    //Log in
    echo '<li>';
    $login_result = @ftp_login($install_ftp_connection, $_POST['ftp_user'], $_POST['ftp_pass']);
    if (!$login_result) {
        echo '<span class="failed">';
        echo sprintf($langmessage['NOT_LOOGED_IN'], '<em>' . htmlspecialchars($_POST['ftp_user']) . '</em>');
        //echo 'Could not log in user  <em>'.$_POST['ftp_user'].'</em>';
        echo '</span>';
        echo '</li></ul>';
        return false;
    } else {
        echo '<span class="passed">';
        echo sprintf($langmessage['LOGGED_IN'], '<em>' . htmlspecialchars($_POST['ftp_user']) . '</em>');
        //echo 'User <em>'.$_POST['ftp_user'].'</em> logged in.';
        echo '</span>';
    }
    echo '</li>';
    //Get FTP Root
    echo '<li>';
    $ftp_root = false;
    if ($login_result) {
        $ftp_root = gpftp::GetFTPRoot($install_ftp_connection, $dataDir);
    }
    if (!$ftp_root) {
        //if( !$login_result ){
        echo '<span class="failed">';
        echo $langmessage['ROOT_DIRECTORY_NOT_FOUND'];
        echo '</span>';
        echo '</li></ul>';
        return false;
    } else {
        echo '<span class="passed">';
        echo sprintf($langmessage['FTP_ROOT'], '<em>' . $ftp_root . '</em>');
        //echo 'FTP Root found: <em>'.$ftp_root.'</em>';
        echo '</span>';
    }
    echo '</li>';
    return true;
}