Project

General

Profile

Download (4.72 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	$Id$
4

    
5
	xmlrpc.inc
6
	Copyright (C) 2005-2006 Colin Smith
7
	All rights reserved.
8

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

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

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

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

    
31
/*
32
	pfSense_BUILDER_BINARIES:
33
	pfSense_MODULE:	utils
34
*/
35

    
36
require_once("auth.inc");
37
require_once("xmlrpc_client.inc");
38

    
39
/*
40
 *   xmlrpc_params_to_php: Convert params array passed from XMLRPC server into a PHP array and return it.
41
 */
42
function xmlrpc_params_to_php($params) {
43
	$array = array();
44
	for ($i = 0; $i < $params->getNumParams(); $i++) {
45
		$value = $params->getParam($i);
46
		$array[] = XML_RPC_decode($value);
47
	}
48
	return $array;
49
}
50

    
51
/*
52
 *   xmlrpc_value_to_php: Convert an XMLRPC value into a PHP scalar/array and return it.
53
 */
54
function xmlrpc_value_to_php($raw_value) {
55
	/*
56
		switch ($raw_value->kindOf()) {
57
			case "scalar":
58
				if ($raw_value->scalartyp() == "boolean") {
59
					$return = (boolean) $raw_value->scalarval();
60
				}
61
				$return = $raw_value->scalarval();
62
				break;
63
			case "array":
64
				$return = array();
65
				for ($i = 0; $i < $raw_value->arraysize(); $i++) {
66
					$value = $raw_value->arraymem($i);
67
					$return[] = xmlrpc_value_to_php($value);
68
				}
69
				break;
70
			case "struct":
71
				$return = array();
72
				for ($i = 0; $i < $raw_value->arraysize(); $i++) {
73
					list($key, $value) = $raw_value->structeach();
74
					$return[$key] = xmlrpc_value_to_php($value);
75
				}
76
				break;
77
		}
78
	*/
79
	return XML_RPC_decode($raw_value);
80
}
81

    
82
/*
83
 *   php_value_to_xmlrpc: Convert a PHP scalar or array into its XMLRPC equivalent.
84
 */
85
function php_value_to_xmlrpc($value, $force_array = false) {
86
	$toreturn = XML_RPC_encode($value);
87
	return $force_array ? array($toreturn) : $toreturn;
88
	/*
89
		if (gettype($value) == "array") {
90
			$xmlrpc_type = "array";
91
			$toreturn = array();
92
			foreach ($value as $key => $val) {
93
				if (is_string($key)) {
94
					$xmlrpc_type = "struct";
95
				}
96
				$toreturn[$key] = php_value_to_xmlrpc($val);
97
			}
98
			return new XML_RPC_Value($toreturn, $xmlrpc_type);
99
		} else {
100
			if ($force_array == true) {
101
				return new XML_RPC_Value(array(new XML_RPC_Value($value, gettype($value))), "array");
102
			} else {
103
				return new XML_RPC_Value($value, gettype($value));
104
			}
105
		}
106
	*/
107
}
108

    
109
/*
110
 *   xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
111
 *                $params[0] contains the local system's plaintext password and removes the password from
112
 *                the array before returning it.
113
 */
114
function xmlrpc_auth(&$params) {
115
	global $config, $_SERVER;
116

    
117
	/* XXX: Should teach caller to pass username and use it here. */
118
	/* XXX: Should clarify from old behaviour what is in params[0] that differs from params['xmlrpcauth'] */
119
	if (isset($config['system']['webgui']['authmode'])) {
120
		$authcfg = auth_get_authserver($config['system']['webgui']['authmode']);
121
		if (authenticate_user("admin", $params[0], $authcfg) ||
122
		    authenticate_user("admin", $params[0])) {
123
			array_shift($params);
124
			unset($params['xmlrpcauth']);
125
			return true;
126
		} else if (!empty($params['xmlrpcauth']) && (authenticate_user("admin", $params['xmlrpcauth'], $authcfg) ||
127
		    authenticate_user("admin", $params['xmlrpcauth']))) {
128
			array_shift($params);
129
			unset($params['xmlrpcauth']);
130
			return true;
131
		}
132
	} else if (authenticate_user("admin", $params[0])) {
133
		array_shift($params);
134
		unset($params['xmlrpcauth']);
135
		return true;
136
	} else if (!empty($params['xmlrpcauth']) && authenticate_user("admin", $params['xmlrpcauth'])) {
137
		array_shift($params);
138
		unset($params['xmlrpcauth']);
139
		return true;
140
	}
141

    
142
	array_shift($params);
143
	unset($params['xmlrpcauth']);
144
	log_error("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']} during sync settings.");
145
	return false;
146
}
147

    
148
?>
(65-65/68)