Project

General

Profile

Download (8.79 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	$Id$
4

    
5
        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
        POSSIBILITY OF SUCH DAMAGE._Value(
29

    
30
	TODO:
31
		* Expose more functions.
32
*/
33

    
34
require_once("xmlrpc_server.inc");
35
require_once("xmlrpc.inc");
36
require_once("config.inc");
37
require_once("functions.inc");
38
require_once("array_intersect_key.inc");
39

    
40
/* grab sync to ip if enabled */
41
if ($config['installedpackages']['carpsettings']['config']) {
42
	foreach ($config['installedpackages']['carpsettings']['config'] as $carp) {
43
		$synchronizetoip = $carp['synchronizetoip'];
44
	}
45
}
46

    
47
if($synchronizetoip) {
48
	if($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
49
		log_error("Disallowing CARP sync loop.");
50
		die;	
51
	}
52
}
53

    
54
$xmlrpc_g = array(
55
			"return" => array(
56
						"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
57
						"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
58
						"authfail" => new XML_RPC_Response(0, $XML_RPC_erruser+1, "Authentication failure")
59
				)
60
		);
61

    
62
/*
63
 *   pfSense XMLRPC errors
64
 *   $XML_RPC_erruser + 1 = Auth failure
65
 */
66
$XML_RPC_erruser = 200;
67

    
68
/* EXPOSED FUNCTIONS */
69

    
70
$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.';
71
$backup_config_section_sig = array(
72
				array(
73
					$XML_RPC_Struct, // First signature element is return value.
74
					$XML_RPC_String,
75
					$XML_RPC_Array
76
				)
77
			);
78

    
79
function backup_config_section_xmlrpc($raw_params) {
80
	global $config, $xmlrpc_g;
81
	$params = xmlrpc_params_to_php($raw_params);
82
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
83
	$val = array_intersect_key($config, array_flip($params[0]));
84
	return new XML_RPC_Response(XML_RPC_encode($val));
85
}
86

    
87
/*****************************/
88

    
89
$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.';
90
$restore_config_section_sig = array(
91
					array(
92
						$XML_RPC_Boolean,
93
						$XML_RPC_String,
94
						$XML_RPC_Struct
95
					)
96
				);
97

    
98
function restore_config_section_xmlrpc($raw_params) {
99
	global $config, $xmlrpc_g;
100
	$params = xmlrpc_params_to_php($raw_params);
101
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
102
	$config = array_merge($config, $params[0]);
103
	$mergedkeys = implode(",", array_keys($params[0]));
104
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
105
	return $xmlrpc_g['return']['true'];
106
}
107

    
108
/*****************************/
109

    
110

    
111
$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.';
112
$merge_config_section_sig = array(
113
					array(
114
						$XML_RPC_Boolean,
115
						$XML_RPC_String,
116
						$XML_RPC_Struct
117
					)
118
				);
119

    
120
function merge_config_section_xmlrpc($raw_params) {
121
	global $config, $xmlrpc_g;
122
	$params = xmlrpc_params_to_php($raw_params);
123
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
124
	$config = array_merge_recursive_unique($config, $params[0]);
125
	$mergedkeys = implode(",", array_keys($params[0]));
126
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
127
	return $xmlrpc_g['return']['true'];
128
}
129

    
130
/*****************************/
131

    
132
$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.';
133
$filter_configure_sig = array(
134
				array(
135
					$XML_RPC_Boolean,
136
					$XML_RPC_String
137
				)
138
			);
139

    
140
function filter_configure_xmlrpc($raw_params) {
141
	global $xmlrpc_g;
142
	$params = xmlrpc_params_to_php($raw_params);
143
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
144
	require_once("vslb.inc");
145
	slbd_configure();
146
	filter_configure();
147
	system_routing_configure();
148
	return $xmlrpc_g['return']['true'];
149
}
150

    
151
/*****************************/
152

    
153
$check_firmware_version_doc = 'Basic XMLRPC wrapper for check_firmware_version. This function will return the output of check_firmware_version upon completion.';
154
$check_firmware_version_sig = array(
155
					array(
156
						$XML_RPC_String,
157
						$XML_RPC_String
158
					)
159
				);
160

    
161
function check_firmware_version_xmlrpc($raw_params) {
162
	global $xmlrpc_g, $XML_RPC_String;
163
	$params = xmlrpc_params_to_php($raw_params);
164
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
165
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
166
}
167

    
168
/*****************************/
169

    
170
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
171
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
172

    
173
function reboot_xmlrpc($raw_params) {
174
	global $xmlrpc_g;
175
	$params = xmlrpc_params_to_php($raw_params);
176
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
177
	mwexec_bg("/etc/rc.reboot");
178
	return $xmlrpc_g['return']['true'];
179
}
180

    
181
/*****************************/
182

    
183
$get_notices_sig = array(
184
				array(
185
					$XML_RPC_Array,
186
					$XML_RPC_String
187
				),
188
				array(
189
					$XML_RPC_Array
190
				)
191
			);
192

    
193
function get_notices_xmlrpc($raw_params) {
194
	global $g, $xmlrpc_g;
195
	$params = xmlrpc_params_to_php($raw_params);
196
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
197
	require_once("notices.inc");
198
	if(!$params) {
199
		$toreturn = get_notices();
200
	} else {
201
		$toreturn = get_notices($params);
202
	}
203
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
204
	return $response;
205
}
206

    
207
/*****************************/
208

    
209
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
210
$carp_configure_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
211

    
212
function interfaces_carp_configure_xmlrpc($raw_params) {
213
	global $xmlrpc_g;
214
	$params = xmlrpc_params_to_php($raw_params);
215
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
216
	interfaces_carp_configure();
217
	interfaces_carp_bring_up_final();
218
	return $xmlrpc_g['return']['true'];
219
}
220

    
221
/*****************************/
222

    
223
$server = new XML_RPC_Server(
224
        array(
225
            'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
226
							'signature' => $carp_configure_doc,
227
							'docstring' => $carp_configure_sig),
228
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
229
							'signature' => $backup_config_section_sig,
230
							'docstring' => $backup_config_section_doc),
231
	    'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
232
							'signature' => $restore_config_section_sig,
233
							'docstring' => $restore_config_section_doc),
234
	    'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
235
							'signature' => $merge_config_section_sig,
236
							'docstring' => $merge_config_section_doc),
237
	    'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
238
							'signature' => $filter_configure_sig,
239
							'docstring' => $filter_configure_doc),
240
	    'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
241
							'signature' => $check_firmware_version_sig,
242
							'docstring' => $check_firmware_version_doc),
243
	    'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
244
							'signature' => $reboot_sig,
245
							'docstring' => $reboot_doc),
246
	    'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
247
							'signature' => $get_notices_sig)
248
        )
249
);
250
?>
(187-187/187)