Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/lib/internal/Customweb/Sogenactif/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/lib/internal/Customweb/Sogenactif/AbstractOfficeAdapter.php
<?php

/**
 *  * You are allowed to use this API in your web application.
 *
 * Copyright (C) 2018 by customweb GmbH
 *
 * This program is licenced under the customweb software licence. With the
 * purchase or the installation of the software in your application you
 * accept the licence agreement. The allowed usage is outlined in the
 * customweb software licence which can be found under
 * http://www.sellxed.com/en/software-license-agreement
 *
 * Any modification or distribution is strictly forbidden. The license
 * grants you the installation in one application. For multiuse you will need
 * to purchase further licences at http://www.sellxed.com/shop.
 *
 * See the customweb software licence agreement for more details.
 *
 */



/**
 * Abstract implementation of an adapter to execute a operation on the
 * office interface.
 *
 * @author Thomas Hunziker
 *
 */
abstract class Customweb_Sogenactif_AbstractOfficeAdapter extends Customweb_Sogenactif_AbstractAdapter {

	/**
	 * This method returns the endpoint URL of the backend service.
	 *
	 * @return string
	 */
	abstract protected function getEndpoint();

	/**
	 * This method sends the given parameters to the endpoint and evaluates the result.
	 *
	 * @param array $parameters
	 * @return array Result parameters
	 * @throws Exception In case the response is not valid or the server was unable to response.
	 */
	protected function processRequest(array $parameters){
		$parameters['seal'] = $this->calculateSeal($parameters);

		$json = json_encode($parameters);

		$request = new Customweb_Core_Http_Request($this->getEndpoint());
		$request->setMethod('POST')->appendHeader('content-type:application/json')->appendHeader('accept:application/json')->setBody($json);
		$client = Customweb_Core_Http_Client_Factory::createClient();
		$response = $client->send($request);

		if ($response->getStatusCode() != '200') {
			throw new Exception(
					Customweb_I18n_Translation::__(
							"Failed to send request to remote server. Expect to receive response code 200, receive code !code. Status Message: !message",
							array(
								'!code' => $response->getStatusCode(),
								'!message' => $response->getStatusMessage()
							)));
		}
		$result = json_decode($response->getBody(), true);

		if ($result === null) {
			throw new Exception(Customweb_I18n_Translation::__("Unable to decode the server response."));
		}

		return $result;
	}

	protected function processWithResponseValidation(array $parameters){
		$response = $this->processWithSealValidation($parameters);

		if (isset($response['responseCode']) && $response['responseCode'] != '00') {
			throw new Exception(Customweb_Sogenactif_Util::getErrorMessageByResponseCode($response['responseCode']));
		}

		return $response;
	}

	protected function processWithSealValidation(array $parameters){
		$response = $this->processRequest($parameters);

		if (!isset($response['seal'])) {
			if (isset($response['responseCode']) && $response['responseCode'] != '00') {
				throw new Exception(
						"Transaction failed because the server responded with:" .
						Customweb_Sogenactif_Util::getErrorMessageByResponseCode($response['responseCode']));
			}

			throw new Exception("No seal was provided in the server response.");
		}

		$calculatedSeal = strtolower($this->calculateSeal($response));
		if ($calculatedSeal !== strtolower($response['seal'])) {
			throw new Exception(Customweb_I18n_Translation::__("The calculated and the returned seal do not match."));
		}

		return $response;
	}

	/**
	 * Calculate seal
	 *
	 * @param array $parameters
	 *
	 * @return string
	 * @throws \Exception
	 */
	protected function calculateSeal(array $parameters){
		$data = '';

		if (isset($parameters['keyVersion'])) {
			unset($parameters['keyVersion']);
		}

		if (isset($parameters['seal'])) {
			unset($parameters['seal']);
		}

		$data = $this->arrayToString($parameters);

		return hash_hmac('sha256', $data, $this->getConfiguration()->getSecretKey());
	}

	private function arrayToString(array $array){
		$str = "";
		ksort($array);
		foreach ($array as $value) {
			if (is_array($value)) {
				$str .= $this->arrayToString($value);
			} else {
				$str .= $value;
			}
		}
		return $str;
	}

	protected function checkLiveAvailability(){
		$url = $this->getEndpoint();
		$replaced = str_replace($this->getConfiguration()->getBaseOfficeEndPointUrlTest(), $this->getConfiguration()->getBaseOfficeEndPointUrlLive(),
				$url);
		$request = new Customweb_Core_Http_Request($replaced);
		$request->setMethod('POST')->appendHeader('content-type:application/json')->appendHeader('accept:application/json');
		$client = Customweb_Core_Http_Client_Factory::createClient();
		try {
			$client->send($request);
		}
		catch (Exception $e) {
			throw new Exception(
					Customweb_I18n_Translation::__('Error connecting to Sogenactif 2.0. Reason: !message',
							array(
								'!message' => $e->getMessage()
							)));
		}
	}
}

Spamworldpro Mini