Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+57
-21
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief FTP Details input class for Form Builder
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 17 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -27,12 +27,16 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
|
||||
/**
|
||||
* @brief Default Options
|
||||
* @code
|
||||
'validate' => TRUE // Should details be validated?
|
||||
'validate' => TRUE, // Should details be validated?
|
||||
'allowBypassValidation' => TRUE, // If TRUE, the user will be allowed to use value even if the validation fails
|
||||
'rejectUnsupportedSftp' => FALSE, // If SFTP deatils are provided, but the server doesn't support it, should validation fail?
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
'validate' => TRUE,
|
||||
'validate' => TRUE,
|
||||
'allowBypassValidation' => FALSE,
|
||||
'rejectUnsupportedSftp' => FALSE,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -44,7 +48,29 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
|
||||
$value = is_array( $this->value ) ? $this->value : json_decode( \IPS\Text\Encrypt::fromTag( $this->value )->decrypt(), TRUE );
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->ftp( $this->name, $value );
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->ftp( $this->name, $value, $this->options['allowBypassValidation'] and $this->error );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @param array $value The value
|
||||
* @return \IPS\Ftp
|
||||
*/
|
||||
public static function connectFromValue( $value )
|
||||
{
|
||||
if ( $value['protocol'] == 'sftp' )
|
||||
{
|
||||
$ftp = new \IPS\Ftp\Sftp( $value['server'], $value['un'], $value['pw'], $value['port'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$ftp = new \IPS\Ftp( $value['server'], $value['un'], $value['pw'], $value['port'], ( $value['protocol'] == 'ssl_ftp' ), 3 );
|
||||
}
|
||||
|
||||
$ftp->chdir( $value['path'] );
|
||||
|
||||
return $ftp;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,33 +80,43 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
/* Do we have a value? */
|
||||
if ( $this->value['server'] or $this->value['un'] or $this->value['pw'] )
|
||||
{
|
||||
if ( $this->options['validate'] )
|
||||
/* And is it different to what it was originally, or do we need to establish the connection for custom validation? */
|
||||
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( \IPS\Text\Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
|
||||
if ( $defaultValue['protocol'] != $this->value['protocol'] or $defaultValue['server'] != $this->value['server'] or $defaultValue['port'] != $this->value['port'] or $defaultValue['un'] != $this->value['un'] or $defaultValue['pw'] != $this->value['pw'] or $defaultValue['path'] != $this->value['path'] or $this->customValidationCode !== NULL )
|
||||
{
|
||||
try
|
||||
/* And are we supposed to be validating? */
|
||||
if ( $this->options['validate'] and ( !$this->options['allowBypassValidation'] or !isset( $this->value['bypassValidation'] ) ) )
|
||||
{
|
||||
if ( $this->value['protocol'] == 'sftp' )
|
||||
/* Do normal validation */
|
||||
try
|
||||
{
|
||||
$ftp = new \IPS\Ftp\Sftp( $this->value['server'], $this->value['un'], $this->value['pw'], $this->value['port'] );
|
||||
$ftp = static::connectFromValue( $this->value );
|
||||
}
|
||||
else
|
||||
catch ( \IPS\Ftp\Exception $e )
|
||||
{
|
||||
$ftp = new \IPS\Ftp( $this->value['server'], $this->value['un'], $this->value['pw'], $this->value['port'], ( $this->value['protocol'] == 'ssl_ftp' ) );
|
||||
throw new \DomainException( 'ftp_err-' . $e->getMessage() );
|
||||
}
|
||||
catch ( \BadMethodCallException $e )
|
||||
{
|
||||
// This means we tried an SFTP connection, but the server doesn't support it. We'll have to assume it's correct unless we've specifically set not to
|
||||
if ( $this->options['rejectUnsupportedSftp'] )
|
||||
{
|
||||
throw new \DomainException( 'ftp_err_no_sftp' );
|
||||
}
|
||||
}
|
||||
|
||||
$ftp->chdir( $this->value['path'] );
|
||||
}
|
||||
catch ( \IPS\Ftp\Exception $e )
|
||||
{
|
||||
throw new \DomainException( 'ftp_err-' . $e->getMessage() );
|
||||
}
|
||||
catch ( \BadMethodCallException $e )
|
||||
{
|
||||
// This means we tried an SFTP connection, but the server doesn't support it. We'll have to assume it's correct
|
||||
}
|
||||
}
|
||||
|
||||
/* Do any custom validation */
|
||||
if( $this->customValidationCode !== NULL )
|
||||
{
|
||||
call_user_func( $this->customValidationCode, $ftp );
|
||||
}
|
||||
}
|
||||
/* If not, should we? */
|
||||
elseif ( $this->required )
|
||||
{
|
||||
throw new \DomainException( 'form_required' );
|
||||
|
||||
Reference in new issue
Block a user