Project

General

Profile

Download (3.56 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	xmlrpc.inc
4
	Copyright (C) 2005-2006 Colin Smith
5
	All rights reserved.
6

    
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9

    
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12

    
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16

    
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28

    
29
require_once("auth.inc");
30
require_once("xmlrpc_client.inc");
31

    
32
/*
33
 *   xmlrpc_params_to_php: Convert params array passed from XMLRPC server into a PHP array and return it.
34
 */
35
function xmlrpc_params_to_php($params) {
36
	$array = array();
37
	for ($i = 0; $i < $params->getNumParams(); $i++) {
38
		$value = $params->getParam($i);
39
		$array[] = XML_RPC_decode($value);
40
	}
41
	return $array;
42
}
43

    
44
/*
45
 *   xmlrpc_value_to_php: Convert an XMLRPC value into a PHP scalar/array and return it.
46
 */
47
function xmlrpc_value_to_php($raw_value) {
48
	return XML_RPC_decode($raw_value);
49
}
50

    
51
/*
52
 *   php_value_to_xmlrpc: Convert a PHP scalar or array into its XMLRPC equivalent.
53
 */
54
function php_value_to_xmlrpc($value, $force_array = false) {
55
	$toreturn = XML_RPC_encode($value);
56
	return $force_array ? array($toreturn) : $toreturn;
57
}
58

    
59
/*
60
 *   xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
61
 *                $params[0] contains the local system's plaintext password and removes the password from
62
 *                the array before returning it.
63
 */
64
function xmlrpc_auth(&$params) {
65
	global $config, $_SERVER;
66

    
67
	/* XXX: Should teach caller to pass username and use it here. */
68
	/* XXX: Should clarify from old behaviour what is in params[0] that differs from params['xmlrpcauth'] */
69
	if (isset($config['system']['webgui']['authmode'])) {
70
		$authcfg = auth_get_authserver($config['system']['webgui']['authmode']);
71
		if (authenticate_user("admin", $params[0], $authcfg) ||
72
		    authenticate_user("admin", $params[0])) {
73
			array_shift($params);
74
			unset($params['xmlrpcauth']);
75
			return true;
76
		} else if (!empty($params['xmlrpcauth']) &&
77
		    (authenticate_user("admin", $params['xmlrpcauth'], $authcfg) ||
78
		    authenticate_user("admin", $params['xmlrpcauth']))) {
79
			array_shift($params);
80
			unset($params['xmlrpcauth']);
81
			return true;
82
		}
83
	} else if (authenticate_user("admin", $params[0])) {
84
		array_shift($params);
85
		unset($params['xmlrpcauth']);
86
		return true;
87
	} else if (!empty($params['xmlrpcauth']) &&
88
	    authenticate_user("admin", $params['xmlrpcauth'])) {
89
		array_shift($params);
90
		unset($params['xmlrpcauth']);
91
		return true;
92
	}
93

    
94
	array_shift($params);
95
	unset($params['xmlrpcauth']);
96
	log_error("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']} during sync settings.");
97
	return false;
98
}
99

    
100
?>
(63-63/65)