Project

General

Profile

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

    
26
if (!function_exists('platform_booting')) {
27
	require_once('globals.inc');
28
}
29

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

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

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

    
48
/* include globals from notices.inc /utility/XML parser files */
49
require_once("notices.inc");
50
require_once("util.inc");
51
require_once("Net/IPv6.php");
52
require_once('config.lib.inc');
53
if (file_exists("/cf/conf/use_xmlreader")) {
54
	require_once("xmlreader.inc");
55
} else {
56
	require_once("xmlparse.inc");
57
}
58
require_once("crypt.inc");
59

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

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

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

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

    
146
			/* write out an fstab */
147

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

    
159
$config = parse_config();
160

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

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

    
179
?>
(10-10/60)