Project

General

Profile

Download (5.53 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-2020 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 (!$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
if (file_exists("/cf/conf/use_xmlreader")) {
56
	require_once("xmlreader.inc");
57
} else {
58
	require_once("xmlparse.inc");
59
}
60
require_once("crypt.inc");
61

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

    
69
if (platform_booting(true)) {
70
	echo ".";
71
	if (file_exists("/cf/conf/config.xml")) {
72
		$config_contents = file_get_contents("/cf/conf/config.xml");
73
		if (stristr($config_contents, "<m0n0wall>") == true) {
74
			echo ".";
75
			/* user has just upgraded from m0n0wall, replace root xml tags */
76
			log_error(gettext("Upgrading m0n0wall configuration to pfSense... "));
77
			$config_contents = str_replace("m0n0wall", "pfsense", $config_contents);
78
			if (!config_validate("{$g['conf_path']}/config.xml")) {
79
				log_error(gettext("ERROR!  Could not convert m0n0wall -> pfsense in config.xml"));
80
			}
81
			file_put_contents("/cf/conf/config.xml", $config_contents);
82
		}
83
		unset($config_contents);
84
	}
85
	/* if our config file exists bail out, we're already set. */
86
	else if (!file_exists($g['cf_conf_path'] . "/config.xml")) {
87
		echo ".";
88
		/* find the device where config.xml resides and write out an fstab */
89
		unset($cfgdevice);
90
		echo ".";
91
		/* check if there's already an fstab (NFS booting?) */
92
		if (!file_exists("{$g['etc_path']}/fstab")) {
93
			echo ".";
94
			/* probe kernel known disks until we find one with config.xml */
95
			$disks = explode(" ", get_single_sysctl("kern.disks"));
96
			foreach ($disks as $mountdisk) {
97
				/* skip mfs mounted filesystems */
98
				if (strstr($mountdisk, "md")) {
99
					continue;
100
				}
101
				if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
102
					if (file_exists("{$g['cf_conf_path']}/config.xml")) {
103
						/* found it */
104
						$cfgdevice = $mountdisk;
105
						$cfgpartition = $cfgdevice . "a";
106
						$cfgfstype = "ufs";
107
						printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
108
					}
109

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

    
112
					if ($cfgdevice) {
113
						break;
114
					}
115
				}
116
				if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
117
					if (platform_booting()) {
118
						echo ".";
119
					}
120
					if (file_exists("{$g['cf_conf_path']}/config.xml")) {
121
						/* found it */
122
						$cfgdevice = $mountdisk;
123
						$cfgpartition = $cfgdevice . "d";
124
						$cfgfstype = "ufs";
125
						printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
126
					}
127

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

    
130
					if ($cfgdevice) {
131
						break;
132
					}
133
				}
134
			}
135
			echo ".";
136
			if (!$cfgdevice) {
137
				$last_backup = discover_last_backup();
138
				if ($last_backup) {
139
					log_error(gettext("No config.xml found, attempting last known config restore."));
140
					file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
141
					restore_backup("/cf/conf/backup/{$last_backup}");
142
				} else {
143
					log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
144
					restore_backup('/conf.default/config.xml');
145
				}
146
			}
147

    
148
			/* write out an fstab */
149

    
150
			$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
151
			$fstab .= "proc /proc procfs rw 0 0\n";
152
			file_put_contents("{$g['etc_path']}/fstab", $fstab);
153
		}
154
		echo ".";
155
		/* mount all filesystems */
156
		mwexec("/sbin/mount -a");
157
	}
158
	echo ".";
159
}
160

    
161
$config = parse_config();
162

    
163
/* set timezone */
164
if (isset($config['system']['timezone']) &&
165
    !empty($config['system']['timezone'])) {
166
	$timezone = $config['system']['timezone'];
167
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
168
	$timezone = $g['default_timezone'];
169
} else {
170
	$timezone = "Etc/UTC";
171
}
172
date_default_timezone_set("$timezone");
173

    
174
if ($config_parsed == true) {
175
	/* process packager manager custom rules */
176
	if (is_dir("/usr/local/pkg/parse_config")) {
177
		run_plugins("/usr/local/pkg/parse_config/");
178
	}
179
}
180

    
181
?>
(10-10/60)