From 9e7ea8fe74f1b3344554b2cdc61c14aa0bcb403a Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Wed, 18 Mar 2015 17:58:14 +0100 Subject: [PATCH] Add proxy support to SyncTool --- app/Config/config.default.php | 8 +++++++ app/Lib/Tools/SyncTool.php | 9 ++++++++ app/Model/Server.php | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/app/Config/config.default.php b/app/Config/config.default.php index c9f6a61f9..ddbf162cc 100644 --- a/app/Config/config.default.php +++ b/app/Config/config.default.php @@ -34,6 +34,14 @@ $config = array ( 'homedir' => '', 'password' => '', ), + 'Proxy' => + array ( + 'host' => '', + 'port' => '', + 'method' => '', + 'user' => '', + 'password' => '', + ), 'SecureAuth' => array ( 'amount' => 5, diff --git a/app/Lib/Tools/SyncTool.php b/app/Lib/Tools/SyncTool.php index d41ad1938..e0528713e 100644 --- a/app/Lib/Tools/SyncTool.php +++ b/app/Lib/Tools/SyncTool.php @@ -8,6 +8,15 @@ class SyncTool { if ($server['Server']['cert_file']) $params['ssl_cafile'] = APP . "files" . DS . "certs" . DS . $server['Server']['id'] . '.pem'; if ($server['Server']['self_signed']) $params['ssl_allow_self_signed'] = $server['Server']['self_signed']; $HttpSocket = new HttpSocket($params); + + $proxy = Configure::read('Proxy'); + if(!empty($proxy['host']) && !empty($proxy['port'])) { + if(!empty($proxy['method']) && !empty($proxy['user']) && !empty($proxy['password'])) { + $HttpSocket->configProxy($proxy['host'], $proxy['port']); + } else { + $HttpSocket->configProxy($proxy['host'], $proxy['port'], $proxy['method'], $proxy['user'], $proxy['password']); + } + } return $HttpSocket; } } diff --git a/app/Model/Server.php b/app/Model/Server.php index 83c5fd9ea..99a3d57ac 100755 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -417,6 +417,49 @@ class Server extends AppModel { 'type' => 'string', ), ), + 'Proxy' => array( + 'branch' => 1, + 'host' => array( + 'level' => 2, + 'description' => 'The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForEmpty', + 'type' => 'string', + ), + 'port' => array( + 'level' => 2, + 'description' => 'The TCP port for the HTTP proxy.', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForNumeric', + 'type' => 'numeric', + ), + 'method' => array( + 'level' => 2, + 'description' => 'The authentication method for the HTTP proxy. Currently supported are Basic or Digest. Leave empty for no proxy authentication.', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForEmpty', + 'type' => 'string', + ), + 'user' => array( + 'level' => 2, + 'description' => 'The authentication username for the HTTP proxy.', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForEmpty', + 'type' => 'string', + ), + 'password' => array( + 'level' => 2, + 'description' => 'The authentication password for the HTTP proxy.', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForEmpty', + 'type' => 'string', + ), + ), 'Security' => array( 'branch' => 1, 'salt' => array(