Fixes to allow for support of server auth using soap with/without ssl

This commit is contained in:
Miles Lott 2001-08-18 20:31:47 +00:00
parent 050cd9acd2
commit c7edc28716
4 changed files with 62 additions and 72 deletions

View File

@ -152,7 +152,7 @@
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct'); $f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
$this->debug("<pre>" . htmlentities($f->serialize()) . "</pre>\n",$debug); $this->debug("<pre>" . htmlentities($f->serialize()) . "</pre>\n",$debug);
$c = CreateObject('phpgwapi.xmlrpc_client',$this->urlparts['xmlrpc'], $hostpart, 80); $c = CreateObject('phpgwapi.xmlrpc_client',$this->urlparts['xmlrpc'], $hostpart, 80);
$c->setDebug(1); $c->setDebug(0);
$r = $c->send($f,0,True); $r = $c->send($f,0,True);
if (!$r) if (!$r)
{ {
@ -213,88 +213,55 @@
function _send_soap_ssl($method_name, $args, $url, $debug=True) function _send_soap_ssl($method_name, $args, $url, $debug=True)
{ {
/* Not working */ $method_name = str_replace('.','_',$method_name);
return; list($uri,$hostpart) = $this->_split_url($url . $this->urlparts['soap']);
preg_match('/^(.*?\/\/.*?)(\/.*)/',$url,$matches); $hostpart = ereg_replace('https://','',$hostpart);
$hostpart = $matches[1]; $hostpart = ereg_replace('http://','',$hostpart);
$uri = $matches[2]; while(list($key,$val) = @each($args))
$this->debug("opening curl to $url", $debug);
if(gettype($args) != 'array')
{ {
$args[] = $args; $arr[] = CreateObject('phpgwapi.soapval',$key, 'string',$val);
}
$soap_message = CreateObject('phpgwapi.soapmsg',$method_name,$arr,'http://soapinterop.org');
/* print_r($soap_message);exit; */
$soap = CreateObject('phpgwapi.soap_client',$uri,$hostpart);
/* _debug_array($soap);exit; */
if($r = $soap->send($soap_message,$method_name))
{
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
/* _debug_array($soap); */
/* echo $soap->debug_str; */
return $r;
} }
else else
{ {
while(list($key,$val) = @each($args)) $this->debug('Fault Code: ' . $r->ernno . ' Reason "' . $r->errstring . '"<br>',$debug);
{
$arr[$key] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
}
} }
$f = CreateObject('phpgwapi.xmlrpcmsg',$method_name,array($arr));
$content_len = strlen($f->serialize());
$cliversion = $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'];
$http_request = 'POST ' . $uri . ' HTTP/1.0' . "\r\n"
. 'User-Agent: phpGroupware/' . $cliversion . '(PHP) ' . "\r\n"
. 'X-PHPGW-Server: ' . $method_name . ' ' . "\r\n"
. 'Content-Type: text/xml' . "\r\n"
. 'Content-Length: ' . $content_len . "\r\n" . "\r\n"
. $f->serialize();
$this->debug("sending http request:</h3><xmp>\n" . $http_request . "\n</xmp>", $debug);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$hostpart);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_request);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response_buf = curl_exec($ch);
curl_close($ch);
$this->debug("got response:</h3>.<xmp>\n$response_buf\n</xmp>\n", $debug);
$retval = '';
if (strlen($response_buf))
{
$xml_begin = substr($response_buf, strpos($response_buf, "<?xml"));
if (strlen($xml_begin))
{
$retval = xmlrpc_decode($xml_begin);
}
else
{
$this->debug('Error: no xml start found from'.$hostpart.'!');
}
}
else
{
$this->debug('Error: no response from '.$hostpart.'!');
}
return $retval;
} }
function _send_soap_($method_name, $args, $url, $debug=True) function _send_soap_($method_name, $args, $url, $debug=True)
{ {
/* Not working */ $method_name = str_replace('.','_',$method_name);
return; list($uri,$hostpart) = $this->_split_url($url . $this->urlparts['soap']);
$hostpart = ereg_replace('https://','',$hostpart);
$hostpart = ereg_replace('http://','',$hostpart);
while(list($key,$val) = @each($args)) while(list($key,$val) = @each($args))
{ {
$arr[$key] = CreateObject('phpgwapi.soapval',$val, 'string'); $arr[] = CreateObject('phpgwapi.soapval',$key, 'string',$val);
} }
$soap_message = CreateObject('phpgwapi.soapmsg', $soap_message = CreateObject('phpgwapi.soapmsg',$method_name,$arr,'http://soapinterop.org');
$method,
$method_params[$method],
$server['methodNamespace']
);
/* print_r($soap_message);exit; */ /* print_r($soap_message);exit; */
$soap = CreateObject('phpgwapi.soap_client',$server['endpoint']); $soap = CreateObject('phpgwapi.soap_client',$uri,$hostpart);
/* print_r($soap);exit; */ /* _debug_array($soap);exit; */
if($return = $soap->send($soap_message,$server['soapaction'])) if($r = $soap->send($soap_message,$method_name))
{ {
return $return; $this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
/* _debug_array($soap); */
/* echo $soap->debug_str; */
return $r;
}
else
{
$this->debug('Fault Code: ' . $r->ernno . ' Reason "' . $r->errstring . '"<br>',$debug);
} }
} }

View File

@ -42,7 +42,7 @@
$this->server = $server; $this->server = $server;
$this->errno; $this->errno;
$this->errstring; $this->errstring;
$this->debug_flag = False; $this->debug_flag = True;
$this->debug_str = ''; $this->debug_str = '';
$this->username = ''; $this->username = '';
$this->password = ''; $this->password = '';

View File

@ -115,7 +115,7 @@
// get/set methodname // get/set methodname
$this->methodname = $parser->root_struct_name; $this->methodname = $parser->root_struct_name;
$this->debug("method name: $this->methodname"); $this->debug("method name: $this->methodname");
// does method exist? // does method exist?
if(function_exists($this->methodname)) if(function_exists($this->methodname))
{ {
@ -181,7 +181,7 @@
} }
$this->debug("request data: $request_data"); $this->debug("request data: $request_data");
} }
/* if there are return values */ /* if there are return values */
if($this->return_type = $this->get_return_type()) if($this->return_type = $this->get_return_type())
{ {

View File

@ -67,4 +67,27 @@
*/ */
$GLOBALS['soap_defencoding'] = 'UTF-8'; $GLOBALS['soap_defencoding'] = 'UTF-8';
function system_auth($m1,$m2,$m3)
{
$serverdata['server_name'] = $m1;
$serverdata['username'] = $m2;
$serverdata['password'] = $m3;
list($sessionid,$kp3) = $GLOBALS['phpgw']->session->create_server($serverdata['username'].'@'.$serverdata['server_name'],$serverdata['password']);
if($sessionid && $kp3)
{
$rtrn = array(
CreateObject('phpgwapi.soapval','sessionid', 'string',$sessionid),
CreateObject('phpgwapi.soapval','kp3','string',$kp3)
);
}
else
{
$rtrn = array(CreateObject('phpgwapi.soapval','GOAWAY','string','XOXO'));
}
$r = CreateObject('phpgwapi.soapmsg','system_authResponse',$rtrn);
return $r;
}
?> ?>