Revision 21dc3a7d
Added by Colin Smith over 20 years ago
usr/local/www/xmlrpc.php | ||
---|---|---|
31 | 31 |
require_once("config.inc"); |
32 | 32 |
require_once("functions.inc"); |
33 | 33 |
|
34 |
// Helper functions. |
|
35 |
|
|
36 |
/* |
|
37 |
* xmlrpc_params_to_php: Convert params array passed from XMLRPC server into a PHP array and return it. |
|
38 |
* |
|
39 |
* XXX: This function does not currently handle XML_RPC_Value objects of type "struct". |
|
40 |
*/ |
|
41 |
function xmlrpc_params_to_php($params) { |
|
42 |
$array = array(); |
|
43 |
$param_length = $params->getNumParams(); |
|
44 |
for($i = 0; $i < $params->getNumParams(); $i++) { |
|
45 |
$value = $params->getParam($i); |
|
46 |
if($value->kindOf == "scalar") { |
|
47 |
$array[] = $value->scalarval(); |
|
48 |
} elseif($value->kindOf == "array") { |
|
49 |
$array[] = xmlrpc_array_to_php($value); |
|
50 |
} |
|
51 |
} |
|
52 |
return $array; |
|
53 |
} |
|
54 |
|
|
34 | 55 |
/* |
35 |
* backup_config_section_xmlrpc: XMLRPC wrapper for backup_config_section. |
|
36 |
* This method must be called with two parameters: a string containing the local |
|
37 |
* system's password followed by a string containing the section to be backed up. |
|
56 |
* xmlrpc_array_to_php: Convert an XMLRPC array into a PHP array and return it. |
|
38 | 57 |
*/ |
39 |
//$backup_config_section_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString)); |
|
58 |
function xmlrpc_array_to_php($array) { |
|
59 |
$return = array(); |
|
60 |
$array_length = $array->arraysize(); |
|
61 |
for($i = 0; $i < $array->arraysize(); $i++) { |
|
62 |
$value = $array->arraymem($i); |
|
63 |
if($value->kindOf == "scalar") { |
|
64 |
$return[] = $value->scalarval(); |
|
65 |
} elseif($value->kindOf == "array") { |
|
66 |
$return[] = xmlrpc_array_to_php($value); |
|
67 |
} |
|
68 |
} |
|
69 |
return $return; |
|
70 |
} |
|
71 |
|
|
72 |
// Exposed functions. |
|
73 |
|
|
74 |
$backup_config_section_doc = 'backup_config_section_xmlrpc: XMLRPC wrapper for backup_config_section. This method must be called with two parameters: a string containing the local system\'s password followed by a string containing the section to be backed up.'; |
|
75 |
$backup_config_section_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString)); |
|
76 |
|
|
40 | 77 |
function backup_config_section_xmlrpc($params) { |
41 | 78 |
global $config; |
42 |
if($params->getNumParams() != 2) return; // Make sure we have 2 params. |
|
43 |
$param1 = $params->getParam(0); |
|
44 |
$password = $param1->scalarval(); |
|
45 |
if(crypt($password, $config['system']['password']) != $config['system']['password']) return; // Basic authentication. |
|
46 |
$param2 = $params->getParam(1); |
|
47 |
$section = $param2->scalarval(); |
|
48 |
$val = new XML_RPC_Value(backup_config_section($section), 'string'); |
|
79 |
$params = xmlrpc_params_to_php($params); // Convert XML_RPC_Value objects to a PHP array of values. |
|
80 |
if(crypt($params[0], $config['system']['password']) != $config['system']['password']) return; // Basic authentication. |
|
81 |
$val = new XML_RPC_Value(backup_config_section($params[1]), 'string'); |
|
49 | 82 |
return new XML_RPC_Response($val); |
50 | 83 |
} |
51 | 84 |
|
52 |
/* |
|
53 |
* restore_config_section_xmlrpc: XMLRPC wrapper for restore_config_section. |
|
54 |
* This method must be called with three parameters: a string containing |
|
55 |
* the local system's password, a string containing the section to be restored, |
|
56 |
* and a string containing the returned value of backup_config_section() for that |
|
57 |
* section. This function returns |
|
58 |
*/ |
|
59 |
//$restore_config_section_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString)); |
|
85 |
$restore_config_section_doc = 'restore_config_section_xmlrpc: XMLRPC wrapper for restore_config_section. This method must be called with three parameters: a string containing the local system\'s password, a string containing the section to be restored, and a string containing the returned value of backup_config_section() for that section. This function returns true upon completion.'; |
|
86 |
$restore_config_section_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString)); |
|
87 |
|
|
60 | 88 |
function restore_config_section_xmlrpc($params) { |
61 | 89 |
global $config; |
62 |
if($params->getNumParams() != 3) return; // Make sure we have 3 params. |
|
63 |
$param1 = $params->getParam(0); |
|
64 |
$password = $param1->scalarval(); |
|
65 |
if(crypt($password, $config['system']['password']) != $config['system']['password']) return; // Basic authentication. |
|
66 |
$param2 = $params->getParam(1); |
|
67 |
$section - $param2->scalarval(); |
|
68 |
$param3 = $params->getParam(2); |
|
69 |
$new_contents = $param3->scalarval(); |
|
70 |
restore_config_section($section, $new_contents); |
|
90 |
$params = xmlrpc_params_to_php($params); |
|
91 |
if(crypt($params[0], $config['system']['password']) != $config['system']['password']) return; // Basic authentication. |
|
92 |
restore_config_section($params[1], $params[2]); |
|
71 | 93 |
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean')); |
72 | 94 |
} |
73 | 95 |
|
74 | 96 |
$server = new XML_RPC_Server( |
75 | 97 |
array( |
76 | 98 |
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc'), |
77 |
// 'signature' => $backup_config_section_sig), |
|
78 |
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc') |
|
79 |
// 'signature' => $restore_config_section_sig) |
|
99 |
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc'), |
|
100 |
) |
|
101 |
); |
|
102 |
|
|
103 |
/* |
|
104 |
XXX: Fix signature handling. |
|
105 |
|
|
106 |
$server = new XML_RPC_Server( |
|
107 |
array( |
|
108 |
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc', |
|
109 |
'signature' => $backup_config_section_sig, |
|
110 |
'docstring' => $backup_config_section_doc), |
|
111 |
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc', |
|
112 |
'signature' => $restore_config_section_sig, |
|
113 |
'docstring' => $restore_config_section_doc) |
|
80 | 114 |
) |
115 |
*/ |
|
81 | 116 |
); |
82 | 117 |
?> |
Also available in: Unified diff
Update XMLRPC server. * Stub in docstrings and signatures (still fixing the latter). * Add xmlrpc_params_to_php and xmlrpc_array_to_php to convert
XMLRPC_Value objects into a PHP array. * Still missing: struct handling, more functions!