3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This class handles all SOAP client requests.
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 class CRM_Utils_SoapServer
{
21 * Number of seconds we should let a soap process idle
24 public static $soap_timeout = 0;
27 * Cache the actual UF Class
33 * Class constructor. This caches the real user framework class locally,
34 * so we can use it for authentication and validation.
36 * @internal param string $uf The userframework class
38 public function __construct() {
39 // any external program which call SoapServer is responsible for
40 // creating and attaching the session
41 $args = func_get_args();
42 $this->ufClass
= array_shift($args);
46 * Simple ping function to test for liveness.
49 * The string to be echoed.
53 public function ping($var) {
54 $session = CRM_Core_Session
::singleton();
55 $key = $session->get('key');
56 $session->set('key', $var);
57 return "PONG: $var ($key)";
64 * The soap key generated by authenticate().
68 public function verify($key) {
69 $session = CRM_Core_Session
::singleton();
71 $soap_key = $session->get('soap_key');
74 if ($key !== sha1($soap_key)) {
75 throw new SoapFault('Client', 'Invalid key');
78 if (self
::$soap_timeout &&
79 $t > ($session->get('soap_time') + self
::$soap_timeout)
81 throw new SoapFault('Client', 'Expired key');
84 // otherwise, we're ok. update the timestamp
86 $session->set('soap_time', $t);
90 * Authentication wrapper to the UF Class.
97 * @param bool $loadCMSBootstrap
101 * The SOAP Client key
103 public function authenticate($name, $pass, $loadCMSBootstrap = FALSE) {
104 require_once str_replace('_', DIRECTORY_SEPARATOR
, $this->ufClass
) . '.php';
106 if ($this->ufClass
== 'CRM_Utils_System_Joomla'
107 ||
$this->ufClass
== 'CRM_Utils_System_WordPress') {
108 $loadCMSBootstrap = TRUE;
111 $result = CRM_Utils_System
::authenticate($name, $pass, $loadCMSBootstrap);
113 if (empty($result)) {
114 throw new SoapFault('Client', 'Invalid login');
117 $session = CRM_Core_Session
::singleton();
118 $session->set('soap_key', $result[2]);
119 $session->set('soap_time', time());
121 return sha1($result[2]);
130 * @param string $hash
131 * @param string $body
136 public function mailer_event_bounce($key, $job, $queue, $hash, $body) {
140 'time_stamp' => date('YmdHis'),
141 'event_queue_id' => $queue,
146 $result = civicrm_api('Mailing', 'event_bounce', $params);
147 return CRM_Utils_Array
::encode_items($result);
151 * Mailer event unsubscribe.
156 * @param string $hash
161 public function mailer_event_unsubscribe($key, $job, $queue, $hash) {
165 'time_stamp' => date('YmdHis'),
166 'org_unsubscribe' => 0,
167 'event_queue_id' => $queue,
171 $result = civicrm_api('MailingGroup', 'event_unsubscribe', $params);
172 return CRM_Utils_Array
::encode_items($result);
184 public function mailer_event_domain_unsubscribe($key, $job, $queue, $hash) {
188 'time_stamp' => date('YmdHis'),
189 'org_unsubscribe' => 1,
190 'event_queue_id' => $queue,
194 $result = civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params);
195 return CRM_Utils_Array
::encode_items($result);
207 public function mailer_event_resubscribe($key, $job, $queue, $hash) {
211 'time_stamp' => date('YmdHis'),
212 'org_unsubscribe' => 0,
213 'event_queue_id' => $queue,
217 $result = civicrm_api('MailingGroup', 'event_resubscribe', $params);
218 return CRM_Utils_Array
::encode_items($result);
230 public function mailer_event_subscribe($key, $email, $domain, $group) {
234 'group_id' => $group,
237 $result = civicrm_api('MailingGroup', 'event_subscribe', $params);
238 return CRM_Utils_Array
::encode_items($result);
250 public function mailer_event_confirm($key, $contact, $subscribe, $hash) {
253 'contact_id' => $contact,
254 'subscribe_id' => $subscribe,
255 'time_stamp' => date('YmdHis'),
256 'event_subscribe_id' => $subscribe,
260 $result = civicrm_api('Mailing', 'event_confirm', $params);
261 return CRM_Utils_Array
::encode_items($result);
271 * @param null $bodyHTML
272 * @param null $fullEmail
277 public function mailer_event_reply($key, $job, $queue, $hash, $bodyTxt, $rt, $bodyHTML = NULL, $fullEmail = NULL) {
281 'event_queue_id' => $queue,
283 'bodyTxt' => $bodyTxt,
285 'bodyHTML' => $bodyHTML,
286 'fullEmail' => $fullEmail,
287 'time_stamp' => date('YmdHis'),
290 $result = civicrm_api('Mailing', 'event_reply', $params);
291 return CRM_Utils_Array
::encode_items($result);
304 public function mailer_event_forward($key, $job, $queue, $hash, $email) {
308 'event_queue_id' => $queue,
313 $result = civicrm_api('Mailing', 'event_forward', $params);
314 return CRM_Utils_Array
::encode_items($result);
319 * @param array $params
324 public function get_contact($key, $params) {
326 $params['version'] = 3;
327 $result = civicrm_api('contact', 'get', $params);
328 return CRM_Utils_Array
::encode_items($result);