Project

General

Profile

Download (18.8 KB) Statistics
| Branch: | Tag: | Revision:
1 50d49018 Colin Smith
<?php
2
/*
3 c5d81585 Renato Botelho
 * xmlrpc.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 880ed461 jim-p
 * Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2005 Colin Smith
8
 * All rights reserved.
9 191cb31d Stephen Beaver
 *
10 b12ea3fb Renato Botelho
 * 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 191cb31d Stephen Beaver
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 191cb31d Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * 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 191cb31d Stephen Beaver
 */
22 50d49018 Colin Smith
23 6b07c15a Matthew Grooms
##|+PRIV
24
##|*IDENT=page-xmlrpclibrary
25 5230f468 jim-p
##|*NAME=XMLRPC Library
26 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'XMLRPC Library' page.
27
##|*MATCH=xmlrpc.php*
28
##|-PRIV
29
30 c81ef6e2 Phil Davis
require_once("config.inc");
31
require_once("functions.inc");
32 f81e7cc4 Renato Botelho
require_once("auth.inc");
33 f6339216 jim-p
require_once("filter.inc");
34 c81ef6e2 Phil Davis
require_once("ipsec.inc");
35
require_once("vpn.inc");
36 7cab6335 Renato Botelho
require_once("captiveportal.inc");
37 c81ef6e2 Phil Davis
require_once("shaper.inc");
38 f81e7cc4 Renato Botelho
require_once("XML/RPC2/Server.php");
39 50d49018 Colin Smith
40 f81e7cc4 Renato Botelho
class pfsense_xmlrpc_server {
41 c87f4b70 Ermal
42 f81e7cc4 Renato Botelho
	private $loop_detected = false;
43
	private $remote_addr;
44 c87f4b70 Ermal
45 dc5f639f PiBa-NL
	private function auth() {
46 f81e7cc4 Renato Botelho
		global $config;
47 dc5f639f PiBa-NL
		$username = $_SERVER['PHP_AUTH_USER'];
48
		$password = $_SERVER['PHP_AUTH_PW'];
49 8da3de34 Colin Smith
50 fb1234ab Renato Botelho
		$login_ok = false;
51 f81e7cc4 Renato Botelho
		if (!empty($username) && !empty($password)) {
52
			$attributes = array();
53
			$authcfg = auth_get_authserver(
54
			    $config['system']['webgui']['authmode']);
55 c3638879 Scott Ullrich
56 f81e7cc4 Renato Botelho
			if (authenticate_user($username, $password,
57
			    $authcfg, $attributes) ||
58
			    authenticate_user($username, $password)) {
59 fb1234ab Renato Botelho
				$login_ok = true;
60 f81e7cc4 Renato Botelho
			}
61
		}
62 3dd2a278 Scott Ullrich
63 fb1234ab Renato Botelho
		if (!$login_ok) {
64 ecfd1ddc jim-p
			log_auth(sprintf(gettext("webConfigurator authentication error for user '%1\$s' from: %2\$s"),
65
			    $username,
66
			    $this->remote_addr));
67 137f46d8 Ermal
68 fb1234ab Renato Botelho
			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 3dd2a278 Scott Ullrich
	}
93 f81e7cc4 Renato Botelho
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 962f215d Phil Davis
	}
108 c3638879 Scott Ullrich
109 f81e7cc4 Renato Botelho
	public function __construct() {
110
		global $config;
111 c3638879 Scott Ullrich
112 f82f991c Renato Botelho
		$this->remote_addr = $_SERVER['REMOTE_ADDR'];
113 137f46d8 Ermal
114 f81e7cc4 Renato Botelho
		/* grab sync to ip if enabled */
115
		if (isset($config['hasync']['synchronizetoip']) &&
116 8d44b2cb PiBa-NL
		    $config['hasync']['synchronizetoip'] == $this->remote_addr) {
117 f81e7cc4 Renato Botelho
			$this->loop_detected = true;
118
		}
119 3dd2a278 Scott Ullrich
	}
120 137f46d8 Ermal
121 f81e7cc4 Renato Botelho
	/**
122
	 * Get host version information
123
	 *
124
	 * @return array
125
	 */
126 dc5f639f PiBa-NL
	public function host_firmware_version($dummy = 1) {
127
		$this->auth();
128 f81e7cc4 Renato Botelho
		return host_firmware_version();
129
	}
130 21dc3a7d Colin Smith
131 f81e7cc4 Renato Botelho
	/**
132
	 * Executes a PHP block of code
133
	 *
134
	 * @param string $code
135
	 *
136
	 * @return bool
137
	 */
138 dc5f639f PiBa-NL
	public function exec_php($code) {
139
		$this->auth();
140 137f46d8 Ermal
141 f81e7cc4 Renato Botelho
		eval($code);
142
		if ($toreturn) {
143
			return $toreturn;
144
		}
145 c87f4b70 Ermal
146 f81e7cc4 Renato Botelho
		return true;
147 3dd2a278 Scott Ullrich
	}
148 137f46d8 Ermal
149 f81e7cc4 Renato Botelho
	/**
150
	 * Executes shell commands
151
	 *
152
	 * @param string $code
153
	 *
154
	 * @return bool
155
	 */
156 dc5f639f PiBa-NL
	public function exec_shell($code) {
157
		$this->auth();
158 50d49018 Colin Smith
159 f81e7cc4 Renato Botelho
		mwexec($code);
160
		return true;
161
	}
162 21dc3a7d Colin Smith
163 f81e7cc4 Renato Botelho
	/**
164
	 * Backup chosen config sections
165
	 *
166
	 * @param array $section
167
	 *
168
	 * @return array
169
	 */
170 dc5f639f PiBa-NL
	public function backup_config_section($section) {
171
		$this->auth();
172 137f46d8 Ermal
173 f81e7cc4 Renato Botelho
		global $config;
174 d026178f Renato Botelho
175 f81e7cc4 Renato Botelho
		return array_intersect_key($config, array_flip($section));
176 fb0eb20b Ermal
	}
177 c87f4b70 Ermal
178 f81e7cc4 Renato Botelho
	/**
179
	 * Restore defined config section into local config
180
	 *
181
	 * @param array $sections
182
	 *
183
	 * @return bool
184
	 */
185 dc5f639f PiBa-NL
	public function restore_config_section($sections) {
186
		$this->auth();
187 f81e7cc4 Renato Botelho
188 7cab6335 Renato Botelho
		global $config, $cpzone, $cpzoneid;
189 1b99e1e5 jim-p
190 f81e7cc4 Renato Botelho
		$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 1b99e1e5 jim-p
		}
231
232 7cab6335 Renato Botelho
		/* 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 d3cc158c jim-p
		/* 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 79f7bc7f Renato Botelho
				}
277
			}
278 d3cc158c jim-p
			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 79f7bc7f Renato Botelho
				}
286
			}
287 d3cc158c jim-p
			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 79f7bc7f Renato Botelho
				}
314
			}
315 d3cc158c jim-p
			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 79f7bc7f Renato Botelho
				}
323
			}
324 d3cc158c jim-p
			unset($sections['system']['user'], $u2keep, $u2del_idx);
325 79f7bc7f Renato Botelho
		}
326
327 b8963db6 Renato Botelho
		$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 f81e7cc4 Renato Botelho
		$vipbackup = array();
362
		$oldvips = array();
363
		if (isset($sections['virtualip']) &&
364
		    is_array($config['virtualip']['vip'])) {
365
			foreach ($config['virtualip']['vip'] as $vip) {
366 c14781e3 Renato Botelho
				if ($vip['mode'] == "carp") {
367 f81e7cc4 Renato Botelho
					$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 51611440 Ermal
					$vipbackup[] = $vip;
396 c14781e3 Renato Botelho
				}
397 51611440 Ermal
			}
398 19b5c3e7 Ermal
		}
399 f51d4f98 Ermal
400 f81e7cc4 Renato Botelho
		/* For vip section, first keep items sent from the master */
401
		$config = array_merge_recursive_unique($config, $sections);
402 51611440 Ermal
403 7cab6335 Renato Botelho
		/* 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 b8963db6 Renato Botelho
		/* 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 ea0dd417 jim-p
				init_config_arr(array('voucher', $zone));
454 b8963db6 Renato Botelho
				$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 f81e7cc4 Renato Botelho
		/*
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 962f215d Phil Davis
		}
494 51611440 Ermal
495 f81e7cc4 Renato Botelho
		/* Log what happened */
496 8cb29dac doktornotor
		$mergedkeys = implode(", ", array_merge(array_keys($sections),
497 f81e7cc4 Renato Botelho
		    $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 19ed1624 Ermal
					}
532 5fda51cd jim-p
533 f81e7cc4 Renato Botelho
				} elseif ($vip['mode'] == "ipalias" &&
534 5fda51cd jim-p
				    (substr($vip['interface'], 0, 4) == '_vip'
535
				    || strstr($vip['interface'], "lo0")) &&
536 f81e7cc4 Renato Botelho
				    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 2708a5cf Ermal
					}
550 f81e7cc4 Renato Botelho
					unset($oldvips[$key]);
551 2708a5cf Ermal
				}
552 51611440 Ermal
553 f81e7cc4 Renato Botelho
				switch ($vip['mode']) {
554 962f215d Phil Davis
				case "proxyarp":
555
					$anyproxyarp = true;
556
					break;
557
				case "ipalias":
558
					interface_ipalias_configure($vip);
559
					break;
560
				case "carp":
561 f81e7cc4 Renato Botelho
					$carp_setuped = true;
562 962f215d Phil Davis
					interface_carp_configure($vip);
563
					break;
564 f81e7cc4 Renato Botelho
				}
565 51611440 Ermal
			}
566 f81e7cc4 Renato Botelho
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 962f215d Phil Davis
				if (is_ipaddrv6($oldvipar['subnet'])) {
577 f81e7cc4 Renato Botelho
					 mwexec("/sbin/ifconfig " .
578
					     escapeshellarg($oldvipif) .
579
					     " inet6 " .
580
					     escapeshellarg($oldvipar['subnet']) .
581
					     " delete");
582 962f215d Phil Davis
				} else {
583 f81e7cc4 Renato Botelho
					pfSense_interface_deladdress($oldvipif,
584
					    $oldvipar['subnet']);
585 962f215d Phil Davis
				}
586 e3cffd6c Ermal LUÇI
			}
587 f81e7cc4 Renato Botelho
			if ($carp_setuped == true) {
588
				interfaces_sync_setup();
589
			}
590
			if ($anyproxyarp == true) {
591
				interface_proxyarp_configure();
592
			}
593 51611440 Ermal
		}
594 f81e7cc4 Renato Botelho
595
		if ($old_ipsec_enabled !== ipsec_enabled()) {
596
			vpn_ipsec_configure();
597 962f215d Phil Davis
		}
598 137f46d8 Ermal
599 f81e7cc4 Renato Botelho
		unset($old_config);
600
601 79f7bc7f Renato Botelho
		local_sync_accounts($u2add, $u2del, $g2add, $g2del);
602 7fead243 Renato Botelho
		$this->filter_configure(false);
603 79f7bc7f Renato Botelho
604 f81e7cc4 Renato Botelho
		return true;
605 962f215d Phil Davis
	}
606 d026178f Renato Botelho
607 f81e7cc4 Renato Botelho
	/**
608
	 * Merge items into installedpackages config section
609
	 *
610
	 * @param array $section
611
	 *
612
	 * @return bool
613
	 */
614 dc5f639f PiBa-NL
	public function merge_installedpackages_section($section) {
615
		$this->auth();
616 d026178f Renato Botelho
617 f81e7cc4 Renato Botelho
		global $config;
618 50d49018 Colin Smith
619 f81e7cc4 Renato Botelho
		if ($this->loop_detected) {
620
			log_error("Disallowing CARP sync loop");
621
			return true;
622
		}
623 82ae5cfc Scott Ullrich
624 f81e7cc4 Renato Botelho
		$config['installedpackages'] = array_merge(
625
		    $config['installedpackages'], $section);
626 8cb29dac doktornotor
		$mergedkeys = implode(", ", array_keys($section));
627 f81e7cc4 Renato Botelho
		write_config(sprintf(gettext(
628
		    "Merged in config (%s sections) from XMLRPC client."),
629
		    $mergedkeys));
630 137f46d8 Ermal
631 f81e7cc4 Renato Botelho
		return true;
632 fb0eb20b Ermal
	}
633 c87f4b70 Ermal
634 f81e7cc4 Renato Botelho
	/**
635
	 * Merge items into config
636
	 *
637
	 * @param array $section
638
	 *
639
	 * @return bool
640
	 */
641 dc5f639f PiBa-NL
	public function merge_config_section($section) {
642
		$this->auth();
643 137f46d8 Ermal
644 f81e7cc4 Renato Botelho
		global $config;
645 82ae5cfc Scott Ullrich
646 f81e7cc4 Renato Botelho
		if ($this->loop_detected) {
647
			log_error("Disallowing CARP sync loop");
648
			return true;
649
		}
650 dc1cd85d Scott Ullrich
651 f81e7cc4 Renato Botelho
		$config_new = $this->array_overlay($config, $section);
652
		$config = $config_new;
653 8cb29dac doktornotor
		$mergedkeys = implode(", ", array_keys($section));
654 f81e7cc4 Renato Botelho
		write_config(sprintf(gettext(
655
		    "Merged in config (%s sections) from XMLRPC client."),
656
		    $mergedkeys));
657 c87f4b70 Ermal
658 f81e7cc4 Renato Botelho
		return true;
659 fb0eb20b Ermal
	}
660 c87f4b70 Ermal
661 f81e7cc4 Renato Botelho
	/**
662
	 * Wrapper for filter_configure()
663
	 *
664
	 * @return bool
665 57b5da70 jim-p
	 */
666 79f7bc7f Renato Botelho
	public function filter_configure($reset_accounts = true) {
667 dc5f639f PiBa-NL
		$this->auth();
668 f81e7cc4 Renato Botelho
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 57b5da70 jim-p
		}
693 f81e7cc4 Renato Botelho
		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 57b5da70 jim-p
		}
703 137f46d8 Ermal
704 f81e7cc4 Renato Botelho
		/*
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 137f46d8 Ermal
712 79f7bc7f Renato Botelho
		if ($reset_accounts) {
713
			local_reset_accounts();
714
		}
715 c87f4b70 Ermal
716 7cab6335 Renato Botelho
		captiveportal_configure();
717
718 f81e7cc4 Renato Botelho
		return true;
719 3dd2a278 Scott Ullrich
	}
720 137f46d8 Ermal
721 f81e7cc4 Renato Botelho
	/**
722
	 * Wrapper for configuring CARP interfaces
723
	 *
724
	 * @return bool
725
	 */
726 dc5f639f PiBa-NL
	public function interfaces_carp_configure() {
727
		$this->auth();
728 efe7562e Scott Ullrich
729 f81e7cc4 Renato Botelho
		if ($this->loop_detected) {
730
			log_error("Disallowing CARP sync loop");
731
			return true;
732
		}
733 0567899d Ermal
734 f81e7cc4 Renato Botelho
		interfaces_vips_configure();
735 e501de37 Ermal
736 f81e7cc4 Renato Botelho
		return true;
737
	}
738 e501de37 Ermal
739 f81e7cc4 Renato Botelho
	/**
740
	 * Wrapper for rc.reboot
741
	 *
742
	 * @return bool
743
	 */
744 dc5f639f PiBa-NL
	public function reboot() {
745
		$this->auth();
746 e501de37 Ermal
747 f81e7cc4 Renato Botelho
		mwexec_bg("/etc/rc.reboot");
748 137f46d8 Ermal
749 f81e7cc4 Renato Botelho
		return true;
750 3dd2a278 Scott Ullrich
	}
751 d9064267 Colin Smith
}
752
753 179377b0 robjarsen
// run script untill its done and can 'unlock' the xmlrpc.lock, this prevents hanging php-fpm / webgui
754
ignore_user_abort(true);
755 8239af2d PiBa-NL
set_time_limit(0);
756
757 67d78c87 Ermal
$xmlrpclockkey = lock('xmlrpc', LOCK_EX);
758
759 f81e7cc4 Renato Botelho
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 4f78ae1d Renato Botelho
	'autoDocument' => false,
766 50d49018 Colin Smith
);
767 b298dd06 Scott Ullrich
768 f81e7cc4 Renato Botelho
$server = XML_RPC2_Server::create(new pfsense_xmlrpc_server(), $options);
769
$server->handleCall();
770 67d78c87 Ermal
771 f81e7cc4 Renato Botelho
unlock($xmlrpclockkey);
772 0b581a8a Scott Ullrich
773 de63649b Rafael Lucas
?>