Revert PR#980 Restore SOAP code CRM-12343
authorColeman Watts <coleman@civicrm.org>
Fri, 26 Jul 2013 23:10:10 +0000 (16:10 -0700)
committerColeman Watts <coleman@civicrm.org>
Fri, 26 Jul 2013 23:10:10 +0000 (16:10 -0700)
----------------------------------------
* CRM-12343: Remove Soap code
  http://issues.civicrm.org/jira/browse/CRM-12343

CRM/Core/Permission/Soap.php [new file with mode: 0644]
CRM/Utils/Hook/Soap.php [new file with mode: 0644]
CRM/Utils/SoapServer.php [new file with mode: 0644]
CRM/Utils/System/Soap.php [new file with mode: 0644]

diff --git a/CRM/Core/Permission/Soap.php b/CRM/Core/Permission/Soap.php
new file mode 100644 (file)
index 0000000..cb52b5b
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ *
+ */
+class CRM_Core_Permission_Soap extends CRM_Core_Permission_Base {
+
+  /**
+   * given a permission string, check for access requirements
+   *
+   * @param string $str the permission to check
+   *
+   * @return boolean true if yes, else false
+   * @access public
+   */
+
+  function check($str) {
+    return TRUE;
+  }
+}
+
diff --git a/CRM/Utils/Hook/Soap.php b/CRM/Utils/Hook/Soap.php
new file mode 100644 (file)
index 0000000..424afe2
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CiviCRM_Hook
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id: $
+ *
+ */
+class CRM_Utils_Hook_Soap extends CRM_Utils_Hook {
+  function invoke($numParams,
+    &$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
+    $fnSuffix
+  ) {
+    // suppress all hok calls during soap
+    return;
+  }
+}
+
diff --git a/CRM/Utils/SoapServer.php b/CRM/Utils/SoapServer.php
new file mode 100644 (file)
index 0000000..348c1e0
--- /dev/null
@@ -0,0 +1,256 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class handles all SOAP client requests.
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+class CRM_Utils_SoapServer {
+
+  /**
+   * Number of seconds we should let a soap process idle
+   * @static
+   */
+  static $soap_timeout = 0;
+
+  /**
+   * Cache the actual UF Class
+   */
+  public $ufClass;
+
+  /**
+   * Class constructor.  This caches the real user framework class locally,
+   * so we can use it for authentication and validation.
+   *
+   * @param  string $uf       The userframework class
+   */
+  public function __construct() {
+    // any external program which call SoapServer is responsible for
+    // creating and attaching the session
+    $args = func_get_args();
+    $this->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 (file)
index 0000000..c8d2c24
--- /dev/null
@@ -0,0 +1,201 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * Soap specific stuff goes here
+ */
+class CRM_Utils_System_Soap extends CRM_Utils_System_Base {
+
+  /**
+   * UF container variables
+   */
+  static $uf = NULL;
+  static $ufClass = NULL;
+
+  /**
+   * sets the title of the page
+   *
+   * @param string $title title  for page
+   * @paqram string $pageTitle
+   *
+   * @return void
+   * @access public
+   */
+  function setTitle($title, $pageTitle) {
+    return;
+  }
+
+  /**
+   * given a permission string, check for access requirements
+   *
+   * @param string $str the permission to check
+   *
+   * @return boolean true if yes, else false
+   * @static
+   * @access public
+   */
+  function checkPermission($str) {
+    return TRUE;
+  }
+
+  /**
+   * Append an additional breadcrumb tag to the existing breadcrumb
+   *
+   * @param string $title
+   * @param string $url
+   *
+   * @return void
+   * @access public
+   */
+  function appendBreadCrumb($title, $url) {
+    return;
+  }
+
+  /**
+   * Append a string to the head of the html file
+   *
+   * @param string $head the new string to be appended
+   *
+   * @return void
+   * @access public
+   */
+  function addHTMLHead($head) {
+    return;
+  }
+
+  /**
+   * Generate an internal CiviCRM URL
+   *
+   * @param $path     string   The path being linked to, such as "civicrm/add"
+   * @param $query    string   A query string to append to the link.
+   * @param $absolute boolean  Whether to force the output to be an absolute link (beginning with http:).
+   *                           Useful for links that will be displayed outside the site, such as in an
+   *                           RSS feed.
+   * @param $fragment string   A fragment identifier (named anchor) to append to the link.
+   *
+   * @return string            an HTML string containing a link to the given path.
+   * @access public
+   *
+   */
+  function url($path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL) {
+    if (isset(self::$ufClass)) {
+      $className = self::$ufClass;
+      $url = $className::url($path, $query, $absolute, $fragment);
+      return $url;
+    }
+    else {
+      return NULL;
+    }
+  }
+
+  /**
+   * figure out the post url for the form
+   *
+   * @param the default action if one is pre-specified
+   *
+   * @return string the url to post the form
+   * @access public
+   */
+  function postURL($action) {
+    return NULL;
+  }
+
+  /**
+   * Function to set the email address of the user
+   *
+   * @param object $user handle to the user object
+   *
+   * @return void
+   * @access public
+   */
+  function setEmail(&$user) {}
+
+  /**
+   * Authenticate a user against the real UF
+   *
+   * @param string $name      Login name
+   * @param string $pass      Login password
+   *
+   * @return array            Result array
+   * @access public
+   */
+  function &authenticate($name, $pass) {
+    if (isset(self::$ufClass)) {
+      $className = self::$ufClass;
+      $result =& $className::authenticate($name, $pass);
+      return $result;
+    }
+    else {
+      return NULL;
+    }
+  }
+
+  /**
+   * Swap the current UF for soap
+   *
+   * @access public
+   */
+  public function swapUF() {
+    $config = CRM_Core_Config::singleton();
+
+    self::$uf = $config->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");
+  }
+}
+