Project

General

Profile

Download (4.39 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("xmlrpc_client.inc");
37

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

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

    
104
/*
105
 *   xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
106
 *                $params[0] contains the local system's plaintext password and removes the password from
107
 *                the array before returning it.
108
 */
109
function xmlrpc_auth(&$params) {
110
	global $config;
111
	$localpass =  $config['system']['user'][0]['password'];	
112
	if(crypt($params[0], $localpass) == $localpass) {
113
		array_shift($params);
114
		return true;
115
	} else if(crypt($params['xmlrpcauth'],  $localpass)  !=  $localpass)  {
116
		unset($params['xmlrpcauth']);
117
		return false;
118
	}
119
	unset($params['xmlrpcauth']);
120
	return false;
121
}
122

    
123
?>
(51-51/54)