1 |
207abd84
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
$Id$
|
4 |
|
|
|
5 |
|
|
xmlrpc.inc
|
6 |
0e16b9ca
|
Scott Ullrich
|
Copyright (C) 2005-2006 Colin Smith
|
7 |
207abd84
|
Colin Smith
|
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 |
523855b0
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_BUILDER_BINARIES:
|
33 |
|
|
pfSense_MODULE: utils
|
34 |
|
|
*/
|
35 |
|
|
|
36 |
b7d5a7ba
|
Ermal
|
require_once("auth.inc");
|
37 |
207abd84
|
Colin Smith
|
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 |
13657e92
|
Colin Smith
|
$array[] = XML_RPC_decode($value);
|
47 |
207abd84
|
Colin Smith
|
}
|
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 |
13657e92
|
Colin Smith
|
/*
|
56 |
207abd84
|
Colin Smith
|
switch($raw_value->kindOf()) {
|
57 |
|
|
case "scalar":
|
58 |
5c6d0f65
|
Colin Smith
|
if($raw_value->scalartyp() == "boolean") $return = (boolean) $raw_value->scalarval();
|
59 |
207abd84
|
Colin Smith
|
$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 |
970095a1
|
Colin Smith
|
$return[] = xmlrpc_value_to_php($value);
|
66 |
207abd84
|
Colin Smith
|
}
|
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 |
13657e92
|
Colin Smith
|
*/
|
77 |
597398c0
|
Colin Smith
|
return XML_RPC_decode($raw_value);
|
78 |
207abd84
|
Colin Smith
|
}
|
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 |
13657e92
|
Colin Smith
|
$toreturn = XML_RPC_encode($value);
|
85 |
|
|
return $force_array ? array($toreturn) : $toreturn;
|
86 |
|
|
/*
|
87 |
207abd84
|
Colin Smith
|
if(gettype($value) == "array") {
|
88 |
|
|
$xmlrpc_type = "array";
|
89 |
|
|
$toreturn = array();
|
90 |
|
|
foreach($value as $key => $val) {
|
91 |
|
|
if(is_string($key)) $xmlrpc_type = "struct";
|
92 |
|
|
$toreturn[$key] = php_value_to_xmlrpc($val);
|
93 |
|
|
}
|
94 |
|
|
return new XML_RPC_Value($toreturn, $xmlrpc_type);
|
95 |
|
|
} else {
|
96 |
|
|
if($force_array == true) {
|
97 |
|
|
return new XML_RPC_Value(array(new XML_RPC_Value($value, gettype($value))), "array");
|
98 |
|
|
} else {
|
99 |
|
|
return new XML_RPC_Value($value, gettype($value));
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
13657e92
|
Colin Smith
|
*/
|
103 |
207abd84
|
Colin Smith
|
}
|
104 |
|
|
|
105 |
|
|
/*
|
106 |
|
|
* xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
|
107 |
|
|
* $params[0] contains the local system's plaintext password and removes the password from
|
108 |
|
|
* the array before returning it.
|
109 |
|
|
*/
|
110 |
|
|
function xmlrpc_auth(&$params) {
|
111 |
ca092d26
|
Ermal
|
global $config, $_SERVER;
|
112 |
d064a115
|
Ermal
|
|
113 |
b7d5a7ba
|
Ermal
|
/* XXX: Should teach caller to pass username and use it here. */
|
114 |
|
|
/* XXX: Should clarify from old behaviour what is in params[0] that differs from params['xmlrpcauth'] */
|
115 |
|
|
if (isset($config['system']['webgui']['authmode'])) {
|
116 |
|
|
$authcfg = auth_get_authserver($config['system']['webgui']['authmode']);
|
117 |
|
|
if (authenticate_user("admin", $params[0], $authcfg) ||
|
118 |
|
|
authenticate_user("admin", $params[0])) {
|
119 |
|
|
array_shift($params);
|
120 |
ccf46756
|
Ermal
|
unset($params['xmlrpcauth']);
|
121 |
b7d5a7ba
|
Ermal
|
return true;
|
122 |
56a8bbf3
|
Ermal
|
} else if (!empty($params['xmlrpcauth']) && (authenticate_user("admin", $params['xmlrpcauth'], $authcfg) ||
|
123 |
|
|
authenticate_user("admin", $params['xmlrpcauth']))) {
|
124 |
b7d5a7ba
|
Ermal
|
array_shift($params);
|
125 |
|
|
unset($params['xmlrpcauth']);
|
126 |
|
|
return true;
|
127 |
|
|
}
|
128 |
|
|
} else if (authenticate_user("admin", $params[0])) {
|
129 |
4d775dd0
|
Ermal
|
array_shift($params);
|
130 |
ccf46756
|
Ermal
|
unset($params['xmlrpcauth']);
|
131 |
207abd84
|
Colin Smith
|
return true;
|
132 |
d5b45feb
|
Ermal
|
} else if (!empty($params['xmlrpcauth']) && authenticate_user("admin", $params['xmlrpcauth'])) {
|
133 |
4d775dd0
|
Ermal
|
array_shift($params);
|
134 |
207abd84
|
Colin Smith
|
unset($params['xmlrpcauth']);
|
135 |
d064a115
|
Ermal
|
return true;
|
136 |
207abd84
|
Colin Smith
|
}
|
137 |
d064a115
|
Ermal
|
|
138 |
4d775dd0
|
Ermal
|
array_shift($params);
|
139 |
|
|
unset($params['xmlrpcauth']);
|
140 |
ca092d26
|
Ermal
|
log_error("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']} during sync settings.");
|
141 |
66752f24
|
Scott Ullrich
|
return false;
|
142 |
207abd84
|
Colin Smith
|
}
|
143 |
|
|
|
144 |
b7d5a7ba
|
Ermal
|
?>
|