2

Can somebody please provide PHP examples for ordering the following security products using SoftLayer API:

  1. SSL certificate

  2. Hardware Firewall ( to devices and to VLANS)

  3. FortiGate Seucirty Applicace ( to VLANs)

  4. Security Software

  5. To order Security Software on device, the customer portal checks if there's any eligible device. What kind of devices are eligible for Security Software ? What SoftLayer API I can use to find those eligible devices ?

Thank you.

mnnmountain
  • 143
  • 1
  • 9

2 Answers2

2

I hope these php scripts can help you:

Order SSL Certificates

 <?php
/**
 * Order SSL certificate
 *
 * This script orders a SSL Certificate
 *
 * Important manual pages:
 * @see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
 * @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
 * @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Security_Certificate
 *
 * @license <http://sldn.softlayer.com/wiki/index.php/license>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/XmlrpcClient.class.php";

/**
 * Your SoftLayer API username
 * @var string
 */
$username = "set me";

/**
 * Your SoftLayer API key
 * Generate one at: https://control.softlayer.com/account/users
 * @var string
 */
$apiKey = "set me";

// Create a SoftLayer API client object for "SoftLayer_Product_Order" services
$productService = Softlayer_XmlrpcClient::getClient("SoftLayer_Product_Order", null, $username, $apiKey);

/**
 * Define SSL Certificates Properties
 * @var int $quantity
 * @var int $packageId
 * @var int $serverCount
 * @var int $validityMonths
 * @var string $orderApproverEmailAddress
 * @var string $serverType
 */
$quantity = 1;
$packageId = 210;
$serverCount = 1;
$validityMonths = 24;
$serverType = "apache2";
$orderApproverEmailAddress = "admin@rubtest.com";

/**
 * Build a skeleton SoftLayer_Container_Product_Order_Attribute_Contact object for administrativeContact, 
 * billingContact, technicalContact and organizationInformation properties. You can use the same information 
 * for all of these properties, or you can create this object for each one.
 * @var string addressLine1
 * @var string city
 * @var string countryCode
 * @var string postalCode
 * @var string state
 * @var string email
 * @var string firstName
 * @var string lastName
 * @var string organizationName
 * @var string phoneNumber
 * @var string title
 */
$addressInfo  = new stdClass();
$addressInfo -> address = new stdClass();
$addressInfo -> address -> addressLine1 = "Simon Lopez Av.";
$addressInfo -> address -> city = "Cochabamba";
$addressInfo -> address -> countryCode = "BO";
$addressInfo -> address -> postalCode = "0591";
$addressInfo -> address -> state = "OT";
$addressInfo -> emailAddress = "noreply@softlayer.com";
$addressInfo -> firstName = "Ruber";
$addressInfo -> lastName = "Cuellar";
$addressInfo -> organizationName = "TestCompany";
$addressInfo -> phoneNumber = "7036659886";
$addressInfo -> title = "TitleTest";

/**
 * Define a collection of SoftLayer_Product_Item_Price objects. You can verify the item available for a given package using
 * SoftLayer_Product_Package::getItemPrices method
 * @see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
 */
$price = new stdClass();
$price->id = 1836;

/**
 * Declare the CSR
 * @var string
 */
$certificateSigningRequest = "-----BEGIN CERTIFICATE REQUEST-----
MIIC8TCCAdkCAQAwgasxCzAJBgNVBAYTAkNaMR8wHQYDVQQIExZDemVjaCBSZXB1
YmxpYywgRXVyb3BlMRQwEgYDVQQHEwtQcmFndWUgQ2l0eTEWMBQGA1UEChMNTXkg
VW5saW1pbnRlZDEMMAoGA1UECxMDVlBOMRQwEgYDVQQDEwtydWJ0ZXN0LmNvbTEp
MCcGCSqGSIb3DQEJARYacnViZXIuY3VlbGxhckBqYWxhc29mdC5jb20wggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDnusRc9LDjfm21A/fz1UhuMoUqkeji
BX/oTXsD/GmRaraOb0QnzjGoaM2K07nMENpQiJRpmEj3tEKwAXNitlapLwlXFvB7
rVd9lkvGmCIEkkDp5nbsdejS7BqJ8ikgEI+HATmdoyi9jxWrM/i6c9pnhF4j9ejI
XQnxd3yvpuxgybF3tN+HOOpXwVH4FQC7x/FRRai8jNxd2f+VzW7EgtIYxgl3L8gr
4DPPAAiX07lEAccEEUhQ3/LbTlSPiT0hiGh8tMcImYFDDyGOIRJKXSptuvYgwHRC
67D6fzT4ITtG2XMkzo5kgyZtwemRiikAzVbmtEFKwht0j0Q+3nf1Yv2BAgMBAAGg
ADANBgkqhkiG9w0BAQUFAAOCAQEAJCRjsdmVhcM+mKbG8NE4YdDyBfKvC03g/mCn
wWZWca1uRbYeJUNH2/LFy9tQ/8J07Cx0KcPmRnHbXkZaSMHsorv4sg6M3XDRaIiu
D/ltOZYlGYC1zFVM+pgiQd84krO0lTf/NiJxyyL3e3owO91h07jPuGGFygSOeKZa
cMMNdLQlPfZIS+hwZUuJSgormGhr+dfPkHbjP3l3X+uO59VNE+1zHTctCqooyCRa
HrHFjNbVD4Ou7Ff6B0LUiw9I54jH69MrtxdrsF+kvOaa44fN1NjqlM1sI4ZQs0O1
15B5NKrFMxG+5BrZYL7n8qEzra7WYFVrebjKexQqSBi4B6XU+g==
-----END CERTIFICATE REQUEST-----";

/*
 * Build a skeleton SoftLayer_Container_Product_Order object with details required to order
 */
$container = new stdClass();
$container -> complexType = "SoftLayer_Container_Product_Order_Security_Certificate";
$container -> packageId = $packageId;
$container -> quantity = $quantity;
$container -> serverCount = $serverCount;
$container -> serverType = $serverType;
$container -> prices = array($price);
$container -> certificateSigningRequest = $certificateSigningRequest;
$container -> validityMonths = $validityMonths;
$container -> orderApproverEmailAddress = $orderApproverEmailAddress;
// technicalContact, administrativeContact, organizationInformation and billingContact
$container -> technicalContact = $addressInfo;
$container -> administrativeContact = $addressInfo;
$container -> organizationInformation = $addressInfo;
$container -> billingContact = $addressInfo;
$order = new stdClass();
$order->orderContainers = array();
$order->orderContainers[0] = $container;

try {
    /*
     * SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
     * to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
     * records.
     */
     $result = $productService -> verifyOrder($order);
     print_r($result);
} catch(Exception $e) {
    echo "Unable to order SSL Certificates: " . $e -> getMessage();
}

Order Firewall Device

<?php
/**
 * Order dedicated Firewall for a Device (Virtual Guest)

 * Important manual pages:
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
 * 
 * License <http://sldn.softlayer.com/article/License>
 * Author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";

/**
 * Your SoftLayer API username
 * @var string
 */
$username = "set me";

/**
 * Your SoftLayer API key
 * Generate one at: https://control.softlayer.com/account/users
 * @var string
 */
$apiKey = "set me";

// Define the virtual guest Id that you wish to add the firewall
$virtualGuestId = 5074554;

// Creating a SoftLayer API client object
$softLayerProductOrder = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $apiKey);

/**
 * Building a skeleton SoftLayer_Product_Item_Price objects. These objects contain
 * much more than ids, but SoftLayer's ordering system only needs the price's id
 * to know what you want to order.
 * to get the list of valid prices for the package
 * use the SoftLayer_Product_Package:getItems method
*/
$prices = array
(
    409, # Price to 100Mbps Hardware Firewall
);

/**
 * Convert our item list into an array of skeleton
 * SoftLayer_Product_Item_Price objects. 
 */
$orderPrices = array();

foreach ($prices as $priceId){
    $price = new stdClass();
    $price->id = $priceId;
    $orderPrices[] = $price;
}

// Define location, packageId and quantity
$location = "AMSTERDAM";
$packageId = 0;  // The package Id for order monitoring packages is 0
$quantity = 1;   

// Build a skeleton SoftLayer_Virtual_Guest object to model the id
// of the virtual guest where you want add the monitoring package
$virtualGuests = new stdClass();
$virtualGuests->id = $virtualGuestId;
$orderVirtualGuest = array
(
    $virtualGuests
);

// Build a SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated object containing
// the order you wish to place.
$orderContainer = new stdClass();
$orderContainer->location           = $location;
$orderContainer->packageId          = $packageId;
$orderContainer->prices             = $orderPrices;
$orderContainer->quantity           = $quantity;
$orderContainer->virtualGuests      = $orderVirtualGuest;

try {
    // Re-declare the order template as a SOAP variable, so the SoftLayer
    // ordering system knows what type of order you're placing.
    $orderTemplate = new SoapVar
    (
        $orderContainer,
        SOAP_ENC_OBJECT,
        'SoftLayer_Container_Product_Order_Network_Protection_Firewall',
        'http://api.service.softlayer.com/soap/v3.1/'
    );

    /*
     * SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
     * to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
     * records.
     */
    $receipt = $softLayerProductOrder->verifyOrder($orderTemplate);
    print_r($receipt);
} catch (Exception $e) {
    echo 'Unable to order the firewall for device: ' . $e->getMessage();
}

Firewall for VLAN

<?php
/**
 * Order Firewall for a VLAN

 * Important manual pages:
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
 * 
 * License <http://sldn.softlayer.com/article/License>
 * Author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";

/**
 * Your SoftLayer API username
 * @var string
 */
$username = "set me";

/**
 * Your SoftLayer API key
 * Generate one at: https://control.softlayer.com/account/users
 * @var string
 */
$apiKey = "set me";

// Create a SoftLayer API client object for "SoftLayer_Product_Order" services
$softLayerProductOrder = Softlayer_SoapClient::getClient("SoftLayer_Product_Order", null, $username, $apiKey);

// Declare the vlan id that you wish to add the firewall
$vlanId = 765032;

/**
 * Building a skeleton SoftLayer_Product_Item_Price objects. These objects contain
 * much more than ids, but SoftLayer's ordering system only needs the price's id
 * to know what you want to order.
 * to get the list of valid prices for the package
 * use the SoftLayer_Product_Package:getItemPrices method
*/
$prices = array
(
    2390, // Hardware Firewall (Dedicated)
    //21514, FortiGate Security Appliance
);

/**
 * Convert our item list into an array of skeleton
 * SoftLayer_Product_Item_Price objects. 
 */
$orderPrices = array();

foreach ($prices as $priceId){
    $price = new stdClass();
    $price->id = $priceId;
    $orderPrices[] = $price;
}

// Declare the location, packageId and quantity
$location = "AMSTERDAM";
$packageId = 0;  // The package Id for order Firewalls
$quantity = 1;

// Build a SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated object containing
// the order you wish to place.
$orderContainer = new stdClass();
$orderContainer->location           = $location;
$orderContainer->packageId          = $packageId;
$orderContainer->prices             = $orderPrices;
$orderContainer->quantity           = $quantity;
$orderContainer-> vlanId = $vlanId;


try {
    // Re-declare the order template as a SOAP variable, so the SoftLayer
    // ordering system knows what type of order you're placing.
    $orderTemplate = new SoapVar
    (
        $orderContainer,
        SOAP_ENC_OBJECT,
        'SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated',
        'http://api.service.softlayer.com/soap/v3/'
    );

    /*
     * SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
     * to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
     * records.
     */
    $receipt = $softLayerProductOrder->verifyOrder($orderTemplate);
    print_r($receipt);
} catch (Exception $e) {
    echo 'Unable to place the order: ' . $e->getMessage();
}

Order Security Software (Anti Virus)

<?php
/**
 * Purchase an Anti-virus for a server
 *
 * Important manual pages:
 * @see http://sldn.softlayer.com/reference/services/SoftLayer_Ticket
 * @see http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createUpgradeTicket
 * 
 * @license <http://sldn.softlayer.com/wiki/index.php/license>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */

require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";

/**
 * Your SoftLayer API username
 * @var string
 */
$username = "set me";

/**
 * Your SoftLayer API key
 * Generate one at: https://control.softlayer.com/account/users
 * @var string
 */
$apiKey = "set me";

/**
 * Define the hardware id where you wish to add the McAfee ANtivirus
 * @var int $attachmentId 
 */
 $attachmentId = 251708;

 // Define a brief description of what you wish to upgrade
 $genericUpgrade = "Add / Upgrade Software";

 // 
$upgradeMaintenanceWindow = "9.30.2015 (Wed) 01:00(GMT-0600) - 04:00(GMT-0600)";
// Declare a detailed description of the server or account upgrade you wish to perform
$details ="I would like additional information on adding McAfee AntiVirus (5$.00 monthly) to my account.";
// Declare the attachmentType e.g. HARDWARE - VIRTUAL_GUEST - NONE
$attachmentType = "HARDWARE";

// Create a SoftLayer API client object for "SoftLayer_Ticket" service
$ticketService = SoftLayer_SoapClient::getClient("SoftLayer_Ticket", null, $username, $apiKey);

try {
    $result = $ticketService -> createUpgradeTicket($attachmentId, $genericUpgrade, $upgradeMaintenanceWindow, $details, $attachmentType);
    print_r($result);
} catch(Exception $e) {
    echo "Unable to create the ticket: " . $e -> getMessage();
}
  • Thank you sldn-rcuellar! – mnnmountain Nov 13 '15 at 16:58
  • Ruber, can you please tell me how you generated the CSR used in the "Order SSL Certificates" sample? Any detailed openssl command for it? Do you know any PHP /API I can use to validate the CSR to get result data such as emailAddress, "ST", "CN" from that CSR ? – mnnmountain Dec 23 '15 at 15:18
  • Take a look of this: [SoftLayer API: Order Security Certificate CSR validation](http://stackoverflow.com/questions/34427466/softlayer-api-order-security-certificate-csr-validation) – Ruber Cuellar Valenzuela Dec 23 '15 at 16:58
1

I created some examples for you, hopefully they are helpful :)

  1. https://softlayer.github.io/php/orderSSLCert/
  2. https://softlayer.github.io/php/orderFirewalls/
  3. https://softlayer.github.io/php/orderFirewalls/
  4. https://softlayer.github.io/php/orderBareMetal/
    To add any security product to a server order, you just have to add the proper price ID to the order.
  5. Anti-Virus is available on RedHat and Windows operating systems, while anti-malware and host IPS is only available on Windows. There are not really any programmatic ways of finding that out, other than trying to place an order and it being rejected.
Chris Gallo
  • 191
  • 1
  • 4
  • Chris, the sample file orderSSLCert has the following method: * Each package has a lot of items, so this function will show you all of those along with their prices. * Search through it for the proper SSL item you want to order, and take note of its price */ function getPackageById($id=0, $onlyShow=0) { $packageClient = \SoftLayer\SoapClient::getClient('SoftLayer_Product_Package', $id, $this->apiUsername, $this->apiKey ); $package = $packageClient->getItems(); – mnnmountain Nov 16 '15 at 18:04
  • Chris, in the sample file orderSSLCert : function getPackageById($id=0, $onlyShow=0)\SoapClient::getClient('SoftLayer_Product_Package', $id, $this->apiUsername, $this->apiKey ); $package = $packageClient->getItems(); Is the id value for the SoftLayer_Product_Item object fixed for all account ? – mnnmountain Nov 16 '15 at 18:11
  • Yes, all SoftLayer_Product_Item ids are fixed and the same for all accounts. – Chris Gallo Nov 16 '15 at 19:09