1 |
50d49018
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
81d8a9ad
|
Colin Smith
|
$Id$
|
4 |
dc1cd85d
|
Scott Ullrich
|
|
5 |
50d49018
|
Colin Smith
|
xmlrpc.php
|
6 |
d1a6552b
|
Scott Ullrich
|
Copyright (C) 2009, 2010 Scott Ullrich
|
7 |
50d49018
|
Colin Smith
|
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 |
0e19e0e4
|
Scott Ullrich
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
50d49018
|
Colin Smith
|
*/
|
31 |
|
|
|
32 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
33 |
|
|
##|*IDENT=page-xmlrpclibrary
|
34 |
|
|
##|*NAME=XMLRPC Library page
|
35 |
|
|
##|*DESCR=Allow access to the 'XMLRPC Library' page.
|
36 |
|
|
##|*MATCH=xmlrpc.php*
|
37 |
|
|
##|-PRIV
|
38 |
|
|
|
39 |
0674f163
|
sullrich
|
require("config.inc");
|
40 |
|
|
require("functions.inc");
|
41 |
|
|
require("filter.inc");
|
42 |
d026178f
|
Renato Botelho
|
require("ipsec.inc");
|
43 |
|
|
require("vpn.inc");
|
44 |
0674f163
|
sullrich
|
require("shaper.inc");
|
45 |
|
|
require("xmlrpc_server.inc");
|
46 |
|
|
require("xmlrpc.inc");
|
47 |
|
|
require("array_intersect_key.inc");
|
48 |
50d49018
|
Colin Smith
|
|
49 |
c87f4b70
|
Ermal
|
function xmlrpc_loop_detect() {
|
50 |
|
|
global $config;
|
51 |
|
|
|
52 |
|
|
/* grab sync to ip if enabled */
|
53 |
|
|
if ($config['hasync'])
|
54 |
|
|
$synchronizetoip = $config['hasync']['synchronizetoip'];
|
55 |
|
|
if($synchronizetoip) {
|
56 |
|
|
if($synchronizetoip == $_SERVER['REMOTE_ADDR'])
|
57 |
|
|
return true;
|
58 |
ff664954
|
Scott Ullrich
|
}
|
59 |
c87f4b70
|
Ermal
|
|
60 |
|
|
return false;
|
61 |
ff664954
|
Scott Ullrich
|
}
|
62 |
|
|
|
63 |
8da3de34
|
Colin Smith
|
$xmlrpc_g = array(
|
64 |
137f46d8
|
Ermal
|
"return" => array(
|
65 |
|
|
"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
|
66 |
|
|
"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
|
67 |
|
|
"authfail" => new XML_RPC_Response(new XML_RPC_Value(gettext("Authentication failed"), $XML_RPC_String))
|
68 |
|
|
)
|
69 |
|
|
);
|
70 |
8da3de34
|
Colin Smith
|
|
71 |
|
|
/*
|
72 |
|
|
* pfSense XMLRPC errors
|
73 |
|
|
* $XML_RPC_erruser + 1 = Auth failure
|
74 |
|
|
*/
|
75 |
|
|
$XML_RPC_erruser = 200;
|
76 |
|
|
|
77 |
|
|
/* EXPOSED FUNCTIONS */
|
78 |
de63649b
|
Rafael Lucas
|
$exec_php_doc = gettext("XMLRPC wrapper for eval(). This method must be called with two parameters: a string containing the local system\'s password followed by the PHP code to evaluate.");
|
79 |
c3638879
|
Scott Ullrich
|
$exec_php_sig = array(
|
80 |
137f46d8
|
Ermal
|
array(
|
81 |
|
|
$XML_RPC_Boolean, // First signature element is return value.
|
82 |
|
|
$XML_RPC_String, // password
|
83 |
|
|
$XML_RPC_String, // shell code to exec
|
84 |
|
|
)
|
85 |
|
|
);
|
86 |
c3638879
|
Scott Ullrich
|
|
87 |
3dd2a278
|
Scott Ullrich
|
function xmlrpc_authfail() {
|
88 |
|
|
log_auth("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']}");
|
89 |
|
|
}
|
90 |
|
|
|
91 |
c3638879
|
Scott Ullrich
|
function exec_php_xmlrpc($raw_params) {
|
92 |
|
|
global $config, $xmlrpc_g;
|
93 |
137f46d8
|
Ermal
|
|
94 |
c3638879
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
95 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
96 |
|
|
xmlrpc_authfail();
|
97 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
98 |
3dd2a278
|
Scott Ullrich
|
}
|
99 |
c3638879
|
Scott Ullrich
|
$exec_php = $params[0];
|
100 |
|
|
eval($exec_php);
|
101 |
2c0dd581
|
Scott Ullrich
|
if($toreturn) {
|
102 |
|
|
$response = XML_RPC_encode($toreturn);
|
103 |
|
|
return new XML_RPC_Response($response);
|
104 |
|
|
} else
|
105 |
|
|
return $xmlrpc_g['return']['true'];
|
106 |
c3638879
|
Scott Ullrich
|
}
|
107 |
|
|
|
108 |
|
|
/*****************************/
|
109 |
de63649b
|
Rafael Lucas
|
$exec_shell_doc = gettext("XMLRPC wrapper for mwexec(). This method must be called with two parameters: a string containing the local system\'s password followed by an shell command to execute.");
|
110 |
c3638879
|
Scott Ullrich
|
$exec_shell_sig = array(
|
111 |
137f46d8
|
Ermal
|
array(
|
112 |
|
|
$XML_RPC_Boolean, // First signature element is return value.
|
113 |
|
|
$XML_RPC_String, // password
|
114 |
|
|
$XML_RPC_String, // shell code to exec
|
115 |
|
|
)
|
116 |
|
|
);
|
117 |
c3638879
|
Scott Ullrich
|
|
118 |
|
|
function exec_shell_xmlrpc($raw_params) {
|
119 |
|
|
global $config, $xmlrpc_g;
|
120 |
137f46d8
|
Ermal
|
|
121 |
c3638879
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
122 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
123 |
|
|
xmlrpc_authfail();
|
124 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
125 |
3dd2a278
|
Scott Ullrich
|
}
|
126 |
c3638879
|
Scott Ullrich
|
$shell_cmd = $params[0];
|
127 |
|
|
mwexec($shell_cmd);
|
128 |
137f46d8
|
Ermal
|
|
129 |
c3638879
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/*****************************/
|
133 |
de63649b
|
Rafael Lucas
|
$backup_config_section_doc = gettext("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.");
|
134 |
8da3de34
|
Colin Smith
|
$backup_config_section_sig = array(
|
135 |
137f46d8
|
Ermal
|
array(
|
136 |
|
|
$XML_RPC_Struct, // First signature element is return value.
|
137 |
|
|
$XML_RPC_String,
|
138 |
|
|
$XML_RPC_Array
|
139 |
|
|
)
|
140 |
|
|
);
|
141 |
21dc3a7d
|
Colin Smith
|
|
142 |
57e6d4c9
|
Colin Smith
|
function backup_config_section_xmlrpc($raw_params) {
|
143 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
144 |
137f46d8
|
Ermal
|
|
145 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
146 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
147 |
fb0eb20b
|
Ermal
|
return;
|
148 |
|
|
}
|
149 |
c87f4b70
|
Ermal
|
|
150 |
8da3de34
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
151 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
152 |
|
|
xmlrpc_authfail();
|
153 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
154 |
3dd2a278
|
Scott Ullrich
|
}
|
155 |
03d89831
|
Scott Ullrich
|
$val = array_intersect_key($config, array_flip($params[0]));
|
156 |
137f46d8
|
Ermal
|
|
157 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(XML_RPC_encode($val));
|
158 |
50d49018
|
Colin Smith
|
}
|
159 |
|
|
|
160 |
8da3de34
|
Colin Smith
|
/*****************************/
|
161 |
de63649b
|
Rafael Lucas
|
$restore_config_section_doc = gettext("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.");
|
162 |
8da3de34
|
Colin Smith
|
$restore_config_section_sig = array(
|
163 |
137f46d8
|
Ermal
|
array(
|
164 |
|
|
$XML_RPC_Boolean,
|
165 |
|
|
$XML_RPC_String,
|
166 |
|
|
$XML_RPC_Struct
|
167 |
|
|
)
|
168 |
|
|
);
|
169 |
21dc3a7d
|
Colin Smith
|
|
170 |
57e6d4c9
|
Colin Smith
|
function restore_config_section_xmlrpc($raw_params) {
|
171 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
172 |
137f46d8
|
Ermal
|
|
173 |
d026178f
|
Renato Botelho
|
$old_config = $config;
|
174 |
|
|
|
175 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
176 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
177 |
fb0eb20b
|
Ermal
|
return;
|
178 |
|
|
}
|
179 |
c87f4b70
|
Ermal
|
|
180 |
57e6d4c9
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
181 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
182 |
|
|
xmlrpc_authfail();
|
183 |
19b5c3e7
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
184 |
3dd2a278
|
Scott Ullrich
|
}
|
185 |
1b99e1e5
|
jim-p
|
|
186 |
|
|
// Some sections should just be copied and not merged or we end
|
187 |
|
|
// up unable to sync the deletion of the last item in a section
|
188 |
174a331e
|
Ermal
|
$sync_full = array('ipsec', 'aliases', 'wol', 'load_balancer', 'openvpn', 'cert', 'ca', 'crl', 'schedules', 'filter', 'nat', 'dhcpd', 'dhcpv6');
|
189 |
1b99e1e5
|
jim-p
|
$sync_full_done = array();
|
190 |
|
|
foreach ($sync_full as $syncfull) {
|
191 |
|
|
if (isset($params[0][$syncfull])) {
|
192 |
|
|
$config[$syncfull] = $params[0][$syncfull];
|
193 |
|
|
unset($params[0][$syncfull]);
|
194 |
|
|
$sync_full_done[] = $syncfull;
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
a8200dbf
|
Ermal
|
$vipbackup = array();
|
199 |
51611440
|
Ermal
|
$oldvips = array();
|
200 |
4d775dd0
|
Ermal
|
if (isset($params[0]['virtualip'])) {
|
201 |
7b47bd4c
|
Ermal
|
if (is_array($config['virtualip']['vip'])) {
|
202 |
51611440
|
Ermal
|
foreach ($config['virtualip']['vip'] as $vipindex => $vip) {
|
203 |
|
|
if ($vip['mode'] == "carp")
|
204 |
7b47bd4c
|
Ermal
|
$oldvips["{$vip['interface']}_vip{$vip['vhid']}"] = "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}";
|
205 |
|
|
else if ($vip['mode'] == "ipalias" && strstr($vip['interface'], "_vip"))
|
206 |
2708a5cf
|
Ermal
|
$oldvips[$vip['subnet']] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}";
|
207 |
7b47bd4c
|
Ermal
|
else if (($vip['mode'] == "ipalias" || $vip['mode'] == 'proxyarp') && !strstr($vip['interface'], "_vip"))
|
208 |
51611440
|
Ermal
|
$vipbackup[] = $vip;
|
209 |
|
|
}
|
210 |
19b5c3e7
|
Ermal
|
}
|
211 |
|
|
}
|
212 |
f51d4f98
|
Ermal
|
|
213 |
b019222a
|
pierrepomes
|
// For vip section, first keep items sent from the master
|
214 |
aa6699fb
|
jim-p
|
$config = array_merge_recursive_unique($config, $params[0]);
|
215 |
51611440
|
Ermal
|
|
216 |
f51d4f98
|
Ermal
|
/* Then add ipalias and proxyarp types already defined on the backup */
|
217 |
|
|
if (is_array($vipbackup) && !empty($vipbackup)) {
|
218 |
51611440
|
Ermal
|
if (!is_array($config['virtualip']))
|
219 |
|
|
$config['virtualip'] = array();
|
220 |
f51d4f98
|
Ermal
|
if (!is_array($config['virtualip']['vip']))
|
221 |
|
|
$config['virtualip']['vip'] = array();
|
222 |
|
|
foreach ($vipbackup as $vip)
|
223 |
51611440
|
Ermal
|
array_unshift($config['virtualip']['vip'], $vip);
|
224 |
a8200dbf
|
Ermal
|
}
|
225 |
51611440
|
Ermal
|
|
226 |
|
|
/* Log what happened */
|
227 |
1b99e1e5
|
jim-p
|
$mergedkeys = implode(",", array_merge(array_keys($params[0]), $sync_full_done));
|
228 |
3a3fb8ea
|
Erik Fonnesbeck
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
|
229 |
51611440
|
Ermal
|
|
230 |
|
|
/*
|
231 |
|
|
* The real work on handling the vips specially
|
232 |
|
|
* This is a copy of intefaces_vips_configure with addition of not reloading existing/not changed carps
|
233 |
|
|
*/
|
234 |
63f81fbd
|
Ermal
|
if (isset($params[0]['virtualip']) && is_array($config['virtualip']) && is_array($config['virtualip']['vip'])) {
|
235 |
51611440
|
Ermal
|
$carp_setuped = false;
|
236 |
f51d4f98
|
Ermal
|
$anyproxyarp = false;
|
237 |
51611440
|
Ermal
|
foreach ($config['virtualip']['vip'] as $vip) {
|
238 |
7b47bd4c
|
Ermal
|
if ($vip['mode'] == "carp" && isset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"])) {
|
239 |
|
|
if ($oldvips["{$vip['interface']}_vip{$vip['vhid']}"] == "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}") {
|
240 |
2708a5cf
|
Ermal
|
if (does_vip_exist($vip)) {
|
241 |
7b47bd4c
|
Ermal
|
unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
|
242 |
d1e03822
|
Ermal
|
continue; // Skip reconfiguring this vips since nothing has changed.
|
243 |
19ed1624
|
Ermal
|
}
|
244 |
92ca32cc
|
Ermal
|
}
|
245 |
7b47bd4c
|
Ermal
|
unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
|
246 |
|
|
} else if ($vip['mode'] == "ipalias" && strstr($vip['interface'], "_vip") && isset($oldvips[$vip['subnet']])) {
|
247 |
2708a5cf
|
Ermal
|
if ($oldvips[$vip['subnet']] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}") {
|
248 |
|
|
if (does_vip_exist($vip)) {
|
249 |
|
|
unset($oldvips[$vip['subnet']]);
|
250 |
|
|
continue; // Skip reconfiguring this vips since nothing has changed.
|
251 |
|
|
}
|
252 |
|
|
}
|
253 |
|
|
unset($oldvips[$vip['subnet']]);
|
254 |
51611440
|
Ermal
|
}
|
255 |
|
|
|
256 |
|
|
switch ($vip['mode']) {
|
257 |
|
|
case "proxyarp":
|
258 |
|
|
$anyproxyarp = true;
|
259 |
|
|
break;
|
260 |
|
|
case "ipalias":
|
261 |
3dacbd7c
|
Renato Botelho
|
interface_ipalias_configure($vip);
|
262 |
51611440
|
Ermal
|
break;
|
263 |
|
|
case "carp":
|
264 |
|
|
if ($carp_setuped == false)
|
265 |
|
|
$carp_setuped = true;
|
266 |
|
|
interface_carp_configure($vip);
|
267 |
|
|
break;
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
/* Cleanup remaining old carps */
|
271 |
|
|
foreach ($oldvips as $oldvipif => $oldvippar) {
|
272 |
7b47bd4c
|
Ermal
|
if (!is_ipaddr($oldvipif) && does_interface_exist($oldvipif))
|
273 |
|
|
pfSense_interface_destroy($oldvipif);
|
274 |
51611440
|
Ermal
|
}
|
275 |
|
|
if ($carp_setuped == true)
|
276 |
|
|
interfaces_carp_setup();
|
277 |
|
|
if ($anyproxyarp == true)
|
278 |
|
|
interface_proxyarp_configure();
|
279 |
|
|
}
|
280 |
137f46d8
|
Ermal
|
|
281 |
d026178f
|
Renato Botelho
|
if (isset($old_config['ipsec']['enable']) !== isset($config['ipsec']['enable']))
|
282 |
|
|
vpn_ipsec_configure();
|
283 |
|
|
|
284 |
|
|
unset($old_config);
|
285 |
|
|
|
286 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
287 |
50d49018
|
Colin Smith
|
}
|
288 |
|
|
|
289 |
82ae5cfc
|
Scott Ullrich
|
/*****************************/
|
290 |
de63649b
|
Rafael Lucas
|
$merge_config_section_doc = gettext("XMLRPC wrapper for merging package sections. 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.");
|
291 |
82ae5cfc
|
Scott Ullrich
|
$merge_config_section_sig = array(
|
292 |
137f46d8
|
Ermal
|
array(
|
293 |
|
|
$XML_RPC_Boolean,
|
294 |
|
|
$XML_RPC_String,
|
295 |
|
|
$XML_RPC_Struct
|
296 |
|
|
)
|
297 |
|
|
);
|
298 |
82ae5cfc
|
Scott Ullrich
|
|
299 |
|
|
function merge_installedpackages_section_xmlrpc($raw_params) {
|
300 |
|
|
global $config, $xmlrpc_g;
|
301 |
137f46d8
|
Ermal
|
|
302 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
303 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
304 |
fb0eb20b
|
Ermal
|
return;
|
305 |
|
|
}
|
306 |
c87f4b70
|
Ermal
|
|
307 |
82ae5cfc
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
308 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
309 |
|
|
xmlrpc_authfail();
|
310 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
311 |
3dd2a278
|
Scott Ullrich
|
}
|
312 |
82ae5cfc
|
Scott Ullrich
|
$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
|
313 |
|
|
$mergedkeys = implode(",", array_keys($params[0]));
|
314 |
3a3fb8ea
|
Erik Fonnesbeck
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
|
315 |
137f46d8
|
Ermal
|
|
316 |
82ae5cfc
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
317 |
|
|
}
|
318 |
|
|
|
319 |
8da3de34
|
Colin Smith
|
/*****************************/
|
320 |
de63649b
|
Rafael Lucas
|
$merge_config_section_doc = gettext("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.");
|
321 |
dc1cd85d
|
Scott Ullrich
|
$merge_config_section_sig = array(
|
322 |
137f46d8
|
Ermal
|
array(
|
323 |
|
|
$XML_RPC_Boolean,
|
324 |
|
|
$XML_RPC_String,
|
325 |
|
|
$XML_RPC_Struct
|
326 |
|
|
)
|
327 |
|
|
);
|
328 |
dc1cd85d
|
Scott Ullrich
|
|
329 |
|
|
function merge_config_section_xmlrpc($raw_params) {
|
330 |
|
|
global $config, $xmlrpc_g;
|
331 |
c87f4b70
|
Ermal
|
|
332 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
333 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
334 |
fb0eb20b
|
Ermal
|
return;
|
335 |
|
|
}
|
336 |
c87f4b70
|
Ermal
|
|
337 |
db748384
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
338 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
339 |
|
|
xmlrpc_authfail();
|
340 |
db748384
|
Scott Ullrich
|
return $xmlrpc_g['return']['authfail'];
|
341 |
3dd2a278
|
Scott Ullrich
|
}
|
342 |
f9d7c5b3
|
Scott Ullrich
|
$config_new = array_overlay($config, $params[0]);
|
343 |
db748384
|
Scott Ullrich
|
$config = $config_new;
|
344 |
|
|
$mergedkeys = implode(",", array_keys($params[0]));
|
345 |
|
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
|
346 |
|
|
return $xmlrpc_g['return']['true'];
|
347 |
dc1cd85d
|
Scott Ullrich
|
}
|
348 |
|
|
|
349 |
|
|
/*****************************/
|
350 |
de63649b
|
Rafael Lucas
|
$filter_configure_doc = gettext("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.");
|
351 |
8da3de34
|
Colin Smith
|
$filter_configure_sig = array(
|
352 |
137f46d8
|
Ermal
|
array(
|
353 |
|
|
$XML_RPC_Boolean,
|
354 |
|
|
$XML_RPC_String
|
355 |
|
|
)
|
356 |
|
|
);
|
357 |
07a7b08f
|
Colin Smith
|
|
358 |
|
|
function filter_configure_xmlrpc($raw_params) {
|
359 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
360 |
137f46d8
|
Ermal
|
|
361 |
07a7b08f
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
362 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
363 |
|
|
xmlrpc_authfail();
|
364 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
365 |
3dd2a278
|
Scott Ullrich
|
}
|
366 |
07a7b08f
|
Colin Smith
|
filter_configure();
|
367 |
e700437b
|
Scott Ullrich
|
system_routing_configure();
|
368 |
41e6d4bd
|
Seth Mos
|
setup_gateways_monitor();
|
369 |
651c32e2
|
Bill Marquette
|
relayd_configure();
|
370 |
c3fef0c9
|
jim-p
|
require_once("openvpn.inc");
|
371 |
|
|
openvpn_resync_all();
|
372 |
|
|
services_dhcpd_configure();
|
373 |
62c4d0fb
|
jim-p
|
services_dnsmasq_configure();
|
374 |
0ce72662
|
jim-p
|
local_sync_accounts();
|
375 |
137f46d8
|
Ermal
|
|
376 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
377 |
07a7b08f
|
Colin Smith
|
}
|
378 |
|
|
|
379 |
8da3de34
|
Colin Smith
|
/*****************************/
|
380 |
de63649b
|
Rafael Lucas
|
$carp_configure_doc = gettext("Basic XMLRPC wrapper for configuring CARP interfaces.");
|
381 |
efe7562e
|
Scott Ullrich
|
$carp_configure_sig = array(
|
382 |
137f46d8
|
Ermal
|
array(
|
383 |
|
|
$XML_RPC_Boolean,
|
384 |
|
|
$XML_RPC_String
|
385 |
|
|
)
|
386 |
|
|
);
|
387 |
efe7562e
|
Scott Ullrich
|
|
388 |
|
|
function interfaces_carp_configure_xmlrpc($raw_params) {
|
389 |
|
|
global $xmlrpc_g;
|
390 |
137f46d8
|
Ermal
|
|
391 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
392 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
393 |
fb0eb20b
|
Ermal
|
return;
|
394 |
|
|
}
|
395 |
c87f4b70
|
Ermal
|
|
396 |
efe7562e
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
397 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
398 |
|
|
xmlrpc_authfail();
|
399 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
400 |
3dd2a278
|
Scott Ullrich
|
}
|
401 |
efe7562e
|
Scott Ullrich
|
interfaces_vips_configure();
|
402 |
137f46d8
|
Ermal
|
|
403 |
efe7562e
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
404 |
|
|
}
|
405 |
|
|
|
406 |
|
|
/*****************************/
|
407 |
de63649b
|
Rafael Lucas
|
$check_firmware_version_doc = gettext("Basic XMLRPC wrapper for check_firmware_version. This function will return the output of check_firmware_version upon completion.");
|
408 |
137f46d8
|
Ermal
|
|
409 |
8da3de34
|
Colin Smith
|
$check_firmware_version_sig = array(
|
410 |
137f46d8
|
Ermal
|
array(
|
411 |
|
|
$XML_RPC_String,
|
412 |
|
|
$XML_RPC_String
|
413 |
|
|
)
|
414 |
|
|
);
|
415 |
44488c3c
|
Colin Smith
|
|
416 |
|
|
function check_firmware_version_xmlrpc($raw_params) {
|
417 |
b4d19b46
|
Bill Marquette
|
global $xmlrpc_g, $XML_RPC_String;
|
418 |
137f46d8
|
Ermal
|
|
419 |
b4d19b46
|
Bill Marquette
|
$params = xmlrpc_params_to_php($raw_params);
|
420 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
421 |
|
|
xmlrpc_authfail();
|
422 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
423 |
3dd2a278
|
Scott Ullrich
|
}
|
424 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
|
425 |
44488c3c
|
Colin Smith
|
}
|
426 |
|
|
|
427 |
e501de37
|
Ermal
|
/*****************************/
|
428 |
0567899d
|
Ermal
|
$pfsense_firmware_version_doc = gettext("Basic XMLRPC wrapper for check_firmware_version. This function will return the output of check_firmware_version upon completion.");
|
429 |
|
|
|
430 |
|
|
$pfsense_firmware_version_sig = array (
|
431 |
|
|
array (
|
432 |
|
|
$XML_RPC_Struct,
|
433 |
|
|
$XML_RPC_String
|
434 |
|
|
)
|
435 |
|
|
);
|
436 |
e501de37
|
Ermal
|
|
437 |
|
|
function pfsense_firmware_version_xmlrpc($raw_params) {
|
438 |
0567899d
|
Ermal
|
global $xmlrpc_g;
|
439 |
e501de37
|
Ermal
|
|
440 |
|
|
$params = xmlrpc_params_to_php($raw_params);
|
441 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
442 |
|
|
xmlrpc_authfail();
|
443 |
|
|
return $xmlrpc_g['return']['authfail'];
|
444 |
|
|
}
|
445 |
0567899d
|
Ermal
|
return new XML_RPC_Response(XML_RPC_encode(host_firmware_version()));
|
446 |
e501de37
|
Ermal
|
}
|
447 |
|
|
|
448 |
8da3de34
|
Colin Smith
|
/*****************************/
|
449 |
de63649b
|
Rafael Lucas
|
$reboot_doc = gettext("Basic XMLRPC wrapper for rc.reboot.");
|
450 |
1cdca133
|
Colin Smith
|
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
451 |
bd0fe65b
|
Colin Smith
|
function reboot_xmlrpc($raw_params) {
|
452 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
453 |
137f46d8
|
Ermal
|
|
454 |
bd0fe65b
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
455 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
456 |
|
|
xmlrpc_authfail();
|
457 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
458 |
3dd2a278
|
Scott Ullrich
|
}
|
459 |
53cf5533
|
Colin Smith
|
mwexec_bg("/etc/rc.reboot");
|
460 |
137f46d8
|
Ermal
|
|
461 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
462 |
bd0fe65b
|
Colin Smith
|
}
|
463 |
|
|
|
464 |
8da3de34
|
Colin Smith
|
/*****************************/
|
465 |
|
|
$get_notices_sig = array(
|
466 |
137f46d8
|
Ermal
|
array(
|
467 |
|
|
$XML_RPC_Array,
|
468 |
|
|
$XML_RPC_String
|
469 |
|
|
),
|
470 |
|
|
array(
|
471 |
|
|
$XML_RPC_Array
|
472 |
|
|
)
|
473 |
|
|
);
|
474 |
8da3de34
|
Colin Smith
|
|
475 |
d9064267
|
Colin Smith
|
function get_notices_xmlrpc($raw_params) {
|
476 |
8da3de34
|
Colin Smith
|
global $g, $xmlrpc_g;
|
477 |
137f46d8
|
Ermal
|
|
478 |
b4d19b46
|
Bill Marquette
|
$params = xmlrpc_params_to_php($raw_params);
|
479 |
3dd2a278
|
Scott Ullrich
|
if(!xmlrpc_auth($params)) {
|
480 |
|
|
xmlrpc_authfail();
|
481 |
|
|
return $xmlrpc_g['return']['authfail'];
|
482 |
|
|
}
|
483 |
0674f163
|
sullrich
|
require("notices.inc");
|
484 |
8da3de34
|
Colin Smith
|
if(!$params) {
|
485 |
d9064267
|
Colin Smith
|
$toreturn = get_notices();
|
486 |
|
|
} else {
|
487 |
8da3de34
|
Colin Smith
|
$toreturn = get_notices($params);
|
488 |
d9064267
|
Colin Smith
|
}
|
489 |
|
|
$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
|
490 |
137f46d8
|
Ermal
|
|
491 |
d9064267
|
Colin Smith
|
return $response;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
67d78c87
|
Ermal
|
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
|
495 |
|
|
|
496 |
8da3de34
|
Colin Smith
|
/*****************************/
|
497 |
21dc3a7d
|
Colin Smith
|
$server = new XML_RPC_Server(
|
498 |
|
|
array(
|
499 |
137f46d8
|
Ermal
|
'pfsense.exec_shell' => array('function' => 'exec_shell_xmlrpc',
|
500 |
0567899d
|
Ermal
|
'signature' => $exec_shell_sig,
|
501 |
|
|
'docstring' => $exec_shell_doc),
|
502 |
137f46d8
|
Ermal
|
'pfsense.exec_php' => array('function' => 'exec_php_xmlrpc',
|
503 |
0567899d
|
Ermal
|
'signature' => $exec_php_sig,
|
504 |
|
|
'docstring' => $exec_php_doc),
|
505 |
137f46d8
|
Ermal
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
506 |
0567899d
|
Ermal
|
'signature' => $filter_configure_sig,
|
507 |
|
|
'docstring' => $filter_configure_doc),
|
508 |
137f46d8
|
Ermal
|
'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
|
509 |
0567899d
|
Ermal
|
'docstring' => $carp_configure_sig),
|
510 |
137f46d8
|
Ermal
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
511 |
0567899d
|
Ermal
|
'signature' => $backup_config_section_sig,
|
512 |
|
|
'docstring' => $backup_config_section_doc),
|
513 |
137f46d8
|
Ermal
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
514 |
0567899d
|
Ermal
|
'signature' => $restore_config_section_sig,
|
515 |
|
|
'docstring' => $restore_config_section_doc),
|
516 |
137f46d8
|
Ermal
|
'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
|
517 |
0567899d
|
Ermal
|
'signature' => $merge_config_section_sig,
|
518 |
|
|
'docstring' => $merge_config_section_doc),
|
519 |
137f46d8
|
Ermal
|
'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
|
520 |
0567899d
|
Ermal
|
'signature' => $merge_config_section_sig,
|
521 |
|
|
'docstring' => $merge_config_section_doc),
|
522 |
137f46d8
|
Ermal
|
'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
|
523 |
0567899d
|
Ermal
|
'signature' => $check_firmware_version_sig,
|
524 |
|
|
'docstring' => $check_firmware_version_doc),
|
525 |
e501de37
|
Ermal
|
'pfsense.host_firmware_version' => array('function' => 'pfsense_firmware_version_xmlrpc',
|
526 |
0567899d
|
Ermal
|
'signature' => $pfsense_firmware_version_sig,
|
527 |
|
|
'docstring' => $host_firmware_version_doc),
|
528 |
137f46d8
|
Ermal
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
529 |
0567899d
|
Ermal
|
'signature' => $reboot_sig,
|
530 |
|
|
'docstring' => $reboot_doc),
|
531 |
137f46d8
|
Ermal
|
'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
|
532 |
0567899d
|
Ermal
|
'signature' => $get_notices_sig)
|
533 |
50d49018
|
Colin Smith
|
)
|
534 |
|
|
);
|
535 |
b298dd06
|
Scott Ullrich
|
|
536 |
67d78c87
|
Ermal
|
unlock($xmlrpclockkey);
|
537 |
|
|
|
538 |
f9d7c5b3
|
Scott Ullrich
|
function array_overlay($a1,$a2)
|
539 |
|
|
{
|
540 |
|
|
foreach($a1 as $k => $v) {
|
541 |
|
|
if(!array_key_exists($k,$a2)) continue;
|
542 |
|
|
if(is_array($v) && is_array($a2[$k])){
|
543 |
|
|
$a1[$k] = array_overlay($v,$a2[$k]);
|
544 |
|
|
}else{
|
545 |
|
|
$a1[$k] = $a2[$k];
|
546 |
0b581a8a
|
Scott Ullrich
|
}
|
547 |
|
|
}
|
548 |
f9d7c5b3
|
Scott Ullrich
|
return $a1;
|
549 |
0b581a8a
|
Scott Ullrich
|
}
|
550 |
|
|
|
551 |
de63649b
|
Rafael Lucas
|
?>
|