Project

General

Profile

Download (11.7 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
        Copyright (C) 2005 Colin Smith
7
        All rights reserved.
8
9
        Redistribution and use in source and binary forms, with or without
10
        modification, are permitted provided that the following conditions are met:
11
12
        1. Redistributions of source code must retain the above copyright notice,
13
           this list of conditions and the following disclaimer.
14
15
        2. Redistributions in binary form must reproduce the above copyright
16
           notice, this list of conditions and the following disclaimer in the
17
           documentation and/or other materials provided with the distribution.
18
19
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 8da3de34 Colin Smith
        POSSIBILITY OF SUCH DAMAGE._Value(
29 780dbd56 Colin Smith
30
	TODO:
31
		* Expose more functions.
32 50d49018 Colin Smith
*/
33
34 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-xmlrpclibrary
36
##|*NAME=XMLRPC Library page
37
##|*DESCR=Allow access to the 'XMLRPC Library' page.
38
##|*MATCH=xmlrpc.php*
39
##|-PRIV
40
41 0674f163 sullrich
require("config.inc");
42
require("functions.inc");
43
require("filter.inc");
44
require("shaper.inc");
45
require("xmlrpc_server.inc");
46
require("xmlrpc.inc");
47
require("array_intersect_key.inc");
48 50d49018 Colin Smith
49 ff664954 Scott Ullrich
/* grab sync to ip if enabled */
50 dd98e330 Scott Ullrich
if($config['installedpackages']['carpsettings']) {
51
	if ($config['installedpackages']['carpsettings']['config']) {
52
		foreach ($config['installedpackages']['carpsettings']['config'] as $carp) {
53
			$synchronizetoip = $carp['synchronizetoip'];
54
		}
55 ff664954 Scott Ullrich
	}
56
}
57
58
if($synchronizetoip) {
59
	if($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
60
		log_error("Disallowing CARP sync loop.");
61
		die;	
62
	}
63
}
64
65 8da3de34 Colin Smith
$xmlrpc_g = array(
66
			"return" => array(
67
						"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
68
						"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
69
						"authfail" => new XML_RPC_Response(0, $XML_RPC_erruser+1, "Authentication failure")
70
				)
71
		);
72
73
/*
74
 *   pfSense XMLRPC errors
75
 *   $XML_RPC_erruser + 1 = Auth failure
76
 */
77
$XML_RPC_erruser = 200;
78
79
/* EXPOSED FUNCTIONS */
80 21dc3a7d Colin Smith
81 c3638879 Scott Ullrich
$exec_php_doc = '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.';
82
$exec_php_sig = array(
83
				array(
84
					$XML_RPC_Boolean, // First signature element is return value.
85
					$XML_RPC_String, // password
86
					$XML_RPC_String, // shell code to exec
87
				)
88
			);
89
90
91
function exec_php_xmlrpc($raw_params) {
92
	global $config, $xmlrpc_g;
93
	$params = xmlrpc_params_to_php($raw_params);
94
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
95
	$exec_php = $params[0];
96
	eval($exec_php);
97
	return $xmlrpc_g['return']['true'];
98
}
99
100
101
102
/*****************************/
103
104
105
$exec_shell_doc = '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.';
106
$exec_shell_sig = array(
107
				array(
108
					$XML_RPC_Boolean, // First signature element is return value.
109
					$XML_RPC_String, // password
110
					$XML_RPC_String, // shell code to exec
111
				)
112
			);
113
114
115
function exec_shell_xmlrpc($raw_params) {
116
	global $config, $xmlrpc_g;
117
	$params = xmlrpc_params_to_php($raw_params);
118
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
119
	$shell_cmd = $params[0];
120
	mwexec($shell_cmd);
121
	return $xmlrpc_g['return']['true'];
122
}
123
124
125
126
/*****************************/
127
128
129 03d89831 Scott Ullrich
$backup_config_section_doc = '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.';
130 8da3de34 Colin Smith
$backup_config_section_sig = array(
131
				array(
132 03d89831 Scott Ullrich
					$XML_RPC_Struct, // First signature element is return value.
133 8da3de34 Colin Smith
					$XML_RPC_String,
134 03d89831 Scott Ullrich
					$XML_RPC_Array
135 8da3de34 Colin Smith
				)
136
			);
137 21dc3a7d Colin Smith
138 57e6d4c9 Colin Smith
function backup_config_section_xmlrpc($raw_params) {
139 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
140 8da3de34 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
141
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
142 03d89831 Scott Ullrich
	$val = array_intersect_key($config, array_flip($params[0]));
143 8da3de34 Colin Smith
	return new XML_RPC_Response(XML_RPC_encode($val));
144 50d49018 Colin Smith
}
145
146 8da3de34 Colin Smith
/*****************************/
147
148 03d89831 Scott Ullrich
$restore_config_section_doc = '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.';
149 8da3de34 Colin Smith
$restore_config_section_sig = array(
150
					array(
151
						$XML_RPC_Boolean,
152
						$XML_RPC_String,
153 03d89831 Scott Ullrich
						$XML_RPC_Struct
154 8da3de34 Colin Smith
					)
155
				);
156 21dc3a7d Colin Smith
157 57e6d4c9 Colin Smith
function restore_config_section_xmlrpc($raw_params) {
158 03d89831 Scott Ullrich
	global $config, $xmlrpc_g;
159 57e6d4c9 Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
160 8da3de34 Colin Smith
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
161 03d89831 Scott Ullrich
	$config = array_merge($config, $params[0]);
162
	$mergedkeys = implode(",", array_keys($params[0]));
163
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
164 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
165 50d49018 Colin Smith
}
166
167 82ae5cfc Scott Ullrich
168
/*****************************/
169
170
171
$merge_config_section_doc = '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.';
172
$merge_config_section_sig = array(
173
					array(
174
						$XML_RPC_Boolean,
175
						$XML_RPC_String,
176
						$XML_RPC_Struct
177
					)
178
				);
179
180
function merge_installedpackages_section_xmlrpc($raw_params) {
181
	global $config, $xmlrpc_g;
182
	$params = xmlrpc_params_to_php($raw_params);
183
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
184
	$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
185
	$mergedkeys = implode(",", array_keys($params[0]));
186
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
187
	return $xmlrpc_g['return']['true'];
188
}
189
190
191 8da3de34 Colin Smith
/*****************************/
192
193 dc1cd85d Scott Ullrich
194
$merge_config_section_doc = '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.';
195
$merge_config_section_sig = array(
196
					array(
197
						$XML_RPC_Boolean,
198
						$XML_RPC_String,
199
						$XML_RPC_Struct
200
					)
201
				);
202
203
function merge_config_section_xmlrpc($raw_params) {
204
	global $config, $xmlrpc_g;
205
	$params = xmlrpc_params_to_php($raw_params);
206
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
207 ee87d929 Scott Ullrich
	$config = array_merge_recursive_unique($config, $params[0]);
208 dc1cd85d Scott Ullrich
	$mergedkeys = implode(",", array_keys($params[0]));
209
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
210
	return $xmlrpc_g['return']['true'];
211
}
212
213
/*****************************/
214
215 07a7b08f Colin Smith
$filter_configure_doc = '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.';
216 8da3de34 Colin Smith
$filter_configure_sig = array(
217
				array(
218
					$XML_RPC_Boolean,
219
					$XML_RPC_String
220
				)
221
			);
222 07a7b08f Colin Smith
223
function filter_configure_xmlrpc($raw_params) {
224 8da3de34 Colin Smith
	global $xmlrpc_g;
225 07a7b08f Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
226 8da3de34 Colin Smith
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
227 0674f163 sullrich
	require("vslb.inc");
228 07a7b08f Colin Smith
	filter_configure();
229 e700437b Scott Ullrich
	system_routing_configure();
230 41e6d4bd Seth Mos
	setup_gateways_monitor();
231 651c32e2 Bill Marquette
	relayd_configure();
232 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
233 07a7b08f Colin Smith
}
234
235 8da3de34 Colin Smith
/*****************************/
236
237 b4d19b46 Bill Marquette
$check_firmware_version_doc = 'Basic XMLRPC wrapper for check_firmware_version. This function will return the output of check_firmware_version upon completion.';
238 8da3de34 Colin Smith
$check_firmware_version_sig = array(
239
					array(
240
						$XML_RPC_String,
241
						$XML_RPC_String
242
					)
243
				);
244 44488c3c Colin Smith
245
function check_firmware_version_xmlrpc($raw_params) {
246 b4d19b46 Bill Marquette
	global $xmlrpc_g, $XML_RPC_String;
247
	$params = xmlrpc_params_to_php($raw_params);
248
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
249 8da3de34 Colin Smith
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
250 44488c3c Colin Smith
}
251
252 8da3de34 Colin Smith
/*****************************/
253 44488c3c Colin Smith
254 bd0fe65b Colin Smith
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
255 1cdca133 Colin Smith
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
256 bd0fe65b Colin Smith
257
function reboot_xmlrpc($raw_params) {
258 8da3de34 Colin Smith
	global $xmlrpc_g;
259 bd0fe65b Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
260 8da3de34 Colin Smith
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
261 53cf5533 Colin Smith
	mwexec_bg("/etc/rc.reboot");
262 8da3de34 Colin Smith
	return $xmlrpc_g['return']['true'];
263 bd0fe65b Colin Smith
}
264
265 8da3de34 Colin Smith
/*****************************/
266
267
$get_notices_sig = array(
268
				array(
269 dc1cd85d Scott Ullrich
					$XML_RPC_Array,
270 8da3de34 Colin Smith
					$XML_RPC_String
271
				),
272
				array(
273
					$XML_RPC_Array
274
				)
275
			);
276
277 d9064267 Colin Smith
function get_notices_xmlrpc($raw_params) {
278 8da3de34 Colin Smith
	global $g, $xmlrpc_g;
279 b4d19b46 Bill Marquette
	$params = xmlrpc_params_to_php($raw_params);
280
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
281 0674f163 sullrich
	require("notices.inc");
282 8da3de34 Colin Smith
	if(!$params) {
283 d9064267 Colin Smith
		$toreturn = get_notices();
284
	} else {
285 8da3de34 Colin Smith
		$toreturn = get_notices($params);
286 d9064267 Colin Smith
	}
287
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
288
	return $response;
289
}
290
291 8da3de34 Colin Smith
/*****************************/
292
293
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
294 670fe849 Scott Ullrich
$carp_configure_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
295
296 52c3baf5 Scott Ullrich
function interfaces_carp_configure_xmlrpc($raw_params) {
297 670fe849 Scott Ullrich
	global $xmlrpc_g;
298 728d393d Colin Smith
	$params = xmlrpc_params_to_php($raw_params);
299 670fe849 Scott Ullrich
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
300 0a595d84 Ermal Lu?i
	interfaces_carp_setup();
301 670fe849 Scott Ullrich
	return $xmlrpc_g['return']['true'];
302 52c3baf5 Scott Ullrich
}
303
304 8da3de34 Colin Smith
/*****************************/
305
306 21dc3a7d Colin Smith
$server = new XML_RPC_Server(
307
        array(
308 c3638879 Scott Ullrich
            'pfsense.exec_shell' 		=> array('function' => 'exec_shell_xmlrpc',
309
							'signature' => $exec_shell_sig,
310
							'docstring' => $exec_shell_doc),
311
            'pfsense.exec_php'	 		=> array('function' => 'exec_php_xmlrpc',
312
							'signature' => $exec_php_sig,
313
							'docstring' => $exec_php_doc),	
314 52c3baf5 Scott Ullrich
            'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
315
							'signature' => $carp_configure_doc,
316
							'docstring' => $carp_configure_sig),
317 07a7b08f Colin Smith
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
318 21dc3a7d Colin Smith
							'signature' => $backup_config_section_sig,
319
							'docstring' => $backup_config_section_doc),
320
	    'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
321
							'signature' => $restore_config_section_sig,
322 07a7b08f Colin Smith
							'docstring' => $restore_config_section_doc),
323 dc1cd85d Scott Ullrich
	    'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
324
							'signature' => $merge_config_section_sig,
325
							'docstring' => $merge_config_section_doc),
326 c3638879 Scott Ullrich
	    'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
327
							'signature' => $merge_config_section_sig,
328
							'docstring' => $merge_config_section_doc),							
329 07a7b08f Colin Smith
	    'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
330
							'signature' => $filter_configure_sig,
331 44488c3c Colin Smith
							'docstring' => $filter_configure_doc),
332
	    'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
333
							'signature' => $check_firmware_version_sig,
334 bd0fe65b Colin Smith
							'docstring' => $check_firmware_version_doc),
335
	    'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
336
							'signature' => $reboot_sig,
337 d9064267 Colin Smith
							'docstring' => $reboot_doc),
338
	    'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
339
							'signature' => $get_notices_sig)
340 50d49018 Colin Smith
        )
341
);
342 32259bc1 Bill Marquette
?>