*
* Maintain list and provide send interface to remote phpgw servers *
* Copyright (C) 2001 Miles Lott *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
* 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 $urlparts = array(
'xmlrpc' => '/phpgroupware/xmlrpc.php',
'soap' => '/phpgroupware/soap.php'
);
/*
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='')
{
$this->db = $GLOBALS['phpgw']->db;
if($serverid)
{
$this->serverid = intval($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=True)
{
$cmd = '$this->_send_' . $this->mode . '_' . $this->security . '($method_name, $args, $url, $debug);';
eval($cmd);
return $this->result;
}
function _split_url($url)
{
preg_match('/^(.*?\/\/.*?)(\/.*)/',$url,$matches);
$hostpart = $matches[1];
$uri = $matches[2];
return array($uri,$hostpart);
}
function _send_xmlrpc_ssl($method_name, $args, $url, $debug=True)
{
list($uri,$hostpart) = $this->_split_url($url . $this->urlparts['xmlrpc']);
$hostpart = ereg_replace('https://','',$hostpart);
$hostpart = ereg_replace('http://','',$hostpart);
if(gettype($args) != 'array')
{
$arr[] = CreateObject('phpgwapi.xmlrpcval',$args,'string');
}
else
{
while(list($key,$val) = @each($args))
{
$arr[] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
}
}
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
$this->debug("
" . htmlentities($f->serialize()) . "
\n",$debug);
$c = CreateObject('phpgwapi.xmlrpc_client',$this->urlparts['xmlrpc'], $hostpart, 80);
$c->setDebug(0);
$r = $c->send($f,0,True);
if (!$r)
{
$this->debug('send failed');
}
$v = $r->value();
if (!$r->faultCode())
{
$this->debug('I got this value back