1 |
207abd84
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
ce77a9c4
|
Phil Davis
|
xmlrpc.inc
|
4 |
|
|
Copyright (C) 2005-2006 Colin Smith
|
5 |
|
|
All rights reserved.
|
6 |
207abd84
|
Colin Smith
|
|
7 |
ce77a9c4
|
Phil Davis
|
Redistribution and use in source and binary forms, with or without
|
8 |
|
|
modification, are permitted provided that the following conditions are met:
|
9 |
207abd84
|
Colin Smith
|
|
10 |
ce77a9c4
|
Phil Davis
|
1. Redistributions of source code must retain the above copyright notice,
|
11 |
|
|
this list of conditions and the following disclaimer.
|
12 |
207abd84
|
Colin Smith
|
|
13 |
ce77a9c4
|
Phil Davis
|
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 |
207abd84
|
Colin Smith
|
|
17 |
ce77a9c4
|
Phil Davis
|
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 |
207abd84
|
Colin Smith
|
*/
|
28 |
|
|
|
29 |
523855b0
|
Scott Ullrich
|
/*
|
30 |
79262830
|
Phil Davis
|
pfSense_BUILDER_BINARIES:
|
31 |
523855b0
|
Scott Ullrich
|
pfSense_MODULE: utils
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
b7d5a7ba
|
Ermal
|
require_once("auth.inc");
|
35 |
207abd84
|
Colin Smith
|
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 |
79262830
|
Phil Davis
|
$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 |
207abd84
|
Colin Smith
|
}
|
48 |
79262830
|
Phil Davis
|
|
49 |
207abd84
|
Colin Smith
|
/*
|
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 |
79262830
|
Phil Davis
|
return XML_RPC_decode($raw_value);
|
54 |
207abd84
|
Colin Smith
|
}
|
55 |
|
|
|
56 |
|
|
/*
|
57 |
|
|
* php_value_to_xmlrpc: Convert a PHP scalar or array into its XMLRPC equivalent.
|
58 |
|
|
*/
|
59 |
|
|
function php_value_to_xmlrpc($value, $force_array = false) {
|
60 |
13657e92
|
Colin Smith
|
$toreturn = XML_RPC_encode($value);
|
61 |
|
|
return $force_array ? array($toreturn) : $toreturn;
|
62 |
207abd84
|
Colin Smith
|
}
|
63 |
|
|
|
64 |
|
|
/*
|
65 |
|
|
* xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
|
66 |
|
|
* $params[0] contains the local system's plaintext password and removes the password from
|
67 |
|
|
* the array before returning it.
|
68 |
|
|
*/
|
69 |
|
|
function xmlrpc_auth(&$params) {
|
70 |
ca092d26
|
Ermal
|
global $config, $_SERVER;
|
71 |
d064a115
|
Ermal
|
|
72 |
b7d5a7ba
|
Ermal
|
/* XXX: Should teach caller to pass username and use it here. */
|
73 |
|
|
/* XXX: Should clarify from old behaviour what is in params[0] that differs from params['xmlrpcauth'] */
|
74 |
|
|
if (isset($config['system']['webgui']['authmode'])) {
|
75 |
|
|
$authcfg = auth_get_authserver($config['system']['webgui']['authmode']);
|
76 |
79262830
|
Phil Davis
|
if (authenticate_user("admin", $params[0], $authcfg) ||
|
77 |
|
|
authenticate_user("admin", $params[0])) {
|
78 |
b7d5a7ba
|
Ermal
|
array_shift($params);
|
79 |
ccf46756
|
Ermal
|
unset($params['xmlrpcauth']);
|
80 |
b7d5a7ba
|
Ermal
|
return true;
|
81 |
9859f355
|
Renato Botelho
|
} else if (!empty($params['xmlrpcauth']) &&
|
82 |
|
|
(authenticate_user("admin", $params['xmlrpcauth'], $authcfg) ||
|
83 |
79262830
|
Phil Davis
|
authenticate_user("admin", $params['xmlrpcauth']))) {
|
84 |
b7d5a7ba
|
Ermal
|
array_shift($params);
|
85 |
|
|
unset($params['xmlrpcauth']);
|
86 |
|
|
return true;
|
87 |
|
|
}
|
88 |
|
|
} else if (authenticate_user("admin", $params[0])) {
|
89 |
4d775dd0
|
Ermal
|
array_shift($params);
|
90 |
ccf46756
|
Ermal
|
unset($params['xmlrpcauth']);
|
91 |
207abd84
|
Colin Smith
|
return true;
|
92 |
9859f355
|
Renato Botelho
|
} else if (!empty($params['xmlrpcauth']) &&
|
93 |
|
|
authenticate_user("admin", $params['xmlrpcauth'])) {
|
94 |
4d775dd0
|
Ermal
|
array_shift($params);
|
95 |
207abd84
|
Colin Smith
|
unset($params['xmlrpcauth']);
|
96 |
d064a115
|
Ermal
|
return true;
|
97 |
207abd84
|
Colin Smith
|
}
|
98 |
d064a115
|
Ermal
|
|
99 |
4d775dd0
|
Ermal
|
array_shift($params);
|
100 |
|
|
unset($params['xmlrpcauth']);
|
101 |
ca092d26
|
Ermal
|
log_error("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']} during sync settings.");
|
102 |
66752f24
|
Scott Ullrich
|
return false;
|
103 |
207abd84
|
Colin Smith
|
}
|
104 |
|
|
|
105 |
b7d5a7ba
|
Ermal
|
?>
|