Esempio n. 1
0
function myProcess($values)
{
    global $form;
    $destination = './uploads/';
    // Account FTP on remote server, directory destination, and allows Y/N file overwriting
    $ftp = array('user' => $values['ftpaccount']['U'], 'pass' => $values['ftpaccount']['P'], 'host' => $values['ftpaccount']['H'], 'dest' => $values['ftpdir'], 'overwrite' => (bool) $values['overwrite']);
    $result = 'done';
    $file =& $form->getElement('tstUpload');
    if ($file->isUploadedFile()) {
        $_ftp = new Net_FTP($ftp['host']);
        $ret = $_ftp->connect();
        if (PEAR::isError($ret)) {
            $result = $ret->getMessage();
            // NET_FTP_ERR_CONNECT_FAILED
        } else {
            $ret = $_ftp->login($ftp['user'], $ftp['pass']);
            if (PEAR::isError($ret)) {
                $result = $ret->getMessage();
                // NET_FTP_ERR_LOGIN_FAILED
            } else {
                $_ftp->setPassive();
                $ret = $_ftp->cd($ftp['dest']);
                if (PEAR::isError($ret)) {
                    $result = $ret->getMessage();
                    // NET_FTP_ERR_DIRCHANGE_FAILED
                } else {
                    $fval = $file->getValue();
                    $ret = $_ftp->put($fval['tmp_name'], $fval['name'], $ftp['overwrite']);
                    if (PEAR::isError($ret)) {
                        $result = $ret->getMessage();
                        // NET_FTP_ERR_UPLOADFILE_FAILED
                    }
                }
            }
            $ret = $_ftp->disconnect();
            if (PEAR::isError($ret)) {
                $result = $ret->getMessage();
                // NET_FTP_ERR_DISCONNECT_FAILED
            }
        }
    }
    // write the semaphore to tell progress meter to stop
    // in script 'progressbar.php'
    $semaphore = $destination . $_GET['ID'];
    $fp = fopen($semaphore, 'w', false);
    fwrite($fp, $result);
    fclose($fp);
}
Esempio n. 2
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     if ($this->ssl) {
         $ret = $ftp->setSsl();
         if (@PEAR::isError($ret)) {
             throw new BuildException('SSL connection not supported by php' . ': ' . $ret->getMessage());
         } else {
             $this->log('Use SSL connection', $this->logLevel);
         }
     }
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         // Array for holding directory content informations
         $remoteFileInformations = array();
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             // Read directory informations, if file exists, else create the directory
             if (!$this->_directoryInformations($ftp, $remoteFileInformations, $dirname)) {
                 $this->log('Will create directory ' . $dirname, $this->logLevel);
                 $ret = $ftp->mkdir($dirname, true);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
                 }
             }
             if ($this->dirmode) {
                 if ($this->dirmode == 'inherit') {
                     $mode = fileperms($dirname);
                 } else {
                     $mode = $this->dirmode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $dirname);
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $local_filemtime = filemtime($file->getCanonicalPath());
             if (isset($remoteFileInformations[$filename]['stamp'])) {
                 $remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'];
             } else {
                 $remoteFileModificationTime = 0;
             }
             if (!$this->depends || $local_filemtime > $remoteFileModificationTime) {
                 if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) {
                     $this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel);
                     continue;
                 }
                 $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
                 $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
                 }
             }
             if ($this->filemode) {
                 if ($this->filemode == 'inherit') {
                     $mode = fileperms($filename);
                 } else {
                     $mode = $this->filemode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $filename);
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
Esempio n. 3
0
/**
 * @author soeren
 * @copyright soeren (C) 2006
 * 
 * This file handles ftp authentication
 */
function ftp_authentication($ftp_login = '', $ftp_pass = '')
{
    global $dir, $mosConfig_live_site;
    if ($ftp_login != '' || $ftp_pass != '') {
        while (@ob_end_clean()) {
        }
        @header("Status: 200 OK");
        $ftp_host = mosGetParam($_POST, 'ftp_host', 'localhost:21');
        $url = @parse_url('ftp://' . $ftp_host);
        if (empty($url)) {
            echo jx_alertBox('Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21');
            echo jx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
            echo 'Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21';
            exit;
        }
        $port = empty($url['port']) ? 21 : $url['port'];
        $ftp = new Net_FTP($url['host'], $port, 20);
        $res = $ftp->connect();
        if (PEAR::isError($res)) {
            echo jx_alertBox($GLOBALS['messages']['ftp_connection_failed']);
            echo jx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
            echo $GLOBALS['messages']['ftp_connection_failed'] . '<br />[' . $res->getMessage() . ']';
            exit;
        } else {
            $res = $ftp->login($ftp_login, $ftp_pass);
            $ftp->disconnect();
            if (PEAR::isError($res)) {
                echo jx_alertBox($GLOBALS['messages']['ftp_login_failed']);
                echo jx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
                echo $GLOBALS['messages']['ftp_login_failed'] . '<br />[' . $res->getMessage() . ']';
                exit;
            }
            echo jx_alertBox('Login OK!');
            $_SESSION['ftp_login'] = $ftp_login;
            $_SESSION['ftp_pass'] = $ftp_pass;
            $_SESSION['ftp_host'] = $_POST['ftp_host'];
            session_write_close();
            echo jx_docLocation(str_replace('index3.php', 'index2.php', make_link('list', '') . '&file_mode=ftp'));
            exit;
        }
    } else {
        ?>
		<script type="text/javascript" src="components/com_joomlaxplorer/scripts/mootools.ajax.js"></script>
		<script type="text/javascript" src="components/com_joomlaxplorer/scripts/functions.js"></script>
		<script type="text/javascript">
		function checkFTPAuth( url ) {
			showLoadingIndicator( $('loadingindicator'), true );
			$('loadingindicator').innerHTML += ' <strong><?php 
        echo $GLOBALS['messages']['ftp_login_check'];
        ?>
</strong>';
			
			var controller = new ajax( url, { 	postBody: $('adminform'),
												evalScripts: true,
												update: 'statustext' 
												} 
									);
			controller.request();
			return false;
		}
		</script>
		
		<?php 
        show_header($GLOBALS["messages"]["ftp_header"]);
        ?>
<br/>
	
	<form name="ftp_auth_form" method="post" action="<?php 
        echo $mosConfig_live_site;
        ?>
/administrator/index3.php" onsubmit="return checkFTPAuth('<?php 
        echo $mosConfig_live_site;
        ?>
/administrator/index3.php');" id="adminform">
	
	<input type="hidden" name="no_html" value="1" />
	<table class="adminform" style="width:400px;">
		<tr><th colspan="3"><?php 
        echo $GLOBALS["messages"]["ftp_login_lbl"];
        ?>
</th></tr>
		
		<tr><td colspan="3" style="text-align:center;" id="loadingindicator"></td></tr>
		<tr><td colspan="3" style="font-weight:bold;text-align:center" id="statustext">&nbsp;</td></tr>
		
		<tr>
			<td width="50" style="text-align:center;" rowspan="3"><img align="absmiddle" src="images/security_f2.png" alt="Login!" /></td>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_login_name"];
        ?>
:</td>
			<td align="left">
				<input type="text" name="ftp_login_name" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_login_name"];
        ?>
" />
			</td>
		</tr>		
		<tr>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_login_pass"];
        ?>
:</td>
			<td align="left">
				<input type="password" name="ftp_login_pass" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_login_pass"];
        ?>
" />
			</td>
		</tr>		
		<tr>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_hostname_port"];
        ?>
:</td>
			<td align="left">
				<input type="text" name="ftp_host" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_hostname"];
        ?>
" value="<?php 
        echo mosGetParam($_SESSION, 'ftp_host', 'localhost:21');
        ?>
" />
			</td>
		</tr>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr>
			<td style="text-align:center;" colspan="3">
			<input type="hidden" name="action" value="ftp_authentication" />
			<input type="hidden" name="option" value="com_joomlaxplorer" />
			<input type="submit" name="submit" value="<?php 
        echo $GLOBALS['messages']['btnlogin'];
        ?>
" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" name="cancel" value="<?php 
        echo $GLOBALS['messages']['btncancel'];
        ?>
" onclick="javascript:document.location='<?php 
        echo make_link('list', $dir);
        ?>
';" />
			</td>
		</tr>
		<tr><td colspan="3">&nbsp;</td></tr>
	</table>
	</form>
	<?php 
    }
}
Esempio n. 4
0
head("\$ftp->get({$singleTestFile}, {$baseDir}{$singleTestFile}, true)");
Var_Dump::display($ftp->get($singleTestFile, $baseDir . $singleTestFile, true));
head("\$ftp->chmod({$singleTestFile}, 700)");
Var_Dump::display($ftp->chmod($singleTestFile, 700));
head("\$ftp->ls(null, NET_FTP_FILES_ONLY)");
Var_Dump::display($ftp->ls(null, NET_FTP_FILES_ONLY));
head("\$ftp->cd('../')");
Var_Dump::display($ftp->cd('../'));
head("\$ftp->chmodRecursive({$baseDir}, 777)");
Var_Dump::display($ftp->chmodRecursive($baseDir, 777));
head("\$ftp->ls(null, NET_FTP_DIRS_ONLY)");
Var_Dump::display($ftp->ls(null, NET_FTP_DIRS_ONLY));
head("\$ftp->putRecursive({$baseDir}{$testUpDir}, {$baseDir}{$testUpDir})");
Var_Dump::display($ftp->putRecursive($baseDir . $testUpDir, $baseDir . $testUpDir));
head("\$ftp->putRecursive({$baseDir}{$testUpDir}, {$baseDir}{$testUpDir})");
Var_Dump::display($ftp->putRecursive($baseDir . $testUpDir, $baseDir . $testUpDir, true));
head("\$ftp->cd({$baseDir}:{$testUpDir})");
Var_Dump::display($ftp->cd($baseDir . $testUpDir));
head("\$ftp->ls(null, NET_FTP_DIRS_FILES)");
Var_Dump::display($ftp->ls(null, NET_FTP_DIRS_FILES));
head("\$ftp->cd(../../)");
Var_Dump::display($ftp->cd('../../'));
head("\$ftp->getRecursive({$baseDir}{$testUpDir}, {$baseDir}{$testDownDir})");
Var_Dump::display($ftp->getRecursive($baseDir . $testUpDir, $baseDir . $testDownDir, true));
head("\$ftp->rm({$baseDir}, true)");
Var_Dump::display($ftp->rm($baseDir, true));
head("\$ftp->ls(null, NET_FTP_DIRS_ONLY)");
Var_Dump::display($ftp->ls(null, NET_FTP_DIRS_ONLY));
head("\$ftp->disconnect()");
Var_Dump::display($ftp->disconnect());
Esempio n. 5
0
    function execAction()
    {
        $ftp_login = extGetParam($_POST, 'ftp_login_name', '');
        $ftp_pass = extGetParam($_POST, 'ftp_login_pass', '');
        global $dir, $mosConfig_live_site;
        if ($ftp_login != '' || $ftp_pass != '') {
            $ftp_host = extGetParam($_POST, 'ftp_hostname_port', 'localhost:21');
            $url = @parse_url('ftp://' . $ftp_host);
            if (empty($url)) {
                ext_Result::sendResult('ftp_authentication', false, 'Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21');
            }
            $port = empty($url['port']) ? 21 : $url['port'];
            $ftp = new Net_FTP($url['host'], $port, 20);
            $res = $ftp->connect();
            if (PEAR::isError($res)) {
                ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_connection_failed'] . ' (' . $url['host'] . ')');
            } else {
                $res = $ftp->login($ftp_login, $ftp_pass);
                $ftp->disconnect();
                if (PEAR::isError($res)) {
                    ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_login_failed']);
                }
                $_SESSION['ftp_login'] = $ftp_login;
                $_SESSION['ftp_pass'] = $ftp_pass;
                $_SESSION['ftp_host'] = $ftp_host;
                $_SESSION['file_mode'] = 'ftp';
                session_write_close();
                ext_Result::sendResult('ftp_authentication', true, ext_Lang::msg('actlogin_success'));
            }
        } else {
            ?>
	<div style="width:auto;">
	    <div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
	    <div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
	
	        <h3 style="margin-bottom:5px;"><?php 
            echo $GLOBALS["messages"]["ftp_header"];
            ?>
</h3>
	        <strong><?php 
            echo $GLOBALS["messages"]["ftp_login_lbl"];
            ?>
</strong><br />
	<br />
	        <div id="adminForm">
	
	        </div>
	    </div></div></div>
	    <div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
	</div>
			<script type="text/javascript">
	var simple = new Ext.form.Form({
	    labelWidth: 175, // label settings here cascade unless overridden
	    url:'<?php 
            echo make_link("rename", $dir, $item);
            ?>
'
	});
	simple.add(
	    new Ext.form.TextField({
	        fieldLabel: '<?php 
            echo ext_Lang::msg('ftp_login_name', true);
            ?>
',
	        name: 'ftp_login_name',
	        width:175,
	        allowBlank:false
	    }),
	    new Ext.form.TextField({
	        fieldLabel: '<?php 
            echo ext_Lang::msg('ftp_login_pass', true);
            ?>
',
	        name: 'ftp_login_pass',
	        inputType: 'password',
	        width:175,
	        allowBlank:false
	    }),
	    new Ext.form.TextField({
	        fieldLabel: '<?php 
            echo ext_Lang::msg('ftp_hostname_port', true);
            ?>
',
	        name: 'ftp_hostname_port',
	        value: '<?php 
            echo extGetParam($_SESSION, 'ftp_host', 'localhost:21');
            ?>
',
	        width:175,
	        allowBlank:false
	    })
	    );
	
	simple.addButton({text: '<?php 
            echo ext_Lang::msg('btnlogin', true);
            ?>
', type: 'submit' }, function() {
		statusBarMessage( '<?php 
            echo ext_Lang::msg('ftp_login_check', true);
            ?>
', true );
	    simple.submit({
	        //reset: true,
	        reset: false,
	        success: function(form, action) { location.reload() },
	        failure: function(form, action) {
	        	if( !action.result ) return;
	        	Ext.MessageBox.alert('<?php 
            echo ext_Lang::err('error', true);
            ?>
', action.result.error);
	        	statusBarMessage( action.result.error, false, false );
	        },
	        scope: simple,
	        // add some vars to the request, similar to hidden fields
	        params: {option: 'com_extplorer', 
	        		action: 'ftp_authentication'
	        }
	    });
	});
	simple.addButton('<?php 
            echo ext_Lang::msg('btncancel', true);
            ?>
', function() { dialog.destroy(); } );
	simple.render('adminForm');
			</script>
			
			<br/>
		<?php 
        }
    }
Esempio n. 6
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             $this->log('Will create directory ' . $dirname, $this->logLevel);
             $ret = $ftp->mkdir($dirname, true);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
             $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
Esempio n. 7
0
// unlimited time operation (removed 30s default restriction)
$f = new Net_FTP();
//
// 3. connect to the FTP server
//
$ret = $f->connect($ftp['host'], $ftp['port']);
if (PEAR::isError($ret)) {
    die($ret->getMessage());
}
printf('connected at <b>%s</b><br />', $ftp['host']);
//
// 4. login to the FTP server as a well-known user
//
$ret = $f->login($ftp['user'], $ftp['pass']);
if (PEAR::isError($ret)) {
    $f->disconnect();
    die($ret->getMessage());
}
printf('login as <b>%s</b><br />', $ftp['user']);
//
// 5. changes directory to final destination for upload operation
//
$ret = $f->cd($dest);
if (PEAR::isError($ret)) {
    $f->disconnect();
    die($ret->getMessage());
}
//
// 6. attachs an instance of the FTP/Progress subclass observer
//
$observer = new Observer_ProgressUpload($meter);
Esempio n. 8
0
    function execAction()
    {
        $ftp_login = extGetParam($_POST, 'ftp_login_name', '');
        $ftp_pass = extGetParam($_POST, 'ftp_login_pass', '');
        global $dir, $mosConfig_live_site;
        if ($ftp_login != '' || $ftp_pass != '') {
            $ftp_host = extGetParam($_POST, 'ftp_hostname_port', 'localhost:21');
            $url = @parse_url('ftp://' . $ftp_host);
            if (empty($url)) {
                ext_Result::sendResult('ftp_authentication', false, 'Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21');
            }
            $port = empty($url['port']) ? 21 : $url['port'];
            $ftp = new Net_FTP($url['host'], $port, 20);
            $res = $ftp->connect();
            if (PEAR::isError($res)) {
                ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_connection_failed'] . ' (' . $url['host'] . ')');
            } else {
                $res = $ftp->login($ftp_login, $ftp_pass);
                $ftp->disconnect();
                if (PEAR::isError($res)) {
                    ext_Result::sendResult('ftp_authentication', false, $GLOBALS['messages']['ftp_login_failed']);
                }
                $_SESSION['ftp_login'] = $ftp_login;
                $_SESSION['ftp_pass'] = $ftp_pass;
                $_SESSION['ftp_host'] = $ftp_host;
                $_SESSION['file_mode'] = 'ftp';
                session_write_close();
                ext_Result::sendResult('ftp_authentication', true, ext_Lang::msg('actlogin_success'));
            }
        } else {
            ?>
	{
		"xtype": "form",
		"id": "simpleform",
		"labelWidth": 125,
		"url":"<?php 
            echo basename($GLOBALS['script_name']);
            ?>
",
		"dialogtitle": "<?php 
            echo $GLOBALS["messages"]["ftp_header"];
            ?>
",
		"title": "<?php 
            echo $GLOBALS["messages"]["ftp_login_lbl"];
            ?>
",
		"frame": true,
		"keys": {
		    "key": Ext.EventObject.ENTER,
		    "fn" : function(){
				if (Ext.getCmp("simpleform").getForm().isValid()) {
					statusBarMessage( '<?php 
            echo ext_Lang::msg('ftp_login_check', true);
            ?>
', true );
					Ext.getCmp("simpleform").getForm().submit({
						"reset": false,
						"success": function(form, action) { location.reload() },
						"failure": function(form, action) {
							if( !action.result ) return;
							Ext.Msg.alert('<?php 
            echo ext_Lang::err('error', true);
            ?>
', action.result.error);
							statusBarMessage( action.result.error, false, false );
						},
						"scope": Ext.getCmp("simpleform").getForm(),
						"params": {
							"option": "com_extplorer", 
							"action": "ftp_authentication"
						}
					});
    	        } else {
        	        return false;
            	}
            }
		},
		"items": [{
			"xtype": "textfield",
			"fieldLabel": "<?php 
            echo ext_Lang::msg('ftp_login_name', true);
            ?>
",
			"name": "ftp_login_name",
			"width":175,
			"allowBlank":false
		},{
			"xtype": "textfield",
			"fieldLabel": "<?php 
            echo ext_Lang::msg('ftp_login_pass', true);
            ?>
",
			"name": "ftp_login_pass",
			"inputType": "password",
			"width":175,
			"allowBlank":false
		},{
			"xtype": "textfield",
			"fieldLabel": "<?php 
            echo ext_Lang::msg('ftp_hostname_port', true);
            ?>
",
			"name": "ftp_hostname_port",
			"value": "<?php 
            echo extGetParam($_SESSION, 'ftp_host', 'localhost:21');
            ?>
",
			"width":175,
			"allowBlank":false
		}],
		"buttons": [{
			"text": "<?php 
            echo ext_Lang::msg('btnlogin', true);
            ?>
", 
			"type": "submit",
			"handler": function() {
				statusBarMessage( '<?php 
            echo ext_Lang::msg('ftp_login_check', true);
            ?>
', true );
				Ext.getCmp("simpleform").getForm().submit({
					"reset": false,
					"success": function(form, action) { location.reload() },
					"failure": function(form, action) {
						if( !action.result ) return;
						Ext.Msg.alert('<?php 
            echo ext_Lang::err('error', true);
            ?>
', action.result.error);
						statusBarMessage( action.result.error, false, false );
					},
					"scope": Ext.getCmp("simpleform").getForm(),
					"params": {
						"option": "com_extplorer", 
						"action": "ftp_authentication"
					}
				});
			}
		},{
			"text": "<?php 
            echo ext_Lang::msg('btncancel', true);
            ?>
", 
			"handler": function() { Ext.getCmp("dialog").destroy(); }
		}]
	}
		<?php 
        }
    }
Esempio n. 9
0
 function _retrieveServerData($id, $dataType)
 {
     switch ($this->{"_source" . ucfirst($dataType)}) {
         case "file":
             // File source is used, get file and read as-is into a string
             $source = realpath($this->{"_sourcePath" . ucfirst($dataType)} . "/" . $id . ".TXT");
             $data = @file_get_contents($source);
             if ($data === false) {
                 return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_WRONG_SERVER_DATA, __FILE__, __LINE__);
             }
             break;
         case "http":
             // HTTP used, acquire request object and fetch data from webserver. Return body of reply
             include_once "HTTP/Request.php";
             $request = new HTTP_Request($this->{"_sourcePath" . ucfirst($dataType)} . "/" . $id . ".TXT", $this->_httpOptions);
             $status = $request->sendRequest();
             if (Services_Weather::isError($status) || (int) $request->getResponseCode() != 200) {
                 return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_WRONG_SERVER_DATA, __FILE__, __LINE__);
             }
             $data = $request->getResponseBody();
             break;
         case "ftp":
             // FTP as source, acquire neccessary object first
             include_once "Net/FTP.php";
             // Parse source to get the server data
             $server = parse_url($this->{"_sourcePath" . ucfirst($dataType)} . "/" . $id . ".TXT");
             // If neccessary options are not set, use defaults
             if (!isset($server["port"]) || $server["port"] == "" || $server["port"] == 0) {
                 $server["port"] = 21;
             }
             if (!isset($server["user"]) || $server["user"] == "") {
                 $server["user"] = "******";
             }
             if (!isset($server["pass"]) || $server["pass"] == "") {
                 $server["pass"] = "******";
             }
             // Instantiate object and connect to server
             $ftp = new Net_FTP($server["host"], $server["port"], $this->_httpOptions["timeout"]);
             $status = $ftp->connect();
             if (Services_Weather::isError($status)) {
                 return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_WRONG_SERVER_DATA, __FILE__, __LINE__);
             }
             // Login to server...
             $status = $ftp->login($server["user"], $server["pass"]);
             if (Services_Weather::isError($status)) {
                 return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_WRONG_SERVER_DATA, __FILE__, __LINE__);
             }
             // ...and retrieve the data into a temporary file
             $tempfile = tempnam("./", "Services_Weather_Metar");
             $status = $ftp->get($server["path"], $tempfile, true, FTP_ASCII);
             if (Services_Weather::isError($status)) {
                 unlink($tempfile);
                 return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_WRONG_SERVER_DATA, __FILE__, __LINE__);
             }
             // Disconnect FTP server, and read data from temporary file
             $ftp->disconnect();
             $data = @file_get_contents($tempfile);
             unlink($tempfile);
             break;
     }
     // Split data into an array and return
     return preg_split("/\n|\r\n|\n\r/", $data);
 }