1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
$Id$
|
5
|
|
6
|
xmlrpc.php
|
7
|
Copyright (C) 2005 Colin Smith
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
|
31
|
TODO:
|
32
|
* Expose more functions.
|
33
|
* Add syslog handling of errors.
|
34
|
* Define XML_RPC_erruser.
|
35
|
* Write handlers for PHP -> XML_RPC_Value.
|
36
|
* xmlrpc_params_to_php currently does *not* handle structs.
|
37
|
*/
|
38
|
|
39
|
include("guiconfig.inc");
|
40
|
require_once("xmlrpc_server.inc");
|
41
|
require_once("xmlrpc.inc");
|
42
|
require_once("xmlparse_pkg.inc");
|
43
|
require_once("config.inc");
|
44
|
require_once("functions.inc");
|
45
|
|
46
|
// Exposed functions.
|
47
|
|
48
|
$backup_config_section_doc = '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.';
|
49
|
$backup_config_section_sig = array(array(string, string, string));
|
50
|
|
51
|
function backup_config_section_xmlrpc($raw_params) {
|
52
|
$params = xmlrpc_params_to_php($raw_params); // Convert XML_RPC_Value objects to a PHP array of values.
|
53
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
54
|
$val = new XML_RPC_Value(backup_config_section($params[0]), 'string');
|
55
|
return new XML_RPC_Response($val);
|
56
|
}
|
57
|
|
58
|
$restore_config_section_doc = '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.';
|
59
|
$restore_config_section_sig = array(array(boolean, string, array(), array()));
|
60
|
|
61
|
function restore_config_section_xmlrpc($raw_params) {
|
62
|
$params = xmlrpc_params_to_php($raw_params);
|
63
|
$i = 0;
|
64
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
65
|
foreach($params[0] as $section) {
|
66
|
restore_config_section($section, $params[1][$i]);
|
67
|
$i++;
|
68
|
}
|
69
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
70
|
}
|
71
|
|
72
|
$filter_configure_doc = 'Basic XMLRPC wrapper for filter_configure. This method must be called with one paramater: a string containing the local system\'s password. This function returns true upon completion.';
|
73
|
$filter_configure_sig = array(array(boolean, string));
|
74
|
|
75
|
function filter_configure_xmlrpc($raw_params) {
|
76
|
$params = xmlrpc_params_to_php($raw_params);
|
77
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
78
|
filter_configure();
|
79
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
80
|
}
|
81
|
|
82
|
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
|
83
|
$check_firmware_version_sig = array(array(string, string));
|
84
|
|
85
|
function check_firmware_version_xmlrpc($raw_params) {
|
86
|
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), 'string'));
|
87
|
}
|
88
|
|
89
|
|
90
|
$auto_update_doc = 'Basic XMLRPC wrapper for auto_update. This method must be called with one paramater: a string containing the local system\'s password. This function will return true upon completion.';
|
91
|
$auto_update_sig = array(array(boolean, string));
|
92
|
|
93
|
function auto_update_xmlrpc($raw_params) {
|
94
|
$params = xmlrpc_params_to_php($raw_params);
|
95
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
96
|
auto_update();
|
97
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
98
|
}
|
99
|
|
100
|
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
|
101
|
$reboot_sig = array(array(boolean, string));
|
102
|
|
103
|
function reboot_xmlrpc($raw_params) {
|
104
|
require_once("util.inc");
|
105
|
$params = xmlrpc_params_to_php($raw_params);
|
106
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
107
|
mwexec_bg("/etc/rc.reboot");
|
108
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
109
|
}
|
110
|
|
111
|
$server = new XML_RPC_Server(
|
112
|
array(
|
113
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
114
|
'signature' => $backup_config_section_sig,
|
115
|
'docstring' => $backup_config_section_doc),
|
116
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
117
|
'signature' => $restore_config_section_sig,
|
118
|
'docstring' => $restore_config_section_doc),
|
119
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
120
|
'signature' => $filter_configure_sig,
|
121
|
'docstring' => $filter_configure_doc),
|
122
|
'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
|
123
|
'signature' => $check_firmware_version_sig,
|
124
|
'docstring' => $check_firmware_version_doc),
|
125
|
// 'pfsense.auto_update' => array('function' => 'auto_update_xmlrpc',
|
126
|
// 'signature' => $auto_update_sig,
|
127
|
// 'docstring' => $auto_update_doc),
|
128
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
129
|
'signature' => $reboot_sig,
|
130
|
'docstring' => $reboot_doc)
|
131
|
)
|
132
|
);
|
133
|
?>
|