Project

General

Profile

Download (4.62 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * config.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally part of m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
if (!function_exists('is_platform_booting')) {
29
	require_once('globals.inc');
30
}
31

    
32
/* do not load this file twice. */
33
//if (in_array("/etc/inc/config.inc", get_included_files()))
34
//	return;
35

    
36
/* include globals from notices.inc /utility/XML parser files */
37
require_once("notices.inc");
38
require_once("util.inc");
39
require_once("Net/IPv6.php");
40
require_once('config.lib.inc');
41
require_once("xmlparse.inc");
42
require_once("crypt.inc");
43

    
44
// Set the memory limit to 128M on i386.  When someone has something like 500+ tunnels
45
// the parser needs quite a bit of ram.   Do not remove this line unless you
46
// know what you are doing.  If in doubt, check with dev@ _/FIRST/_!
47
if (!$ARCH) {
48
	$ARCH = php_uname("m");
49
}
50

    
51
// Set memory limit to 512M on amd64.
52
ini_set("memory_limit", get_php_default_memory($ARCH) . 'M');
53

    
54
/* if /debugging exists, lets set $debugging
55
   so we can output more information */
56
if (file_exists("/debugging")) {
57
	$debugging = true;
58
	$g['debug'] = true;
59
}
60

    
61
if (is_platform_booting() && is_cli_sapi() &&
62
    !file_exists(g_get('cf_conf_path') . "/config.xml")) {
63
	echo ".";
64
	/* find the device where config.xml resides and write out an fstab */
65
	unset($cfgdevice);
66
	echo ".";
67
	/* check if there's already an fstab (NFS booting?) */
68
	if (!file_exists("{$g['etc_path']}/fstab")) {
69
		echo ".";
70
		/* probe kernel known disks until we find one with config.xml */
71
		$disks = explode(" ", get_single_sysctl("kern.disks"));
72
		foreach ($disks as $mountdisk) {
73
			/* skip mfs mounted filesystems */
74
			if (strstr($mountdisk, "md")) {
75
				continue;
76
			}
77
			if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
78
				if (file_exists("{$g['cf_conf_path']}/config.xml")) {
79
					/* found it */
80
					$cfgdevice = $mountdisk;
81
					$cfgpartition = $cfgdevice . "a";
82
					$cfgfstype = "ufs";
83
					printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
84
				}
85

    
86
				mwexec("/sbin/umount -f {$g['cf_path']}");
87

    
88
				if ($cfgdevice) {
89
					break;
90
				}
91
			}
92
			if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
93
				if (is_platform_booting()) {
94
					echo ".";
95
				}
96
				if (file_exists("{$g['cf_conf_path']}/config.xml")) {
97
					/* found it */
98
					$cfgdevice = $mountdisk;
99
					$cfgpartition = $cfgdevice . "d";
100
					$cfgfstype = "ufs";
101
					printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
102
				}
103

    
104
				mwexec("/sbin/umount -f {$g['cf_path']}");
105

    
106
				if ($cfgdevice) {
107
					break;
108
				}
109
			}
110
		}
111
		echo ".";
112
		if (!$cfgdevice && !config_read_file(true)) {
113
			log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
114
			if (restore_backup('/conf.default/config.xml')) {
115
				config_read_file();
116
			}
117
		}
118

    
119
		/* write out an fstab */
120

    
121
		$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
122
		$fstab .= "proc /proc procfs rw 0 0\n";
123
		file_put_contents("{$g['etc_path']}/fstab", $fstab);
124
	}
125
	echo ".";
126
	/* mount all filesystems */
127
	mwexec("/sbin/mount -a");
128
	echo ".";
129
}
130

    
131
config_read_file(true, true);
132

    
133
/* set timezone */
134
$timezone = config_get_path('system/timezone');
135
if (isset($timezone) &&
136
    !empty($timezone)) {
137
	// noop
138
} elseif (isset($g['default_timezone']) && !empty(g_get('default_timezone'))) {
139
	$timezone = g_get('default_timezone');
140
} else {
141
	$timezone = "Etc/UTC";
142
}
143
date_default_timezone_set("$timezone");
144

    
145
/* override php memory limit */
146
$php_memory_limit = config_get_path('system/php_memory_limit', 0);
147
if (($php_memory_limit >= 128) && ($php_memory_limit <= get_php_max_memory())) {
148
    ini_set("memory_limit", config_get_path('system/php_memory_limit') . "M");
149
}
150

    
151
if ($config_parsed == true) {
152
	/* process packager manager custom rules */
153
	if (is_dir("/usr/local/pkg/parse_config")) {
154
		run_plugins("/usr/local/pkg/parse_config/");
155
	}
156
}
157

    
158
?>
(10-10/61)