Project

General

Profile

Download (3.71 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
	rc.initial.setlanip
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	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

    
21
	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
	/* parse the configuration and include all functions used below */
34
	require_once("config.inc");
35
	require_once("functions.inc");
36

    
37
	$fp = fopen('php://stdin', 'r');
38

    
39
	do {
40
		echo "\nEnter the new LAN IP address: ";
41
		$lanip = chop(fgets($fp));
42
		if ($lanip === "") {
43
			fclose($fp);
44
			exit(0);
45
		}
46
	} while (!is_ipaddr($lanip));
47

    
48
	echo "\nSubnet masks are entered as bit counts (as in CIDR notation) in {$g['product_name']}.\n";
49
	echo "e.g. 255.255.255.0 = 24\n";
50
	echo "     255.255.0.0   = 16\n";
51
	echo "     255.0.0.0     = 8\n\n";
52

    
53
	do {
54
		echo "Enter the new LAN subnet bit count: ";
55
		$lanbits = chop(fgets($fp));
56
		if ($lanbits === "") {
57
			fclose($fp);
58
			exit(0);
59
		}
60
	} while (!is_numeric($lanbits) || ($lanbits < 1) || ($lanbits > 31));
61

    
62
	$config['interfaces']['lan']['ipaddr'] = $lanip;
63
	$config['interfaces']['lan']['subnet'] = $lanbits;
64

    
65
	echo "\nDo you want to enable the DHCP server on LAN [y|n]?  ";
66

    
67
	if (strcasecmp(chop(fgets($fp)), "y") == 0) {
68
		do {
69
			echo "Enter the start address of the client address range: ";
70
			$dhcpstartip = chop(fgets($fp));
71
			if ($dhcpstartip === "") {
72
				fclose($fp);
73
				exit(0);
74
			}
75
		} while (!is_ipaddr($dhcpstartip));
76

    
77
		do {
78
			echo "Enter the end address of the client address range: ";
79
			$dhcpendip = chop(fgets($fp));
80
			if ($dhcpendip === "") {
81
				fclose($fp);
82
				exit(0);
83
			}
84
		} while (!is_ipaddr($dhcpendip));
85
		$restart_dhcpd = true;
86
		$config['dhcpd']['lan']['enable'] = true;
87
		$config['dhcpd']['lan']['range']['from'] = $dhcpstartip;
88
		$config['dhcpd']['lan']['range']['to'] = $dhcpendip;
89
	} else {
90
		unset($config['dhcpd']['lan']['enable']);
91
	}
92

    
93
	if ($config['system']['webgui']['protocol'] == "https") {
94

    
95
		echo "\nDo you want to revert to HTTP as the webGUI protocol? (y/n) ";
96

    
97
		if (strcasecmp(chop(fgets($fp)), "y") == 0)
98
			$config['system']['webgui']['protocol'] = "http";
99
	}
100

    
101
	if (isset($config['system']['webgui']['noantilockout'])) {
102
		echo "\nNote: the anti-lockout rule on LAN has been re-enabled.\n";
103
		unset($config['system']['webgui']['noantilockout']);
104
	}
105

    
106
	write_config("LAN IP configuration from console menu");
107
	interfaces_lan_configure();
108

    
109
	if($restart_dhcpd) 
110
		services_dhcpd_configure();
111

    
112
	echo <<<EOD
113

    
114
The LAN IP address has been set to $lanip/$lanbits.
115
You can now access the webGUI by opening the following URL
116
in your web browser:
117

    
118
http://$lanip/
119

    
120
Press ENTER to continue.
121

    
122
EOD;
123

    
124
	fgets($fp);
125
	fclose($fp);
126
?>
(50-50/82)