1
|
<?php
|
2
|
/*
|
3
|
$Id$
|
4
|
|
5
|
xmlrpc.php
|
6
|
Copyright (C) 2005 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._Value(
|
29
|
|
30
|
TODO:
|
31
|
* Expose more functions.
|
32
|
*/
|
33
|
|
34
|
require_once("xmlrpc_server.inc");
|
35
|
require_once("xmlrpc.inc");
|
36
|
require_once("config.inc");
|
37
|
require_once("functions.inc");
|
38
|
require_once("array_intersect_key.inc");
|
39
|
|
40
|
/* grab sync to ip if enabled */
|
41
|
if ($config['installedpackages']['carpsettings']['config']) {
|
42
|
foreach ($config['installedpackages']['carpsettings']['config'] as $carp) {
|
43
|
$synchronizetoip = $carp['synchronizetoip'];
|
44
|
}
|
45
|
}
|
46
|
|
47
|
if($synchronizetoip) {
|
48
|
if($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
|
49
|
log_error("Disallowing CARP sync loop.");
|
50
|
die;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
$xmlrpc_g = array(
|
55
|
"return" => array(
|
56
|
"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
|
57
|
"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
|
58
|
"authfail" => new XML_RPC_Response(0, $XML_RPC_erruser+1, "Authentication failure")
|
59
|
)
|
60
|
);
|
61
|
|
62
|
/*
|
63
|
* pfSense XMLRPC errors
|
64
|
* $XML_RPC_erruser + 1 = Auth failure
|
65
|
*/
|
66
|
$XML_RPC_erruser = 200;
|
67
|
|
68
|
/* EXPOSED FUNCTIONS */
|
69
|
|
70
|
$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 an array containing the keys to be backed up.';
|
71
|
$backup_config_section_sig = array(
|
72
|
array(
|
73
|
$XML_RPC_Struct, // First signature element is return value.
|
74
|
$XML_RPC_String,
|
75
|
$XML_RPC_Array
|
76
|
)
|
77
|
);
|
78
|
|
79
|
function backup_config_section_xmlrpc($raw_params) {
|
80
|
global $config, $xmlrpc_g;
|
81
|
$params = xmlrpc_params_to_php($raw_params);
|
82
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
83
|
$val = array_intersect_key($config, array_flip($params[0]));
|
84
|
return new XML_RPC_Response(XML_RPC_encode($val));
|
85
|
}
|
86
|
|
87
|
/*****************************/
|
88
|
|
89
|
$restore_config_section_doc = 'XMLRPC wrapper for restore_config_section. This method must be called with two parameters: a string containing the local system\'s password and an array to merge into the system\'s config. This function returns true upon completion.';
|
90
|
$restore_config_section_sig = array(
|
91
|
array(
|
92
|
$XML_RPC_Boolean,
|
93
|
$XML_RPC_String,
|
94
|
$XML_RPC_Struct
|
95
|
)
|
96
|
);
|
97
|
|
98
|
function restore_config_section_xmlrpc($raw_params) {
|
99
|
global $config, $xmlrpc_g;
|
100
|
$params = xmlrpc_params_to_php($raw_params);
|
101
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
102
|
$config = array_merge($config, $params[0]);
|
103
|
$mergedkeys = implode(",", array_keys($params[0]));
|
104
|
write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
|
105
|
return $xmlrpc_g['return']['true'];
|
106
|
}
|
107
|
|
108
|
/*****************************/
|
109
|
|
110
|
|
111
|
$merge_config_section_doc = 'XMLRPC wrapper for merge_config_section. This method must be called with two parameters: a string containing the local system\'s password and an array to merge into the system\'s config. This function returns true upon completion.';
|
112
|
$merge_config_section_sig = array(
|
113
|
array(
|
114
|
$XML_RPC_Boolean,
|
115
|
$XML_RPC_String,
|
116
|
$XML_RPC_Struct
|
117
|
)
|
118
|
);
|
119
|
|
120
|
function merge_config_section_xmlrpc($raw_params) {
|
121
|
global $config, $xmlrpc_g;
|
122
|
$params = xmlrpc_params_to_php($raw_params);
|
123
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
124
|
$config = array_merge_recursive_unique($config, $params[0]);
|
125
|
$mergedkeys = implode(",", array_keys($params[0]));
|
126
|
write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
|
127
|
return $xmlrpc_g['return']['true'];
|
128
|
}
|
129
|
|
130
|
/*****************************/
|
131
|
|
132
|
$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.';
|
133
|
$filter_configure_sig = array(
|
134
|
array(
|
135
|
$XML_RPC_Boolean,
|
136
|
$XML_RPC_String
|
137
|
)
|
138
|
);
|
139
|
|
140
|
function filter_configure_xmlrpc($raw_params) {
|
141
|
global $xmlrpc_g;
|
142
|
$params = xmlrpc_params_to_php($raw_params);
|
143
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
144
|
require_once("vslb.inc");
|
145
|
slbd_configure();
|
146
|
filter_configure();
|
147
|
system_routing_configure();
|
148
|
return $xmlrpc_g['return']['true'];
|
149
|
}
|
150
|
|
151
|
/*****************************/
|
152
|
|
153
|
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
|
154
|
$check_firmware_version_sig = array(
|
155
|
array(
|
156
|
$XML_RPC_String,
|
157
|
$XML_RPC_String
|
158
|
)
|
159
|
);
|
160
|
|
161
|
function check_firmware_version_xmlrpc($raw_params) {
|
162
|
global $XML_RPC_String;
|
163
|
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
|
164
|
}
|
165
|
|
166
|
/*****************************/
|
167
|
|
168
|
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
|
169
|
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
170
|
|
171
|
function reboot_xmlrpc($raw_params) {
|
172
|
global $xmlrpc_g;
|
173
|
$params = xmlrpc_params_to_php($raw_params);
|
174
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
175
|
mwexec_bg("/etc/rc.reboot");
|
176
|
return $xmlrpc_g['return']['true'];
|
177
|
}
|
178
|
|
179
|
/*****************************/
|
180
|
|
181
|
$get_notices_sig = array(
|
182
|
array(
|
183
|
$XML_RPC_Array,
|
184
|
$XML_RPC_String
|
185
|
),
|
186
|
array(
|
187
|
$XML_RPC_Array
|
188
|
)
|
189
|
);
|
190
|
|
191
|
function get_notices_xmlrpc($raw_params) {
|
192
|
global $g, $xmlrpc_g;
|
193
|
require_once("notices.inc");
|
194
|
$params = array_pop(xmlrpc_params_to_php($raw_params));
|
195
|
if(!$params) {
|
196
|
$toreturn = get_notices();
|
197
|
} else {
|
198
|
$toreturn = get_notices($params);
|
199
|
}
|
200
|
$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
|
201
|
return $response;
|
202
|
}
|
203
|
|
204
|
/*****************************/
|
205
|
|
206
|
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
|
207
|
$carp_configure_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
208
|
|
209
|
function interfaces_carp_configure_xmlrpc($raw_params) {
|
210
|
global $xmlrpc_g;
|
211
|
$params = xmlrpc_params_to_php($raw_params);
|
212
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
213
|
interfaces_carp_configure();
|
214
|
interfaces_carp_bring_up_final();
|
215
|
return $xmlrpc_g['return']['true'];
|
216
|
}
|
217
|
|
218
|
/*****************************/
|
219
|
|
220
|
$server = new XML_RPC_Server(
|
221
|
array(
|
222
|
'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
|
223
|
'signature' => $carp_configure_doc,
|
224
|
'docstring' => $carp_configure_sig),
|
225
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
226
|
'signature' => $backup_config_section_sig,
|
227
|
'docstring' => $backup_config_section_doc),
|
228
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
229
|
'signature' => $restore_config_section_sig,
|
230
|
'docstring' => $restore_config_section_doc),
|
231
|
'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
|
232
|
'signature' => $merge_config_section_sig,
|
233
|
'docstring' => $merge_config_section_doc),
|
234
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
235
|
'signature' => $filter_configure_sig,
|
236
|
'docstring' => $filter_configure_doc),
|
237
|
'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
|
238
|
'signature' => $check_firmware_version_sig,
|
239
|
'docstring' => $check_firmware_version_doc),
|
240
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
241
|
'signature' => $reboot_sig,
|
242
|
'docstring' => $reboot_doc),
|
243
|
'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
|
244
|
'signature' => $get_notices_sig)
|
245
|
)
|
246
|
);
|
247
|
?>
|