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("config.inc");
|
43
|
require_once("functions.inc");
|
44
|
|
45
|
// Exposed functions.
|
46
|
|
47
|
$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.';
|
48
|
$backup_config_section_sig = array(array($XML_RPC_String, $XML_RPC_String, $XML_RPC_String));
|
49
|
|
50
|
function backup_config_section_xmlrpc($raw_params) {
|
51
|
$params = xmlrpc_params_to_php($raw_params); // Convert XML_RPC_Value objects to a PHP array of values.
|
52
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
53
|
$val = new XML_RPC_Value(backup_config_section($params[0]), 'string');
|
54
|
return new XML_RPC_Response($val);
|
55
|
}
|
56
|
|
57
|
$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.';
|
58
|
$restore_config_section_sig = array(array($XML_RPC_Boolean, $XML_RPC_String, $XML_RPC_Array, $XML_RPC_Array));
|
59
|
|
60
|
function restore_config_section_xmlrpc($raw_params) {
|
61
|
$params = xmlrpc_params_to_php($raw_params);
|
62
|
$i = 0;
|
63
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
64
|
foreach($params[0] as $section) {
|
65
|
restore_config_section($section, $params[1][$i]);
|
66
|
$i++;
|
67
|
}
|
68
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
69
|
}
|
70
|
|
71
|
$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.';
|
72
|
$filter_configure_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
73
|
|
74
|
function filter_configure_xmlrpc($raw_params) {
|
75
|
$params = xmlrpc_params_to_php($raw_params);
|
76
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
77
|
filter_configure();
|
78
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
79
|
}
|
80
|
|
81
|
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
|
82
|
$check_firmware_version_sig = array(array($XML_RPC_String, $XML_RPC_String));
|
83
|
|
84
|
function check_firmware_version_xmlrpc($raw_params) {
|
85
|
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), 'string'));
|
86
|
}
|
87
|
|
88
|
|
89
|
$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.';
|
90
|
$auto_update_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
91
|
|
92
|
function auto_update_xmlrpc($raw_params) {
|
93
|
$params = xmlrpc_params_to_php($raw_params);
|
94
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
95
|
auto_update();
|
96
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
97
|
}
|
98
|
|
99
|
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
|
100
|
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
101
|
|
102
|
function reboot_xmlrpc($raw_params) {
|
103
|
require_once("util.inc");
|
104
|
$params = xmlrpc_params_to_php($raw_params);
|
105
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", 'string'));
|
106
|
mwexec_bg("/etc/rc.reboot");
|
107
|
return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
|
108
|
}
|
109
|
|
110
|
$get_notices_sig = array(array($XML_RPC_Array, $XML_RPC_String), array($XML_RPC_Array));
|
111
|
function get_notices_xmlrpc($raw_params) {
|
112
|
global $g;
|
113
|
require_once("notices.inc");
|
114
|
$params = xmlrpc_params_to_php($raw_params);
|
115
|
if(!$params[0]) {
|
116
|
$toreturn = get_notices();
|
117
|
} else {
|
118
|
$toreturn = get_notices($params[0]);
|
119
|
}
|
120
|
$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
|
121
|
print $response->serialize();
|
122
|
return $response;
|
123
|
}
|
124
|
|
125
|
$server = new XML_RPC_Server(
|
126
|
array(
|
127
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
128
|
'signature' => $backup_config_section_sig,
|
129
|
'docstring' => $backup_config_section_doc),
|
130
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
131
|
'signature' => $restore_config_section_sig,
|
132
|
'docstring' => $restore_config_section_doc),
|
133
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
134
|
'signature' => $filter_configure_sig,
|
135
|
'docstring' => $filter_configure_doc),
|
136
|
'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
|
137
|
'signature' => $check_firmware_version_sig,
|
138
|
'docstring' => $check_firmware_version_doc),
|
139
|
// 'pfsense.auto_update' => array('function' => 'auto_update_xmlrpc',
|
140
|
// 'signature' => $auto_update_sig,
|
141
|
// 'docstring' => $auto_update_doc),
|
142
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
143
|
'signature' => $reboot_sig,
|
144
|
'docstring' => $reboot_doc),
|
145
|
'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
|
146
|
'signature' => $get_notices_sig)
|
147
|
)
|
148
|
);
|
149
|
?>
|