Project

General

Profile

Download (37.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/****h* pfSense/pfsense-utils
3
 * NAME
4
 *   pfsense-utils.inc - Utilities specific to pfSense
5
 * DESCRIPTION
6
 *   This include contains various pfSense specific functions.
7
 * HISTORY
8
 *   $Id$
9
 ******
10
 *
11
 * Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
12
 * All rights reserved.
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 * this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 * notice, this list of conditions and the following disclaimer in the
21
 * documentation and/or other materials provided with the distribution.
22
 *
23
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
 * RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 */
35

    
36
function get_tmp_file() {
37
	return "/tmp/tmp-" . time();
38
}
39

    
40
/****f* pfsense-utils/get_dns_servers
41
 * NAME
42
 *   get_dns_servres - get system dns servers
43
 * INPUTS
44
 *   $dns_servers - an array of the dns servers
45
 * RESULT
46
 *   null
47
 ******/
48
function get_dns_servers() {
49
	$dns_servers = array();
50
	$dns = `cat /etc/resolv.conf`;
51
	$dns_s = split("\n", $dns);
52
	foreach($dns_s as $dns) {
53
		if (preg_match("/nameserver (.*)/", $dns, $matches))
54
			$dns_servers[] = $matches[1];		
55
	}
56
	return $dns_servers;
57
}
58

    
59
 	
60
/****f* pfsense-utils/log_error
61
* NAME
62
*   log_error  - Sends a string to syslog.
63
* INPUTS
64
*   $error     - string containing the syslog message.
65
* RESULT
66
*   null
67
******/
68
function log_error($error) {
69
    $page = $_SERVER['PHP_SELF'];
70
    syslog(LOG_WARNING, "$page: $error");
71
    return;
72
}
73

    
74
/****f* pfsense-utils/get_interface_mac_address
75
 * NAME
76
 *   get_interface_mac_address - Return a interfaces mac address
77
 * INPUTS
78
 *   $interface	- interface to obtain mac address from
79
 * RESULT
80
 *   $mac - the mac address of the interface
81
 ******/
82
function get_interface_mac_address($interface) {
83
    $mac = exec("ifconfig {$interface} | awk '/ether/ {print $2}'");
84
    return trim($mac);
85
}
86

    
87
/****f* pfsense-utils/return_dir_as_array
88
 * NAME
89
 *   return_dir_as_array - Return a directory's contents as an array.
90
 * INPUTS
91
 *   $dir	- string containing the path to the desired directory.
92
 * RESULT
93
 *   $dir_array - array containing the directory's contents. This array will be empty if the path specified is invalid.
94
 ******/
95
function return_dir_as_array($dir) {
96
    $dir_array = array();
97
    if (is_dir($dir)) {
98
	if ($dh = opendir($dir)) {
99
	    while (($file = readdir($dh)) !== false) {
100
		$canadd = 0;
101
		if($file == ".") $canadd = 1;
102
		if($file == "..") $canadd = 1;
103
		if($canadd == 0)
104
		    array_push($dir_array, $file);
105
	    }
106
	    closedir($dh);
107
	}
108
    }
109
    return $dir_array;
110
}
111

    
112
/****f* pfsense-utils/enable_hardware_offloading
113
 * NAME
114
 *   enable_hardware_offloading - Enable a NIC's supported hardware features.
115
 * INPUTS
116
 *   $interface	- string containing the physical interface to work on.
117
 * RESULT
118
 *   null
119
 * NOTES
120
 *   This function only supports the fxp driver's loadable microcode.
121
 ******/
122
function enable_hardware_offloading($interface) {
123
    global $g, $config;
124
    if(isset($config['system']['do_not_use_nic_microcode']))
125
	return;
126
    if($g['booting']) {
127
	/* translate wan, lan, opt -> real interface if needed */
128
	$int = filter_translate_type_to_real_interface($interface);
129
	if($int <> "") $interface = $int;
130
	$options = strtolower(`/sbin/ifconfig {$interface} | grep options`);
131
	$supported_ints = array('fxp');
132
	foreach($supported_ints as $int) {
133
		if(stristr($interface,$int) != false) {
134
			mwexec("/sbin/ifconfig {$interface} link0");
135
		}
136
	}
137
	if(stristr($options, "txcsum") == true)
138
	    mwexec("/sbin/ifconfig {$interface} txcsum 2>/dev/null");
139
	if(stristr($options, "rxcsum") == true)    
140
	    mwexec("/sbin/ifconfig {$interface} rxcsum 2>/dev/null");    
141
	if(stristr($options, "polling") == true)
142
	    mwexec("/sbin/ifconfig {$interface} polling 2>/dev/null");
143
    }
144
    return;
145
}
146

    
147
/****f* pfsense-utils/setup_microcode
148
 * NAME
149
 *   enumerates all interfaces and calls enable_hardware_offloading which
150
 *   enables a NIC's supported hardware features.
151
 * INPUTS
152
 *   
153
 * RESULT
154
 *   null
155
 * NOTES
156
 *   This function only supports the fxp driver's loadable microcode.
157
 ******/
158
function setup_microcode() {
159
   global $config;
160
    $ifdescrs = array('wan', 'lan');
161
    for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
162
	$ifdescrs['opt' . $j] = "opt" . $j;
163
    }
164
    foreach($ifdescrs as $if)
165
	enable_hardware_offloading($if);
166
}
167

    
168
/****f* pfsense-utils/return_filename_as_array
169
 * NAME
170
 *   return_filename_as_array - Return a file's contents as an array.
171
 * INPUTS
172
 *   $filename	- string containing the path to the desired file.
173
 *   $strip	- array of characters to strip - default is '#'.
174
 * RESULT
175
 *   $file	- array containing the file's contents.
176
 * NOTES
177
 *   This function strips lines starting with '#' and leading/trailing whitespace by default.
178
 ******/
179
function return_filename_as_array($filename, $strip = array('#')) {
180
    if(file_exists($filename)) $file = file($filename);
181
    if(is_array($file)) {
182
	foreach($file as $line) $line = trim($line);
183
        foreach($strip as $tostrip) $file = preg_grep("/^{$tostrip}/", $file, PREG_GREP_INVERT);
184
    }
185
    return $file;
186
}
187

    
188
/****f* pfsense-utils/file_put_contents
189
 * NAME
190
 *   file_put_contents - Wrapper for file_put_contents if it doesn't exist
191
 * RESULT
192
 *   none
193
 ******/
194
if(!function_exists("file_put_contents")) {
195
    function file_put_contents($filename, $data) {
196
	$fd = fopen($filename,"w");
197
	fwrite($fd, $data);
198
	fclose($fd);
199
    }
200
}
201

    
202
/****f* pfsense-utils/get_carp_status
203
 * NAME
204
 *   get_carp_status - Return whether CARP is enabled or disabled.
205
 * RESULT
206
 *   boolean	- true if CARP is enabled, false if otherwise.
207
 ******/
208
function get_carp_status() {
209
    /* grab the current status of carp */
210
    $status = `/sbin/sysctl net.inet.carp.allow | cut -d" " -f2`;
211
    if(intval($status) == "0") return false;
212
    return true;
213
}
214

    
215
/****f* pfsense-utils/is_carp_defined
216
 * NAME
217
 *   is_carp_defined - Return whether CARP is detected in the kernel.
218
 * RESULT
219
 *   boolean	- true if CARP is detected, false otherwise.
220
 ******/
221
function is_carp_defined() {
222
    /* is carp compiled into the kernel and userland? */
223
    $command = "/sbin/sysctl -a | grep carp";
224
    $fd = popen($command . " 2>&1 ", "r");
225
    if(!$fd) {
226
	log_error("Warning, could not execute command {$command}");
227
	return 0;
228
    }
229
    while(!feof($fd)) {
230
	$tmp .= fread($fd,49);
231
    }
232
    fclose($fd);
233

    
234
    if($tmp == "")
235
	return false;
236
    else
237
	return true;
238
}
239

    
240
/****f* pfsense-utils/find_number_of_created_carp_interfaces
241
 * NAME
242
 *   find_number_of_created_carp_interfaces - Return the number of CARP interfaces.
243
 * RESULT
244
 *   $tmp	- Number of currently created CARP interfaces.
245
 ******/
246
function find_number_of_created_carp_interfaces() {
247
    $command = "/sbin/ifconfig | /usr/bin/grep \"carp*:\" | /usr/bin/wc -l";
248
    $fd = popen($command . " 2>&1 ", "r");
249
    if(!$fd) {
250
	log_error("Warning, could not execute command {$command}");
251
	return 0;
252
    }
253
    while(!feof($fd)) {
254
	$tmp .= fread($fd,49);
255
    }
256
    fclose($fd);
257
    $tmp = intval($tmp);
258
    return $tmp;
259
}
260

    
261
/****f* pfsense-utils/link_ip_to_carp_interface
262
 * NAME
263
 *   link_ip_to_carp_interface - Find where a CARP interface links to.
264
 * INPUTS
265
 *   $ip
266
 * RESULT
267
 *   $carp_ints
268
 ******/
269
function link_ip_to_carp_interface($ip) {
270
	global $config;
271
	if($ip == "") return;
272

    
273
	$ifdescrs = array('wan', 'lan');
274
	for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
275
		$ifdescrs['opt' . $j] = "opt" . $j;
276
	}
277

    
278
	$ft = split("\.", $ip);
279
	$ft_ip = $ft[0] . "." . $ft[1] . "." . $ft[2] . ".";
280

    
281
	$carp_ints = "";
282
	$num_carp_ints = find_number_of_created_carp_interfaces();
283
	foreach ($ifdescrs as $ifdescr => $ifname) {
284
		for($x=0; $x<$num_carp_ints; $x++) {
285
			$carp_int = "carp{$x}";
286
			$carp_ip = find_interface_ip($carp_int);
287
			$carp_ft = split("\.", $carp_ip);
288
			$carp_ft_ip = $carp_ft[0] . "." . $carp_ft[1] . "." . $carp_ft[2] . ".";
289
			$result = does_interface_exist($carp_int);
290
			if($result <> true) break;
291
			if($ft_ip == $carp_ft_ip)
292
			if(stristr($carp_ints,$carp_int) == false)
293
			$carp_ints .= " " . $carp_int;
294
		}
295
	}
296
	return $carp_ints;
297
}
298

    
299
/****f* pfsense-utils/exec_command
300
 * NAME
301
 *   exec_command - Execute a command and return a string of the result.
302
 * INPUTS
303
 *   $command	- String of the command to be executed.
304
 * RESULT
305
 *   String containing the command's result.
306
 * NOTES
307
 *   This function returns the command's stdout and stderr.
308
 ******/
309
function exec_command($command) {
310
    $output = array();
311
    exec($command . ' 2>&1 ', $output);
312
    return(implode("\n", $output));
313
}
314

    
315
/****f* interfaces/is_jumbo_capable
316
 * NAME
317
 *   is_jumbo_capable - Test if interface is jumbo frame capable.  Useful for determining VLAN capability.
318
 * INPUTS
319
 *   $int             - string containing interface name
320
 * RESULT
321
 *   boolean          - true or false
322
 ******/
323
function is_jumbo_capable($int) {
324
	/* Per:
325
	 * http://www.freebsd.org/cgi/man.cgi?query=vlan&manpath=FreeBSD+6.0-current&format=html
326
	 * Only the following drivers support large frames
327
	 */
328
	$capable = array("bfe", "dc", "de", "fxp", "hme", "rl", "sis", "ste",
329
		"tl", "tx", "xl", "em");
330
	
331
	$int_family = preg_split("/[0-9]+/", $int);
332

    
333
	if (in_array($int_family[0], $capable))
334
		return true;
335
	else
336
		return false;
337
}
338

    
339
/*
340
 * does_interface_exist($interface): return true or false if a interface is detected.
341
 */
342
function does_interface_exist($interface) {
343
    $ints = exec_command("/sbin/ifconfig -l");
344
    if(stristr($ints, $interface) !== false)
345
	return true;
346
    else
347
	return false;
348
}
349

    
350
/*
351
 * convert_ip_to_network_format($ip, $subnet): converts an ip address to network form
352
 */
353
function convert_ip_to_network_format($ip, $subnet) {
354
    $ipsplit = split('[.]', $ip);
355
    $string = $ipsplit[0] . "." . $ipsplit[1] . "." . $ipsplit[2] . ".0/" . $subnet;
356
    return $string;
357
}
358

    
359
/*
360
 * find_interface_ip($interface): return the interface ip (first found)
361
 */
362
function find_interface_ip($interface) {
363
    if(does_interface_exist($interface) == false) return;
364
    $ip = exec_command("/sbin/ifconfig {$interface} | /usr/bin/grep -w \"inet\" | /usr/bin/cut -d\" \" -f 2");
365
    $ip = str_replace("\n","",$ip);
366
    return $ip;
367
}
368

    
369
function guess_interface_from_ip($ipaddress) {
370
    $ints = `/sbin/ifconfig -l`;
371
    $ints_split = split(" ", $ints);
372
    $ip_subnet_split = split("\.", $ipaddress);
373
    $ip_subnet = $ip_subnet_split[0] . "." . $ip_subnet_split[1] . "." . $ip_subnet_split[2] . ".";
374
    foreach($ints_split as $int) {
375
        $ip = find_interface_ip($int);
376
        $ip_split = split("\.", $ip);
377
        $ip_tocheck = $ip_split[0] . "." . $ip_split[1] . "." . $ip_split[2] . ".";
378
        if(stristr($ip_tocheck, $ip_subnet) != false) return $int;
379
    }
380
}
381

    
382
function filter_opt_interface_to_real($opt) {
383
    global $config;
384
    return $config['interfaces'][$opt]['if'];
385
}
386

    
387
function filter_get_opt_interface_descr($opt) {
388
    global $config;
389
    return $config['interfaces'][$opt]['descr'];
390
}
391

    
392
function get_friendly_interface_list_as_array() {
393
    global $config;
394
    $ints = array();
395
    $ifdescrs = array('wan', 'lan');
396
    for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
397
		$ifdescrs['opt' . $j] = "opt" . $j;
398
    }
399
    $ifdescrs = get_interface_list();
400
    foreach ($ifdescrs as $ifdescr => $ifname) {
401
		array_push($ints,$ifdescr);
402
    }
403
    return $ints;
404
}
405

    
406
/*
407
 * find_ip_interface($ip): return the interface where an ip is defined
408
 */
409
function find_ip_interface($ip) {
410
    global $config;
411
    $ifdescrs = array('wan', 'lan');
412
    for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
413
	$ifdescrs['opt' . $j] = "opt" . $j;
414
    }
415
    foreach ($ifdescrs as $ifdescr => $ifname) {
416
	$int = filter_translate_type_to_real_interface($ifname);
417
	$ifconfig = exec_command("/sbin/ifconfig {$int}");
418
	if(stristr($ifconfig,$ip) <> false)
419
	    return $int;
420
    }
421
    return false;
422
}
423

    
424
/*
425
 *  filter_translate_type_to_real_interface($interface): returns the real interface name
426
 *                                                       for a friendly interface.  ie: wan
427
 */
428
function filter_translate_type_to_real_interface($interface) {
429
    global $config;
430
    if($config['interfaces'][$interface]['if'] <> "") {
431
	return $config['interfaces'][$interface]['if'];
432
    } else {
433
	return $interface;
434
    }
435
}
436

    
437
/*
438
 * get_carp_interface_status($carpinterface): returns the status of a carp ip
439
 */
440
function get_carp_interface_status($carpinterface) {
441
	/* basically cache the contents of ifconfig statement
442
	to speed up this routine */
443
	global $carp_query;
444
	if($carp_query == "")
445
	$carp_query = split("\n", `/sbin/ifconfig | /usr/bin/grep carp`);
446
	$found_interface = 0;
447
	foreach($carp_query as $int) {
448
		if($found_interface == 1) {
449
			if(stristr($int, "MASTER") == true) return "MASTER";
450
			if(stristr($int, "BACKUP") == true) return "BACKUP";
451
			if(stristr($int, "INIT") == true) return "INIT";
452
			return false;
453
		}
454
		if(stristr($int, $carpinterface) == true)
455
		$found_interface=1;
456
	}
457
	return;
458
}
459

    
460
/*
461
 * get_pfsync_interface_status($pfsyncinterface): returns the status of a pfsync
462
 */
463
function get_pfsync_interface_status($pfsyncinterface) {
464
    $result = does_interface_exist($pfsyncinterface);
465
    if($result <> true) return;
466
    $status = exec_command("/sbin/ifconfig {$pfsyncinterface} | /usr/bin/grep \"pfsync:\" | /usr/bin/cut -d\" \" -f5");
467
    return $status;
468
}
469

    
470
/*
471
 * find_carp_interface($ip): return the carp interface where an ip is defined
472
 */
473
function find_carp_interface($ip) {
474
    global $find_carp_ifconfig;
475
    if($find_carp_ifconfig == "") {
476
	$find_carp_ifconfig = array();
477
	$num_carp_ints = find_number_of_created_carp_interfaces();
478
	for($x=0; $x<$num_carp_ints; $x++) {
479
	    $find_carp_ifconfig[$x] = exec_command("/sbin/ifconfig carp{$x}");
480
	}
481
    }
482
    $carps = 0;
483
    foreach($find_carp_ifconfig as $fci) {
484
	if(stristr($fci, $ip) == true)
485
	    return "carp{$carps}";
486
	$carps++;
487
    }
488
}
489

    
490
/*
491
 * find_number_of_created_bridges(): returns the number of currently created bridges
492
 */
493
function find_number_of_created_bridges() {
494
    return `/sbin/ifconfig | grep \"bridge[0-999]\:" | wc -l`;
495
}
496

    
497
/*
498
 * add_rule_to_anchor($anchor, $rule): adds the specified rule to an anchor
499
 */
500
function add_rule_to_anchor($anchor, $rule, $label) {
501
    mwexec("echo " . $rule . " | /sbin/pfctl -a " . $anchor . ":" . $label . " -f -");
502
}
503

    
504
/*
505
 * remove_text_from_file
506
 * remove $text from file $file
507
 */
508
function remove_text_from_file($file, $text) {
509
    global $fd_log;
510
    fwrite($fd_log, "Adding needed text items:\n");
511
    $filecontents = exec_command_and_return_text("cat " . $file);
512
    $textTMP = str_replace($text, "", $filecontents);
513
    $text .= $textTMP;
514
    fwrite($fd_log, $text . "\n");
515
    $fd = fopen($file, "w");
516
    fwrite($fd, $text);
517
    fclose($fd);
518
}
519

    
520
/*
521
 * add_text_to_file($file, $text): adds $text to $file.
522
 * replaces the text if it already exists.
523
 */
524
function add_text_to_file($file, $text) {
525
	if(file_exists($file) and is_writable($file)) {
526
		$filecontents = file($file);
527
		$filecontents[] = $text;
528
		$tmpfile = get_tmp_file();
529
		$fout = fopen($tmpfile, "w");
530
		foreach($filecontents as $line) {
531
			fwrite($fout, rtrim($line) . "\n");
532
		}
533
		fclose($fout);
534
		rename($tmpfile, $file);
535
		return true;
536
	} else {
537
		return false;
538
	}
539
}
540

    
541
/*
542
 *   after_sync_bump_adv_skew(): create skew values by 1S
543
 */
544
function after_sync_bump_adv_skew() {
545
	global $config, $g;
546
	$processed_skew = 1;
547
	$a_vip = &$config['virtualip']['vip'];
548
	foreach ($a_vip as $vipent) {
549
		if($vipent['advskew'] <> "") {
550
			$processed_skew = 1;
551
			$vipent['advskew'] = $vipent['advskew']+1;
552
		}
553
	}
554
	if($processed_skew == 1)
555
		write_config("After synch increase advertising skew");
556
}
557

    
558
/*
559
 * get_filename_from_url($url): converts a url to its filename.
560
 */
561
function get_filename_from_url($url) {
562
	return basename($url);
563
}
564

    
565
/*
566
 *   update_output_window: update bottom textarea dynamically.
567
 */
568
function update_output_window($text) {
569
    $log = ereg_replace("\n", "\\n", $text);
570
    echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"" . $log . "\";</script>";
571
}
572

    
573
/*
574
 *   get_dir: return an array of $dir
575
 */
576
function get_dir($dir) {
577
    $dir_array = array();
578
    $d = dir($dir);
579
    while (false !== ($entry = $d->read())) {
580
	array_push($dir_array, $entry);
581
    }
582
    $d->close();
583
    return $dir_array;
584
}
585

    
586
/*
587
 *   update_output_window: update top textarea dynamically.
588
 */
589
function update_status($status) {
590
    echo "\n<script language=\"JavaScript\">document.forms[0].status.value=\"" . $status . "\";</script>";
591
}
592

    
593
/*
594
 *   exec_command_and_return_text_array: execute command and return output
595
 */
596
function exec_command_and_return_text_array($command) {
597
	$fd = popen($command . " 2>&1 ", "r");
598
	while(!feof($fd)) {
599
		$tmp .= fread($fd,49);
600
	}
601
	fclose($fd);
602
	$temp_array = split("\n", $tmp);
603
	return $temp_array;
604
}
605

    
606
/*
607
 *   exec_command_and_return_text: execute command and return output
608
 */
609
function exec_command_and_return_text($command) {
610
    return exec_command($command);
611
}
612

    
613
/*
614
 *   exec_command_and_return_text: execute command and update output window dynamically
615
 */
616
function execute_command_return_output($command) {
617
    global $fd_log;
618
    $fd = popen($command . " 2>&1 ", "r");
619
    echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"\";</script>";
620
    $counter = 0;
621
    $counter2 = 0;
622
    while(!feof($fd)) {
623
	$tmp = fread($fd, 50);
624
	$tmp1 = ereg_replace("\n","\\n", $tmp);
625
	$text = ereg_replace("\"","'", $tmp1);
626
	if($lasttext == "..") {
627
	    $text = "";
628
	    $lasttext = "";
629
	    $counter=$counter-2;
630
	} else {
631
	    $lasttext .= $text;
632
	}
633
	if($counter > 51) {
634
	    $counter = 0;
635
	    $extrabreak = "\\n";
636
	} else {
637
	    $extrabreak = "";
638
	    $counter++;
639
	}
640
	if($counter2 > 600) {
641
	    echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = \"\";</script>";
642
	    $counter2 = 0;
643
	} else
644
	    $counter2++;
645
	echo "\n<script language=\"JavaScript\">this.document.forms[0].output.value = this.document.forms[0].output.value + \"" . $text . $extrabreak .  "\"; f('output'); </script>";
646
    }
647
    fclose($fd);
648
}
649

    
650
/*
651
 * convert_friendly_interface_to_real_interface_name($interface): convert WAN to FXP0
652
 */
653
function convert_friendly_interface_to_real_interface_name($interface) {
654
    global $config;
655
    $lc_interface = strtolower($interface);
656
    if($lc_interface == "lan") return $config['interfaces']['lan']['if'];
657
    if($lc_interface == "wan") return $config['interfaces']['wan']['if'];
658
    $ifdescrs = array();
659
    for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
660
	$ifdescrs['opt' . $j] = "opt" . $j;
661
    foreach ($ifdescrs as $ifdescr => $ifname) {
662
	if(strtolower($ifname) == $lc_interface)
663
	    return $config['interfaces'][$ifname]['if'];
664
	if(strtolower($config['interfaces'][$ifname]['descr']) == $lc_interface)
665
	    return $config['interfaces'][$ifname]['if'];
666
    }
667
    return $interface;
668
}
669

    
670
/*
671
 * convert_real_interface_to_friendly_interface_name($interface): convert fxp0 -> wan, etc.
672
 */
673
function convert_real_interface_to_friendly_interface_name($interface) {
674
    global $config;
675
    $ifdescrs = array('wan', 'lan');
676
    for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
677
	$ifdescrs['opt' . $j] = "opt" . $j;
678
    foreach ($ifdescrs as $ifdescr => $ifname) {
679
	$int = filter_translate_type_to_real_interface($ifname);
680
	if($ifname == $interface) return $ifname;
681
	if($int == $interface) return $ifname;
682
    }
683
    return $interface;
684
}
685

    
686
/*
687
 * update_progress_bar($percent): updates the javascript driven progress bar.
688
 */
689
function update_progress_bar($percent) {
690
    if($percent > 100) $percent = 1;
691
    echo "\n<script type=\"text/javascript\" language=\"javascript\">";
692
    echo "\ndocument.progressbar.style.width='" . $percent . "%';";
693
    echo "\n</script>";
694
}
695

    
696
/*
697
 * gather_altq_queue_stats():  gather alq queue stats and return an array that
698
 *                             is queuename|qlength|measured_packets
699
 *                             NOTE: this command takes 5 seconds to run
700
 */
701
function gather_altq_queue_stats($dont_return_root_queues) {
702
    mwexec("/usr/bin/killall -9 pfctl");
703
    $stats = `/sbin/pfctl -vvsq & /bin/sleep 5;/usr/bin/killall pfctl 2>/dev/null`;
704
    $stats_array = split("\n", $stats);
705
    $queue_stats = array();
706
    foreach ($stats_array as $stats_line) {
707
        if (preg_match_all("/queue\s+(\w+)\s+/",$stats_line,$match_array))
708
            $queue_name = $match_array[1][0];
709
        if (preg_match_all("/measured:\s+.*packets\/s\,\s(.*)\s+\]/",$stats_line,$match_array))
710
            $speed = $match_array[1][0];
711
        if (preg_match_all("/borrows:\s+(.*)/",$stats_line,$match_array))
712
            $borrows = $match_array[1][0];
713
        if (preg_match_all("/suspends:\s+(.*)/",$stats_line,$match_array))
714
            $suspends = $match_array[1][0];
715
        if (preg_match_all("/dropped pkts:\s+(.*)/",$stats_line,$match_array))
716
            $drops = $match_array[1][0];
717
        if (preg_match_all("/measured:\s+(.*)packets/",$stats_line,$match_array)) {
718
            $measured = $match_array[1][0];
719
	    if($dont_return_root_queues == true)
720
		if(stristr($queue_name,"root_") == false)
721
		    array_push($queue_stats, "{$queue_name}|{$speed}|{$measured}|{$borrows}|{$suspends}|{$drops}");
722
        }
723
    }
724
    return $queue_stats;
725
}
726

    
727
/*
728
 * reverse_strrchr($haystack, $needle):  Return everything in $haystack up to the *last* instance of $needle.
729
 *					 Useful for finding paths and stripping file extensions.
730
 */
731
function reverse_strrchr($haystack, $needle)
732
{
733
               return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) +1 ) : false;
734
}
735

    
736
/*
737
 *  backup_config_section($section): returns as an xml file string of
738
 *                                   the configuration section
739
 */
740
function backup_config_section($section) {
741
    global $config;
742
    $new_section = &$config[$section];
743
    /* generate configuration XML */
744
    $xmlconfig = dump_xml_config($new_section, $section);
745
    $xmlconfig = str_replace("<?xml version=\"1.0\"?>", "", $xmlconfig);
746
    return $xmlconfig;
747
}
748

    
749
/*
750
 *  backup_config_ts_scheduler(): returns the traffic shaper scheduler for backup
751
 */
752
function backup_config_ts_scheduler() {
753
    global $config;
754
    $new_section = &$config['syste']['schedulertype'];
755
    /* generate configuration XML */
756
    $xmlconfig = dump_xml_config($new_section, $section);
757
    $xmlconfig = str_replace("<?xml version=\"1.0\"?>", "", $xmlconfig);
758
    return $xmlconfig;
759
}
760

    
761
/*
762
 *  backup_config_section($section): returns as an xml file string of
763
 *                                   the configuration section
764
 */
765
function backup_vip_config_section() {
766
    global $config;
767
    $new_section = &$config['virtualip'];
768
    foreach($new_section['vip'] as $section) {
769
	if($section['mode'] == "proxyarp") {
770
		unset($section);		
771
	}
772
	if($section['advskew'] <> "") {
773
		$section_val = intval($section['advskew']);
774
		$section_val=$section_val+100;
775
		if($section_val > 255)
776
			$section_val = 255;
777
		$section['advskew'] = $section_val;
778
	}
779
	$temp['vip'][] = $section;
780
    }
781
    
782
    /* generate configuration XML */
783
    $xmlconfig = dump_xml_config($temp, "virtualip");
784
    $xmlconfig = str_replace("<?xml version=\"1.0\"?>", "", $xmlconfig);
785
    return $xmlconfig;
786
}
787

    
788
/*
789
 *  restore_config_section($section, new_contents): restore a configuration section,
790
 *                                                  and write the configuration out
791
 *                                                  to disk/cf.
792
 */
793
function restore_config_section($section, $new_contents) {
794
    global $config;
795
    conf_mount_rw();
796
    $fout = fopen("{$g['tmp_path']}/tmpxml","w");
797
    fwrite($fout, $new_contents);
798
    fclose($fout);
799
    $section_xml = parse_xml_config($g['tmp_path'] . "/tmpxml", $section);
800
    $config[$section] = &$section_xml;
801
    unlink($g['tmp_path'] . "/tmpxml");
802
    write_config("Restored {$section} of config file (maybe from CARP partner)");
803
    conf_mount_ro();
804
    return;
805
}
806

    
807
/*
808
 * http_post($server, $port, $url, $vars): does an http post to a web server
809
 *                                         posting the vars array.
810
 * written by nf@bigpond.net.au
811
 */
812
function http_post($server, $port, $url, $vars) {
813
    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)";
814
    $urlencoded = "";
815
    while (list($key,$value) = each($vars))
816
	$urlencoded.= urlencode($key) . "=" . urlencode($value) . "&";
817
    $urlencoded = substr($urlencoded,0,-1);
818

    
819
    $content_length = strlen($urlencoded);
820

    
821
    $headers = "POST $url HTTP/1.1
822
Accept: */*
823
Accept-Language: en-au
824
Content-Type: application/x-www-form-urlencoded
825
User-Agent: $user_agent
826
Host: $server
827
Connection: Keep-Alive
828
Cache-Control: no-cache
829
Content-Length: $content_length
830

    
831
";
832

    
833
    $fp = fsockopen($server, $port, $errno, $errstr);
834
    if (!$fp) {
835
	return false;
836
    }
837

    
838
    fputs($fp, $headers);
839
    fputs($fp, $urlencoded);
840

    
841
    $ret = "";
842
    while (!feof($fp))
843
	$ret.= fgets($fp, 1024);
844

    
845
    fclose($fp);
846

    
847
    return $ret;
848

    
849
}
850

    
851
/*
852
 *  php_check_syntax($code_tocheck, $errormessage): checks $code_to_check for errors
853
 */
854
if (!function_exists('php_check_syntax')){
855
   function php_check_syntax($code_to_check, &$errormessage){
856
	return false;
857
        $fout = fopen("/tmp/codetocheck.php","w");
858
        $code = $_POST['content'];
859
        $code = str_replace("<?php", "", $code);
860
        $code = str_replace("?>", "", $code);
861
        fwrite($fout, "<?php\n\n");
862
        fwrite($fout, $code_to_check);
863
        fwrite($fout, "\n\n?>\n");
864
        fclose($fout);
865
        $command = "/usr/local/bin/php -l /tmp/codetocheck.php";
866
        $output = exec_command($command);
867
        if (stristr($output, "Errors parsing") == false) {
868
            echo "false\n";
869
            $errormessage = '';
870
            return(false);
871
        } else {
872
            $errormessage = $output;
873
            return(true);
874
        }
875
    }
876
}
877

    
878
/*
879
 *  php_check_filename_syntax($filename, $errormessage): checks the file $filename for errors
880
 */
881
if (!function_exists('php_check_syntax')){
882
   function php_check_syntax($code_to_check, &$errormessage){
883
	return false;
884
        $command = "/usr/local/bin/php -l " . $code_to_check;
885
        $output = exec_command($command);
886
        if (stristr($output, "Errors parsing") == false) {
887
            echo "false\n";
888
            $errormessage = '';
889
            return(false);
890
        } else {
891
            $errormessage = $output;
892
            return(true);
893
        }
894
    }
895
}
896

    
897
/*
898
 * rmdir_recursive($path,$follow_links=false)
899
 * Recursively remove a directory tree (rm -rf path)
900
 * This is for directories _only_
901
 */
902
function rmdir_recursive($path,$follow_links=false) {
903
	$to_do = glob($path);
904
	if(!is_array($to_do)) $to_do = array($to_do);
905
	foreach($to_do as $workingdir) { // Handle wildcards by foreaching.
906
		if(file_exists($workingdir)) {
907
			if(is_dir($workingdir)) {
908
				$dir = opendir($workingdir);
909
				while ($entry = readdir($dir)) {
910
					if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry")))
911
						unlink("$workingdir/$entry");
912
					elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..')
913
						rmdir_recursive("$workingdir/$entry");
914
				}
915
				closedir($dir);
916
				rmdir($workingdir);
917
			} elseif (is_file($workingdir)) {
918
				unlink($workingdir);
919
			}
920
               	}
921
	}
922
	return;
923
}
924

    
925
/*
926
 *     get_memory()
927
 *     returns an array listing the amount of
928
 *     memory installed in the hardware
929
 *     [0]real and [1]available
930
 */
931
function get_memory() {
932
        $mem = `cat /var/log/dmesg.boot | grep memory`;
933
        if (preg_match_all("/real memory  = .* \((.*) MB/", $mem, $matches))
934
                $real = $matches[1];
935
        if (preg_match_all("/avail memory = .* \((.*) MB/", $mem, $matches))
936
                $avail = $matches[1];
937
        return array($real[0],$avail[0]);
938
}
939

    
940

    
941
/*
942
 *    safe_mkdir($path, $mode = 0755)
943
 *    create directory if it doesn't already exist and isn't a file!
944
 */
945
function safe_mkdir($path, $mode=0755) {
946
	global $g;
947

    
948
	/* cdrom is ro. */
949
	if($g['platform'] == "cdrom")
950
		return false;
951
	
952
	if (!is_file($path) && !is_dir($path))
953
		return mkdir($path, $mode);
954
	else
955
		return false;
956
}
957

    
958
/*
959
 * make_dirs($path, $mode = 0755)
960
 * create directory tree recursively (mkdir -p)
961
 */
962
function make_dirs($path, $mode = 0755) {
963
	/* is dir already created? */
964
	if(is_dir($path)) return;
965
	/* create directory in question */
966
	$to_create = explode("/", $path);
967
	foreach($to_create as $tc) 
968
	    if(!is_dir($tc))
969
		safe_mkdir($path, $mode);
970
}
971

    
972
/*
973
 * check_firmware_version(): Check whether the current firmware installed is the most recently released.
974
 */
975
function check_firmware_version($tocheck = "all", $return_php = true) {
976
        global $g, $config;
977
	$xmlrpc_base_url = $g['xmlrpcbaseurl'];
978
        $xmlrpc_path = $g['xmlrpcpath'];
979
	$rawparams = array("firmware" => array("version" => trim(file_get_contents('/etc/version'))),
980
			"kernel"   => array("version" => trim(file_get_contents('/etc/version_kernel'))),
981
			"base"     => array("version" => trim(file_get_contents('/etc/version_base'))),
982
			"platform" => trim(file_get_contents('/etc/platform'))
983
		);
984
	if($tocheck == "all") {
985
		$params = $rawparams;
986
	} else {
987
		foreach($tocheck as $check) {
988
			$params['check'] = $rawparams['check'];
989
			$params['platform'] = $rawparams['platform'];
990
		}
991
	}
992
	if($config['system']['firmware']['branch']) {
993
		$params['branch'] = $config['system']['firmware']['branch'];
994
	}
995
	$xmlparams = php_value_to_xmlrpc($params);
996
        $msg = new XML_RPC_Message('pfsense.get_firmware_version', array($xmlparams));
997
        $cli = new XML_RPC_Client($xmlrpc_path, $xmlrpc_base_url);
998
	//$cli->setDebug(1);
999
	$resp = $cli->send($msg, 10);
1000
	if(!$resp or $resp->faultCode()) {
1001
		$raw_versions = false;
1002
	} else {
1003
		$raw_versions = XML_RPC_decode($resp->value());
1004
		$raw_versions["current"] = $params;
1005
	}
1006
	return $raw_versions;
1007
}
1008

    
1009
function get_disk_info() {
1010
        exec("df -h | grep -w '/' | awk '{ print $2, $3, $4, $5 }'", $diskout);
1011
        return explode(' ', $diskout[0]);
1012
        // $size, $used, $avail, $cap
1013
}
1014

    
1015
/****f* pfsense-utils/display_top_tabs
1016
 * NAME
1017
 *   display_top_tabs - display tabs with rounded edges
1018
 * INPUTS
1019
 *   $text	- array of tabs
1020
 * RESULT
1021
 *   null
1022
 ******/
1023
    function display_top_tabs($tab_array) {
1024
	    echo "<table cellpadding='0' cellspacing='0'>\n";
1025
	    echo " <tr height='1'>\n";
1026
	    $tabscounter = 0;
1027
	    foreach ($tab_array as $ta) {
1028
		    if($ta[1] == true) {
1029
			    echo "  <td bgcolor='#EEEEEE' onClick=\"document.location='{$ta[2]}'\"><div id='tabactive'></div></td>\n";
1030
		    } else {
1031
			    echo "  <td bgcolor='#777777' onClick=\"document.location='{$ta[2]}'\"><div id='tabdeactive{$tabscounter}'></div></td>\n";
1032
		    }
1033
		    $tabscounter++;
1034
	    }
1035
	    echo "</tr>\n<tr>\n";
1036
	    foreach ($tab_array as $ta) {
1037
		    if($ta[1] == true) {
1038
			    echo "  <td bgcolor='#EEEEEE' onClick=\"document.location='{$ta[2]}'\"><B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
1039
			    echo "&nbsp;&nbsp;&nbsp;";
1040
			    echo "<font size='-12'>&nbsp;</td>\n";
1041
		    } else {
1042
			    echo "  <td bgcolor='#777777' onClick=\"document.location='{$ta[2]}'\"><B>&nbsp;&nbsp;&nbsp;<a href='{$ta[2]}'>";
1043
			    echo "<font color='white'>{$ta[0]}</a>&nbsp;&nbsp;&nbsp;";
1044
			    echo "<font size='-12'>&nbsp;</td>\n";
1045
		    }
1046
	    }
1047
	    echo "</tr>\n<tr height='5px'>\n";
1048
	    foreach ($tab_array as $ta) {
1049
		    if($ta[1] == true) {
1050
			    echo "  <td bgcolor='#EEEEEE' onClick=\"document.location='{$ta[2]}'\"></td>\n";
1051
		    } else {
1052
			    echo "  <td bgcolor='#777777' onClick=\"document.location='{$ta[2]}'\"></td>\n";
1053
		    }
1054
		    $tabscounter++;
1055
	    }
1056
	    echo " </tr>\n";
1057
	    echo "</table>\n";
1058
	    
1059
	    echo "<script type=\"text/javascript\">";
1060
	    echo "NiftyCheck();\n";
1061
	    echo "Rounded(\"div#tabactive\",\"top\",\"#FFF\",\"#EEEEEE\",\"smooth\");\n";
1062
	    for($x=0; $x<$tabscounter; $x++) 
1063
		    echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"#FFF\",\"#777777\",\"smooth\");\n";
1064
	    echo "</script>";
1065
    }
1066

    
1067

    
1068
/****f* pfsense-utils/display_topbar
1069
 * NAME
1070
 *   display_topbar - top a table off with rounded edges
1071
 * INPUTS
1072
 *   $text	- (optional) Text to include in bar
1073
 * RESULT
1074
 *   null
1075
 ******/
1076
function display_topbar($text = "", $bg_color="#990000", $replace_color="#FFFFFF", $rounding_style="smooth") {	    
1077
	echo "     <table width='100%' cellpadding='0' cellspacing='0'>\n";
1078
	echo "       <tr height='1'>\n";
1079
	echo "         <td width='100%' valign='top' color='{$bg_color}' bgcolor='{$bg_color}'>";
1080
	echo "		<div id='topbar'></div></td>\n";
1081
	echo "       </tr>\n";
1082
	echo "       <tr height='1'>\n";
1083
	if ($text != "")
1084
		echo "         <td height='1' class='listtopic'>{$text}</td>\n";
1085
	else
1086
		echo "         <td height='1' class='listtopic'></td>\n";
1087
	echo "       </tr>\n";
1088
	echo "     </table>";
1089
	echo "<script type=\"text/javascript\">";
1090
	echo "NiftyCheck();\n";
1091
	echo "Rounded(\"div#topbar\",\"top\",\"{$replace_color}\",\"{$bg_color}\",\"{$rounding_style}\");\n";
1092
	echo "</script>";
1093
}
1094

    
1095
/****f* pfsense-utils/generate_random_mac_address
1096
 * NAME
1097
 *   generate_random_mac - generates a random mac address
1098
 * INPUTS
1099
 *   none
1100
 * RESULT
1101
 *   $mac - a random mac address
1102
 ******/
1103
function generate_random_mac_address() {
1104
	$mac = "00:a0:8e";
1105
	for($x=0; $x<3; $x++) 
1106
	    $mac .= ":" . dechex(rand(16, 255));
1107

    
1108
	return $mac;
1109
}
1110

    
1111
/****f* pfsense-utils/strncpy
1112
 * NAME
1113
 *   strncpy - copy strings
1114
 * INPUTS
1115
 *   &$dst, $src, $length
1116
 * RESULT
1117
 *   none
1118
 ******/
1119
function strncpy(&$dst, $src, $length) {
1120
	if (strlen($src) > $length) {
1121
		$dst = substr($src, 0, $length);
1122
	} else {
1123
		$dst = $src;
1124
	}
1125
}
1126

    
1127
/****f* pfsense-utils/reload_interfaces_sync
1128
 * NAME
1129
 *   reload_interfaces - reload all interfaces
1130
 * INPUTS
1131
 *   none
1132
 * RESULT
1133
 *   none
1134
 ******/
1135
function reload_interfaces_sync() {
1136
	global $config, $g;
1137
	
1138
	if(file_exists("{$g['tmp_path']}/config.cache"))
1139
		unlink("{$g['tmp_path']}/config.cache");
1140
	
1141
	/* parse config.xml again */
1142
	$config = parse_config(true);
1143
	
1144
	/* set up LAN interface */
1145
	interfaces_lan_configure();
1146

    
1147
	/* set up WAN interface */
1148
	interfaces_wan_configure();
1149

    
1150
	/* set up Optional interfaces */
1151
	interfaces_optional_configure();
1152
        
1153
	/* set up static routes */
1154
	system_routing_configure();
1155
	
1156
	/* enable routing */
1157
	system_routing_enable();
1158
}
1159

    
1160
/****f* pfsense-utils/reload_all
1161
 * NAME
1162
 *   reload_all - triggers a reload of all settings
1163
 *   * INPUTS
1164
 *   none
1165
 * RESULT
1166
 *   none
1167
 ******/
1168
function reload_all() {
1169
	touch("/tmp/reload_all");
1170
}
1171

    
1172
/****f* pfsense-utils/reload_interfaces
1173
 * NAME
1174
 *   reload_interfaces - triggers a reload of all interfaces
1175
 * INPUTS
1176
 *   none
1177
 * RESULT
1178
 *   none
1179
 ******/
1180
function reload_interfaces() {
1181
	touch("/tmp/reload_interfaces");
1182
}
1183

    
1184
/****f* pfsense-utils/sync_webgui_passwords
1185
 * NAME
1186
 *   sync_webgui_passwords - syncs webgui and ssh passwords
1187
 * INPUTS
1188
 *   none
1189
 * RESULT
1190
 *   none
1191
 ******/
1192
function sync_webgui_passwords() {
1193
	global $config, $g;
1194
	conf_mount_rw();
1195
	$fd = fopen("{$g['varrun_path']}/htpasswd", "w");
1196
	if (!$fd) {
1197
		printf("Error: cannot open htpasswd in system_password_configure().\n");
1198
		return 1;
1199
	}
1200
	/* set admin account */
1201
	$username = $config['system']['username'];
1202
	
1203
	/* set defined user account */
1204
	if($username <> "admin") {
1205
		$username = $config['system']['username'];
1206
		fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
1207
	} else {
1208
		fwrite($fd, $username . ":" . $config['system']['password'] . "\n");	
1209
	}	
1210
	fclose($fd);
1211
	chmod("{$g['varrun_path']}/htpasswd", 0600);	
1212
	$crypted_pw = $config['system']['password'];
1213
	/* sync root */
1214
	$fd = popen("/usr/sbin/pw usermod -n root -H 0", "w");
1215
	fwrite($fd, $crypted_pw);
1216
	pclose($fd);
1217
	mwexec("/usr/sbin/pw usermod -n root -s /bin/sh");
1218
	/* sync admin */
1219
	$fd = popen("/usr/sbin/pw usermod -n admin -H 0", "w");
1220
	fwrite($fd, $crypted_pw);
1221
	pclose($fd);
1222
	mwexec("/usr/sbin/pw usermod -n admin -s /etc/rc.initial");
1223
	mwexec("/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd");
1224
	mwexec("/usr/sbin/pwd_mkdb /etc/master.passwd");
1225
	conf_mount_ro();
1226
}
1227

    
1228
/****f* pfsense-utils/reload_all_sync
1229
 * NAME
1230
 *   reload_all - reload all settings
1231
 *   * INPUTS
1232
 *   none
1233
 * RESULT
1234
 *   none
1235
 ******/
1236
function reload_all_sync() {
1237
	global $config, $g;
1238
	
1239
	if(file_exists("{$g['tmp_path']}/config.cache"))
1240
		unlink("{$g['tmp_path']}/config.cache");
1241
	
1242
	/* parse config.xml again */
1243
	$config = parse_config(true);
1244

    
1245
	/* set up our timezone */
1246
	system_timezone_configure();
1247

    
1248
	/* set up our hostname */
1249
	system_hostname_configure();
1250

    
1251
	/* make hosts file */
1252
	system_hosts_generate();
1253

    
1254
	/* generate resolv.conf */
1255
	system_resolvconf_generate();
1256

    
1257
	/* set up LAN interface */
1258
	interfaces_lan_configure();
1259

    
1260
	/* set up WAN interface */
1261
	interfaces_wan_configure();
1262

    
1263
	/* set up Optional interfaces */
1264
	interfaces_optional_configure();
1265
        
1266
	/* bring up carp interfaces */
1267
	interfaces_carp_configure();
1268
	
1269
	/* set up static routes */
1270
	system_routing_configure();
1271

    
1272
	/* enable routing */
1273
	system_routing_enable();
1274
	
1275
	/* ensure passwords are sync'd */
1276
	system_password_configure();
1277

    
1278
	/* start dnsmasq service */
1279
	services_dnsmasq_configure();
1280

    
1281
	/* start dyndns service */
1282
	services_dyndns_configure();
1283

    
1284
	/* start DHCP service */
1285
	services_dhcpd_configure();
1286

    
1287
	/* start the NTP client */
1288
	system_ntp_configure();
1289

    
1290
	/* start ftp proxy helpers if they are enabled */
1291
	system_start_ftp_helpers();
1292

    
1293
        /* reload the filter */
1294
	filter_configure();
1295
	
1296
	/* sync pw database */
1297
	conf_mount_rw();
1298
	mwexec("/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd");
1299
	conf_mount_ro();
1300
	
1301
}
1302

    
1303
?>
(12-12/24)