Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

153
service/core/NusoapSoap.php Executable file
View File

@@ -0,0 +1,153 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require('service/core/SugarSoapService.php');
require('include/nusoap/nusoap.php');
/**
* This is an abstract class for the soap implementation for using NUSOAP. This class is responsible for making
* all NUSOAP call by passing the client's request to NUSOAP server and seding response back to client
*
*/
abstract class NusoapSoap extends SugarSoapService{
/**
* This is the constructor. It creates an instance of NUSOAP server.
*
* @param String $url - This is the soap URL
* @access public
*/
public function __construct($url){
$GLOBALS['log']->info('Begin: NusoapSoap->__construct');
$this->server = new soap_server();
$this->soapURL = $url;
$this->server->configureWSDL('sugarsoap', $this->getNameSpace(), $url);
if(!isset($GLOBALS['HTTP_RAW_POST_DATA']))$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
parent::__construct();
$GLOBALS['log']->info('End: NusoapSoap->__construct');
} // ctor
/**
* It passes request data to NUSOAP server and sends response back to client
* @access public
*/
public function serve(){
$GLOBALS['log']->info('Begin: NusoapSoap->serve');
ob_clean();
$this->server->service($GLOBALS['HTTP_RAW_POST_DATA']);
ob_end_flush();
flush();
$GLOBALS['log']->info('End: NusoapSoap->serve');
} // fn
/**
* This method registers all the complex type with NUSOAP server so that proper WSDL can be generated
*
* @param String $name - name of complex type
* @param String $typeClass - (complexType|simpleType|attribute)
* @param String $phpType - array or struct
* @param String $compositor - (all|sequence|choice)
* @param String $restrictionBase - SOAP-ENC:Array or empty
* @param Array $elements - array ( name => array(name=>'',type=>'') )
* @param Array $attrs - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
* @param String $arrayType - arrayType: namespace:name (xsd:string)
* @access public
*/
public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
$this->server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
} // fn
/**
* This method registers all the functions you want to expose as services with NUSOAP
*
* @param String $function - name of the function
* @param Array $input - assoc array of input values: key = param name, value = param type
* @param Array $output - assoc array of output values: key = param name, value = param type
* @access public
*/
function registerFunction($function, $input, $output){
if(in_array($function, $this->excludeFunctions))return;
$use = false;
$style = false;
if (isset($_REQUEST['use']) && ($_REQUEST['use'] == 'literal')) {
$use = "literal";
} // if
if (isset($_REQUEST['style']) && ($_REQUEST['style'] == 'document')) {
$style = "document";
} // if
$this->server->register($function, $input, $output, $this->getNameSpace(), '',$style, $use);
} // fn
/**
* This function registers implementation class name with NUSOAP so when NUSOAP makes a call to a funciton,
* it will be made on this class object
*
* @param String $implementationClass
* @access public
*/
function registerImplClass($implementationClass){
$GLOBALS['log']->info('Begin: NusoapSoap->registerImplClass');
if (empty($implementationClass)) {
$implementationClass = $this->implementationClass;
} // if
$this->server->register_class($implementationClass);
$GLOBALS['log']->info('End: NusoapSoap->registerImplClass');
} // fn
/**
* Sets the name of the registry class
*
* @param String $registryClass
* @access public
*/
function registerClass($registryClass){
$GLOBALS['log']->info('Begin: NusoapSoap->registerClass');
$this->registryClass = $registryClass;
$GLOBALS['log']->info('End: NusoapSoap->registerClass');
} // fn
/**
* This function sets the fault object on the NUSOAP
*
* @param SoapError $errorObject - This is an object of type SoapError
* @access public
*/
public function error($errorObject){
$GLOBALS['log']->info('Begin: NusoapSoap->error');
$this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
$GLOBALS['log']->info('Begin: NusoapSoap->error');
} // fn
} // clazz

173
service/core/PHP5Soap.php Executable file
View File

@@ -0,0 +1,173 @@
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
<?php
require('service/core/SugarSoapService.php');
require('include/nusoap/nusoap.php');
abstract class PHP5Soap extends SugarSoapService{
private $nusoap_server = null;
public function __construct($url){
$this->soapURL = $url;
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
global $HTTP_RAW_POST_DATA;
if(!isset($HTTP_RAW_POST_DATA)) {
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
}
parent::__construct();
}
public function setObservers() {
} // fn
/**
* Serves the Soap Request
* @return
*/
public function serve(){
ob_clean();
global $HTTP_RAW_POST_DATA;
$GLOBALS['log']->debug("I am here1 ". $HTTP_RAW_POST_DATA);
$qs = '';
if (isset($_SERVER['QUERY_STRING'])) {
$qs = $_SERVER['QUERY_STRING'];
} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$qs = $HTTP_SERVER_VARS['QUERY_STRING'];
} else {
$qs = '';
}
if (stristr($qs, 'wsdl') || $HTTP_RAW_POST_DATA == ''){
$wsdlCacheFile = $this->getWSDLPath(false);
if (stristr($qs, 'wsdl')) {
if($fh = @sugar_fopen($wsdlCacheFile, "r")) {
$contents = fread($fh, filesize($wsdlCacheFile));
fclose($fh);
header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
print $contents;
} // if
} else {
$this->nusoap_server->service($HTTP_RAW_POST_DATA);
} // else
} else {
$this->server->handle();
}
ob_end_flush();
flush();
}
private function generateSoapServer() {
if ($this->server == null) {
$soap_url = $this->getSoapURL() . "?wsdl";
$this->server = new SoapServer($this->getWSDLPath(true), array('soap_version'=>SOAP_1_2, 'encoding'=>'ISO-8859-1'));
}
} // fn
private function generateNuSoap() {
if ($this->nusoap_server == null) {
$this->nusoap_server = new soap_server();
$this->nusoap_server->configureWSDL('sugarsoap', $this->getNameSpace(), "");
$this->nusoap_server->register_class('SugarWebServiceImpl');
} // if
} // fn
public function getWSDLPath($generateWSDL) {
global $sugar_config;
$uploadDir = $sugar_config['upload_dir'];
$wsdlURL = $this->getSoapURL().'?wsdl';
$wsdlCacheFile = $uploadDir.'/wsdlcache-' . md5($wsdlURL);
if ($generateWSDL) {
$oldqs = $_SERVER['QUERY_STRING'];
$_SERVER['QUERY_STRING'] = "wsdl";
$this->nusoap_server->service($wsdlURL);
$_SERVER['QUERY_STRING'] = $oldqs;
if($fh = @sugar_fopen($wsdlCacheFile, "w")) {
fputs($fh, ob_get_contents());
fclose($fh);
} // if
return $wsdlCacheFile;
//ob_clean();
} else {
return $wsdlCacheFile;
}
} // fn
public function getNameSpace() {
return $this->soapURL;
} // fn
/**
* This function allows specifying what version of PHP soap to use
* PHP soap supports version 1.1 and 1.2.
* @return
* @param $version String[optional]
*/
public function setSoapVersion($version='1.1'){
//PHP SOAP supports 1.1 and 1.2 only currently
$this->soap_version = ($version == '1.2')?'1.2':'1.1';
}
public function error($errorObject){
$this->server->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription()); }
public function registerImplClass($implementationClass){
if (empty($implementationClass)) {
$implementationClass = $this->implementationClass;
} // if
$this->generateSoapServer();
$this->server->setClass($implementationClass);
parent::setObservers();
}
function registerClass($registryClass){
$this->registryClass = $registryClass;
}
public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType=''){
$this->nusoap_server->wsdl->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
}
function registerFunction($function, $input, $output){
if(in_array($function, $this->excludeFunctions))return;
if ($this->nusoap_server == null) {
$this->generateNuSoap();
} // if
$this->nusoap_server->register($function, $input, $output, $this->getNameSpace());
}
}

113
service/core/REST/SugarRest.php Executable file
View File

@@ -0,0 +1,113 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* This class is a base class implementation of REST protocol
*
*/
class SugarRest{
/**
* Constructor
*
* @param String $implementation - name of the implementation class
*/
function __construct($implementation){
$this->implementation = $implementation;
} // fn
/**
* It will json encode version of the input object
*
* @param array $input - assoc array of input values: key = param name, value = param type
* @return String - print's $input object
*/
function generateResponse($input){
print_r($input);
} // fn
/**
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
*
* @return unknown
*/
function serve(){
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
if (empty($_REQUEST['method'])) {
echo '<pre>';
$reflect = new ReflectionClass(get_class($this->implementation));
$restWSDL = $reflect->__toString();
$restWSDL = preg_replace('/@@.*/', "", $restWSDL);
echo $restWSDL;
}else{
$er = new SoapError();
$er->set_error('invalid_call');
$this->fault($er);
}
}else{
$method = $_REQUEST['method'];
return $this->implementation->$method();
} // else
} // fn
/**
* This function sends response to client containing error object
*
* @param SoapError $errorObject - This is an object of type SoapError
* @access public
*/
function fault($errorObject){
$this->faultServer->generateFaultResponse($errorObject);
} // fn
function generateFaultResponse($errorObject){
//ob_clean();
$GLOBALS['log']->info('In SugarRest->fault. Setting fault object on response');
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: text/html; charset="ISO-8859-1"');
echo '<br>500 Internal Server Error <br>';
if(is_object($errorObject)){
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
$GLOBALS['log']->error($error);
echo $error;
}else{
$GLOBALS['log']->error(var_export($errorObject, true));
print_r($errorObject);
} // else
}
} // clazz

View File

@@ -0,0 +1,103 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/REST/SugarRestSerialize.php');
/**
* This class is a JSON implementation of REST protocol
*
*/
class SugarRestJSON extends SugarRestSerialize{
/**
* It will json encode the input object and echo's it
*
* @param array $input - assoc array of input values: key = param name, value = param type
* @return String - echos json encoded string of $input
*/
function generateResponse($input){
$json = getJSONObj();
ob_clean();
if (isset($this->faultObject)) {
$this->generateFaultResponse($this->faultObject);
} else {
echo $json->encode($input);
}
} // fn
/**
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
*
* @return unknown
*/
function serve(){
$GLOBALS['log']->info('Begin: SugarRestJSON->serve');
$json_data = !empty($_REQUEST['rest_data'])? $_REQUEST['rest_data']: '';
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
$er = new SoapError();
$er->set_error('invalid_call');
$this->fault($er);
}else{
$method = $_REQUEST['method'];
$json = getJSONObj();
$data = $json->decode(from_html($json_data));
if(!is_array($data))$data = array($data);
$GLOBALS['log']->info('End: SugarRestJSON->serve');
return call_user_func_array(array( $this->implementation, $method),$data);
} // else
} // fn
/**
* This function sends response to client containing error object
*
* @param SoapError $errorObject - This is an object of type SoapError
* @access public
*/
function fault($errorObject){
$this->faultServer->faultObject = $errorObject;
} // fn
function generateFaultResponse($errorObject){
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
$GLOBALS['log']->error($error);
$json = getJSONObj();
ob_clean();
echo $json->encode($errorObject);
} // fn
} // class

View File

@@ -0,0 +1,138 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/REST/SugarRest.php');
/**
* This class is a serialize implementation of REST protocol
*
*/
class SugarRestRSS extends SugarRest{
/**
* It will serialize the input object and echo's it
*
* @param array $input - assoc array of input values: key = param name, value = param type
* @return String - echos serialize string of $input
*/
function generateResponse($input){
$method = !empty($_REQUEST['method'])? $_REQUEST['method']: '';
if($method != 'get_entry_list')$this->fault('RSS currently only supports the get_entry_list method');
ob_clean();
$this->generateResponseHeader($input['result_count']);
$this->generateItems($input);
$this->generateResponseFooter();
} // fn
function generateResponseHeader($count){
$date = gmdate("D, d M Y H:i:s") . " GMT";
echo'<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>SugarCRM RSS Feed</title>
<link>http://cnn.com</link>
<description>' . $count. ' records found</description>
<pubDate>' . $date . '</pubDate>
<generator>SugarCRM</generator>
<ttl>' . $count . '</ttl>
';
}
function generateItems($input){
if(!empty($input['entry_list'])){
foreach($input['entry_list'] as $item){
$this->generateItem($item);
}
}
}
function generateItem($item){
echo "<item>\n";
$name = !empty($item['name_value_list']['name'])?htmlentities( $item['name_value_list']['name']): '';
echo "<title>$name</title>\n";
echo "<link>". $GLOBALS['sugar_config']['site_url'] . htmlentities('/index.php?module=' . $item['module_name']. '&record=' . $item['id']) . "</link>\n";
echo "<description><![CDATA[";
$displayFieldNames = true;
if(count($item['name_value_list']) == 2 &&isset($item['name_value_list']['name']))$displayFieldNames = false;
foreach($item['name_value_list'] as $k=>$v){
if($k =='name')continue;
if($k == 'date_modified')continue;
if($displayFieldNames) echo '<b>' .htmlentities( $k) . ':<b>&nbsp;';
echo htmlentities( $v) . "\n<br>";
}
echo "]]></description>\n";
if(!empty($item['name_value_list']['date_modified'])){
$date = date("D, d M Y H:i:s", strtotime($item['name_value_list']['date_modified'])) . " GMT";
echo "<pubDate>$date</pubDate>";
}
echo "<guid>" . $item['id']. "</guid>\n";
echo "</item>\n";
}
function generateResponseFooter(){
echo'</channel></rss>';
}
/**
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
*
* @return unknown
*/
function serve(){
$this->fault('RSS is not a valid input_type');
} // fn
function fault($faultObject){
ob_clean();
$this->generateResponseHeader();
echo '<item><name>';
if(is_object($errorObject)){
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
$GLOBALS['log']->error($error);
}else{
$GLOBALS['log']->error(var_export($errorObject, true));
$error = var_export($errorObject, true);
} // else
echo $error;
echo '</name></item>';
$this->generateResponseFooter();
}
} // clazz

View File

@@ -0,0 +1,99 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/REST/SugarRest.php');
/**
* This class is a serialize implementation of REST protocol
*
*/
class SugarRestSerialize extends SugarRest{
/**
* It will serialize the input object and echo's it
*
* @param array $input - assoc array of input values: key = param name, value = param type
* @return String - echos serialize string of $input
*/
function generateResponse($input){
ob_clean();
if (isset($this->faultObject)) {
$this->generateFaultResponse($this->faultObject);
} else {
echo serialize($input);
}
} // fn
/**
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
*
* @return unknown
*/
function serve(){
$GLOBALS['log']->info('Begin: SugarRestSerialize->serve');
$data = !empty($_REQUEST['rest_data'])? $_REQUEST['rest_data']: '';
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
$er = new SoapError();
$er->set_error('invalid_call');
$this->fault($er);
}else{
$method = $_REQUEST['method'];
$data = unserialize(from_html($data));
if(!is_array($data))$data = array($data);
$GLOBALS['log']->info('End: SugarRestSerialize->serve');
return call_user_func_array(array( $this->implementation, $method),$data);
} // else
} // fn
/**
* This function sends response to client containing error object
*
* @param SoapError $errorObject - This is an object of type SoapError
* @access public
*/
function fault($errorObject){
$this->faultServer->faultObject = $errorObject;
} // fn
function generateFaultResponse($errorObject){
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
$GLOBALS['log']->error($error);
ob_clean();
echo serialize($errorObject);
} // fn
} // clazz

File diff suppressed because it is too large Load Diff

195
service/core/SugarRestService.php Executable file
View File

@@ -0,0 +1,195 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/SugarWebService.php');
require_once('service/core/SugarRestServiceImpl.php');
/**
* Base class for rest services
*
*/
class SugarRestService extends SugarWebService{
protected $implementationClass = 'SugarRestServiceImpl';
protected $restURL = "";
protected $registeredFunc = array();
/**
* Constructor.
*
* @param String $url - REST url
*/
function __construct($url){
$GLOBALS['log']->info('Begin: SugarRestService->__construct');
$this->restURL = $url;
$responseTypeString = 'SugarRest';
if(!empty($_REQUEST['response_type'])) {
$responseTypeString = clean_string($_REQUEST['response_type'], 'ALPHANUM');
if (strcasecmp($responseTypeString, 'JSON') === 0) {
$responseTypeString = 'SugarRest'. 'JSON';
} elseif (strcasecmp($responseTypeString, 'RSS') === 0) {
$responseTypeString = 'SugarRest'. 'RSS';
} elseif(strcasecmp($responseTypeString, 'Serialize') === 0) {
$responseTypeString = 'SugarRest'. 'Serialize';
}
} // if
$this->responseClass = $responseTypeString;
//$this->responseClass = (!empty($_REQUEST['response_type']))?'SugarRest'.clean_string($_REQUEST['response_type'], 'ALPHANUM'): 'SugarRest';
if(!file_exists('service/core/REST/' . $this->responseClass. '.php'))$this->responseClass = 'SugarRest';
$this->serverClass = (!empty($_REQUEST['input_type']))?'SugarRest'.clean_string($_REQUEST['input_type'], 'ALPHANUM'): 'SugarRest';
$GLOBALS['log']->info('SugarRestService->__construct serverclass = ' . $this->serverClass);
if(!file_exists('service/core/REST/' . $this->serverClass . '.php'))$this->serverClass = 'SugarRest';
require_once('service/core/REST/'. $this->serverClass . '.php');
$GLOBALS['log']->info('End: SugarRestService->__construct');
} // ctor
/**
* Its a no op method
*
* @access public
*/
public function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType){
} // fn
/**
* This method registers all the functions you want to expose as services with REST
*
* @param String $function - name of the function
* @param Array $input - assoc array of input values: key = param name, value = param type
* @param Array $output - assoc array of output values: key = param name, value = param type
* @access public
*/
function registerFunction($function, $input, $output){
if(in_array($function, $this->excludeFunctions))return;
$this->registeredFunc[$function] = array('input'=> $input, 'output'=>$output);
} // fn
/**
* It passes request data to REST server and sends response back to client
* @access public
*/
function serve(){
$GLOBALS['log']->info('Begin: SugarRestService->serve');
require_once('service/core/REST/'. $this->responseClass . '.php');
$response = $this->responseClass;
$responseServer = new $response($this->implementation);
$this->server->faultServer = $responseServer;
$this->responseServer->faultServer = $responseServer;
$responseServer->generateResponse($this->server->serve());
$GLOBALS['log']->info('End: SugarRestService->serve');
} // fn
/**
* Enter description here...
*
* @param Array $excludeFunctions - All the functions you don't want to register
*/
function register($excludeFunctions = array()){
} // fn
/**
* This mehtod returns registered implementation class
*
* @return String - implementationClass
* @access public
*/
public function getRegisteredImplClass() {
return $this->implementationClass;
} // fn
/**
* This mehtod returns registry class
*
* @return String - registryClass
* @access public
*/
public function getRegisteredClass() {
return $this->registryClass;
} // fn
/**
* Sets the name of the registry class
*
* @param String $registryClass
* @access public
*/
function registerClass($registryClass){
$this->registryClass = $registryClass;
}
/**
* This function registers implementation class name and creates an instance of rest implementation class
* it will be made on this class object
*
* @param String $implementationClass
* @access public
*/
function registerImplClass($className){
$GLOBALS['log']->info('Begin: SugarRestService->registerImplClass');
$this->implementationClass = $className;
$this->implementation = new $this->implementationClass();
$this->server = new $this->serverClass($this->implementation);
$this->server->registerd = $this->registeredFunc;
$GLOBALS['log']->info('End: SugarRestService->registerImplClass');
} // fn
/**
* This function sets the fault object on the REST
*
* @param SoapError $errorObject - This is an object of type SoapError
* @access public
*/
function error($errorObject){
$GLOBALS['log']->info('Begin: SugarRestService->error');
$this->server->fault($errorObject);
$GLOBALS['log']->info('Begin: SugarRestService->error');
} // fn
/**
* This mehtod returns server
*
* @return String - server
* @access public
*/
function getServer(){
return $this->server;
} // fn
}

View File

@@ -0,0 +1,49 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* This class is an implemenatation class for all the rest services
*/
require_once('service/core/SugarWebServiceImpl.php');
class SugarRestServiceImpl extends SugarWebServiceImpl {
function md5($string){
return md5($string);
}
}
require_once('service/core/SugarRestUtils.php');
SugarRestServiceImpl::$helperObject = new SugarRestUtils();

39
service/core/SugarRestUtils.php Executable file
View File

@@ -0,0 +1,39 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/SoapHelperWebService.php');
class SugarRestUtils extends SoapHelperWebServices {
}

155
service/core/SugarSoapService.php Executable file
View File

@@ -0,0 +1,155 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('service/core/SugarWebService.php');
require_once('service/core/SugarWebServiceImpl.php');
/**
* This ia an abstract class for the soapservice. All the global fun
*
*/
abstract class SugarSoapService extends SugarWebService{
protected $soap_version = '1.1';
protected $namespace = 'http://www.sugarcrm.com/sugarcrm';
protected $implementationClass = 'SugarWebServiceImpl';
protected $registryClass = "";
protected $soapURL = "";
/**
* This is an abstract method. The implementation method should registers all the functions you want to expose as services.
*
* @param String $function - name of the function
* @param Array $input - assoc array of input values: key = param name, value = param type
* @param Array $output - assoc array of output values: key = param name, value = param type
* @access public
*/
abstract function registerFunction($function, $input, $output);
/**
* This is an abstract method. This implementation method should register all the complex type
*
* @param String $name - name of complex type
* @param String $typeClass - (complexType|simpleType|attribute)
* @param String $phpType - array or struct
* @param String $compositor - (all|sequence|choice)
* @param String $restrictionBase - SOAP-ENC:Array or empty
* @param Array $elements - array ( name => array(name=>'',type=>'') )
* @param Array $attrs - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
* @param String $arrayType - arrayType: namespace:name (xsd:string)
* @access public
*/
abstract function registerType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs=array(), $arrayType='');
/**
* Constructor
*
*/
protected function __construct(){
$this->setObservers();
}
/**
* This method sets the soap server object on all the observers
* @access public
*/
public function setObservers() {
global $observers;
if(!empty($observers)){
foreach($observers as $observer) {
if(method_exists($observer, 'set_soap_server')) {
$observer->set_soap_server($this->server);
}
}
}
} // fn
/**
* This method returns the soapURL
*
* @return String - soapURL
* @access public
*/
public function getSoapURL(){
return $this->soapURL;
}
public function getSoapVersion(){
return $this->soap_version;
}
/**
* This method returns the namespace
*
* @return String - namespace
* @access public
*/
public function getNameSpace(){
return $this->namespace;
}
/**
* This mehtod returns registered implementation class
*
* @return String - implementationClass
* @access public
*/
public function getRegisteredImplClass() {
return $this->implementationClass;
}
/**
* This mehtod returns registry class
*
* @return String - registryClass
* @access public
*/
public function getRegisteredClass() {
return $this->registryClass;
}
/**
* This mehtod returns server
*
* @return String -server
* @access public
*/
public function getServer() {
return $this->server;
} // fn
} // class

View File

@@ -0,0 +1,52 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* This is an abstract class for all the web services.
* All type of web services should provide proper implementation of all the abstract methods
*/
abstract class SugarWebService{
protected $server = null;
protected $excludeFunctions = array();
abstract function register($excludeFunctions = array());
abstract function registerImplClass($class);
abstract function getRegisteredImplClass();
abstract function registerClass($class);
abstract function getRegisteredClass();
abstract function serve();
abstract function error($errorObject);
}

File diff suppressed because it is too large Load Diff

62
service/core/webservice.php Executable file
View File

@@ -0,0 +1,62 @@
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program 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 along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/**
* This file intialize the service class and does all the setters based on the values provided in soap/rest entry point
* and calls serve method which takes the request and send response back to the client
*/
ob_start();
require('include/entryPoint.php');
require_once('soap/SoapError.php');
require_once('SoapHelperWebService.php');
require_once('SugarRestUtils.php');
require_once($webservice_path);
require_once($registry_path);
$url = $GLOBALS['sugar_config']['site_url'].$location;
$service = new $webservice_class($url);
$service->registerClass($registry_class);
$service->register();
$service->registerImplClass($webservice_impl_class);
// set the service object in the global scope so that any error, if happens, can be set on this object
global $service_object;
$service_object = $service;
$service->serve();