mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 18:44:30 +00:00
PHRAS-771 #time 2h
report de PHRAS-750 (connect to ftp via a auth proxy)
This commit is contained in:
@@ -21,9 +21,11 @@ class FtpServiceProvider implements ServiceProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['phraseanet.ftp.client'] = $app->protect(function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) {
|
$app['phraseanet.ftp.client'] = $app->protect(
|
||||||
return new \ftpclient($host, $port, $timeout, $ssl, $proxy, $proxyport);
|
function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false, $proxyuser = false, $proxypwd = false) {
|
||||||
});
|
return new \ftpclient($host, $port, $timeout, $ssl, $proxy, $proxyport, $proxyuser, $proxypwd);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -41,6 +41,8 @@ class FtpEditor extends AbstractEditor
|
|||||||
<tasksettings>
|
<tasksettings>
|
||||||
<proxy></proxy>
|
<proxy></proxy>
|
||||||
<proxyport></proxyport>
|
<proxyport></proxyport>
|
||||||
|
<proxyuser></proxyuser>
|
||||||
|
<proxypwd></proxypwd>
|
||||||
</tasksettings>
|
</tasksettings>
|
||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
@@ -53,6 +55,8 @@ EOF;
|
|||||||
return [
|
return [
|
||||||
'proxy' => static::FORM_TYPE_STRING,
|
'proxy' => static::FORM_TYPE_STRING,
|
||||||
'proxyport' => static::FORM_TYPE_STRING,
|
'proxyport' => static::FORM_TYPE_STRING,
|
||||||
|
'proxyuser' => static::FORM_TYPE_STRING,
|
||||||
|
'proxypwd' => static::FORM_TYPE_STRING,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\TaskManager\Job;
|
namespace Alchemy\Phrasea\TaskManager\Job;
|
||||||
|
|
||||||
|
use ftpclient;
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\Application\Helper\NotifierAware;
|
use Alchemy\Phrasea\Application\Helper\NotifierAware;
|
||||||
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
|
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
|
||||||
@@ -95,6 +96,8 @@ class FtpJob extends AbstractJob
|
|||||||
|
|
||||||
$proxy = (string) $settings->proxy;
|
$proxy = (string) $settings->proxy;
|
||||||
$proxyport = (string) $settings->proxyport;
|
$proxyport = (string) $settings->proxyport;
|
||||||
|
$proxyuser = (string) $settings->proxyuser;
|
||||||
|
$proxypwd = (string) $settings->proxypwd;
|
||||||
|
|
||||||
$state = "";
|
$state = "";
|
||||||
$ftp_server = $export->getAddr();
|
$ftp_server = $export->getAddr();
|
||||||
@@ -122,7 +125,11 @@ class FtpJob extends AbstractJob
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$ssl = $export->isSsl();
|
$ssl = $export->isSsl();
|
||||||
$ftp_client = $app['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $proxy, $proxyport);
|
/** @var \ftpClient $ftp_client */
|
||||||
|
$ftp_client = $app['phraseanet.ftp.client'](
|
||||||
|
$ftp_server, 21, 300, $ssl, $proxy, $proxyport,
|
||||||
|
$proxyuser, $proxypwd
|
||||||
|
);
|
||||||
$ftp_client->login($ftp_user_name, $ftp_user_pass);
|
$ftp_client->login($ftp_user_name, $ftp_user_pass);
|
||||||
|
|
||||||
if ($export->isPassif()) {
|
if ($export->isPassif()) {
|
||||||
@@ -261,7 +268,7 @@ class FtpJob extends AbstractJob
|
|||||||
if ($export->isLogfile()) {
|
if ($export->isLogfile()) {
|
||||||
$this->log('debug', "logfile ");
|
$this->log('debug', "logfile ");
|
||||||
|
|
||||||
$date = new DateTime();
|
$date = new \DateTime();
|
||||||
$buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n";
|
$buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n";
|
||||||
|
|
||||||
foreach ($export->getElements() as $exportElement) {
|
foreach ($export->getElements() as $exportElement) {
|
||||||
|
@@ -12,36 +12,53 @@
|
|||||||
class ftpclient
|
class ftpclient
|
||||||
{
|
{
|
||||||
protected $connexion;
|
protected $connexion;
|
||||||
protected $proxy;
|
|
||||||
protected $host;
|
protected $host;
|
||||||
|
protected $port;
|
||||||
protected $cached_dirs = [];
|
protected $cached_dirs = [];
|
||||||
protected $debug = false;
|
protected $debug = false;
|
||||||
|
private $proxyhost = false;
|
||||||
|
private $proxyport = false;
|
||||||
|
private $proxyuser = false;
|
||||||
|
private $proxypwd = false;
|
||||||
|
|
||||||
public function __construct($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false)
|
private function cleanAddr($addr, &$usedSSL)
|
||||||
{
|
{
|
||||||
$host = mb_substr($host, -1, 1) == '/' ? mb_substr($host, 0, (mb_strlen($host) - 1)) : $host;
|
$addr = trim($addr);
|
||||||
|
if(substr($addr, 0, 7) === "ftps://") {
|
||||||
|
$addr = substr($addr, 7);
|
||||||
|
$usedSSL = true;
|
||||||
|
}
|
||||||
|
elseif(substr($addr, 0, 6) === "ftp://") {
|
||||||
|
$addr = substr($addr, 6);
|
||||||
|
}
|
||||||
|
if(substr($addr, -1, 1) == '/') {
|
||||||
|
$addr = substr($addr, 0, (strlen($addr) - 1));
|
||||||
|
}
|
||||||
|
return $addr;
|
||||||
|
}
|
||||||
|
|
||||||
if (mb_strpos($host, 'ftp://') !== false)
|
public function __construct($host, $port = 21, $timeout = 90, $ssl = false,
|
||||||
$host = mb_substr($host, 6);
|
$proxyhost = false,
|
||||||
|
$proxyport = false,
|
||||||
$host = $proxy ? $proxy : $host;
|
$proxyuser = false,
|
||||||
$port = $proxyport ? $proxyport : $port;
|
$proxypwd = false
|
||||||
|
)
|
||||||
if ($this->debug && $proxy)
|
{
|
||||||
echo "Utilisation du proxy $proxy\n<br>";
|
|
||||||
|
|
||||||
if ($this->debug && $proxyport)
|
|
||||||
echo "Utilisation du port proxy $proxyport\n<br>";
|
|
||||||
|
|
||||||
$this->proxy = $proxy;
|
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->proxyhost = $proxyhost;
|
||||||
|
$this->proxyport = $proxyport;
|
||||||
|
$this->proxyuser = $proxyuser;
|
||||||
|
$this->proxypwd = $proxypwd;
|
||||||
|
|
||||||
|
// if there is a proxy, connect to it, not on host/port provided
|
||||||
|
$host = $proxyhost ? $proxyhost : $host;
|
||||||
|
$port = $proxyport ? $proxyport : $port;
|
||||||
|
// clean the addr, force ssl if needed
|
||||||
|
$host = $this->cleanAddr($host, $ssl);
|
||||||
|
|
||||||
if ($this->debug)
|
if ($this->debug)
|
||||||
echo "Ouverture de connection vers $host:$port timeout $timeout et proxy $proxy:$proxyport\n<br>";
|
echo "Ouverture de connection vers $host:$port timeout $timeout\n<br>";
|
||||||
|
|
||||||
if (trim($host) == '') {
|
|
||||||
throw new Exception('Nom d\'hote incorrect ' . $host);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($ssl === true) {
|
if ($ssl === true) {
|
||||||
@@ -72,22 +89,29 @@ class ftpclient
|
|||||||
|
|
||||||
public function login($username, $password)
|
public function login($username, $password)
|
||||||
{
|
{
|
||||||
$username = $this->proxy ? $username . "@" . $this->host : $username;
|
if($this->proxyhost) {
|
||||||
|
$username .= ("@" . $this->host);
|
||||||
|
if ($this->proxyuser) {
|
||||||
|
$username .= (' ' . $this->proxyuser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$retry = 3;
|
$retry = 3;
|
||||||
$done = false;
|
$done = false;
|
||||||
|
|
||||||
if ($this->debug)
|
while (!$done && $retry-- > 0) {
|
||||||
echo "tentative de login avec $username, $password\n<br>";
|
$ret = ftp_raw($this->connexion, "USER ".$username);
|
||||||
|
if(is_array($ret) && $password) {
|
||||||
while ($retry > 0) {
|
$ret = ftp_raw($this->connexion, "PASS ".$password);
|
||||||
if ((@ftp_login($this->connexion, $username, $password)) === false) {
|
}
|
||||||
$retry --;
|
if(is_array($ret) && $this->proxypwd) {
|
||||||
} else {
|
$ret = ftp_raw($this->connexion, "ACCT ".$this->proxypwd);
|
||||||
$retry = 0;
|
}
|
||||||
|
if(is_array($ret)) {
|
||||||
$done = true;
|
$done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $done) {
|
if (! $done) {
|
||||||
throw new Exception('Impossible de s\'authentifier sur le serveur FTP');
|
throw new Exception('Impossible de s\'authentifier sur le serveur FTP');
|
||||||
}
|
}
|
||||||
|
@@ -7,12 +7,26 @@
|
|||||||
<input class="formElem" type="text" name="proxy" />
|
<input class="formElem" type="text" name="proxy" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ 'task::ftp:proxy port' | trans }}</label>
|
<label class="control-label">{{ 'task::ftp:proxy port' | trans }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input class="formElem" type="text" name="proxyport" />
|
<input class="formElem" type="text" name="proxyport" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">{{ 'task::ftp:proxy user' | trans }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input class="formElem" type="text" name="proxyuser" autocomplete="off" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">{{ 'task::ftp:proxy password' | trans }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<!-- input type=password is double because of chrome and autofill issue see http://stackoverflow.com/questions/10938891/disable-autofill-in-chrome-without-disabling-autocomplete -->
|
||||||
|
<input class="formElem" type="text" name="proxypwd_fake" autocomplete="off" style="display:none" />
|
||||||
|
<input class="formElem" type="text" name="proxypwd" autocomplete="off" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +41,8 @@
|
|||||||
var gform = document.forms['graphicForm'];
|
var gform = document.forms['graphicForm'];
|
||||||
gform.proxy.value = xml.find("proxy").text();
|
gform.proxy.value = xml.find("proxy").text();
|
||||||
gform.proxyport.value = xml.find("proxyport").text();
|
gform.proxyport.value = xml.find("proxyport").text();
|
||||||
|
gform.proxyuser.value = xml.find("proxyuser").text();
|
||||||
|
gform.proxypwd.value = xml.find("proxypwd").text();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user