Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+38 -26
View File
@@ -12,16 +12,28 @@
namespace IPS\Helpers\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use DomainException;
use IPS\Ftp as FtpClass;
use IPS\Ftp\Exception;
use IPS\Ftp\Sftp as SftpClass;
use IPS\Output;
use IPS\Text\Encrypt;
use IPS\Theme;
use function defined;
use function is_array;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* FTP input class for Form Builder
*/
class _Ftp extends \IPS\Helpers\Form\FormAbstract
class Ftp extends FormAbstract
{
/**
* @brief Default Options
@@ -32,7 +44,7 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
);
* @endcode
*/
protected $defaultOptions = array(
protected array $defaultOptions = array(
'validate' => TRUE,
'allowBypassValidation' => FALSE,
'rejectUnsupportedSftp' => FALSE,
@@ -43,18 +55,18 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
*
* @return string
*/
public function html()
public function html(): string
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, 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 );
$defaultValue = \is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( \IPS\Text\Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
$value = is_array( $this->value ) ? $this->value : json_decode( Encrypt::fromTag( $this->value )->decrypt(), TRUE );
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
if ( isset( $value['pw'] ) and isset( $defaultValue['pw'] ) and $value['pw'] and $value['pw'] === $defaultValue['pw'] and !$this->error )
{
$value['pw'] = '********';
}
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->ftp( $this->name, $value, $this->options['allowBypassValidation'] and $this->error );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->ftp( $this->name, $value, $this->options['allowBypassValidation'] and $this->error );
}
/**
@@ -62,13 +74,13 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
*
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
$value = parent::getValue();
if ( isset( $value['pw'] ) and $value['pw'] === '********' )
{
$defaultValue = \is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( \IPS\Text\Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
$value['pw'] = $defaultValue['pw'];
}
@@ -78,18 +90,18 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
/**
* Validate
*
* @param array $value The value
* @return \IPS\Ftp
* @param array $value The value
* @return FtpClass|SftpClass
*/
public static function connectFromValue( $value )
public static function connectFromValue( array $value ): FtpClass|SftpClass
{
if ( $value['protocol'] == 'sftp' )
{
$ftp = new \IPS\Ftp\Sftp( $value['server'], $value['un'], $value['pw'], $value['port'] );
$ftp = new SftpClass( $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 = new FtpClass( $value['server'], $value['un'], $value['pw'], $value['port'], ( $value['protocol'] == 'ssl_ftp' ), 3 );
}
$ftp->chdir( $value['path'] );
@@ -102,13 +114,13 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
*
* @return bool
*/
public function validate()
public function validate(): bool
{
/* Do we have a value? */
if ( $this->value['server'] or $this->value['un'] or $this->value['pw'] )
{
/* 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 );
$defaultValue = is_array( $this->defaultValue ) ? $this->defaultValue : json_decode( Encrypt::fromTag( $this->defaultValue )->decrypt(), TRUE );
if ( !isset( $defaultValue['protocol'] ) or $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 )
{
/* And are we supposed to be validating? */
@@ -119,16 +131,16 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
{
$ftp = static::connectFromValue( $this->value );
}
catch ( \IPS\Ftp\Exception $e )
catch ( Exception $e )
{
throw new \DomainException( 'ftp_err-' . $e->getMessage() );
throw new DomainException( 'ftp_err-' . $e->getMessage() );
}
catch ( \BadMethodCallException $e )
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' );
throw new DomainException( 'ftp_err_no_sftp' );
}
}
}
@@ -144,7 +156,7 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
/* If not, should we? */
elseif ( $this->required )
{
throw new \DomainException( 'form_required' );
throw new DomainException( 'form_required' );
}
return true;
@@ -154,10 +166,10 @@ class _Ftp extends \IPS\Helpers\Form\FormAbstract
* String Value
*
* @param mixed $value The value
* @return string
* @return string|int|null
*/
public static function stringValue( $value )
public static function stringValue( mixed $value ): string|int|null
{
return \IPS\Text\Encrypt::fromPlaintext( json_encode( $value ) )->tag();
return Encrypt::fromPlaintext( json_encode( $value ) )->tag();
}
}