Project

General

Profile

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