1
0
Fork 0
Dieser Commit ist enthalten in:
Harald-Innetzberger 2012-04-30 18:28:18 +00:00
Ursprung 016c27d322
Commit ddbd6ea5ab
3 geänderte Dateien mit 122 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -286,6 +286,108 @@ class ConfigController extends Zend_Controller_Action
$this->_forward('index');
}
/**
* Test FTP-Connection
*
* @return void
*/
public function testFtpConnectionAction()
{
$translator = $this->view->lang->getTranslator();
if ($this->_request->isPost()) {
$postData = $this->_request->getPost();
$index = (int)$this->_request->getPost('param');
// fetch the required params
$server = $postData['ftp_'.$index.'_server'];
$port = $postData['ftp_'.$index.'_port'];
$timeout = $postData['ftp_'.$index.'_timeout'];
$mode = $postData['ftp_'.$index.'_passiveMode'];
$ssl = $postData['ftp_'.$index.'_ssl'];
$user = $postData['ftp_'.$index.'_user'];
$password = $postData['ftp_'.$index.'_pass'];
$directory = $postData['ftp_'.$index.'_dir'];
// Params for transferring a test file
$name = 'ftp_transfer_testfile.txt';
$filename = APPLICATION_PATH . '/forms/Config/ftp_transfertest/ftp_transfer_testfile.txt';
$target_folder = APPLICATION_PATH . '/forms/Config/ftp_transfertest/ftp_target/';
$upload = false;
// try to connect via ssl to the ftp server
if ($ssl == 'y' && function_exists('ftp_ssl_connect')) {
$ftpStream = ftp_ssl_connect($server, $port, $timeout);
} else {
// otherwise try to connect to the ftp server normally
$ftpStream = ftp_connect($server, $port, $timeout);
}
// got resource?
if (!is_resource($ftpStream)) {
$message = sprintf($translator->_('L_FTP_CONNECTION_ERROR'), $server, $port);
// connection ok? let's try to login
} else if (!ftp_login($ftpStream, $user, $password)) {
$message = sprintf($translator->_('L_FTP_LOGIN_ERROR'), $user);
// if passive mode is set turn it on
if ($mode == 'y') {
ftp_pasv($ftpStream, true);
}
// login ok? let's set/change the ftp upload directory
} else if (!ftp_chdir($ftpStream, $directory)) {
$message = sprintf($translator->_('L_CHANGEDIRERROR'));
// chmod target_folder if it's necessary
} else if (file_exists($target_folder) && substr(sprintf('%o', fileperms($target_folder)), -4) < '0755') {
ftp_chmod($ftpStream, 0755, $target_folder);
$message = '';
// ftp directory exists and chmod ok? let's test the ftp transfer with a test file
} else if (!ftp_put($ftpStream, $target_folder.$name, $filename, FTP_ASCII)) {
$message = sprintf($translator->_('L_FTP_FILE_TRANSFER_ERROR'), $name);
} else {
$upload = true;
$message = sprintf($translator->_('L_FTP_FILE_TRANSFER_SUCCESS'), $name)
. '<br /><br />' .
$translator->_('L_FTP_OK');
// delete the test file after a successful transfer test
if (file_exists($target_folder.$name)) {
ftp_delete($ftpStream, $target_folder.$name);
}
}
// let's show the error messages
if (!$upload && count($message) > 0) {
$this->view->popUpMessage()->addMessage(
'config-validate-error',
'L_ERROR',
$message,
array(
'modal' => true
)
);
// or show the confirmation message
} else if ($upload && count($message) > 0) {
$this->view->popUpMessage()->addMessage(
'config-validate-message',
'L_NOTICE',
$message,
array(
'modal' => true
)
);
}
// close ftp connection
ftp_close($ftpStream);
}
$this->_forward('index');
}
/**
* Set the default value of all sub forms to the configuration values
*

Datei anzeigen

@ -51,7 +51,7 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm
$this->_addInputServerAndPort($ftpConnectionId);
$this->_addInputUserAndPass($ftpConnectionId);
$this->_addInputPath($ftpConnectionId);
if ($nrOfFtpProfiles > 1) {
$buttonDelete = 'ftpDelete' . $ftpConnectionId;
} else {
@ -305,7 +305,7 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm
/**
* Add Button "Test connection"
* Add Button "Delete connection"
*
*
* @param int $index
* @param string $buttonDelete
*
@ -318,7 +318,7 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm
} else {
$buttonDecorator = 'Default';
}
$this->addElement(
'button',
'ftpCheck' . $index,
@ -331,8 +331,8 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm
'escape' => false,
'label' => '',
'class' => 'Formbutton ftpToggle' . $index,
'onclick' => "alert('checkConnection(" .
$index . ")');",
'onclick' => "testFtpConnection(" .
$index . ");",
)
);

Datei anzeigen

@ -31,6 +31,14 @@ $deleteFtpConnectionUrl = $this->url(
null,
true
);
$testFtpConnectionUrl = $this->url(
array(
'controller' => 'config',
'action' => 'test.Ftp.Connection',
),
null,
true
);
?>
<script type="text/javascript">
/*<![CDATA[*/
@ -165,6 +173,13 @@ $deleteFtpConnectionUrl = $this->url(
$('#config_form').submit();
}
function testFtpConnection(recipientId)
{
setParam(recipientId);
$('#config_form').attr('action','<?php echo $testFtpConnectionUrl; ?>');
$('#config_form').submit();
}
function setParam(value)
{
$('#param').val(value);