3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This class handles all SOAP client requests.
32 * @copyright CiviCRM LLC (c) 2004-2019
34 class CRM_Utils_SoapServer
{
37 * Number of seconds we should let a soap process idle
40 public static $soap_timeout = 0;
43 * Cache the actual UF Class
49 * Class constructor. This caches the real user framework class locally,
50 * so we can use it for authentication and validation.
52 * @internal param string $uf The userframework class
54 public function __construct() {
55 // any external program which call SoapServer is responsible for
56 // creating and attaching the session
57 $args = func_get_args();
58 $this->ufClass
= array_shift($args);
62 * Simple ping function to test for liveness.
65 * The string to be echoed.
69 public function ping($var) {
70 $session = CRM_Core_Session
::singleton();
71 $key = $session->get('key');
72 $session->set('key', $var);
73 return "PONG: $var ($key)";
80 * The soap key generated by authenticate().
84 public function verify($key) {
85 $session = CRM_Core_Session
::singleton();
87 $soap_key = $session->get('soap_key');
90 if ($key !== sha1($soap_key)) {
91 throw new SoapFault('Client', 'Invalid key');
94 if (self
::$soap_timeout &&
95 $t > ($session->get('soap_time') + self
::$soap_timeout)
97 throw new SoapFault('Client', 'Expired key');
100 // otherwise, we're ok. update the timestamp
102 $session->set('soap_time', $t);
106 * Authentication wrapper to the UF Class.
108 * @param string $name
110 * @param string $pass
113 * @param bool $loadCMSBootstrap
117 * The SOAP Client key
119 public function authenticate($name, $pass, $loadCMSBootstrap = FALSE) {
120 require_once str_replace('_', DIRECTORY_SEPARATOR
, $this->ufClass
) . '.php';
122 if ($this->ufClass
== 'CRM_Utils_System_Joomla'
123 ||
$this->ufClass
== 'CRM_Utils_System_WordPress') {
124 $loadCMSBootstrap = TRUE;
127 $result = CRM_Utils_System
::authenticate($name, $pass, $loadCMSBootstrap);
129 if (empty($result)) {
130 throw new SoapFault('Client', 'Invalid login');
133 $session = CRM_Core_Session
::singleton();
134 $session->set('soap_key', $result[2]);
135 $session->set('soap_time', time());
137 return sha1($result[2]);
146 * @param string $hash
147 * @param string $body
152 public function mailer_event_bounce($key, $job, $queue, $hash, $body) {
156 'time_stamp' => date('YmdHis'),
157 'event_queue_id' => $queue,
162 $result = civicrm_api('Mailing', 'event_bounce', $params);
163 return CRM_Utils_Array
::encode_items($result);
167 * Mailer event unsubscribe.
172 * @param string $hash
177 public function mailer_event_unsubscribe($key, $job, $queue, $hash) {
181 'time_stamp' => date('YmdHis'),
182 'org_unsubscribe' => 0,
183 'event_queue_id' => $queue,
187 $result = civicrm_api('MailingGroup', 'event_unsubscribe', $params);
188 return CRM_Utils_Array
::encode_items($result);
200 public function mailer_event_domain_unsubscribe($key, $job, $queue, $hash) {
204 'time_stamp' => date('YmdHis'),
205 'org_unsubscribe' => 1,
206 'event_queue_id' => $queue,
210 $result = civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params);
211 return CRM_Utils_Array
::encode_items($result);
223 public function mailer_event_resubscribe($key, $job, $queue, $hash) {
227 'time_stamp' => date('YmdHis'),
228 'org_unsubscribe' => 0,
229 'event_queue_id' => $queue,
233 $result = civicrm_api('MailingGroup', 'event_resubscribe', $params);
234 return CRM_Utils_Array
::encode_items($result);
246 public function mailer_event_subscribe($key, $email, $domain, $group) {
250 'group_id' => $group,
253 $result = civicrm_api('MailingGroup', 'event_subscribe', $params);
254 return CRM_Utils_Array
::encode_items($result);
266 public function mailer_event_confirm($key, $contact, $subscribe, $hash) {
269 'contact_id' => $contact,
270 'subscribe_id' => $subscribe,
271 'time_stamp' => date('YmdHis'),
272 'event_subscribe_id' => $subscribe,
276 $result = civicrm_api('Mailing', 'event_confirm', $params);
277 return CRM_Utils_Array
::encode_items($result);
287 * @param null $bodyHTML
288 * @param null $fullEmail
293 public function mailer_event_reply($key, $job, $queue, $hash, $bodyTxt, $rt, $bodyHTML = NULL, $fullEmail = NULL) {
297 'event_queue_id' => $queue,
299 'bodyTxt' => $bodyTxt,
301 'bodyHTML' => $bodyHTML,
302 'fullEmail' => $fullEmail,
303 'time_stamp' => date('YmdHis'),
306 $result = civicrm_api('Mailing', 'event_reply', $params);
307 return CRM_Utils_Array
::encode_items($result);
320 public function mailer_event_forward($key, $job, $queue, $hash, $email) {
324 'event_queue_id' => $queue,
329 $result = civicrm_api('Mailing', 'event_forward', $params);
330 return CRM_Utils_Array
::encode_items($result);
335 * @param array $params
340 public function get_contact($key, $params) {
342 $params['version'] = 3;
343 $result = civicrm_api('contact', 'get', $params);
344 return CRM_Utils_Array
::encode_items($result);