Project

General

Profile

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