/**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     try {
         if (!Maestrano::param('connec.enabled')) {
             return false;
         }
         $client = new Maestrano_Connec_Client();
         $notification = json_decode(file_get_contents('php://input'), false);
         $entity_name = strtoupper(trim($notification->entity));
         $entity_id = $notification->id;
         switch ($entity_name) {
             case "PERSONS":
                 $customerMapper = new CustomerMapper();
                 $customerMapper->fetchConnecResource($entity_id);
                 break;
             case "ITEMS":
                 $productMapper = new ProductMapper();
                 $productMapper->fetchConnecResource($entity_id);
                 break;
             case "TAXCODES":
                 $taxMapper = new TaxMapper();
                 $taxMapper->fetchConnecResource($entity_id);
                 break;
         }
     } catch (Exception $e) {
         error_log("Caught exception in subscribe " . json_encode($e->getMessage()));
     }
 }
 public function testConfigurationFromFile()
 {
     $path = "config.json";
     file_put_contents($path, json_encode($this->config));
     Maestrano::configure($path);
     $this->assertEquals($this->config['environment'], Maestrano::param('environment'));
     $this->assertEquals($this->config['app']['host'], Maestrano::param('app.host'));
     $this->assertEquals($this->config['api']['id'], Maestrano::param('api.id'));
     $this->assertEquals($this->config['api']['key'], Maestrano::param('api.key'));
     $this->assertEquals($this->config['api']['host'], Maestrano::param('api.host'));
     $this->assertEquals($this->config['api']['group_id'], Maestrano::param('api.group_id'));
     $this->assertEquals($this->config['sso']['init_path'], Maestrano::param('sso.init_path'));
     $this->assertEquals($this->config['sso']['consume_path'], Maestrano::param('sso.consume_path'));
     $this->assertEquals($this->config['sso']['idp'], Maestrano::param('sso.idp'));
     $this->assertEquals($this->config['sso']['x509_fingerprint'], Maestrano::param('sso.x509_fingerprint'));
     $this->assertEquals($this->config['sso']['x509_certificate'], Maestrano::param('sso.x509_certificate'));
     $this->assertEquals($this->config['connec']['enabled'], Maestrano::param('connec.enabled'));
     $this->assertEquals($this->config['connec']['host'], Maestrano::param('connec.host'));
     $this->assertEquals($this->config['connec']['base_path'], Maestrano::param('connec.base_path'));
     $this->assertEquals($this->config['connec']['v2_path'], Maestrano::param('connec.v2_path'));
     $this->assertEquals($this->config['connec']['reports_path'], Maestrano::param('connec.reports_path'));
     $this->assertEquals($this->config['webhook']['account']['groups_path'], Maestrano::param('webhook.account.groups_path'));
     $this->assertEquals($this->config['webhook']['account']['group_users_path'], Maestrano::param('webhook.account.group_users_path'));
     $this->assertEquals($this->config['webhook']['connec']['initialization_path'], Maestrano::param('webhook.connec.initialization_path'));
     $this->assertEquals($this->config['webhook']['connec']['notifications_path'], Maestrano::param('webhook.connec.notifications_path'));
     $this->assertEquals($this->config['webhook']['connec']['subscriptions'], Maestrano::param('webhook.connec.subscriptions'));
     unlink($path);
 }
Beispiel #3
0
 /**
  * Return the real email if Maestrano Sso Creation Mode is set
  * to "real" and the Virtual email otherwise ("virtual" mode)
  * @return
  */
 public function toEmail()
 {
     if (Maestrano::param('sso.creation_mode') == "real") {
         return $this->email;
     } else {
         return $this->virtualEmail;
     }
 }
Beispiel #4
0
 private function _curlRequest($method, $absUrl, $headers, $params)
 {
     $curl = curl_init();
     $method = strtoupper($method);
     $opts = array();
     if ($method == 'GET') {
         $opts[CURLOPT_HTTPGET] = 1;
         if (count($params) > 0) {
             $encoded = self::encode($params);
             $absUrl = "{$absUrl}?{$encoded}";
         }
     } else {
         if ($method == 'POST') {
             $opts[CURLOPT_POST] = 1;
             $opts[CURLOPT_POSTFIELDS] = json_encode($params);
         } else {
             if ($method == 'PUT') {
                 $opts[CURLOPT_CUSTOMREQUEST] = "PUT";
                 $opts[CURLOPT_POSTFIELDS] = json_encode($params);
             } else {
                 if ($method == 'DELETE') {
                     $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                     if (count($params) > 0) {
                         $encoded = self::encode($params);
                         $absUrl = "{$absUrl}?{$encoded}";
                     }
                 } else {
                     throw new Maestrano_Api_Error("Unrecognized method {$method}");
                 }
             }
         }
     }
     $absUrl = self::utf8($absUrl);
     $opts[CURLOPT_URL] = $absUrl;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_CONNECTTIMEOUT] = 30;
     $opts[CURLOPT_TIMEOUT] = 80;
     $opts[CURLOPT_HTTPHEADER] = $headers;
     if (!Maestrano::param('verify_ssl_certs')) {
         $opts[CURLOPT_SSL_VERIFYPEER] = false;
     }
     curl_setopt_array($curl, $opts);
     $rbody = curl_exec($curl);
     if (!defined('CURLE_SSL_CACERT_BADFILE')) {
         define('CURLE_SSL_CACERT_BADFILE', 77);
         // constant not defined in PHP
     }
     $errno = curl_errno($curl);
     if ($errno == CURLE_SSL_CACERT || $errno == CURLE_SSL_PEER_CERTIFICATE || $errno == CURLE_SSL_CACERT_BADFILE) {
         array_push($headers, 'X-Maestrano-Client-Info: {"ca":"using Maestrano-supplied CA bundle"}');
         $cert = $this->caBundle();
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($curl, CURLOPT_CAINFO, $cert);
         $rbody = curl_exec($curl);
     }
     if ($rbody === false) {
         $errno = curl_errno($curl);
         $message = curl_error($curl);
         curl_close($curl);
         $this->handleCurlError($errno, $message);
     }
     $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array('body' => $rbody, 'code' => $rcode);
 }
Beispiel #5
0
 /**
  * Return a json string describing the configuration
  * currently used by the PHP bindings
  */
 public static function toMetadata()
 {
     $config = array('environment' => Maestrano::param('environment'), 'app' => array('host' => Maestrano::param('app.host')), 'api' => array('id' => Maestrano::param('api.id'), 'version' => Maestrano::param('api.version'), 'verify_ssl_certs' => false, 'lang' => Maestrano::param('api.lang'), 'lang_version' => Maestrano::param('api.lang_version'), 'host' => Maestrano::param('api.host'), 'base' => Maestrano::param('api.base')), 'sso' => array('enabled' => Maestrano::param('sso.enabled'), 'slo_enabled' => Maestrano::param('sso.slo_enabled'), 'init_path' => Maestrano::param('sso.init_path'), 'consume_path' => Maestrano::param('sso.consume_path'), 'creation_mode' => Maestrano::param('sso.creation_mode'), 'idm' => Maestrano::param('sso.idm'), 'idp' => Maestrano::param('sso.idp'), 'name_id_format' => Maestrano::param('sso.name_id_format'), 'x509_fingerprint' => Maestrano::param('sso.x509_fingerprint'), 'x509_certificate' => Maestrano::param('sso.x509_certificate')), 'connec' => array('enabled' => Maestrano::param('connec.enabled'), 'host' => Maestrano::param('connec.host'), 'base_path' => Maestrano::param('connec.base_path'), 'v2_path' => Maestrano::param('connec.v2_path'), 'reports_path' => Maestrano::param('connec.reports_path')), 'webhook' => array('account' => array('groups_path' => Maestrano::param('webhook.account.groups_path'), 'group_users_path' => Maestrano::param('webhook.account.group_users_path')), 'connec' => array('initialization_path' => Maestrano::param('webhook.connec.initialization_path'), 'notifications_path' => Maestrano::param('webhook.connec.notifications_path'), 'subscriptions' => Maestrano::param('webhook.connec.subscriptions'))));
     return json_encode($config);
 }
Beispiel #6
0
 /**
  * @param number $errno
  * @param string $message
  * @throws Maestrano_Api_ConnectionError
  */
 public function handleCurlError($errno, $message)
 {
     $apiBase = Maestrano::param('api.host');
     switch ($errno) {
         case CURLE_COULDNT_CONNECT:
         case CURLE_COULDNT_RESOLVE_HOST:
         case CURLE_OPERATION_TIMEOUTED:
             $msg = "Could not connect to Maestrano ({$apiBase}).  Please check your " . "internet connection and try again.  If this problem persists, " . "you should check Maestrano's service status at " . "https://twitter.com/Maestrano, or";
             break;
         case CURLE_SSL_CACERT:
         case CURLE_SSL_PEER_CERTIFICATE:
             $msg = "Could not verify Maestrano's SSL certificate.  Please make sure " . "that your network is not intercepting certificates.  " . "(Try going to {$apiBase} in your browser.)  " . "If this problem persists,";
             break;
         default:
             $msg = "Unexpected error communicating with Maestrano.  " . "If this problem persists,";
     }
     $msg .= " let us know at support@Maestrano.com.";
     $msg .= "\n\n(Network error [errno {$errno}]: {$message})";
     throw new Maestrano_Api_ConnectionError($msg);
 }
 public function processLocalUpdate($model, $pushToConnec = true, $delete = false, $saveResult = false)
 {
     $pushToConnec = $pushToConnec && Maestrano::param('connec.enabled');
     error_log("process local update entity={$this->connec_entity_name}, local_id=" . $this->getId($model) . ", pushToConnec={$pushToConnec}, delete={$delete}");
     if ($pushToConnec) {
         $this->pushToConnec($model, $saveResult);
     }
     if ($delete) {
         $this->flagAsDeleted($model);
     }
 }
Beispiel #8
0
 /**
  * Return a settings object for php-saml
  * 
  * @return Maestrano_Saml_Settings
  */
 public function getSamlSettings()
 {
     $settings = new Maestrano_Saml_Settings();
     // Configure SAML
     $settings->idpPublicCertificate = Maestrano::param('sso.x509_certificate');
     $settings->spIssuer = Maestrano::param('api.id');
     $settings->requestedNameIdFormat = Maestrano::param('sso.name_id_format');
     $settings->idpSingleSignOnUrl = $this->getIdpUrl();
     $settings->spReturnUrl = $this->getConsumeUrl();
     return $settings;
 }