UpdateSslOffload.php
UpdateSslOffload.php
<?php
require_once __DIR__.'/vendor/autoload.php';
$username = "set me";
$apiKey = "set me";
$vipAddress = "50.23.117.130";
$certificate = "www.testssl.com";
$enable = true;
$secureTransportProtocols = array("SSLV3", "TLSV12");
$secureTransportCiphers = array("EXP-RC4-MD5", "RC4-SHA");
$accountService = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
$balancerService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress', null, $username, $apiKey);
$groupService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Routing_Type', null, $username, $apiKey);
$methodService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Routing_Method', null, $username, $apiKey);
$filter = new stdClass();
$filter -> adcLoadBalancers = new stdClass();
$filter -> adcLoadBalancers -> ipAddress = new stdClass();
$filter -> adcLoadBalancers -> ipAddress -> ipAddress = new stdClass();
$filter -> adcLoadBalancers -> ipAddress -> ipAddress -> operation = $vipAddress;
$filterSsl = new stdClass();
$filterSsl -> securityCertificates = new stdClass();
$filterSsl -> securityCertificates -> commonName = new stdClass();
$filterSsl -> securityCertificates -> commonName -> operation = $certificate;
$templateObject = new stdClass();
try {
$certificateFlag = false;
if($certificate == "No Certificate")
{
$templateObject -> securityCertificateId = null;
}
else{
$accountService -> setObjectFilter($filterSsl);
$securityCertificates = $accountService -> getSecurityCertificates();
if(sizeof($securityCertificates)>0)
{
foreach($securityCertificates as $ssl)
{
if($ssl -> validityDays > 0)
{
$templateObject -> securityCertificateId = $ssl -> id;
$certificateFlag = true;
}
}
if($enable)
{
$protocols = array();
if(sizeof($secureTransportProtocols)>0 && sizeof($secureTransportCiphers) >0)
{
foreach($secureTransportProtocols as $protocol)
{
$protocols[] = array("keyName"=> $protocol);
}
$templateObject -> secureTransportProtocols = $protocols;
$ciphers = array();
foreach($secureTransportCiphers as $cipher)
{
$ciphers[] = array("keyName" => $cipher);
}
$templateObject -> secureTransportCiphers = $ciphers;
}
else{
echo "You must define at least one item in 'Secure Transport Protocol' (\$secureTransportProtocols) and 'Secure Transport Ciphers' (\$secureTransportCiphers)";
return;
}
}
}else{
echo $certificate . " certificate doesn't exists.";
return;
}
}
$accountService -> setObjectFilter($filter);
$loadBalancers = $accountService -> getAdcLoadBalancers();
$balancerService -> setInitParameter($loadBalancers[0] -> id);
$result = $balancerService -> editObject($templateObject);
print_r("Has been updated the 'SSL Offload' from " . $vipAddress . " Load Balancer?: " . $result);
if($certificateFlag == true)
{
if($enable)
{
$bool = $balancerService -> startSsl();
}
else
{
$bool = $balancerService -> stopSsl();
}
}
} catch(Exception $e) {
echo "Unable to update Ssl Offload: " . $e -> getMessage();
}