Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
1 50d49018 Colin Smith
<?php
2
/*
3 c5d81585 Renato Botelho
 * xmlrpc.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * Copyright (c) 2005 Colin Smith
8
 * All rights reserved.
9 191cb31d Stephen Beaver
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 191cb31d Stephen Beaver
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 191cb31d Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 191cb31d Stephen Beaver
 */
22 50d49018 Colin Smith
23 6b07c15a Matthew Grooms
##|+PRIV
24
##|*IDENT=page-xmlrpclibrary
25 5230f468 jim-p
##|*NAME=XMLRPC Library
26 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'XMLRPC Library' page.
27
##|*MATCH=xmlrpc.php*
28
##|-PRIV
29
30 c81ef6e2 Phil Davis
require_once("config.inc");
31
require_once("functions.inc");
32 f6339216 jim-p
require_once("filter.inc");
33 c81ef6e2 Phil Davis
require_once("ipsec.inc");
34
require_once("vpn.inc");
35
require_once("shaper.inc");
36
require_once("xmlrpc_server.inc");
37
require_once("xmlrpc.inc");
38 50d49018 Colin Smith
39 c87f4b70 Ermal
function xmlrpc_loop_detect() {
40
	global $config;
41
42
	/* grab sync to ip if enabled */
43 962f215d Phil Davis
	if ($config['hasync']) {
44 c87f4b70 Ermal
		$synchronizetoip = $config['hasync']['synchronizetoip'];
45 962f215d Phil Davis
	}
46
	if ($synchronizetoip) {
47
		if ($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
48
			return true;
49
		}
50 ff664954 Scott Ullrich
	}
51 c87f4b70 Ermal
52
	return false;
53 ff664954 Scott Ullrich
}
54
55 8da3de34 Colin Smith
$xmlrpc_g = array(
56 137f46d8 Ermal
	"return" => array(
57
		"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
58
		"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
59
		"authfail" => new XML_RPC_Response(new XML_RPC_Value(gettext("Authentication failed"), $XML_RPC_String))
60
	)
61
);
62 8da3de34 Colin Smith
63
/*
64
 *   pfSense XMLRPC errors
65
 *   $XML_RPC_erruser + 1 = Auth failure
66
 */
67
$XML_RPC_erruser = 200;
68
69
/* EXPOSED FUNCTIONS */
70 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.");
71 c3638879 Scott Ullrich
$exec_php_sig = array(
72 137f46d8 Ermal
	array(
73
		$XML_RPC_Boolean, // First signature element is return value.
74
		$XML_RPC_String, // password
75
		$XML_RPC_String, // shell code to exec
76
	)
77
);
78 c3638879 Scott Ullrich
79 3dd2a278 Scott Ullrich
function xmlrpc_authfail() {
80
	log_auth("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']}");
81
}
82
83 c3638879 Scott Ullrich
function exec_php_xmlrpc($raw_params) {
84
	global $config, $xmlrpc_g;
85 137f46d8 Ermal
86 c3638879 Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
87 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
88 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
89 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
90 3dd2a278 Scott Ullrich
	}
91 c3638879 Scott Ullrich
	$exec_php = $params[0];
92
	eval($exec_php);
93 962f215d Phil Davis
	if ($toreturn) {
94 2c0dd581 Scott Ullrich
		$response = XML_RPC_encode($toreturn);
95
		return new XML_RPC_Response($response);
96 962f215d Phil Davis
	} else {
97 2c0dd581 Scott Ullrich
		return $xmlrpc_g['return']['true'];
98 962f215d Phil Davis
	}
99 c3638879 Scott Ullrich
}
100
101
/*****************************/
102 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.");
103 c3638879 Scott Ullrich
$exec_shell_sig = array(
104 137f46d8 Ermal
	array(
105
		$XML_RPC_Boolean, // First signature element is return value.
106
		$XML_RPC_String, // password
107
		$XML_RPC_String, // shell code to exec
108
	)
109
);
110 c3638879 Scott Ullrich
111
function exec_shell_xmlrpc($raw_params) {
112
	global $config, $xmlrpc_g;
113 137f46d8 Ermal
114 c3638879 Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
115 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
116 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
117 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
118 3dd2a278 Scott Ullrich
	}
119 c3638879 Scott Ullrich
	$shell_cmd = $params[0];
120
	mwexec($shell_cmd);
121 137f46d8 Ermal
122 c3638879 Scott Ullrich
	return $xmlrpc_g['return']['true'];
123
}
124
125
/*****************************/
126 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.");
127 8da3de34 Colin Smith
$backup_config_section_sig = array(
128 137f46d8 Ermal
	array(
129
		$XML_RPC_Struct, // First signature element is return value.
130
		$XML_RPC_String,
131
		$XML_RPC_Array
132
	)
133
);
134 21dc3a7d Colin Smith
135 57e6d4c9 Colin Smith
function backup_config_section_xmlrpc($raw_params) {
136 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
137 137f46d8 Ermal
138 fb0eb20b Ermal
	if (xmlrpc_loop_detect()) {
139 c87f4b70 Ermal
		log_error("Disallowing CARP sync loop");
140 fb0eb20b Ermal
		return;
141
	}
142 c87f4b70 Ermal
143 8da3de34 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
144 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
145 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
146 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
147 3dd2a278 Scott Ullrich
	}
148 03d89831 Scott Ullrich
	$val = array_intersect_key($config, array_flip($params[0]));
149 137f46d8 Ermal
150 8da3de34 Colin Smith
	return new XML_RPC_Response(XML_RPC_encode($val));
151 50d49018 Colin Smith
}
152
153 8da3de34 Colin Smith
/*****************************/
154 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.");
155 8da3de34 Colin Smith
$restore_config_section_sig = array(
156 137f46d8 Ermal
	array(
157
		$XML_RPC_Boolean,
158
		$XML_RPC_String,
159
		$XML_RPC_Struct
160
	)
161
);
162 21dc3a7d Colin Smith
163 57e6d4c9 Colin Smith
function restore_config_section_xmlrpc($raw_params) {
164 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
165 137f46d8 Ermal
166 d026178f Renato Botelho
	$old_config = $config;
167 1a2de6d6 Luiz Otavio O Souza
	$old_ipsec_enabled = ipsec_enabled();
168 d026178f Renato Botelho
169 fb0eb20b Ermal
	if (xmlrpc_loop_detect()) {
170 c87f4b70 Ermal
		log_error("Disallowing CARP sync loop");
171 fb0eb20b Ermal
		return;
172
	}
173 c87f4b70 Ermal
174 57e6d4c9 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
175 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
176 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
177 19b5c3e7 Ermal
		return $xmlrpc_g['return']['authfail'];
178 3dd2a278 Scott Ullrich
	}
179 1b99e1e5 jim-p
180
	// Some sections should just be copied and not merged or we end
181
	//   up unable to sync the deletion of the last item in a section
182 f29fd4d0 Renato Botelho
	$sync_full = array('dnsmasq', 'unbound', 'ipsec', 'aliases', 'wol', 'load_balancer', 'openvpn', 'cert', 'ca', 'crl', 'schedules', 'filter', 'nat', 'dhcpd', 'dhcpv6');
183 1b99e1e5 jim-p
	$sync_full_done = array();
184
	foreach ($sync_full as $syncfull) {
185
		if (isset($params[0][$syncfull])) {
186
			$config[$syncfull] = $params[0][$syncfull];
187
			unset($params[0][$syncfull]);
188
			$sync_full_done[] = $syncfull;
189
		}
190
	}
191
192 a8200dbf Ermal
	$vipbackup = array();
193 51611440 Ermal
	$oldvips = array();
194 4d775dd0 Ermal
	if (isset($params[0]['virtualip'])) {
195 7b47bd4c Ermal
		if (is_array($config['virtualip']['vip'])) {
196 51611440 Ermal
			foreach ($config['virtualip']['vip'] as $vipindex => $vip) {
197 c14781e3 Renato Botelho
				if ($vip['mode'] == "carp") {
198
					$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['content'] = "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}";
199
					$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['interface'] = $vip['interface'];
200
					$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['subnet'] = $vip['subnet'];
201 2a5960b0 Luiz Otavio O Souza
				} else if ($vip['mode'] == "ipalias" && (substr($vip['interface'], 0, 4) == '_vip' || strstr($vip['interface'], "lo0"))) {
202 c14781e3 Renato Botelho
					$oldvips[$vip['subnet']]['content'] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}";
203
					$oldvips[$vip['subnet']]['interface'] = $vip['interface'];
204
					$oldvips[$vip['subnet']]['subnet'] = $vip['subnet'];
205 2a5960b0 Luiz Otavio O Souza
				} else if (($vip['mode'] == "ipalias" || $vip['mode'] == 'proxyarp') && !(substr($vip['interface'], 0, 4) == '_vip') || strstr($vip['interface'], "lo0")) {
206 51611440 Ermal
					$vipbackup[] = $vip;
207 c14781e3 Renato Botelho
				}
208 51611440 Ermal
			}
209 19b5c3e7 Ermal
		}
210
	}
211 f51d4f98 Ermal
212 962f215d Phil Davis
	// For vip section, first keep items sent from the master
213 aa6699fb jim-p
	$config = array_merge_recursive_unique($config, $params[0]);
214 51611440 Ermal
215 962f215d Phil Davis
	/* Then add ipalias and proxyarp types already defined on the backup */
216 f51d4f98 Ermal
	if (is_array($vipbackup) && !empty($vipbackup)) {
217 962f215d Phil Davis
		if (!is_array($config['virtualip'])) {
218 51611440 Ermal
			$config['virtualip'] = array();
219 962f215d Phil Davis
		}
220
		if (!is_array($config['virtualip']['vip'])) {
221 f51d4f98 Ermal
			$config['virtualip']['vip'] = array();
222 962f215d Phil Davis
		}
223
		foreach ($vipbackup as $vip) {
224 51611440 Ermal
			array_unshift($config['virtualip']['vip'], $vip);
225 962f215d Phil Davis
		}
226 a8200dbf Ermal
	}
227 51611440 Ermal
228
	/* Log what happened */
229 1b99e1e5 jim-p
	$mergedkeys = implode(",", array_merge(array_keys($params[0]), $sync_full_done));
230 6c07db48 Phil Davis
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
231 51611440 Ermal
232 962f215d Phil Davis
	/*
233 51611440 Ermal
	 * The real work on handling the vips specially
234
	 * This is a copy of intefaces_vips_configure with addition of not reloading existing/not changed carps
235
	 */
236 63f81fbd Ermal
	if (isset($params[0]['virtualip']) && is_array($config['virtualip']) && is_array($config['virtualip']['vip'])) {
237 51611440 Ermal
		$carp_setuped = false;
238 f51d4f98 Ermal
		$anyproxyarp = false;
239 51611440 Ermal
		foreach ($config['virtualip']['vip'] as $vip) {
240 7b47bd4c Ermal
			if ($vip['mode'] == "carp" && isset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"])) {
241 c14781e3 Renato Botelho
				if ($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['content'] == "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}") {
242 2708a5cf Ermal
					if (does_vip_exist($vip)) {
243 7b47bd4c Ermal
						unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
244 d1e03822 Ermal
						continue; // Skip reconfiguring this vips since nothing has changed.
245 19ed1624 Ermal
					}
246 92ca32cc Ermal
				}
247 7b47bd4c Ermal
			} else if ($vip['mode'] == "ipalias" && strstr($vip['interface'], "_vip") && isset($oldvips[$vip['subnet']])) {
248 c14781e3 Renato Botelho
				if ($oldvips[$vip['subnet']]['content'] == "{$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 962f215d Phil Davis
				case "proxyarp":
259
					$anyproxyarp = true;
260
					break;
261
				case "ipalias":
262
					interface_ipalias_configure($vip);
263
					break;
264
				case "carp":
265
					if ($carp_setuped == false) {
266
						$carp_setuped = true;
267
					}
268
					interface_carp_configure($vip);
269
					break;
270 51611440 Ermal
			}
271
		}
272
		/* Cleanup remaining old carps */
273 c14781e3 Renato Botelho
		foreach ($oldvips as $oldvipar) {
274
			$oldvipif = get_real_interface($oldvipar['interface']);
275 e3cffd6c Ermal LUÇI
			if (!empty($oldvipif)) {
276 962f215d Phil Davis
				if (is_ipaddrv6($oldvipar['subnet'])) {
277 e3cffd6c Ermal LUÇI
					 mwexec("/sbin/ifconfig " . escapeshellarg($oldvipif) . " inet6 " . escapeshellarg($oldvipar['subnet']) . " delete");
278 962f215d Phil Davis
				} else {
279 e3cffd6c Ermal LUÇI
					pfSense_interface_deladdress($oldvipif, $oldvipar['subnet']);
280 962f215d Phil Davis
				}
281 e3cffd6c Ermal LUÇI
			}
282 51611440 Ermal
		}
283 962f215d Phil Davis
		if ($carp_setuped == true) {
284 8ff85c39 Ermal
			interfaces_sync_setup();
285 962f215d Phil Davis
		}
286
		if ($anyproxyarp == true) {
287 51611440 Ermal
			interface_proxyarp_configure();
288 962f215d Phil Davis
		}
289 51611440 Ermal
	}
290 137f46d8 Ermal
291 1a2de6d6 Luiz Otavio O Souza
	if ($old_ipsec_enabled !== ipsec_enabled()) {
292 d026178f Renato Botelho
		vpn_ipsec_configure();
293 962f215d Phil Davis
	}
294 d026178f Renato Botelho
295
	unset($old_config);
296
297 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
298 50d49018 Colin Smith
}
299
300 82ae5cfc Scott Ullrich
/*****************************/
301 29e5cbb4 Phil Davis
$merge_installedpackages_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.");
302
$merge_installedpackages_section_sig = array(
303 137f46d8 Ermal
	array(
304
		$XML_RPC_Boolean,
305
		$XML_RPC_String,
306
		$XML_RPC_Struct
307
	)
308
);
309 82ae5cfc Scott Ullrich
310
function merge_installedpackages_section_xmlrpc($raw_params) {
311
	global $config, $xmlrpc_g;
312 137f46d8 Ermal
313 fb0eb20b Ermal
	if (xmlrpc_loop_detect()) {
314 c87f4b70 Ermal
		log_error("Disallowing CARP sync loop");
315 fb0eb20b Ermal
		return;
316
	}
317 c87f4b70 Ermal
318 82ae5cfc Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
319 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
320 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
321 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
322 3dd2a278 Scott Ullrich
	}
323 82ae5cfc Scott Ullrich
	$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
324
	$mergedkeys = implode(",", array_keys($params[0]));
325 6c07db48 Phil Davis
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
326 137f46d8 Ermal
327 82ae5cfc Scott Ullrich
	return $xmlrpc_g['return']['true'];
328
}
329
330 8da3de34 Colin Smith
/*****************************/
331 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.");
332 dc1cd85d Scott Ullrich
$merge_config_section_sig = array(
333 137f46d8 Ermal
	array(
334
		$XML_RPC_Boolean,
335
		$XML_RPC_String,
336
		$XML_RPC_Struct
337
	)
338
);
339 dc1cd85d Scott Ullrich
340
function merge_config_section_xmlrpc($raw_params) {
341
	global $config, $xmlrpc_g;
342 c87f4b70 Ermal
343 fb0eb20b Ermal
	if (xmlrpc_loop_detect()) {
344 c87f4b70 Ermal
		log_error("Disallowing CARP sync loop");
345 fb0eb20b Ermal
		return;
346
	}
347 c87f4b70 Ermal
348 db748384 Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
349 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
350 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
351 db748384 Scott Ullrich
		return $xmlrpc_g['return']['authfail'];
352 3dd2a278 Scott Ullrich
	}
353 f9d7c5b3 Scott Ullrich
	$config_new = array_overlay($config, $params[0]);
354 db748384 Scott Ullrich
	$config = $config_new;
355
	$mergedkeys = implode(",", array_keys($params[0]));
356
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
357
	return $xmlrpc_g['return']['true'];
358 dc1cd85d Scott Ullrich
}
359
360
/*****************************/
361 962f215d Phil Davis
$filter_configure_doc = gettext("Basic XMLRPC wrapper for filter_configure. This method must be called with one parameter: a string containing the local system\'s password. This function returns true upon completion.");
362 8da3de34 Colin Smith
$filter_configure_sig = array(
363 137f46d8 Ermal
	array(
364
		$XML_RPC_Boolean,
365
		$XML_RPC_String
366
	)
367
);
368 07a7b08f Colin Smith
369
function filter_configure_xmlrpc($raw_params) {
370 57b5da70 jim-p
	global $xmlrpc_g, $g, $config;
371 137f46d8 Ermal
372 07a7b08f Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
373 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
374 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
375 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
376 3dd2a278 Scott Ullrich
	}
377 07a7b08f Colin Smith
	filter_configure();
378 e700437b Scott Ullrich
	system_routing_configure();
379 41e6d4bd Seth Mos
	setup_gateways_monitor();
380 651c32e2 Bill Marquette
	relayd_configure();
381 c3fef0c9 jim-p
	require_once("openvpn.inc");
382
	openvpn_resync_all();
383 57b5da70 jim-p
384
	/* The DNS Resolver and the DNS Forwarder may both be active so long as
385
	 * they are running on different ports. See ticket #5882
386
	 */
387
	$need_dhcp_start = true;
388 962f215d Phil Davis
	if (isset($config['dnsmasq']['enable'])) {
389 57b5da70 jim-p
		/* Configure dnsmasq but tell it NOT to restart DHCP */
390
		services_dnsmasq_configure(false);
391
	} else {
392
		/* kill any running dnsmasq since it is not enabled. */
393
		if (file_exists("{$g['varrun_path']}/dnsmasq.pid")) {
394
			sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM");
395
		}
396
	}
397
	if (isset($config['unbound']['enable'])) {
398
		/* Configure unbound but tell it NOT to restart DHCP */
399
		services_unbound_configure(false);
400 962f215d Phil Davis
	} else {
401 57b5da70 jim-p
		/* kill any running Unbound instance since it is not enabled. */
402
		if (file_exists("{$g['varrun_path']}/unbound.pid")) {
403
			sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM");
404
		}
405 962f215d Phil Davis
	}
406 57b5da70 jim-p
407
	/* Call this separately since the above are manually set to skip the DHCP restart they normally perform.
408
	 * This avoids restarting dhcpd twice as described on ticket #3797
409
	 */
410
	services_dhcpd_configure();
411
412 0ce72662 jim-p
	local_sync_accounts();
413 137f46d8 Ermal
414 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
415 07a7b08f Colin Smith
}
416
417 8da3de34 Colin Smith
/*****************************/
418 de63649b Rafael Lucas
$carp_configure_doc = gettext("Basic XMLRPC wrapper for configuring CARP interfaces.");
419 efe7562e Scott Ullrich
$carp_configure_sig = array(
420 137f46d8 Ermal
	array(
421
		$XML_RPC_Boolean,
422
		$XML_RPC_String
423
	)
424
);
425 efe7562e Scott Ullrich
426
function interfaces_carp_configure_xmlrpc($raw_params) {
427
	global $xmlrpc_g;
428 137f46d8 Ermal
429 fb0eb20b Ermal
	if (xmlrpc_loop_detect()) {
430 c87f4b70 Ermal
		log_error("Disallowing CARP sync loop");
431 fb0eb20b Ermal
		return;
432
	}
433 c87f4b70 Ermal
434 efe7562e Scott Ullrich
	$params = xmlrpc_params_to_php($raw_params);
435 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
436 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
437 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
438 3dd2a278 Scott Ullrich
	}
439 efe7562e Scott Ullrich
	interfaces_vips_configure();
440 137f46d8 Ermal
441 efe7562e Scott Ullrich
	return $xmlrpc_g['return']['true'];
442
}
443
444
/*****************************/
445 0cdb94e1 Renato Botelho
$pfsense_firmware_version_doc = gettext("Basic XMLRPC wrapper for host_firmware_version. This function will return the output of host_firmware_version upon completion.");
446 0567899d Ermal
447
$pfsense_firmware_version_sig = array (
448 962f215d Phil Davis
	array (
449
		$XML_RPC_Struct,
450
		$XML_RPC_String
451
	)
452 0567899d Ermal
);
453 e501de37 Ermal
454
function pfsense_firmware_version_xmlrpc($raw_params) {
455 962f215d Phil Davis
		global $xmlrpc_g;
456 e501de37 Ermal
457 962f215d Phil Davis
		$params = xmlrpc_params_to_php($raw_params);
458
		if (!xmlrpc_auth($params)) {
459 3dd2a278 Scott Ullrich
			xmlrpc_authfail();
460
			return $xmlrpc_g['return']['authfail'];
461
		}
462 962f215d Phil Davis
		return new XML_RPC_Response(XML_RPC_encode(host_firmware_version()));
463 e501de37 Ermal
}
464
465 8da3de34 Colin Smith
/*****************************/
466 de63649b Rafael Lucas
$reboot_doc = gettext("Basic XMLRPC wrapper for rc.reboot.");
467 1cdca133 Colin Smith
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
468 bd0fe65b Colin Smith
function reboot_xmlrpc($raw_params) {
469 8da3de34 Colin Smith
	global $xmlrpc_g;
470 137f46d8 Ermal
471 bd0fe65b Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
472 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
473 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
474 137f46d8 Ermal
		return $xmlrpc_g['return']['authfail'];
475 3dd2a278 Scott Ullrich
	}
476 53cf5533 Colin Smith
	mwexec_bg("/etc/rc.reboot");
477 137f46d8 Ermal
478 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
479 bd0fe65b Colin Smith
}
480
481 8da3de34 Colin Smith
/*****************************/
482
$get_notices_sig = array(
483 137f46d8 Ermal
	array(
484
		$XML_RPC_Array,
485
		$XML_RPC_String
486
	),
487
	array(
488
		$XML_RPC_Array
489
	)
490
);
491 8da3de34 Colin Smith
492 d9064267 Colin Smith
function get_notices_xmlrpc($raw_params) {
493 8da3de34 Colin Smith
	global $g, $xmlrpc_g;
494 137f46d8 Ermal
495 b4d19b46 Bill Marquette
	$params = xmlrpc_params_to_php($raw_params);
496 962f215d Phil Davis
	if (!xmlrpc_auth($params)) {
497 3dd2a278 Scott Ullrich
		xmlrpc_authfail();
498
		return $xmlrpc_g['return']['authfail'];
499
	}
500 962f215d Phil Davis
	if (!function_exists("get_notices")) {
501 c81ef6e2 Phil Davis
		require_once("notices.inc");
502 962f215d Phil Davis
	}
503
	if (!$params) {
504 d9064267 Colin Smith
		$toreturn = get_notices();
505
	} else {
506 8da3de34 Colin Smith
		$toreturn = get_notices($params);
507 d9064267 Colin Smith
	}
508
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
509 137f46d8 Ermal
510 d9064267 Colin Smith
	return $response;
511
}
512
513 67d78c87 Ermal
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
514
515 8da3de34 Colin Smith
/*****************************/
516 21dc3a7d Colin Smith
$server = new XML_RPC_Server(
517 962f215d Phil Davis
	array(
518 137f46d8 Ermal
		'pfsense.exec_shell' => array('function' => 'exec_shell_xmlrpc',
519 0567899d Ermal
			'signature' => $exec_shell_sig,
520
			'docstring' => $exec_shell_doc),
521 137f46d8 Ermal
		'pfsense.exec_php' => array('function' => 'exec_php_xmlrpc',
522 0567899d Ermal
			'signature' => $exec_php_sig,
523 962f215d Phil Davis
			'docstring' => $exec_php_doc),
524 137f46d8 Ermal
		'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
525 0567899d Ermal
			'signature' => $filter_configure_sig,
526
			'docstring' => $filter_configure_doc),
527 137f46d8 Ermal
		'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
528 29e5cbb4 Phil Davis
			'signature' => $carp_configure_sig,
529
			'docstring' => $carp_configure_doc),
530 137f46d8 Ermal
		'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
531 0567899d Ermal
			'signature' => $backup_config_section_sig,
532
			'docstring' => $backup_config_section_doc),
533 137f46d8 Ermal
		'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
534 0567899d Ermal
			'signature' => $restore_config_section_sig,
535
			'docstring' => $restore_config_section_doc),
536 137f46d8 Ermal
		'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
537 0567899d Ermal
			'signature' => $merge_config_section_sig,
538
			'docstring' => $merge_config_section_doc),
539 137f46d8 Ermal
		'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
540 29e5cbb4 Phil Davis
			'signature' => $merge_installedpackages_section_sig,
541
			'docstring' => $merge_installedpackages_section_doc),
542 e501de37 Ermal
		'pfsense.host_firmware_version' => array('function' => 'pfsense_firmware_version_xmlrpc',
543 0567899d Ermal
			'signature' => $pfsense_firmware_version_sig,
544 29e5cbb4 Phil Davis
			'docstring' => $pfsense_firmware_version_doc),
545 137f46d8 Ermal
		'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
546 0567899d Ermal
			'signature' => $reboot_sig,
547
			'docstring' => $reboot_doc),
548 137f46d8 Ermal
		'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
549 0567899d Ermal
			'signature' => $get_notices_sig)
550 962f215d Phil Davis
	)
551 50d49018 Colin Smith
);
552 b298dd06 Scott Ullrich
553 67d78c87 Ermal
unlock($xmlrpclockkey);
554
555 6c07db48 Phil Davis
function array_overlay($a1, $a2) {
556 962f215d Phil Davis
	foreach ($a1 as $k => $v) {
557 6c07db48 Phil Davis
		if (!array_key_exists($k, $a2)) {
558 962f215d Phil Davis
			continue;
559
		}
560
		if (is_array($v) && is_array($a2[$k])) {
561 6c07db48 Phil Davis
			$a1[$k] = array_overlay($v, $a2[$k]);
562 962f215d Phil Davis
		} else {
563
			$a1[$k] = $a2[$k];
564
		}
565
	}
566
	return $a1;
567
}
568 0b581a8a Scott Ullrich
569 de63649b Rafael Lucas
?>