From 9e1e832ac7fb3f4e327ba06a5582837a93e13c6e Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Tue, 22 May 2018 13:37:09 +0200 Subject: [PATCH 1/3] FEATURE: Add support for generic ssh options Support `sshOptions` that are added to the ssh- and rsync commands useed by the clone command-controller. This is especially helpful to configure ssh proxy settings. ``` Sitegeist: MagicWand: clonePresets: example: sshOptions: '-o "ProxyCommand=..." ' ``` --- .../Command/CloneCommandController.php | 26 +++++++++++++------ Configuration/Settings.yaml | 2 ++ README.md | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php index c7a17b0..28753c2 100644 --- a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php +++ b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php @@ -78,6 +78,9 @@ public function presetCommand($presetName, $yes = false, $keepDb = false) $keepDb, (isset($this->clonePresets[$presetName]['flowCommand']) ? $this->clonePresets[$presetName]['flowCommand'] : null + ), + (isset($this->clonePresets[$presetName]['sshOptions']) ? + $this->clonePresets[$presetName]['sshOptions'] : '' ) ); } else { @@ -102,6 +105,7 @@ public function presetCommand($presetName, $yes = false, $keepDb = false) * @param boolean $yes confirm execution without further input * @param boolean $keepDb skip dropping of database during sync * @param string $remoteFlowCommand the flow command to execute on the remote system + * @param string $sshOptions additional options for the ssh command */ public function remoteHostCommand( $host, @@ -112,7 +116,8 @@ public function remoteHostCommand( $postClone = null, $yes = false, $keepDb = false, - $remoteFlowCommand = null + $remoteFlowCommand = null, + $sshOptions = '' ) { // fallback if ($remoteFlowCommand === null) { @@ -127,11 +132,12 @@ public function remoteHostCommand( // read remote configuration $this->outputHeadLine('Fetch remote configuration'); $remotePersistenceConfigurationYaml = $this->executeLocalShellCommand( - 'ssh -p %s %s@%s "cd %s; FLOW_CONTEXT=%s ' + 'ssh -p %s %s %s@%s "cd %s; FLOW_CONTEXT=%s ' . $remoteFlowCommand . ' configuration:show --type Settings --path Neos.Flow.persistence.backendOptions;"', [ $port, + $sshOptions, $user, $host, $path, @@ -189,7 +195,7 @@ public function remoteHostCommand( # Fallback to default MySQL port if not given. # ################################################ - if ( ! isset($remotePersistenceConfiguration['port'])) { + if (!isset($remotePersistenceConfiguration['port'])) { $remotePersistenceConfiguration['port'] = 3306; } @@ -230,9 +236,10 @@ public function remoteHostCommand( $this->outputHeadLine('Transfer Database'); $this->executeLocalShellCommand( - 'ssh -p %s %s@%s \'mysqldump --add-drop-table --host=\'"\'"\'%s\'"\'"\' --port=\'"\'"\'%d\'"\'"\' --user=\'"\'"\'%s\'"\'"\' --password=\'"\'"\'%s\'"\'"\' \'"\'"\'%s\'"\'"\'\' | mysql --host=\'%s\' --port=\'%s\' --user=\'%s\' --password=\'%s\' \'%s\'', + 'ssh -p %s %s %s@%s \'mysqldump --add-drop-table --host=\'"\'"\'%s\'"\'"\' --port=\'"\'"\'%d\'"\'"\' --user=\'"\'"\'%s\'"\'"\' --password=\'"\'"\'%s\'"\'"\' \'"\'"\'%s\'"\'"\'\' | mysql --host=\'%s\' --port=\'%s\' --user=\'%s\' --password=\'%s\' \'%s\'', [ $port, + $sshOptions, $user, $host, $remotePersistenceConfiguration['host'], @@ -254,9 +261,10 @@ public function remoteHostCommand( $this->outputHeadLine('Transfer Files'); $this->executeLocalShellCommand( - 'rsync -e "ssh -p %s" -kLr %s@%s:%s/* %s', + 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, + $sshOptions, $user, $host, $remoteDataPersistentPath, @@ -276,20 +284,22 @@ public function remoteHostCommand( // If the translation directory is available print true - because we didn't get the return value here $translationsAvailable = trim( $this->executeLocalShellCommand( - 'ssh %s@%s -p %s "[ -d %s ] && echo true"', + 'ssh -p %s %s %s@%s "[ -d %s ] && echo true"', [ + $port, + $sshOptions, $user, $host, - $port, $remoteDataTranslationsPath] ) ); if ($translationsAvailable === 'true') { $this->executeLocalShellCommand( - 'rsync -e "ssh -p %s" -kLr %s@%s:%s/* %s', + 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, + $sshOptions, $user, $host, $remoteDataTranslationsPath, diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 38d9b6c..bc89722 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -11,6 +11,8 @@ Sitegeist: # user: ~ # # ssh port # port: ~ +# # ssh options +# sshOptions: ~ # # path on the remote server # path: ~ # # flow-context on the remote server diff --git a/README.md b/README.md index 1fe4302..c252413 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Sitegeist: # user: ~ # # ssh port # port: ~ +# # ssh options +# sshOptions: ~ # # path on the remote server # path: ~ # # flow-context on the remote server From a488f43854c948b48e386dcdee842f0f2a049ea2 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Tue, 29 May 2018 11:26:50 +0200 Subject: [PATCH 2/3] TASK: Escape sshOptions for rsync command --- .../Sitegeist/MagicWand/Command/CloneCommandController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php index 28753c2..d404355 100644 --- a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php +++ b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php @@ -264,7 +264,7 @@ public function remoteHostCommand( 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, - $sshOptions, + str_replace('"', "'", $sshOptions), $user, $host, $remoteDataPersistentPath, @@ -299,7 +299,7 @@ public function remoteHostCommand( 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, - $sshOptions, + escapeshellarg($sshOptions), $user, $host, $remoteDataTranslationsPath, From 7d5f12b5709424f4549314bb18f35559fceb1203 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Tue, 29 May 2018 11:36:34 +0200 Subject: [PATCH 3/3] TASK: Add slashes to the ssh options that are passed to the rsync command --- .../Sitegeist/MagicWand/Command/CloneCommandController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php index d404355..d76cf6d 100644 --- a/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php +++ b/Classes/Sitegeist/MagicWand/Command/CloneCommandController.php @@ -264,7 +264,7 @@ public function remoteHostCommand( 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, - str_replace('"', "'", $sshOptions), + addslashes($sshOptions), $user, $host, $remoteDataPersistentPath, @@ -299,7 +299,7 @@ public function remoteHostCommand( 'rsync -e "ssh -p %s %s" -kLr %s@%s:%s/* %s', [ $port, - escapeshellarg($sshOptions), + addslashes($sshOptions), $user, $host, $remoteDataTranslationsPath,