Project

General

Profile

Download (3.88 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 pfSense.\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
	do {
66
    $good = false;
67
	  echo "\nDo you want to enable the DHCP server on LAN [y|n]?  ";
68
    $yn = strtolower(chop(fgets($fp)));
69
    if ($yn[0] == "y" or $yn[0] == "n")
70
      $good = true;
71
  } while (!$good);
72

    
73
	if ($yn == "y") {
74
		do {
75
			echo "Enter the start address of the client address range: ";
76
			$dhcpstartip = chop(fgets($fp));
77
			if ($dhcpstartip === "") {
78
				fclose($fp);
79
				exit(0);
80
			}
81
		} while (!is_ipaddr($dhcpstartip));
82

    
83
		do {
84
			echo "Enter the end address of the client address range: ";
85
			$dhcpendip = chop(fgets($fp));
86
			if ($dhcpendip === "") {
87
				fclose($fp);
88
				exit(0);
89
			}
90
		} while (!is_ipaddr($dhcpendip));
91

    
92
		$config['dhcpd']['lan']['enable'] = true;
93
		$config['dhcpd']['lan']['range']['from'] = $dhcpstartip;
94
		$config['dhcpd']['lan']['range']['to'] = $dhcpendip;
95
	} else {
96
		unset($config['dhcpd']['lan']['enable']);
97
	}
98

    
99
	if ($config['system']['webgui']['protocol'] == "https") {
100

    
101
  	do {
102
      $good = false;
103
  		echo "\nDo you want to revert to HTTP as the webConfigurator protocol? (y/n) ";
104
      $yn = strtolower(chop(fgets($fp)));
105
      if ($yn[0] == "y" or $yn[0] == "n")
106
        $good = true;
107
    } while (!$good);
108

    
109
		if ($yn == "y")
110
			$config['system']['webgui']['protocol'] = "http";
111
	}
112

    
113
	if (isset($config['system']['webgui']['noantilockout'])) {
114
		echo "\nNote: the anti-lockout rule on LAN has been re-enabled.\n";
115
		unset($config['system']['webgui']['noantilockout']);
116
	}
117

    
118
	write_config("LAN IP configuration from console menu");
119
	interfaces_lan_configure();
120

    
121
	echo <<<EOD
122

    
123
The LAN IP address has been set to $lanip/$lanbits.
124
You can now access the webConfigurator by opening the following URL
125
in your web browser:
126

    
127
http://$lanip/
128

    
129
Press ENTER to continue.
130

    
131
EOD;
132

    
133
	fgets($fp);
134
	fclose($fp);
135
?>
(47-47/76)