Project

General

Profile

Download (17.4 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
require("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 c87f4b70 Ermal
	if (xmlrpc_loop_detect())
146
		log_error("Disallowing CARP sync loop");
147
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 c87f4b70 Ermal
	if (xmlrpc_loop_detect())
174
		log_error("Disallowing CARP sync loop");
175
176 57e6d4c9 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
177 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
178
		xmlrpc_authfail();
179 19b5c3e7 Ermal
		return $xmlrpc_g['return']['authfail'];
180 3dd2a278 Scott Ullrich
	}
181 1b99e1e5 jim-p
182
	// Some sections should just be copied and not merged or we end
183
	//   up unable to sync the deletion of the last item in a section
184 c4bd43cc Renato Botelho
	$sync_full = array('ipsec', 'aliases', 'wol', 'load_balancer', 'openvpn', 'cert', 'ca', 'crl', 'schedules', 'filter', 'nat', 'dhcpd');
185 1b99e1e5 jim-p
	$sync_full_done = array();
186
	foreach ($sync_full as $syncfull) {
187
		if (isset($params[0][$syncfull])) {
188
			$config[$syncfull] = $params[0][$syncfull];
189
			unset($params[0][$syncfull]);
190
			$sync_full_done[] = $syncfull;
191
		}
192
	}
193
194 a8200dbf Ermal
	$vipbackup = array();
195 51611440 Ermal
	$oldvips = array();
196 4d775dd0 Ermal
	if (isset($params[0]['virtualip'])) {
197 7b47bd4c Ermal
		if (is_array($config['virtualip']['vip'])) {
198 51611440 Ermal
			foreach ($config['virtualip']['vip'] as $vipindex => $vip) {
199
				if ($vip['mode'] == "carp")
200 7b47bd4c Ermal
					$oldvips["{$vip['interface']}_vip{$vip['vhid']}"] = "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}";
201
				else if ($vip['mode'] == "ipalias" && strstr($vip['interface'], "_vip"))
202 2708a5cf Ermal
					$oldvips[$vip['subnet']] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}";
203 7b47bd4c Ermal
				else if (($vip['mode'] == "ipalias" || $vip['mode'] == 'proxyarp') && !strstr($vip['interface'], "_vip"))
204 51611440 Ermal
					$vipbackup[] = $vip;
205
			}
206 19b5c3e7 Ermal
		}
207
	}
208 f51d4f98 Ermal
209 b019222a pierrepomes
        // For vip section, first keep items sent from the master
210 aa6699fb jim-p
	$config = array_merge_recursive_unique($config, $params[0]);
211 51611440 Ermal
212 f51d4f98 Ermal
        /* Then add ipalias and proxyarp types already defined on the backup */
213
	if (is_array($vipbackup) && !empty($vipbackup)) {
214 51611440 Ermal
		if (!is_array($config['virtualip']))
215
			$config['virtualip'] = array();
216 f51d4f98 Ermal
		if (!is_array($config['virtualip']['vip']))
217
			$config['virtualip']['vip'] = array();
218
		foreach ($vipbackup as $vip)
219 51611440 Ermal
			array_unshift($config['virtualip']['vip'], $vip);
220 a8200dbf Ermal
	}
221 51611440 Ermal
222
	/* Log what happened */
223 1b99e1e5 jim-p
	$mergedkeys = implode(",", array_merge(array_keys($params[0]), $sync_full_done));
224 3a3fb8ea Erik Fonnesbeck
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
225 51611440 Ermal
226
	/* 
227
	 * The real work on handling the vips specially
228
	 * This is a copy of intefaces_vips_configure with addition of not reloading existing/not changed carps
229
	 */
230 63f81fbd Ermal
	if (isset($params[0]['virtualip']) && is_array($config['virtualip']) && is_array($config['virtualip']['vip'])) {
231 51611440 Ermal
		$carp_setuped = false;
232 f51d4f98 Ermal
		$anyproxyarp = false;
233 51611440 Ermal
		foreach ($config['virtualip']['vip'] as $vip) {
234 7b47bd4c Ermal
			if ($vip['mode'] == "carp" && isset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"])) {
235
				if ($oldvips["{$vip['interface']}_vip{$vip['vhid']}"] == "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}") {
236 2708a5cf Ermal
					if (does_vip_exist($vip)) {
237 7b47bd4c Ermal
						unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
238 d1e03822 Ermal
						continue; // Skip reconfiguring this vips since nothing has changed.
239 19ed1624 Ermal
					}
240 92ca32cc Ermal
				}
241 7b47bd4c Ermal
				unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
242
			} else if ($vip['mode'] == "ipalias" && strstr($vip['interface'], "_vip") && isset($oldvips[$vip['subnet']])) {
243 2708a5cf Ermal
				if ($oldvips[$vip['subnet']] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}") {
244
					if (does_vip_exist($vip)) {
245
						unset($oldvips[$vip['subnet']]);
246
						continue; // Skip reconfiguring this vips since nothing has changed.
247
					}
248
				}
249
				unset($oldvips[$vip['subnet']]);
250 51611440 Ermal
			}
251
252
			switch ($vip['mode']) {
253
			case "proxyarp":
254
				$anyproxyarp = true;
255
				break;
256
			case "ipalias":
257 3dacbd7c Renato Botelho
				interface_ipalias_configure($vip);
258 51611440 Ermal
				break;
259
			case "carp":
260
				if ($carp_setuped == false)
261
                                        $carp_setuped = true;
262
				interface_carp_configure($vip);
263
				break;
264
			}
265
		}
266
		/* Cleanup remaining old carps */
267
		foreach ($oldvips as $oldvipif => $oldvippar) {
268 7b47bd4c Ermal
			if (!is_ipaddr($oldvipif) && does_interface_exist($oldvipif))
269
					pfSense_interface_destroy($oldvipif);
270 51611440 Ermal
		}
271
		if ($carp_setuped == true)
272
			interfaces_carp_setup();
273
		if ($anyproxyarp == true)
274
			interface_proxyarp_configure();
275
	}
276 137f46d8 Ermal
277 d026178f Renato Botelho
	if (isset($old_config['ipsec']['enable']) !== isset($config['ipsec']['enable']))
278
		vpn_ipsec_configure();
279
280
	unset($old_config);
281
282 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
283 50d49018 Colin Smith
}
284
285 82ae5cfc Scott Ullrich
/*****************************/
286 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.");
287 82ae5cfc Scott Ullrich
$merge_config_section_sig = array(
288 137f46d8 Ermal
	array(
289
		$XML_RPC_Boolean,
290
		$XML_RPC_String,
291
		$XML_RPC_Struct
292
	)
293
);
294 82ae5cfc Scott Ullrich
295
function merge_installedpackages_section_xmlrpc($raw_params) {
296
	global $config, $xmlrpc_g;
297 137f46d8 Ermal
298 c87f4b70 Ermal
	if (xmlrpc_loop_detect())
299
		log_error("Disallowing CARP sync loop");
300
301 82ae5cfc Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
302 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
303
		xmlrpc_authfail();
304 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
305 3dd2a278 Scott Ullrich
	}
306 82ae5cfc Scott Ullrich
	$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
307
	$mergedkeys = implode(",", array_keys($params[0]));
308 3a3fb8ea Erik Fonnesbeck
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
309 137f46d8 Ermal
310 82ae5cfc Scott Ullrich
	return $xmlrpc_g['return']['true'];
311
}
312
313 8da3de34 Colin Smith
/*****************************/
314 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.");
315 dc1cd85d 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 dc1cd85d Scott Ullrich
323
function merge_config_section_xmlrpc($raw_params) {
324
	global $config, $xmlrpc_g;
325 c87f4b70 Ermal
326
	if (xmlrpc_loop_detect())
327
		log_error("Disallowing CARP sync loop");
328
329 db748384 Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
330 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
331
		xmlrpc_authfail();
332 db748384 Scott Ullrich
		return $xmlrpc_g['return']['authfail'];
333 3dd2a278 Scott Ullrich
	}
334 f9d7c5b3 Scott Ullrich
	$config_new = array_overlay($config, $params[0]);
335 db748384 Scott Ullrich
	$config = $config_new;
336
	$mergedkeys = implode(",", array_keys($params[0]));
337
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
338
	return $xmlrpc_g['return']['true'];
339 dc1cd85d Scott Ullrich
}
340
341
/*****************************/
342 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.");
343 8da3de34 Colin Smith
$filter_configure_sig = array(
344 137f46d8 Ermal
	array(
345
		$XML_RPC_Boolean,
346
		$XML_RPC_String
347
	)
348
);
349 07a7b08f Colin Smith
350
function filter_configure_xmlrpc($raw_params) {
351 8da3de34 Colin Smith
	global $xmlrpc_g;
352 137f46d8 Ermal
353 07a7b08f Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
354 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
355
		xmlrpc_authfail();
356 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
357 3dd2a278 Scott Ullrich
	}
358 07a7b08f Colin Smith
	filter_configure();
359 e700437b Scott Ullrich
	system_routing_configure();
360 41e6d4bd Seth Mos
	setup_gateways_monitor();
361 651c32e2 Bill Marquette
	relayd_configure();
362 c3fef0c9 jim-p
	require_once("openvpn.inc");
363
	openvpn_resync_all();
364
	services_dhcpd_configure();
365 62c4d0fb jim-p
	services_dnsmasq_configure();
366 0ce72662 jim-p
	local_sync_accounts();
367 137f46d8 Ermal
368 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
369 07a7b08f Colin Smith
}
370
371 8da3de34 Colin Smith
/*****************************/
372 de63649b Rafael Lucas
$carp_configure_doc = gettext("Basic XMLRPC wrapper for configuring CARP interfaces.");
373 efe7562e Scott Ullrich
$carp_configure_sig = array(
374 137f46d8 Ermal
	array(
375
		$XML_RPC_Boolean,
376
		$XML_RPC_String
377
	)
378
);
379 efe7562e Scott Ullrich
380
function interfaces_carp_configure_xmlrpc($raw_params) {
381
	global $xmlrpc_g;
382 137f46d8 Ermal
383 c87f4b70 Ermal
	if (xmlrpc_loop_detect())
384
		log_error("Disallowing CARP sync loop");
385
386 efe7562e Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
387 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
388
		xmlrpc_authfail();
389 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
390 3dd2a278 Scott Ullrich
	}
391 efe7562e Scott Ullrich
	interfaces_vips_configure();
392 137f46d8 Ermal
393 efe7562e Scott Ullrich
	return $xmlrpc_g['return']['true'];
394
}
395
396
/*****************************/
397 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.");
398 137f46d8 Ermal
399 8da3de34 Colin Smith
$check_firmware_version_sig = array(
400 137f46d8 Ermal
	array(
401
		$XML_RPC_String,
402
		$XML_RPC_String
403
	)
404
);
405 44488c3c Colin Smith
406
function check_firmware_version_xmlrpc($raw_params) {
407 b4d19b46 Bill Marquette
	global $xmlrpc_g, $XML_RPC_String;
408 137f46d8 Ermal
409 b4d19b46 Bill Marquette
	$params = xmlrpc_params_to_php($raw_params);
410 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
411
		xmlrpc_authfail();
412 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
413 3dd2a278 Scott Ullrich
	}
414 8da3de34 Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
415 44488c3c Colin Smith
}
416
417 e501de37 Ermal
/*****************************/
418 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.");
419
420
$pfsense_firmware_version_sig = array (
421
        array (
422
                $XML_RPC_Struct,
423
                $XML_RPC_String
424
        )
425
);
426 e501de37 Ermal
427
function pfsense_firmware_version_xmlrpc($raw_params) {
428 0567899d Ermal
        global $xmlrpc_g;
429 e501de37 Ermal
430
        $params = xmlrpc_params_to_php($raw_params);
431 3dd2a278 Scott Ullrich
        if(!xmlrpc_auth($params)) {
432
			xmlrpc_authfail();
433
			return $xmlrpc_g['return']['authfail'];
434
		}
435 0567899d Ermal
        return new XML_RPC_Response(XML_RPC_encode(host_firmware_version()));
436 e501de37 Ermal
}
437
438 8da3de34 Colin Smith
/*****************************/
439 de63649b Rafael Lucas
$reboot_doc = gettext("Basic XMLRPC wrapper for rc.reboot.");
440 1cdca133 Colin Smith
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
441 bd0fe65b Colin Smith
function reboot_xmlrpc($raw_params) {
442 8da3de34 Colin Smith
	global $xmlrpc_g;
443 137f46d8 Ermal
444 bd0fe65b Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
445 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
446
		xmlrpc_authfail();
447 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
448 3dd2a278 Scott Ullrich
	}
449 53cf5533 Colin Smith
	mwexec_bg("/etc/rc.reboot");
450 137f46d8 Ermal
451 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
452 bd0fe65b Colin Smith
}
453
454 8da3de34 Colin Smith
/*****************************/
455
$get_notices_sig = array(
456 137f46d8 Ermal
	array(
457
		$XML_RPC_Array,
458
		$XML_RPC_String
459
	),
460
	array(
461
		$XML_RPC_Array
462
	)
463
);
464 8da3de34 Colin Smith
465 d9064267 Colin Smith
function get_notices_xmlrpc($raw_params) {
466 8da3de34 Colin Smith
	global $g, $xmlrpc_g;
467 137f46d8 Ermal
468 b4d19b46 Bill Marquette
	$params = xmlrpc_params_to_php($raw_params);
469 3dd2a278 Scott Ullrich
	if(!xmlrpc_auth($params)) {
470
		xmlrpc_authfail();
471
		return $xmlrpc_g['return']['authfail'];
472
	}
473 0674f163 sullrich
	require("notices.inc");
474 8da3de34 Colin Smith
	if(!$params) {
475 d9064267 Colin Smith
		$toreturn = get_notices();
476
	} else {
477 8da3de34 Colin Smith
		$toreturn = get_notices($params);
478 d9064267 Colin Smith
	}
479
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
480 137f46d8 Ermal
481 d9064267 Colin Smith
	return $response;
482
}
483
484 67d78c87 Ermal
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
485
486 8da3de34 Colin Smith
/*****************************/
487 21dc3a7d Colin Smith
$server = new XML_RPC_Server(
488
        array(
489 137f46d8 Ermal
		'pfsense.exec_shell' => array('function' => 'exec_shell_xmlrpc',
490 0567899d Ermal
			'signature' => $exec_shell_sig,
491
			'docstring' => $exec_shell_doc),
492 137f46d8 Ermal
		'pfsense.exec_php' => array('function' => 'exec_php_xmlrpc',
493 0567899d Ermal
			'signature' => $exec_php_sig,
494
			'docstring' => $exec_php_doc),	
495 137f46d8 Ermal
		'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
496 0567899d Ermal
			'signature' => $filter_configure_sig,
497
			'docstring' => $filter_configure_doc),
498 137f46d8 Ermal
		'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
499 0567899d Ermal
			'docstring' => $carp_configure_sig),
500 137f46d8 Ermal
		'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
501 0567899d Ermal
			'signature' => $backup_config_section_sig,
502
			'docstring' => $backup_config_section_doc),
503 137f46d8 Ermal
		'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
504 0567899d Ermal
			'signature' => $restore_config_section_sig,
505
			'docstring' => $restore_config_section_doc),
506 137f46d8 Ermal
		'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
507 0567899d Ermal
			'signature' => $merge_config_section_sig,
508
			'docstring' => $merge_config_section_doc),
509 137f46d8 Ermal
		'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
510 0567899d Ermal
			'signature' => $merge_config_section_sig,
511
			'docstring' => $merge_config_section_doc),							
512 137f46d8 Ermal
		'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
513 0567899d Ermal
			'signature' => $check_firmware_version_sig,
514
			'docstring' => $check_firmware_version_doc),
515 e501de37 Ermal
		'pfsense.host_firmware_version' => array('function' => 'pfsense_firmware_version_xmlrpc',
516 0567899d Ermal
			'signature' => $pfsense_firmware_version_sig,
517
			'docstring' => $host_firmware_version_doc),
518 137f46d8 Ermal
		'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
519 0567899d Ermal
			'signature' => $reboot_sig,
520
			'docstring' => $reboot_doc),
521 137f46d8 Ermal
		'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
522 0567899d Ermal
			'signature' => $get_notices_sig)
523 50d49018 Colin Smith
        )
524
);
525 b298dd06 Scott Ullrich
526 67d78c87 Ermal
unlock($xmlrpclockkey);
527
528 f9d7c5b3 Scott Ullrich
    function array_overlay($a1,$a2)
529
    {
530
        foreach($a1 as $k => $v) {
531
            if(!array_key_exists($k,$a2)) continue;
532
            if(is_array($v) && is_array($a2[$k])){
533
                $a1[$k] = array_overlay($v,$a2[$k]);
534
            }else{
535
                $a1[$k] = $a2[$k];
536 0b581a8a Scott Ullrich
            }
537
        }
538 f9d7c5b3 Scott Ullrich
        return $a1;
539 0b581a8a Scott Ullrich
    }
540
541 de63649b Rafael Lucas
?>