1
|
<?php
|
2
|
/*
|
3
|
* xmlrpc.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
|
7
|
* Copyright (c) 2005 Colin Smith
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
##|+PRIV
|
24
|
##|*IDENT=page-xmlrpclibrary
|
25
|
##|*NAME=XMLRPC Library
|
26
|
##|*DESCR=Allow access to the 'XMLRPC Library' page.
|
27
|
##|*MATCH=xmlrpc.php*
|
28
|
##|-PRIV
|
29
|
|
30
|
require_once("config.inc");
|
31
|
require_once("functions.inc");
|
32
|
require_once("auth.inc");
|
33
|
require_once("filter.inc");
|
34
|
require_once("ipsec.inc");
|
35
|
require_once("vpn.inc");
|
36
|
require_once("captiveportal.inc");
|
37
|
require_once("shaper.inc");
|
38
|
require_once("XML/RPC2/Server.php");
|
39
|
|
40
|
class pfsense_xmlrpc_server {
|
41
|
|
42
|
private $loop_detected = false;
|
43
|
private $remote_addr;
|
44
|
|
45
|
private function auth() {
|
46
|
global $config;
|
47
|
$username = $_SERVER['PHP_AUTH_USER'];
|
48
|
$password = $_SERVER['PHP_AUTH_PW'];
|
49
|
|
50
|
$login_ok = false;
|
51
|
if (!empty($username) && !empty($password)) {
|
52
|
$attributes = array();
|
53
|
$authcfg = auth_get_authserver(
|
54
|
$config['system']['webgui']['authmode']);
|
55
|
|
56
|
if (authenticate_user($username, $password,
|
57
|
$authcfg, $attributes) ||
|
58
|
authenticate_user($username, $password)) {
|
59
|
$login_ok = true;
|
60
|
}
|
61
|
}
|
62
|
|
63
|
if (!$login_ok) {
|
64
|
log_auth(sprintf(gettext("webConfigurator authentication error for user '%1\$s' from: %2\$s"),
|
65
|
$username,
|
66
|
$this->remote_addr));
|
67
|
|
68
|
require_once("XML/RPC2/Exception.php");
|
69
|
throw new XML_RPC2_FaultException(gettext(
|
70
|
'Authentication failed: Invalid username or password'),
|
71
|
-1);
|
72
|
}
|
73
|
|
74
|
$user_entry = getUserEntry($username);
|
75
|
/*
|
76
|
* admin (uid = 0) is allowed
|
77
|
* or regular user with necessary privilege
|
78
|
*/
|
79
|
if (isset($user_entry['uid']) && $user_entry['uid'] != '0' &&
|
80
|
!userHasPrivilege($user_entry, 'system-xmlrpc-ha-sync')) {
|
81
|
log_auth("webConfigurator authentication error for '" .
|
82
|
$username . "' from " . $this->remote_addr .
|
83
|
" not enough privileges");
|
84
|
|
85
|
require_once("XML/RPC2/Exception.php");
|
86
|
throw new XML_RPC2_FaultException(gettext(
|
87
|
'Authentication failed: not enough privileges'),
|
88
|
-2);
|
89
|
}
|
90
|
|
91
|
return;
|
92
|
}
|
93
|
|
94
|
private function array_overlay($a1, $a2) {
|
95
|
foreach ($a1 as $k => $v) {
|
96
|
if (!array_key_exists($k, $a2)) {
|
97
|
continue;
|
98
|
}
|
99
|
if (is_array($v) && is_array($a2[$k])) {
|
100
|
$a1[$k] = $this->array_overlay($v, $a2[$k]);
|
101
|
} else {
|
102
|
$a1[$k] = $a2[$k];
|
103
|
}
|
104
|
}
|
105
|
|
106
|
return $a1;
|
107
|
}
|
108
|
|
109
|
public function __construct() {
|
110
|
global $config;
|
111
|
|
112
|
$this->remote_addr = $_SERVER['REMOTE_ADDR'];
|
113
|
|
114
|
/* grab sync to ip if enabled */
|
115
|
if (isset($config['hasync']['synchronizetoip']) &&
|
116
|
$config['hasync']['synchronizetoip'] == $this->remote_addr) {
|
117
|
$this->loop_detected = true;
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Get host version information
|
123
|
*
|
124
|
* @return array
|
125
|
*/
|
126
|
public function host_firmware_version($dummy = 1) {
|
127
|
$this->auth();
|
128
|
return host_firmware_version();
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Executes a PHP block of code
|
133
|
*
|
134
|
* @param string $code
|
135
|
*
|
136
|
* @return bool
|
137
|
*/
|
138
|
public function exec_php($code) {
|
139
|
$this->auth();
|
140
|
|
141
|
eval($code);
|
142
|
if ($toreturn) {
|
143
|
return $toreturn;
|
144
|
}
|
145
|
|
146
|
return true;
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* Executes shell commands
|
151
|
*
|
152
|
* @param string $code
|
153
|
*
|
154
|
* @return bool
|
155
|
*/
|
156
|
public function exec_shell($code) {
|
157
|
$this->auth();
|
158
|
|
159
|
mwexec($code);
|
160
|
return true;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* Backup chosen config sections
|
165
|
*
|
166
|
* @param array $section
|
167
|
*
|
168
|
* @return array
|
169
|
*/
|
170
|
public function backup_config_section($section) {
|
171
|
$this->auth();
|
172
|
|
173
|
global $config;
|
174
|
|
175
|
return array_intersect_key($config, array_flip($section));
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Restore defined config section into local config
|
180
|
*
|
181
|
* @param array $sections
|
182
|
*
|
183
|
* @return bool
|
184
|
*/
|
185
|
public function restore_config_section($sections) {
|
186
|
$this->auth();
|
187
|
|
188
|
global $config, $cpzone, $cpzoneid;
|
189
|
|
190
|
$old_config = $config;
|
191
|
$old_ipsec_enabled = ipsec_enabled();
|
192
|
|
193
|
if ($this->loop_detected) {
|
194
|
log_error("Disallowing CARP sync loop");
|
195
|
return true;
|
196
|
}
|
197
|
|
198
|
/*
|
199
|
* Some sections should just be copied and not merged or we end
|
200
|
* up unable to sync the deletion of the last item in a section
|
201
|
*/
|
202
|
$sync_full_sections = array(
|
203
|
'aliases',
|
204
|
'ca',
|
205
|
'cert',
|
206
|
'crl',
|
207
|
'dhcpd',
|
208
|
'dhcpv6',
|
209
|
'dnsmasq',
|
210
|
'filter',
|
211
|
'ipsec',
|
212
|
'load_balancer',
|
213
|
'nat',
|
214
|
'openvpn',
|
215
|
'schedules',
|
216
|
'unbound',
|
217
|
'wol',
|
218
|
);
|
219
|
|
220
|
$syncd_full_sections = array();
|
221
|
|
222
|
foreach ($sync_full_sections as $section) {
|
223
|
if (!isset($sections[$section])) {
|
224
|
continue;
|
225
|
}
|
226
|
|
227
|
$config[$section] = $sections[$section];
|
228
|
unset($sections[$section]);
|
229
|
$syncd_full_sections[] = $section;
|
230
|
}
|
231
|
|
232
|
/* Create a list of CP zones to be deleted locally */
|
233
|
$cp_to_del = array();
|
234
|
if (is_array($config['captiveportal'])) {
|
235
|
if (is_array($sections['captiveportal'])) {
|
236
|
$remote_cp = $sections['captiveportal'];
|
237
|
} else {
|
238
|
$remote_cp = array();
|
239
|
}
|
240
|
foreach ($config['captiveportal'] as $zone => $item) {
|
241
|
if (!isset($remote_cp[$zone])) {
|
242
|
$cp_to_del[] = $zone;
|
243
|
}
|
244
|
}
|
245
|
unset($remote_cp);
|
246
|
}
|
247
|
|
248
|
/* Only touch users if users are set to synchronize from the primary node
|
249
|
* See https://redmine.pfsense.org/issues/8450
|
250
|
*/
|
251
|
if ($sections['system']['user'] && $sections['system']['group']) {
|
252
|
$g2add = array();
|
253
|
$g2del = array();
|
254
|
$g2del_idx = array();
|
255
|
$g2keep = array();
|
256
|
if (is_array($sections['system']['group'])) {
|
257
|
$local_groups = isset($config['system']['group'])
|
258
|
? $config['system']['group']
|
259
|
: array();
|
260
|
|
261
|
foreach ($sections['system']['group'] as $group) {
|
262
|
$idx = array_search($group['name'],
|
263
|
array_column($local_groups, 'name'));
|
264
|
|
265
|
if ($idx === false) {
|
266
|
$g2add[] = $group;
|
267
|
} else if ($group['gid'] < 1999) {
|
268
|
$g2keep[] = $idx;
|
269
|
} else if ($group != $local_groups[$idx]) {
|
270
|
$g2add[] = $group;
|
271
|
$g2del[] = $group;
|
272
|
$g2del_idx[] = $idx;
|
273
|
} else {
|
274
|
$g2keep[] = $idx;
|
275
|
}
|
276
|
}
|
277
|
}
|
278
|
if (is_array($config['system']['group'])) {
|
279
|
foreach ($config['system']['group'] as $idx => $group) {
|
280
|
if (array_search($idx, $g2keep) === false &&
|
281
|
array_search($idx, $g2del_idx) === false) {
|
282
|
$g2del[] = $group;
|
283
|
$g2del_idx[] = $idx;
|
284
|
}
|
285
|
}
|
286
|
}
|
287
|
unset($sections['system']['group'], $g2keep, $g2del_idx);
|
288
|
|
289
|
$u2add = array();
|
290
|
$u2del = array();
|
291
|
$u2del_idx = array();
|
292
|
$u2keep = array();
|
293
|
if (is_array($sections['system']['user'])) {
|
294
|
$local_users = isset($config['system']['user'])
|
295
|
? $config['system']['user']
|
296
|
: array();
|
297
|
|
298
|
foreach ($sections['system']['user'] as $user) {
|
299
|
$idx = array_search($user['name'],
|
300
|
array_column($local_users, 'name'));
|
301
|
|
302
|
if ($idx === false) {
|
303
|
$u2add[] = $user;
|
304
|
} else if ($user['uid'] < 2000) {
|
305
|
$u2keep[] = $idx;
|
306
|
} else if ($user != $local_users[$idx]) {
|
307
|
$u2add[] = $user;
|
308
|
$u2del[] = $user;
|
309
|
$u2del_idx[] = $idx;
|
310
|
} else {
|
311
|
$u2keep[] = $idx;
|
312
|
}
|
313
|
}
|
314
|
}
|
315
|
if (is_array($config['system']['user'])) {
|
316
|
foreach ($config['system']['user'] as $idx => $user) {
|
317
|
if (array_search($idx, $u2keep) === false &&
|
318
|
array_search($idx, $u2del_idx) === false) {
|
319
|
$u2del[] = $user;
|
320
|
$u2del_idx[] = $idx;
|
321
|
}
|
322
|
}
|
323
|
}
|
324
|
unset($sections['system']['user'], $u2keep, $u2del_idx);
|
325
|
}
|
326
|
|
327
|
$voucher = array();
|
328
|
if (is_array($sections['voucher'])) {
|
329
|
/* Save voucher rolls to process after merge */
|
330
|
$voucher = $sections['voucher'];
|
331
|
|
332
|
foreach($sections['voucher'] as $zone => $item) {
|
333
|
unset($sections['voucher'][$zone]['roll']);
|
334
|
if (isset($config['voucher'][$zone]['vouchersyncdbip'])) {
|
335
|
$sections['voucher'][$zone]['vouchersyncdbip'] =
|
336
|
$config['voucher'][$zone]['vouchersyncdbip'];
|
337
|
} else {
|
338
|
unset($sections['voucher'][$zone]['vouchersyncdbip']);
|
339
|
}
|
340
|
if (isset($config['voucher'][$zone]['vouchersyncport'])) {
|
341
|
$sections['voucher'][$zone]['vouchersyncport'] =
|
342
|
$config['voucher'][$zone]['vouchersyncport'];
|
343
|
} else {
|
344
|
unset($sections['voucher'][$zone]['vouchersyncport']);
|
345
|
}
|
346
|
if (isset($config['voucher'][$zone]['vouchersyncusername'])) {
|
347
|
$sections['voucher'][$zone]['vouchersyncusername'] =
|
348
|
$config['voucher'][$zone]['vouchersyncusername'];
|
349
|
} else {
|
350
|
unset($sections['voucher'][$zone]['vouchersyncusername']);
|
351
|
}
|
352
|
if (isset($config['voucher'][$zone]['vouchersyncpass'])) {
|
353
|
$sections['voucher'][$zone]['vouchersyncpass'] =
|
354
|
$config['voucher'][$zone]['vouchersyncpass'];
|
355
|
} else {
|
356
|
unset($sections['voucher'][$zone]['vouchersyncpass']);
|
357
|
}
|
358
|
}
|
359
|
}
|
360
|
|
361
|
$vipbackup = array();
|
362
|
$oldvips = array();
|
363
|
if (isset($sections['virtualip']) &&
|
364
|
is_array($config['virtualip']['vip'])) {
|
365
|
foreach ($config['virtualip']['vip'] as $vip) {
|
366
|
if ($vip['mode'] == "carp") {
|
367
|
$key = $vip['interface'] .
|
368
|
"_vip" . $vip['vhid'];
|
369
|
|
370
|
$oldvips[$key]['content'] =
|
371
|
$vip['password'] .
|
372
|
$vip['advskew'] .
|
373
|
$vip['subnet'] .
|
374
|
$vip['subnet_bits'] .
|
375
|
$vip['advbase'];
|
376
|
$oldvips[$key]['interface'] =
|
377
|
$vip['interface'];
|
378
|
$oldvips[$key]['subnet'] =
|
379
|
$vip['subnet'];
|
380
|
} else if ($vip['mode'] == "ipalias" &&
|
381
|
(substr($vip['interface'], 0, 4) == '_vip'
|
382
|
|| strstr($vip['interface'], "lo0"))) {
|
383
|
$oldvips[$vip['subnet']]['content'] =
|
384
|
$vip['interface'] .
|
385
|
$vip['subnet'] .
|
386
|
$vip['subnet_bits'];
|
387
|
$oldvips[$vip['subnet']]['interface'] =
|
388
|
$vip['interface'];
|
389
|
$oldvips[$vip['subnet']]['subnet'] =
|
390
|
$vip['subnet'];
|
391
|
} else if (($vip['mode'] == "ipalias" ||
|
392
|
$vip['mode'] == 'proxyarp') &&
|
393
|
!(substr($vip['interface'], 0, 4) == '_vip')
|
394
|
|| strstr($vip['interface'], "lo0")) {
|
395
|
$vipbackup[] = $vip;
|
396
|
}
|
397
|
}
|
398
|
}
|
399
|
|
400
|
/* For vip section, first keep items sent from the master */
|
401
|
$config = array_merge_recursive_unique($config, $sections);
|
402
|
|
403
|
/* Remove local CP zones removed remote */
|
404
|
foreach ($cp_to_del as $zone) {
|
405
|
$cpzone = $zone;
|
406
|
$cpzoneid = $config['captiveportal'][$cpzone]['zoneid'];
|
407
|
unset($config['captiveportal'][$cpzone]['enable']);
|
408
|
captiveportal_configure_zone(
|
409
|
$config['captiveportal'][$cpzone]);
|
410
|
unset($config['captiveportal'][$cpzone]);
|
411
|
if (isset($config['voucher'][$cpzone])) {
|
412
|
unset($config['voucher'][$cpzone]);
|
413
|
}
|
414
|
}
|
415
|
|
416
|
/* Remove locally items removed remote */
|
417
|
foreach ($voucher as $zone => $item) {
|
418
|
/* No rolls on master, delete local ones */
|
419
|
if (!is_array($item['roll'])) {
|
420
|
unset($config['voucher'][$zone]['roll']);
|
421
|
}
|
422
|
}
|
423
|
|
424
|
$l_rolls = array();
|
425
|
if (is_array($config['voucher'])) {
|
426
|
foreach ($config['voucher'] as $zone => $item) {
|
427
|
if (!is_array($item['roll'])) {
|
428
|
continue;
|
429
|
}
|
430
|
foreach ($item['roll'] as $idx => $roll) {
|
431
|
/* Make it easy to find roll by # */
|
432
|
$l_rolls[$zone][$roll['number']] = $idx;
|
433
|
}
|
434
|
}
|
435
|
}
|
436
|
|
437
|
/*
|
438
|
* Process vouchers sent by primary node and:
|
439
|
* - Add new items
|
440
|
* - Update existing items based on 'lastsync' field
|
441
|
*/
|
442
|
foreach ($voucher as $zone => $item) {
|
443
|
if (!is_array($item['roll'])) {
|
444
|
continue;
|
445
|
}
|
446
|
foreach ($item['roll'] as $idx => $roll) {
|
447
|
if (!isset($l_rolls[$zone][$roll['number']])) {
|
448
|
$config['voucher'][$zone]['roll'][] =
|
449
|
$roll;
|
450
|
continue;
|
451
|
}
|
452
|
$l_roll_idx = $l_rolls[$zone][$roll['number']];
|
453
|
init_config_arr(array('voucher', $zone));
|
454
|
$l_vouchers = &$config['voucher'][$zone];
|
455
|
$l_roll = $l_vouchers['roll'][$l_roll_idx];
|
456
|
if (!isset($l_roll['lastsync'])) {
|
457
|
$l_roll['lastsync'] = 0;
|
458
|
}
|
459
|
|
460
|
if (isset($roll['lastsync']) &&
|
461
|
$roll['lastsync'] != $l_roll['lastsync']) {
|
462
|
$l_vouchers['roll'][$l_roll_idx] =
|
463
|
$roll;
|
464
|
unset($l_rolls[$zone][$roll['number']]);
|
465
|
}
|
466
|
}
|
467
|
}
|
468
|
|
469
|
/*
|
470
|
* At this point $l_rolls contains only items that are not
|
471
|
* present on primary node. They must be removed
|
472
|
*/
|
473
|
foreach ($l_rolls as $zone => $item) {
|
474
|
foreach ($item as $number => $idx) {
|
475
|
unset($config['voucher'][$zone][$idx]);
|
476
|
}
|
477
|
}
|
478
|
|
479
|
/*
|
480
|
* Then add ipalias and proxyarp types already defined
|
481
|
* on the backup
|
482
|
*/
|
483
|
if (is_array($vipbackup) && !empty($vipbackup)) {
|
484
|
if (!is_array($config['virtualip'])) {
|
485
|
$config['virtualip'] = array();
|
486
|
}
|
487
|
if (!is_array($config['virtualip']['vip'])) {
|
488
|
$config['virtualip']['vip'] = array();
|
489
|
}
|
490
|
foreach ($vipbackup as $vip) {
|
491
|
array_unshift($config['virtualip']['vip'], $vip);
|
492
|
}
|
493
|
}
|
494
|
|
495
|
/* Log what happened */
|
496
|
$mergedkeys = implode(", ", array_merge(array_keys($sections),
|
497
|
$syncd_full_sections));
|
498
|
write_config(sprintf(gettext(
|
499
|
"Merged in config (%s sections) from XMLRPC client."),
|
500
|
$mergedkeys));
|
501
|
|
502
|
/*
|
503
|
* The real work on handling the vips specially
|
504
|
* This is a copy of intefaces_vips_configure with addition of
|
505
|
* not reloading existing/not changed carps
|
506
|
*/
|
507
|
if (isset($sections['virtualip']) &&
|
508
|
is_array($config['virtualip']) &&
|
509
|
is_array($config['virtualip']['vip'])) {
|
510
|
$carp_setuped = false;
|
511
|
$anyproxyarp = false;
|
512
|
|
513
|
foreach ($config['virtualip']['vip'] as $vip) {
|
514
|
$key = "{$vip['interface']}_vip{$vip['vhid']}";
|
515
|
|
516
|
if ($vip['mode'] == "carp" &&
|
517
|
isset($oldvips[$key])) {
|
518
|
if ($oldvips[$key]['content'] ==
|
519
|
$vip['password'] .
|
520
|
$vip['advskew'] .
|
521
|
$vip['subnet'] .
|
522
|
$vip['subnet_bits'] .
|
523
|
$vip['advbase'] &&
|
524
|
does_vip_exist($vip)) {
|
525
|
unset($oldvips[$key]);
|
526
|
/*
|
527
|
* Skip reconfiguring this vips
|
528
|
* since nothing has changed.
|
529
|
*/
|
530
|
continue;
|
531
|
}
|
532
|
|
533
|
} elseif ($vip['mode'] == "ipalias" &&
|
534
|
(substr($vip['interface'], 0, 4) == '_vip'
|
535
|
|| strstr($vip['interface'], "lo0")) &&
|
536
|
isset($oldvips[$vip['subnet']])) {
|
537
|
$key = $vip['subnet'];
|
538
|
if ($oldvips[$key]['content'] ==
|
539
|
$vip['interface'] .
|
540
|
$vip['subnet'] .
|
541
|
$vip['subnet_bits'] &&
|
542
|
does_vip_exist($vip)) {
|
543
|
unset($oldvips[$key]);
|
544
|
/*
|
545
|
* Skip reconfiguring this vips
|
546
|
* since nothing has changed.
|
547
|
*/
|
548
|
continue;
|
549
|
}
|
550
|
unset($oldvips[$key]);
|
551
|
}
|
552
|
|
553
|
switch ($vip['mode']) {
|
554
|
case "proxyarp":
|
555
|
$anyproxyarp = true;
|
556
|
break;
|
557
|
case "ipalias":
|
558
|
interface_ipalias_configure($vip);
|
559
|
break;
|
560
|
case "carp":
|
561
|
$carp_setuped = true;
|
562
|
interface_carp_configure($vip);
|
563
|
break;
|
564
|
}
|
565
|
}
|
566
|
|
567
|
/* Cleanup remaining old carps */
|
568
|
foreach ($oldvips as $oldvipar) {
|
569
|
$oldvipif = get_real_interface(
|
570
|
$oldvipar['interface']);
|
571
|
|
572
|
if (empty($oldvipif)) {
|
573
|
continue;
|
574
|
}
|
575
|
|
576
|
if (is_ipaddrv6($oldvipar['subnet'])) {
|
577
|
mwexec("/sbin/ifconfig " .
|
578
|
escapeshellarg($oldvipif) .
|
579
|
" inet6 " .
|
580
|
escapeshellarg($oldvipar['subnet']) .
|
581
|
" delete");
|
582
|
} else {
|
583
|
pfSense_interface_deladdress($oldvipif,
|
584
|
$oldvipar['subnet']);
|
585
|
}
|
586
|
}
|
587
|
if ($carp_setuped == true) {
|
588
|
interfaces_sync_setup();
|
589
|
}
|
590
|
if ($anyproxyarp == true) {
|
591
|
interface_proxyarp_configure();
|
592
|
}
|
593
|
}
|
594
|
|
595
|
if ($old_ipsec_enabled !== ipsec_enabled()) {
|
596
|
vpn_ipsec_configure();
|
597
|
}
|
598
|
|
599
|
unset($old_config);
|
600
|
|
601
|
local_sync_accounts($u2add, $u2del, $g2add, $g2del);
|
602
|
$this->filter_configure(false);
|
603
|
|
604
|
return true;
|
605
|
}
|
606
|
|
607
|
/**
|
608
|
* Merge items into installedpackages config section
|
609
|
*
|
610
|
* @param array $section
|
611
|
*
|
612
|
* @return bool
|
613
|
*/
|
614
|
public function merge_installedpackages_section($section) {
|
615
|
$this->auth();
|
616
|
|
617
|
global $config;
|
618
|
|
619
|
if ($this->loop_detected) {
|
620
|
log_error("Disallowing CARP sync loop");
|
621
|
return true;
|
622
|
}
|
623
|
|
624
|
$config['installedpackages'] = array_merge(
|
625
|
$config['installedpackages'], $section);
|
626
|
$mergedkeys = implode(", ", array_keys($section));
|
627
|
write_config(sprintf(gettext(
|
628
|
"Merged in config (%s sections) from XMLRPC client."),
|
629
|
$mergedkeys));
|
630
|
|
631
|
return true;
|
632
|
}
|
633
|
|
634
|
/**
|
635
|
* Merge items into config
|
636
|
*
|
637
|
* @param array $section
|
638
|
*
|
639
|
* @return bool
|
640
|
*/
|
641
|
public function merge_config_section($section) {
|
642
|
$this->auth();
|
643
|
|
644
|
global $config;
|
645
|
|
646
|
if ($this->loop_detected) {
|
647
|
log_error("Disallowing CARP sync loop");
|
648
|
return true;
|
649
|
}
|
650
|
|
651
|
$config_new = $this->array_overlay($config, $section);
|
652
|
$config = $config_new;
|
653
|
$mergedkeys = implode(", ", array_keys($section));
|
654
|
write_config(sprintf(gettext(
|
655
|
"Merged in config (%s sections) from XMLRPC client."),
|
656
|
$mergedkeys));
|
657
|
|
658
|
return true;
|
659
|
}
|
660
|
|
661
|
/**
|
662
|
* Wrapper for filter_configure()
|
663
|
*
|
664
|
* @return bool
|
665
|
*/
|
666
|
public function filter_configure($reset_accounts = true) {
|
667
|
$this->auth();
|
668
|
|
669
|
global $g, $config;
|
670
|
|
671
|
filter_configure();
|
672
|
system_routing_configure();
|
673
|
setup_gateways_monitor();
|
674
|
relayd_configure();
|
675
|
require_once("openvpn.inc");
|
676
|
openvpn_resync_all();
|
677
|
|
678
|
/*
|
679
|
* The DNS Resolver and the DNS Forwarder may both be active so
|
680
|
* long as * they are running on different ports.
|
681
|
* See ticket #5882
|
682
|
*/
|
683
|
if (isset($config['dnsmasq']['enable'])) {
|
684
|
/* Configure dnsmasq but tell it NOT to restart DHCP */
|
685
|
services_dnsmasq_configure(false);
|
686
|
} else {
|
687
|
/* kill any running dnsmasq instance */
|
688
|
if (isvalidpid("{$g['varrun_path']}/dnsmasq.pid")) {
|
689
|
sigkillbypid("{$g['varrun_path']}/dnsmasq.pid",
|
690
|
"TERM");
|
691
|
}
|
692
|
}
|
693
|
if (isset($config['unbound']['enable'])) {
|
694
|
/* Configure unbound but tell it NOT to restart DHCP */
|
695
|
services_unbound_configure(false);
|
696
|
} else {
|
697
|
/* kill any running Unbound instance */
|
698
|
if (isvalidpid("{$g['varrun_path']}/unbound.pid")) {
|
699
|
sigkillbypid("{$g['varrun_path']}/unbound.pid",
|
700
|
"TERM");
|
701
|
}
|
702
|
}
|
703
|
|
704
|
/*
|
705
|
* Call this separately since the above are manually set to
|
706
|
* skip the DHCP restart they normally perform.
|
707
|
* This avoids restarting dhcpd twice as described on
|
708
|
* ticket #3797
|
709
|
*/
|
710
|
services_dhcpd_configure();
|
711
|
|
712
|
if ($reset_accounts) {
|
713
|
local_reset_accounts();
|
714
|
}
|
715
|
|
716
|
captiveportal_configure();
|
717
|
|
718
|
return true;
|
719
|
}
|
720
|
|
721
|
/**
|
722
|
* Wrapper for configuring CARP interfaces
|
723
|
*
|
724
|
* @return bool
|
725
|
*/
|
726
|
public function interfaces_carp_configure() {
|
727
|
$this->auth();
|
728
|
|
729
|
if ($this->loop_detected) {
|
730
|
log_error("Disallowing CARP sync loop");
|
731
|
return true;
|
732
|
}
|
733
|
|
734
|
interfaces_vips_configure();
|
735
|
|
736
|
return true;
|
737
|
}
|
738
|
|
739
|
/**
|
740
|
* Wrapper for rc.reboot
|
741
|
*
|
742
|
* @return bool
|
743
|
*/
|
744
|
public function reboot() {
|
745
|
$this->auth();
|
746
|
|
747
|
mwexec_bg("/etc/rc.reboot");
|
748
|
|
749
|
return true;
|
750
|
}
|
751
|
}
|
752
|
|
753
|
// run script untill its done and can 'unlock' the xmlrpc.lock, this prevents hanging php-fpm / webgui
|
754
|
ignore_user_abort(true);
|
755
|
set_time_limit(0);
|
756
|
|
757
|
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
|
758
|
|
759
|
XML_RPC2_Backend::setBackend('php');
|
760
|
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
|
761
|
|
762
|
$options = array(
|
763
|
'prefix' => 'pfsense.',
|
764
|
'encoding' => 'utf-8',
|
765
|
'autoDocument' => false,
|
766
|
);
|
767
|
|
768
|
$server = XML_RPC2_Server::create(new pfsense_xmlrpc_server(), $options);
|
769
|
$server->handleCall();
|
770
|
|
771
|
unlock($xmlrpclockkey);
|
772
|
|
773
|
?>
|