1 |
50d49018
|
Colin Smith
|
<?php
|
2 |
|
|
/*
|
3 |
aaec5634
|
Renato Botelho
|
* xmlrpc.php
|
4 |
191cb31d
|
Stephen Beaver
|
*
|
5 |
aaec5634
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
2a2396a6
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
aaec5634
|
Renato Botelho
|
* Copyright (c) 2005 Colin Smith
|
8 |
|
|
* All rights reserved.
|
9 |
191cb31d
|
Stephen Beaver
|
*
|
10 |
aaec5634
|
Renato Botelho
|
* Redistribution and use in source and binary forms, with or without
|
11 |
|
|
* modification, are permitted provided that the following conditions are met:
|
12 |
191cb31d
|
Stephen Beaver
|
*
|
13 |
aaec5634
|
Renato Botelho
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
* this list of conditions and the following disclaimer.
|
15 |
191cb31d
|
Stephen Beaver
|
*
|
16 |
aaec5634
|
Renato Botelho
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
* notice, this list of conditions and the following disclaimer in
|
18 |
|
|
* the documentation and/or other materials provided with the
|
19 |
|
|
* distribution.
|
20 |
191cb31d
|
Stephen Beaver
|
*
|
21 |
aaec5634
|
Renato Botelho
|
* 3. All advertising materials mentioning features or use of this software
|
22 |
|
|
* must display the following acknowledgment:
|
23 |
|
|
* "This product includes software developed by the pfSense Project
|
24 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25 |
191cb31d
|
Stephen Beaver
|
*
|
26 |
aaec5634
|
Renato Botelho
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27 |
|
|
* endorse or promote products derived from this software without
|
28 |
|
|
* prior written permission. For written permission, please contact
|
29 |
|
|
* coreteam@pfsense.org.
|
30 |
191cb31d
|
Stephen Beaver
|
*
|
31 |
aaec5634
|
Renato Botelho
|
* 5. Products derived from this software may not be called "pfSense"
|
32 |
|
|
* nor may "pfSense" appear in their names without prior written
|
33 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
34 |
191cb31d
|
Stephen Beaver
|
*
|
35 |
aaec5634
|
Renato Botelho
|
* 6. Redistributions of any form whatsoever must retain the following
|
36 |
|
|
* acknowledgment:
|
37 |
191cb31d
|
Stephen Beaver
|
*
|
38 |
aaec5634
|
Renato Botelho
|
* "This product includes software developed by the pfSense Project
|
39 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40 |
191cb31d
|
Stephen Beaver
|
*
|
41 |
aaec5634
|
Renato Botelho
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53 |
191cb31d
|
Stephen Beaver
|
*/
|
54 |
50d49018
|
Colin Smith
|
|
55 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
56 |
|
|
##|*IDENT=page-xmlrpclibrary
|
57 |
5230f468
|
jim-p
|
##|*NAME=XMLRPC Library
|
58 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'XMLRPC Library' page.
|
59 |
|
|
##|*MATCH=xmlrpc.php*
|
60 |
|
|
##|-PRIV
|
61 |
|
|
|
62 |
aceaf18c
|
Phil Davis
|
require_once("config.inc");
|
63 |
|
|
require_once("functions.inc");
|
64 |
f6339216
|
jim-p
|
require_once("filter.inc");
|
65 |
aceaf18c
|
Phil Davis
|
require_once("ipsec.inc");
|
66 |
|
|
require_once("vpn.inc");
|
67 |
|
|
require_once("shaper.inc");
|
68 |
|
|
require_once("xmlrpc_server.inc");
|
69 |
|
|
require_once("xmlrpc.inc");
|
70 |
50d49018
|
Colin Smith
|
|
71 |
c87f4b70
|
Ermal
|
function xmlrpc_loop_detect() {
|
72 |
|
|
global $config;
|
73 |
|
|
|
74 |
|
|
/* grab sync to ip if enabled */
|
75 |
962f215d
|
Phil Davis
|
if ($config['hasync']) {
|
76 |
c87f4b70
|
Ermal
|
$synchronizetoip = $config['hasync']['synchronizetoip'];
|
77 |
962f215d
|
Phil Davis
|
}
|
78 |
|
|
if ($synchronizetoip) {
|
79 |
|
|
if ($synchronizetoip == $_SERVER['REMOTE_ADDR']) {
|
80 |
|
|
return true;
|
81 |
|
|
}
|
82 |
ff664954
|
Scott Ullrich
|
}
|
83 |
c87f4b70
|
Ermal
|
|
84 |
|
|
return false;
|
85 |
ff664954
|
Scott Ullrich
|
}
|
86 |
|
|
|
87 |
8da3de34
|
Colin Smith
|
$xmlrpc_g = array(
|
88 |
137f46d8
|
Ermal
|
"return" => array(
|
89 |
|
|
"true" => new XML_RPC_Response(new XML_RPC_Value(true, $XML_RPC_Boolean)),
|
90 |
|
|
"false" => new XML_RPC_Response(new XML_RPC_Value(false, $XML_RPC_Boolean)),
|
91 |
|
|
"authfail" => new XML_RPC_Response(new XML_RPC_Value(gettext("Authentication failed"), $XML_RPC_String))
|
92 |
|
|
)
|
93 |
|
|
);
|
94 |
8da3de34
|
Colin Smith
|
|
95 |
|
|
/*
|
96 |
|
|
* pfSense XMLRPC errors
|
97 |
|
|
* $XML_RPC_erruser + 1 = Auth failure
|
98 |
|
|
*/
|
99 |
|
|
$XML_RPC_erruser = 200;
|
100 |
|
|
|
101 |
|
|
/* EXPOSED FUNCTIONS */
|
102 |
de63649b
|
Rafael Lucas
|
$exec_php_doc = gettext("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.");
|
103 |
c3638879
|
Scott Ullrich
|
$exec_php_sig = array(
|
104 |
137f46d8
|
Ermal
|
array(
|
105 |
|
|
$XML_RPC_Boolean, // First signature element is return value.
|
106 |
|
|
$XML_RPC_String, // password
|
107 |
|
|
$XML_RPC_String, // shell code to exec
|
108 |
|
|
)
|
109 |
|
|
);
|
110 |
c3638879
|
Scott Ullrich
|
|
111 |
3dd2a278
|
Scott Ullrich
|
function xmlrpc_authfail() {
|
112 |
|
|
log_auth("webConfigurator authentication error for 'admin' from {$_SERVER['REMOTE_ADDR']}");
|
113 |
|
|
}
|
114 |
|
|
|
115 |
c3638879
|
Scott Ullrich
|
function exec_php_xmlrpc($raw_params) {
|
116 |
|
|
global $config, $xmlrpc_g;
|
117 |
137f46d8
|
Ermal
|
|
118 |
c3638879
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
119 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
120 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
121 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
122 |
3dd2a278
|
Scott Ullrich
|
}
|
123 |
c3638879
|
Scott Ullrich
|
$exec_php = $params[0];
|
124 |
|
|
eval($exec_php);
|
125 |
962f215d
|
Phil Davis
|
if ($toreturn) {
|
126 |
2c0dd581
|
Scott Ullrich
|
$response = XML_RPC_encode($toreturn);
|
127 |
|
|
return new XML_RPC_Response($response);
|
128 |
962f215d
|
Phil Davis
|
} else {
|
129 |
2c0dd581
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
130 |
962f215d
|
Phil Davis
|
}
|
131 |
c3638879
|
Scott Ullrich
|
}
|
132 |
|
|
|
133 |
|
|
/*****************************/
|
134 |
de63649b
|
Rafael Lucas
|
$exec_shell_doc = gettext("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.");
|
135 |
c3638879
|
Scott Ullrich
|
$exec_shell_sig = array(
|
136 |
137f46d8
|
Ermal
|
array(
|
137 |
|
|
$XML_RPC_Boolean, // First signature element is return value.
|
138 |
|
|
$XML_RPC_String, // password
|
139 |
|
|
$XML_RPC_String, // shell code to exec
|
140 |
|
|
)
|
141 |
|
|
);
|
142 |
c3638879
|
Scott Ullrich
|
|
143 |
|
|
function exec_shell_xmlrpc($raw_params) {
|
144 |
|
|
global $config, $xmlrpc_g;
|
145 |
137f46d8
|
Ermal
|
|
146 |
c3638879
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
147 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
148 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
149 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
150 |
3dd2a278
|
Scott Ullrich
|
}
|
151 |
c3638879
|
Scott Ullrich
|
$shell_cmd = $params[0];
|
152 |
|
|
mwexec($shell_cmd);
|
153 |
137f46d8
|
Ermal
|
|
154 |
c3638879
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
/*****************************/
|
158 |
de63649b
|
Rafael Lucas
|
$backup_config_section_doc = gettext("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.");
|
159 |
8da3de34
|
Colin Smith
|
$backup_config_section_sig = array(
|
160 |
137f46d8
|
Ermal
|
array(
|
161 |
|
|
$XML_RPC_Struct, // First signature element is return value.
|
162 |
|
|
$XML_RPC_String,
|
163 |
|
|
$XML_RPC_Array
|
164 |
|
|
)
|
165 |
|
|
);
|
166 |
21dc3a7d
|
Colin Smith
|
|
167 |
57e6d4c9
|
Colin Smith
|
function backup_config_section_xmlrpc($raw_params) {
|
168 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
169 |
137f46d8
|
Ermal
|
|
170 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
171 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
172 |
fb0eb20b
|
Ermal
|
return;
|
173 |
|
|
}
|
174 |
c87f4b70
|
Ermal
|
|
175 |
8da3de34
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
176 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
177 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
178 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
179 |
3dd2a278
|
Scott Ullrich
|
}
|
180 |
03d89831
|
Scott Ullrich
|
$val = array_intersect_key($config, array_flip($params[0]));
|
181 |
137f46d8
|
Ermal
|
|
182 |
8da3de34
|
Colin Smith
|
return new XML_RPC_Response(XML_RPC_encode($val));
|
183 |
50d49018
|
Colin Smith
|
}
|
184 |
|
|
|
185 |
8da3de34
|
Colin Smith
|
/*****************************/
|
186 |
de63649b
|
Rafael Lucas
|
$restore_config_section_doc = gettext("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.");
|
187 |
8da3de34
|
Colin Smith
|
$restore_config_section_sig = array(
|
188 |
137f46d8
|
Ermal
|
array(
|
189 |
|
|
$XML_RPC_Boolean,
|
190 |
|
|
$XML_RPC_String,
|
191 |
|
|
$XML_RPC_Struct
|
192 |
|
|
)
|
193 |
|
|
);
|
194 |
21dc3a7d
|
Colin Smith
|
|
195 |
57e6d4c9
|
Colin Smith
|
function restore_config_section_xmlrpc($raw_params) {
|
196 |
03d89831
|
Scott Ullrich
|
global $config, $xmlrpc_g;
|
197 |
137f46d8
|
Ermal
|
|
198 |
d026178f
|
Renato Botelho
|
$old_config = $config;
|
199 |
1a2de6d6
|
Luiz Otavio O Souza
|
$old_ipsec_enabled = ipsec_enabled();
|
200 |
d026178f
|
Renato Botelho
|
|
201 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
202 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
203 |
fb0eb20b
|
Ermal
|
return;
|
204 |
|
|
}
|
205 |
c87f4b70
|
Ermal
|
|
206 |
57e6d4c9
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
207 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
208 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
209 |
19b5c3e7
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
210 |
3dd2a278
|
Scott Ullrich
|
}
|
211 |
1b99e1e5
|
jim-p
|
|
212 |
|
|
// Some sections should just be copied and not merged or we end
|
213 |
|
|
// up unable to sync the deletion of the last item in a section
|
214 |
f29fd4d0
|
Renato Botelho
|
$sync_full = array('dnsmasq', 'unbound', 'ipsec', 'aliases', 'wol', 'load_balancer', 'openvpn', 'cert', 'ca', 'crl', 'schedules', 'filter', 'nat', 'dhcpd', 'dhcpv6');
|
215 |
1b99e1e5
|
jim-p
|
$sync_full_done = array();
|
216 |
|
|
foreach ($sync_full as $syncfull) {
|
217 |
|
|
if (isset($params[0][$syncfull])) {
|
218 |
|
|
$config[$syncfull] = $params[0][$syncfull];
|
219 |
|
|
unset($params[0][$syncfull]);
|
220 |
|
|
$sync_full_done[] = $syncfull;
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
|
224 |
a8200dbf
|
Ermal
|
$vipbackup = array();
|
225 |
51611440
|
Ermal
|
$oldvips = array();
|
226 |
4d775dd0
|
Ermal
|
if (isset($params[0]['virtualip'])) {
|
227 |
7b47bd4c
|
Ermal
|
if (is_array($config['virtualip']['vip'])) {
|
228 |
51611440
|
Ermal
|
foreach ($config['virtualip']['vip'] as $vipindex => $vip) {
|
229 |
c14781e3
|
Renato Botelho
|
if ($vip['mode'] == "carp") {
|
230 |
|
|
$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['content'] = "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}";
|
231 |
|
|
$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['interface'] = $vip['interface'];
|
232 |
|
|
$oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['subnet'] = $vip['subnet'];
|
233 |
2a5960b0
|
Luiz Otavio O Souza
|
} else if ($vip['mode'] == "ipalias" && (substr($vip['interface'], 0, 4) == '_vip' || strstr($vip['interface'], "lo0"))) {
|
234 |
c14781e3
|
Renato Botelho
|
$oldvips[$vip['subnet']]['content'] = "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}";
|
235 |
|
|
$oldvips[$vip['subnet']]['interface'] = $vip['interface'];
|
236 |
|
|
$oldvips[$vip['subnet']]['subnet'] = $vip['subnet'];
|
237 |
2a5960b0
|
Luiz Otavio O Souza
|
} else if (($vip['mode'] == "ipalias" || $vip['mode'] == 'proxyarp') && !(substr($vip['interface'], 0, 4) == '_vip') || strstr($vip['interface'], "lo0")) {
|
238 |
51611440
|
Ermal
|
$vipbackup[] = $vip;
|
239 |
c14781e3
|
Renato Botelho
|
}
|
240 |
51611440
|
Ermal
|
}
|
241 |
19b5c3e7
|
Ermal
|
}
|
242 |
|
|
}
|
243 |
f51d4f98
|
Ermal
|
|
244 |
962f215d
|
Phil Davis
|
// For vip section, first keep items sent from the master
|
245 |
aa6699fb
|
jim-p
|
$config = array_merge_recursive_unique($config, $params[0]);
|
246 |
51611440
|
Ermal
|
|
247 |
962f215d
|
Phil Davis
|
/* Then add ipalias and proxyarp types already defined on the backup */
|
248 |
f51d4f98
|
Ermal
|
if (is_array($vipbackup) && !empty($vipbackup)) {
|
249 |
962f215d
|
Phil Davis
|
if (!is_array($config['virtualip'])) {
|
250 |
51611440
|
Ermal
|
$config['virtualip'] = array();
|
251 |
962f215d
|
Phil Davis
|
}
|
252 |
|
|
if (!is_array($config['virtualip']['vip'])) {
|
253 |
f51d4f98
|
Ermal
|
$config['virtualip']['vip'] = array();
|
254 |
962f215d
|
Phil Davis
|
}
|
255 |
|
|
foreach ($vipbackup as $vip) {
|
256 |
51611440
|
Ermal
|
array_unshift($config['virtualip']['vip'], $vip);
|
257 |
962f215d
|
Phil Davis
|
}
|
258 |
a8200dbf
|
Ermal
|
}
|
259 |
51611440
|
Ermal
|
|
260 |
|
|
/* Log what happened */
|
261 |
1b99e1e5
|
jim-p
|
$mergedkeys = implode(",", array_merge(array_keys($params[0]), $sync_full_done));
|
262 |
6c07db48
|
Phil Davis
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
|
263 |
51611440
|
Ermal
|
|
264 |
962f215d
|
Phil Davis
|
/*
|
265 |
51611440
|
Ermal
|
* The real work on handling the vips specially
|
266 |
|
|
* This is a copy of intefaces_vips_configure with addition of not reloading existing/not changed carps
|
267 |
|
|
*/
|
268 |
63f81fbd
|
Ermal
|
if (isset($params[0]['virtualip']) && is_array($config['virtualip']) && is_array($config['virtualip']['vip'])) {
|
269 |
51611440
|
Ermal
|
$carp_setuped = false;
|
270 |
f51d4f98
|
Ermal
|
$anyproxyarp = false;
|
271 |
51611440
|
Ermal
|
foreach ($config['virtualip']['vip'] as $vip) {
|
272 |
7b47bd4c
|
Ermal
|
if ($vip['mode'] == "carp" && isset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"])) {
|
273 |
c14781e3
|
Renato Botelho
|
if ($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]['content'] == "{$vip['password']}{$vip['advskew']}{$vip['subnet']}{$vip['subnet_bits']}{$vip['advbase']}") {
|
274 |
2708a5cf
|
Ermal
|
if (does_vip_exist($vip)) {
|
275 |
7b47bd4c
|
Ermal
|
unset($oldvips["{$vip['interface']}_vip{$vip['vhid']}"]);
|
276 |
d1e03822
|
Ermal
|
continue; // Skip reconfiguring this vips since nothing has changed.
|
277 |
19ed1624
|
Ermal
|
}
|
278 |
92ca32cc
|
Ermal
|
}
|
279 |
69a991b3
|
jim-p
|
} else if ($vip['mode'] == "ipalias" && (substr($vip['interface'], 0, 4) == '_vip' || strstr($vip['interface'], "lo0")) && isset($oldvips[$vip['subnet']])) {
|
280 |
c14781e3
|
Renato Botelho
|
if ($oldvips[$vip['subnet']]['content'] == "{$vip['interface']}{$vip['subnet']}{$vip['subnet_bits']}") {
|
281 |
2708a5cf
|
Ermal
|
if (does_vip_exist($vip)) {
|
282 |
|
|
unset($oldvips[$vip['subnet']]);
|
283 |
|
|
continue; // Skip reconfiguring this vips since nothing has changed.
|
284 |
|
|
}
|
285 |
|
|
}
|
286 |
|
|
unset($oldvips[$vip['subnet']]);
|
287 |
51611440
|
Ermal
|
}
|
288 |
|
|
|
289 |
|
|
switch ($vip['mode']) {
|
290 |
962f215d
|
Phil Davis
|
case "proxyarp":
|
291 |
|
|
$anyproxyarp = true;
|
292 |
|
|
break;
|
293 |
|
|
case "ipalias":
|
294 |
|
|
interface_ipalias_configure($vip);
|
295 |
|
|
break;
|
296 |
|
|
case "carp":
|
297 |
|
|
if ($carp_setuped == false) {
|
298 |
|
|
$carp_setuped = true;
|
299 |
|
|
}
|
300 |
|
|
interface_carp_configure($vip);
|
301 |
|
|
break;
|
302 |
51611440
|
Ermal
|
}
|
303 |
|
|
}
|
304 |
|
|
/* Cleanup remaining old carps */
|
305 |
c14781e3
|
Renato Botelho
|
foreach ($oldvips as $oldvipar) {
|
306 |
|
|
$oldvipif = get_real_interface($oldvipar['interface']);
|
307 |
e3cffd6c
|
Ermal LUÇI
|
if (!empty($oldvipif)) {
|
308 |
962f215d
|
Phil Davis
|
if (is_ipaddrv6($oldvipar['subnet'])) {
|
309 |
e3cffd6c
|
Ermal LUÇI
|
mwexec("/sbin/ifconfig " . escapeshellarg($oldvipif) . " inet6 " . escapeshellarg($oldvipar['subnet']) . " delete");
|
310 |
962f215d
|
Phil Davis
|
} else {
|
311 |
e3cffd6c
|
Ermal LUÇI
|
pfSense_interface_deladdress($oldvipif, $oldvipar['subnet']);
|
312 |
962f215d
|
Phil Davis
|
}
|
313 |
e3cffd6c
|
Ermal LUÇI
|
}
|
314 |
51611440
|
Ermal
|
}
|
315 |
962f215d
|
Phil Davis
|
if ($carp_setuped == true) {
|
316 |
8ff85c39
|
Ermal
|
interfaces_sync_setup();
|
317 |
962f215d
|
Phil Davis
|
}
|
318 |
|
|
if ($anyproxyarp == true) {
|
319 |
51611440
|
Ermal
|
interface_proxyarp_configure();
|
320 |
962f215d
|
Phil Davis
|
}
|
321 |
51611440
|
Ermal
|
}
|
322 |
137f46d8
|
Ermal
|
|
323 |
1a2de6d6
|
Luiz Otavio O Souza
|
if ($old_ipsec_enabled !== ipsec_enabled()) {
|
324 |
d026178f
|
Renato Botelho
|
vpn_ipsec_configure();
|
325 |
962f215d
|
Phil Davis
|
}
|
326 |
d026178f
|
Renato Botelho
|
|
327 |
|
|
unset($old_config);
|
328 |
|
|
|
329 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
330 |
50d49018
|
Colin Smith
|
}
|
331 |
|
|
|
332 |
82ae5cfc
|
Scott Ullrich
|
/*****************************/
|
333 |
29e5cbb4
|
Phil Davis
|
$merge_installedpackages_section_doc = gettext("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.");
|
334 |
|
|
$merge_installedpackages_section_sig = array(
|
335 |
137f46d8
|
Ermal
|
array(
|
336 |
|
|
$XML_RPC_Boolean,
|
337 |
|
|
$XML_RPC_String,
|
338 |
|
|
$XML_RPC_Struct
|
339 |
|
|
)
|
340 |
|
|
);
|
341 |
82ae5cfc
|
Scott Ullrich
|
|
342 |
|
|
function merge_installedpackages_section_xmlrpc($raw_params) {
|
343 |
|
|
global $config, $xmlrpc_g;
|
344 |
137f46d8
|
Ermal
|
|
345 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
346 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
347 |
fb0eb20b
|
Ermal
|
return;
|
348 |
|
|
}
|
349 |
c87f4b70
|
Ermal
|
|
350 |
82ae5cfc
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
351 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
352 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
353 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
354 |
3dd2a278
|
Scott Ullrich
|
}
|
355 |
82ae5cfc
|
Scott Ullrich
|
$config['installedpackages'] = array_merge($config['installedpackages'], $params[0]);
|
356 |
|
|
$mergedkeys = implode(",", array_keys($params[0]));
|
357 |
6c07db48
|
Phil Davis
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
|
358 |
137f46d8
|
Ermal
|
|
359 |
82ae5cfc
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
360 |
|
|
}
|
361 |
|
|
|
362 |
8da3de34
|
Colin Smith
|
/*****************************/
|
363 |
de63649b
|
Rafael Lucas
|
$merge_config_section_doc = gettext("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.");
|
364 |
dc1cd85d
|
Scott Ullrich
|
$merge_config_section_sig = array(
|
365 |
137f46d8
|
Ermal
|
array(
|
366 |
|
|
$XML_RPC_Boolean,
|
367 |
|
|
$XML_RPC_String,
|
368 |
|
|
$XML_RPC_Struct
|
369 |
|
|
)
|
370 |
|
|
);
|
371 |
dc1cd85d
|
Scott Ullrich
|
|
372 |
|
|
function merge_config_section_xmlrpc($raw_params) {
|
373 |
|
|
global $config, $xmlrpc_g;
|
374 |
c87f4b70
|
Ermal
|
|
375 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
376 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
377 |
fb0eb20b
|
Ermal
|
return;
|
378 |
|
|
}
|
379 |
c87f4b70
|
Ermal
|
|
380 |
db748384
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
381 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
382 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
383 |
db748384
|
Scott Ullrich
|
return $xmlrpc_g['return']['authfail'];
|
384 |
3dd2a278
|
Scott Ullrich
|
}
|
385 |
f9d7c5b3
|
Scott Ullrich
|
$config_new = array_overlay($config, $params[0]);
|
386 |
db748384
|
Scott Ullrich
|
$config = $config_new;
|
387 |
|
|
$mergedkeys = implode(",", array_keys($params[0]));
|
388 |
|
|
write_config(sprintf(gettext("Merged in config (%s sections) from XMLRPC client."), $mergedkeys));
|
389 |
|
|
return $xmlrpc_g['return']['true'];
|
390 |
dc1cd85d
|
Scott Ullrich
|
}
|
391 |
|
|
|
392 |
|
|
/*****************************/
|
393 |
962f215d
|
Phil Davis
|
$filter_configure_doc = gettext("Basic XMLRPC wrapper for filter_configure. This method must be called with one parameter: a string containing the local system\'s password. This function returns true upon completion.");
|
394 |
8da3de34
|
Colin Smith
|
$filter_configure_sig = array(
|
395 |
137f46d8
|
Ermal
|
array(
|
396 |
|
|
$XML_RPC_Boolean,
|
397 |
|
|
$XML_RPC_String
|
398 |
|
|
)
|
399 |
|
|
);
|
400 |
07a7b08f
|
Colin Smith
|
|
401 |
|
|
function filter_configure_xmlrpc($raw_params) {
|
402 |
57b5da70
|
jim-p
|
global $xmlrpc_g, $g, $config;
|
403 |
137f46d8
|
Ermal
|
|
404 |
07a7b08f
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
405 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
406 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
407 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
408 |
3dd2a278
|
Scott Ullrich
|
}
|
409 |
07a7b08f
|
Colin Smith
|
filter_configure();
|
410 |
e700437b
|
Scott Ullrich
|
system_routing_configure();
|
411 |
41e6d4bd
|
Seth Mos
|
setup_gateways_monitor();
|
412 |
651c32e2
|
Bill Marquette
|
relayd_configure();
|
413 |
c3fef0c9
|
jim-p
|
require_once("openvpn.inc");
|
414 |
|
|
openvpn_resync_all();
|
415 |
57b5da70
|
jim-p
|
|
416 |
|
|
/* The DNS Resolver and the DNS Forwarder may both be active so long as
|
417 |
|
|
* they are running on different ports. See ticket #5882
|
418 |
|
|
*/
|
419 |
|
|
$need_dhcp_start = true;
|
420 |
962f215d
|
Phil Davis
|
if (isset($config['dnsmasq']['enable'])) {
|
421 |
57b5da70
|
jim-p
|
/* Configure dnsmasq but tell it NOT to restart DHCP */
|
422 |
|
|
services_dnsmasq_configure(false);
|
423 |
|
|
} else {
|
424 |
|
|
/* kill any running dnsmasq since it is not enabled. */
|
425 |
|
|
if (file_exists("{$g['varrun_path']}/dnsmasq.pid")) {
|
426 |
|
|
sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM");
|
427 |
|
|
}
|
428 |
|
|
}
|
429 |
|
|
if (isset($config['unbound']['enable'])) {
|
430 |
|
|
/* Configure unbound but tell it NOT to restart DHCP */
|
431 |
|
|
services_unbound_configure(false);
|
432 |
962f215d
|
Phil Davis
|
} else {
|
433 |
57b5da70
|
jim-p
|
/* kill any running Unbound instance since it is not enabled. */
|
434 |
|
|
if (file_exists("{$g['varrun_path']}/unbound.pid")) {
|
435 |
|
|
sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM");
|
436 |
|
|
}
|
437 |
962f215d
|
Phil Davis
|
}
|
438 |
57b5da70
|
jim-p
|
|
439 |
|
|
/* Call this separately since the above are manually set to skip the DHCP restart they normally perform.
|
440 |
|
|
* This avoids restarting dhcpd twice as described on ticket #3797
|
441 |
|
|
*/
|
442 |
|
|
services_dhcpd_configure();
|
443 |
|
|
|
444 |
0ce72662
|
jim-p
|
local_sync_accounts();
|
445 |
137f46d8
|
Ermal
|
|
446 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
447 |
07a7b08f
|
Colin Smith
|
}
|
448 |
|
|
|
449 |
8da3de34
|
Colin Smith
|
/*****************************/
|
450 |
de63649b
|
Rafael Lucas
|
$carp_configure_doc = gettext("Basic XMLRPC wrapper for configuring CARP interfaces.");
|
451 |
efe7562e
|
Scott Ullrich
|
$carp_configure_sig = array(
|
452 |
137f46d8
|
Ermal
|
array(
|
453 |
|
|
$XML_RPC_Boolean,
|
454 |
|
|
$XML_RPC_String
|
455 |
|
|
)
|
456 |
|
|
);
|
457 |
efe7562e
|
Scott Ullrich
|
|
458 |
|
|
function interfaces_carp_configure_xmlrpc($raw_params) {
|
459 |
|
|
global $xmlrpc_g;
|
460 |
137f46d8
|
Ermal
|
|
461 |
fb0eb20b
|
Ermal
|
if (xmlrpc_loop_detect()) {
|
462 |
c87f4b70
|
Ermal
|
log_error("Disallowing CARP sync loop");
|
463 |
fb0eb20b
|
Ermal
|
return;
|
464 |
|
|
}
|
465 |
c87f4b70
|
Ermal
|
|
466 |
efe7562e
|
Scott Ullrich
|
$params = xmlrpc_params_to_php($raw_params);
|
467 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
468 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
469 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
470 |
3dd2a278
|
Scott Ullrich
|
}
|
471 |
efe7562e
|
Scott Ullrich
|
interfaces_vips_configure();
|
472 |
137f46d8
|
Ermal
|
|
473 |
efe7562e
|
Scott Ullrich
|
return $xmlrpc_g['return']['true'];
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
/*****************************/
|
477 |
0cdb94e1
|
Renato Botelho
|
$pfsense_firmware_version_doc = gettext("Basic XMLRPC wrapper for host_firmware_version. This function will return the output of host_firmware_version upon completion.");
|
478 |
0567899d
|
Ermal
|
|
479 |
|
|
$pfsense_firmware_version_sig = array (
|
480 |
962f215d
|
Phil Davis
|
array (
|
481 |
|
|
$XML_RPC_Struct,
|
482 |
|
|
$XML_RPC_String
|
483 |
|
|
)
|
484 |
0567899d
|
Ermal
|
);
|
485 |
e501de37
|
Ermal
|
|
486 |
|
|
function pfsense_firmware_version_xmlrpc($raw_params) {
|
487 |
962f215d
|
Phil Davis
|
global $xmlrpc_g;
|
488 |
e501de37
|
Ermal
|
|
489 |
962f215d
|
Phil Davis
|
$params = xmlrpc_params_to_php($raw_params);
|
490 |
|
|
if (!xmlrpc_auth($params)) {
|
491 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
492 |
|
|
return $xmlrpc_g['return']['authfail'];
|
493 |
|
|
}
|
494 |
962f215d
|
Phil Davis
|
return new XML_RPC_Response(XML_RPC_encode(host_firmware_version()));
|
495 |
e501de37
|
Ermal
|
}
|
496 |
|
|
|
497 |
8da3de34
|
Colin Smith
|
/*****************************/
|
498 |
de63649b
|
Rafael Lucas
|
$reboot_doc = gettext("Basic XMLRPC wrapper for rc.reboot.");
|
499 |
1cdca133
|
Colin Smith
|
$reboot_sig = array(array($XML_RPC_Boolean, $XML_RPC_String));
|
500 |
bd0fe65b
|
Colin Smith
|
function reboot_xmlrpc($raw_params) {
|
501 |
8da3de34
|
Colin Smith
|
global $xmlrpc_g;
|
502 |
137f46d8
|
Ermal
|
|
503 |
bd0fe65b
|
Colin Smith
|
$params = xmlrpc_params_to_php($raw_params);
|
504 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
505 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
506 |
137f46d8
|
Ermal
|
return $xmlrpc_g['return']['authfail'];
|
507 |
3dd2a278
|
Scott Ullrich
|
}
|
508 |
53cf5533
|
Colin Smith
|
mwexec_bg("/etc/rc.reboot");
|
509 |
137f46d8
|
Ermal
|
|
510 |
8da3de34
|
Colin Smith
|
return $xmlrpc_g['return']['true'];
|
511 |
bd0fe65b
|
Colin Smith
|
}
|
512 |
|
|
|
513 |
8da3de34
|
Colin Smith
|
/*****************************/
|
514 |
|
|
$get_notices_sig = array(
|
515 |
137f46d8
|
Ermal
|
array(
|
516 |
|
|
$XML_RPC_Array,
|
517 |
|
|
$XML_RPC_String
|
518 |
|
|
),
|
519 |
|
|
array(
|
520 |
|
|
$XML_RPC_Array
|
521 |
|
|
)
|
522 |
|
|
);
|
523 |
8da3de34
|
Colin Smith
|
|
524 |
d9064267
|
Colin Smith
|
function get_notices_xmlrpc($raw_params) {
|
525 |
8da3de34
|
Colin Smith
|
global $g, $xmlrpc_g;
|
526 |
137f46d8
|
Ermal
|
|
527 |
b4d19b46
|
Bill Marquette
|
$params = xmlrpc_params_to_php($raw_params);
|
528 |
962f215d
|
Phil Davis
|
if (!xmlrpc_auth($params)) {
|
529 |
3dd2a278
|
Scott Ullrich
|
xmlrpc_authfail();
|
530 |
|
|
return $xmlrpc_g['return']['authfail'];
|
531 |
|
|
}
|
532 |
962f215d
|
Phil Davis
|
if (!function_exists("get_notices")) {
|
533 |
aceaf18c
|
Phil Davis
|
require_once("notices.inc");
|
534 |
962f215d
|
Phil Davis
|
}
|
535 |
|
|
if (!$params) {
|
536 |
d9064267
|
Colin Smith
|
$toreturn = get_notices();
|
537 |
|
|
} else {
|
538 |
8da3de34
|
Colin Smith
|
$toreturn = get_notices($params);
|
539 |
d9064267
|
Colin Smith
|
}
|
540 |
|
|
$response = new XML_RPC_Response(XML_RPC_encode($toreturn));
|
541 |
137f46d8
|
Ermal
|
|
542 |
d9064267
|
Colin Smith
|
return $response;
|
543 |
|
|
}
|
544 |
|
|
|
545 |
67d78c87
|
Ermal
|
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
|
546 |
|
|
|
547 |
8da3de34
|
Colin Smith
|
/*****************************/
|
548 |
21dc3a7d
|
Colin Smith
|
$server = new XML_RPC_Server(
|
549 |
962f215d
|
Phil Davis
|
array(
|
550 |
137f46d8
|
Ermal
|
'pfsense.exec_shell' => array('function' => 'exec_shell_xmlrpc',
|
551 |
0567899d
|
Ermal
|
'signature' => $exec_shell_sig,
|
552 |
|
|
'docstring' => $exec_shell_doc),
|
553 |
137f46d8
|
Ermal
|
'pfsense.exec_php' => array('function' => 'exec_php_xmlrpc',
|
554 |
0567899d
|
Ermal
|
'signature' => $exec_php_sig,
|
555 |
962f215d
|
Phil Davis
|
'docstring' => $exec_php_doc),
|
556 |
137f46d8
|
Ermal
|
'pfsense.filter_configure' => array('function' => 'filter_configure_xmlrpc',
|
557 |
0567899d
|
Ermal
|
'signature' => $filter_configure_sig,
|
558 |
|
|
'docstring' => $filter_configure_doc),
|
559 |
137f46d8
|
Ermal
|
'pfsense.interfaces_carp_configure' => array('function' => 'interfaces_carp_configure_xmlrpc',
|
560 |
29e5cbb4
|
Phil Davis
|
'signature' => $carp_configure_sig,
|
561 |
|
|
'docstring' => $carp_configure_doc),
|
562 |
137f46d8
|
Ermal
|
'pfsense.backup_config_section' => array('function' => 'backup_config_section_xmlrpc',
|
563 |
0567899d
|
Ermal
|
'signature' => $backup_config_section_sig,
|
564 |
|
|
'docstring' => $backup_config_section_doc),
|
565 |
137f46d8
|
Ermal
|
'pfsense.restore_config_section' => array('function' => 'restore_config_section_xmlrpc',
|
566 |
0567899d
|
Ermal
|
'signature' => $restore_config_section_sig,
|
567 |
|
|
'docstring' => $restore_config_section_doc),
|
568 |
137f46d8
|
Ermal
|
'pfsense.merge_config_section' => array('function' => 'merge_config_section_xmlrpc',
|
569 |
0567899d
|
Ermal
|
'signature' => $merge_config_section_sig,
|
570 |
|
|
'docstring' => $merge_config_section_doc),
|
571 |
137f46d8
|
Ermal
|
'pfsense.merge_installedpackages_section_xmlrpc' => array('function' => 'merge_installedpackages_section_xmlrpc',
|
572 |
29e5cbb4
|
Phil Davis
|
'signature' => $merge_installedpackages_section_sig,
|
573 |
|
|
'docstring' => $merge_installedpackages_section_doc),
|
574 |
e501de37
|
Ermal
|
'pfsense.host_firmware_version' => array('function' => 'pfsense_firmware_version_xmlrpc',
|
575 |
0567899d
|
Ermal
|
'signature' => $pfsense_firmware_version_sig,
|
576 |
29e5cbb4
|
Phil Davis
|
'docstring' => $pfsense_firmware_version_doc),
|
577 |
137f46d8
|
Ermal
|
'pfsense.reboot' => array('function' => 'reboot_xmlrpc',
|
578 |
0567899d
|
Ermal
|
'signature' => $reboot_sig,
|
579 |
|
|
'docstring' => $reboot_doc),
|
580 |
137f46d8
|
Ermal
|
'pfsense.get_notices' => array('function' => 'get_notices_xmlrpc',
|
581 |
0567899d
|
Ermal
|
'signature' => $get_notices_sig)
|
582 |
962f215d
|
Phil Davis
|
)
|
583 |
50d49018
|
Colin Smith
|
);
|
584 |
b298dd06
|
Scott Ullrich
|
|
585 |
67d78c87
|
Ermal
|
unlock($xmlrpclockkey);
|
586 |
|
|
|
587 |
6c07db48
|
Phil Davis
|
function array_overlay($a1, $a2) {
|
588 |
962f215d
|
Phil Davis
|
foreach ($a1 as $k => $v) {
|
589 |
6c07db48
|
Phil Davis
|
if (!array_key_exists($k, $a2)) {
|
590 |
962f215d
|
Phil Davis
|
continue;
|
591 |
|
|
}
|
592 |
|
|
if (is_array($v) && is_array($a2[$k])) {
|
593 |
6c07db48
|
Phil Davis
|
$a1[$k] = array_overlay($v, $a2[$k]);
|
594 |
962f215d
|
Phil Davis
|
} else {
|
595 |
|
|
$a1[$k] = $a2[$k];
|
596 |
|
|
}
|
597 |
|
|
}
|
598 |
|
|
return $a1;
|
599 |
|
|
}
|
600 |
0b581a8a
|
Scott Ullrich
|
|
601 |
de63649b
|
Rafael Lucas
|
?>
|