use Cubist\Net\Transfer\FTP;
use Cubist\Net\Transfer\IServer;
use Cubist\Net\Transfer\SFTP;
+use Cubist\Net\Transfer\S3;
class ExternalServer extends CubistMagicAbstractModel implements IServer
{
parent::setFields();
$this->addField('name', Text::class, __('Nom'), ['column' => true]);
- $this->addField('protocol', SelectFromArray::class, __('Protocole'), ['options' => $this->getProtocols(), 'default' => 'FTP', 'column' => true, 'allows_null' => false]);
+ $this->addField('protocol', SelectFromArray::class, __('Protocole'), ['options' => $this->getProtocols(), 'default' => 'SFTP', 'column' => true, 'allows_null' => false]);
$this->addField('ftp_mode', SelectFromArray::class, __('Mode de transfert'), ['options' => ['0' => __('Mode passif'), '1' => __('Mode actif')], 'default' => '1', 'when' => ['protocol' => $this->getFTPProtocols()], 'allows_null' => false,]);
$this->addField('host', Text::class, __('Hôte'), ['default' => '', 'column' => true, 'when' => ['protocol' => $this->getHostProtocols()]]);
$this->addField('port', Integer::class, __('Port'), ['hint' => __('Laisser vide pour utiliser le port par défaut'), 'default' => '', 'min' => 1, 'max' => 65536, 'when' => ['protocol' => $this->getPortProtocols()]]);
$this->addField('username', Text::class, __('Nom d\'utilisateur'), ['when' => ['protocol' => $this->getUsernameProtocols()]]);
$this->addField('password', Password::class, __('Mot de passe'), ['when' => ['protocol' => $this->getPasswordProtocols()]]);
+ $this->addField('region', Text::class, __('Région'), ['when' => ['protocol' => 'S3']]);
+ $this->addField('endpoint', URL::class, __('Endpoint'), ['when' => ['protocol' => 'S3Compatible']]);
+ $this->addField('key', Text::class, __('Clé d\'accès'), ['when' => ['protocol' => $this->getS3Protocols()]]);
+ $this->addField('secret', Password::class, __('Secret'), ['when' => ['protocol' => $this->getS3Protocols()]]);
+ $this->addField('bucket', Text::class, __('Bucket'), ['when' => ['protocol' => $this->getS3Protocols()]]);
$this->addField('base_path', Text::class, __('Chemin de base'), ['default' => '/']);
$this->addField('base_url', Text::class, __('URL de base'), ['default' => 'https://', 'column' => true, 'column_type' => 'model_function', 'column_function_name' => 'getBaseURL']);
}
return ['name' => $server->name, 'base_url' => $server->getBaseURL() ?: $server->base_path];
}
+ protected function getS3Protocols()
+ {
+ return ['S3', 'S3Compatible'];
+ }
+
protected function getProtocols()
{
- return ['FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'SFTP' => 'SFTP'];
+ return ['SFTP' => 'SFTP', 'FTP' => __('FTP non sécurisé'), 'FTPS' => __('FTP sécurisé explicite sur TLS'), 'FTPES' => __('FTP sécurisé implicite sur TLS'), 'S3' => __('Amazon S3'), 'S3Compatible' => __('Serveurs S3 compatibles')];
}
protected function getFTPProtocols()
return new FTP($this);
} else if ($this->getProtocol() === 'SFTP') {
return new SFTP($this);
+ } else if ($this->getProtocol() === 'S3') {
+ return new S3($this);
}
return null;
}
return $this->base_url;
}
+ public function getRegion()
+ {
+ return $this->region;
+ }
+
+ public function getKey()
+ {
+ return $this->key;
+ }
+
+ public function getSecret()
+ {
+ return $this->secret;
+ }
+
+ public function getBucket()
+ {
+ return $this->bucket;
+ }
+
+ public function getEndpoint()
+ {
+ return $this->endpoint;
+ }
+
public function getSettings()
{
return ['ftp_mode' => $this->ftp_mode];