Project

General

Profile

Download (7.99 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 09221bc3 Renato Botelho
/*
3 8acd654a Renato Botelho
 * config.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 8acd654a Renato Botelho
 * All rights reserved.
8
 *
9
 * originally part of m0n0wall (http://m0n0.ch/wall)
10 aaec5634 Renato Botelho
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11 8acd654a Renato Botelho
 * All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56
 */
57 5b237745 Scott Ullrich
58 1e0b1727 Phil Davis
if (!function_exists('platform_booting')) {
59 ca301b52 Ermal LUÇI
	require_once('globals.inc');
60 1e0b1727 Phil Davis
}
61 ca301b52 Ermal LUÇI
62 96447b25 Scott Ullrich
/* do not load this file twice. */
63 cba19251 Chris Buechler
//if (in_array("/etc/inc/config.inc", get_included_files()))
64
//	return;
65 96447b25 Scott Ullrich
66 31c3942c Scott Ullrich
// Set the memory limit to 128M on i386.  When someone has something like 500+ tunnels
67 5acce704 Renato Botelho
// the parser needs quite a bit of ram.   Do not remove this line unless you
68 8ecc250a Scott Ullrich
// know what you are doing.  If in doubt, check with dev@ _/FIRST/_!
69 1e0b1727 Phil Davis
if (!$ARCH) {
70 7a755156 Ermal
	$ARCH = php_uname("m");
71 1e0b1727 Phil Davis
}
72 31c3942c Scott Ullrich
73 16bcd358 Chris Buechler
// Set memory limit to 512M on amd64.
74 1e0b1727 Phil Davis
if ($ARCH == "amd64") {
75 16bcd358 Chris Buechler
	ini_set("memory_limit", "512M");
76 1e0b1727 Phil Davis
} else {
77 086cf944 Phil Davis
	ini_set("memory_limit", "128M");
78 1e0b1727 Phil Davis
}
79 8ecc250a Scott Ullrich
80 bb1546f6 Ermal Lu?i
/* include globals from notices.inc /utility/XML parser files */
81
require_once("notices.inc");
82 5b237745 Scott Ullrich
require_once("util.inc");
83 22b5abac Seth Mos
require_once("IPv6.inc");
84 730b6148 smos
require_once('config.lib.inc');
85 1e0b1727 Phil Davis
if (file_exists("/cf/conf/use_xmlreader")) {
86 093bcebc Scott Ullrich
	require_once("xmlreader.inc");
87 1e0b1727 Phil Davis
} else {
88 093bcebc Scott Ullrich
	require_once("xmlparse.inc");
89 1e0b1727 Phil Davis
}
90 67fc82b5 Ermal Lu?i
require_once("crypt.inc");
91 5b237745 Scott Ullrich
92
/* read platform */
93
if (file_exists("{$g['etc_path']}/platform")) {
94
	$g['platform'] = chop(file_get_contents("{$g['etc_path']}/platform"));
95
} else {
96
	$g['platform'] = "unknown";
97
}
98
99 727a2b91 Scott Ullrich
/* if /debugging exists, lets set $debugging
100
   so we can output more information */
101 1e0b1727 Phil Davis
if (file_exists("/debugging")) {
102 727a2b91 Scott Ullrich
	$debugging = true;
103 1324a93a Scott Ullrich
	$g['debug'] = true;
104
}
105 727a2b91 Scott Ullrich
106 1e0b1727 Phil Davis
if (platform_booting(true)) {
107 6878d797 Ermal LUÇI
	echo ".";
108 1e0b1727 Phil Davis
	if (file_exists("/cf/conf/config.xml")) {
109 6878d797 Ermal LUÇI
		$config_contents = file_get_contents("/cf/conf/config.xml");
110 1e0b1727 Phil Davis
		if (stristr($config_contents, "<m0n0wall>") == true) {
111 6878d797 Ermal LUÇI
			echo ".";
112 1e0b1727 Phil Davis
			/* user has just upgraded from m0n0wall, replace root xml tags */
113 6878d797 Ermal LUÇI
			log_error(gettext("Upgrading m0n0wall configuration to pfSense... "));
114 086cf944 Phil Davis
			$config_contents = str_replace("m0n0wall", "pfsense", $config_contents);
115 1e0b1727 Phil Davis
			if (!config_validate("{$g['conf_path']}/config.xml")) {
116 6878d797 Ermal LUÇI
				log_error(gettext("ERROR!  Could not convert m0n0wall -> pfsense in config.xml"));
117 1e0b1727 Phil Davis
			}
118 6878d797 Ermal LUÇI
			conf_mount_rw();
119
			file_put_contents("/cf/conf/config.xml", $config_contents);
120
			conf_mount_ro();
121
		}
122
		unset($config_contents);
123 49ed889c Scott Ullrich
	}
124 6878d797 Ermal LUÇI
	/* if our config file exists bail out, we're already set. */
125 086cf944 Phil Davis
	else if (!file_exists($g['cf_conf_path'] . "/config.xml")) {
126 6878d797 Ermal LUÇI
		echo ".";
127
		/* find the device where config.xml resides and write out an fstab */
128
		unset($cfgdevice);
129
		echo ".";
130
		/* check if there's already an fstab (NFS booting?) */
131
		if (!file_exists("{$g['etc_path']}/fstab")) {
132
			echo ".";
133
			if (strstr($g['platform'], "cdrom")) {
134
				/* config is on floppy disk for CD-ROM version */
135
				$cfgdevice = $cfgpartition = "fd0";
136
				$_gb = exec('/sbin/dmesg -a', $dmesg);
137 1e0b1727 Phil Davis
				if (preg_match("/da0/", $dmesg) == true) {
138 6878d797 Ermal LUÇI
					$cfgdevice = $cfgpartition = "da0" ;
139
					if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
140
						/* could not mount, fallback to floppy */
141
						$cfgdevice = $cfgpartition = "fd0";
142 5b237745 Scott Ullrich
					}
143 655a80eb Scott Ullrich
				}
144 6878d797 Ermal LUÇI
				unset($dmesg);
145
				$cfgfstype = "msdosfs";
146
				echo gettext("CDROM build") . "\n";
147
				echo "   " . gettext("CFG:") . " {$cfgpartition}\n";
148
				echo "  " . gettext("TYPE:") . " {$cfgfstype}\n";
149
			} else {
150
				echo ".";
151
				/* probe kernel known disks until we find one with config.xml */
152
				$disks = explode(" ", get_single_sysctl("kern.disks"));
153
				foreach ($disks as $mountdisk) {
154
					/* skip mfs mounted filesystems */
155 1e0b1727 Phil Davis
					if (strstr($mountdisk, "md")) {
156 6878d797 Ermal LUÇI
						continue;
157 1e0b1727 Phil Davis
					}
158 6878d797 Ermal LUÇI
					if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
159
						if (file_exists("{$g['cf_conf_path']}/config.xml")) {
160
							/* found it */
161
							$cfgdevice = $mountdisk;
162
							$cfgpartition = $cfgdevice . "a";
163
							$cfgfstype = "ufs";
164
							printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
165
						}
166
167
						mwexec("/sbin/umount -f {$g['cf_path']}");
168
169 1e0b1727 Phil Davis
						if ($cfgdevice) {
170 6878d797 Ermal LUÇI
							break;
171 1e0b1727 Phil Davis
						}
172 6878d797 Ermal LUÇI
					}
173
					if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
174 1e0b1727 Phil Davis
						if (platform_booting()) {
175
							echo ".";
176
						}
177 6878d797 Ermal LUÇI
						if (file_exists("{$g['cf_conf_path']}/config.xml")) {
178
							/* found it */
179
							$cfgdevice = $mountdisk;
180
							$cfgpartition = $cfgdevice . "d";
181
							$cfgfstype = "ufs";
182
							printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
183
						}
184
185
						mwexec("/sbin/umount -f {$g['cf_path']}");
186
187 1e0b1727 Phil Davis
						if ($cfgdevice) {
188 6878d797 Ermal LUÇI
							break;
189 1e0b1727 Phil Davis
						}
190 655a80eb Scott Ullrich
					}
191 5b237745 Scott Ullrich
				}
192
			}
193 6878d797 Ermal LUÇI
			echo ".";
194
			if (!$cfgdevice) {
195
				$last_backup = discover_last_backup();
196 1e0b1727 Phil Davis
				if ($last_backup) {
197 6878d797 Ermal LUÇI
					log_error(gettext("No config.xml found, attempting last known config restore."));
198
					file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
199
					restore_backup("/cf/conf/backup/{$last_backup}");
200
				} else {
201
					log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
202
					restore_backup('/conf.default/config.xml');
203
				}
204 1a23410c Scott Ullrich
			}
205 5b237745 Scott Ullrich
206 6878d797 Ermal LUÇI
			/* write out an fstab */
207 5b237745 Scott Ullrich
208 6878d797 Ermal LUÇI
			$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
209
			$fstab .= "proc /proc procfs rw 0 0\n";
210
			file_put_contents("{$g['etc_path']}/fstab", $fstab);
211
		}
212
		echo ".";
213
		/* mount all filesystems */
214
		mwexec("/sbin/mount -a");
215 5b237745 Scott Ullrich
	}
216 6878d797 Ermal LUÇI
	echo ".";
217 5b237745 Scott Ullrich
}
218
219 f1d634bb Scott Ullrich
$config = parse_config();
220
221 34d70cc0 Scott Ullrich
/* set timezone */
222 ecaca752 Renato Botelho
if (isset($config['system']['timezone']) &&
223
    !empty($config['system']['timezone'])) {
224
	$timezone = $config['system']['timezone'];
225
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
226
	$timezone = $g['default_timezone'];
227
} else {
228 34d70cc0 Scott Ullrich
	$timezone = "Etc/UTC";
229 1e0b1727 Phil Davis
}
230 34d70cc0 Scott Ullrich
date_default_timezone_set("$timezone");
231
232 1e0b1727 Phil Davis
if ($config_parsed == true) {
233 135ef84a Scott Ullrich
	/* process packager manager custom rules */
234 1e0b1727 Phil Davis
	if (is_dir("/usr/local/pkg/parse_config")) {
235 135ef84a Scott Ullrich
		run_plugins("/usr/local/pkg/parse_config/");
236
	}
237
}
238
239 730b6148 smos
?>