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 |
37d60e23
|
Luiz Souza
|
* Copyright (c) 2014-2025 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 |
816fef25
|
Marcos Mendoza
|
if (!function_exists('is_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 |
bb1546f6
|
Ermal Lu?i
|
/* include globals from notices.inc /utility/XML parser files */
|
37 |
|
|
require_once("notices.inc");
|
38 |
5b237745
|
Scott Ullrich
|
require_once("util.inc");
|
39 |
470fddb1
|
Renato Botelho
|
require_once("Net/IPv6.php");
|
40 |
730b6148
|
smos
|
require_once('config.lib.inc');
|
41 |
d8c35176
|
Marcos Mendoza
|
require_once("xmlparse.inc");
|
42 |
67fc82b5
|
Ermal Lu?i
|
require_once("crypt.inc");
|
43 |
5b237745
|
Scott Ullrich
|
|
44 |
fc62ac50
|
Christopher
|
// Set the memory limit to 128M on i386. When someone has something like 500+ tunnels
|
45 |
|
|
// the parser needs quite a bit of ram. Do not remove this line unless you
|
46 |
|
|
// know what you are doing. If in doubt, check with dev@ _/FIRST/_!
|
47 |
|
|
if (!$ARCH) {
|
48 |
|
|
$ARCH = php_uname("m");
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// Set memory limit to 512M on amd64.
|
52 |
|
|
ini_set("memory_limit", get_php_default_memory($ARCH) . 'M');
|
53 |
|
|
|
54 |
727a2b91
|
Scott Ullrich
|
/* if /debugging exists, lets set $debugging
|
55 |
|
|
so we can output more information */
|
56 |
1e0b1727
|
Phil Davis
|
if (file_exists("/debugging")) {
|
57 |
727a2b91
|
Scott Ullrich
|
$debugging = true;
|
58 |
1324a93a
|
Scott Ullrich
|
$g['debug'] = true;
|
59 |
|
|
}
|
60 |
727a2b91
|
Scott Ullrich
|
|
61 |
816fef25
|
Marcos Mendoza
|
if (is_platform_booting() && is_cli_sapi() &&
|
62 |
2568e151
|
Christian McDonald
|
!file_exists(g_get('cf_conf_path') . "/config.xml")) {
|
63 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
64 |
28b16209
|
Renato Botelho do Couto
|
/* find the device where config.xml resides and write out an fstab */
|
65 |
|
|
unset($cfgdevice);
|
66 |
|
|
echo ".";
|
67 |
|
|
/* check if there's already an fstab (NFS booting?) */
|
68 |
|
|
if (!file_exists("{$g['etc_path']}/fstab")) {
|
69 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
70 |
28b16209
|
Renato Botelho do Couto
|
/* probe kernel known disks until we find one with config.xml */
|
71 |
|
|
$disks = explode(" ", get_single_sysctl("kern.disks"));
|
72 |
|
|
foreach ($disks as $mountdisk) {
|
73 |
|
|
/* skip mfs mounted filesystems */
|
74 |
|
|
if (strstr($mountdisk, "md")) {
|
75 |
|
|
continue;
|
76 |
|
|
}
|
77 |
|
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}a {$g['cf_path']}") == 0) {
|
78 |
|
|
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
|
79 |
|
|
/* found it */
|
80 |
|
|
$cfgdevice = $mountdisk;
|
81 |
|
|
$cfgpartition = $cfgdevice . "a";
|
82 |
|
|
$cfgfstype = "ufs";
|
83 |
|
|
printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
|
84 |
60f164f3
|
Renato Botelho
|
}
|
85 |
28b16209
|
Renato Botelho do Couto
|
|
86 |
|
|
mwexec("/sbin/umount -f {$g['cf_path']}");
|
87 |
|
|
|
88 |
|
|
if ($cfgdevice) {
|
89 |
|
|
break;
|
90 |
5b237745
|
Scott Ullrich
|
}
|
91 |
|
|
}
|
92 |
28b16209
|
Renato Botelho do Couto
|
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d {$g['cf_path']}") == 0) {
|
93 |
816fef25
|
Marcos Mendoza
|
if (is_platform_booting()) {
|
94 |
28b16209
|
Renato Botelho do Couto
|
echo ".";
|
95 |
|
|
}
|
96 |
|
|
if (file_exists("{$g['cf_conf_path']}/config.xml")) {
|
97 |
|
|
/* found it */
|
98 |
|
|
$cfgdevice = $mountdisk;
|
99 |
|
|
$cfgpartition = $cfgdevice . "d";
|
100 |
|
|
$cfgfstype = "ufs";
|
101 |
|
|
printf(gettext('Found configuration on %1$s.%2$s'), $cfgdevice, "\n");
|
102 |
6878d797
|
Ermal LUÇI
|
}
|
103 |
5b237745
|
Scott Ullrich
|
|
104 |
28b16209
|
Renato Botelho do Couto
|
mwexec("/sbin/umount -f {$g['cf_path']}");
|
105 |
5b237745
|
Scott Ullrich
|
|
106 |
28b16209
|
Renato Botelho do Couto
|
if ($cfgdevice) {
|
107 |
|
|
break;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
6878d797
|
Ermal LUÇI
|
}
|
111 |
|
|
echo ".";
|
112 |
af909d61
|
Marcos Mendoza
|
if (!$cfgdevice && !config_read_file(true)) {
|
113 |
|
|
log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
|
114 |
|
|
if (restore_backup('/conf.default/config.xml')) {
|
115 |
|
|
config_read_file();
|
116 |
28b16209
|
Renato Botelho do Couto
|
}
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/* write out an fstab */
|
120 |
|
|
|
121 |
|
|
$fstab = "/dev/{$cfgpartition} {$g['cf_path']} {$cfgfstype} ro,noatime 1 1\n";
|
122 |
|
|
$fstab .= "proc /proc procfs rw 0 0\n";
|
123 |
|
|
file_put_contents("{$g['etc_path']}/fstab", $fstab);
|
124 |
5b237745
|
Scott Ullrich
|
}
|
125 |
6878d797
|
Ermal LUÇI
|
echo ".";
|
126 |
28b16209
|
Renato Botelho do Couto
|
/* mount all filesystems */
|
127 |
|
|
mwexec("/sbin/mount -a");
|
128 |
|
|
echo ".";
|
129 |
5b237745
|
Scott Ullrich
|
}
|
130 |
|
|
|
131 |
735b7681
|
Marcos Mendoza
|
config_read_file(true, true);
|
132 |
f1d634bb
|
Scott Ullrich
|
|
133 |
34d70cc0
|
Scott Ullrich
|
/* set timezone */
|
134 |
63d6bb4f
|
Marcos Mendoza
|
$timezone = config_get_path('system/timezone');
|
135 |
|
|
if (isset($timezone) &&
|
136 |
|
|
!empty($timezone)) {
|
137 |
|
|
// noop
|
138 |
2568e151
|
Christian McDonald
|
} elseif (isset($g['default_timezone']) && !empty(g_get('default_timezone'))) {
|
139 |
|
|
$timezone = g_get('default_timezone');
|
140 |
ecaca752
|
Renato Botelho
|
} else {
|
141 |
34d70cc0
|
Scott Ullrich
|
$timezone = "Etc/UTC";
|
142 |
1e0b1727
|
Phil Davis
|
}
|
143 |
34d70cc0
|
Scott Ullrich
|
date_default_timezone_set("$timezone");
|
144 |
|
|
|
145 |
fc62ac50
|
Christopher
|
/* override php memory limit */
|
146 |
|
|
$php_memory_limit = config_get_path('system/php_memory_limit', 0);
|
147 |
|
|
if (($php_memory_limit >= 128) && ($php_memory_limit <= get_php_max_memory())) {
|
148 |
|
|
ini_set("memory_limit", config_get_path('system/php_memory_limit') . "M");
|
149 |
|
|
}
|
150 |
|
|
|
151 |
1e0b1727
|
Phil Davis
|
if ($config_parsed == true) {
|
152 |
135ef84a
|
Scott Ullrich
|
/* process packager manager custom rules */
|
153 |
1e0b1727
|
Phil Davis
|
if (is_dir("/usr/local/pkg/parse_config")) {
|
154 |
135ef84a
|
Scott Ullrich
|
run_plugins("/usr/local/pkg/parse_config/");
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
|
158 |
730b6148
|
smos
|
?>
|