/** * Get a list of applications available for connections. * * @param array $params * @return array * @throws API_Exception * @throws CRM_Core_Exception * @throws \Civi\Cxn\Rpc\Exception\InvalidMessageException */ function civicrm_api3_cxn_app_get($params) { // You should not change CIVICRM_CXN_APPS_URL in production; this is for local development. $url = defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : \Civi\Cxn\Rpc\Constants::OFFICIAL_APPMETAS_URL; list($headers, $blob, $code) = CRM_Cxn_CiviCxnHttp::singleton()->send('GET', $url, ''); if ($code != 200) { throw new API_Exception("Failed to download application list."); } $agent = new \Civi\Cxn\Rpc\Agent(NULL, NULL); $agent->setCertValidator(CRM_Cxn_BAO_Cxn::createCertificateValidator()); $message = $agent->decode(array(AppMetasMessage::NAME, GarbledMessage::NAME), $blob); if ($message instanceof AppMetasMessage) { return _civicrm_api3_basic_array_get('CxnApp', $params, $message->getData(), 'appId', array('appId', 'appUrl', 'desc', 'appCert', 'perm')); } elseif ($message instanceof GarbledMessage) { return civicrm_api3_create_error('Received garbled response', array('garbled_message' => $message->getData())); } else { return civicrm_api3_create_error("Unrecognized message"); } }
/** * Construct a client for performing registration actions. * * @return \Civi\Cxn\Rpc\RegistrationClient * @throws CRM_Core_Exception */ public static function createRegistrationClient() { $cxnStore = new \CRM_Cxn_CiviCxnStore(); $client = new \Civi\Cxn\Rpc\RegistrationClient($cxnStore, \CRM_Cxn_BAO_Cxn::getSiteCallbackUrl()); $client->setLog(new \CRM_Utils_SystemLogger()); $client->setCertValidator(self::createCertificateValidator()); $client->setHttp(CRM_Cxn_CiviCxnHttp::singleton()); return $client; }
/** * * @param array $params * Array with keys: * - cxn_guid OR app_guid: string. * - page: string. * @return array * @throws Exception */ function civicrm_api3_cxn_getlink($params) { $cxnId = _civicrm_api3_cxn_parseCxnId($params); $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId); if (empty($params['page']) || !is_string($params['page'])) { throw new API_Exception("Invalid page"); } /** @var \Civi\Cxn\Rpc\RegistrationClient $client */ $client = \Civi::service('cxn_reg_client'); return $client->call($appMeta, 'Cxn', 'getlink', array('page' => $params['page'])); }
/** * * @param array $params * @return array * @throws Exception */ function civicrm_api3_cxn_getcfg($params) { $result = array('CIVICRM_CXN_CA' => defined('CIVICRM_CXN_CA') ? CIVICRM_CXN_CA : NULL, 'CIVICRM_CXN_VIA' => defined('CIVICRM_CXN_VIA') ? CIVICRM_CXN_VIA : NULL, 'CIVICRM_CXN_APPS_URL' => defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : NULL, 'siteCallbackUrl' => CRM_Cxn_BAO_Cxn::getSiteCallbackUrl()); return civicrm_api3_create_success($result); $cxnId = _civicrm_api3_cxn_parseCxnId($params); $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId); if (empty($params['page']) || !is_string($params['page'])) { throw new API_Exception("Invalid page"); } /** @var \Civi\Cxn\Rpc\RegistrationClient $client */ $client = \Civi\Core\Container::singleton()->get('cxn_reg_client'); return $client->call($appMeta, 'Cxn', 'getlink', array('page' => $params['page'])); }
/** * * @param array $params * @return array * @throws Exception */ function civicrm_api3_cxn_getcfg($params) { $result = array('CIVICRM_CXN_CA' => defined('CIVICRM_CXN_CA') ? CIVICRM_CXN_CA : NULL, 'CIVICRM_CXN_VIA' => defined('CIVICRM_CXN_VIA') ? CIVICRM_CXN_VIA : NULL, 'CIVICRM_CXN_APPS_URL' => defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : NULL, 'siteCallbackUrl' => CRM_Cxn_BAO_Cxn::getSiteCallbackUrl()); return civicrm_api3_create_success($result); }
/* +--------------------------------------------------------------------+ | CiviCRM version 4.7 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2015 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | | CiviCRM is free software; you can copy, modify, and distribute it | | under the terms of the GNU Affero General Public License | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | | | CiviCRM is distributed in the hope that it will be useful, but | | WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | See the GNU Affero General Public License for more details. | | | | You should have received a copy of the GNU Affero General Public | | License and the CiviCRM Licensing Exception along | | with this program; if not, contact CiviCRM LLC | | at info[AT]civicrm[DOT]org. If you have questions about the | | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ */ require_once '../civicrm.config.php'; $config = CRM_Core_Config::singleton(); CRM_Utils_System::loadBootStrap(array(), FALSE); CRM_Cxn_BAO_Cxn::createApiServer()->handle(file_get_contents('php://input'))->send();
/** * @param CRM_Cxn_DAO_Cxn $dao * @return array * Array-encoded connection details. */ protected function convertDaoToCxn($dao) { $appMeta = json_decode($dao->app_meta, TRUE); return array('cxnId' => $dao->cxn_guid, 'secret' => $dao->secret, 'appId' => $dao->app_guid, 'appUrl' => $appMeta['appUrl'], 'siteUrl' => CRM_Cxn_BAO_Cxn::getSiteCallbackUrl(), 'perm' => json_decode($dao->perm, TRUE)); }