commit c4605c429b83148b83a127523d7d71e8bdb67df0
parent 2a8d30194119577706aeacd3a0596e06ffa42e62
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 14 Oct 2020 00:01:07 +0200
Fix: The targets SCP,SFTP,DAV are now tested and ready :)
Diffstat:
4 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/modules/cms/generator/target/Dav.class.php b/modules/cms/generator/target/Dav.class.php
@@ -33,28 +33,49 @@ class Dav extends BaseTarget
/**
* @var false|resource
*/
- private $fp;
+ //private $socket;
public function checkConnection()
{
- $content = "HEAD / HTTP/1.1\r\n";
+ $dest = $this->url->path;
+
+ $content = "HEAD /$dest HTTP/1.1\r\n";
$content .= "Host: ".$this->url->host."\r\n";
$content .= "Connection: Close\r\n";
$content .= "\r\n";
- fwrite($this->fp, $content );
+ fwrite($this->createSocket(), $content );
}
public function put($source, $dest, $time)
{
+ $dest = $this->url->path . '/' . $dest;
+
+ $this->mkdirs( dirname($dest) ); // Try MKCOL
+
$content = "PUT $dest HTTP/1.1\r\n";
$content .= "Host: ".$this->url->host."\r\n";
+ $content .= "Content-Length: ".filesize($source)."\r\n";
$content .= "Connection: Close\r\n";
$content .= "\r\n";
- fwrite($this->fp, $content);
- fwrite($this->fp, file_get_contents($source));
+ fwrite($this->createSocket(), $content.file_get_contents($source));
+ }
+
+
+ /**
+ * resursive make the directory on DAV server.
+ *
+ * @param String path
+ */
+ private function mkdirs($strPath)
+ {
+ $pStrPath = dirname($strPath);
+ if ( $pStrPath && $pStrPath != '.' && $pStrPath != '/' )
+ $this->mkdirs($pStrPath);
+
+ $this->mkcol( $strPath );
}
@@ -63,12 +84,12 @@ class Dav extends BaseTarget
$content .= "Host: ".$this->url->host."\r\n";
$content .= "Connection: Close\r\n";
$content .= "\r\n";
- fwrite($this->fp, $content);
+ fwrite($this->createSocket(), $content);
}
public function close()
{
- fclose($this->fp);
+ //fclose($this->socket);
}
protected static function acceptsSchemes()
@@ -78,11 +99,20 @@ class Dav extends BaseTarget
public function open()
{
- $this->fp = fsockopen($this->url->host, empty($this->url->port)?80:$this->url->port, $errno, $errstr, 5);
+ $this->checkConnection();
+ }
- if(!$this->fp)
+ /**
+ * @return false|resource
+ */
+ protected function createSocket()
+ {
+ $socket = fsockopen($this->url->host, empty($this->url->port) ? 80 : $this->url->port, $errno, $errstr, 5);
+
+ if(!$socket)
throw new PublisherException("cannot connect to DAV server: $errno -> $errstr");
- $this->checkConnection();
+ return $socket;
+
}
}
\ No newline at end of file
diff --git a/modules/cms/generator/target/Fax.class.php b/modules/cms/generator/target/Fax.class.php
@@ -36,13 +36,12 @@ class Fax extends BaseTarget
public function put($source, $dest, $time)
{
- Logger::debug("düüüüüüüüüüüükrrrkkrkrkrkkrkrkrkr");
- // very, very funny, right?
+ // here must happen some magic
}
public function close()
{
- Logger::debug("Hanging up ...");
+ Logger::debug("Hanging up........................... NO CARRIER");
}
protected static function acceptsSchemes()
diff --git a/modules/cms/generator/target/SFtp.class.php b/modules/cms/generator/target/SFtp.class.php
@@ -77,6 +77,8 @@ class SFtp extends Scp
$sftp = $this->sftpConnection;
+ ssh2_sftp_mkdir ( $sftp, dirname($dest),0755, true);
+
$stream = @fopen("ssh2.sftp://$sftp$dest", 'w');
if (! $stream)
diff --git a/modules/cms/generator/target/Scp.class.php b/modules/cms/generator/target/Scp.class.php
@@ -82,8 +82,18 @@ class Scp extends BaseTarget
{
$dest = $this->url->path . '/' . $dest;
-
- ssh2_scp_send($this->sshConnection, $source, $dest, 0644);
+ // ok, lets create the necessary directories on the remote side.
+ $stream = ssh2_exec($this->sshConnection,'mkdir -p '.dirname($dest) );
+ if ( $stream )
+ fclose($stream);
+ else
+ throw new PublisherException("Failed to mkdir ".dirname($dest).' on remote');
+
+ $success = ssh2_scp_send($this->sshConnection, $source, $dest, 0644);
+
+ if ( !$success) {
+ throw new PublisherException( 'Failed to publish '.$source.' to '.$dest );
+ }
}