Project

General

Profile

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