summaryrefslogtreecommitdiffstats
path: root/src/Calls
diff options
context:
space:
mode:
Diffstat (limited to 'src/Calls')
-rw-r--r--src/Calls/AnalyzeCall.php47
-rw-r--r--src/Calls/GenericCall.php133
-rw-r--r--src/Calls/GetEndpointDataCall.php51
-rw-r--r--src/Calls/InfoCall.php34
4 files changed, 265 insertions, 0 deletions
diff --git a/src/Calls/AnalyzeCall.php b/src/Calls/AnalyzeCall.php
new file mode 100644
index 0000000..4a4dff8
--- /dev/null
+++ b/src/Calls/AnalyzeCall.php
@@ -0,0 +1,47 @@
+<?php
+namespace BjoernrDe\SSLLabsApi\Calls;
+
+use BjoernrDe\SSLLabsApi\Objects\Host;
+use BjoernrDe\SSLLabsApi\Exceptions\InvalidScopeException;
+use BjoernrDe\SSLLabsApi\Exceptions\MissingApiParameterException;
+
+/**
+ * API Call 'analyze'
+ *
+ * @author Björn Roland
+ */
+class AnalyzeCall extends GenericCall
+{
+ /**
+ * Class constructor
+ *
+ * @param array $parameters
+ */
+ public function __construct($parameters = array())
+ {
+ if (!is_array($parameters))
+ {
+ throw new InvalidScopeException('Parameters must be an array');
+ }
+ if (!isset($parameters['host']) || empty($parameters['host']))
+ {
+ throw new MissingApiParameterException('Missing host parameter');
+ }
+
+ parent::__construct('analyze', $parameters);
+ }
+
+ /**
+ * Send API call
+ *
+ * @return SSLLabsApi\Objects\Host
+ * @see SSLLabsApi\Calls\GenericCall::send()
+ */
+ public function send()
+ {
+ $response = parent::send();
+ $hostObject = new Host();
+
+ return ($hostObject->populateObjectByApiResponse($response));
+ }
+} \ No newline at end of file
diff --git a/src/Calls/GenericCall.php b/src/Calls/GenericCall.php
new file mode 100644
index 0000000..f8d886c
--- /dev/null
+++ b/src/Calls/GenericCall.php
@@ -0,0 +1,133 @@
+<?php
+namespace BjoernrDe\SSLLabsApi\Calls;
+
+use BjoernrDe\SSLLabsApi\Exceptions\ApiErrorException;
+
+class GenericCall
+{
+ CONST API_URL = "https://api.ssllabs.com/api/v2";
+ CONST DEV_API_URL = "https://api.dev.ssllabs.com/api/v2/";
+
+ /**
+ * Api call
+ * @var string
+ */
+ private $apiCall;
+
+ /**
+ * Additional parameters for Api call
+ * i.e. hostname in analyze api call
+ *
+ * @var array
+ */
+ private $parameters;
+
+ /**
+ * DEV-Mode on|off
+ * If true ssllabs dev api is used for api calls
+ *
+ * @var boolean
+ */
+ private $devMode = false;
+
+ /**
+ * Class constructor
+ *
+ * @param string $apiCall
+ * @param array $parameters
+ */
+ public function __construct($apiCall, $parameters = array())
+ {
+ $this->apiCall = $apiCall;
+ $this->parameters = $parameters;
+ }
+
+ /**
+ * Get DEV mode
+ *
+ * @return boolean
+ */
+ public function getDevMode()
+ {
+ return ($this->devMode);
+ }
+
+ /**
+ * Set DEV mode on or off
+ *
+ * @param boolean $devMode
+ */
+ public function setDevMode($devMode)
+ {
+ $this->devMode = (boolean) $devMode;
+ }
+
+ /**
+ * Send request
+ *
+ * @throws ApiErrorException
+ * @return string|boolean JSON Api reponse or false
+ */
+ public function send()
+ {
+ if (!empty($this->apiCall))
+ {
+ //we also want content from failed api responses
+ $context = stream_context_create
+ (
+ array
+ (
+ 'http' => array
+ (
+ 'ignore_errors' => true,
+ 'timeout' => 5
+ )
+ )
+ );
+
+ $apiUrl = $this->getDevMode() ? self::DEV_API_URL : self::API_URL;
+ $apiResponse = @file_get_contents($apiUrl . '/' . $this->apiCall . $this->buildGetParameterString($this->parameters), false, $context);
+
+ if ($apiResponse === false)
+ {
+ throw new ApiErrorException('No response from API');
+ }
+
+ return ($apiResponse);
+ }
+
+ return (false);
+ }
+
+ /**
+ * Build GET parameter string for API
+ * + performs boolean to string (true = 'on' ; false = 'off') operation
+ *
+ * @param array $parameters
+ */
+ private function buildGetParameterString($parameters)
+ {
+ $string = '';
+
+ $counter = 0;
+ foreach ($parameters as $name => $value)
+ {
+ if (!is_string($name) || (!is_string($value) && !is_bool($value) && !is_int($value)))
+ {
+ continue;
+ }
+
+ if (is_bool($value))
+ {
+ $value = ($value) ? 'on' : 'off';
+ }
+
+ $string .= ($counter == 0) ? '?' : '&';
+ $string .= urlencode($name) . '=' . urlencode($value);
+
+ $counter++;
+ }
+
+ return ($string);
+ }
+} \ No newline at end of file
diff --git a/src/Calls/GetEndpointDataCall.php b/src/Calls/GetEndpointDataCall.php
new file mode 100644
index 0000000..a691c7f
--- /dev/null
+++ b/src/Calls/GetEndpointDataCall.php
@@ -0,0 +1,51 @@
+<?php
+namespace BjoernrDe\SSLLabsApi\Calls;
+
+use BjoernrDe\SSLLabsApi\Objects\Endpoint;
+use BjoernrDe\SSLLabsApi\Exceptions\InvalidScopeException;
+use BjoernrDe\SSLLabsApi\Exceptions\MissingApiParameterException;
+
+/**
+ * API Call 'getEndpointData'
+ *
+ * @author Björn Roland
+ */
+class GetEndpointDataCall extends GenericCall
+{
+ /**
+ * Class constructor
+ *
+ * @param array $parameters
+ */
+ public function __construct($parameters = array())
+ {
+ if (!is_array($parameters))
+ {
+ throw new InvalidScopeException('Parameters must be an array');
+ }
+ else if (!isset($parameters['host']) || empty($parameters['host']))
+ {
+ throw new MissingApiParameterException('Missing host parameter');
+ }
+ else if (!isset($parameters['s']) || empty($parameters['s']))
+ {
+ throw new MissingApiParameterException('Missing endpoint ip address (s) parameter');
+ }
+
+ parent::__construct('getEndpointData', $parameters);
+ }
+
+ /**
+ * Send API call
+ *
+ * @return SSLLabsApi\Objects\Host
+ * @see SSLLabsApi\Calls\GenericCall::send()
+ */
+ public function send()
+ {
+ $response = parent::send();
+ $endpointObject = new Endpoint();
+
+ return ($endpointObject->populateObjectByApiResponse($response));
+ }
+} \ No newline at end of file
diff --git a/src/Calls/InfoCall.php b/src/Calls/InfoCall.php
new file mode 100644
index 0000000..90752ce
--- /dev/null
+++ b/src/Calls/InfoCall.php
@@ -0,0 +1,34 @@
+<?php
+namespace BjoernrDe\SSLLabsApi\Calls;
+
+use BjoernrDe\SSLLabsApi\Objects\Info;
+
+/**
+ * API Call 'info'
+ *
+ * @author Björn Roland
+ */
+class InfoCall extends GenericCall
+{
+ /**
+ * Class constructor
+ */
+ public function __construct()
+ {
+ parent::__construct('info');
+ }
+
+ /**
+ * Send API call
+ *
+ * @return SSLLabsApi\Objects\Info
+ * @see SSLLabsApi\Calls\GenericCall::send()
+ */
+ public function send()
+ {
+ $response = parent::send();
+ $infoObject = new Info();
+
+ return ($infoObject->populateObjectByApiResponse($response));
+ }
+} \ No newline at end of file