Project

General

Profile

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