Project

General

Profile

Download (4.71 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-2022 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('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
// Set the memory limit to 128M on i386.  When someone has something like 500+ tunnels
37
// the parser needs quite a bit of ram.   Do not remove this line unless you
38
// know what you are doing.  If in doubt, check with dev@ _/FIRST/_!
39
if (!isset($ARCH)) {
40
	$ARCH = php_uname("m");
41
}
42

    
43
// Set memory limit to 512M on amd64.
44
if ($ARCH == "amd64") {
45
	ini_set("memory_limit", "512M");
46
} else {
47
	ini_set("memory_limit", "128M");
48
}
49

    
50
/* include globals from notices.inc /utility/XML parser files */
51
require_once("notices.inc");
52
require_once("util.inc");
53
require_once("Net/IPv6.php");
54
require_once('config.lib.inc');
55
require_once("xmlparse.inc");
56
require_once("crypt.inc");
57

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

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

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

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

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

    
110
				if ($cfgdevice) {
111
					break;
112
				}
113
			}
114
		}
115
		echo ".";
116
		if (!$cfgdevice) {
117
			$last_backup = discover_last_backup();
118
			if ($last_backup) {
119
				log_error(gettext("No config.xml found, attempting last known config restore."));
120
				file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
121
				restore_backup("/cf/conf/backup/{$last_backup}");
122
			} else {
123
				log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
124
				restore_backup('/conf.default/config.xml');
125
			}
126
		}
127

    
128
		/* write out an fstab */
129

    
130
		$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
131
		$fstab .= "proc /proc procfs rw 0 0\n";
132
		file_put_contents("{$g['etc_path']}/fstab", $fstab);
133
	}
134
	echo ".";
135
	/* mount all filesystems */
136
	mwexec("/sbin/mount -a");
137
	echo ".";
138
}
139

    
140
global $config;
141
$config = parse_config();
142

    
143
/* set timezone */
144
if (isset($config['system']['timezone']) &&
145
    !empty($config['system']['timezone'])) {
146
	$timezone = config_get_path('system/timezone');
147
} elseif (isset($g['default_timezone']) && !empty(g_get('default_timezone'))) {
148
	$timezone = g_get('default_timezone');
149
} else {
150
	$timezone = "Etc/UTC";
151
}
152
date_default_timezone_set("$timezone");
153

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

    
161
?>
(11-11/61)