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