1 |
cb7d18d5
|
Renato Botelho
|
#!/usr/local/bin/php-cgi -q
|
2 |
5b237745
|
Scott Ullrich
|
<?php
|
3 |
|
|
/*
|
4 |
ac24dc24
|
Renato Botelho
|
* rc.initial.setlanip
|
5 |
|
|
*
|
6 |
|
|
* part of pfSense (https://www.pfsense.org)
|
7 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
8 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9 |
8f2f85c3
|
Luiz Otavio O Souza
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
10 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
|
|
* originally part of m0n0wall (http://m0n0.ch/wall)
|
13 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
14 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
15 |
|
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
17 |
|
|
* you may not use this file except in compliance with the License.
|
18 |
|
|
* You may obtain a copy of the License at
|
19 |
ac24dc24
|
Renato Botelho
|
*
|
20 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
21 |
ac24dc24
|
Renato Botelho
|
*
|
22 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
23 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
24 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
25 |
|
|
* See the License for the specific language governing permissions and
|
26 |
|
|
* limitations under the License.
|
27 |
ac24dc24
|
Renato Botelho
|
*/
|
28 |
5b237745
|
Scott Ullrich
|
|
29 |
c63e3594
|
Darren Embry
|
$options = getopt("hn", array("dry-run", "help"));
|
30 |
5833da65
|
Reid Linnemann
|
$restart_webgui = false;
|
31 |
c63e3594
|
Darren Embry
|
|
32 |
|
|
if (isset($options["h"]) || isset($options["help"])) {
|
33 |
|
|
echo "usage: /etc/rc.initial.setlanip [option ...]\n";
|
34 |
|
|
echo " -h, --help show this message\n";
|
35 |
|
|
echo " -n, --dry-run do not make any configuration changes\n";
|
36 |
9ea554ee
|
Ermal LUÇI
|
return 0;
|
37 |
c63e3594
|
Darren Embry
|
}
|
38 |
|
|
|
39 |
|
|
$dry_run = isset($options["n"]) || isset($options["dry-run"]);
|
40 |
|
|
if ($dry_run) {
|
41 |
|
|
echo "DRY RUN MODE IS ON\n";
|
42 |
|
|
}
|
43 |
|
|
|
44 |
416e1530
|
Darren Embry
|
/* parse the configuration and include all functions used below */
|
45 |
|
|
require_once("config.inc");
|
46 |
|
|
require_once("functions.inc");
|
47 |
|
|
require_once("filter.inc");
|
48 |
|
|
require_once("shaper.inc");
|
49 |
|
|
require_once("rrd.inc");
|
50 |
bbc3533f
|
Scott Ullrich
|
|
51 |
e6abcccc
|
Phil Davis
|
function console_prompt_for_yn ($prompt_text) {
|
52 |
|
|
global $fp;
|
53 |
|
|
|
54 |
|
|
$good_answer = false;
|
55 |
|
|
|
56 |
|
|
do {
|
57 |
|
|
echo "\n" . $prompt_text . " (y/n) ";
|
58 |
|
|
$yn = strtolower(chop(fgets($fp)));
|
59 |
|
|
if (($yn == "y") || ($yn == "yes")) {
|
60 |
|
|
$boolean_answer = true;
|
61 |
|
|
$good_answer = true;
|
62 |
|
|
}
|
63 |
|
|
if (($yn == "n") || ($yn == "no")) {
|
64 |
|
|
$boolean_answer = false;
|
65 |
|
|
$good_answer = true;
|
66 |
|
|
}
|
67 |
|
|
} while (!$good_answer);
|
68 |
|
|
|
69 |
|
|
return $boolean_answer;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
416e1530
|
Darren Embry
|
function console_get_interface_from_ppp($realif) {
|
73 |
|
|
global $config;
|
74 |
aab5f04c
|
Ermal
|
|
75 |
81777072
|
Christian McDonald
|
foreach (config_get_path('ppps/ppp', []) as $pppid => $ppp) {
|
76 |
|
|
if ($realif == $ppp['if']) {
|
77 |
|
|
$ifaces = explode(",", $ppp['ports']);
|
78 |
|
|
return $ifaces[0];
|
79 |
aab5f04c
|
Ermal
|
}
|
80 |
|
|
}
|
81 |
|
|
|
82 |
416e1530
|
Darren Embry
|
return "";
|
83 |
|
|
}
|
84 |
|
|
|
85 |
c1361a9f
|
Darren Embry
|
function prompt_for_enable_dhcp_server($version = 4) {
|
86 |
416e1530
|
Darren Embry
|
global $config, $fp, $interface;
|
87 |
13ae614b
|
jim-p
|
|
88 |
416e1530
|
Darren Embry
|
/* only allow DHCP server to be enabled when static IP is
|
89 |
|
|
configured on this interface */
|
90 |
c1361a9f
|
Darren Embry
|
if ($version === 6) {
|
91 |
|
|
$is_ipaddr = is_ipaddrv6($config['interfaces'][$interface]['ipaddrv6']);
|
92 |
|
|
} else {
|
93 |
|
|
$is_ipaddr = is_ipaddrv4($config['interfaces'][$interface]['ipaddr']);
|
94 |
|
|
}
|
95 |
e6abcccc
|
Phil Davis
|
if (!($is_ipaddr)) {
|
96 |
|
|
return false;
|
97 |
e1454e42
|
Scott Ullrich
|
}
|
98 |
e6abcccc
|
Phil Davis
|
|
99 |
|
|
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP";
|
100 |
|
|
$upperifname = strtoupper($interface);
|
101 |
1579e70f
|
Phil Davis
|
return console_prompt_for_yn (sprintf(gettext('Do you want to enable the %1$s server on %2$s?'), $label_DHCP, $upperifname));
|
102 |
416e1530
|
Darren Embry
|
}
|
103 |
e1454e42
|
Scott Ullrich
|
|
104 |
0098aa73
|
Darren Embry
|
function get_interface_config_description($iface) {
|
105 |
|
|
global $config;
|
106 |
|
|
$c = $config['interfaces'][$iface];
|
107 |
086cf944
|
Phil Davis
|
if (!$c) {
|
108 |
|
|
return null;
|
109 |
e173dd74
|
Phil Davis
|
}
|
110 |
0098aa73
|
Darren Embry
|
$if = $c['if'];
|
111 |
|
|
$result = $if;
|
112 |
|
|
$result2 = array();
|
113 |
|
|
$ipaddr = $c['ipaddr'];
|
114 |
|
|
$ipaddrv6 = $c['ipaddrv6'];
|
115 |
|
|
if (is_ipaddr($ipaddr)) {
|
116 |
|
|
$result2[] = "static";
|
117 |
|
|
} else if ($ipaddr == "dhcp") {
|
118 |
|
|
$result2[] = "dhcp";
|
119 |
|
|
}
|
120 |
|
|
if (is_ipaddr($ipaddrv6)) {
|
121 |
|
|
$result2[] = "staticv6";
|
122 |
|
|
} else if ($ipaddrv6 == "dhcp6") {
|
123 |
|
|
$result2[] = "dhcp6";
|
124 |
|
|
}
|
125 |
|
|
if (count($result2)) {
|
126 |
|
|
$result .= " - " . implode(", ", $result2);
|
127 |
|
|
}
|
128 |
|
|
return $result;
|
129 |
|
|
}
|
130 |
|
|
|
131 |
416e1530
|
Darren Embry
|
$fp = fopen('php://stdin', 'r');
|
132 |
bbc3533f
|
Scott Ullrich
|
|
133 |
416e1530
|
Darren Embry
|
/* build an interface collection */
|
134 |
f593f80b
|
Phil Davis
|
$ifdescrs = get_configured_interface_with_descr(true);
|
135 |
3f63e8e2
|
Darren Embry
|
$count = count($ifdescrs);
|
136 |
e173dd74
|
Phil Davis
|
|
137 |
|
|
/* grab interface that we will operate on, unless there is only one interface */
|
138 |
3f63e8e2
|
Darren Embry
|
if ($count > 1) {
|
139 |
416e1530
|
Darren Embry
|
echo "Available interfaces:\n\n";
|
140 |
|
|
$x=1;
|
141 |
e173dd74
|
Phil Davis
|
foreach ($ifdescrs as $iface => $ifdescr) {
|
142 |
0098aa73
|
Darren Embry
|
$config_descr = get_interface_config_description($iface);
|
143 |
|
|
echo "{$x} - {$ifdescr} ({$config_descr})\n";
|
144 |
416e1530
|
Darren Embry
|
$x++;
|
145 |
8dee794b
|
Scott Ullrich
|
}
|
146 |
416e1530
|
Darren Embry
|
echo "\nEnter the number of the interface you wish to configure: ";
|
147 |
e173dd74
|
Phil Davis
|
$intnum = chop(fgets($fp));
|
148 |
416e1530
|
Darren Embry
|
} else {
|
149 |
3f63e8e2
|
Darren Embry
|
$intnum = $count;
|
150 |
416e1530
|
Darren Embry
|
}
|
151 |
e173dd74
|
Phil Davis
|
|
152 |
086cf944
|
Phil Davis
|
if ($intnum < 1) {
|
153 |
9ea554ee
|
Ermal LUÇI
|
return;
|
154 |
086cf944
|
Phil Davis
|
}
|
155 |
|
|
if ($intnum > $count) {
|
156 |
9ea554ee
|
Ermal LUÇI
|
return;
|
157 |
086cf944
|
Phil Davis
|
}
|
158 |
e173dd74
|
Phil Davis
|
|
159 |
416e1530
|
Darren Embry
|
$index = 1;
|
160 |
|
|
foreach ($ifdescrs as $ifname => $ifdesc) {
|
161 |
6c07db48
|
Phil Davis
|
if ($intnum == $index) {
|
162 |
416e1530
|
Darren Embry
|
$interface = $ifname;
|
163 |
|
|
break;
|
164 |
|
|
} else {
|
165 |
|
|
$index++;
|
166 |
8dee794b
|
Scott Ullrich
|
}
|
167 |
e173dd74
|
Phil Davis
|
}
|
168 |
|
|
if (!$interface) {
|
169 |
416e1530
|
Darren Embry
|
echo "Invalid interface!\n";
|
170 |
9ea554ee
|
Ermal LUÇI
|
return;
|
171 |
416e1530
|
Darren Embry
|
}
|
172 |
aab5f04c
|
Ermal
|
|
173 |
416e1530
|
Darren Embry
|
$ifaceassigned = "";
|
174 |
c1361a9f
|
Darren Embry
|
|
175 |
b504ede5
|
Viktor Gurov
|
function next_unused_gateway_name($interface, $inet_type = 'inet') {
|
176 |
d23b53eb
|
Darren Embry
|
global $g, $config;
|
177 |
b504ede5
|
Viktor Gurov
|
|
178 |
|
|
if ($inet_type == 'inet') {
|
179 |
|
|
$name_suffix = "GW";
|
180 |
|
|
} else {
|
181 |
|
|
$name_suffix = "GWv6";
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
$new_name = strtoupper($interface) . $name_suffix;
|
185 |
d23b53eb
|
Darren Embry
|
|
186 |
e173dd74
|
Phil Davis
|
if (!is_array($config['gateways']['gateway_item'])) {
|
187 |
|
|
return $new_name;
|
188 |
|
|
}
|
189 |
d23b53eb
|
Darren Embry
|
$count = 1;
|
190 |
|
|
do {
|
191 |
|
|
$existing = false;
|
192 |
|
|
foreach ($config['gateways']['gateway_item'] as $item) {
|
193 |
|
|
if ($item['name'] === $new_name) {
|
194 |
|
|
$existing = true;
|
195 |
|
|
break;
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
if ($existing) {
|
199 |
|
|
$count += 1;
|
200 |
b504ede5
|
Viktor Gurov
|
$new_name = strtoupper($interface) . $name_suffix . "_" . $count;
|
201 |
d23b53eb
|
Darren Embry
|
}
|
202 |
|
|
} while ($existing);
|
203 |
|
|
return $new_name;
|
204 |
|
|
}
|
205 |
|
|
|
206 |
789f8b22
|
Viktor G
|
function add_gateway_to_config($interface, $gatewayip, $inet_type, $nonlocalgateway=false) {
|
207 |
d23b53eb
|
Darren Embry
|
global $g, $config, $dry_run;
|
208 |
c6c398c6
|
jim-p
|
init_config_arr(array('gateways', 'gateway_item'));
|
209 |
d23b53eb
|
Darren Embry
|
$a_gateways = &$config['gateways']['gateway_item'];
|
210 |
|
|
if ($dry_run) {
|
211 |
|
|
print_r($a_gateways);
|
212 |
|
|
}
|
213 |
9a15b8d2
|
Renato Botelho
|
$new_name = '';
|
214 |
d23b53eb
|
Darren Embry
|
foreach ($a_gateways as $item) {
|
215 |
|
|
if ($item['ipprotocol'] === $inet_type) {
|
216 |
e173dd74
|
Phil Davis
|
if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip)) {
|
217 |
9a15b8d2
|
Renato Botelho
|
$new_name = $item['name'];
|
218 |
e173dd74
|
Phil Davis
|
}
|
219 |
d23b53eb
|
Darren Embry
|
}
|
220 |
|
|
}
|
221 |
9a15b8d2
|
Renato Botelho
|
if ($new_name == '') {
|
222 |
b504ede5
|
Viktor Gurov
|
$new_name = next_unused_gateway_name($interface, $inet_type);
|
223 |
9a15b8d2
|
Renato Botelho
|
$item = array(
|
224 |
|
|
"interface" => $interface,
|
225 |
|
|
"gateway" => $gatewayip,
|
226 |
|
|
"name" => $new_name,
|
227 |
|
|
"weight" => 1,
|
228 |
|
|
"ipprotocol" => $inet_type,
|
229 |
|
|
"interval" => true,
|
230 |
43a9b03d
|
PiBa-NL
|
"descr" => "Interface $interface Gateway"
|
231 |
9a15b8d2
|
Renato Botelho
|
);
|
232 |
789f8b22
|
Viktor G
|
if ($nonlocalgateway) {
|
233 |
|
|
$item['nonlocalgateway'] = true;
|
234 |
|
|
}
|
235 |
9a15b8d2
|
Renato Botelho
|
if ($dry_run) {
|
236 |
|
|
print_r($item);
|
237 |
|
|
}
|
238 |
|
|
$a_gateways[] = $item;
|
239 |
d23b53eb
|
Darren Embry
|
}
|
240 |
28ad96a5
|
Stephen Jones
|
|
241 |
43a9b03d
|
PiBa-NL
|
//set the new GW as the default if there isnt one set yet
|
242 |
b187fcce
|
Christian McDonald
|
init_config_arr(array('gateways'));
|
243 |
13ae614b
|
jim-p
|
if (console_prompt_for_yn (gettext("Should this gateway be set as the default gateway?"))) {
|
244 |
|
|
if ($item['ipprotocol'] == "inet") {
|
245 |
|
|
config_set_path('gateways/defaultgw4', $new_name);
|
246 |
|
|
}
|
247 |
|
|
if ($item['ipprotocol'] == "inet6") {
|
248 |
|
|
config_set_path('gateways/defaultgw6', $new_name);
|
249 |
|
|
}
|
250 |
43a9b03d
|
PiBa-NL
|
}
|
251 |
9a15b8d2
|
Renato Botelho
|
|
252 |
|
|
return $new_name;
|
253 |
d23b53eb
|
Darren Embry
|
}
|
254 |
|
|
|
255 |
c1361a9f
|
Darren Embry
|
function console_configure_ip_address($version) {
|
256 |
|
|
global $g, $config, $interface, $restart_dhcpd, $ifaceassigned, $fp;
|
257 |
|
|
|
258 |
|
|
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
|
259 |
789f8b22
|
Viktor G
|
$maxbits = ($version === 6) ? 128 : 32;
|
260 |
c1361a9f
|
Darren Embry
|
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP";
|
261 |
|
|
|
262 |
|
|
$upperifname = strtoupper($interface);
|
263 |
|
|
|
264 |
13ae614b
|
jim-p
|
if (console_prompt_for_yn (sprintf(gettext('Configure %1$s address %2$s interface via %3$s?'), $label_IPvX, $upperifname, $label_DHCP))) {
|
265 |
|
|
$ifppp = console_get_interface_from_ppp(get_real_interface($interface));
|
266 |
|
|
if (!empty($ifppp)) {
|
267 |
|
|
$ifaceassigned = $ifppp;
|
268 |
e173dd74
|
Phil Davis
|
}
|
269 |
13ae614b
|
jim-p
|
$intip = ($version === 6) ? "dhcp6" : "dhcp";
|
270 |
|
|
$intbits = "";
|
271 |
|
|
$isintdhcp = true;
|
272 |
|
|
$restart_dhcpd = true;
|
273 |
416e1530
|
Darren Embry
|
}
|
274 |
e173dd74
|
Phil Davis
|
|
275 |
13ae614b
|
jim-p
|
if ($isintdhcp == false) {
|
276 |
e173dd74
|
Phil Davis
|
while (true) {
|
277 |
416e1530
|
Darren Embry
|
do {
|
278 |
1579e70f
|
Phil Davis
|
echo "\n" . sprintf(gettext('Enter the new %1$s %2$s address. Press <ENTER> for none:'),
|
279 |
e173dd74
|
Phil Davis
|
$upperifname, $label_IPvX) . "\n> ";
|
280 |
bebf0fa8
|
Renato Botelho
|
$intip = chop(fgets($fp));
|
281 |
c5a33683
|
Luiz Souza
|
$intbits_ok = false;
|
282 |
|
|
if (strstr($intip, "/")) {
|
283 |
|
|
list($intip, $intbits) = explode("/", $intip);
|
284 |
|
|
$intbits_ok = (is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits))) ? true : false;
|
285 |
|
|
}
|
286 |
bebf0fa8
|
Renato Botelho
|
$is_ipaddr = ($version === 6) ? is_ipaddrv6($intip) : is_ipaddrv4($intip);
|
287 |
|
|
if ($is_ipaddr && is_ipaddr_configured($intip, $interface, true)) {
|
288 |
|
|
$ip_conflict = true;
|
289 |
|
|
echo gettext("This IP address conflicts with another interface or a VIP") . "\n";
|
290 |
e173dd74
|
Phil Davis
|
} else {
|
291 |
bebf0fa8
|
Renato Botelho
|
$ip_conflict = false;
|
292 |
e173dd74
|
Phil Davis
|
}
|
293 |
bebf0fa8
|
Renato Botelho
|
} while (($ip_conflict === true) || !($is_ipaddr || $intip == ''));
|
294 |
c5a33683
|
Luiz Souza
|
if ($is_ipaddr && $intip != '') {
|
295 |
|
|
if ($intbits_ok == false) {
|
296 |
|
|
echo "\n" . sprintf(gettext("Subnet masks are entered as bit counts (as in CIDR notation) in %s."),
|
297 |
573ec19d
|
Renato Botelho do Couto
|
$g['product_label']) . "\n";
|
298 |
c5a33683
|
Luiz Souza
|
if ($version === 6) {
|
299 |
|
|
echo "e.g. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 = 120\n";
|
300 |
|
|
echo " ffff:ffff:ffff:ffff:ffff:ffff:ffff:0 = 112\n";
|
301 |
|
|
echo " ffff:ffff:ffff:ffff:ffff:ffff:0:0 = 96\n";
|
302 |
|
|
echo " ffff:ffff:ffff:ffff:ffff:0:0:0 = 80\n";
|
303 |
|
|
echo " ffff:ffff:ffff:ffff:0:0:0:0 = 64\n";
|
304 |
|
|
} else {
|
305 |
|
|
echo "e.g. 255.255.255.0 = 24\n";
|
306 |
|
|
echo " 255.255.0.0 = 16\n";
|
307 |
|
|
echo " 255.0.0.0 = 8\n";
|
308 |
|
|
}
|
309 |
bebf0fa8
|
Renato Botelho
|
}
|
310 |
c5a33683
|
Luiz Souza
|
while ($intbits_ok == false) {
|
311 |
bebf0fa8
|
Renato Botelho
|
$upperifname = strtoupper($interface);
|
312 |
1579e70f
|
Phil Davis
|
echo "\n" . sprintf(gettext('Enter the new %1$s %2$s subnet bit count (1 to %3$s):'),
|
313 |
e173dd74
|
Phil Davis
|
$upperifname, $label_IPvX, $maxbits) . "\n> ";
|
314 |
bebf0fa8
|
Renato Botelho
|
$intbits = chop(fgets($fp));
|
315 |
87657b95
|
Phil Davis
|
$intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits));
|
316 |
bebf0fa8
|
Renato Botelho
|
$restart_dhcpd = true;
|
317 |
|
|
|
318 |
|
|
if ($version === 4 && $intbits < $maxbits) {
|
319 |
|
|
if ($intip == gen_subnet($intip, $intbits)) {
|
320 |
|
|
echo gettext("You cannot set network address to an interface");
|
321 |
|
|
continue 2;
|
322 |
|
|
$intbits_ok = false;
|
323 |
|
|
} else if ($intip == gen_subnet_max($intip, $intbits)) {
|
324 |
|
|
echo gettext("You cannot set broadcast address to an interface");
|
325 |
|
|
continue 2;
|
326 |
|
|
$intbits_ok = false;
|
327 |
|
|
}
|
328 |
20dda766
|
Renato Botelho
|
}
|
329 |
c5a33683
|
Luiz Souza
|
}
|
330 |
bebf0fa8
|
Renato Botelho
|
|
331 |
|
|
if ($version === 6) {
|
332 |
|
|
$subnet = gen_subnetv6($intip, $intbits);
|
333 |
|
|
} else {
|
334 |
|
|
$subnet = gen_subnet($intip, $intbits);
|
335 |
20dda766
|
Renato Botelho
|
}
|
336 |
bebf0fa8
|
Renato Botelho
|
do {
|
337 |
1579e70f
|
Phil Davis
|
echo "\n" . sprintf(gettext('For a WAN, enter the new %1$s %2$s upstream gateway address.'), $upperifname, $label_IPvX) . "\n" .
|
338 |
974fb32c
|
Phillip Davis
|
gettext("For a LAN, press <ENTER> for none:") . "\n> ";
|
339 |
bebf0fa8
|
Renato Botelho
|
$gwip = chop(fgets($fp));
|
340 |
|
|
$is_ipaddr = ($version === 6) ? is_ipaddrv6($gwip) : is_ipaddrv4($gwip);
|
341 |
|
|
$is_in_subnet = $is_ipaddr && ip_in_subnet($gwip, $subnet . "/" . $intbits);
|
342 |
789f8b22
|
Viktor G
|
$nonlocalgateway = false;
|
343 |
bebf0fa8
|
Renato Botelho
|
if ($gwip != '') {
|
344 |
|
|
if (!$is_ipaddr) {
|
345 |
|
|
echo sprintf(gettext("not an %s IP address!"), $label_IPvX) . "\n";
|
346 |
|
|
} else if (!$is_in_subnet) {
|
347 |
789f8b22
|
Viktor G
|
$nonlocalgateway = true;
|
348 |
|
|
echo gettext("Non-local gateway detected.");
|
349 |
bebf0fa8
|
Renato Botelho
|
}
|
350 |
|
|
}
|
351 |
789f8b22
|
Viktor G
|
} while (!(empty($gwip) || $is_ipaddr));
|
352 |
c63e3594
|
Darren Embry
|
|
353 |
005a7049
|
Darren Embry
|
if ($gwip != '') {
|
354 |
bebf0fa8
|
Renato Botelho
|
$inet_type = ($version === 6) ? "inet6" : "inet";
|
355 |
789f8b22
|
Viktor G
|
$gwname = add_gateway_to_config($interface, $gwip, $inet_type, $nonlocalgateway);
|
356 |
c63e3594
|
Darren Embry
|
}
|
357 |
d23b53eb
|
Darren Embry
|
}
|
358 |
bebf0fa8
|
Renato Botelho
|
$ifppp = console_get_interface_from_ppp(get_real_interface($interface));
|
359 |
e173dd74
|
Phil Davis
|
if (!empty($ifppp)) {
|
360 |
bebf0fa8
|
Renato Botelho
|
$ifaceassigned = $ifppp;
|
361 |
e173dd74
|
Phil Davis
|
}
|
362 |
bebf0fa8
|
Renato Botelho
|
break;
|
363 |
5b237745
|
Scott Ullrich
|
}
|
364 |
416e1530
|
Darren Embry
|
}
|
365 |
5b237745
|
Scott Ullrich
|
|
366 |
9a15b8d2
|
Renato Botelho
|
return array($intip, $intbits, $gwname);
|
367 |
c1361a9f
|
Darren Embry
|
}
|
368 |
bbc3533f
|
Scott Ullrich
|
|
369 |
9a15b8d2
|
Renato Botelho
|
list($intip, $intbits, $gwname) = console_configure_ip_address(4);
|
370 |
|
|
list($intip6, $intbits6, $gwname6) = console_configure_ip_address(6);
|
371 |
bbc3533f
|
Scott Ullrich
|
|
372 |
e173dd74
|
Phil Davis
|
if (!empty($ifaceassigned)) {
|
373 |
416e1530
|
Darren Embry
|
$config['interfaces'][$interface]['if'] = $ifaceassigned;
|
374 |
e173dd74
|
Phil Davis
|
}
|
375 |
9a15b8d2
|
Renato Botelho
|
$config['interfaces'][$interface]['ipaddr'] = $intip;
|
376 |
|
|
$config['interfaces'][$interface]['subnet'] = $intbits;
|
377 |
|
|
$config['interfaces'][$interface]['gateway'] = $gwname;
|
378 |
|
|
$config['interfaces'][$interface]['ipaddrv6'] = $intip6;
|
379 |
|
|
$config['interfaces'][$interface]['subnetv6'] = $intbits6;
|
380 |
|
|
$config['interfaces'][$interface]['gatewayv6'] = $gwname6;
|
381 |
|
|
$config['interfaces'][$interface]['enable'] = true;
|
382 |
bbc3533f
|
Scott Ullrich
|
|
383 |
c1361a9f
|
Darren Embry
|
function console_configure_dhcpd($version = 4) {
|
384 |
5a997d96
|
Phil Davis
|
global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits, $intip6, $intbits6;
|
385 |
c1361a9f
|
Darren Embry
|
|
386 |
1f56ce58
|
Renato Botelho
|
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4";
|
387 |
|
|
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd";
|
388 |
c1361a9f
|
Darren Embry
|
|
389 |
e173dd74
|
Phil Davis
|
if ($g['services_dhcp_server_enable'] && prompt_for_enable_dhcp_server($version)) {
|
390 |
5a997d96
|
Phil Davis
|
$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
|
391 |
|
|
$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
|
392 |
c1361a9f
|
Darren Embry
|
do {
|
393 |
12f5a2d8
|
Phil Davis
|
do {
|
394 |
|
|
echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " ";
|
395 |
|
|
$dhcpstartip = chop(fgets($fp));
|
396 |
|
|
if ($dhcpstartip === "") {
|
397 |
|
|
fclose($fp);
|
398 |
9ea554ee
|
Ermal LUÇI
|
return 0;
|
399 |
12f5a2d8
|
Phil Davis
|
}
|
400 |
|
|
$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
|
401 |
|
|
$is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end);
|
402 |
e173dd74
|
Phil Davis
|
if (!$is_inrange) {
|
403 |
12f5a2d8
|
Phil Davis
|
echo gettext("This IP address must be in the interface's subnet") . "\n";
|
404 |
e173dd74
|
Phil Davis
|
}
|
405 |
12f5a2d8
|
Phil Davis
|
} while (!$is_ipaddr || !$is_inrange);
|
406 |
c1361a9f
|
Darren Embry
|
|
407 |
12f5a2d8
|
Phil Davis
|
do {
|
408 |
|
|
echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
|
409 |
|
|
$dhcpendip = chop(fgets($fp));
|
410 |
|
|
if ($dhcpendip === "") {
|
411 |
|
|
fclose($fp);
|
412 |
9ea554ee
|
Ermal LUÇI
|
return 0;
|
413 |
12f5a2d8
|
Phil Davis
|
}
|
414 |
|
|
$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
|
415 |
|
|
$is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
|
416 |
e173dd74
|
Phil Davis
|
if (!$is_inrange) {
|
417 |
12f5a2d8
|
Phil Davis
|
echo gettext("This IP address must be in the interface's subnet") . "\n";
|
418 |
e173dd74
|
Phil Davis
|
}
|
419 |
12f5a2d8
|
Phil Davis
|
$not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip);
|
420 |
|
|
if ($not_inorder) {
|
421 |
|
|
echo gettext("The end address of the DHCP range must be >= the start address") . "\n";
|
422 |
|
|
}
|
423 |
|
|
} while (!$is_ipaddr || !$is_inrange);
|
424 |
|
|
} while ($not_inorder);
|
425 |
c1361a9f
|
Darren Embry
|
$restart_dhcpd = true;
|
426 |
86fb2194
|
Renato Botelho
|
init_config_arr(array($dhcpd, $interface, 'range'));
|
427 |
c1361a9f
|
Darren Embry
|
$config[$dhcpd][$interface]['enable'] = true;
|
428 |
|
|
$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
|
429 |
|
|
$config[$dhcpd][$interface]['range']['to'] = $dhcpendip;
|
430 |
|
|
} else {
|
431 |
e173dd74
|
Phil Davis
|
if (isset($config[$dhcpd][$interface]['enable'])) {
|
432 |
c1361a9f
|
Darren Embry
|
unset($config[$dhcpd][$interface]['enable']);
|
433 |
ba667cc6
|
Phil Davis
|
$restart_dhcpd = true;
|
434 |
c63e3594
|
Darren Embry
|
}
|
435 |
1e1a9918
|
Viktor G
|
/* disable RA mode, see https://redmine.pfsense.org/issues/11609 */
|
436 |
|
|
if (isset($config[$dhcpd][$interface]['ramode']) &&
|
437 |
|
|
($config[$dhcpd][$interface]['ramode'] != 'disabled')) {
|
438 |
|
|
$config[$dhcpd][$interface]['ramode'] = 'disabled';
|
439 |
|
|
$restart_dhcpd = true;
|
440 |
|
|
}
|
441 |
|
|
if ($restart_dhcpd) {
|
442 |
|
|
printf(gettext("Disabling %s DHCPD...") . "\n", $label_IPvX);
|
443 |
|
|
}
|
444 |
c1361a9f
|
Darren Embry
|
}
|
445 |
eca5402b
|
Phil Davis
|
return 1;
|
446 |
416e1530
|
Darren Embry
|
}
|
447 |
bbc3533f
|
Scott Ullrich
|
|
448 |
086cf944
|
Phil Davis
|
if (console_configure_dhcpd(4) == 0) {
|
449 |
3377dc9d
|
Ermal LUÇI
|
return 0;
|
450 |
086cf944
|
Phil Davis
|
}
|
451 |
|
|
if (console_configure_dhcpd(6) == 0) {
|
452 |
3377dc9d
|
Ermal LUÇI
|
return 0;
|
453 |
086cf944
|
Phil Davis
|
}
|
454 |
e173dd74
|
Phil Davis
|
|
455 |
c1361a9f
|
Darren Embry
|
//*****************************************************************************
|
456 |
|
|
|
457 |
416e1530
|
Darren Embry
|
if ($config['system']['webgui']['protocol'] == "https") {
|
458 |
e6abcccc
|
Phil Davis
|
if (console_prompt_for_yn (gettext("Do you want to revert to HTTP as the webConfigurator protocol?"))) {
|
459 |
416e1530
|
Darren Embry
|
$config['system']['webgui']['protocol'] = "http";
|
460 |
|
|
$restart_webgui = true;
|
461 |
01d72b37
|
Scott Ullrich
|
}
|
462 |
416e1530
|
Darren Embry
|
}
|
463 |
bbc3533f
|
Scott Ullrich
|
|
464 |
81777072
|
Christian McDonald
|
if (config_path_enabled('system/webgui', 'noantilockout')) {
|
465 |
005a7049
|
Darren Embry
|
echo "\n" . sprintf(gettext("Note: the anti-lockout rule on %s has been re-enabled."), $interface) . "\n";
|
466 |
81777072
|
Christian McDonald
|
config_del_path('system/webgui/noantilockout');
|
467 |
416e1530
|
Darren Embry
|
}
|
468 |
bbc3533f
|
Scott Ullrich
|
|
469 |
81777072
|
Christian McDonald
|
if (config_get_path('interfaces/lan')) {
|
470 |
|
|
$paths = ['dhcpd/wan', 'dhcpdv6/wan'];
|
471 |
|
|
foreach ($paths as $path) {
|
472 |
|
|
if (config_get_path($path)) {
|
473 |
|
|
config_del_path($path);
|
474 |
e173dd74
|
Phil Davis
|
}
|
475 |
81777072
|
Christian McDonald
|
}
|
476 |
416e1530
|
Darren Embry
|
}
|
477 |
68ad6d22
|
Scott Ullrich
|
|
478 |
81777072
|
Christian McDonald
|
if (!config_get_path('interfaces/lan')) {
|
479 |
|
|
$paths = ['interfaces/lan', 'dhcpd/lan', 'dhcpdv6/lan',
|
480 |
|
|
'shaper', 'ezshaper', 'nat'];
|
481 |
|
|
foreach ($paths as $path) {
|
482 |
|
|
if (config_get_path($path)) {
|
483 |
|
|
config_del_path($path);
|
484 |
|
|
}
|
485 |
|
|
}
|
486 |
|
|
if (!$dry_run) {
|
487 |
c63e3594
|
Darren Embry
|
system("rm /var/dhcpd/var/db/* >/dev/null 2>/dev/null");
|
488 |
ba667cc6
|
Phil Davis
|
$restart_dhcpd = true;
|
489 |
81777072
|
Christian McDonald
|
}
|
490 |
416e1530
|
Darren Embry
|
}
|
491 |
68ad6d22
|
Scott Ullrich
|
|
492 |
416e1530
|
Darren Embry
|
$upperifname = strtoupper($interface);
|
493 |
c63e3594
|
Darren Embry
|
if (!$dry_run) {
|
494 |
|
|
echo "\nPlease wait while the changes are saved to {$upperifname}...";
|
495 |
1b8bf24d
|
Darren Embry
|
write_config(sprintf(gettext("%s IP configuration from console menu"), $interface));
|
496 |
772e14a2
|
Viktor G
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard")) {
|
497 |
|
|
// if any of the interfaces is manually configured, it means that the assignment is OK
|
498 |
|
|
touch("{$g['conf_path']}/assign_complete");
|
499 |
|
|
}
|
500 |
c63e3594
|
Darren Embry
|
interface_reconfigure(strtolower($upperifname));
|
501 |
8727b3c8
|
Phil Davis
|
echo "\n Reloading filter...";
|
502 |
c63e3594
|
Darren Embry
|
filter_configure_sync();
|
503 |
8ce04d22
|
Chris Buechler
|
echo "\n Reloading routing configuration...";
|
504 |
|
|
system_routing_configure();
|
505 |
e173dd74
|
Phil Davis
|
if ($restart_dhcpd) {
|
506 |
|
|
echo "\n DHCPD...";
|
507 |
c63e3594
|
Darren Embry
|
services_dhcpd_configure();
|
508 |
|
|
}
|
509 |
e173dd74
|
Phil Davis
|
if ($restart_webgui) {
|
510 |
8727b3c8
|
Phil Davis
|
echo "\n Restarting webConfigurator... ";
|
511 |
c63e3594
|
Darren Embry
|
mwexec("/etc/rc.restart_webgui");
|
512 |
|
|
}
|
513 |
416e1530
|
Darren Embry
|
}
|
514 |
e173dd74
|
Phil Davis
|
|
515 |
416e1530
|
Darren Embry
|
if ($intip != '') {
|
516 |
|
|
if (is_ipaddr($intip)) {
|
517 |
1579e70f
|
Phil Davis
|
$intipstr = "{$intip}/{$intbits}";
|
518 |
416e1530
|
Darren Embry
|
} else {
|
519 |
1579e70f
|
Phil Davis
|
$intipstr = $intip;
|
520 |
416e1530
|
Darren Embry
|
}
|
521 |
1579e70f
|
Phil Davis
|
echo "\n\n" . sprintf(gettext('The IPv4 %1$s address has been set to %2$s'), $upperifname, $intipstr) . "\n";
|
522 |
c1361a9f
|
Darren Embry
|
}
|
523 |
|
|
if ($intip6 != '') {
|
524 |
|
|
if (is_ipaddr($intip6)) {
|
525 |
1579e70f
|
Phil Davis
|
$intip6str = "${intip6}/${intbits6}";
|
526 |
c1361a9f
|
Darren Embry
|
} else {
|
527 |
1579e70f
|
Phil Davis
|
$intip6str = $intip6;
|
528 |
c1361a9f
|
Darren Embry
|
}
|
529 |
1579e70f
|
Phil Davis
|
echo "\n\n" . sprintf(gettext('The IPv6 %1$s address has been set to %2$s'), $upperifname, $intip6str) . "\n";
|
530 |
c1361a9f
|
Darren Embry
|
}
|
531 |
|
|
|
532 |
|
|
if ($intip != '' || $intip6 != '') {
|
533 |
13ae614b
|
jim-p
|
if ((count($ifdescrs) == "1") ||
|
534 |
|
|
(!interface_has_gateway($interface) && !interface_has_gatewayv6($interface))) {
|
535 |
416e1530
|
Darren Embry
|
if ($debug) {
|
536 |
|
|
echo "ifdescrs count is " . count($ifdescrs) . "\n";
|
537 |
|
|
echo "interface is {$interface} \n";
|
538 |
db747fb1
|
Chris Buechler
|
}
|
539 |
416e1530
|
Darren Embry
|
echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n";
|
540 |
e173dd74
|
Phil Davis
|
if (!empty($config['system']['webgui']['port'])) {
|
541 |
416e1530
|
Darren Embry
|
$webuiport = $config['system']['webgui']['port'];
|
542 |
b3cb233f
|
Darren Embry
|
if ($intip != '') {
|
543 |
d71371bc
|
Darren Embry
|
echo " {$config['system']['webgui']['protocol']}://{$intip}:{$webuiport}/\n";
|
544 |
b3cb233f
|
Darren Embry
|
}
|
545 |
|
|
if ($intip6 != '') {
|
546 |
|
|
if (is_ipaddr($intip6)) {
|
547 |
d71371bc
|
Darren Embry
|
echo " {$config['system']['webgui']['protocol']}://[{$intip6}]:{$webuiport}/\n";
|
548 |
b3cb233f
|
Darren Embry
|
} else {
|
549 |
d71371bc
|
Darren Embry
|
echo " {$config['system']['webgui']['protocol']}://{$intip6}:{$webuiport}/\n";
|
550 |
b3cb233f
|
Darren Embry
|
}
|
551 |
|
|
}
|
552 |
416e1530
|
Darren Embry
|
} else {
|
553 |
b3cb233f
|
Darren Embry
|
if ($intip != '') {
|
554 |
|
|
echo " {$config['system']['webgui']['protocol']}://{$intip}/\n";
|
555 |
|
|
}
|
556 |
|
|
if ($intip6 != '') {
|
557 |
|
|
if (is_ipaddr($intip6)) {
|
558 |
|
|
echo " {$config['system']['webgui']['protocol']}://[{$intip6}]/\n";
|
559 |
|
|
} else {
|
560 |
|
|
echo " {$config['system']['webgui']['protocol']}://{$intip6}/\n";
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
35380504
|
Seth Mos
|
}
|
564 |
8dee794b
|
Scott Ullrich
|
}
|
565 |
416e1530
|
Darren Embry
|
}
|
566 |
5b237745
|
Scott Ullrich
|
|
567 |
416e1530
|
Darren Embry
|
echo "\n" . gettext('Press <ENTER> to continue.');
|
568 |
5b237745
|
Scott Ullrich
|
|
569 |
416e1530
|
Darren Embry
|
fgets($fp);
|
570 |
|
|
fclose($fp);
|
571 |
e173dd74
|
Phil Davis
|
|
572 |
9b2e42c9
|
Ermal
|
?>
|