*
* Maintain list and provide send interface to remote phpgw servers *
* Copyright (C) 2001 Miles Lott *
* -------------------------------------------------------------------------*
* This library is part of the eGroupWare API *
* http://www.egroupware.org *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library 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 Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class interserver
{
var $db;
var $accounts;
var $table = 'phpgw_interserv';
var $total = 0;
var $result = '';
var $servers = array();
var $serverid = 0;
var $security = '';
var $mode = '';
var $authed = False;
var $sessionid = '';
var $kp3 = '';
/* These are now entered as defaults if the admin forgot to enter the full URL */
var $urlparts = array();
/*
0/none == no access
1/apps == read app data only
99/all == read accounts and other api data
Two servers must have each other setup as 'all' for full coop
*/
var $trust_levels = array(
'none' => 0,
'apps' => 1,
'all' => 99
);
/*
0 - No trust, but they may trust us
1 - Trust to make requests of us
2 - Trust remote server's trusts also
3 - We both trust each other
4 - We both trust each other, and we trust the remote server's trusts also
*/
var $trust_relationships = array(
'outbound' => 0,
'inbound' => 1,
'passthrough' => 2,
'bi-directional' => 3,
'bi-dir passthrough' => 4
);
var $security_types = array(
'standard' => '',
'ssl' => 'ssl'
);
var $server_modes = array(
'XML-RPC' => 'xmlrpc',
'SOAP' => 'soap'
);
function interserver($serverid='')
{
$url = eregi_replace('https*://[^/]*/','',$GLOBALS['egw_info']['server']['webserver_url']);
$this->urlparts = array(
'xmlrpc' => $url.'/xmlrpc.php',
'soap' => $url.'/soap.php'
);
$this->db = clone($GLOBALS['egw']->db);
if($serverid)
{
$this->serverid = (int)$serverid;
$this->setup();
}
}
function debug($str,$debug=False)
{
if($debug)
{
$this->_debug($str);
}
}
function _debug($err='')
{
if(!$err)
{
return;
}
echo $err . ' ';
}
function setup()
{
$this->read_repository();
if($this->server['trust_level'])
{
$this->accounts = CreateObject('phpgwapi.accounts');
$this->accounts->server = $this->serverid;
}
$this->security = $this->server['server_security'];
$this->mode = $this->server['server_mode'];
}
/* send command to remote server */
function send($method_name, $args, $url, $debug=False)
{
$cmd = '_send_' . ($this->mode ? $this->mode : 'xmlrpc') . '_' . $this->security;
$this->$cmd($method_name, $args, $url, $debug);
return $this->result;
}
function _split_url($url)
{
preg_match('/^(.*?\/\/.*?)(\/.*)/',$url,$matches);
$hostpart = $matches[1];
$hostpart = str_replace('https://','',$hostpart);
$hostpart = str_replace('http://','',$hostpart);
switch($this->mode)
{
case 'soap':
if(!strstr($matches[2],'soap.php'))
{
$matches[2] .= $this->urlparts['soap'];
}
break;
case 'xmlrpc':
if(!strstr($matches[2],'xmlrpc.php'))
{
$matches[2] .= $this->urlparts['xmlrpc'];
}
break;
default:
break;
}
$uri = $matches[2];
return array($uri,$hostpart);
}
function _send_xmlrpc_ssl($method_name, $args, $url, $debug=True)
{
list($uri,$hostpart) = $this->_split_url($url);
if(!@is_array($args))
{
$arr[] = CreateObject('phpgwapi.xmlrpcval',$args,'string');
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'string');
}
else
{
foreach($args as $key => $val)
{
if(@is_array($val))
{
foreach($val as $x => $y)
{
$tmp[$x] = CreateObject('phpgwapi.xmlrpcval',$y, 'string');
}
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$tmp,'struct');
}
else
{
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
}
}
$arr[] = CreateObject('phpgwapi.xmlrpcval',$ele,'struct');
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
}
$this->debug('
' . htmlentities($f->serialize()) . "
\n",$debug);
$c = CreateObject('phpgwapi.xmlrpc_client',$uri, $hostpart, 443);
$c->setCredentials($this->sessionid,$this->kp3);
$c->setDebug($debug);
$r = $c->send($f,0,'https');
if (!$r)
{
$this->debug('send failed');
}
$v = $r->value();
if (!$r->faultCode())
{
$this->debug('I got this value back