Project

General

Profile

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