Announcement

Collapse
No announcement yet.

[PATCH] Add (simple) support for authenticated proxy

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [PATCH] Add (simple) support for authenticated proxy

    Hello,

    I wanted to try PTS for benchmarking some servers in our organization. But the proxy requires authentication and PTS doesn't support it...
    I tried with the http_proxy option but PTS doesn't support the "http://userasswd@proxyort"/ syntax.

    So, I added it into the PTS code and I want to share it if someone need this functionality.

    Basically, my patch add ProxyUser and ProxyPassword tag in the user_config.xml file. I have also added the ProxyEncrypted tag which combine the two other tags in the form "userassword" with a base64 encoding. I know this is not really encrypted but it's just a begining and better that just the user/password directly in the config file.

    I'm not an expert in PHP, this is the first code I do, so there may be a lot of mistake :-)

    Lo?c

    Code:
    pts-add-authenticated-proxy.patch:
    diff -urN /users/phoronix-test-suite.old/pts-core/objects/client/pts_config.php /users/phoronix-test-suite/pts-core/objects/client/pts_config.php
    --- /users/phoronix-test-suite.old/pts-core/objects/client/pts_config.php	2014-12-15 17:44:26.000000000 +0100
    +++ /users/phoronix-test-suite/pts-core/objects/client/pts_config.php	2015-02-05 14:37:47.000000000 +0100
    @@ -141,6 +141,9 @@
     		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/Timeout', $read_config);
     		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/ProxyAddress', $read_config);
     		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/ProxyPort', $read_config);
    +		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/ProxyUser', $read_config);
    +		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/ProxyPassword', $read_config);
    +		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Networking/ProxyEncrypted', $read_config);
     
     		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Server/RemoteAccessPort', $read_config);
     		$config->addXmlNodeFromReader('PhoronixTestSuite/Options/Server/Password', $read_config);
    diff -urN /users/phoronix-test-suite/pts-core/objects/pts_network.php /users/phoronix-test-suite/pts-core/objects/pts_network.php
    --- /users/phoronix-test-suite.old/pts-core/objects/pts_network.php	2014-12-15 18:05:54.000000000 +0100
    +++ /users/phoronix-test-suite/pts-core/objects/pts_network.php	2015-02-05 15:43:36.000000000 +0100
    @@ -150,6 +150,19 @@
     		if(self::$network_proxy)
     		{
     			curl_setopt($cr, CURLOPT_PROXY, self::$network_proxy['proxy']);
    +
    +			if(self::$network_proxy['userpwd'] != false || self::$network_proxy['encrypted'] != false)
    +			{
    +				if(self::$network_proxy['encrypted'] != false)
    +				{
    +					$auth = base64_decode(self::$network_proxy['encrypted']);
    +				}
    +				else
    +				{
    +					$auth = self::$network_proxy['userpwd'];
    +				}
    +				curl_setopt($cr, CURLOPT_PROXYUSERPWD, $auth);
    +			}
     		}
     
     		curl_exec($cr);
    @@ -190,6 +203,9 @@
     	}
     	public static function stream_context_create($parameters = null, $proxy_address = false, $proxy_port = false, $http_timeout = -1)
     	{
    +		$proxy_userpwd = false;
    +		$proxy_encrypted = false;
    +
     		if(!is_array($parameters))
     		{
     			$parameters = array();
    @@ -199,6 +215,8 @@
     		{
     			$proxy_address = self::$network_proxy['address'];
     			$proxy_port = self::$network_proxy['port'];
    +			$proxy_userpwd = self::$network_proxy['userpwd'];
    +			$proxy_encrypted = self::$network_proxy['encrypted'];
     		}
     
     		if($proxy_address != false && $proxy_port != false && is_numeric($proxy_port))
    @@ -217,7 +235,23 @@
     		}
     
     		$parameters['http']['user_agent'] = pts_codename(true);
    -		$parameters['http']['header'] = "Content-Type: application/x-www-form-urlencoded\r\n";
    +
    +		if($proxy_userpwd != false || $proxy_encrypted != false)
    +		{
    +			if($proxy_encrypted != false)
    +			{
    +				$auth = $proxy_encrypted;
    +			}
    +			else
    +			{
    +				$auth = base64_encode($proxy_userpwd);
    +			}
    +			$parameters['http']['header'] = array("Proxy-Authorization: Basic $auth", "Authorization: Basic $auth", "Content-Type: application/x-www-form-urlencoded\r\n");
    +		}
    +		else
    +		{
    +			$parameters['http']['header'] = "Content-Type: application/x-www-form-urlencoded\r\n";
    +		}
     
     		$stream_context = stream_context_create($parameters);
     
    @@ -268,9 +302,15 @@
     	{
     		if(($proxy_address = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyAddress', false)) && ($proxy_port = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPort', false)))
     		{
    +			$proxy_user = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyUser', false);
    +			$proxy_pwd = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPassword', false);
    +			$proxy_encrypted = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyEncrypted', false);
    +
     			self::$network_proxy['proxy'] = $proxy_address . ':' . $proxy_port;
     			self::$network_proxy['address'] = $proxy_address;
     			self::$network_proxy['port'] = $proxy_port;
    +			self::$network_proxy['userpwd'] = $proxy_user . ':' . $proxy_pwd;
    +			self::$network_proxy['encrypted'] = $proxy_encrypted;
     		}
     		else if(($env_proxy = getenv('http_proxy')) != false && count($env_proxy = pts_strings::colon_explode($env_proxy)) == 2)
     		{

  • #2
    Hi!

    I just saw that PTS now supports (since PTS 7.0.1) user/password in proxy configurations, great!

    Comment

    Working...
    X