Project

General

Profile

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