Project

General

Profile

Download (13.1 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
require("shaper.inc");
43
require("xmlrpc_server.inc");
44
require("xmlrpc.inc");
45
require("array_intersect_key.inc");
46 50d49018 Colin Smith
47 ff664954 Scott Ullrich
/* grab sync to ip if enabled */
48 dd98e330 Scott Ullrich
if($config['installedpackages']['carpsettings']) {
49
	if ($config['installedpackages']['carpsettings']['config']) {
50
		foreach ($config['installedpackages']['carpsettings']['config'] as $carp) {
51
			$synchronizetoip = $carp['synchronizetoip'];
52
		}
53 ff664954 Scott Ullrich
	}
54
}
55
56
if($synchronizetoip) {
57
	if($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
58 de63649b Rafael Lucas
		log_error(gettext("Disallowing CARP sync loop."));
59 ff664954 Scott Ullrich
		die;	
60
	}
61
}
62
63 8da3de34 Colin Smith
$xmlrpc_g = array(
64
			"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 de63649b Rafael Lucas
						"authfail" => new XML_RPC_Response(new XML_RPC_Value(gettext("Authentication failed"), $XML_RPC_String))
68 8da3de34 Colin Smith
				)
69
		);
70
71
/*
72
 *   pfSense XMLRPC errors
73
 *   $XML_RPC_erruser + 1 = Auth failure
74
 */
75
$XML_RPC_erruser = 200;
76
77
/* EXPOSED FUNCTIONS */
78 21dc3a7d Colin Smith
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 0e19e0e4 Scott Ullrich
					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
function exec_php_xmlrpc($raw_params) {
89
	global $config, $xmlrpc_g;
90
	$params = xmlrpc_params_to_php($raw_params);
91
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
92
	$exec_php = $params[0];
93
	eval($exec_php);
94 2c0dd581 Scott Ullrich
	if($toreturn) {
95
		$response = XML_RPC_encode($toreturn);
96
		return new XML_RPC_Response($response);
97
	} else
98
		return $xmlrpc_g['return']['true'];
99 c3638879 Scott Ullrich
}
100
101
/*****************************/
102
103 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.");
104 c3638879 Scott Ullrich
$exec_shell_sig = array(
105 0e19e0e4 Scott Ullrich
					array(
106
						$XML_RPC_Boolean, // First signature element is return value.
107
						$XML_RPC_String, // password
108
						$XML_RPC_String, // shell code to exec
109
					)
110
				);
111 c3638879 Scott Ullrich
112
113
function exec_shell_xmlrpc($raw_params) {
114
	global $config, $xmlrpc_g;
115
	$params = xmlrpc_params_to_php($raw_params);
116
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
117
	$shell_cmd = $params[0];
118
	mwexec($shell_cmd);
119
	return $xmlrpc_g['return']['true'];
120
}
121
122
123
124
/*****************************/
125
126
127 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.");
128 8da3de34 Colin Smith
$backup_config_section_sig = array(
129 0e19e0e4 Scott Ullrich
								array(
130
									$XML_RPC_Struct, // First signature element is return value.
131
									$XML_RPC_String,
132
									$XML_RPC_Array
133
								)
134
							);
135 21dc3a7d Colin Smith
136 57e6d4c9 Colin Smith
function backup_config_section_xmlrpc($raw_params) {
137 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
138 8da3de34 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
139
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
140 03d89831 Scott Ullrich
	$val = array_intersect_key($config, array_flip($params[0]));
141 8da3de34 Colin Smith
	return new XML_RPC_Response(XML_RPC_encode($val));
142 50d49018 Colin Smith
}
143
144 8da3de34 Colin Smith
/*****************************/
145
146 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.");
147 8da3de34 Colin Smith
$restore_config_section_sig = array(
148 0e19e0e4 Scott Ullrich
								array(
149
									$XML_RPC_Boolean,
150
									$XML_RPC_String,
151
									$XML_RPC_Struct
152
								)
153
							);
154 21dc3a7d Colin Smith
155 57e6d4c9 Colin Smith
function restore_config_section_xmlrpc($raw_params) {
156 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
157 57e6d4c9 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
158 19b5c3e7 Ermal
	if(!xmlrpc_auth($params))
159
		return $xmlrpc_g['return']['authfail'];
160 a8200dbf Ermal
	$vipbackup = array();
161 19b5c3e7 Ermal
	if (isset($params[0]['virtualip'])) {
162
		if(is_array($config['virtualip']['vip'])) {
163
			foreach ($config['virtualip']['vip'] as $vip)
164
				interface_vip_bring_down($vip);
165
		}
166 a8200dbf Ermal
        	$vipbackup = $config['virtualip']['vip'];
167 19b5c3e7 Ermal
	}
168 b019222a pierrepomes
        // For vip section, first keep items sent from the master
169 03d89831 Scott Ullrich
	$config = array_merge($config, $params[0]);
170 b019222a pierrepomes
        // Then add ipalias and proxyarp types already defined on the backup
171 a8200dbf Ermal
        foreach ($vipbackup as $vip) {
172 b019222a pierrepomes
                if (($vip['mode'] == 'ipalias') || ($vip['mode'] == 'proxyarp'))
173
                        $config['virtualip']['vip'][]=$vip ;
174 a8200dbf Ermal
	}
175 03d89831 Scott Ullrich
	$mergedkeys = implode(",", array_keys($params[0]));
176 3a3fb8ea Erik Fonnesbeck
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
177 2de2abe0 Ermal
	interfaces_vips_configure();
178 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
179 50d49018 Colin Smith
}
180
181 82ae5cfc Scott Ullrich
182
/*****************************/
183
184
185 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.");
186 82ae5cfc Scott Ullrich
$merge_config_section_sig = array(
187 0e19e0e4 Scott Ullrich
								array(
188
									$XML_RPC_Boolean,
189
									$XML_RPC_String,
190
									$XML_RPC_Struct
191
								)
192
							);
193 82ae5cfc Scott Ullrich
194
function merge_installedpackages_section_xmlrpc($raw_params) {
195
	global $config, $xmlrpc_g;
196
	$params = xmlrpc_params_to_php($raw_params);
197
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
198
	$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
199
	$mergedkeys = implode(",", array_keys($params[0]));
200 3a3fb8ea Erik Fonnesbeck
	write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."),$mergedkeys));
201 82ae5cfc Scott Ullrich
	return $xmlrpc_g['return']['true'];
202
}
203
204
205 8da3de34 Colin Smith
/*****************************/
206
207 dc1cd85d Scott Ullrich
208 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.");
209 dc1cd85d Scott Ullrich
$merge_config_section_sig = array(
210 0e19e0e4 Scott Ullrich
								array(
211
									$XML_RPC_Boolean,
212
									$XML_RPC_String,
213
									$XML_RPC_Struct
214
								)
215
							);
216 dc1cd85d Scott Ullrich
217
function merge_config_section_xmlrpc($raw_params) {
218
	global $config, $xmlrpc_g;
219
	$params = xmlrpc_params_to_php($raw_params);
220 19b5c3e7 Ermal
	if(!xmlrpc_auth($params))
221
		return $xmlrpc_g['return']['authfail'];
222
	if (isset($params[0]['virtualip'])) {
223
                if(is_array($config['virtualip']['vip'])) {
224
                        foreach ($config['virtualip']['vip'] as $vip)
225
                                interface_vip_bring_down($vip);
226
                }
227
        }
228 a771c044 Scott Ullrich
	$config = array_merge_recursive_unique($config, $params[0]);
229 dc1cd85d Scott Ullrich
	$mergedkeys = implode(",", array_keys($params[0]));
230
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
231 2de2abe0 Ermal
	interfaces_vips_configure();
232 dc1cd85d Scott Ullrich
	return $xmlrpc_g['return']['true'];
233
}
234
235
/*****************************/
236
237 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.");
238 8da3de34 Colin Smith
$filter_configure_sig = array(
239 0e19e0e4 Scott Ullrich
							array(
240
								$XML_RPC_Boolean,
241
								$XML_RPC_String
242
							)
243
						);
244 07a7b08f Colin Smith
245
function filter_configure_xmlrpc($raw_params) {
246 8da3de34 Colin Smith
	global $xmlrpc_g;
247 07a7b08f Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
248 8da3de34 Colin Smith
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
249 07a7b08f Colin Smith
	filter_configure();
250 e700437b Scott Ullrich
	system_routing_configure();
251 41e6d4bd Seth Mos
	setup_gateways_monitor();
252 651c32e2 Bill Marquette
	relayd_configure();
253 c3fef0c9 jim-p
	require_once("openvpn.inc");
254
	openvpn_resync_all();
255
	services_dhcpd_configure();
256 62c4d0fb jim-p
	services_dnsmasq_configure();
257 0ce72662 jim-p
	local_sync_accounts();
258 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
259 07a7b08f Colin Smith
}
260
261 8da3de34 Colin Smith
/*****************************/
262
263 de63649b Rafael Lucas
$carp_configure_doc = gettext("Basic XMLRPC wrapper for configuring CARP interfaces.");
264 efe7562e Scott Ullrich
$carp_configure_sig = array(
265
							array(
266
								$XML_RPC_Boolean,
267
								$XML_RPC_String
268
							)
269
						);
270
271
function interfaces_carp_configure_xmlrpc($raw_params) {
272
	global $xmlrpc_g;
273
	$params = xmlrpc_params_to_php($raw_params);
274
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
275
	interfaces_vips_configure();
276
	return $xmlrpc_g['return']['true'];
277
}
278
279
/*****************************/
280
281 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.");
282 8da3de34 Colin Smith
$check_firmware_version_sig = array(
283 0e19e0e4 Scott Ullrich
								array(
284
									$XML_RPC_String,
285
									$XML_RPC_String
286
								)
287
							);
288 44488c3c Colin Smith
289
function check_firmware_version_xmlrpc($raw_params) {
290 b4d19b46 Bill Marquette
	global $xmlrpc_g, $XML_RPC_String;
291
	$params = xmlrpc_params_to_php($raw_params);
292
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
293 8da3de34 Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
294 44488c3c Colin Smith
}
295
296 8da3de34 Colin Smith
/*****************************/
297 44488c3c Colin Smith
298 de63649b Rafael Lucas
$reboot_doc = gettext("Basic XMLRPC wrapper for rc.reboot.");
299 1cdca133 Colin Smith
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
300 bd0fe65b Colin Smith
301
function reboot_xmlrpc($raw_params) {
302 8da3de34 Colin Smith
	global $xmlrpc_g;
303 bd0fe65b Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
304 8da3de34 Colin Smith
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
305 53cf5533 Colin Smith
	mwexec_bg("/etc/rc.reboot");
306 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
307 bd0fe65b Colin Smith
}
308
309 8da3de34 Colin Smith
/*****************************/
310
311
$get_notices_sig = array(
312 0e19e0e4 Scott Ullrich
					array(
313
						$XML_RPC_Array,
314
						$XML_RPC_String
315
					),
316
					array(
317
						$XML_RPC_Array
318
					)
319
				);
320 8da3de34 Colin Smith
321 d9064267 Colin Smith
function get_notices_xmlrpc($raw_params) {
322 8da3de34 Colin Smith
	global $g, $xmlrpc_g;
323 b4d19b46 Bill Marquette
	$params = xmlrpc_params_to_php($raw_params);
324
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
325 0674f163 sullrich
	require("notices.inc");
326 8da3de34 Colin Smith
	if(!$params) {
327 d9064267 Colin Smith
		$toreturn = get_notices();
328
	} else {
329 8da3de34 Colin Smith
		$toreturn = get_notices($params);
330 d9064267 Colin Smith
	}
331
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
332
	return $response;
333
}
334
335 8da3de34 Colin Smith
/*****************************/
336
337 21dc3a7d Colin Smith
$server = new XML_RPC_Server(
338
        array(
339 c3638879 Scott Ullrich
            'pfsense.exec_shell' 		=> array('function' => 'exec_shell_xmlrpc',
340
							'signature' => $exec_shell_sig,
341
							'docstring' => $exec_shell_doc),
342 efe7562e Scott Ullrich
            		 'pfsense.exec_php'	=> array('function' => 'exec_php_xmlrpc',
343 c3638879 Scott Ullrich
							'signature' => $exec_php_sig,
344
							'docstring' => $exec_php_doc),	
345 efe7562e Scott Ullrich
			 'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
346
							'signature' => $filter_configure_sig,
347
							'docstring' => $filter_configure_doc),
348 52c3baf5 Scott Ullrich
            'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
349
							'docstring' => $carp_configure_sig),
350 07a7b08f Colin Smith
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
351 21dc3a7d Colin Smith
							'signature' => $backup_config_section_sig,
352
							'docstring' => $backup_config_section_doc),
353 0e19e0e4 Scott Ullrich
			'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
354 21dc3a7d Colin Smith
							'signature' => $restore_config_section_sig,
355 07a7b08f Colin Smith
							'docstring' => $restore_config_section_doc),
356 0e19e0e4 Scott Ullrich
			'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
357 dc1cd85d Scott Ullrich
							'signature' => $merge_config_section_sig,
358
							'docstring' => $merge_config_section_doc),
359 0e19e0e4 Scott Ullrich
			'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
360 c3638879 Scott Ullrich
							'signature' => $merge_config_section_sig,
361
							'docstring' => $merge_config_section_doc),							
362 0e19e0e4 Scott Ullrich
			'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
363 44488c3c Colin Smith
							'signature' => $check_firmware_version_sig,
364 bd0fe65b Colin Smith
							'docstring' => $check_firmware_version_doc),
365 0e19e0e4 Scott Ullrich
			'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
366 bd0fe65b Colin Smith
							'signature' => $reboot_sig,
367 d9064267 Colin Smith
							'docstring' => $reboot_doc),
368 0e19e0e4 Scott Ullrich
			'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
369 d9064267 Colin Smith
							'signature' => $get_notices_sig)
370 50d49018 Colin Smith
        )
371
);
372 b298dd06 Scott Ullrich
373 de63649b Rafael Lucas
?>