Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+63
-21
@@ -79,7 +79,7 @@ class _Ftp extends \IPS\File
|
||||
}
|
||||
$ftp->chdir( $values['ftp_details']['path'] );
|
||||
|
||||
$filename = md5( uniqid() ) . '.ips.txt';
|
||||
$filename = md5( mt_rand() ) . '.ips.txt';
|
||||
$tmpFileName = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
|
||||
\file_put_contents( $tmpFileName, 'OK' );
|
||||
$ftp->upload( $filename, $tmpFileName );
|
||||
@@ -113,7 +113,7 @@ class _Ftp extends \IPS\File
|
||||
*/
|
||||
public static function displayName( $settings )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'filehandler_display_name', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('filehandler__Ftp'), $settings['ftp_details']['server'] ) ) );
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'filehandler_display_name', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('filehandler__Ftp'), ( !empty( $settings['ftp_details']['path'] ) ) ? $settings['ftp_details']['server'] . " (" . $settings['ftp_details']['path'] . ")" : $settings['ftp_details']['server'] ) ) );
|
||||
}
|
||||
|
||||
/* !File Handling */
|
||||
@@ -191,7 +191,11 @@ class _Ftp extends \IPS\File
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->ftp()->delete( $this->container . '/' . $this->filename );
|
||||
/* Only issue delete command if the file (and container) exist...otherwise a delete command would fail but our intention is complete */
|
||||
if( $this->checkExists( $this->container . '/' . $this->filename ) )
|
||||
{
|
||||
$this->ftp()->delete( $this->container . '/' . $this->filename );
|
||||
}
|
||||
|
||||
/* Log deletion request */
|
||||
$this->log( "file_deletion", 'delete', NULL, 'log' );
|
||||
@@ -206,7 +210,11 @@ class _Ftp extends \IPS\File
|
||||
*/
|
||||
public function deleteContainer( $container )
|
||||
{
|
||||
$this->ftp()->rmdir( $container, TRUE );
|
||||
/* Actually remove, checking if it exists before attempting */
|
||||
if( $this->checkExists( $container ) )
|
||||
{
|
||||
$this->ftp()->rmdir( $container, TRUE );
|
||||
}
|
||||
|
||||
/* Log deletion request */
|
||||
$realContainer = $this->container;
|
||||
@@ -214,13 +222,38 @@ class _Ftp extends \IPS\File
|
||||
$this->log( "container_deletion", 'delete', NULL, 'log' );
|
||||
$this->container = $realContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a path exists
|
||||
*
|
||||
* @param string $path Path to check
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkExists( $path )
|
||||
{
|
||||
$pathBits = explode( '/', $path );
|
||||
$reconstructed = array();
|
||||
|
||||
foreach( $pathBits as $piece )
|
||||
{
|
||||
$pathToCheck = count( $reconstructed ) ? implode( '/', $reconstructed ) : '.';
|
||||
if( $this->ftp()->ls( $pathToCheck ) === FALSE OR !in_array( $piece, $this->ftp()->ls( $pathToCheck ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$reconstructed[] = $piece;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* !FTP Utility Methods */
|
||||
|
||||
|
||||
/**
|
||||
* @brief FTP Connection
|
||||
*/
|
||||
protected $ftp = NULL;
|
||||
protected static $ftp = array();
|
||||
|
||||
/**
|
||||
* Get FTP Connection
|
||||
@@ -230,20 +263,22 @@ class _Ftp extends \IPS\File
|
||||
*/
|
||||
protected function ftp()
|
||||
{
|
||||
if ( $this->ftp === NULL )
|
||||
$key = md5( json_encode( $this->configuration ) );
|
||||
|
||||
if ( !isset( static::$ftp[ $key ] ) OR static::$ftp[ $key ] === NULL )
|
||||
{
|
||||
if ( $this->configuration['ftp_details']['protocol'] == 'sftp' )
|
||||
{
|
||||
$this->ftp = new \IPS\Ftp\Sftp( $this->configuration['ftp_details']['server'], $this->configuration['ftp_details']['un'], $this->configuration['ftp_details']['pw'], $this->configuration['ftp_details']['port'] );
|
||||
static::$ftp[ $key ] = new \IPS\Ftp\Sftp( $this->configuration['ftp_details']['server'], $this->configuration['ftp_details']['un'], $this->configuration['ftp_details']['pw'], $this->configuration['ftp_details']['port'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ftp = new \IPS\Ftp( $this->configuration['ftp_details']['server'], $this->configuration['ftp_details']['un'], $this->configuration['ftp_details']['pw'], $this->configuration['ftp_details']['port'], ( $this->configuration['ftp_details']['protocol'] == 'ssl_ftp' ) );
|
||||
static::$ftp[ $key ] = new \IPS\Ftp( $this->configuration['ftp_details']['server'], $this->configuration['ftp_details']['un'], $this->configuration['ftp_details']['pw'], $this->configuration['ftp_details']['port'], ( $this->configuration['ftp_details']['protocol'] == 'ssl_ftp' ) );
|
||||
}
|
||||
|
||||
$this->ftp->chdir( $this->configuration['ftp_details']['path'] );
|
||||
static::$ftp[ $key ]->chdir( $this->configuration['ftp_details']['path'] );
|
||||
}
|
||||
return $this->ftp;
|
||||
return static::$ftp[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,18 +364,25 @@ class _Ftp extends \IPS\File
|
||||
*/
|
||||
public function filesize()
|
||||
{
|
||||
$this->ftp()->chdir( $this->configuration['ftp_details']['path'] );
|
||||
|
||||
if( $this->container )
|
||||
try
|
||||
{
|
||||
$this->ftp()->chdir( $this->container );
|
||||
$this->ftp()->chdir( $this->configuration['ftp_details']['path'] );
|
||||
|
||||
if( $this->container )
|
||||
{
|
||||
$this->ftp()->chdir( $this->container );
|
||||
}
|
||||
|
||||
$size = $this->ftp()->size( $this->filename );
|
||||
|
||||
$this->ftp()->chdir( $this->configuration['ftp_details']['path'] );
|
||||
|
||||
return $size ?: parent::filesize();
|
||||
}
|
||||
catch( \IPS\Ftp\Exception $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$size = $this->ftp()->size( $this->filename );
|
||||
|
||||
$this->ftp()->chdir( $this->configuration['ftp_details']['path'] );
|
||||
|
||||
return $size ?: parent::filesize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user