1
|
<?php
|
2
|
/*
|
3
|
* config.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 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
|
* 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
|
|
58
|
if (!function_exists('platform_booting')) {
|
59
|
require_once('globals.inc');
|
60
|
}
|
61
|
|
62
|
/* do not load this file twice. */
|
63
|
//if (in_array("/etc/inc/config.inc", get_included_files()))
|
64
|
// return;
|
65
|
|
66
|
// Set the memory limit to 128M on i386. When someone has something like 500+ tunnels
|
67
|
// the parser needs quite a bit of ram. Do not remove this line unless you
|
68
|
// know what you are doing. If in doubt, check with dev@ _/FIRST/_!
|
69
|
if (!$ARCH) {
|
70
|
$ARCH = php_uname("m");
|
71
|
}
|
72
|
|
73
|
// Set memory limit to 512M on amd64.
|
74
|
if ($ARCH == "amd64") {
|
75
|
ini_set("memory_limit", "512M");
|
76
|
} else {
|
77
|
ini_set("memory_limit", "128M");
|
78
|
}
|
79
|
|
80
|
/* include globals from notices.inc /utility/XML parser files */
|
81
|
require_once("notices.inc");
|
82
|
require_once("util.inc");
|
83
|
require_once("IPv6.inc");
|
84
|
require_once('config.lib.inc');
|
85
|
if (file_exists("/cf/conf/use_xmlreader")) {
|
86
|
require_once("xmlreader.inc");
|
87
|
} else {
|
88
|
require_once("xmlparse.inc");
|
89
|
}
|
90
|
require_once("crypt.inc");
|
91
|
|
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
|
/* if /debugging exists, lets set $debugging
|
100
|
so we can output more information */
|
101
|
if (file_exists("/debugging")) {
|
102
|
$debugging = true;
|
103
|
$g['debug'] = true;
|
104
|
}
|
105
|
|
106
|
if (platform_booting(true)) {
|
107
|
echo ".";
|
108
|
if (file_exists("/cf/conf/config.xml")) {
|
109
|
$config_contents = file_get_contents("/cf/conf/config.xml");
|
110
|
if (stristr($config_contents, "<m0n0wall>") == true) {
|
111
|
echo ".";
|
112
|
/* user has just upgraded from m0n0wall, replace root xml tags */
|
113
|
log_error(gettext("Upgrading m0n0wall configuration to pfSense... "));
|
114
|
$config_contents = str_replace("m0n0wall", "pfsense", $config_contents);
|
115
|
if (!config_validate("{$g['conf_path']}/config.xml")) {
|
116
|
log_error(gettext("ERROR! Could not convert m0n0wall -> pfsense in config.xml"));
|
117
|
}
|
118
|
conf_mount_rw();
|
119
|
file_put_contents("/cf/conf/config.xml", $config_contents);
|
120
|
conf_mount_ro();
|
121
|
}
|
122
|
unset($config_contents);
|
123
|
}
|
124
|
/* if our config file exists bail out, we're already set. */
|
125
|
else if (!file_exists($g['cf_conf_path'] . "/config.xml")) {
|
126
|
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
|
if (preg_match("/da0/", $dmesg) == true) {
|
138
|
$cfgdevice = $cfgpartition = "da0" ;
|
139
|
if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
|
140
|
/* could not mount, fallback to floppy */
|
141
|
$cfgdevice = $cfgpartition = "fd0";
|
142
|
}
|
143
|
}
|
144
|
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
|
if (strstr($mountdisk, "md")) {
|
156
|
continue;
|
157
|
}
|
158
|
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
|
if ($cfgdevice) {
|
170
|
break;
|
171
|
}
|
172
|
}
|
173
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
|
174
|
if (platform_booting()) {
|
175
|
echo ".";
|
176
|
}
|
177
|
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
|
if ($cfgdevice) {
|
188
|
break;
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
}
|
193
|
echo ".";
|
194
|
if (!$cfgdevice) {
|
195
|
$last_backup = discover_last_backup();
|
196
|
if ($last_backup) {
|
197
|
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
|
}
|
205
|
|
206
|
/* write out an fstab */
|
207
|
|
208
|
$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
|
}
|
216
|
echo ".";
|
217
|
}
|
218
|
|
219
|
$config = parse_config();
|
220
|
|
221
|
/* set timezone */
|
222
|
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
|
$timezone = "Etc/UTC";
|
229
|
}
|
230
|
date_default_timezone_set("$timezone");
|
231
|
|
232
|
if ($config_parsed == true) {
|
233
|
/* process packager manager custom rules */
|
234
|
if (is_dir("/usr/local/pkg/parse_config")) {
|
235
|
run_plugins("/usr/local/pkg/parse_config/");
|
236
|
}
|
237
|
}
|
238
|
|
239
|
?>
|