1
|
<?php
|
2
|
/*
|
3
|
* wizard_utils.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
* you may not use this file except in compliance with the License.
|
13
|
* You may obtain a copy of the License at
|
14
|
*
|
15
|
* http://www.apache.org/licenses/LICENSE-2.0
|
16
|
*
|
17
|
* Unless required by applicable law or agreed to in writing, software
|
18
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
* See the License for the specific language governing permissions and
|
21
|
* limitations under the License.
|
22
|
*/
|
23
|
|
24
|
require_once("config.gui.inc");
|
25
|
require_once("util.inc");
|
26
|
require_once("globals.inc");
|
27
|
require_once("pfsense-utils.inc");
|
28
|
|
29
|
// Save all of the parameters changed by the setup wizard
|
30
|
function save_setupwizard_config(
|
31
|
$hostname,
|
32
|
$domain,
|
33
|
$timezone,
|
34
|
$timeservers,
|
35
|
$spoofmac,
|
36
|
$mtu,
|
37
|
$mss,
|
38
|
$bogons,
|
39
|
$rfc1918,
|
40
|
$lanip,
|
41
|
$dnsoverride,
|
42
|
$primarydns,
|
43
|
$secondarydns,
|
44
|
$dhcphostname,
|
45
|
$wangateway,
|
46
|
$wanip,
|
47
|
$wantype,
|
48
|
$pppoeUsername,
|
49
|
$pppoePassword,
|
50
|
$pppoeOnDemand,
|
51
|
$pppoeIdelTimeout,
|
52
|
$pppoeServiceName,
|
53
|
$ppppoeLocalIP) {
|
54
|
|
55
|
global $config, $g;
|
56
|
|
57
|
// General ====================================================================================================================
|
58
|
$config['system']['hostname'] = $hostname;
|
59
|
$config['system']['domain'] = $domain;
|
60
|
|
61
|
// Time =======================================================================================================================
|
62
|
$config['system']['timezone'] = $timezone;
|
63
|
$config['system']['timeservers'] = $timeservers;
|
64
|
|
65
|
// WAN ========================================================================================================================
|
66
|
setorforget($config['interfaces']['wan']['spoofmac'], $spoofmac);
|
67
|
setorforget($config['interfaces']['wan']['mtu'], $mtu);
|
68
|
setorforget($config['interfaces']['wan']['mss'], $mss);
|
69
|
$config['interfaces']['wan']['dhcphostname'] = $dhcphostname;
|
70
|
|
71
|
if ($bogons == "on") {
|
72
|
$config['interfaces']['wan']['blockbogons'] = "on";
|
73
|
} else {
|
74
|
config_del_path('interfaces/wan/blockbogons');
|
75
|
}
|
76
|
|
77
|
if ($rfc1918 == "on") {
|
78
|
$config['interfaces']['wan']['blockpriv'] = "on";
|
79
|
} else {
|
80
|
config_del_path('interfaces/wan/blockpriv');
|
81
|
}
|
82
|
|
83
|
if (strlen($wangateway) > 0) {
|
84
|
init_config_arr(array('gateways', 'gateway_item'));
|
85
|
$found = false;
|
86
|
$defaultgw_found = false;
|
87
|
$gwlist = config_get_path('gateways/gateway_item', []);
|
88
|
$ifgw = '';
|
89
|
foreach ($gwlist as & $gw) {
|
90
|
if ($gw['interface'] != "wan")
|
91
|
continue;
|
92
|
if (isset($gw['defaultgw']))
|
93
|
$defaultgw_found = true;
|
94
|
if ($gw['name'] == 'WANGW' || $gw['gateway'] == $wangateway) {
|
95
|
$found = true;
|
96
|
$gw['gateway'] = $wangateway;
|
97
|
$ifgw = $gw['name'];
|
98
|
}
|
99
|
}
|
100
|
config_set_path('interfaces/wan/gateway', $ifgw);
|
101
|
config_set_path('gateways/gateway_item', $gwlist);
|
102
|
if (!$found) {
|
103
|
$newgw = array();
|
104
|
$newgw['interface'] = "wan";
|
105
|
$newgw['gateway'] = $wangateway;
|
106
|
$newgw['name'] = "WANGW";
|
107
|
$newgw['weight'] = 1;
|
108
|
$newgw['descr'] = "WAN Gateway";
|
109
|
$newgw['defaultgw'] = !$defaultgw_found;
|
110
|
$config['gateways']['gateway_item'][] = $newgw;
|
111
|
$config['interfaces']['wan']['gateway'] = "WANGW";
|
112
|
}
|
113
|
}
|
114
|
|
115
|
$pppfg = array();
|
116
|
$type = $wantype;
|
117
|
|
118
|
init_config_arr(array('ppps', 'ppp'));
|
119
|
if (count($config['ppps']['ppp'])) {
|
120
|
foreach (config_get_path('ppps/ppp', []) as $pppid => $ppp) {
|
121
|
if ($ppp['ptpid'] == "0") {
|
122
|
if ((substr($config['interfaces']['wan']['if'],0,5) == "pppoe") || (substr($config['interfaces']['wan']['if'],0,4) == "pptp")) {
|
123
|
$oldif = explode(",", $ppp['ports']);
|
124
|
$config['interfaces']['wan']['if'] = $oldif[0];
|
125
|
}
|
126
|
if ($type == "pppoe" || $type == "pptp")
|
127
|
config_del_path("ppps/ppp/{$pppid}");
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
|
132
|
if ($type == "pppoe" || $type == "pptp") {
|
133
|
if ($type == "pptp") {
|
134
|
$pppfg['username'] = $pppUsername;
|
135
|
$pppfg['ondemand'] = $pppOnDemand;
|
136
|
$pppfg['idletimeout'] = $pppIdleTimeout;
|
137
|
}
|
138
|
|
139
|
$pppfg['password'] = base64_encode($pppPassword);
|
140
|
$tmp = array();
|
141
|
$tmp['ptpid'] = "0";
|
142
|
$tmp['type'] = $type;
|
143
|
$tmp['if'] = $type . "0";
|
144
|
$tmp['ports'] = config_get_path('interfaces/wan/if');
|
145
|
$config['ppps']['ppp'][] = array_merge($tmp, $pppfg);
|
146
|
unset($tmp);
|
147
|
$config['interfaces']['wan']['if'] = $type."0";
|
148
|
}
|
149
|
|
150
|
if(strpos($wanip, "/") !== false){
|
151
|
$ip = explode("/", $wanip);
|
152
|
$config['interfaces']['wan']['ipaddr'] = $ip[0];
|
153
|
$config['interfaces']['wan']['subnet'] = $ip[1];
|
154
|
} else {
|
155
|
$config['interfaces']['wan']['ipaddr'] = $wanip;
|
156
|
}
|
157
|
|
158
|
// LAN ========================================================================================================================
|
159
|
$lp = explode("/", $lanip);
|
160
|
$addr = $lp[0];
|
161
|
$mask = $lp[1];
|
162
|
|
163
|
$config['interfaces']['lan']['ipaddr'] = $addr;
|
164
|
$config['interfaces']['lan']['subnet'] = $mask;
|
165
|
|
166
|
init_config_arr(array('dhcpd', 'lan', 'range', 'from'));
|
167
|
init_config_arr(array('dhcpd', 'lan', 'range', 'to'));
|
168
|
|
169
|
if (!ip_in_subnet($config['dhcpd']['lan']['range']['from'], "{$addr}/{$mask}") ||
|
170
|
!ip_in_subnet($config['dhcpd']['lan']['range']['to'], "{$addr}/{$mask}")) {
|
171
|
|
172
|
$ipaddresses_before = ip_range_size_v4($lowestip, $addr);
|
173
|
$ipaddresses_after = ip_range_size_v4($addr, $highestip);
|
174
|
if ($ipaddresses_after >= $ipaddresses_before) {
|
175
|
// The LAN IP is in the 1st half of the subnet, so put DHCP in the 2nd half.
|
176
|
if ($ipaddresses_after > 30) {
|
177
|
// There is reasonable space in the subnet, use a smaller chunk of the space for DHCP
|
178
|
// This case will work out like the old defaults if the user has specified the ".1" address.
|
179
|
// The range will be something like ".10" to ".245"
|
180
|
$config['dhcpd']['lan']['range']['from'] = ip_after($addr, 9);
|
181
|
$config['dhcpd']['lan']['range']['to'] = ip_before($highestip, 10);
|
182
|
} else {
|
183
|
// There is not much space in the subnet, so allocate everything above the LAN IP to DHCP.
|
184
|
$config['dhcpd']['lan']['range']['from'] = ip_after($addr);
|
185
|
$config['dhcpd']['lan']['range']['to'] = ip_before($highestip);
|
186
|
}
|
187
|
} else {
|
188
|
// The LAN IP is in the 2nd half of the subnet, so put DHCP in the 1st half.
|
189
|
if ($ipaddresses_before > 30) {
|
190
|
// There is reasonable space in the subnet, use a smaller chunk of the space for DHCP
|
191
|
$config['dhcpd']['lan']['range']['from'] = ip_after($lowestip, 10);
|
192
|
$config['dhcpd']['lan']['range']['to'] = ip_before($addr, 9);
|
193
|
} else {
|
194
|
// There is not much space in the subnet, so allocate everything below the LAN IP to DHCP.
|
195
|
$config['dhcpd']['lan']['range']['from'] = ip_after($lowestip);
|
196
|
$config['dhcpd']['lan']['range']['to'] = ip_before($addr);
|
197
|
}
|
198
|
}
|
199
|
}
|
200
|
|
201
|
// DNS ========================================================================================================================
|
202
|
if ($dnsoverride == "on") {
|
203
|
$config['system']['dnsallowoverride'] = "on";
|
204
|
} else {
|
205
|
config_del_path('system/dnsallowoverride');
|
206
|
}
|
207
|
|
208
|
$config['system']['dnsserver'] = array($primarydns, $secondarydns);
|
209
|
|
210
|
write_config("Configuration updated by setup wizard");
|
211
|
reload_all();
|
212
|
mwexec_bg("/etc/rc.update_bogons.sh now");
|
213
|
touch("{$g['cf_conf_path']}/copynotice_display");
|
214
|
}
|
215
|
|
216
|
function setorforget(&$node, $value) {
|
217
|
if(strlen($value) > 0) {
|
218
|
$node = $value;
|
219
|
} else {
|
220
|
unset($node);
|
221
|
}
|
222
|
}
|
223
|
|
224
|
?>
|