*
* 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
);
var $trust_relationships = array(
'outbound' => 0, /* No trust, but they may trust us */
'inbound' => 1, /* Trust to make requests of us */
'passthrough' => 2, /* Trust remote server's trusts also */
'bi-directional' => 3, /* We both trust each other */
'bi-dir passthrough' => 4 /* We both trust each other, and we trust the remote server's trusts also */
);
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)
{
if(!function_exists(curl_init))
{
$this->debug('No curl functions available - use of ssl is invalid',$debug);
return False;
}
/* curl Method borrowed from:
http://sourceforge.net/tracker/index.php?func=detail&aid=427359&group_id=23199&atid=377731
*/
list($uri,$hostpart) = $this->_split_url($url . $this->urlparts['xmlrpc']);
$this->debug("opening curl to $url", $debug);
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);
$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: ' . $GLOBALS['HTTP_HOST'] . ' ' . "\r\n"
. 'X-PHPGW-Version: ' . $cliversion . "\r\n"
. 'Content-Type: text/xml' . "\r\n"
. 'Content-Length: ' . $content_len . "\r\n\r\n"
. $f->serialize();
$this->debug("sending http request: