2001-08-13 18:24:03 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - phpgw Inter-server communications class *
|
|
|
|
* This file written by Miles Lott <milosch@phpgroupware.org> *
|
|
|
|
* 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;
|
2001-08-15 05:54:15 +02:00
|
|
|
var $result = '';
|
2001-08-13 18:24:03 +02:00
|
|
|
|
|
|
|
var $servers = array();
|
|
|
|
var $serverid = 0;
|
|
|
|
var $security = '';
|
|
|
|
var $mode = '';
|
|
|
|
var $authed = False;
|
2001-08-20 01:55:58 +02:00
|
|
|
var $sessionid = '';
|
|
|
|
var $kp3 = '';
|
2001-11-30 05:46:50 +01:00
|
|
|
|
|
|
|
/* These are now entered as defaults if the admin forgot to enter the full URL */
|
2001-08-13 18:24:03 +02:00
|
|
|
var $urlparts = array(
|
|
|
|
'xmlrpc' => '/phpgroupware/xmlrpc.php',
|
|
|
|
'soap' => '/phpgroupware/soap.php'
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
2001-08-15 19:05:08 +02:00
|
|
|
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
|
2001-08-13 18:24:03 +02:00
|
|
|
*/
|
|
|
|
var $trust_levels = array(
|
|
|
|
'none' => 0,
|
|
|
|
'apps' => 1,
|
|
|
|
'all' => 99
|
|
|
|
);
|
|
|
|
|
2001-08-15 19:05:08 +02:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2001-08-13 18:24:03 +02:00
|
|
|
var $trust_relationships = array(
|
2001-08-15 19:05:08 +02:00
|
|
|
'outbound' => 0,
|
|
|
|
'inbound' => 1,
|
|
|
|
'passthrough' => 2,
|
|
|
|
'bi-directional' => 3,
|
|
|
|
'bi-dir passthrough' => 4
|
2001-08-13 18:24:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2001-08-14 00:17:22 +02:00
|
|
|
$this->security = $this->server['server_security'];
|
|
|
|
$this->mode = $this->server['server_mode'];
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send command to remote server */
|
|
|
|
function send($method_name, $args, $url, $debug=True)
|
|
|
|
{
|
2001-08-15 05:54:15 +02:00
|
|
|
$cmd = '$this->_send_' . $this->mode . '_' . $this->security . '($method_name, $args, $url, $debug);';
|
2001-08-13 18:24:03 +02:00
|
|
|
eval($cmd);
|
2001-08-15 05:54:15 +02:00
|
|
|
return $this->result;
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _split_url($url)
|
|
|
|
{
|
|
|
|
preg_match('/^(.*?\/\/.*?)(\/.*)/',$url,$matches);
|
2001-08-14 00:17:22 +02:00
|
|
|
$hostpart = $matches[1];
|
2001-10-22 23:13:11 +02:00
|
|
|
$hostpart = ereg_replace('https://','',$hostpart);
|
|
|
|
$hostpart = ereg_replace('http://','',$hostpart);
|
|
|
|
switch($this->mode)
|
|
|
|
{
|
|
|
|
case 'soap':
|
|
|
|
if(!ereg('soap.php',$matches[2]))
|
|
|
|
{
|
|
|
|
$matches[2] .= $this->urlparts['soap'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'xmlrpc':
|
|
|
|
if(!ereg('xmlrpc.php',$matches[2]))
|
|
|
|
{
|
|
|
|
$matches[2] .= $this->urlparts['xmlrpc'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-08-13 18:24:03 +02:00
|
|
|
$uri = $matches[2];
|
2001-08-14 00:17:22 +02:00
|
|
|
return array($uri,$hostpart);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _send_xmlrpc_ssl($method_name, $args, $url, $debug=True)
|
|
|
|
{
|
2001-11-30 05:46:50 +01:00
|
|
|
list($uri,$hostpart) = $this->_split_url($url);
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!is_array($args))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-22 05:51:29 +02:00
|
|
|
$arr[] = CreateObject('phpgwapi.xmlrpcval',$args,'string');
|
|
|
|
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'string');
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(list($key,$val) = @each($args))
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(is_array($val))
|
2001-08-20 18:51:04 +02:00
|
|
|
{
|
|
|
|
while(list($x,$y) = each($val))
|
|
|
|
{
|
|
|
|
$tmp[$x] = CreateObject('phpgwapi.xmlrpcval',$y, 'string');
|
|
|
|
}
|
|
|
|
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$tmp,'struct');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
|
|
|
|
}
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-30 02:29:55 +02:00
|
|
|
$arr[] = CreateObject('phpgwapi.xmlrpcval',$ele,'struct');
|
|
|
|
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-20 18:33:26 +02:00
|
|
|
|
2001-08-15 16:01:44 +02:00
|
|
|
$this->debug("<pre>" . htmlentities($f->serialize()) . "</pre>\n",$debug);
|
2001-11-30 05:46:50 +01:00
|
|
|
$c = CreateObject('phpgwapi.xmlrpc_client',$uri, $hostpart, 443);
|
2001-08-30 02:29:55 +02:00
|
|
|
$c->setCredentials($this->sessionid,$this->kp3);
|
2001-08-18 22:31:47 +02:00
|
|
|
$c->setDebug(0);
|
2001-08-30 02:29:55 +02:00
|
|
|
$r = $c->send($f,0,'https');
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$r)
|
2001-08-15 16:01:44 +02:00
|
|
|
{
|
|
|
|
$this->debug('send failed');
|
|
|
|
}
|
|
|
|
$v = $r->value();
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$r->faultCode())
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-15 16:01:44 +02:00
|
|
|
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
|
2001-12-06 16:51:06 +01:00
|
|
|
$this->result = xmlrpc_decode($v);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-15 16:01:44 +02:00
|
|
|
$this->debug('Fault Code: ' . $r->faultCode() . ' Reason "' . $r->faultString() . '"<br>',$debug);
|
2001-12-06 16:51:06 +01:00
|
|
|
$this->result = htmlentities($r->serialize());
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-15 05:54:15 +02:00
|
|
|
return $this->result;
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _send_xmlrpc_($method_name, $args, $url, $debug=True)
|
|
|
|
{
|
2001-11-30 05:46:50 +01:00
|
|
|
list($uri,$hostpart) = $this->_split_url($url);
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!is_array($args))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-22 05:51:29 +02:00
|
|
|
$arr[] = CreateObject('phpgwapi.xmlrpcval',$args,'string');
|
|
|
|
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'string');
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(list($key,$val) = @each($args))
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(is_array($val))
|
2001-08-20 18:51:04 +02:00
|
|
|
{
|
|
|
|
while(list($x,$y) = each($val))
|
|
|
|
{
|
|
|
|
$tmp[$x] = CreateObject('phpgwapi.xmlrpcval',$y, 'string');
|
|
|
|
}
|
|
|
|
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$tmp,'struct');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ele[$key] = CreateObject('phpgwapi.xmlrpcval',$val, 'string');
|
|
|
|
}
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-22 05:51:29 +02:00
|
|
|
$arr[] = CreateObject('phpgwapi.xmlrpcval',$ele,'struct');
|
|
|
|
$f = CreateObject('phpgwapi.xmlrpcmsg', $method_name, $arr,'struct');
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-20 18:33:26 +02:00
|
|
|
|
2001-08-23 08:47:50 +02:00
|
|
|
$this->debug('<pre>' . htmlentities($f->serialize()) . '</pre>' . "\n",$debug);
|
2001-11-30 05:46:50 +01:00
|
|
|
$c = CreateObject('phpgwapi.xmlrpc_client',$uri, $hostpart, 80);
|
2001-08-30 02:29:55 +02:00
|
|
|
$c->setCredentials($this->sessionid,$this->kp3);
|
2001-08-23 08:47:50 +02:00
|
|
|
// _debug_array($c);
|
|
|
|
$c->setDebug(0);
|
2001-08-13 18:24:03 +02:00
|
|
|
$r = $c->send($f);
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$r)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$this->debug('send failed');
|
|
|
|
}
|
|
|
|
$v = $r->value();
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$r->faultCode())
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
|
2001-12-06 16:51:06 +01:00
|
|
|
$this->result = xmlrpc_decode($v);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->debug('Fault Code: ' . $r->faultCode() . ' Reason "' . $r->faultString() . '"<br>',$debug);
|
2001-12-06 16:51:06 +01:00
|
|
|
$this->result = htmlentities($r->serialize());
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-15 05:54:15 +02:00
|
|
|
return $this->result;
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _send_soap_ssl($method_name, $args, $url, $debug=True)
|
|
|
|
{
|
2001-08-18 22:31:47 +02:00
|
|
|
$method_name = str_replace('.','_',$method_name);
|
2001-11-30 05:46:50 +01:00
|
|
|
list($uri,$hostpart) = $this->_split_url($url);
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!is_array($args))
|
2001-08-22 05:51:29 +02:00
|
|
|
{
|
|
|
|
$arr[] = CreateObject('phpgwapi.soapval','','string',$args);
|
|
|
|
}
|
|
|
|
else
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-22 05:51:29 +02:00
|
|
|
while(list($key,$val) = @each($args))
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(is_array($val))
|
2001-08-22 05:51:29 +02:00
|
|
|
{
|
|
|
|
while(list($x,$y) = each($val))
|
|
|
|
{
|
|
|
|
$tmp[] = CreateObject('phpgwapi.soapval',$x,'string',$y);
|
|
|
|
}
|
|
|
|
$arr[] = CreateObject('phpgwapi.soapval',$key, 'array',$tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$arr[] = CreateObject('phpgwapi.soapval',$key, 'string',$val);
|
|
|
|
}
|
|
|
|
}
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-08-22 05:51:29 +02:00
|
|
|
|
2001-08-27 13:38:45 +02:00
|
|
|
$soap_message = CreateObject('phpgwapi.soapmsg',$method_name,$arr);
|
2001-08-18 22:31:47 +02:00
|
|
|
/* print_r($soap_message);exit; */
|
|
|
|
$soap = CreateObject('phpgwapi.soap_client',$uri,$hostpart);
|
2001-08-20 01:55:58 +02:00
|
|
|
$soap->username = $this->sessionid;
|
|
|
|
$soap->password = $this->kp3;
|
2001-08-18 22:31:47 +02:00
|
|
|
/* _debug_array($soap);exit; */
|
|
|
|
if($r = $soap->send($soap_message,$method_name))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-18 22:31:47 +02:00
|
|
|
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
|
2001-08-27 13:38:45 +02:00
|
|
|
$this->result = $r->decode();
|
|
|
|
return $this->result;
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-18 22:31:47 +02:00
|
|
|
$this->debug('Fault Code: ' . $r->ernno . ' Reason "' . $r->errstring . '"<br>',$debug);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _send_soap_($method_name, $args, $url, $debug=True)
|
|
|
|
{
|
2001-12-10 03:09:31 +01:00
|
|
|
$method_name = str_replace('.','_',$method_name);
|
2001-11-30 05:46:50 +01:00
|
|
|
list($uri,$hostpart) = $this->_split_url($url);
|
2001-12-10 03:09:31 +01:00
|
|
|
|
|
|
|
if(!$args)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-12-10 03:09:31 +01:00
|
|
|
$arr = '';
|
2001-08-22 05:51:29 +02:00
|
|
|
}
|
2001-12-10 03:09:31 +01:00
|
|
|
elseif(is_array($args))
|
2001-08-22 05:51:29 +02:00
|
|
|
{
|
|
|
|
while(list($key,$val) = @each($args))
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(is_array($val))
|
2001-08-22 05:51:29 +02:00
|
|
|
{
|
|
|
|
while(list($x,$y) = each($val))
|
|
|
|
{
|
|
|
|
$tmp[] = CreateObject('phpgwapi.soapval',$x,'string',$y);
|
|
|
|
}
|
2001-08-30 02:29:55 +02:00
|
|
|
$ele[] = CreateObject('phpgwapi.soapval',$key, 'array',$tmp);
|
|
|
|
$complex = True;
|
2001-08-22 05:51:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 02:29:55 +02:00
|
|
|
$ele[] = CreateObject('phpgwapi.soapval',$key, 'string',$val);
|
2001-08-22 05:51:29 +02:00
|
|
|
}
|
|
|
|
}
|
2001-12-10 03:09:31 +01:00
|
|
|
$arr[] = CreateObject('phpgwapi.soapval','','struct',$ele);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$arr[] = CreateObject('phpgwapi.soapval','','string',$args);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
2001-12-10 03:09:31 +01:00
|
|
|
$this->request = $arr;
|
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
$soap_message = CreateObject('phpgwapi.soapmsg',$method_name,$this->request);
|
2001-08-18 22:31:47 +02:00
|
|
|
$soap = CreateObject('phpgwapi.soap_client',$uri,$hostpart);
|
2001-08-20 01:55:58 +02:00
|
|
|
$soap->username = $this->sessionid;
|
|
|
|
$soap->password = $this->kp3;
|
2001-08-18 22:31:47 +02:00
|
|
|
if($r = $soap->send($soap_message,$method_name))
|
|
|
|
{
|
2001-08-27 13:38:45 +02:00
|
|
|
_debug_array(htmlentities($soap->outgoing_payload));
|
2001-08-30 02:29:55 +02:00
|
|
|
_debug_array(htmlentities($soap->incoming_payload));
|
2001-08-18 22:31:47 +02:00
|
|
|
$this->debug('<hr>I got this value back<br><pre>' . htmlentities($r->serialize()) . '</pre><hr>',$debug);
|
2001-08-27 13:38:45 +02:00
|
|
|
$this->result = $r->decode();
|
|
|
|
return $this->result;
|
2001-08-18 22:31:47 +02:00
|
|
|
}
|
|
|
|
else
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2001-08-22 05:51:29 +02:00
|
|
|
_debug_array($soap->outgoing_payload);
|
2001-08-18 22:31:47 +02:00
|
|
|
$this->debug('Fault Code: ' . $r->ernno . ' Reason "' . $r->errstring . '"<br>',$debug);
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
function build_request($_req,$recursed=False,$ext='')
|
|
|
|
{
|
|
|
|
if(is_array($_req))
|
|
|
|
{
|
|
|
|
$ele = array();
|
|
|
|
@reset($_req);
|
|
|
|
while(list($key,$val) = @each($_req))
|
|
|
|
{
|
|
|
|
$ele[$key] = $this->build_request($val,True,$key);
|
|
|
|
}
|
|
|
|
$this->request[] = CreateObject('phpgwapi.soapval',$ext,'struct',$ele);
|
|
|
|
$ext = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
$_type = (is_long($_req) ? 'int' : gettype($_req));
|
2001-08-30 02:29:55 +02:00
|
|
|
if($recursed)
|
|
|
|
{
|
|
|
|
return CreateObject('phpgwapi.soapval',$ext,$_type,$_req);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->request[$ext] = CreateObject('phpgwapi.soapval',$ext,$_type,$_req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-13 18:24:03 +02:00
|
|
|
/* Following are for server list management and query */
|
|
|
|
function read_repository($serverid='')
|
|
|
|
{
|
2001-08-14 00:17:22 +02:00
|
|
|
if(!$serverid)
|
|
|
|
{
|
|
|
|
$serverid = $this->serverid;
|
|
|
|
}
|
2002-02-15 19:57:30 +01:00
|
|
|
$sql = "SELECT * FROM ".$this->table." WHERE server_id=" . intval($serverid);
|
2001-08-13 18:24:03 +02:00
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
|
|
|
$this->server['server_name'] = $this->db->f('server_name');
|
|
|
|
$this->server['server_url'] = $this->db->f('server_url');
|
|
|
|
$this->server['server_mode'] = $this->db->f('server_mode');
|
|
|
|
$this->server['server_security'] = $this->db->f('server_security');
|
|
|
|
$this->server['trust_level'] = $this->db->f('trust_level');
|
|
|
|
$this->server['trust_rel'] = $this->db->f('trust_rel');
|
|
|
|
$this->server['username'] = $this->db->f('username');
|
|
|
|
$this->server['password'] = $this->db->f('password');
|
|
|
|
$this->server['admin_name'] = $this->db->f('admin_name');
|
|
|
|
$this->server['admin_email'] = $this->db->f('admin_email');
|
|
|
|
}
|
|
|
|
return $this->server;
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_repository($serverid='')
|
|
|
|
{
|
|
|
|
if(!$serverid)
|
|
|
|
{
|
|
|
|
$serverid = $this->serverid;
|
|
|
|
}
|
2002-02-08 06:21:30 +01:00
|
|
|
if($serverid && is_array($this->server))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$sql = "UPDATE $this->table SET "
|
|
|
|
. "server_name='" . $this->server['server_name'] . "',"
|
|
|
|
. "server_url='" . $this->server['server_url'] . "',"
|
2001-08-13 22:49:48 +02:00
|
|
|
. "server_mode='" . $this->server['server_mode'] . "',"
|
2001-08-13 18:24:03 +02:00
|
|
|
. "server_security='" . $this->server['server_security'] . "',"
|
|
|
|
. "trust_level=" . intval($this->server['trust_level']) . ","
|
|
|
|
. "trust_rel=" . intval($this->server['trust_rel']) . ","
|
|
|
|
. "username='" . $this->server['username'] . "',"
|
|
|
|
. "password='" . $this->server['password'] . "',"
|
|
|
|
. "admin_name='" . $this->server['admin_name'] . "',"
|
|
|
|
. "admin_email='" . $this->server['admin_email'] . "' "
|
|
|
|
. "WHERE server_id=" . intval($serverid);
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
function create($server_info='')
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!is_array($server_info))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$sql = "INSERT INTO $this->table (server_name,server_url,server_mode,server_security,"
|
|
|
|
. "trust_level,trust_rel,username,password,admin_name,admin_email) "
|
|
|
|
. "VALUES('" . $server_info['server_name'] . "','" . $server_info['server_url'] . "','"
|
|
|
|
. $server_info['server_mode'] . "','" . $server_info['server_security'] . "',"
|
|
|
|
. intval($server_info['trust_level']) . "," . intval($server_info['trust_rel']) . ",'"
|
|
|
|
. $server_info['username'] . "','" . $server_info['password'] . "','"
|
|
|
|
. $server_info['admin_name'] . "','" . $server_info['admin_email'] . "')";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
|
|
|
|
$sql = "SELECT server_id FROM $this->table WHERE server_name='" . $server_info['server_name'] . "'";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
|
|
|
$server_info['server_id'] = $this->db->f(0);
|
|
|
|
$this->serverid = $server_info['server_id'];
|
|
|
|
$this->server = $server_info;
|
|
|
|
return $this->serverid;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete($serverid='')
|
|
|
|
{
|
|
|
|
if(!$serverid)
|
|
|
|
{
|
|
|
|
$serverid = $this->serverid;
|
|
|
|
}
|
|
|
|
if($serverid)
|
|
|
|
{
|
|
|
|
$sql = "DELETE FROM $this->table WHERE server_id=$serverid";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-09-05 13:16:58 +02:00
|
|
|
function get_list($start='',$sort='',$order='',$query='',$offset='',&$total)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$sort)
|
2001-09-05 13:16:58 +02:00
|
|
|
{
|
|
|
|
$sort = 'DESC';
|
|
|
|
}
|
2002-02-08 06:21:30 +01:00
|
|
|
if($query)
|
2001-09-05 13:16:58 +02:00
|
|
|
{
|
|
|
|
$whereclause = "WHERE server_name LIKE '%$query%'"
|
|
|
|
. "OR server_url LIKE '%$query%'"
|
|
|
|
. "OR server_mode LIKE '%$query%'"
|
|
|
|
. "OR admin_name LIKE '%$query%'"
|
|
|
|
. "OR admin_email LIKE '%$query%'";
|
|
|
|
}
|
2002-02-08 06:21:30 +01:00
|
|
|
if($order)
|
2001-09-05 13:16:58 +02:00
|
|
|
{
|
|
|
|
$orderclause = 'ORDER BY ' . $order . ' ' . $sort;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$orderclause = 'ORDER BY server_name ASC';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM $this->table $whereclause $orderclause";
|
2001-08-13 18:24:03 +02:00
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
2001-08-15 05:54:15 +02:00
|
|
|
|
2002-02-08 06:21:30 +01:00
|
|
|
while($this->db->next_record())
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$this->servers[$this->db->f('server_name')]['server_id'] = $this->db->f('server_id');
|
|
|
|
$this->servers[$this->db->f('server_name')]['server_name'] = $this->db->f('server_name');
|
|
|
|
$this->servers[$this->db->f('server_name')]['server_url'] = $this->db->f('server_url');
|
|
|
|
$this->servers[$this->db->f('server_name')]['server_mode'] = $this->db->f('server_mode');
|
|
|
|
$this->servers[$this->db->f('server_name')]['server_security'] = $this->db->f('server_security');
|
|
|
|
$this->servers[$this->db->f('server_name')]['trust_level'] = $this->db->f('trust_level');
|
|
|
|
$this->servers[$this->db->f('server_name')]['trust_rel'] = $this->db->f('trust_rel');
|
|
|
|
$this->servers[$this->db->f('server_name')]['admin_name'] = $this->db->f('admin_name');
|
|
|
|
$this->servers[$this->db->f('server_name')]['admin_email'] = $this->db->f('admin_email');
|
|
|
|
}
|
2001-09-05 13:16:58 +02:00
|
|
|
$this->total = $this->db->num_rows();
|
|
|
|
$total = $this->total;
|
2001-08-13 18:24:03 +02:00
|
|
|
return $this->servers;
|
|
|
|
}
|
|
|
|
|
2001-09-05 13:16:58 +02:00
|
|
|
function formatted_list($server_id=0,$java=False,$local=False)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if($java)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$jselect = ' onChange="this.form.submit();"';
|
|
|
|
}
|
|
|
|
$select = "\n" .'<select name="server_id"' . $jselect . ">\n";
|
|
|
|
$select .= '<option value="0"';
|
|
|
|
if(!$server_id)
|
|
|
|
{
|
|
|
|
$select .= ' selected';
|
|
|
|
}
|
2001-09-05 13:16:58 +02:00
|
|
|
$selectlang = $local ? lang('Local') : lang('Please Select');
|
|
|
|
$select .= '>' . $selectlang . '</option>'."\n";
|
2001-08-13 18:24:03 +02:00
|
|
|
|
2001-09-05 13:16:58 +02:00
|
|
|
$x = '';
|
|
|
|
$slist = $this->get_list('','','','','',$x);
|
2002-02-08 06:21:30 +01:00
|
|
|
while(list($key,$val) = each($slist))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$foundservers = True;
|
|
|
|
$select .= '<option value="' . $val['server_id'] . '"';
|
2002-02-08 06:21:30 +01:00
|
|
|
if($val['server_id'] == $server_id)
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$select .= ' selected';
|
|
|
|
}
|
|
|
|
$select .= '>' . $val['server_name'] . '</option>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$select .= '</select>'."\n";
|
|
|
|
$select .= '<noscript><input type="submit" name="server_id_select" value="' . lang('Select') . '"></noscript>' . "\n";
|
|
|
|
if(!$foundservers)
|
|
|
|
{
|
|
|
|
$select = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $select;
|
|
|
|
}
|
|
|
|
|
|
|
|
function name2id($server_name='')
|
|
|
|
{
|
|
|
|
if(!$server_name)
|
|
|
|
{
|
|
|
|
$server_name = $this->server['server_name'];
|
|
|
|
}
|
|
|
|
if($server_name)
|
|
|
|
{
|
|
|
|
$sql = "SELECT server_id FROM $this->table WHERE server_name='$server_name'";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
|
|
|
$serverid = $this->db->f(0);
|
|
|
|
return $serverid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
function id2name($serverid='')
|
|
|
|
{
|
|
|
|
if(!$serverid)
|
|
|
|
{
|
|
|
|
$serverid = $this->serverid;
|
|
|
|
}
|
|
|
|
if($serverid)
|
|
|
|
{
|
2001-11-30 05:46:50 +01:00
|
|
|
$sql = "SELECT server_name FROM $this->table WHERE server_id=$serverid";
|
2001-08-13 18:24:03 +02:00
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
|
|
|
$server_name = $this->db->f(0);
|
|
|
|
return $server_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
function exists($serverdata='')
|
|
|
|
{
|
|
|
|
if(!$serverdata)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2002-02-08 06:21:30 +01:00
|
|
|
if(is_int($serverdata))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
$serverid = $serverdata;
|
|
|
|
settype($server_name,'string');
|
|
|
|
$server_name = $this->id2name($serverid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$server_name = $serverdata;
|
|
|
|
}
|
|
|
|
$sql = "SELECT server_id FROM $this->table WHERE server_name='$server_name'";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-10-22 23:13:11 +02:00
|
|
|
/* TODO - Determine trust level here */
|
2001-08-13 18:24:03 +02:00
|
|
|
function auth($serverdata='')
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if(!$serverdata || !is_array($serverdata))
|
2001-08-13 18:24:03 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$server_name = $serverdata['server_name'];
|
|
|
|
$username = $serverdata['username'];
|
|
|
|
$password = $serverdata['password'];
|
|
|
|
|
|
|
|
$sql = "SELECT server_id,trust_rel FROM $this->table WHERE server_name='$server_name'";
|
|
|
|
$this->db->query($sql,__LINE__,__FILE__);
|
|
|
|
if($this->db->next_record())
|
|
|
|
{
|
2002-02-08 06:21:30 +01:00
|
|
|
if($username == $GLOBALS['phpgw_info']['server']['site_username'] &&
|
2001-08-13 18:24:03 +02:00
|
|
|
$password == $GLOBALS['phpgw_info']['server']['site_password'] &&
|
|
|
|
$this->db->f('trust_rel') >= 1)
|
|
|
|
{
|
|
|
|
$this->authed = True;
|
2001-08-15 05:54:15 +02:00
|
|
|
return True;
|
2001-08-13 18:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|