Project

General

Profile

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