openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

commit fcbde6c91e684c0516fa388f400d312bc668873c
parent 220120e3f59ab7c2bc0e6ad45db6e056ecd406bf
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed, 18 Nov 2020 21:01:59 +0100

Renaming of target classes for naming convention reasons.

Diffstat:
Mmodules/cms/generator/link/LinkFormat.class.php | 7+++++++
Dmodules/cms/generator/target/Dav.class.php | 114-------------------------------------------------------------------------------
Amodules/cms/generator/target/DavTarget.class.php | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmodules/cms/generator/target/Fax.class.php | 52----------------------------------------------------
Amodules/cms/generator/target/FaxTarget.class.php | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmodules/cms/generator/target/Ftp.class.php | 176-------------------------------------------------------------------------------
Amodules/cms/generator/target/FtpTarget.class.php | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/cms/generator/target/Ftps.class.php | 2+-
Dmodules/cms/generator/target/Local.class.php | 202-------------------------------------------------------------------------------
Amodules/cms/generator/target/LocalTarget.class.php | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmodules/cms/generator/target/SFtp.class.php | 102-------------------------------------------------------------------------------
Amodules/cms/generator/target/SFtpTarget.class.php | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmodules/cms/generator/target/Scp.class.php | 114-------------------------------------------------------------------------------
Amodules/cms/generator/target/ScpTarget.class.php | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/cms/generator/target/Target.class.php | 22++++++++++++++++++++++
Mmodules/cms/generator/target/TargetFactory.class.php | 12++++++------
16 files changed, 790 insertions(+), 767 deletions(-)

diff --git a/modules/cms/generator/link/LinkFormat.class.php b/modules/cms/generator/link/LinkFormat.class.php @@ -8,5 +8,12 @@ use cms\model\BaseObject; interface LinkFormat { + /** + * Creates an absolute or relative URL to a node object. + * + * @param BaseObject $from the actual context + * @param BaseObject $to the target object we want to link to + * @return string the link to the object + */ public function linkToObject( BaseObject $from, BaseObject $to ); } \ No newline at end of file diff --git a/modules/cms/generator/target/Dav.class.php b/modules/cms/generator/target/Dav.class.php @@ -1,113 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; -use util\Url; - - -/** - * Publishing a file over WebDAV. - * - * @author Jan Dankert - */ -class Dav extends BaseTarget -{ - /** - * @var false|resource - */ - //private $socket; - - public function checkConnection() - { - $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->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->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 ); - } - - - public function mkcol( $dir ) { - $content = "MKCOL $dir HTTP/1.1\r\n"; - $content .= "Host: ".$this->url->host."\r\n"; - $content .= "Connection: Close\r\n"; - $content .= "\r\n"; - fwrite($this->createSocket(), $content); - } - - public function close() - { - //fclose($this->socket); - } - - public function open() - { - $this->checkConnection(); - } - - /** - * @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"); - - return $socket; - - } -}- \ No newline at end of file diff --git a/modules/cms/generator/target/DavTarget.class.php b/modules/cms/generator/target/DavTarget.class.php @@ -0,0 +1,113 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; +use util\Url; + + +/** + * Publishing a file over WebDAV. + * + * @author Jan Dankert + */ +class DavTarget extends BaseTarget +{ + /** + * @var false|resource + */ + //private $socket; + + public function checkConnection() + { + $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->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->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 ); + } + + + public function mkcol( $dir ) { + $content = "MKCOL $dir HTTP/1.1\r\n"; + $content .= "Host: ".$this->url->host."\r\n"; + $content .= "Connection: Close\r\n"; + $content .= "\r\n"; + fwrite($this->createSocket(), $content); + } + + public function close() + { + //fclose($this->socket); + } + + public function open() + { + $this->checkConnection(); + } + + /** + * @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"); + + 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 @@ -1,51 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; - - -/** - * Publishing a file over fax. Who says that this is not possible? - * - * @author Jan Dankert - */ -class Fax extends BaseTarget -{ - public function open() - { - Logger::debug("Dialing ..."); - } - - public function put($source, $dest, $time) - { - // here must happen some magic - } - - public function close() - { - Logger::debug("Hanging up........................... NO CARRIER"); - } - - public function __construct($targetUrl) - { - } -} -// ok, this class was a joke.- \ No newline at end of file diff --git a/modules/cms/generator/target/FaxTarget.class.php b/modules/cms/generator/target/FaxTarget.class.php @@ -0,0 +1,51 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; + + +/** + * Publishing a file over fax. Who says that this is not possible? + * + * @author Jan Dankert + */ +class FaxTarget extends BaseTarget +{ + public function open() + { + Logger::debug("Dialing ..."); + } + + public function put($source, $dest, $time) + { + // here must happen some magic + } + + public function close() + { + Logger::debug("Hanging up........................... NO CARRIER"); + } + + public function __construct($targetUrl) + { + } +} +// ok, this class was a joke.+ \ No newline at end of file diff --git a/modules/cms/generator/target/Ftp.class.php b/modules/cms/generator/target/Ftp.class.php @@ -1,175 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use cms\base\Configuration; -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; - - -/** - * FTP-BaseTarget. - * - * @author Jan Dankert - */ -class Ftp extends BaseTarget -{ - private $connection; - - // Aufbauen der Verbindung - public function open() - { - //$conf = \cms\base\Configuration::rawConfig(); - //$conf_ftp = $conf['publish']['ftp']; - $ftp = $this->url; - - // Die projektspezifischen Werte gewinnen bei �berschneidungen mit den Default-Werten - //$ftp = array_merge($conf_ftp, $ftp); - - $this->connection = $this->createConnection(); - - if (!$this->connection) { - Logger::error('Cannot connect to ' . $this->url->host . ':' . $this->url->port); - throw new PublisherException('Cannot connect to ' . $this->url->scheme . '-server: ' . $this->url->host . ':' . $this->url->port); - } - - if (empty($this->url->user)) { - $ftp['user'] = 'anonymous'; - $ftp['pass'] = 'openrat@openrat.de'; - } - - if (!ftp_login($this->connection, $this->url->user, $this->url->pass)) - throw new PublisherException('Unable to login as user ' . $this->url->user); - - $pasv = $this->url->fragment == 'passive'; - - if ( $pasv ) - if (!ftp_pasv($this->connection, true)) - throw new PublisherException('Cannot switch to FTP PASV mode'); - - if ( $this->url->query ) { - parse_str($this->url->query, $ftp_var); - - if (isset($ftp_var['site'])) { - $site_commands = explode(',', $ftp_var['site']); - foreach ($site_commands as $cmd) { - if (!@ftp_site($this->connection, $cmd)) - throw new PublisherException('unable to do SITE command: ' . $cmd); - } - } - } - - $path = rtrim($this->url->path, '/'); - - if (!@ftp_chdir($this->connection, $path)) - throw new PublisherException('unable CHDIR to directory: ' . $path); - } - - - /** - * Kopieren einer Datei vom lokalen System auf den FTP-Server. - * - * @param String Quelle - * @param String Ziel - * @param int FTP-Mode (BINARY oder ASCII) - */ - public function put($source, $dest, $lastChangeDate) - { - $dest = $this->url->path . '/' . $dest; - - //$this->log .= "Copying file: $source -&gt; $dest ...\n"; - - $mode = FTP_BINARY; - $p = strrpos(basename($dest), '.'); // Letzten Punkt suchen - - if ($p !== false) // Wennn letzten Punkt gefunden, dann dort aufteilen - { - $extension = substr(basename($dest), $p + 1); - $type = Configuration::subset('mime-types')->get( $extension,'application/download'); - if (substr($type, 0, 5) == 'text/') - $mode = FTP_ASCII; - } - - Logger::debug("FTP PUT target:$dest mode:" . (($mode == FTP_ASCII) ? 'ascii' : 'binary')); - - if (!@ftp_put($this->connection, $dest, $source, $mode)) { - if (!$this->mkdirs(dirname($dest))) - return; // Fehler. - - ftp_chdir($this->connection, $this->url->path); - - if (!@ftp_put($this->connection, $dest, $source, $mode)) - throw new PublisherException("FTP PUT failed.\n" . - "source : $source\n" . - "destination: $dest"); - - } - } - - - /** - * Private Methode zum rekursiven Anlegen von Verzeichnissen. - * - * @param String Pfad - * @return boolean true, wenn ok - */ - private function mkdirs($strPath) - { - if (@ftp_chdir($this->connection, $strPath)) - return true; // Verzeichnis existiert schon :) - - $pStrPath = dirname($strPath); - - if (!$this->mkdirs($pStrPath)) - return false; - - if (!@ftp_mkdir($this->connection, $strPath)) - throw new PublisherException("failed to create remote directory: $strPath"); - - return true; - } - - - /** - * Schliessen der FTP-Verbindung.<br> - * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. - */ - public function close() - { - if (!@ftp_quit($this->connection)) { - // Closing not possible. - // Only logging. Maybe we could throw an Exception here? - Logger::warn('Failed to close FTP connection. Continueing...'); - return; - } - } - - protected function createConnection() - { - return ftp_connect($this->url->host, $this->url->port); - } - - public static function isAvailable() - { - return function_exists('ftp_connect'); - } -} - - -?>- \ No newline at end of file diff --git a/modules/cms/generator/target/FtpTarget.class.php b/modules/cms/generator/target/FtpTarget.class.php @@ -0,0 +1,175 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use cms\base\Configuration; +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; + + +/** + * FTP-BaseTarget. + * + * @author Jan Dankert + */ +class FtpTarget extends BaseTarget +{ + private $connection; + + // Aufbauen der Verbindung + public function open() + { + //$conf = \cms\base\Configuration::rawConfig(); + //$conf_ftp = $conf['publish']['ftp']; + $ftp = $this->url; + + // Die projektspezifischen Werte gewinnen bei �berschneidungen mit den Default-Werten + //$ftp = array_merge($conf_ftp, $ftp); + + $this->connection = $this->createConnection(); + + if (!$this->connection) { + Logger::error('Cannot connect to ' . $this->url->host . ':' . $this->url->port); + throw new PublisherException('Cannot connect to ' . $this->url->scheme . '-server: ' . $this->url->host . ':' . $this->url->port); + } + + if (empty($this->url->user)) { + $ftp['user'] = 'anonymous'; + $ftp['pass'] = 'openrat@openrat.de'; + } + + if (!ftp_login($this->connection, $this->url->user, $this->url->pass)) + throw new PublisherException('Unable to login as user ' . $this->url->user); + + $pasv = $this->url->fragment == 'passive'; + + if ( $pasv ) + if (!ftp_pasv($this->connection, true)) + throw new PublisherException('Cannot switch to FTP PASV mode'); + + if ( $this->url->query ) { + parse_str($this->url->query, $ftp_var); + + if (isset($ftp_var['site'])) { + $site_commands = explode(',', $ftp_var['site']); + foreach ($site_commands as $cmd) { + if (!@ftp_site($this->connection, $cmd)) + throw new PublisherException('unable to do SITE command: ' . $cmd); + } + } + } + + $path = rtrim($this->url->path, '/'); + + if (!@ftp_chdir($this->connection, $path)) + throw new PublisherException('unable CHDIR to directory: ' . $path); + } + + + /** + * Kopieren einer Datei vom lokalen System auf den FTP-Server. + * + * @param String Quelle + * @param String Ziel + * @param int FTP-Mode (BINARY oder ASCII) + */ + public function put($source, $dest, $lastChangeDate) + { + $dest = $this->url->path . '/' . $dest; + + //$this->log .= "Copying file: $source -&gt; $dest ...\n"; + + $mode = FTP_BINARY; + $p = strrpos(basename($dest), '.'); // Letzten Punkt suchen + + if ($p !== false) // Wennn letzten Punkt gefunden, dann dort aufteilen + { + $extension = substr(basename($dest), $p + 1); + $type = Configuration::subset('mime-types')->get( $extension,'application/download'); + if (substr($type, 0, 5) == 'text/') + $mode = FTP_ASCII; + } + + Logger::debug("FTP PUT target:$dest mode:" . (($mode == FTP_ASCII) ? 'ascii' : 'binary')); + + if (!@ftp_put($this->connection, $dest, $source, $mode)) { + if (!$this->mkdirs(dirname($dest))) + return; // Fehler. + + ftp_chdir($this->connection, $this->url->path); + + if (!@ftp_put($this->connection, $dest, $source, $mode)) + throw new PublisherException("FTP PUT failed.\n" . + "source : $source\n" . + "destination: $dest"); + + } + } + + + /** + * Private Methode zum rekursiven Anlegen von Verzeichnissen. + * + * @param String Pfad + * @return boolean true, wenn ok + */ + private function mkdirs($strPath) + { + if (@ftp_chdir($this->connection, $strPath)) + return true; // Verzeichnis existiert schon :) + + $pStrPath = dirname($strPath); + + if (!$this->mkdirs($pStrPath)) + return false; + + if (!@ftp_mkdir($this->connection, $strPath)) + throw new PublisherException("failed to create remote directory: $strPath"); + + return true; + } + + + /** + * Schliessen der FTP-Verbindung.<br> + * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. + */ + public function close() + { + if (!@ftp_quit($this->connection)) { + // Closing not possible. + // Only logging. Maybe we could throw an Exception here? + Logger::warn('Failed to close FTP connection. Continueing...'); + return; + } + } + + protected function createConnection() + { + return ftp_connect($this->url->host, $this->url->port); + } + + public static function isAvailable() + { + return function_exists('ftp_connect'); + } +} + + +?>+ \ No newline at end of file diff --git a/modules/cms/generator/target/Ftps.class.php b/modules/cms/generator/target/Ftps.class.php @@ -27,7 +27,7 @@ use util\exception\UIException; * * @author Jan Dankert */ -class Ftps extends Ftp +class FtpsTarget extends FtpTarget { /** * Creates a new connection. diff --git a/modules/cms/generator/target/Local.class.php b/modules/cms/generator/target/Local.class.php @@ -1,201 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use cms\base\Configuration; -use cms\base\Startup; -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; -use util\FileUtils; -use util\Url; - - -/** - * Publishing to the local filesystem. - * - * @author Jan Dankert - */ -class Local extends BaseTarget -{ - /** - * @var string - */ - private $localDestinationDirectory; - - /** - * @param $url Url - */ - public function open() - { - $fileSystemConfig = Configuration::subset(['publish','filesystem']); - - $targetDir = rtrim( $this->url->path,'/' ); - - if ( FileUtils::isAbsolutePath($targetDir) && $fileSystemConfig->is('per_project',true )) - { - $this->localDestinationDirectory = FileUtils::toAbsolutePath([$targetDir]); // Projekteinstellung verwenden. - } - else - { - // Konfiguriertes Verzeichnis verwenden. - $this->localDestinationDirectory = FileUtils::toAbsolutePath([$fileSystemConfig->get('directory','/var/www'),$targetDir]); - } - - - // Sofort pruefen, ob das Zielverzeichnis ueberhaupt beschreibbar ist. - if ( $this->localDestinationDirectory && $this->localDestinationDirectory[0] == '#') - $this->localDestinationDirectory = ''; - - } - - /** - * Copying a file to local filesystem. - * - * @param String Quelle - * @param String Ziel - */ - public function put($source, $dest, $lastChangeDate) - { - // Is the output directory writable? - if ( !is_writeable( $this->localDestinationDirectory ) ) - throw new PublisherException('directory not writable: ' . $this->localDestinationDirectory); - - $dest = $this->localDestinationDirectory.'/'.$dest; - - // Is the destination writable? - if ( is_file($dest) && !is_writeable( $dest ) ) - throw new PublisherException('file not writable: ' . $dest); - - // Copy file to destination - if (!@copy( $source,$dest )); - { - // Create directories, if necessary. - $this->mkdirs( dirname($dest) ); - - if (!@copy( $source,$dest )) - throw new PublisherException( 'failed copying local file:' . "\n" . - 'source : ' . $source . "\n" . - 'destination: ' . $dest); - - // Das Änderungsdatum der Datei auch in der Zieldatei setzen. - if ( Configuration::subset('publish')->is('set_modification_date',false ) ) - if ( ! is_null($lastChangeDate) ) - @touch( $dest,$lastChangeDate ); - - Logger::debug("published: $dest"); - } - - $chmod = Configuration::subset('security')->get('chmod',''); - - if ( $chmod ) - { - // CHMOD auf der Datei ausfuehren. - if ( ! @chmod($dest,octdec($chmod) ) ) - throw new PublisherException('Unable to CHMOD file ' . $dest); - } - - } - - - - /** - * Rekursives Anlagen von Verzeichnisse - * Nett gemacht. - * Quelle: http://de3.php.net/manual/de/function.mkdir.php - * Thx to acroyear at io dot com - * - * @param String Verzeichnis - * @return boolean - */ - private function mkdirs($path ) - { - if ( is_dir($path) ) - return; // Path exists - - $parentPath = dirname($path); - - $this->mkdirs($parentPath); - - // - if ( ! @mkdir($path) ) - throw new PublisherException( 'Cannot create directory: ' . $path); - - // CHMOD auf dem Verzeichnis ausgef�hren. - $chmod = Configuration::subset('security')->get('chmod_dir',''); - - if ( $chmod ) - { - if ( ! @chmod($path,octdec($chmod) ) ) - throw new PublisherException('Unable to CHMOD directory ' . $path); - } - } - - - - - - - /** - * Aufraeumen des Zielverzeichnisses.<br><br> - * Es wird der komplette Zielordner samt Unterverzeichnissen durchsucht. Jede - * Datei, die laenger existiert als der aktuelle Request alt ist, wird geloescht.<br> - * Natuerlich darf diese Funktion nur nach einem Gesamt-Veroeffentlichen ausgefuehrt werden. - */ - public function clean() - { - if ( !empty($this->localDestinationDirectory) ) - $this->cleanFolder($this->localDestinationDirectory); - } - - - - /** - * Aufr�umen eines Verzeichnisses.<br><br> - * Dateien, die l�nger existieren als der aktuelle Request alt ist, werden gel�scht.<br> - * - * @param String Verzeichnis - */ - private function cleanFolder( $folderName ) - { - $dh = opendir( $folderName ); - - while( $file = readdir($dh) ) - { - if ( $file != '.' && $file != '..') - { - $fullpath = $folderName.'/'.$file; - - // Wenn eine Datei beschreibbar und entsprechend alt - // ist, dann entfernen - if ( is_file($fullpath) && - is_writable($fullpath) && - filemtime($fullpath) < Startup::getStartTime() ) - unlink($fullpath); - - // Bei Ordnern rekursiv absteigen - if ( is_dir( $fullpath) ) - { - $this->cleanFolder($fullpath); - @rmdir($fullpath); - } - } - } - } - -}- \ No newline at end of file diff --git a/modules/cms/generator/target/LocalTarget.class.php b/modules/cms/generator/target/LocalTarget.class.php @@ -0,0 +1,201 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use cms\base\Configuration; +use cms\base\Startup; +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; +use util\FileUtils; +use util\Url; + + +/** + * Publishing to the local filesystem. + * + * @author Jan Dankert + */ +class LocalTarget extends BaseTarget +{ + /** + * @var string + */ + private $localDestinationDirectory; + + /** + * @param $url Url + */ + public function open() + { + $fileSystemConfig = Configuration::subset(['publish','filesystem']); + + $targetDir = rtrim( $this->url->path,'/' ); + + if ( FileUtils::isAbsolutePath($targetDir) && $fileSystemConfig->is('per_project',true )) + { + $this->localDestinationDirectory = FileUtils::toAbsolutePath([$targetDir]); // Projekteinstellung verwenden. + } + else + { + // Konfiguriertes Verzeichnis verwenden. + $this->localDestinationDirectory = FileUtils::toAbsolutePath([$fileSystemConfig->get('directory','/var/www'),$targetDir]); + } + + + // Sofort pruefen, ob das Zielverzeichnis ueberhaupt beschreibbar ist. + if ( $this->localDestinationDirectory && $this->localDestinationDirectory[0] == '#') + $this->localDestinationDirectory = ''; + + } + + /** + * Copying a file to local filesystem. + * + * @param String Quelle + * @param String Ziel + */ + public function put($source, $dest, $lastChangeDate) + { + // Is the output directory writable? + if ( !is_writeable( $this->localDestinationDirectory ) ) + throw new PublisherException('directory not writable: ' . $this->localDestinationDirectory); + + $dest = $this->localDestinationDirectory.'/'.$dest; + + // Is the destination writable? + if ( is_file($dest) && !is_writeable( $dest ) ) + throw new PublisherException('file not writable: ' . $dest); + + // Copy file to destination + if (!@copy( $source,$dest )); + { + // Create directories, if necessary. + $this->mkdirs( dirname($dest) ); + + if (!@copy( $source,$dest )) + throw new PublisherException( 'failed copying local file:' . "\n" . + 'source : ' . $source . "\n" . + 'destination: ' . $dest); + + // Das Änderungsdatum der Datei auch in der Zieldatei setzen. + if ( Configuration::subset('publish')->is('set_modification_date',false ) ) + if ( ! is_null($lastChangeDate) ) + @touch( $dest,$lastChangeDate ); + + Logger::debug("published: $dest"); + } + + $chmod = Configuration::subset('security')->get('chmod',''); + + if ( $chmod ) + { + // CHMOD auf der Datei ausfuehren. + if ( ! @chmod($dest,octdec($chmod) ) ) + throw new PublisherException('Unable to CHMOD file ' . $dest); + } + + } + + + + /** + * Rekursives Anlagen von Verzeichnisse + * Nett gemacht. + * Quelle: http://de3.php.net/manual/de/function.mkdir.php + * Thx to acroyear at io dot com + * + * @param String Verzeichnis + * @return boolean + */ + private function mkdirs($path ) + { + if ( is_dir($path) ) + return; // Path exists + + $parentPath = dirname($path); + + $this->mkdirs($parentPath); + + // + if ( ! @mkdir($path) ) + throw new PublisherException( 'Cannot create directory: ' . $path); + + // CHMOD auf dem Verzeichnis ausgef�hren. + $chmod = Configuration::subset('security')->get('chmod_dir',''); + + if ( $chmod ) + { + if ( ! @chmod($path,octdec($chmod) ) ) + throw new PublisherException('Unable to CHMOD directory ' . $path); + } + } + + + + + + + /** + * Aufraeumen des Zielverzeichnisses.<br><br> + * Es wird der komplette Zielordner samt Unterverzeichnissen durchsucht. Jede + * Datei, die laenger existiert als der aktuelle Request alt ist, wird geloescht.<br> + * Natuerlich darf diese Funktion nur nach einem Gesamt-Veroeffentlichen ausgefuehrt werden. + */ + public function clean() + { + if ( !empty($this->localDestinationDirectory) ) + $this->cleanFolder($this->localDestinationDirectory); + } + + + + /** + * Aufr�umen eines Verzeichnisses.<br><br> + * Dateien, die l�nger existieren als der aktuelle Request alt ist, werden gel�scht.<br> + * + * @param String Verzeichnis + */ + private function cleanFolder( $folderName ) + { + $dh = opendir( $folderName ); + + while( $file = readdir($dh) ) + { + if ( $file != '.' && $file != '..') + { + $fullpath = $folderName.'/'.$file; + + // Wenn eine Datei beschreibbar und entsprechend alt + // ist, dann entfernen + if ( is_file($fullpath) && + is_writable($fullpath) && + filemtime($fullpath) < Startup::getStartTime() ) + unlink($fullpath); + + // Bei Ordnern rekursiv absteigen + if ( is_dir( $fullpath) ) + { + $this->cleanFolder($fullpath); + @rmdir($fullpath); + } + } + } + } + +}+ \ No newline at end of file diff --git a/modules/cms/generator/target/SFtp.class.php b/modules/cms/generator/target/SFtp.class.php @@ -1,102 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; - - -/** - * Darstellen einer FTP-Verbindung, das beinhaltet - * das Login, das Kopieren von Dateien sowie praktische - * FTP-Funktionen - * - * @author $Author$ - * @version $Revision$ - * @package openrat.services - */ -class SFtp extends Scp -{ - /** - * @var resource - */ - protected $sftpConnection; - - - // Aufbauen der Verbindung - public function open() - { - $this->createConnection(); - - $this->sftpConnection = @ssh2_sftp($this->sshConnection); - - if (! $this->sftpConnection) - throw new PublisherException("Could not initialize SFTP subsystem."); - - } - - - /** - * Kopieren einer Datei vom lokalen System auf den SFTP-Server. - * - * @param String Quelle - * @param String Ziel - * @param int time) - */ - public function put($source, $dest, $lastChangeDate) - { - $dest = $this->url->path . '/' . $dest; - - $sftp = $this->sftpConnection; - - ssh2_sftp_mkdir ( $sftp, dirname($dest),0755, true); - - $stream = @fopen("ssh2.sftp://$sftp$dest", 'w'); - - if (! $stream) - throw new PublisherException("Could not create SFTP-Stream on file: $dest"); - - $data_to_send = @file_get_contents($source); - - if ($data_to_send === false) - throw new PublisherException("Could not open local file: $source"); - - if (@fwrite($stream, $data_to_send) === false) - throw new PublisherException("Could not send data from file: $source."); - - @fclose($stream); - } - - - /** - * Schliessen der FTP-Verbindung.<br> - * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. - */ - public function close() - { - parent::close(); - } - - - public static function isAvailable() - { - return parent::isAvailable() && function_exists('ssh2_sftp'); - } -} - diff --git a/modules/cms/generator/target/SFtpTarget.class.php b/modules/cms/generator/target/SFtpTarget.class.php @@ -0,0 +1,96 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; + + +/** + * A Secure-FTP (*not* FTPS!) target. + */ +class SFtpTarget extends ScpTarget +{ + /** + * @var resource + */ + protected $sftpConnection; + + + // Aufbauen der Verbindung + public function open() + { + $this->createConnection(); + + $this->sftpConnection = @ssh2_sftp($this->sshConnection); + + if (! $this->sftpConnection) + throw new PublisherException("Could not initialize SFTP subsystem."); + + } + + + /** + * Kopieren einer Datei vom lokalen System auf den SFTP-Server. + * + * @param String Quelle + * @param String Ziel + * @param int time) + */ + public function put($source, $dest, $lastChangeDate) + { + $dest = $this->url->path . '/' . $dest; + + $sftp = $this->sftpConnection; + + ssh2_sftp_mkdir ( $sftp, dirname($dest),0755, true); + + $stream = @fopen("ssh2.sftp://$sftp$dest", 'w'); + + if (! $stream) + throw new PublisherException("Could not create SFTP-Stream on file: $dest"); + + $data_to_send = @file_get_contents($source); + + if ($data_to_send === false) + throw new PublisherException("Could not open local file: $source"); + + if (@fwrite($stream, $data_to_send) === false) + throw new PublisherException("Could not send data from file: $source."); + + @fclose($stream); + } + + + /** + * Schliessen der FTP-Verbindung.<br> + * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. + */ + public function close() + { + parent::close(); + } + + + public static function isAvailable() + { + return parent::isAvailable() && function_exists('ssh2_sftp'); + } +} + diff --git a/modules/cms/generator/target/Scp.class.php b/modules/cms/generator/target/Scp.class.php @@ -1,113 +0,0 @@ -<?php -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -namespace cms\generator\target; - -use logger\Logger; -use util\exception\PublisherException; -use util\exception\UIException; - - -/** - * Darstellen einer FTP-Verbindung, das beinhaltet - * das Login, das Kopieren von Dateien sowie praktische - * FTP-Funktionen - * - * @author $Author$ - * @version $Revision$ - * @package openrat.services - */ -class Scp extends BaseTarget -{ - /** - * @var resource - */ - protected $sshConnection; - - // Aufbauen der Verbindung - public function open() - { - $this->sshConnection = $this->createConnection(); - } - - - - protected function createConnection() { - - if ( empty($this->url->port) ) - $this->url->port = 22; // Default-SSH-port - - $sshConnection = @ssh2_connect($this->url->host,$this->url->port ); - - if (! $sshConnection) - throw new PublisherException("Could not connect to ".$this->url->host.':'.$this->url->port ); - - - if (! @ssh2_auth_password($sshConnection, $this->url->user,$this->url->pass) ) - throw new PublisherException("Could not authenticate with user ".$this->url->user); - - $this->sshConnection = $sshConnection; - - return $sshConnection; - } - - - - /** - * Kopieren einer Datei vom lokalen System auf den FTP-Server. - * - * @param String Quelle - * @param String Ziel - * @param int FTP-Mode (BINARY oder ASCII) - */ - public function put($source, $dest, $lastChangeDate) - { - $dest = $this->url->path . '/' . $dest; - - // 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 ); - } - } - - - /** - * Schliessen der FTP-Verbindung.<br> - * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. - */ - public function close() - { - ssh2_disconnect($this->sshConnection); - } - - - public static function isAvailable() - { - return function_exists('ssh2_connect'); - } -} - - -?>- \ No newline at end of file diff --git a/modules/cms/generator/target/ScpTarget.class.php b/modules/cms/generator/target/ScpTarget.class.php @@ -0,0 +1,113 @@ +<?php +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +namespace cms\generator\target; + +use logger\Logger; +use util\exception\PublisherException; +use util\exception\UIException; + + +/** + * Darstellen einer FTP-Verbindung, das beinhaltet + * das Login, das Kopieren von Dateien sowie praktische + * FTP-Funktionen + * + * @author $Author$ + * @version $Revision$ + * @package openrat.services + */ +class ScpTarget extends BaseTarget +{ + /** + * @var resource + */ + protected $sshConnection; + + // Aufbauen der Verbindung + public function open() + { + $this->sshConnection = $this->createConnection(); + } + + + + protected function createConnection() { + + if ( empty($this->url->port) ) + $this->url->port = 22; // Default-SSH-port + + $sshConnection = @ssh2_connect($this->url->host,$this->url->port ); + + if (! $sshConnection) + throw new PublisherException("Could not connect to ".$this->url->host.':'.$this->url->port ); + + + if (! @ssh2_auth_password($sshConnection, $this->url->user,$this->url->pass) ) + throw new PublisherException("Could not authenticate with user ".$this->url->user); + + $this->sshConnection = $sshConnection; + + return $sshConnection; + } + + + + /** + * Kopieren einer Datei vom lokalen System auf den FTP-Server. + * + * @param String Quelle + * @param String Ziel + * @param int FTP-Mode (BINARY oder ASCII) + */ + public function put($source, $dest, $lastChangeDate) + { + $dest = $this->url->path . '/' . $dest; + + // 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 ); + } + } + + + /** + * Schliessen der FTP-Verbindung.<br> + * Sollte unbedingt aufgerufen werden, damit keine unn�tigen Sockets aufbleiben. + */ + public function close() + { + ssh2_disconnect($this->sshConnection); + } + + + public static function isAvailable() + { + return function_exists('ssh2_connect'); + } +} + + +?>+ \ No newline at end of file diff --git a/modules/cms/generator/target/Target.class.php b/modules/cms/generator/target/Target.class.php @@ -6,15 +6,32 @@ namespace cms\generator\target; use util\Url; +/** + * A target is a target for publishing files. A target is the bridge to a place where files are being copied to. + */ interface Target { + /** + * Creating the target. + * + * @param $targetUrl string target URL + */ public function __construct( $targetUrl ); + /** + * Open the connection to the target. + */ public function open(); + /** + * Pushing a file to the target. + * @param $source string local filename + * @param $dest string remote filename + * @param $timestamp int timestamp of source file + */ public function put($source, $dest, $timestamp); @@ -24,6 +41,11 @@ interface Target public function close(); + /** + * Is this target available? + * + * @return boolean + */ public static function isAvailable(); } \ No newline at end of file diff --git a/modules/cms/generator/target/TargetFactory.class.php b/modules/cms/generator/target/TargetFactory.class.php @@ -29,27 +29,27 @@ class TargetFactory case '': case 'file': case 'local': - $target = new Local($url); + $target = new LocalTarget($url); break; case 'dav': - $target = new Dav($url); + $target = new DavTarget($url); break; case 'ftp': - $target = new Ftp($url); + $target = new FtpTarget($url); break; case 'ftps': - $target = new Ftps($url); + $target = new FtpsTarget($url); break; case 'scp': - $target = new Scp($url); + $target = new ScpTarget($url); break; case 'sftp': - $target = new SFtp($url); + $target = new SFtpTarget($url); break; default: