Project

General

Profile

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