Project

General

Profile

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