예제 #1
0
 /**
  * Gets the singleton SoapClient which is used to connect to the TransIP Api.
  *
  * @param  mixed       $parameters  Parameters.
  * @return SoapClient               The SoapClient object to which we can connect to the TransIP API
  */
 public static function _getSoapClient($parameters = array())
 {
     $endpoint = Transip_ApiSettings::$endpoint;
     if (self::$_soapClient === null) {
         $extensions = get_loaded_extensions();
         $errors = array();
         if (!class_exists('SoapClient') || !in_array('soap', $extensions)) {
             $errors[] = 'The PHP SOAP extension doesn\'t seem to be installed. You need to install the PHP SOAP extension. (See: http://www.php.net/manual/en/book.soap.php)';
         }
         if (!in_array('openssl', $extensions)) {
             $errors[] = 'The PHP OpenSSL extension doesn\'t seem to be installed. You need to install PHP with the OpenSSL extension. (See: http://www.php.net/manual/en/book.openssl.php)';
         }
         if (!empty($errors)) {
             die('<p>' . implode("</p>\n<p>", $errors) . '</p>');
         }
         $classMap = array('DataCenterVisitor' => 'Transip_DataCenterVisitor');
         $options = array('classmap' => $classMap, 'encoding' => 'utf-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => false);
         $wsdlUri = "https://{$endpoint}/wsdl/?service=" . self::SERVICE;
         try {
             self::$_soapClient = new SoapClient($wsdlUri, $options);
         } catch (SoapFault $sf) {
             throw new Exception("Unable to connect to endpoint '{$endpoint}'");
         }
         self::$_soapClient->__setCookie('login', Transip_ApiSettings::$login);
         self::$_soapClient->__setCookie('mode', Transip_ApiSettings::$mode);
     }
     $timestamp = time();
     $nonce = uniqid('', true);
     self::$_soapClient->__setCookie('timestamp', $timestamp);
     self::$_soapClient->__setCookie('nonce', $nonce);
     self::$_soapClient->__setCookie('clientVersion', self::API_VERSION);
     self::$_soapClient->__setCookie('signature', self::_urlencode(self::_sign(array_merge($parameters, array('__service' => self::SERVICE, '__hostname' => $endpoint, '__timestamp' => $timestamp, '__nonce' => $nonce)))));
     return self::$_soapClient;
 }
<?php

/**
 * This example creates an IPAddress.
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
try {
    // Creates an IpAddress and will assign it to the current user.
    // Please note that 127.0.0.1 is an example address.
    Transip_ColocationService::createIpAddress('127.0.0.1', 'reverse.example.com');
} catch (Exception $e) {
    print "error: {$e->getMessage()}\n";
}
<?php

/**
 * This example sets the reverse dns for an IPAddress.
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
try {
    // Change the reverse dns of an already active IPAddress assigned to the current user
    // Please note that 127.0.0.1 is a example addresss
    Transip_ColocationService::setReverseDns('127.0.0.1', 'reverse.example.com');
} catch (Exception $e) {
    print "error: {$e->getMessage()}\n";
}
<?php

/**
 * This example deletes an active IPAddress.
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
try {
    // Please note that 127.0.0.1 is an example address
    Transip_ColocationService::deleteIpAddress('127.0.0.1');
} catch (Exception $e) {
    print "error: {$e->getMessage()}\n";
}
<?php

/**
 * This example requests access to the datacenter
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
if (isset($_POST['request']) && count($_POST['request']) > 0) {
    extract($_POST['request']);
    try {
        // filter out empty input fields
        $visitor = array_filter($visitor, 'strlen');
        $dataCenterVisitors = Transip_ColocationService::requestAccess($when, $duration, $visitor, $phoneNumber);
        $result = '';
        foreach ($dataCenterVisitors as $dataCenterVisitor) {
            if ($dataCenterVisitor->hasBeenRegisteredBefore) {
                $result .= "{$dataCenterVisitor->name} (no code needed)\n";
            } else {
                $result .= "{$dataCenterVisitor->name}";
                $result .= " (reservation number: {$dataCenterVisitor->reservationNumber};";
                $result .= " access code: {$dataCenterVisitor->accessCode})\n";
            }
        }
    } catch (SoapFault $e) {
        // It is possible that an error occurs when connecting to the TransIP Soap API,
        // those errors will be thrown as a SoapFault exception.
        $result = 'An error occurred: ' . htmlspecialchars($e->getMessage());
    }
}
<?php

/**
 * This example requests remotehands
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
if (isset($_POST['request']) && count($_POST['request']) > 0) {
    extract($_POST['request']);
    try {
        $dataCenterHandsRequest = Transip_ColocationService::requestRemoteHands($coloName, $contactName, $phoneNumber, $expectedDuration, $instructions);
        $result = 'The request has been sent.';
    } catch (SoapFault $e) {
        // It is possible that an error occurs when connecting to the TransIP Soap API,
        // those errors will be thrown as a SoapFault exception.
        $result = 'An error occurred: ' . htmlspecialchars($e->getMessage());
    }
}
?>
<html>
<head>
	<title>TransIP API Datacenter Remote Hands Request</title>
</head>

<body>
	<h2>TransIP API Datacenter Remote Hands Request</h2>
	<?php 
echo isset($result) ? '<p><pre>' . $result . '</pre></p>' : '';
?>
 *  Transip_ColocationService::getIpAddresses()
 *  Transip_ColocationService::getReverseDns()
 *
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/ColocationService.php';
try {
    // retrieve all colocation items and loop
    $coloNames = Transip_ColocationService::getColoNames();
    foreach ($coloNames as $coloName) {
        echo $coloName . ':' . PHP_EOL;
        // for each colo, get the IPRanges used by this colo
        $ipRanges = Transip_ColocationService::getIpRanges($coloName);
        foreach ($ipRanges as $ipRange) {
            echo '- IP range: ' . $ipRange . PHP_EOL;
        }
        // get all IPAddresses attached to this colo and iterate over
        // the addresses to get the reverse dns and print information.
        $ipAddresses = Transip_ColocationService::getIpAddresses($coloName);
        foreach ($ipAddresses as $ipAddress) {
            $reverseDns = Transip_ColocationService::getReverseDns($ipAddress);
            echo '- IP address: ' . $ipAddress . ' (rDNS "' . $reverseDns . '")' . PHP_EOL;
        }
        echo PHP_EOL;
    }
} catch (Exception $exception) {
    // When something goes wrong, an Exception will be thrown with relevant information.
    echo "An Exception occured. Code: {$exception->getCode()}, message: {$exception->getMessage()}\n";
}