Project

General

Profile

Download (7.88 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	config.inc
4

    
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (c) 2004-2016 Electric Sheep Fencing, LLC. All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in
20
	   the documentation and/or other materials provided with the
21
	   distribution.
22

    
23
	3. All advertising materials mentioning features or use of this software
24
	   must display the following acknowledgment:
25
	   "This product includes software developed by the pfSense Project
26
	   for use in the pfSense® software distribution. (http://www.pfsense.org/).
27

    
28
	4. The names "pfSense" and "pfSense Project" must not be used to
29
	   endorse or promote products derived from this software without
30
	   prior written permission. For written permission, please contact
31
	   coreteam@pfsense.org.
32

    
33
	5. Products derived from this software may not be called "pfSense"
34
	   nor may "pfSense" appear in their names without prior written
35
	   permission of the Electric Sheep Fencing, LLC.
36

    
37
	6. Redistributions of any form whatsoever must retain the following
38
	   acknowledgment:
39

    
40
	"This product includes software developed by the pfSense Project
41
	for use in the pfSense software distribution (http://www.pfsense.org/).
42

    
43
	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
	OF THE POSSIBILITY OF SUCH DAMAGE.
55
*/
56

    
57
if (!function_exists('platform_booting')) {
58
	require_once('globals.inc');
59
}
60

    
61
/* do not load this file twice. */
62
//if (in_array("/etc/inc/config.inc", get_included_files()))
63
//	return;
64

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

    
72
// Set memory limit to 512M on amd64.
73
if ($ARCH == "amd64") {
74
	ini_set("memory_limit", "512M");
75
} else {
76
	ini_set("memory_limit", "128M");
77
}
78

    
79
/* include globals from notices.inc /utility/XML parser files */
80
require_once("notices.inc");
81
require_once("util.inc");
82
require_once("IPv6.inc");
83
require_once('config.lib.inc');
84
if (file_exists("/cf/conf/use_xmlreader")) {
85
	require_once("xmlreader.inc");
86
} else {
87
	require_once("xmlparse.inc");
88
}
89
require_once("crypt.inc");
90

    
91
/* read platform */
92
if (file_exists("{$g['etc_path']}/platform")) {
93
	$g['platform'] = chop(file_get_contents("{$g['etc_path']}/platform"));
94
} else {
95
	$g['platform'] = "unknown";
96
}
97

    
98
/* if /debugging exists, lets set $debugging
99
   so we can output more information */
100
if (file_exists("/debugging")) {
101
	$debugging = true;
102
	$g['debug'] = true;
103
}
104

    
105
if (platform_booting(true)) {
106
	echo ".";
107
	if (file_exists("/cf/conf/config.xml")) {
108
		$config_contents = file_get_contents("/cf/conf/config.xml");
109
		if (stristr($config_contents, "<m0n0wall>") == true) {
110
			echo ".";
111
			/* user has just upgraded from m0n0wall, replace root xml tags */
112
			log_error(gettext("Upgrading m0n0wall configuration to pfSense... "));
113
			$config_contents = str_replace("m0n0wall", "pfsense", $config_contents);
114
			if (!config_validate("{$g['conf_path']}/config.xml")) {
115
				log_error(gettext("ERROR!  Could not convert m0n0wall -> pfsense in config.xml"));
116
			}
117
			conf_mount_rw();
118
			file_put_contents("/cf/conf/config.xml", $config_contents);
119
			conf_mount_ro();
120
		}
121
		unset($config_contents);
122
	}
123
	/* if our config file exists bail out, we're already set. */
124
	else if (!file_exists($g['cf_conf_path'] . "/config.xml")) {
125
		echo ".";
126
		/* find the device where config.xml resides and write out an fstab */
127
		unset($cfgdevice);
128
		echo ".";
129
		/* check if there's already an fstab (NFS booting?) */
130
		if (!file_exists("{$g['etc_path']}/fstab")) {
131
			echo ".";
132
			if (strstr($g['platform'], "cdrom")) {
133
				/* config is on floppy disk for CD-ROM version */
134
				$cfgdevice = $cfgpartition = "fd0";
135
				$_gb = exec('/sbin/dmesg -a', $dmesg);
136
				if (preg_match("/da0/", $dmesg) == true) {
137
					$cfgdevice = $cfgpartition = "da0" ;
138
					if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
139
						/* could not mount, fallback to floppy */
140
						$cfgdevice = $cfgpartition = "fd0";
141
					}
142
				}
143
				unset($dmesg);
144
				$cfgfstype = "msdosfs";
145
				echo gettext("CDROM build") . "\n";
146
				echo "   " . gettext("CFG:") . " {$cfgpartition}\n";
147
				echo "  " . gettext("TYPE:") . " {$cfgfstype}\n";
148
			} else {
149
				echo ".";
150
				/* probe kernel known disks until we find one with config.xml */
151
				$disks = explode(" ", get_single_sysctl("kern.disks"));
152
				foreach ($disks as $mountdisk) {
153
					/* skip mfs mounted filesystems */
154
					if (strstr($mountdisk, "md")) {
155
						continue;
156
					}
157
					if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
158
						if (file_exists("{$g['cf_conf_path']}/config.xml")) {
159
							/* found it */
160
							$cfgdevice = $mountdisk;
161
							$cfgpartition = $cfgdevice . "a";
162
							$cfgfstype = "ufs";
163
							printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
164
						}
165

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

    
168
						if ($cfgdevice) {
169
							break;
170
						}
171
					}
172
					if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
173
						if (platform_booting()) {
174
							echo ".";
175
						}
176
						if (file_exists("{$g['cf_conf_path']}/config.xml")) {
177
							/* found it */
178
							$cfgdevice = $mountdisk;
179
							$cfgpartition = $cfgdevice . "d";
180
							$cfgfstype = "ufs";
181
							printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
182
						}
183

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

    
186
						if ($cfgdevice) {
187
							break;
188
						}
189
					}
190
				}
191
			}
192
			echo ".";
193
			if (!$cfgdevice) {
194
				$last_backup = discover_last_backup();
195
				if ($last_backup) {
196
					log_error(gettext("No config.xml found, attempting last known config restore."));
197
					file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
198
					restore_backup("/cf/conf/backup/{$last_backup}");
199
				} else {
200
					log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
201
					restore_backup('/conf.default/config.xml');
202
				}
203
			}
204

    
205
			/* write out an fstab */
206

    
207
			$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
208
			$fstab .= "proc /proc procfs rw 0 0\n";
209
			file_put_contents("{$g['etc_path']}/fstab", $fstab);
210
		}
211
		echo ".";
212
		/* mount all filesystems */
213
		mwexec("/sbin/mount -a");
214
	}
215
	echo ".";
216
}
217

    
218
$config = parse_config();
219

    
220
/* set timezone */
221
if (isset($config['system']['timezone']) &&
222
    !empty($config['system']['timezone'])) {
223
	$timezone = $config['system']['timezone'];
224
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
225
	$timezone = $g['default_timezone'];
226
} else {
227
	$timezone = "Etc/UTC";
228
}
229
date_default_timezone_set("$timezone");
230

    
231
if ($config_parsed == true) {
232
	/* process packager manager custom rules */
233
	if (is_dir("/usr/local/pkg/parse_config")) {
234
		run_plugins("/usr/local/pkg/parse_config/");
235
	}
236
}
237

    
238
?>
(11-11/65)