1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
09221bc3
|
Renato Botelho
|
/*
|
3 |
5b237745
|
Scott Ullrich
|
config.inc
|
4 |
09221bc3
|
Renato Botelho
|
|
5 |
|
|
part of pfSense (https://www.pfsense.org)
|
6 |
|
|
Copyright (c) 2004-2016 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
5b237745
|
Scott Ullrich
|
|
8 |
cfc707f7
|
Scott Ullrich
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9 |
5b237745
|
Scott Ullrich
|
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 |
09221bc3
|
Renato Botelho
|
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 |
5b237745
|
Scott Ullrich
|
*/
|
56 |
|
|
|
57 |
1e0b1727
|
Phil Davis
|
if (!function_exists('platform_booting')) {
|
58 |
ca301b52
|
Ermal LUÇI
|
require_once('globals.inc');
|
59 |
1e0b1727
|
Phil Davis
|
}
|
60 |
ca301b52
|
Ermal LUÇI
|
|
61 |
96447b25
|
Scott Ullrich
|
/* do not load this file twice. */
|
62 |
cba19251
|
Chris Buechler
|
//if (in_array("/etc/inc/config.inc", get_included_files()))
|
63 |
|
|
// return;
|
64 |
96447b25
|
Scott Ullrich
|
|
65 |
31c3942c
|
Scott Ullrich
|
// Set the memory limit to 128M on i386. When someone has something like 500+ tunnels
|
66 |
5acce704
|
Renato Botelho
|
// the parser needs quite a bit of ram. Do not remove this line unless you
|
67 |
8ecc250a
|
Scott Ullrich
|
// know what you are doing. If in doubt, check with dev@ _/FIRST/_!
|
68 |
1e0b1727
|
Phil Davis
|
if (!$ARCH) {
|
69 |
7a755156
|
Ermal
|
$ARCH = php_uname("m");
|
70 |
1e0b1727
|
Phil Davis
|
}
|
71 |
31c3942c
|
Scott Ullrich
|
|
72 |
b20c7ef1
|
Chris Buechler
|
// Set memory limit to 512M on amd64.
|
73 |
1e0b1727
|
Phil Davis
|
if ($ARCH == "amd64") {
|
74 |
b20c7ef1
|
Chris Buechler
|
ini_set("memory_limit", "512M");
|
75 |
1e0b1727
|
Phil Davis
|
} else {
|
76 |
086cf944
|
Phil Davis
|
ini_set("memory_limit", "128M");
|
77 |
1e0b1727
|
Phil Davis
|
}
|
78 |
8ecc250a
|
Scott Ullrich
|
|
79 |
bb1546f6
|
Ermal Lu?i
|
/* include globals from notices.inc /utility/XML parser files */
|
80 |
|
|
require_once("notices.inc");
|
81 |
5b237745
|
Scott Ullrich
|
require_once("util.inc");
|
82 |
22b5abac
|
Seth Mos
|
require_once("IPv6.inc");
|
83 |
730b6148
|
smos
|
require_once('config.lib.inc');
|
84 |
1e0b1727
|
Phil Davis
|
if (file_exists("/cf/conf/use_xmlreader")) {
|
85 |
093bcebc
|
Scott Ullrich
|
require_once("xmlreader.inc");
|
86 |
1e0b1727
|
Phil Davis
|
} else {
|
87 |
093bcebc
|
Scott Ullrich
|
require_once("xmlparse.inc");
|
88 |
1e0b1727
|
Phil Davis
|
}
|
89 |
67fc82b5
|
Ermal Lu?i
|
require_once("crypt.inc");
|
90 |
5b237745
|
Scott Ullrich
|
|
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 |
727a2b91
|
Scott Ullrich
|
/* if /debugging exists, lets set $debugging
|
99 |
|
|
so we can output more information */
|
100 |
1e0b1727
|
Phil Davis
|
if (file_exists("/debugging")) {
|
101 |
727a2b91
|
Scott Ullrich
|
$debugging = true;
|
102 |
1324a93a
|
Scott Ullrich
|
$g['debug'] = true;
|
103 |
|
|
}
|
104 |
727a2b91
|
Scott Ullrich
|
|
105 |
1e0b1727
|
Phil Davis
|
if (platform_booting(true)) {
|
106 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
107 |
1e0b1727
|
Phil Davis
|
if (file_exists("/cf/conf/config.xml")) {
|
108 |
6878d797
|
Ermal LUÇI
|
$config_contents = file_get_contents("/cf/conf/config.xml");
|
109 |
1e0b1727
|
Phil Davis
|
if (stristr($config_contents, "<m0n0wall>") == true) {
|
110 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
111 |
1e0b1727
|
Phil Davis
|
/* user has just upgraded from m0n0wall, replace root xml tags */
|
112 |
6878d797
|
Ermal LUÇI
|
log_error(gettext("Upgrading m0n0wall configuration to pfSense... "));
|
113 |
086cf944
|
Phil Davis
|
$config_contents = str_replace("m0n0wall", "pfsense", $config_contents);
|
114 |
1e0b1727
|
Phil Davis
|
if (!config_validate("{$g['conf_path']}/config.xml")) {
|
115 |
6878d797
|
Ermal LUÇI
|
log_error(gettext("ERROR! Could not convert m0n0wall -> pfsense in config.xml"));
|
116 |
1e0b1727
|
Phil Davis
|
}
|
117 |
6878d797
|
Ermal LUÇI
|
conf_mount_rw();
|
118 |
|
|
file_put_contents("/cf/conf/config.xml", $config_contents);
|
119 |
|
|
conf_mount_ro();
|
120 |
|
|
}
|
121 |
|
|
unset($config_contents);
|
122 |
49ed889c
|
Scott Ullrich
|
}
|
123 |
6878d797
|
Ermal LUÇI
|
/* if our config file exists bail out, we're already set. */
|
124 |
086cf944
|
Phil Davis
|
else if (!file_exists($g['cf_conf_path'] . "/config.xml")) {
|
125 |
6878d797
|
Ermal LUÇI
|
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 |
1e0b1727
|
Phil Davis
|
if (preg_match("/da0/", $dmesg) == true) {
|
137 |
6878d797
|
Ermal LUÇI
|
$cfgdevice = $cfgpartition = "da0" ;
|
138 |
|
|
if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
|
139 |
|
|
/* could not mount, fallback to floppy */
|
140 |
|
|
$cfgdevice = $cfgpartition = "fd0";
|
141 |
5b237745
|
Scott Ullrich
|
}
|
142 |
655a80eb
|
Scott Ullrich
|
}
|
143 |
6878d797
|
Ermal LUÇI
|
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 |
1e0b1727
|
Phil Davis
|
if (strstr($mountdisk, "md")) {
|
155 |
6878d797
|
Ermal LUÇI
|
continue;
|
156 |
1e0b1727
|
Phil Davis
|
}
|
157 |
6878d797
|
Ermal LUÇI
|
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 |
1e0b1727
|
Phil Davis
|
if ($cfgdevice) {
|
169 |
6878d797
|
Ermal LUÇI
|
break;
|
170 |
1e0b1727
|
Phil Davis
|
}
|
171 |
6878d797
|
Ermal LUÇI
|
}
|
172 |
|
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
|
173 |
1e0b1727
|
Phil Davis
|
if (platform_booting()) {
|
174 |
|
|
echo ".";
|
175 |
|
|
}
|
176 |
6878d797
|
Ermal LUÇI
|
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 |
1e0b1727
|
Phil Davis
|
if ($cfgdevice) {
|
187 |
6878d797
|
Ermal LUÇI
|
break;
|
188 |
1e0b1727
|
Phil Davis
|
}
|
189 |
655a80eb
|
Scott Ullrich
|
}
|
190 |
5b237745
|
Scott Ullrich
|
}
|
191 |
|
|
}
|
192 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
193 |
|
|
if (!$cfgdevice) {
|
194 |
|
|
$last_backup = discover_last_backup();
|
195 |
1e0b1727
|
Phil Davis
|
if ($last_backup) {
|
196 |
6878d797
|
Ermal LUÇI
|
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 |
1a23410c
|
Scott Ullrich
|
}
|
204 |
5b237745
|
Scott Ullrich
|
|
205 |
6878d797
|
Ermal LUÇI
|
/* write out an fstab */
|
206 |
5b237745
|
Scott Ullrich
|
|
207 |
6878d797
|
Ermal LUÇI
|
$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 |
5b237745
|
Scott Ullrich
|
}
|
215 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
216 |
5b237745
|
Scott Ullrich
|
}
|
217 |
|
|
|
218 |
f1d634bb
|
Scott Ullrich
|
$config = parse_config();
|
219 |
|
|
|
220 |
34d70cc0
|
Scott Ullrich
|
/* set timezone */
|
221 |
ecaca752
|
Renato Botelho
|
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 |
34d70cc0
|
Scott Ullrich
|
$timezone = "Etc/UTC";
|
228 |
1e0b1727
|
Phil Davis
|
}
|
229 |
34d70cc0
|
Scott Ullrich
|
date_default_timezone_set("$timezone");
|
230 |
|
|
|
231 |
1e0b1727
|
Phil Davis
|
if ($config_parsed == true) {
|
232 |
135ef84a
|
Scott Ullrich
|
/* process packager manager custom rules */
|
233 |
1e0b1727
|
Phil Davis
|
if (is_dir("/usr/local/pkg/parse_config")) {
|
234 |
135ef84a
|
Scott Ullrich
|
run_plugins("/usr/local/pkg/parse_config/");
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
730b6148
|
smos
|
?>
|