Project

General

Profile

Download (17.9 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -q
2 5b237745 Scott Ullrich
<?php
3
/*
4 8acd654a Renato Botelho
 * rc.initial.setlanip
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
8 8acd654a Renato Botelho
 * All rights reserved.
9
 *
10
 * originally part of m0n0wall (http://m0n0.ch/wall)
11 aaec5634 Renato Botelho
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12 8acd654a Renato Botelho
 * All rights reserved.
13
 *
14
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16
 *
17
 * 1. Redistributions of source code must retain the above copyright notice,
18
 *    this list of conditions and the following disclaimer.
19
 *
20
 * 2. Redistributions in binary form must reproduce the above copyright
21
 *    notice, this list of conditions and the following disclaimer in
22
 *    the documentation and/or other materials provided with the
23
 *    distribution.
24
 *
25
 * 3. All advertising materials mentioning features or use of this software
26
 *    must display the following acknowledgment:
27
 *    "This product includes software developed by the pfSense Project
28
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
29
 *
30
 * 4. The names "pfSense" and "pfSense Project" must not be used to
31
 *    endorse or promote products derived from this software without
32
 *    prior written permission. For written permission, please contact
33
 *    coreteam@pfsense.org.
34
 *
35
 * 5. Products derived from this software may not be called "pfSense"
36
 *    nor may "pfSense" appear in their names without prior written
37
 *    permission of the Electric Sheep Fencing, LLC.
38
 *
39
 * 6. Redistributions of any form whatsoever must retain the following
40
 *    acknowledgment:
41
 *
42
 * "This product includes software developed by the pfSense Project
43
 * for use in the pfSense software distribution (http://www.pfsense.org/).
44
 *
45
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
46
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
49
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
56
 * OF THE POSSIBILITY OF SUCH DAMAGE.
57
 */
58 5b237745 Scott Ullrich
59 c63e3594 Darren Embry
$options = getopt("hn", array("dry-run", "help"));
60
61
if (isset($options["h"]) || isset($options["help"])) {
62
	echo "usage: /etc/rc.initial.setlanip [option ...]\n";
63
	echo "  -h, --help       show this message\n";
64
	echo "  -n, --dry-run    do not make any configuration changes\n";
65 9ea554ee Ermal LUÇI
	return 0;
66 c63e3594 Darren Embry
}
67
68
$dry_run = isset($options["n"]) || isset($options["dry-run"]);
69
if ($dry_run) {
70
	echo "DRY RUN MODE IS ON\n";
71
}
72
73 416e1530 Darren Embry
/* parse the configuration and include all functions used below */
74
require_once("config.inc");
75
require_once("functions.inc");
76
require_once("filter.inc");
77
require_once("shaper.inc");
78
require_once("rrd.inc");
79 bbc3533f Scott Ullrich
80 e6abcccc Phil Davis
function console_prompt_for_yn ($prompt_text) {
81
	global $fp;
82
83
	$good_answer = false;
84
85
	do {
86
		echo "\n" . $prompt_text . " (y/n) ";
87
		$yn = strtolower(chop(fgets($fp)));
88
		if (($yn == "y") || ($yn == "yes")) {
89
			$boolean_answer = true;
90
			$good_answer = true;
91
		}
92
		if (($yn == "n") || ($yn == "no")) {
93
			$boolean_answer = false;
94
			$good_answer = true;
95
		}
96
	} while (!$good_answer);
97
98
	return $boolean_answer;
99
}
100
101 416e1530 Darren Embry
function console_get_interface_from_ppp($realif) {
102
	global $config;
103 aab5f04c Ermal
104 416e1530 Darren Embry
	if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
105
		foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
106
			if ($realif == $ppp['if']) {
107
				$ifaces = explode(",", $ppp['ports']);
108
				return $ifaces[0];
109 aab5f04c Ermal
			}
110
		}
111
	}
112
113 416e1530 Darren Embry
	return "";
114
}
115
116 c1361a9f Darren Embry
function prompt_for_enable_dhcp_server($version = 4) {
117 416e1530 Darren Embry
	global $config, $fp, $interface;
118 e173dd74 Phil Davis
	if ($interface == "wan") {
119
		if ($config['interfaces']['lan']) {
120 e6abcccc Phil Davis
			return false;
121 e173dd74 Phil Davis
		}
122 416e1530 Darren Embry
	}
123
	/* only allow DHCP server to be enabled when static IP is
124
	   configured on this interface */
125 c1361a9f Darren Embry
	if ($version === 6) {
126
		$is_ipaddr = is_ipaddrv6($config['interfaces'][$interface]['ipaddrv6']);
127
	} else {
128
		$is_ipaddr = is_ipaddrv4($config['interfaces'][$interface]['ipaddr']);
129
	}
130 e6abcccc Phil Davis
	if (!($is_ipaddr)) {
131
		return false;
132 e1454e42 Scott Ullrich
	}
133 e6abcccc Phil Davis
134
	$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP";
135
	$upperifname = strtoupper($interface);
136
	return console_prompt_for_yn (sprintf(gettext("Do you want to enable the %s server on %s?"), $label_DHCP, $upperifname));
137 416e1530 Darren Embry
}
138 e1454e42 Scott Ullrich
139 0098aa73 Darren Embry
function get_interface_config_description($iface) {
140
	global $config;
141
	$c = $config['interfaces'][$iface];
142 086cf944 Phil Davis
	if (!$c) {
143
		return null;
144 e173dd74 Phil Davis
	}
145 0098aa73 Darren Embry
	$if = $c['if'];
146
	$result = $if;
147
	$result2 = array();
148
	$ipaddr = $c['ipaddr'];
149
	$ipaddrv6 = $c['ipaddrv6'];
150
	if (is_ipaddr($ipaddr)) {
151
		$result2[] = "static";
152
	} else if ($ipaddr == "dhcp") {
153
		$result2[] = "dhcp";
154
	}
155
	if (is_ipaddr($ipaddrv6)) {
156
		$result2[] = "staticv6";
157
	} else if ($ipaddrv6 == "dhcp6") {
158
		$result2[] = "dhcp6";
159
	}
160
	if (count($result2)) {
161
		$result .= " - " . implode(", ", $result2);
162
	}
163
	return $result;
164
}
165
166 416e1530 Darren Embry
$fp = fopen('php://stdin', 'r');
167 bbc3533f Scott Ullrich
168 416e1530 Darren Embry
/* build an interface collection */
169
$ifdescrs = get_configured_interface_with_descr(false, true);
170 3f63e8e2 Darren Embry
$count = count($ifdescrs);
171 e173dd74 Phil Davis
172
/* grab interface that we will operate on, unless there is only one interface */
173 3f63e8e2 Darren Embry
if ($count > 1) {
174 416e1530 Darren Embry
	echo "Available interfaces:\n\n";
175
	$x=1;
176 e173dd74 Phil Davis
	foreach ($ifdescrs as $iface => $ifdescr) {
177 0098aa73 Darren Embry
		$config_descr = get_interface_config_description($iface);
178
		echo "{$x} - {$ifdescr} ({$config_descr})\n";
179 416e1530 Darren Embry
		$x++;
180 8dee794b Scott Ullrich
	}
181 416e1530 Darren Embry
	echo "\nEnter the number of the interface you wish to configure: ";
182 e173dd74 Phil Davis
	$intnum = chop(fgets($fp));
183 416e1530 Darren Embry
} else {
184 3f63e8e2 Darren Embry
	$intnum = $count;
185 416e1530 Darren Embry
}
186 e173dd74 Phil Davis
187 086cf944 Phil Davis
if ($intnum < 1) {
188 9ea554ee Ermal LUÇI
	return;
189 086cf944 Phil Davis
}
190
if ($intnum > $count) {
191 9ea554ee Ermal LUÇI
	return;
192 086cf944 Phil Davis
}
193 e173dd74 Phil Davis
194 416e1530 Darren Embry
$index = 1;
195
foreach ($ifdescrs as $ifname => $ifdesc) {
196 6c07db48 Phil Davis
	if ($intnum == $index) {
197 416e1530 Darren Embry
		$interface = $ifname;
198
		break;
199
	} else {
200
		$index++;
201 8dee794b Scott Ullrich
	}
202 e173dd74 Phil Davis
}
203
if (!$interface) {
204 416e1530 Darren Embry
	echo "Invalid interface!\n";
205 9ea554ee Ermal LUÇI
	return;
206 416e1530 Darren Embry
}
207 aab5f04c Ermal
208 416e1530 Darren Embry
$ifaceassigned = "";
209 c1361a9f Darren Embry
210 d23b53eb Darren Embry
function next_unused_gateway_name($interface) {
211
	global $g, $config;
212
	$new_name = "GW_" . strtoupper($interface);
213
214 e173dd74 Phil Davis
	if (!is_array($config['gateways']['gateway_item'])) {
215
		return $new_name;
216
	}
217 d23b53eb Darren Embry
	$count = 1;
218
	do {
219
		$existing = false;
220
		foreach ($config['gateways']['gateway_item'] as $item) {
221
			if ($item['name'] === $new_name) {
222
				$existing = true;
223
				break;
224
			}
225
		}
226
		if ($existing) {
227
			$count += 1;
228
			$new_name = "GW_" . strtoupper($interface) . "_" . $count;
229
		}
230
	} while ($existing);
231
	return $new_name;
232
}
233
234
function add_gateway_to_config($interface, $gatewayip, $inet_type) {
235
	global $g, $config, $dry_run;
236
	if (!is_array($config['gateways']['gateway_item'])) {
237
		$config['gateways']['gateway_item'] = array();
238
	}
239
	$a_gateways = &$config['gateways']['gateway_item'];
240
	if ($dry_run) {
241
		print_r($a_gateways);
242
	}
243 9a15b8d2 Renato Botelho
	$new_name = '';
244 d23b53eb Darren Embry
	$is_default = true;
245
	foreach ($a_gateways as $item) {
246
		if ($item['ipprotocol'] === $inet_type) {
247 e173dd74 Phil Davis
			if (isset($item['defaultgw'])) {
248 9a15b8d2 Renato Botelho
				$is_default = false;
249 e173dd74 Phil Davis
			}
250
			if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip)) {
251 9a15b8d2 Renato Botelho
				$new_name = $item['name'];
252 e173dd74 Phil Davis
			}
253 d23b53eb Darren Embry
		}
254
	}
255 9a15b8d2 Renato Botelho
	if ($new_name == '') {
256
		$new_name = next_unused_gateway_name($interface);
257
		$item = array(
258
			"interface" => $interface,
259
			"gateway" => $gatewayip,
260
			"name" => $new_name,
261
			"weight" => 1,
262
			"ipprotocol" => $inet_type,
263
			"interval" => true,
264
			"descr" => "Interface $interface Gateway",
265
			"defaultgw" => $is_default
266
		);
267
		if ($dry_run) {
268
			print_r($item);
269
		}
270
		$a_gateways[] = $item;
271 d23b53eb Darren Embry
	}
272 9a15b8d2 Renato Botelho
273
	return $new_name;
274 d23b53eb Darren Embry
}
275
276 c1361a9f Darren Embry
function console_configure_ip_address($version) {
277
	global $g, $config, $interface, $restart_dhcpd, $ifaceassigned, $fp;
278
279
	$label_IPvX = ($version === 6) ? "IPv6"   : "IPv4";
280
	$maxbits    = ($version === 6) ? 127      : 31;
281
	$label_DHCP = ($version === 6) ? "DHCP6"  : "DHCP";
282
283
	$upperifname = strtoupper($interface);
284
285 e173dd74 Phil Davis
	if ($interface == "wan") {
286 e6abcccc Phil Davis
		if (console_prompt_for_yn (sprintf(gettext("Configure %s address %s interface via %s?"), $label_IPvX, $upperifname, $label_DHCP))) {
287 aab5f04c Ermal
			$ifppp = console_get_interface_from_ppp(get_real_interface("wan"));
288 e173dd74 Phil Davis
			if (!empty($ifppp)) {
289 aab5f04c Ermal
				$ifaceassigned = $ifppp;
290 e173dd74 Phil Davis
			}
291 c1361a9f Darren Embry
			$intip = ($version === 6) ? "dhcp6" : "dhcp";
292 416e1530 Darren Embry
			$intbits = "";
293
			$isintdhcp = true;
294
			$restart_dhcpd = true;
295 e173dd74 Phil Davis
		}
296 416e1530 Darren Embry
	}
297 e173dd74 Phil Davis
298
	if ($isintdhcp == false or $interface <> "wan") {
299
		while (true) {
300 416e1530 Darren Embry
			do {
301 bebf0fa8 Renato Botelho
				echo "\n" . sprintf(gettext("Enter the new %s %s address.  Press <ENTER> for none:"),
302 e173dd74 Phil Davis
							$upperifname, $label_IPvX) . "\n> ";
303 bebf0fa8 Renato Botelho
				$intip = chop(fgets($fp));
304
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($intip) : is_ipaddrv4($intip);
305
				if ($is_ipaddr && is_ipaddr_configured($intip, $interface, true)) {
306
					$ip_conflict = true;
307
					echo gettext("This IP address conflicts with another interface or a VIP") . "\n";
308 e173dd74 Phil Davis
				} else {
309 bebf0fa8 Renato Botelho
					$ip_conflict = false;
310 e173dd74 Phil Davis
				}
311 bebf0fa8 Renato Botelho
			} while (($ip_conflict === true) || !($is_ipaddr || $intip == ''));
312
			if ($intip != '') {
313
				echo "\n" . sprintf(gettext("Subnet masks are entered as bit counts (as in CIDR notation) in %s."),
314 e173dd74 Phil Davis
							$g['product_name']) . "\n";
315 bebf0fa8 Renato Botelho
				if ($version === 6) {
316
					echo "e.g. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 = 120\n";
317
					echo "     ffff:ffff:ffff:ffff:ffff:ffff:ffff:0    = 112\n";
318
					echo "     ffff:ffff:ffff:ffff:ffff:ffff:0:0       =  96\n";
319
					echo "     ffff:ffff:ffff:ffff:ffff:0:0:0          =  80\n";
320
					echo "     ffff:ffff:ffff:ffff:0:0:0:0             =  64\n";
321
				} else {
322
					echo "e.g. 255.255.255.0 = 24\n";
323
					echo "     255.255.0.0   = 16\n";
324
					echo "     255.0.0.0     = 8\n";
325
				}
326
				do {
327
					$upperifname = strtoupper($interface);
328 e6abcccc Phil Davis
					echo "\n" . sprintf(gettext("Enter the new %s %s subnet bit count (1 to %s):"),
329 e173dd74 Phil Davis
								$upperifname, $label_IPvX, $maxbits) . "\n> ";
330 bebf0fa8 Renato Botelho
					$intbits = chop(fgets($fp));
331 87657b95 Phil Davis
					$intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits));
332 bebf0fa8 Renato Botelho
					$restart_dhcpd = true;
333
334
					if ($version === 4 && $intbits < $maxbits) {
335
						if ($intip == gen_subnet($intip, $intbits)) {
336
							echo gettext("You cannot set network address to an interface");
337
							continue 2;
338
							$intbits_ok = false;
339
						} else if ($intip == gen_subnet_max($intip, $intbits)) {
340
							echo gettext("You cannot set broadcast address to an interface");
341
							continue 2;
342
							$intbits_ok = false;
343
						}
344 20dda766 Renato Botelho
					}
345 bebf0fa8 Renato Botelho
				} while (!$intbits_ok);
346
347
				if ($version === 6) {
348
					$subnet = gen_subnetv6($intip, $intbits);
349
				} else {
350
					$subnet = gen_subnet($intip, $intbits);
351 20dda766 Renato Botelho
				}
352 bebf0fa8 Renato Botelho
				do {
353 974fb32c Phillip Davis
					echo "\n" . sprintf(gettext("For a WAN, enter the new %s %s upstream gateway address."), $upperifname, $label_IPvX) . "\n" .
354
								gettext("For a LAN, press <ENTER> for none:") . "\n> ";
355 bebf0fa8 Renato Botelho
					$gwip = chop(fgets($fp));
356
					$is_ipaddr = ($version === 6) ? is_ipaddrv6($gwip) : is_ipaddrv4($gwip);
357
					$is_in_subnet = $is_ipaddr && ip_in_subnet($gwip, $subnet . "/" . $intbits);
358
					if ($gwip != '') {
359
						if (!$is_ipaddr) {
360
							echo sprintf(gettext("not an %s IP address!"), $label_IPvX) . "\n";
361
						} else if (!$is_in_subnet) {
362
							echo gettext("not in subnet!") . "\n";
363
						}
364
					}
365
				} while (!($gwip == '' || ($is_ipaddr && $is_in_subnet)));
366 c63e3594 Darren Embry
367 005a7049 Darren Embry
				if ($gwip != '') {
368 bebf0fa8 Renato Botelho
					$inet_type = ($version === 6) ? "inet6" : "inet";
369
					$gwname = add_gateway_to_config($interface, $gwip, $inet_type);
370 c63e3594 Darren Embry
				}
371 d23b53eb Darren Embry
			}
372 bebf0fa8 Renato Botelho
			$ifppp = console_get_interface_from_ppp(get_real_interface($interface));
373 e173dd74 Phil Davis
			if (!empty($ifppp)) {
374 bebf0fa8 Renato Botelho
				$ifaceassigned = $ifppp;
375 e173dd74 Phil Davis
			}
376 bebf0fa8 Renato Botelho
			break;
377 5b237745 Scott Ullrich
		}
378 416e1530 Darren Embry
	}
379 5b237745 Scott Ullrich
380 9a15b8d2 Renato Botelho
	return array($intip, $intbits, $gwname);
381 c1361a9f Darren Embry
}
382 bbc3533f Scott Ullrich
383 9a15b8d2 Renato Botelho
list($intip,  $intbits,  $gwname)  = console_configure_ip_address(4);
384
list($intip6, $intbits6, $gwname6) = console_configure_ip_address(6);
385 bbc3533f Scott Ullrich
386 e173dd74 Phil Davis
if (!empty($ifaceassigned)) {
387 416e1530 Darren Embry
	$config['interfaces'][$interface]['if'] = $ifaceassigned;
388 e173dd74 Phil Davis
}
389 9a15b8d2 Renato Botelho
$config['interfaces'][$interface]['ipaddr']    = $intip;
390
$config['interfaces'][$interface]['subnet']    = $intbits;
391
$config['interfaces'][$interface]['gateway']   = $gwname;
392
$config['interfaces'][$interface]['ipaddrv6']  = $intip6;
393
$config['interfaces'][$interface]['subnetv6']  = $intbits6;
394
$config['interfaces'][$interface]['gatewayv6'] = $gwname6;
395
$config['interfaces'][$interface]['enable']    = true;
396 bbc3533f Scott Ullrich
397 c1361a9f Darren Embry
function console_configure_dhcpd($version = 4) {
398 5a997d96 Phil Davis
	global $g, $config, $restart_dhcpd, $fp, $interface, $dry_run, $intip, $intbits, $intip6, $intbits6;
399 c1361a9f Darren Embry
400 1f56ce58 Renato Botelho
	$label_IPvX = ($version === 6) ? "IPv6"    : "IPv4";
401
	$dhcpd      = ($version === 6) ? "dhcpdv6" : "dhcpd";
402 c1361a9f Darren Embry
403 e173dd74 Phil Davis
	if ($g['services_dhcp_server_enable'] && prompt_for_enable_dhcp_server($version)) {
404 5a997d96 Phil Davis
		$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
405
		$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
406 c1361a9f Darren Embry
		do {
407 12f5a2d8 Phil Davis
			do {
408
				echo sprintf(gettext("Enter the start address of the %s client address range:"), $label_IPvX) . " ";
409
				$dhcpstartip = chop(fgets($fp));
410
				if ($dhcpstartip === "") {
411
					fclose($fp);
412 9ea554ee Ermal LUÇI
					return 0;
413 12f5a2d8 Phil Davis
				}
414
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
415
				$is_inrange = is_inrange($dhcpstartip, $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
			} while (!$is_ipaddr || !$is_inrange);
420 c1361a9f Darren Embry
421 12f5a2d8 Phil Davis
			do {
422
				echo sprintf(gettext("Enter the end address of the %s client address range:"), $label_IPvX) . " ";
423
				$dhcpendip = chop(fgets($fp));
424
				if ($dhcpendip === "") {
425
					fclose($fp);
426 9ea554ee Ermal LUÇI
					return 0;
427 12f5a2d8 Phil Davis
				}
428
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
429
				$is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
430 e173dd74 Phil Davis
				if (!$is_inrange) {
431 12f5a2d8 Phil Davis
					echo gettext("This IP address must be in the interface's subnet") . "\n";
432 e173dd74 Phil Davis
				}
433 12f5a2d8 Phil Davis
				$not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip);
434
				if ($not_inorder) {
435
					echo gettext("The end address of the DHCP range must be >= the start address") . "\n";
436
				}
437
			} while (!$is_ipaddr || !$is_inrange);
438
		} while ($not_inorder);
439 c1361a9f Darren Embry
		$restart_dhcpd = true;
440
		$config[$dhcpd][$interface]['enable'] = true;
441
		$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
442
		$config[$dhcpd][$interface]['range']['to'] = $dhcpendip;
443
	} else {
444 e173dd74 Phil Davis
		if (isset($config[$dhcpd][$interface]['enable'])) {
445 c1361a9f Darren Embry
			unset($config[$dhcpd][$interface]['enable']);
446 ba667cc6 Phil Davis
			printf(gettext("Disabling %s DHCPD..."), $label_IPvX);
447
			$restart_dhcpd = true;
448 c63e3594 Darren Embry
		}
449 c1361a9f Darren Embry
	}
450 eca5402b Phil Davis
	return 1;
451 416e1530 Darren Embry
}
452 bbc3533f Scott Ullrich
453 086cf944 Phil Davis
if (console_configure_dhcpd(4) == 0) {
454 3377dc9d Ermal LUÇI
	return 0;
455 086cf944 Phil Davis
}
456
if (console_configure_dhcpd(6) == 0) {
457 3377dc9d Ermal LUÇI
	return 0;
458 086cf944 Phil Davis
}
459 e173dd74 Phil Davis
460 c1361a9f Darren Embry
//*****************************************************************************
461
462 416e1530 Darren Embry
if ($config['system']['webgui']['protocol'] == "https") {
463 01d72b37 Scott Ullrich
464 e6abcccc Phil Davis
	if (console_prompt_for_yn (gettext("Do you want to revert to HTTP as the webConfigurator protocol?"))) {
465 416e1530 Darren Embry
		$config['system']['webgui']['protocol'] = "http";
466
		$restart_webgui = true;
467 01d72b37 Scott Ullrich
	}
468 416e1530 Darren Embry
}
469 bbc3533f Scott Ullrich
470 416e1530 Darren Embry
if (isset($config['system']['webgui']['noantilockout'])) {
471 005a7049 Darren Embry
	echo "\n" . sprintf(gettext("Note: the anti-lockout rule on %s has been re-enabled."), $interface) . "\n";
472 416e1530 Darren Embry
	unset($config['system']['webgui']['noantilockout']);
473
}
474 bbc3533f Scott Ullrich
475 e173dd74 Phil Davis
if ($config['interfaces']['lan']) {
476
	if ($config['dhcpd']) {
477
		if ($config['dhcpd']['wan']) {
478
			unset($config['dhcpd']['wan']);
479
		}
480
	}
481
	if ($config['dhcpdv6']) {
482
		if ($config['dhcpdv6']['wan']) {
483 1f56ce58 Renato Botelho
			unset($config['dhcpdv6']['wan']);
484 e173dd74 Phil Davis
		}
485
	}
486 416e1530 Darren Embry
}
487 68ad6d22 Scott Ullrich
488 e173dd74 Phil Davis
if (!$config['interfaces']['lan']) {
489 416e1530 Darren Embry
	unset($config['interfaces']['lan']);
490 e173dd74 Phil Davis
	if ($config['dhcpd']['lan']) {
491 416e1530 Darren Embry
		unset($config['dhcpd']['lan']);
492 e173dd74 Phil Davis
	}
493
	if ($config['dhcpdv6']['lan']) {
494 1f56ce58 Renato Botelho
		unset($config['dhcpdv6']['lan']);
495 e173dd74 Phil Davis
	}
496 416e1530 Darren Embry
	unset($config['shaper']);
497
	unset($config['ezshaper']);
498
	unset($config['nat']);
499 c63e3594 Darren Embry
	if (!$dry_run) {
500
		system("rm /var/dhcpd/var/db/* >/dev/null 2>/dev/null");
501 ba667cc6 Phil Davis
		$restart_dhcpd = true;
502 c63e3594 Darren Embry
	}
503 416e1530 Darren Embry
}
504 68ad6d22 Scott Ullrich
505 416e1530 Darren Embry
$upperifname = strtoupper($interface);
506 c63e3594 Darren Embry
if (!$dry_run) {
507
	echo "\nPlease wait while the changes are saved to {$upperifname}...";
508 1b8bf24d Darren Embry
	write_config(sprintf(gettext("%s IP configuration from console menu"), $interface));
509 c63e3594 Darren Embry
	interface_reconfigure(strtolower($upperifname));
510 8727b3c8 Phil Davis
	echo "\n Reloading filter...";
511 c63e3594 Darren Embry
	filter_configure_sync();
512 8ce04d22 Chris Buechler
	echo "\n Reloading routing configuration...";
513
	system_routing_configure();
514 e173dd74 Phil Davis
	if ($restart_dhcpd) {
515
		echo "\n DHCPD...";
516 c63e3594 Darren Embry
		services_dhcpd_configure();
517
	}
518 e173dd74 Phil Davis
	if ($restart_webgui) {
519 8727b3c8 Phil Davis
		echo "\n Restarting webConfigurator... ";
520 c63e3594 Darren Embry
		mwexec("/etc/rc.restart_webgui");
521
	}
522 416e1530 Darren Embry
}
523 e173dd74 Phil Davis
524 416e1530 Darren Embry
if ($intip != '') {
525
	if (is_ipaddr($intip)) {
526 1b8bf24d Darren Embry
		echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"),
527 e173dd74 Phil Davis
							  $upperifname, "{$intip}/{$intbits}") . "\n";
528 416e1530 Darren Embry
	} else {
529 1b8bf24d Darren Embry
		echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"),
530 e173dd74 Phil Davis
							  $upperifname, $intip) . "\n";
531 416e1530 Darren Embry
	}
532 c1361a9f Darren Embry
}
533
if ($intip6 != '') {
534
	if (is_ipaddr($intip6)) {
535 1b8bf24d Darren Embry
		echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"),
536 e173dd74 Phil Davis
							  $upperifname, "${intip6}/${intbits6}") . "\n";
537 c1361a9f Darren Embry
	} else {
538 1b8bf24d Darren Embry
		echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"),
539 e173dd74 Phil Davis
							  $upperifname, $intip6) . "\n";
540 c1361a9f Darren Embry
	}
541
}
542
543
if ($intip != '' || $intip6 != '') {
544 8727b3c8 Phil Davis
	if (count($ifdescrs) == "1" or $interface == "lan") {
545 416e1530 Darren Embry
		if ($debug) {
546
			echo "ifdescrs count is " . count($ifdescrs) . "\n";
547
			echo "interface is {$interface} \n";
548 db747fb1 Chris Buechler
		}
549 416e1530 Darren Embry
		echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n";
550 e173dd74 Phil Davis
		if (!empty($config['system']['webgui']['port'])) {
551 416e1530 Darren Embry
			$webuiport = $config['system']['webgui']['port'];
552 b3cb233f Darren Embry
			if ($intip != '') {
553 d71371bc Darren Embry
				echo "		{$config['system']['webgui']['protocol']}://{$intip}:{$webuiport}/\n";
554 b3cb233f Darren Embry
			}
555
			if ($intip6 != '') {
556
				if (is_ipaddr($intip6)) {
557 d71371bc Darren Embry
					echo "		{$config['system']['webgui']['protocol']}://[{$intip6}]:{$webuiport}/\n";
558 b3cb233f Darren Embry
				} else {
559 d71371bc Darren Embry
					echo "		{$config['system']['webgui']['protocol']}://{$intip6}:{$webuiport}/\n";
560 b3cb233f Darren Embry
				}
561
			}
562 416e1530 Darren Embry
		} else {
563 b3cb233f Darren Embry
			if ($intip != '') {
564
				echo "		{$config['system']['webgui']['protocol']}://{$intip}/\n";
565
			}
566
			if ($intip6 != '') {
567
				if (is_ipaddr($intip6)) {
568
					echo "		{$config['system']['webgui']['protocol']}://[{$intip6}]/\n";
569
				} else {
570
					echo "		{$config['system']['webgui']['protocol']}://{$intip6}/\n";
571
				}
572
			}
573 35380504 Seth Mos
		}
574 8dee794b Scott Ullrich
	}
575 416e1530 Darren Embry
}
576 5b237745 Scott Ullrich
577 416e1530 Darren Embry
echo "\n" . gettext('Press <ENTER> to continue.');
578 5b237745 Scott Ullrich
579 416e1530 Darren Embry
fgets($fp);
580
fclose($fp);
581 e173dd74 Phil Davis
582 9b2e42c9 Ermal
?>