Project

General

Profile

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