Project

General

Profile

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