From: Coleman Watts Date: Fri, 26 Jul 2013 23:10:10 +0000 (-0700) Subject: Revert PR#980 Restore SOAP code CRM-12343 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=40d837dfefbb9b401b4e39ae48ddd27e73ce1ca8;p=civicrm-core.git Revert PR#980 Restore SOAP code CRM-12343 ---------------------------------------- * CRM-12343: Remove Soap code http://issues.civicrm.org/jira/browse/CRM-12343 --- diff --git a/CRM/Core/Permission/Soap.php b/CRM/Core/Permission/Soap.php new file mode 100644 index 0000000000..cb52b5b2fb --- /dev/null +++ b/CRM/Core/Permission/Soap.php @@ -0,0 +1,54 @@ +ufClass = array_shift($args); + } + + /** + * Simple ping function to test for liveness. + * + * @param string $var The string to be echoed + * + * @return string $var + * @access public + */ + public function ping($var) { + $session = CRM_Core_Session::singleton(); + $key = $session->get('key'); + $session->set('key', $var); + return "PONG: $var ($key)"; + } + + /** + * Verify a SOAP key + * + * @param string $key The soap key generated by authenticate() + * + * @return none + * @access public + */ + public function verify($key) { + $session = CRM_Core_Session::singleton(); + + $soap_key = $session->get('soap_key'); + $t = time(); + + if ($key !== sha1($soap_key)) { + throw new SoapFault('Client', 'Invalid key'); + } + + + if (self::$soap_timeout && + $t > ($session->get('soap_time') + self::$soap_timeout) + ) { + throw new SoapFault('Client', 'Expired key'); + } + + /* otherwise, we're ok. update the timestamp */ + + $session->set('soap_time', $t); + } + + /** + * Authentication wrapper to the UF Class + * + * @param string $name Login name + * @param string $pass Password + * + * @return string The SOAP Client key + * @access public + * @static + */ + public function authenticate($name, $pass, $loadCMSBootstrap = FALSE) { + require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->ufClass) . '.php'); + + if ($this->ufClass == 'CRM_Utils_System_Joomla'){ + $loadCMSBootstrap = true; + } + + $className = $this->ufClass; + $result =& $className::authenticate($name, $pass, $loadCMSBootstrap ); + + if (empty($result)) { + throw new SoapFault('Client', 'Invalid login'); + } + + $session = CRM_Core_Session::singleton(); + $session->set('soap_key', $result[2]); + $session->set('soap_time', time()); + + return sha1($result[2]); + } + + /*** MAILER API ***/ + public function mailer_event_bounce($key, $job, $queue, $hash, $body) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'time_stamp' => date('YmdHis'), + 'event_queue_id' => $queue, + 'hash' => $hash, + 'body' => $body, + 'version' => 3, + ); + return civicrm_api('Mailing', 'event_bounce', $params); + } + + public function mailer_event_unsubscribe($key, $job, $queue, $hash) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'time_stamp' => date('YmdHis'), + 'org_unsubscribe' => 0, + 'event_queue_id' => $queue, + 'hash' => $hash, + 'version' => 3, + ); + return civicrm_api('MailingGroup', 'event_unsubscribe', $params); + } + + public function mailer_event_domain_unsubscribe($key, $job, $queue, $hash) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'time_stamp' => date('YmdHis'), + 'org_unsubscribe' => 1, + 'event_queue_id' => $queue, + 'hash' => $hash, + 'version' => 3, + ); + return civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params); + } + + public function mailer_event_resubscribe($key, $job, $queue, $hash) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'time_stamp' => date('YmdHis'), + 'org_unsubscribe' => 0, + 'event_queue_id' => $queue, + 'hash' => $hash, + 'version' => 3, + ); + return civicrm_api('MailingGroup', 'event_resubscribe', $params); + } + + public function mailer_event_subscribe($key, $email, $domain, $group) { + $this->verify($key); + $params = array( + 'email' => $email, + 'group_id' => $group, + 'version' => 3, + ); + return civicrm_api('MailingGroup', 'event_subscribe', $params); + } + + public function mailer_event_confirm($key, $contact, $subscribe, $hash) { + $this->verify($key); + $params = array( + 'contact_id' => $contact, + 'subscribe_id' => $subscribe, + 'time_stamp' => date('YmdHis'), + 'event_subscribe_id' => $subscribe, + 'hash' => $hash, + 'version' => 3, + ); + return civicrm_api('Mailing', 'event_confirm', $params); + } + + public function mailer_event_reply($key, $job, $queue, $hash, $bodyTxt, $rt, $bodyHTML = NULL, $fullEmail = NULL) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'event_queue_id' => $queue, + 'hash' => $hash, + 'bodyTxt' => $bodyTxt, + 'replyTo' => $rt, + 'bodyHTML' => $bodyHTML, + 'fullEmail' => $fullEmail, + 'time_stamp' => date('YmdHis'), + 'version' => 3, + ); + return civicrm_api('Mailing', 'event_reply', $params); + } + + public function mailer_event_forward($key, $job, $queue, $hash, $email) { + $this->verify($key); + $params = array( + 'job_id' => $job, + 'event_queue_id' => $queue, + 'hash' => $hash, + 'email' => $email, + 'version' => 3, + ); + return civicrm_api('Mailing', 'event_forward', $params); + } + + public function get_contact($key, $params) { + $this->verify($key); + $params['version'] = 3; + return civicrm_api('contact', 'get', $params); + } +} + diff --git a/CRM/Utils/System/Soap.php b/CRM/Utils/System/Soap.php new file mode 100644 index 0000000000..c8d2c24704 --- /dev/null +++ b/CRM/Utils/System/Soap.php @@ -0,0 +1,201 @@ +userFramework; + $config->userFramework = 'Soap'; + + self::$ufClass = $config->userFrameworkClass; + $config->userFrameworkClass = 'CRM_Utils_System_Soap'; + } + + /** + * Get the locale set in the hosting CMS + * + * @return null as the language is set elsewhere + */ + function getUFLocale() { + return NULL; + } + + /** + * Get user login URL for hosting CMS (method declared in each CMS system class) + * + * @param string $destination - if present, add destination to querystring (works for Drupal only) + * + * @return string - loginURL for the current CMS + * @static + */ + public function getLoginURL($destination = '') { + throw new Exception("Method not implemented: getLoginURL"); + } +} +