From 0b5469cd703c7950af124856bad5ccb13fef3ac3 Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Sun, 20 Dec 2015 19:05:27 -0800 Subject: [PATCH] CRM-16173 - Display alert for local/private sites. --- ang/crmCxn.js | 1 + ang/crmCxn/CheckAddress.js | 33 +++++++++++++++++++++++++++++++++ ang/crmCxn/Connectivity.html | 4 ++++ ang/crmCxn/ManageCtrl.js | 13 ++++++++++++- api/v3/Cxn.php | 29 +++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 ang/crmCxn/CheckAddress.js create mode 100644 ang/crmCxn/Connectivity.html diff --git a/ang/crmCxn.js b/ang/crmCxn.js index 38b4baf949..2d2193959a 100644 --- a/ang/crmCxn.js +++ b/ang/crmCxn.js @@ -15,6 +15,7 @@ var reqs = {}; reqs.cxns = ['Cxn', 'get', {sequential: 1}]; reqs.appMetas = ['CxnApp', 'get', {sequential: 1, return: ['id', 'title', 'desc', 'appId', 'appUrl', 'perm']}]; + reqs.cfg = ['Cxn', 'getcfg', {}]; reqs.sysCheck = ['System', 'check', {}]; // FIXME: filter on checkCxnOverrides return crmApi(reqs); } diff --git a/ang/crmCxn/CheckAddress.js b/ang/crmCxn/CheckAddress.js new file mode 100644 index 0000000000..2313ddd017 --- /dev/null +++ b/ang/crmCxn/CheckAddress.js @@ -0,0 +1,33 @@ +(function (angular, $, _) { + + angular.module('crmCxn').factory('crmCxnCheckAddr', function($q, $timeout) { + var TIMEOUT = 6000, CHECK_ADDR = 'https://mycivi.org/check-addr'; + return function(url) { + var dfr = $q.defer(), result = null; + + function onErr() { + if (result !== null) return; + result = {url: url, valid: false}; + dfr.resolve(result); + } + + $.ajax({ + url: CHECK_ADDR, + data: {url: url}, + jsonp: "callback", + dataType: "jsonp" + }).fail(onErr) + .done(function(response) { + if (result !== null) return; + result = {url: url, valid: response.result}; + dfr.resolve(result); + } + ); + // JSONP may not provide errors directly. + $timeout(onErr, TIMEOUT); + + return dfr.promise; + }; + }); + +})(angular, CRM.$, CRM._); diff --git a/ang/crmCxn/Connectivity.html b/ang/crmCxn/Connectivity.html new file mode 100644 index 0000000000..e8a14d8aaa --- /dev/null +++ b/ang/crmCxn/Connectivity.html @@ -0,0 +1,4 @@ +

{{ts('There was a problem verifying that this site is available on the public Internet.')}}

+

{{ts('See also:')}} + {{ts('Firewalls and Proxies')}} +

\ No newline at end of file diff --git a/ang/crmCxn/ManageCtrl.js b/ang/crmCxn/ManageCtrl.js index 97615f0fb8..634b678530 100644 --- a/ang/crmCxn/ManageCtrl.js +++ b/ang/crmCxn/ManageCtrl.js @@ -1,6 +1,6 @@ (function(angular, $, _) { - angular.module('crmCxn').controller('CrmCxnManageCtrl', function CrmCxnManageCtrl($scope, apiCalls, crmApi, crmUiAlert, crmBlocker, crmStatus, $timeout, dialogService) { + angular.module('crmCxn').controller('CrmCxnManageCtrl', function CrmCxnManageCtrl($scope, apiCalls, crmApi, crmUiAlert, crmBlocker, crmStatus, $timeout, dialogService, crmCxnCheckAddr) { var ts = $scope.ts = CRM.ts(null); if (apiCalls.appMetas.is_error) { $scope.appMetas = []; @@ -12,6 +12,17 @@ $scope.cxns = apiCalls.cxns.values; $scope.alerts = _.where(apiCalls.sysCheck.values, {name: 'checkCxnOverrides'}); + crmCxnCheckAddr(apiCalls.cfg.values.siteCallbackUrl).then(function(response) { + if (response.valid) return; + crmUiAlert({ + type: 'warning', + title: ts('Internet Access Required'), + templateUrl: '~/crmCxn/Connectivity.html', + scope: $scope.$new(), + options: {expires: false} + }); + }); + $scope.filter = {}; var block = $scope.block = crmBlocker(); diff --git a/api/v3/Cxn.php b/api/v3/Cxn.php index 199d091634..af39133707 100644 --- a/api/v3/Cxn.php +++ b/api/v3/Cxn.php @@ -255,3 +255,32 @@ function civicrm_api3_cxn_getlink($params) { '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'], + )); +} -- 2.25.1