Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable extern/soap.php. Remove implementation and tests. #25317

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
319 changes: 9 additions & 310 deletions CRM/Utils/SoapServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,322 +10,21 @@
*/

/**
* This class handles all SOAP client requests.
* (OBSOLETE) This class previously handled SOAP requests.
*
* The class is still referenced in some other repos. A stub is preserved to avoid hard-crashes
* when scanning the codebase.
*
* @deprecated
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Utils_SoapServer {

/**
* Number of seconds we should let a soap process idle
* @var int
*/
public static $soap_timeout = 0;

/**
* Cache the actual UF Class
* @var string
*/
public $ufClass;

/**
* Class constructor. This caches the real user framework class locally,
* so we can use it for authentication and validation.
*
* @internal 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
*/
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().
*
* @throws SoapFault
*/
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.
*
* @param bool $loadCMSBootstrap
*
* @throws SoapFault
* @return string
* The SOAP Client key
*/
public function authenticate($name, $pass, $loadCMSBootstrap = FALSE) {
require_once str_replace('_', DIRECTORY_SEPARATOR, $this->ufClass) . '.php';

if ($this->ufClass == 'CRM_Utils_System_Joomla'
|| $this->ufClass == 'CRM_Utils_System_WordPress') {
$loadCMSBootstrap = TRUE;
}

$result = CRM_Utils_System::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.
*
* @param string $key
* @param int $job
* @param int $queue
* @param string $hash
* @param string $body
*
* @return array|int
* @throws \SoapFault
*/
public function mailer_event_bounce($key, $job, $queue, $hash, $body) {
$this->verify($key);
$params = [
'job_id' => $job,
'time_stamp' => date('YmdHis'),
'event_queue_id' => $queue,
'hash' => $hash,
'body' => $body,
'version' => 3,
];
$result = civicrm_api('Mailing', 'event_bounce', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* Mailer event unsubscribe.
*
* @param string $key
* @param int $job
* @param int $queue
* @param string $hash
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_unsubscribe($key, $job, $queue, $hash) {
$this->verify($key);
$params = [
'job_id' => $job,
'time_stamp' => date('YmdHis'),
'org_unsubscribe' => 0,
'event_queue_id' => $queue,
'hash' => $hash,
'version' => 3,
];
$result = civicrm_api('MailingGroup', 'event_unsubscribe', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $job
* @param $queue
* @param $hash
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_domain_unsubscribe($key, $job, $queue, $hash) {
$this->verify($key);
$params = [
'job_id' => $job,
'time_stamp' => date('YmdHis'),
'org_unsubscribe' => 1,
'event_queue_id' => $queue,
'hash' => $hash,
'version' => 3,
];
$result = civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $job
* @param $queue
* @param $hash
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_resubscribe($key, $job, $queue, $hash) {
$this->verify($key);
$params = [
'job_id' => $job,
'time_stamp' => date('YmdHis'),
'org_unsubscribe' => 0,
'event_queue_id' => $queue,
'hash' => $hash,
'version' => 3,
];
$result = civicrm_api('MailingGroup', 'event_resubscribe', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $email
* @param $domain
* @param $group
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_subscribe($key, $email, $domain, $group) {
$this->verify($key);
$params = [
'email' => $email,
'group_id' => $group,
'version' => 3,
];
$result = civicrm_api('MailingGroup', 'event_subscribe', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $contact
* @param $subscribe
* @param $hash
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_confirm($key, $contact, $subscribe, $hash) {
$this->verify($key);
$params = [
'contact_id' => $contact,
'subscribe_id' => $subscribe,
'time_stamp' => date('YmdHis'),
'event_subscribe_id' => $subscribe,
'hash' => $hash,
'version' => 3,
];
$result = civicrm_api('Mailing', 'event_confirm', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $job
* @param $queue
* @param $hash
* @param $bodyTxt
* @param $rt
* @param null $bodyHTML
* @param null $fullEmail
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_reply($key, $job, $queue, $hash, $bodyTxt, $rt, $bodyHTML = NULL, $fullEmail = NULL) {
$this->verify($key);
$params = [
'job_id' => $job,
'event_queue_id' => $queue,
'hash' => $hash,
'bodyTxt' => $bodyTxt,
'replyTo' => $rt,
'bodyHTML' => $bodyHTML,
'fullEmail' => $fullEmail,
'time_stamp' => date('YmdHis'),
'version' => 3,
];
$result = civicrm_api('Mailing', 'event_reply', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param $job
* @param $queue
* @param $hash
* @param $email
*
* @return array|int
* @throws SoapFault
*/
public function mailer_event_forward($key, $job, $queue, $hash, $email) {
$this->verify($key);
$params = [
'job_id' => $job,
'event_queue_id' => $queue,
'hash' => $hash,
'email' => $email,
'version' => 3,
];
$result = civicrm_api('Mailing', 'event_forward', $params);
return CRM_Utils_Array::encode_items($result);
}

/**
* @param $key
* @param array $params
*
* @return array|int
* @throws SoapFault
*/
public function get_contact($key, $params) {
$this->verify($key);
$params['version'] = 3;
$result = civicrm_api('contact', 'get', $params);
return CRM_Utils_Array::encode_items($result);
public function __call($name, $arguments) {
throw new \SoapFault('obsolete', 'SOAP support is no longer included with civicrm-core.');
// It's removed because (a) the main consumer is no longer live, (b) it's awkward to maintain 'extern/' scripts,
// and (c) there's an extensionized version at https://lab.civicrm.org/extensions/civismtp/
}

}
31 changes: 8 additions & 23 deletions extern/soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@
}
session_start();

require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';

$server = new SoapServer(NULL,
array(
'uri' => 'urn:civicrm',
'soap_version' => SOAP_1_2,
)
);


require_once 'CRM/Utils/SoapServer.php';
$crm_soap = new CRM_Utils_SoapServer();

/* Cache the real UF, override it with the SOAP environment */

$civicrmConfig = CRM_Core_Config::singleton();

$server->setClass('CRM_Utils_SoapServer', $civicrmConfig->userFrameworkClass);

$server->setPersistence(SOAP_PERSISTENCE_SESSION);

$server->handle();
$server = new SoapServer(NULL, [
'uri' => 'urn:civicrm',
'soap_version' => SOAP_1_2,
]);

$server->fault('obsolete', "SOAP support is no longer included with civicrm-core.");
// It's removed because (a) the main consumer is no longer live, (b) it's awkward to maintain 'extern/' scripts,
// and (c) there's an extensionized version at https://lab.civicrm.org/extensions/civismtp/
Loading