Project

General

Profile

Download (7.21 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	$Id$
5
	
6
        xmlrpc.php
7
        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
        POSSIBILITY OF SUCH DAMAGE._Value(
30

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

    
35
require_once("xmlrpc_server.inc");
36
require_once("xmlrpc.inc");
37
require_once("config.inc");
38
require_once("functions.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 a string containing the section to be backed up.';
57
$backup_config_section_sig = array(
58
				array(
59
					$XML_RPC_String, // First signature element is return value.
60
					$XML_RPC_String,
61
					$XML_RPC_String
62
				)
63
			);
64

    
65
function backup_config_section_xmlrpc($raw_params) {
66
	global $xmlrpc_g;
67
	$params = xmlrpc_params_to_php($raw_params);
68
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
69
	$val = backup_config_section($params['section']); 
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 three parameters: a string containing the local system\'s password, a string containing the section to be restored, and a string containing the returned value of backup_config_section() for that section. 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_Array,
81
						$XML_RPC_Array
82
					)
83
				);
84

    
85
function restore_config_section_xmlrpc($raw_params) {
86
	global $xmlrpc_g;
87
	$params = xmlrpc_params_to_php($raw_params);
88
	$i = 0;
89
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
90
	foreach($params[0] as $section) {
91
		restore_config_section($section, $params[1][$i]);
92
		$i++;
93
	}
94
	return $xmlrpc_g['return']['true'];
95
}
96

    
97
/*****************************/
98

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

    
107
function filter_configure_xmlrpc($raw_params) {
108
	global $xmlrpc_g;
109
	$params = xmlrpc_params_to_php($raw_params);
110
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
111
	filter_configure();
112
	return $xmlrpc_g['return']['true'];
113
}
114

    
115
/*****************************/
116

    
117
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
118
$check_firmware_version_sig = array(
119
					array(
120
						$XML_RPC_String,
121
						$XML_RPC_String
122
					)
123
				);
124

    
125
function check_firmware_version_xmlrpc($raw_params) {
126
	return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
127
}
128

    
129
/*****************************/
130

    
131
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
132
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
133

    
134
function reboot_xmlrpc($raw_params) {
135
	global $xmlrpc_g;
136
	$params = xmlrpc_params_to_php($raw_params);
137
	if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
138
	mwexec_bg("/etc/rc.reboot");
139
	return $xmlrpc_g['return']['true'];
140
}
141

    
142
/*****************************/
143

    
144
$get_notices_sig = array(
145
				array(
146
					$XML_RPC_Array, 
147
					$XML_RPC_String
148
				),
149
				array(
150
					$XML_RPC_Array
151
				)
152
			);
153

    
154
function get_notices_xmlrpc($raw_params) {
155
	global $g, $xmlrpc_g;
156
	require_once("notices.inc");
157
	$params = array_pop(xmlrpc_params_to_php($raw_params));
158
	if(!$params) {
159
		$toreturn = get_notices();
160
	} else {
161
		$toreturn = get_notices($params);
162
	}
163
	$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
164
	return $response;
165
}
166

    
167
/*****************************/
168

    
169
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
170
$carp_configure_sig = array(
171
				array(
172
					$XML_RPC_Boolean,
173
					$XML_RPC_String
174
				)
175
			);
176
			
177
function interfaces_carp_configure_xmlrpc($raw_params) {
178
	global $xmlrpc_g;
179
	$params = xmlrpc_params_to_php($raw_params);
180
	if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", $XML_RPC_String));
181
	interfaces_carp_configure();
182
	return new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean));
183
}
184

    
185
/*****************************/
186

    
187
$server = new XML_RPC_Server(
188
        array(
189
            'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
190
							'signature' => $carp_configure_doc,
191
							'docstring' => $carp_configure_sig),
192
            'pfsense.backup_config_section' => 	array('function' => 'backup_config_section_xmlrpc',
193
							'signature' => $backup_config_section_sig,
194
							'docstring' => $backup_config_section_doc),
195
	    'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
196
							'signature' => $restore_config_section_sig,
197
							'docstring' => $restore_config_section_doc),
198
	    'pfsense.filter_configure' => 	array('function' => 'filter_configure_xmlrpc',
199
							'signature' => $filter_configure_sig,
200
							'docstring' => $filter_configure_doc),
201
	    'pfsense.check_firmware_version' =>	array('function' => 'check_firmware_version_xmlrpc',
202
							'signature' => $check_firmware_version_sig,
203
							'docstring' => $check_firmware_version_doc),
204
	    'pfsense.reboot' =>			array('function' => 'reboot_xmlrpc',
205
							'signature' => $reboot_sig,
206
							'docstring' => $reboot_doc),
207
	    'pfsense.get_notices' =>		array('function' => 'get_notices_xmlrpc',
208
							'signature' => $get_notices_sig)
209
        )
210
);
211
?>
(147-147/147)