Esempio n. 1
0
File: HEV.php Progetto: synap/ebics
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $parameters = json_decode(file_get_contents('parameters.json'));
     $url = $parameters->url;
     $HostID = $parameters->host;
     // Template pour requête HEV
     $xsl = new DOMDocument();
     $xsl->load('xslt/hev.xsl');
     // Configuration du moteur de template
     $proc = new XSLTProcessor();
     $proc->setParameter('', 'HostID', $HostID);
     $proc->importStylesheet($xsl);
     // Récupération du résultat
     $doc = $proc->transformToDoc(new DOMDocument());
     $request = new Request('POST', $url);
     $request->setBody($doc->saveXML());
     $client = new Client();
     $client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
     $response = $client->send($request);
     $dom = new DOMDocument();
     $dom->loadXML($response->getBodyAsString());
     //echo "\nVoici la liste des versions compatibles avec ce serveur:\n\n";
     $result = array();
     foreach ($dom->getElementsByTagName('VersionNumber') as $version) {
         $result[] = array($version->getAttribute('ProtocolVersion'), "EBICS version {$version->nodeValue}");
     }
     $table = new Table($output);
     $table->setHeaders(array('Protocole', 'Description'))->setRows($result);
     $table->render();
 }
Esempio n. 2
0
File: INI.php Progetto: synap/ebics
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Récupération des paramètres de connexion
     $parameters = json_decode(file_get_contents('parameters.json'));
     // Récupération du certificat X509
     $cert = file_get_contents('test/fixtures/keys/A005/cert.pem');
     $cert_details = openssl_x509_parse($cert);
     $params = array('X509IssuerName' => $cert_details['name'], 'X509SerialNumber' => $cert_details['serialNumber'], 'X509Certificate' => str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', "\n"), '', $cert));
     $cert_details = openssl_pkey_get_details(openssl_pkey_get_public($cert));
     $params = array_merge(array('Modulus' => base64_encode($cert_details['rsa']['n']), 'Exponent' => base64_encode($cert_details['rsa']['e'])), $params);
     // Attention, la cohérence entre les différente valeurs n'est pas vérifiée dans
     // la phase d'initialisation. Seule la longueur des valeurs l'est
     // Création de la signature A005
     $xsl = new DOMDocument();
     $xsl->load('xslt/SignaturePubKeyOrderData.xsl');
     $proc = new XSLTProcessor();
     $proc->setParameter('', 'X509IssuerName', $params['X509IssuerName']);
     $proc->setParameter('', 'X509SerialNumber', $params['X509SerialNumber']);
     $proc->setParameter('', 'X509Certificate', $params['X509Certificate']);
     $proc->setParameter('', 'Modulus', $params['Modulus']);
     $proc->setParameter('', 'Exponent', $params['Exponent']);
     $proc->setParameter('', 'PartnerID', $parameters->partner);
     $proc->setParameter('', 'UserID', $parameters->user);
     $proc->setParameter('', 'TimeStamp', date('c'));
     $proc->importStylesheet($xsl);
     $A005 = $proc->transformToXML(new DOMDocument());
     // On compresse et on encode en base64
     $A005 = gzcompress($A005);
     $A005 = base64_encode($A005);
     $xsl = new DOMDocument();
     $xsl->load('xslt/ebicsUnsecuredRequest.xsl');
     $proc->importStylesheet($xsl);
     $proc->setParameter('', 'HostID', $parameters->host);
     $proc->setParameter('', 'OrderData', $A005);
     $xml = $proc->transformToXML(new DOMDocument());
     $request = new Request('POST', $parameters->url);
     $request->setBody($xml);
     $client = new Client();
     $client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
     $response = $client->send($request);
     $dom = new DOMDocument();
     $dom->formatOutput = true;
     $dom->loadXML($response->getBodyAsString());
     echo $dom->saveXML();
 }
Esempio n. 3
0
 /**
  * Constructor
  *
  * Settings are provided through the 'settings' argument. The following
  * settings are supported:
  *
  *   * baseUri
  *   * userName (optional)
  *   * password (optional)
  *   * proxy (optional)
  *   * authType (optional)
  *   * encoding (optional)
  *
  *  authType must be a bitmap, using self::AUTH_BASIC, self::AUTH_DIGEST
  *  and self::AUTH_NTLM. If you know which authentication method will be
  *  used, it's recommended to set it, as it will save a great deal of
  *  requests to 'discover' this information.
  *
  *  Encoding is a bitmap with one of the ENCODING constants.
  *
  * @param array $settings
  */
 function __construct(array $settings)
 {
     if (!isset($settings['baseUri'])) {
         throw new \InvalidArgumentException('A baseUri must be provided');
     }
     parent::__construct();
     $this->baseUri = $settings['baseUri'];
     if (isset($settings['proxy'])) {
         $this->addCurlSetting(CURLOPT_PROXY, $settings['proxy']);
     }
     if (isset($settings['userName'])) {
         $userName = $settings['userName'];
         $password = isset($settings['password']) ? $settings['password'] : '';
         if (isset($settings['authType'])) {
             $curlType = 0;
             if ($settings['authType'] & self::AUTH_BASIC) {
                 $curlType |= CURLAUTH_BASIC;
             }
             if ($settings['authType'] & self::AUTH_DIGEST) {
                 $curlType |= CURLAUTH_DIGEST;
             }
             if ($settings['authType'] & self::AUTH_NTLM) {
                 $curlType |= CURLAUTH_NTLM;
             }
         } else {
             $curlType = CURLAUTH_BASIC | CURLAUTH_DIGEST;
         }
         $this->addCurlSetting(CURLOPT_HTTPAUTH, $curlType);
         $this->addCurlSetting(CURLOPT_USERPWD, $userName . ':' . $password);
     }
     if (isset($settings['encoding'])) {
         $encoding = $settings['encoding'];
         $encodings = [];
         if ($encoding & self::ENCODING_IDENTITY) {
             $encodings[] = 'identity';
         }
         if ($encoding & self::ENCODING_DEFLATE) {
             $encodings[] = 'deflate';
         }
         if ($encoding & self::ENCODING_GZIP) {
             $encodings[] = 'gzip';
         }
         $this->addCurlSetting(CURLOPT_ENCODING, implode(',', $encodings));
     }
     $this->addCurlSetting(CURLOPT_USERAGENT, 'sabre-dav/' . Version::VERSION . ' (http://sabre.io/)');
     $this->xml = new Xml\Service();
     // BC
     $this->propertyMap =& $this->xml->elementMap;
 }
Esempio n. 4
0
 * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
 * @author Evert Pot (http://evertpot.com/)
 * @license http://sabre.io/license/ Modified BSD License
 */
use Sabre\HTTP\Request, Sabre\HTTP\Client;
// Find the autoloader
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/vendor/autoload.php'];
foreach ($paths as $path) {
    if (file_exists($path)) {
        include $path;
        break;
    }
}
// This is the request we're repeating a 1000 times.
$request = new Request('GET', 'http://localhost/');
$client = new Client();
for ($i = 0; $i < 1000; $i++) {
    echo "{$i} sending\n";
    $client->sendAsync($request, function ($response) use($i) {
        echo "{$i} -> " . $response->getStatus() . "\n";
    }, function ($error) use($i) {
        if ($error['status'] === Client::STATUS_CURLERROR) {
            // Curl errors
            echo "{$i} -> curl error: " . $error['curl_errmsg'] . "\n";
        } else {
            // HTTP errors
            echo "{$i} -> " . $error['response']->getStatus() . "\n";
        }
    });
}
// After everything is done, we call 'wait'. This causes the client to wait for
Esempio n. 5
0
File: HIA.php Progetto: synap/ebics
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $parameters = json_decode(file_get_contents('parameters.json'));
     $X002 = file_get_contents('test/fixtures/keys/X002/cert.pem');
     $cert_details = openssl_x509_parse($X002);
     $params['X002'] = array('X509IssuerName' => $cert_details['name'], 'X509SerialNumber' => $cert_details['serialNumber'], 'X509Certificate' => str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', "\n"), '', $X002));
     $cert_details = openssl_pkey_get_details(openssl_pkey_get_public($X002));
     $params['X002'] = array_merge(array('Modulus' => base64_encode($cert_details['rsa']['n']), 'Exponent' => base64_encode($cert_details['rsa']['e'])), $params['X002']);
     $E002 = file_get_contents('test/fixtures/keys/E002/cert.pem');
     $cert_details = openssl_x509_parse($E002);
     $params['E002'] = array('X509IssuerName' => $cert_details['name'], 'X509SerialNumber' => $cert_details['serialNumber'], 'X509Certificate' => str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', "\n"), '', $E002));
     $cert_details = openssl_pkey_get_details(openssl_pkey_get_public($E002));
     $params['E002'] = array_merge(array('Modulus' => base64_encode($cert_details['rsa']['n']), 'Exponent' => base64_encode($cert_details['rsa']['e'])), $params['E002']);
     // Attention, la cohérence entre les différente valeurs n'est pas vérifiée dans
     // la phase d'initialisation. Seule la longueur des valeurs l'est
     // Création de la signature A005
     $data = '<?xml version="1.0" encoding="UTF-8"?>
     <HIARequestOrderData xmlns="http://www.ebics.org/H003" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ebics.org/H003 http://www.ebics.org/H003/ebics_orders.xsd">
       <AuthenticationPubKeyInfo>
         <ds:X509Data>
           <ds:X509IssuerSerial>
             <ds:X509IssuerName>' . $params['X002']['X509IssuerName'] . '</ds:X509IssuerName>
             <ds:X509SerialNumber>' . $params['X002']['X509SerialNumber'] . '</ds:X509SerialNumber>
           </ds:X509IssuerSerial>
           <ds:X509Certificate>' . $params['X002']['X509Certificate'] . '</ds:X509Certificate>
         </ds:X509Data>
         <PubKeyValue>
           <ds:RSAKeyValue>
             <ds:Modulus>' . $params['X002']['Modulus'] . '</ds:Modulus>
             <ds:Exponent>' . $params['X002']['Exponent'] . '</ds:Exponent>
           </ds:RSAKeyValue>
         </PubKeyValue>
         <AuthenticationVersion>X002</AuthenticationVersion>
       </AuthenticationPubKeyInfo>
       <EncryptionPubKeyInfo>
         <ds:X509Data>
           <ds:X509IssuerSerial>
             <ds:X509IssuerName>' . $params['E002']['X509IssuerName'] . '</ds:X509IssuerName>
             <ds:X509SerialNumber>' . $params['E002']['X509SerialNumber'] . '</ds:X509SerialNumber>
           </ds:X509IssuerSerial>
           <ds:X509Certificate>' . $params['E002']['X509Certificate'] . '</ds:X509Certificate>
         </ds:X509Data>
         <PubKeyValue>
           <ds:RSAKeyValue>
             <ds:Modulus>' . $params['E002']['Modulus'] . '</ds:Modulus>
             <ds:Exponent>' . $params['E002']['Exponent'] . '</ds:Exponent>
           </ds:RSAKeyValue>
         </PubKeyValue>
         <EncryptionVersion>E002</EncryptionVersion>
       </EncryptionPubKeyInfo>
       <PartnerID>' . $parameters->partner . '</PartnerID>
       <UserID>' . $parameters->user . '</UserID>
     </HIARequestOrderData>';
     $data = base64_encode(gzcompress($data));
     $xml = '<?xml version="1.0"?>
     <ebicsUnsecuredRequest xmlns="http://www.ebics.org/H003" Revision="1" Version="H003">
       <header authenticate="true">
         <static>
           <HostID>' . $parameters->host . '</HostID>
           <PartnerID>' . $parameters->partner . '</PartnerID>
           <UserID>' . $parameters->user . '</UserID>
           <OrderDetails>
             <OrderType>HIA</OrderType>
             <OrderID>A102</OrderID>
             <OrderAttribute>DZNNN</OrderAttribute>
           </OrderDetails>
           <SecurityMedium>0000</SecurityMedium>
         </static>
         <mutable/>
       </header>
       <body>
         <DataTransfer>
           <OrderData>' . $data . '</OrderData>
         </DataTransfer>
       </body>
     </ebicsUnsecuredRequest>';
     $request = new Request('POST', $parameters->url);
     $request->setBody($xml);
     $client = new Client();
     $client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
     $response = $client->send($request);
     $dom = new DOMDocument();
     $dom->formatOutput = true;
     $dom->loadXML($response->getBodyAsString());
     echo $dom->saveXML();
 }
Esempio n. 6
0
 /**
  * Constructor
  *
  * Settings are provided through the 'settings' argument. The following
  * settings are supported:
  *
  *   * baseUri
  *   * userName (optional)
  *   * password (optional)
  *   * proxy (optional)
  *   * authType (optional)
  *   * encoding (optional)
  *
  *  authType must be a bitmap, using self::AUTH_BASIC and
  *  self::AUTH_DIGEST. If you know which authentication method will be
  *  used, it's recommended to set it, as it will save a great deal of
  *  requests to 'discover' this information.
  *
  *  Encoding is a bitmap with one of the ENCODING constants.
  *
  * @param array $settings
  */
 function __construct(array $settings)
 {
     if (!isset($settings['baseUri'])) {
         throw new \InvalidArgumentException('A baseUri must be provided');
     }
     $validSettings = ['baseUri', 'userName', 'password', 'proxy'];
     parent::__construct();
     $this->baseUri = $settings['baseUri'];
     if (isset($settings['proxy'])) {
         $this->addCurlSetting(CURLOPT_PROXY, $settings['proxy']);
     }
     if (isset($settings['userName'])) {
         $userName = $settings['userName'];
         $password = isset($settings['password']) ? $settings['password'] : '';
         if (isset($settings['authType'])) {
             $curlType = 0;
             if ($settings['authType'] & self::AUTH_BASIC) {
                 $curlType |= CURLAUTH_BASIC;
             }
             if ($settings['authType'] & self::AUTH_DIGEST) {
                 $curlType |= CURLAUTH_DIGEST;
             }
         } else {
             $curlType = CURLAUTH_BASIC | CURLAUTH_DIGEST;
         }
         $this->addCurlSetting(CURLOPT_HTTPAUTH, $curlType);
         $this->addCurlSetting(CURLOPT_USERPWD, $userName . ':' . $password);
     }
     if (isset($settings['encoding'])) {
         $encoding = $settings['encoding'];
         $encodings = [];
         if ($encoding & self::ENCODING_IDENTITY) {
             $encodings[] = 'identity';
         }
         if ($encoding & self::ENCODING_DEFLATE) {
             $encodings[] = 'deflate';
         }
         if ($encoding & self::ENCODING_GZIP) {
             $encodings[] = 'gzip';
         }
         $this->addCurlSetting(CURLOPT_ENCODING, implode(',', $encodings));
     }
     $this->propertyMap['{DAV:}resourcetype'] = 'Sabre\\DAV\\Property\\ResourceType';
 }
Esempio n. 7
0
// The url we're proxying to.
$remoteUrl = 'http://example.org/';
// The url we're proxying from. Please note that this must be a relative url,
// and basically acts as the base url.
//
// If your $remoteUrl doesn't end with a slash, this one probably shouldn't
// either.
$myBaseUrl = '/reverseproxy.php';
// $myBaseUrl = '/~evert/sabre/http/examples/reverseproxy.php/';
use Sabre\HTTP\Sapi;
use Sabre\HTTP\Client;
// Find the autoloader
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/vendor/autoload.php'];
foreach ($paths as $path) {
    if (file_exists($path)) {
        include $path;
        break;
    }
}
$request = Sapi::getRequest();
$request->setBaseUrl($myBaseUrl);
$subRequest = clone $request;
// Removing the Host header.
$subRequest->removeHeader('Host');
// Rewriting the url.
$subRequest->setUrl($remoteUrl . $request->getPath());
$client = new Client();
// Sends the HTTP request to the server
$response = $client->send($subRequest);
// Sends the response back to the client that connected to the proxy.
Sapi::sendResponse($response);
Esempio n. 8
0
<?php

/**
 * This example shows how to make a HTTP request with the Request and Response
 * objects.
 *
 * @copyright Copyright (C) 2009-2014 fruux GmbH. All rights reserved.
 * @author Evert Pot (http://evertpot.com/)
 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
 */
use Sabre\HTTP\Request, Sabre\HTTP\Client;
// Find the autoloader
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/vendor/autoload.php'];
foreach ($paths as $path) {
    if (file_exists($path)) {
        include $path;
        break;
    }
}
// Constructing the request.
$request = new Request('GET', 'http://localhost/');
$client = new Client();
//$client->addCurlSetting(CURLOPT_PROXY,'localhost:8888');
$response = $client->send($request);
echo "Response:\n";
echo (string) $response;
Esempio n. 9
0
 /**
  * Sends a request to a HTTP server, and returns a response.
  *
  * Switches request URL for absolute URL
  *
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 public function send(HTTP\RequestInterface $request)
 {
     $url = $request->getUrl();
     $absoluteUrl = $this->getAbsoluteUrl($url);
     $request->setUrl($absoluteUrl);
     return parent::send($request);
 }