Project

General

Profile

Download (8.26 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
$xmlrpc_g = array(
41
			"return" => array(
42
						"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
43
						"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
44
						"authfail" => new XML_RPC_Response(0, $XML_RPC_erruser+1, "Authentication failure")
45
				)
46
		);
47

    
48
/*
49
 *   pfSense XMLRPC errors
50
 *   $XML_RPC_erruser + 1 = Auth failure
51
 */
52
$XML_RPC_erruser = 200;
53

    
54
/* EXPOSED FUNCTIONS */
55

    
56
$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.';
57
$backup_config_section_sig = array(
58
				array(
59
					$XML_RPC_Struct, // First signature element is return value.
60
					$XML_RPC_String,
61
					$XML_RPC_Array
62
				)
63
			);
64

    
65
function backup_config_section_xmlrpc($raw_params) {
66
	global $config, $xmlrpc_g;
67
	$params = xmlrpc_params_to_php($raw_params);
68
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
69
	$val = array_intersect_key($config, array_flip($params[0]));
70
	return new XML_RPC_Response(XML_RPC_encode($val));
71
}
72

    
73
/*****************************/
74

    
75
$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.';
76
$restore_config_section_sig = array(
77
					array(
78
						$XML_RPC_Boolean,
79
						$XML_RPC_String,
80
						$XML_RPC_Struct
81
					)
82
				);
83

    
84
function restore_config_section_xmlrpc($raw_params) {
85
	global $config, $xmlrpc_g;
86
	$params = xmlrpc_params_to_php($raw_params);
87
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
88
	$config = array_merge($config, $params[0]);
89
	$mergedkeys = implode(",", array_keys($params[0]));
90
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
91
	return $xmlrpc_g['return']['true'];
92
}
93

    
94
/*****************************/
95

    
96

    
97
$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.';
98
$merge_config_section_sig = array(
99
					array(
100
						$XML_RPC_Boolean,
101
						$XML_RPC_String,
102
						$XML_RPC_Struct
103
					)
104
				);
105

    
106
function merge_config_section_xmlrpc($raw_params) {
107
	global $config, $xmlrpc_g;
108
	$params = xmlrpc_params_to_php($raw_params);
109
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
110
	$config = array_merge_recursive_unique($config, $params[0]);
111
	$mergedkeys = implode(",", array_keys($params[0]));
112
	write_config("Merged in config ({$mergedkeys} sections) from XMLRPC client.");
113
	return $xmlrpc_g['return']['true'];
114
}
115

    
116
/*****************************/
117

    
118
$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.';
119
$filter_configure_sig = array(
120
				array(
121
					$XML_RPC_Boolean,
122
					$XML_RPC_String
123
				)
124
			);
125

    
126
function filter_configure_xmlrpc($raw_params) {
127
	global $xmlrpc_g;
128
	$params = xmlrpc_params_to_php($raw_params);
129
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
130
	require_once("vslb.inc");
131
	slbd_configure();
132
	filter_configure();
133
	system_routing_configure();
134
	return $xmlrpc_g['return']['true'];
135
}
136

    
137
/*****************************/
138

    
139
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
140
$check_firmware_version_sig = array(
141
					array(
142
						$XML_RPC_String,
143
						$XML_RPC_String
144
					)
145
				);
146

    
147
function check_firmware_version_xmlrpc($raw_params) {
148
	global $XML_RPC_String;
149
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
150
}
151

    
152
/*****************************/
153

    
154
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
155
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
156

    
157
function reboot_xmlrpc($raw_params) {
158
	global $xmlrpc_g;
159
	$params = xmlrpc_params_to_php($raw_params);
160
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
161
	mwexec_bg("/etc/rc.reboot");
162
	return $xmlrpc_g['return']['true'];
163
}
164

    
165
/*****************************/
166

    
167
$get_notices_sig = array(
168
				array(
169
					$XML_RPC_Array,
170
					$XML_RPC_String
171
				),
172
				array(
173
					$XML_RPC_Array
174
				)
175
			);
176

    
177
function get_notices_xmlrpc($raw_params) {
178
	global $g, $xmlrpc_g;
179
	require_once("notices.inc");
180
	$params = array_pop(xmlrpc_params_to_php($raw_params));
181
	if(!$params) {
182
		$toreturn = get_notices();
183
	} else {
184
		$toreturn = get_notices($params);
185
	}
186
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
187
	return $response;
188
}
189

    
190
/*****************************/
191

    
192
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
193
$carp_configure_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
194

    
195
function interfaces_carp_configure_xmlrpc($raw_params) {
196
	global $xmlrpc_g;
197
	$params = xmlrpc_params_to_php($raw_params);
198
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
199
	interfaces_carp_configure();
200
	interfaces_carp_bring_up_final();
201
	return $xmlrpc_g['return']['true'];
202
}
203

    
204
/*****************************/
205

    
206
$server = new XML_RPC_Server(
207
        array(
208
            'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
209
							'signature' => $carp_configure_doc,
210
							'docstring' => $carp_configure_sig),
211
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
212
							'signature' => $backup_config_section_sig,
213
							'docstring' => $backup_config_section_doc),
214
	    'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
215
							'signature' => $restore_config_section_sig,
216
							'docstring' => $restore_config_section_doc),
217
	    'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
218
							'signature' => $merge_config_section_sig,
219
							'docstring' => $merge_config_section_doc),
220
	    'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
221
							'signature' => $filter_configure_sig,
222
							'docstring' => $filter_configure_doc),
223
	    'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
224
							'signature' => $check_firmware_version_sig,
225
							'docstring' => $check_firmware_version_doc),
226
	    'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
227
							'signature' => $reboot_sig,
228
							'docstring' => $reboot_doc),
229
	    'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
230
							'signature' => $get_notices_sig)
231
        )
232
);
233
?>
(174-174/174)