1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
09221bc3
|
Renato Botelho
|
/*
|
3 |
ac24dc24
|
Renato Botelho
|
* config.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
8f2f85c3
|
Luiz Otavio O Souza
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
9 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
10 |
|
|
*
|
11 |
|
|
* originally part of m0n0wall (http://m0n0.ch/wall)
|
12 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
14 |
|
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16 |
|
|
* you may not use this file except in compliance with the License.
|
17 |
|
|
* You may obtain a copy of the License at
|
18 |
ac24dc24
|
Renato Botelho
|
*
|
19 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20 |
ac24dc24
|
Renato Botelho
|
*
|
21 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
22 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24 |
|
|
* See the License for the specific language governing permissions and
|
25 |
|
|
* limitations under the License.
|
26 |
ac24dc24
|
Renato Botelho
|
*/
|
27 |
5b237745
|
Scott Ullrich
|
|
28 |
1e0b1727
|
Phil Davis
|
if (!function_exists('platform_booting')) {
|
29 |
ca301b52
|
Ermal LUÇI
|
require_once('globals.inc');
|
30 |
1e0b1727
|
Phil Davis
|
}
|
31 |
ca301b52
|
Ermal LUÇI
|
|
32 |
96447b25
|
Scott Ullrich
|
/* do not load this file twice. */
|
33 |
cba19251
|
Chris Buechler
|
//if (in_array("/etc/inc/config.inc", get_included_files()))
|
34 |
|
|
// return;
|
35 |
96447b25
|
Scott Ullrich
|
|
36 |
31c3942c
|
Scott Ullrich
|
// Set the memory limit to 128M on i386. When someone has something like 500+ tunnels
|
37 |
5acce704
|
Renato Botelho
|
// the parser needs quite a bit of ram. Do not remove this line unless you
|
38 |
8ecc250a
|
Scott Ullrich
|
// know what you are doing. If in doubt, check with dev@ _/FIRST/_!
|
39 |
5833da65
|
Reid Linnemann
|
if (!isset($ARCH)) {
|
40 |
7a755156
|
Ermal
|
$ARCH = php_uname("m");
|
41 |
1e0b1727
|
Phil Davis
|
}
|
42 |
31c3942c
|
Scott Ullrich
|
|
43 |
b20c7ef1
|
Chris Buechler
|
// Set memory limit to 512M on amd64.
|
44 |
1e0b1727
|
Phil Davis
|
if ($ARCH == "amd64") {
|
45 |
b20c7ef1
|
Chris Buechler
|
ini_set("memory_limit", "512M");
|
46 |
1e0b1727
|
Phil Davis
|
} else {
|
47 |
086cf944
|
Phil Davis
|
ini_set("memory_limit", "128M");
|
48 |
1e0b1727
|
Phil Davis
|
}
|
49 |
8ecc250a
|
Scott Ullrich
|
|
50 |
bb1546f6
|
Ermal Lu?i
|
/* include globals from notices.inc /utility/XML parser files */
|
51 |
|
|
require_once("notices.inc");
|
52 |
5b237745
|
Scott Ullrich
|
require_once("util.inc");
|
53 |
470fddb1
|
Renato Botelho
|
require_once("Net/IPv6.php");
|
54 |
730b6148
|
smos
|
require_once('config.lib.inc');
|
55 |
1e0b1727
|
Phil Davis
|
if (file_exists("/cf/conf/use_xmlreader")) {
|
56 |
093bcebc
|
Scott Ullrich
|
require_once("xmlreader.inc");
|
57 |
1e0b1727
|
Phil Davis
|
} else {
|
58 |
093bcebc
|
Scott Ullrich
|
require_once("xmlparse.inc");
|
59 |
1e0b1727
|
Phil Davis
|
}
|
60 |
67fc82b5
|
Ermal Lu?i
|
require_once("crypt.inc");
|
61 |
5b237745
|
Scott Ullrich
|
|
62 |
727a2b91
|
Scott Ullrich
|
/* if /debugging exists, lets set $debugging
|
63 |
|
|
so we can output more information */
|
64 |
1e0b1727
|
Phil Davis
|
if (file_exists("/debugging")) {
|
65 |
727a2b91
|
Scott Ullrich
|
$debugging = true;
|
66 |
1324a93a
|
Scott Ullrich
|
$g['debug'] = true;
|
67 |
|
|
}
|
68 |
727a2b91
|
Scott Ullrich
|
|
69 |
28b16209
|
Renato Botelho do Couto
|
if (platform_booting(true) &&
|
70 |
|
|
!file_exists($g['cf_conf_path'] . "/config.xml")) {
|
71 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
72 |
28b16209
|
Renato Botelho do Couto
|
/* find the device where config.xml resides and write out an fstab */
|
73 |
|
|
unset($cfgdevice);
|
74 |
|
|
echo ".";
|
75 |
|
|
/* check if there's already an fstab (NFS booting?) */
|
76 |
|
|
if (!file_exists("{$g['etc_path']}/fstab")) {
|
77 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
78 |
28b16209
|
Renato Botelho do Couto
|
/* probe kernel known disks until we find one with config.xml */
|
79 |
|
|
$disks = explode(" ", get_single_sysctl("kern.disks"));
|
80 |
|
|
foreach ($disks as $mountdisk) {
|
81 |
|
|
/* skip mfs mounted filesystems */
|
82 |
|
|
if (strstr($mountdisk, "md")) {
|
83 |
|
|
continue;
|
84 |
|
|
}
|
85 |
|
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
|
86 |
|
|
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
|
87 |
|
|
/* found it */
|
88 |
|
|
$cfgdevice = $mountdisk;
|
89 |
|
|
$cfgpartition = $cfgdevice . "a";
|
90 |
|
|
$cfgfstype = "ufs";
|
91 |
|
|
printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
|
92 |
60f164f3
|
Renato Botelho
|
}
|
93 |
28b16209
|
Renato Botelho do Couto
|
|
94 |
|
|
mwexec("/sbin/umount -f {$g['cf_path']}");
|
95 |
|
|
|
96 |
|
|
if ($cfgdevice) {
|
97 |
|
|
break;
|
98 |
5b237745
|
Scott Ullrich
|
}
|
99 |
|
|
}
|
100 |
28b16209
|
Renato Botelho do Couto
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
|
101 |
|
|
if (platform_booting()) {
|
102 |
|
|
echo ".";
|
103 |
|
|
}
|
104 |
|
|
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
|
105 |
|
|
/* found it */
|
106 |
|
|
$cfgdevice = $mountdisk;
|
107 |
|
|
$cfgpartition = $cfgdevice . "d";
|
108 |
|
|
$cfgfstype = "ufs";
|
109 |
|
|
printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
|
110 |
6878d797
|
Ermal LUÇI
|
}
|
111 |
5b237745
|
Scott Ullrich
|
|
112 |
28b16209
|
Renato Botelho do Couto
|
mwexec("/sbin/umount -f {$g['cf_path']}");
|
113 |
5b237745
|
Scott Ullrich
|
|
114 |
28b16209
|
Renato Botelho do Couto
|
if ($cfgdevice) {
|
115 |
|
|
break;
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
6878d797
|
Ermal LUÇI
|
}
|
119 |
|
|
echo ".";
|
120 |
28b16209
|
Renato Botelho do Couto
|
if (!$cfgdevice) {
|
121 |
|
|
$last_backup = discover_last_backup();
|
122 |
|
|
if ($last_backup) {
|
123 |
|
|
log_error(gettext("No config.xml found, attempting last known config restore."));
|
124 |
|
|
file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
|
125 |
|
|
restore_backup("/cf/conf/backup/{$last_backup}");
|
126 |
|
|
} else {
|
127 |
|
|
log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
|
128 |
|
|
restore_backup('/conf.default/config.xml');
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/* write out an fstab */
|
133 |
|
|
|
134 |
|
|
$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
|
135 |
|
|
$fstab .= "proc /proc procfs rw 0 0\n";
|
136 |
|
|
file_put_contents("{$g['etc_path']}/fstab", $fstab);
|
137 |
5b237745
|
Scott Ullrich
|
}
|
138 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
139 |
28b16209
|
Renato Botelho do Couto
|
/* mount all filesystems */
|
140 |
|
|
mwexec("/sbin/mount -a");
|
141 |
|
|
echo ".";
|
142 |
5b237745
|
Scott Ullrich
|
}
|
143 |
|
|
|
144 |
f1d634bb
|
Scott Ullrich
|
$config = parse_config();
|
145 |
|
|
|
146 |
34d70cc0
|
Scott Ullrich
|
/* set timezone */
|
147 |
ecaca752
|
Renato Botelho
|
if (isset($config['system']['timezone']) &&
|
148 |
|
|
!empty($config['system']['timezone'])) {
|
149 |
|
|
$timezone = $config['system']['timezone'];
|
150 |
|
|
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
|
151 |
|
|
$timezone = $g['default_timezone'];
|
152 |
|
|
} else {
|
153 |
34d70cc0
|
Scott Ullrich
|
$timezone = "Etc/UTC";
|
154 |
1e0b1727
|
Phil Davis
|
}
|
155 |
34d70cc0
|
Scott Ullrich
|
date_default_timezone_set("$timezone");
|
156 |
|
|
|
157 |
1e0b1727
|
Phil Davis
|
if ($config_parsed == true) {
|
158 |
135ef84a
|
Scott Ullrich
|
/* process packager manager custom rules */
|
159 |
1e0b1727
|
Phil Davis
|
if (is_dir("/usr/local/pkg/parse_config")) {
|
160 |
135ef84a
|
Scott Ullrich
|
run_plugins("/usr/local/pkg/parse_config/");
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
|
164 |
730b6148
|
smos
|
?>
|