Revision b78111c4
Added by Phil Davis over 10 years ago
etc/rc.initial.setlanip | ||
---|---|---|
55 | 55 |
require_once("shaper.inc"); |
56 | 56 |
require_once("rrd.inc"); |
57 | 57 |
|
58 |
function console_prompt_for_yn ($prompt_text) { |
|
59 |
global $fp; |
|
60 |
|
|
61 |
$good_answer = false; |
|
62 |
|
|
63 |
do { |
|
64 |
echo "\n" . $prompt_text . " (y/n) "; |
|
65 |
$yn = strtolower(chop(fgets($fp))); |
|
66 |
if (($yn == "y") || ($yn == "yes")) { |
|
67 |
$boolean_answer = true; |
|
68 |
$good_answer = true; |
|
69 |
} |
|
70 |
if (($yn == "n") || ($yn == "no")) { |
|
71 |
$boolean_answer = false; |
|
72 |
$good_answer = true; |
|
73 |
} |
|
74 |
} while (!$good_answer); |
|
75 |
|
|
76 |
return $boolean_answer; |
|
77 |
} |
|
78 |
|
|
58 | 79 |
function console_get_interface_from_ppp($realif) { |
59 | 80 |
global $config; |
60 | 81 |
|
... | ... | |
74 | 95 |
global $config, $fp, $interface; |
75 | 96 |
if($interface == "wan") { |
76 | 97 |
if($config['interfaces']['lan']) |
77 |
return "n";
|
|
98 |
return false;
|
|
78 | 99 |
} |
79 | 100 |
/* only allow DHCP server to be enabled when static IP is |
80 | 101 |
configured on this interface */ |
... | ... | |
83 | 104 |
} else { |
84 | 105 |
$is_ipaddr = is_ipaddrv4($config['interfaces'][$interface]['ipaddr']); |
85 | 106 |
} |
86 |
if ($is_ipaddr) { |
|
87 |
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP"; |
|
88 |
do { |
|
89 |
$good = false; |
|
90 |
$upperifname = strtoupper($interface); |
|
91 |
echo "\n" . sprintf(gettext("Do you want to enable the %s server on %s? [y|n]"), |
|
92 |
$label_DHCP, $upperifname) . " "; |
|
93 |
$yn = strtolower(chop(fgets($fp))); |
|
94 |
if ($yn[0] == "y" or $yn[0] == "n") |
|
95 |
$good = true; |
|
96 |
} while (!$good); |
|
107 |
if (!($is_ipaddr)) { |
|
108 |
return false; |
|
97 | 109 |
} |
98 |
return $yn; |
|
110 |
|
|
111 |
$label_DHCP = ($version === 6) ? "DHCP6" : "DHCP"; |
|
112 |
$upperifname = strtoupper($interface); |
|
113 |
return console_prompt_for_yn (sprintf(gettext("Do you want to enable the %s server on %s?"), $label_DHCP, $upperifname)); |
|
99 | 114 |
} |
100 | 115 |
|
101 | 116 |
function get_interface_config_description($iface) { |
... | ... | |
238 | 253 |
$upperifname = strtoupper($interface); |
239 | 254 |
|
240 | 255 |
if($interface == "wan") { |
241 |
echo sprintf(gettext("Configure %s address %s interface via %s? [y|n]"), |
|
242 |
$label_IPvX, $upperifname, $label_DHCP) . "\n> "; |
|
243 |
$intdhcp = chop(fgets($fp)); |
|
244 |
if(strtolower($intdhcp) == "y" || strtolower($intdhcp) == "yes") { |
|
256 |
if (console_prompt_for_yn (sprintf(gettext("Configure %s address %s interface via %s?"), $label_IPvX, $upperifname, $label_DHCP))) { |
|
245 | 257 |
$ifppp = console_get_interface_from_ppp(get_real_interface("wan")); |
246 | 258 |
if (!empty($ifppp)) |
247 | 259 |
$ifaceassigned = $ifppp; |
... | ... | |
281 | 293 |
} |
282 | 294 |
do { |
283 | 295 |
$upperifname = strtoupper($interface); |
284 |
echo "\n" . sprintf(gettext("Enter the new %s %s subnet bit count:"), |
|
285 |
$upperifname, $label_IPvX) . "\n> "; |
|
296 |
echo "\n" . sprintf(gettext("Enter the new %s %s subnet bit count (1 to %s):"),
|
|
297 |
$upperifname, $label_IPvX, $maxbits) . "\n> ";
|
|
286 | 298 |
$intbits = chop(fgets($fp)); |
287 | 299 |
$intbits_ok = is_numeric($intbits) && (($intbits >= 1) && ($intbits <= $maxbits)); |
288 | 300 |
$restart_dhcpd = true; |
... | ... | |
354 | 366 |
$label_IPvX = ($version === 6) ? "IPv6" : "IPv4"; |
355 | 367 |
$dhcpd = ($version === 6) ? "dhcpdv6" : "dhcpd"; |
356 | 368 |
|
357 |
if($g['services_dhcp_server_enable']) |
|
358 |
$yn = prompt_for_enable_dhcp_server($version); |
|
359 |
if ($yn == "y") { |
|
369 |
if($g['services_dhcp_server_enable'] && prompt_for_enable_dhcp_server($version)) { |
|
360 | 370 |
$subnet_start = ($version === 6) ? gen_subnetv6($intip6, $intbits6) : gen_subnet($intip, $intbits); |
361 | 371 |
$subnet_end = ($version === 6) ? gen_subnetv6_max($intip6, $intbits6) : gen_subnet_max($intip, $intbits); |
362 | 372 |
do { |
... | ... | |
413 | 423 |
|
414 | 424 |
if ($config['system']['webgui']['protocol'] == "https") { |
415 | 425 |
|
416 |
do { |
|
417 |
$good = false; |
|
418 |
echo "\n" . gettext("Do you want to revert to HTTP as the webConfigurator protocol? (y/n)") . " "; |
|
419 |
$yn = strtolower(chop(fgets($fp))); |
|
420 |
if ($yn[0] == "y" or $yn[0] == "n") |
|
421 |
$good = true; |
|
422 |
} while (!$good); |
|
423 |
|
|
424 |
if ($yn == "y") { |
|
426 |
if (console_prompt_for_yn (gettext("Do you want to revert to HTTP as the webConfigurator protocol?"))) { |
|
425 | 427 |
$config['system']['webgui']['protocol'] = "http"; |
426 | 428 |
$restart_webgui = true; |
427 | 429 |
} |
Also available in: Unified diff
Validation of y/n answers in setlanip
At the moment the user can answer "yes" to most of the questions, but then later code only checks if the answer is "y". Thus you can type in "yes" in some places, have it accepted, but actually the negative action is taken. That is weird and will mess up people who try typing a whole string starting with "y".
With this change it makes the user type one of "y", "yes", "n", "no". When they type 1 of those, it is turned into either "y" or "n". Then the existing implementation logic all works as expected.
Hopefully this is the "final" version that fixes the behavior of the (y/n) questions.
I also included the bit at 296-297 which adds the CIDR bit-count range to the prompt, so the user can see exactly what input is valid/expected there.
Redmine issue #4100