Project

General

Profile

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