1 |
50d49018
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
81d8a9ad
|
Colin Smith
|
$Id$
|
4 |
|
|
|
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 |
|
|
require_once("xmlrpc_server.inc");
|
35 |
6fe6b916
|
Colin Smith
|
require_once("xmlrpc.inc");
|
36 |
50d49018
|
Colin Smith
|
require_once("config.inc");
|
37 |
|
|
require_once("functions.inc");
|
38 |
03d89831
|
Scott Ullrich
|
require_once("array_intersect_key.inc");
|
39 |
50d49018
|
Colin Smith
|
|
40 |
8da3de34
|
Colin Smith
|
$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 |
21dc3a7d
|
Colin Smith
|
|
56 |
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.';
|
57 |
8da3de34
|
Colin Smith
|
$backup_config_section_sig = array(
|
58 |
|
|
array(
|
59 |
03d89831
|
Scott Ullrich
|
$XML_RPC_Struct, // First signature element is return value.
|
60 |
8da3de34
|
Colin Smith
|
$XML_RPC_String,
|
61 |
03d89831
|
Scott Ullrich
|
$XML_RPC_Array
|
62 |
8da3de34
|
Colin Smith
|
)
|
63 |
|
|
);
|
64 |
21dc3a7d
|
Colin Smith
|
|
65 |
57e6d4c9
|
Colin Smith
|
function backup_config_section_xmlrpc($raw_params) {
|
66 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
67 |
8da3de34
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
68 |
|
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
69 |
03d89831
|
Scott Ullrich
|
$val = array_intersect_key($config, array_flip($params[0]));
|
70 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(XML_RPC_encode($val));
|
71 |
50d49018
|
Colin Smith
|
}
|
72 |
|
|
|
73 |
8da3de34
|
Colin Smith
|
/*****************************/
|
74 |
|
|
|
75 |
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.';
|
76 |
8da3de34
|
Colin Smith
|
$restore_config_section_sig = array(
|
77 |
|
|
array(
|
78 |
|
|
$XML_RPC_Boolean,
|
79 |
|
|
$XML_RPC_String,
|
80 |
03d89831
|
Scott Ullrich
|
$XML_RPC_Struct
|
81 |
8da3de34
|
Colin Smith
|
)
|
82 |
|
|
);
|
83 |
21dc3a7d
|
Colin Smith
|
|
84 |
57e6d4c9
|
Colin Smith
|
function restore_config_section_xmlrpc($raw_params) {
|
85 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
86 |
57e6d4c9
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
87 |
8da3de34
|
Colin Smith
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
88 |
03d89831
|
Scott Ullrich
|
$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 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
92 |
50d49018
|
Colin Smith
|
}
|
93 |
|
|
|
94 |
8da3de34
|
Colin Smith
|
/*****************************/
|
95 |
|
|
|
96 |
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.';
|
97 |
8da3de34
|
Colin Smith
|
$filter_configure_sig = array(
|
98 |
|
|
array(
|
99 |
|
|
$XML_RPC_Boolean,
|
100 |
|
|
$XML_RPC_String
|
101 |
|
|
)
|
102 |
|
|
);
|
103 |
07a7b08f
|
Colin Smith
|
|
104 |
|
|
function filter_configure_xmlrpc($raw_params) {
|
105 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
106 |
07a7b08f
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
107 |
8da3de34
|
Colin Smith
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
108 |
07a7b08f
|
Colin Smith
|
filter_configure();
|
109 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
110 |
07a7b08f
|
Colin Smith
|
}
|
111 |
|
|
|
112 |
8da3de34
|
Colin Smith
|
/*****************************/
|
113 |
|
|
|
114 |
186359bf
|
Colin Smith
|
$check_firmware_version_doc = 'Basic XMLRPC wrapper for filter_configure. This function will return the output of check_firmware_version upon completion.';
|
115 |
8da3de34
|
Colin Smith
|
$check_firmware_version_sig = array(
|
116 |
|
|
array(
|
117 |
|
|
$XML_RPC_String,
|
118 |
|
|
$XML_RPC_String
|
119 |
|
|
)
|
120 |
|
|
);
|
121 |
44488c3c
|
Colin Smith
|
|
122 |
|
|
function check_firmware_version_xmlrpc($raw_params) {
|
123 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(new XML_RPC_Value(check_firmware_version(false), $XML_RPC_String));
|
124 |
44488c3c
|
Colin Smith
|
}
|
125 |
|
|
|
126 |
8da3de34
|
Colin Smith
|
/*****************************/
|
127 |
44488c3c
|
Colin Smith
|
|
128 |
bd0fe65b
|
Colin Smith
|
$reboot_doc = 'Basic XMLRPC wrapper for rc.reboot.';
|
129 |
1cdca133
|
Colin Smith
|
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
130 |
bd0fe65b
|
Colin Smith
|
|
131 |
|
|
function reboot_xmlrpc($raw_params) {
|
132 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
133 |
bd0fe65b
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
134 |
8da3de34
|
Colin Smith
|
if(!xmlrpc_auth($params)) return $xmlrpc_g['return']['authfail'];
|
135 |
53cf5533
|
Colin Smith
|
mwexec_bg("/etc/rc.reboot");
|
136 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
137 |
bd0fe65b
|
Colin Smith
|
}
|
138 |
|
|
|
139 |
8da3de34
|
Colin Smith
|
/*****************************/
|
140 |
|
|
|
141 |
|
|
$get_notices_sig = array(
|
142 |
|
|
array(
|
143 |
|
|
$XML_RPC_Array,
|
144 |
|
|
$XML_RPC_String
|
145 |
|
|
),
|
146 |
|
|
array(
|
147 |
|
|
$XML_RPC_Array
|
148 |
|
|
)
|
149 |
|
|
);
|
150 |
|
|
|
151 |
d9064267
|
Colin Smith
|
function get_notices_xmlrpc($raw_params) {
|
152 |
8da3de34
|
Colin Smith
|
global $g, $xmlrpc_g;
|
153 |
d9064267
|
Colin Smith
|
require_once("notices.inc");
|
154 |
8da3de34
|
Colin Smith
|
$params = array_pop(xmlrpc_params_to_php($raw_params));
|
155 |
|
|
if(!$params) {
|
156 |
d9064267
|
Colin Smith
|
$toreturn = get_notices();
|
157 |
|
|
} else {
|
158 |
8da3de34
|
Colin Smith
|
$toreturn = get_notices($params);
|
159 |
d9064267
|
Colin Smith
|
}
|
160 |
|
|
$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
|
161 |
|
|
return $response;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
8da3de34
|
Colin Smith
|
/*****************************/
|
165 |
|
|
|
166 |
|
|
$carp_configure_doc = 'Basic XMLRPC wrapper for configuring CARP interfaces.';
|
167 |
|
|
$carp_configure_sig = array(
|
168 |
|
|
array(
|
169 |
|
|
$XML_RPC_Boolean,
|
170 |
|
|
$XML_RPC_String
|
171 |
|
|
)
|
172 |
|
|
);
|
173 |
|
|
|
174 |
52c3baf5
|
Scott Ullrich
|
function interfaces_carp_configure_xmlrpc($raw_params) {
|
175 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
176 |
728d393d
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
177 |
8da3de34
|
Colin Smith
|
if(!xmlrpc_auth($params)) return new XML_RPC_Response(new XML_RPC_Value("auth_failure", $XML_RPC_String));
|
178 |
52c3baf5
|
Scott Ullrich
|
interfaces_carp_configure();
|
179 |
985e98ee
|
Scott Ullrich
|
interfaces_carp_bring_up_final();
|
180 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean));
|
181 |
52c3baf5
|
Scott Ullrich
|
}
|
182 |
|
|
|
183 |
8da3de34
|
Colin Smith
|
/*****************************/
|
184 |
|
|
|
185 |
21dc3a7d
|
Colin Smith
|
$server = new XML_RPC_Server(
|
186 |
|
|
array(
|
187 |
52c3baf5
|
Scott Ullrich
|
'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
|
188 |
|
|
'signature' => $carp_configure_doc,
|
189 |
|
|
'docstring' => $carp_configure_sig),
|
190 |
07a7b08f
|
Colin Smith
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
191 |
21dc3a7d
|
Colin Smith
|
'signature' => $backup_config_section_sig,
|
192 |
|
|
'docstring' => $backup_config_section_doc),
|
193 |
|
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
194 |
|
|
'signature' => $restore_config_section_sig,
|
195 |
07a7b08f
|
Colin Smith
|
'docstring' => $restore_config_section_doc),
|
196 |
|
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
197 |
|
|
'signature' => $filter_configure_sig,
|
198 |
44488c3c
|
Colin Smith
|
'docstring' => $filter_configure_doc),
|
199 |
|
|
'pfsense.check_firmware_version' => array('function' => 'check_firmware_version_xmlrpc',
|
200 |
|
|
'signature' => $check_firmware_version_sig,
|
201 |
bd0fe65b
|
Colin Smith
|
'docstring' => $check_firmware_version_doc),
|
202 |
|
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
203 |
|
|
'signature' => $reboot_sig,
|
204 |
d9064267
|
Colin Smith
|
'docstring' => $reboot_doc),
|
205 |
|
|
'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
|
206 |
|
|
'signature' => $get_notices_sig)
|
207 |
50d49018
|
Colin Smith
|
)
|
208 |
|
|
);
|
209 |
03d89831
|
Scott Ullrich
|
?>
|