Project

General

Profile

« Previous | Next » 

Revision e173dd74

Added by Phil Davis over 10 years ago

Code style for etc files

View differences:

etc/rc.initial.setlanip
30 30
	POSSIBILITY OF SUCH DAMAGE.
31 31
*/
32 32

  
33

  
34

  
35 33
$options = getopt("hn", array("dry-run", "help"));
36 34

  
37 35
if (isset($options["h"]) || isset($options["help"])) {
......
46 44
	echo "DRY RUN MODE IS ON\n";
47 45
}
48 46

  
49

  
50

  
51 47
/* parse the configuration and include all functions used below */
52 48
require_once("config.inc");
53 49
require_once("functions.inc");
......
93 89

  
94 90
function prompt_for_enable_dhcp_server($version = 4) {
95 91
	global $config, $fp, $interface;
96
	if($interface == "wan") {
97
		if($config['interfaces']['lan']) 
92
	if ($interface == "wan") {
93
		if ($config['interfaces']['lan']) {
98 94
			return false;
95
		}
99 96
	}
100 97
	/* only allow DHCP server to be enabled when static IP is
101 98
	   configured on this interface */
......
116 113
function get_interface_config_description($iface) {
117 114
	global $config;
118 115
	$c = $config['interfaces'][$iface];
119
	if (!$c) { return null; }
116
	if (!$c) { 
117
		return null; 
118
	}
120 119
	$if = $c['if'];
121 120
	$result = $if;
122 121
	$result2 = array();
......
143 142
/* build an interface collection */
144 143
$ifdescrs = get_configured_interface_with_descr(false, true);
145 144
$count = count($ifdescrs);
146
	
147
/* grab interface that we will operate on, unless there is only one
148
   interface */
145

  
146
/* grab interface that we will operate on, unless there is only one interface */
149 147
if ($count > 1) {
150 148
	echo "Available interfaces:\n\n";
151 149
	$x=1;
152
	foreach($ifdescrs as $iface => $ifdescr) {
150
	foreach ($ifdescrs as $iface => $ifdescr) {
153 151
		$config_descr = get_interface_config_description($iface);
154 152
		echo "{$x} - {$ifdescr} ({$config_descr})\n";
155 153
		$x++;
156 154
	}
157 155
	echo "\nEnter the number of the interface you wish to configure: ";
158
	$intnum = chop(fgets($fp));	
156
	$intnum = chop(fgets($fp));
159 157
} else {
160 158
	$intnum = $count;
161 159
}
162
	
163
if($intnum < 1) 
160

  
161
if ($intnum < 1)
164 162
	return;
165
if($intnum > $count)
163
if ($intnum > $count)
166 164
	return;
167
		
165

  
168 166
$index = 1;
169 167
foreach ($ifdescrs as $ifname => $ifdesc) {
170 168
	if ($intnum == $index)  {
......
173 171
	} else {
174 172
		$index++;
175 173
	}
176
}	
177
if(!$interface) {
174
}
175
if (!$interface) {
178 176
	echo "Invalid interface!\n";
179 177
	return;
180 178
}
......
185 183
	global $g, $config;
186 184
	$new_name = "GW_" . strtoupper($interface);
187 185

  
188
	if (!is_array($config['gateways']['gateway_item'])) { return $new_name; }
186
	if (!is_array($config['gateways']['gateway_item'])) {
187
		return $new_name;
188
	}
189 189
	$count = 1;
190 190
	do {
191 191
		$existing = false;
......
216 216
	$is_default = true;
217 217
	foreach ($a_gateways as $item) {
218 218
		if ($item['ipprotocol'] === $inet_type) {
219
			if (isset($item['defaultgw']))
219
			if (isset($item['defaultgw'])) {
220 220
				$is_default = false;
221
			if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip))
221
			}
222
			if (($item['interface'] === $interface) && ($item['gateway'] === $gatewayip)) {
222 223
				$new_name = $item['name'];
224
			}
223 225
		}
224 226
	}
225 227
	if ($new_name == '') {
......
252 254

  
253 255
	$upperifname = strtoupper($interface);
254 256

  
255
	if($interface == "wan") {
257
	if ($interface == "wan") {
256 258
		if (console_prompt_for_yn (sprintf(gettext("Configure %s address %s interface via %s?"), $label_IPvX, $upperifname, $label_DHCP))) {
257 259
			$ifppp = console_get_interface_from_ppp(get_real_interface("wan"));
258
			if (!empty($ifppp))
260
			if (!empty($ifppp)) {
259 261
				$ifaceassigned = $ifppp;
262
			}
260 263
			$intip = ($version === 6) ? "dhcp6" : "dhcp";
261 264
			$intbits = "";
262 265
			$isintdhcp = true;
263 266
			$restart_dhcpd = true;
264
		} 
267
		}
265 268
	}
266
		
267
	if($isintdhcp == false or $interface <> "wan") {
268
		while(true) {
269

  
270
	if ($isintdhcp == false or $interface <> "wan") {
271
		while (true) {
269 272
			do {
270 273
				echo "\n" . sprintf(gettext("Enter the new %s %s address.  Press <ENTER> for none:"),
271
						    $upperifname, $label_IPvX) . "\n> ";
274
							$upperifname, $label_IPvX) . "\n> ";
272 275
				$intip = chop(fgets($fp));
273 276
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($intip) : is_ipaddrv4($intip);
274 277
				if ($is_ipaddr && is_ipaddr_configured($intip, $interface, true)) {
275 278
					$ip_conflict = true;
276 279
					echo gettext("This IP address conflicts with another interface or a VIP") . "\n";
277
				} else
280
				} else {
278 281
					$ip_conflict = false;
282
				}
279 283
			} while (($ip_conflict === true) || !($is_ipaddr || $intip == ''));
280 284
			if ($intip != '') {
281 285
				echo "\n" . sprintf(gettext("Subnet masks are entered as bit counts (as in CIDR notation) in %s."),
282
						    $g['product_name']) . "\n";
286
							$g['product_name']) . "\n";
283 287
				if ($version === 6) {
284 288
					echo "e.g. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 = 120\n";
285 289
					echo "     ffff:ffff:ffff:ffff:ffff:ffff:ffff:0    = 112\n";
......
294 298
				do {
295 299
					$upperifname = strtoupper($interface);
296 300
					echo "\n" . sprintf(gettext("Enter the new %s %s subnet bit count (1 to %s):"),
297
							    $upperifname, $label_IPvX, $maxbits) . "\n> ";
301
								$upperifname, $label_IPvX, $maxbits) . "\n> ";
298 302
					$intbits = chop(fgets($fp));
299 303
					$intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits));
300 304
					$restart_dhcpd = true;
......
338 342
				}
339 343
			}
340 344
			$ifppp = console_get_interface_from_ppp(get_real_interface($interface));
341
			if (!empty($ifppp))
345
			if (!empty($ifppp)) {
342 346
				$ifaceassigned = $ifppp;
347
			}
343 348
			break;
344 349
		}
345 350
	}
......
350 355
list($intip,  $intbits,  $gwname)  = console_configure_ip_address(4);
351 356
list($intip6, $intbits6, $gwname6) = console_configure_ip_address(6);
352 357

  
353
if (!empty($ifaceassigned))
358
if (!empty($ifaceassigned)) {
354 359
	$config['interfaces'][$interface]['if'] = $ifaceassigned;
360
}
355 361
$config['interfaces'][$interface]['ipaddr']    = $intip;
356 362
$config['interfaces'][$interface]['subnet']    = $intbits;
357 363
$config['interfaces'][$interface]['gateway']   = $gwname;
......
366 372
	$label_IPvX = ($version === 6) ? "IPv6"    : "IPv4";
367 373
	$dhcpd      = ($version === 6) ? "dhcpdv6" : "dhcpd";
368 374

  
369
	if($g['services_dhcp_server_enable'] && prompt_for_enable_dhcp_server($version)) {
375
	if ($g['services_dhcp_server_enable'] && prompt_for_enable_dhcp_server($version)) {
370 376
		$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits);
371 377
		$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits);
372 378
		do {
......
379 385
				}
380 386
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpstartip) : is_ipaddrv4($dhcpstartip);
381 387
				$is_inrange = is_inrange($dhcpstartip, $subnet_start, $subnet_end);
382
				if (!$is_inrange)
388
				if (!$is_inrange) {
383 389
					echo gettext("This IP address must be in the interface's subnet") . "\n";
390
				}
384 391
			} while (!$is_ipaddr || !$is_inrange);
385 392

  
386 393
			do {
......
392 399
				}
393 400
				$is_ipaddr = ($version === 6) ? is_ipaddrv6($dhcpendip) : is_ipaddrv4($dhcpendip);
394 401
				$is_inrange = is_inrange($dhcpendip, $subnet_start, $subnet_end);
395
				if (!$is_inrange)
402
				if (!$is_inrange) {
396 403
					echo gettext("This IP address must be in the interface's subnet") . "\n";
404
				}
397 405
				$not_inorder = ($version === 6) ? (inet_pton($dhcpendip) < inet_pton($dhcpstartip)) : ip_less_than($dhcpendip, $dhcpstartip);
398 406
				if ($not_inorder) {
399 407
					echo gettext("The end address of the DHCP range must be >= the start address") . "\n";
......
405 413
		$config[$dhcpd][$interface]['range']['from'] = $dhcpstartip;
406 414
		$config[$dhcpd][$interface]['range']['to'] = $dhcpendip;
407 415
	} else {
408
		if(isset($config[$dhcpd][$interface]['enable'])) {
416
		if (isset($config[$dhcpd][$interface]['enable'])) {
409 417
			unset($config[$dhcpd][$interface]['enable']);
410 418
			printf(gettext("Disabling %s DHCPD..."), $label_IPvX);
411 419
			$restart_dhcpd = true;
......
418 426
	return 0;
419 427
if (console_configure_dhcpd(6) == 0)
420 428
	return 0;
421
	
429

  
422 430
//*****************************************************************************
423 431

  
424 432
if ($config['system']['webgui']['protocol'] == "https") {
......
434 442
	unset($config['system']['webgui']['noantilockout']);
435 443
}
436 444

  
437
if($config['interfaces']['lan']) {
438
	if($config['dhcpd'])
439
		if($config['dhcpd']['wan'])
440
			unset($config['dhcpd']['wan']);		
441
	if($config['dhcpdv6'])
442
		if($config['dhcpdv6']['wan'])
445
if ($config['interfaces']['lan']) {
446
	if ($config['dhcpd']) {
447
		if ($config['dhcpd']['wan']) {
448
			unset($config['dhcpd']['wan']);
449
		}
450
	}
451
	if ($config['dhcpdv6']) {
452
		if ($config['dhcpdv6']['wan']) {
443 453
			unset($config['dhcpdv6']['wan']);
454
		}
455
	}
444 456
}
445 457

  
446
if(!$config['interfaces']['lan']) {
458
if (!$config['interfaces']['lan']) {
447 459
	unset($config['interfaces']['lan']);
448
	if($config['dhcpd']['lan'])
460
	if ($config['dhcpd']['lan']) {
449 461
		unset($config['dhcpd']['lan']);
450
	if($config['dhcpdv6']['lan'])
462
	}
463
	if ($config['dhcpdv6']['lan']) {
451 464
		unset($config['dhcpdv6']['lan']);
465
	}
452 466
	unset($config['shaper']);
453 467
	unset($config['ezshaper']);
454 468
	unset($config['nat']);
......
467 481
	filter_configure_sync();
468 482
	echo "\n Reloading routing configuration...";
469 483
	system_routing_configure();
470
	if($restart_dhcpd) {
471
		echo "\n DHCPD..."; 
484
	if ($restart_dhcpd) {
485
		echo "\n DHCPD...";
472 486
		services_dhcpd_configure();
473 487
	}
474
	if($restart_webgui) {
488
	if ($restart_webgui) {
475 489
		echo "\n Restarting webConfigurator... ";
476 490
		mwexec("/etc/rc.restart_webgui");
477 491
	}
478 492
}
479
	
493

  
480 494
if ($intip != '') {
481 495
	if (is_ipaddr($intip)) {
482 496
		echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"),
483
		                      $upperifname, "{$intip}/{$intbits}") . "\n";
497
							  $upperifname, "{$intip}/{$intbits}") . "\n";
484 498
	} else {
485 499
		echo "\n\n" . sprintf(gettext("The IPv4 %s address has been set to %s"),
486
		                      $upperifname, $intip) . "\n";
500
							  $upperifname, $intip) . "\n";
487 501
	}
488 502
}
489 503
if ($intip6 != '') {
490 504
	if (is_ipaddr($intip6)) {
491 505
		echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"),
492
		                      $upperifname, "${intip6}/${intbits6}") . "\n";
506
							  $upperifname, "${intip6}/${intbits6}") . "\n";
493 507
	} else {
494 508
		echo "\n\n" . sprintf(gettext("The IPv6 %s address has been set to %s"),
495
		                      $upperifname, $intip6) . "\n";
509
							  $upperifname, $intip6) . "\n";
496 510
	}
497 511
}
498 512

  
......
503 517
			echo "interface is {$interface} \n";
504 518
		}
505 519
		echo gettext('You can now access the webConfigurator by opening the following URL in your web browser:') . "\n";
506
		if(!empty($config['system']['webgui']['port'])) {
520
		if (!empty($config['system']['webgui']['port'])) {
507 521
			$webuiport = $config['system']['webgui']['port'];
508 522
			if ($intip != '') {
509 523
				echo "		{$config['system']['webgui']['protocol']}://{$intip}:{$webuiport}/\n";
......
534 548

  
535 549
fgets($fp);
536 550
fclose($fp);
537
		
551

  
538 552
?>

Also available in: Unified diff