Project

General

Profile

Download (4.72 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
/*
30
	pfSense_BUILDER_BINARIES:
31
	pfSense_MODULE:	utils
32
*/
33

    
34
require_once("auth.inc");
35
require_once("xmlrpc_client.inc");
36

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

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

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

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

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

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

    
146
?>
(65-65/67)