1 |
58fdcb9c
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
installer.php
|
4 |
|
|
part of pfSense (http://www.pfsense.com/)
|
5 |
|
|
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
|
6 |
|
|
All rights reserved.
|
7 |
|
|
|
8 |
|
|
Redistribution and use in source and binary forms, with or without
|
9 |
|
|
modification, are permitted provided that the following conditions are met:
|
10 |
|
|
|
11 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
12 |
|
|
this list of conditions and the following disclaimer.
|
13 |
|
|
|
14 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
15 |
|
|
notice, this list of conditions and the following disclaimer in the
|
16 |
|
|
documentation and/or other materials provided with the distribution.
|
17 |
|
|
|
18 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
require("guiconfig.inc");
|
31 |
|
|
|
32 |
6bd7a614
|
Scott Ullrich
|
if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") {
|
33 |
|
|
Header("Location: /index.php");
|
34 |
|
|
exit;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
5d4f96c6
|
Scott Ullrich
|
// Main switch dispatcher
|
38 |
|
|
switch ($_REQUEST['state']) {
|
39 |
|
|
case "quickeasyinstall":
|
40 |
|
|
quickeasyinstall_gui();
|
41 |
|
|
break;
|
42 |
|
|
case "update_installer_status":
|
43 |
|
|
update_installer_status();
|
44 |
|
|
exit;
|
45 |
|
|
case "quickeasyinstall":
|
46 |
|
|
begin_quick_easy_install();
|
47 |
|
|
default:
|
48 |
|
|
installer_main();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
58fdcb9c
|
Scott Ullrich
|
function write_out_pc_sysinstaller_config($disk) {
|
52 |
|
|
$fd = fopen("/PCBSD/pc-sysinstall/examples/pfSense-install.cfg", "w");
|
53 |
|
|
if(!$fd) {
|
54 |
|
|
return true;
|
55 |
|
|
}
|
56 |
|
|
$config = <<<EOF
|
57 |
|
|
# Sample configuration file for an installation using pc-sysinstall
|
58 |
|
|
|
59 |
|
|
installMode=fresh
|
60 |
|
|
installInteractive=yes
|
61 |
|
|
installType=FreeBSD
|
62 |
|
|
installMedium=LiveCD
|
63 |
|
|
|
64 |
|
|
# Set the disk parameters
|
65 |
|
|
disk0={$disk}
|
66 |
|
|
partition=all
|
67 |
|
|
bootManager=bsd
|
68 |
|
|
commitDiskPart
|
69 |
|
|
|
70 |
|
|
# Setup the disk label
|
71 |
|
|
# All sizes are expressed in MB
|
72 |
|
|
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
|
73 |
|
|
# Size 0 means use the rest of the slice size
|
74 |
|
|
disk0-part=UFS+S 0 /
|
75 |
|
|
# Do it now!
|
76 |
|
|
commitDiskLabel
|
77 |
|
|
|
78 |
|
|
# Set if we are installing via optical, USB, or FTP
|
79 |
|
|
installType=FreeBSD
|
80 |
|
|
|
81 |
|
|
packageType=cpdup
|
82 |
|
|
|
83 |
|
|
# Optional Components
|
84 |
|
|
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,sys,usr,var
|
85 |
|
|
|
86 |
|
|
runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh && cd / && /usr/local/bin/after_installation_routines.sh
|
87 |
|
|
EOF;
|
88 |
|
|
fwrite($fd, $config);
|
89 |
|
|
fclose($fd);
|
90 |
|
|
return;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
function start_installation() {
|
94 |
|
|
$fd = fopen("/tmp/installer.sh", "w");
|
95 |
5d4f96c6
|
Scott Ullrich
|
if(!$fd) {
|
96 |
|
|
die("Could not open /tmp/installer.sh for writing");
|
97 |
|
|
exit;
|
98 |
|
|
}
|
99 |
58fdcb9c
|
Scott Ullrich
|
fwrite($fd, "/PCBSD/pc-sysinstall/pc-sysinstall -c /PCBSD/pc-sysinstall/examples/pfSense-install.cfg && touch /tmp/install_complete");
|
100 |
|
|
fclose($fd);
|
101 |
|
|
exec("chmod a+rx /tmp/installer.sh");
|
102 |
|
|
mwexec_bg("sh /tmp/installer.sh");
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
function installer_find_first_disk() {
|
106 |
|
|
$disk = `/PCBSD/pc-sysinstall/pc-sysinstall disk-list | head -n1 | cut -d':' -f1`;
|
107 |
|
|
return $disk;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
function update_installer_status() {
|
111 |
|
|
if(!file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log"))
|
112 |
|
|
return;
|
113 |
|
|
echo `tail -n20 /tmp/.pc-sysinstall/pc-sysinstall.log`;
|
114 |
|
|
if(file_exists("/tmp/install_complete")) {
|
115 |
|
|
echo "Installation completed.";
|
116 |
|
|
unlink_if_exists("/tmp/installer.sh");
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
function update_installer_status_win($status) {
|
121 |
|
|
echo "<script type=\"text/javascript\">\n";
|
122 |
|
|
echo "\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
|
123 |
|
|
echo "installeroutput.scroll = installeroutput.maxScroll;\n";
|
124 |
|
|
echo "</script>";
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
function begin_quick_easy_install() {
|
128 |
|
|
unlink_if_exists("/tmp/install_complete");
|
129 |
|
|
$disk = installer_find_first_disk();
|
130 |
|
|
if(!$disk) {
|
131 |
|
|
// XXX: hide progress bar
|
132 |
|
|
$savemsg = "Could not find a suitable disk for installation";
|
133 |
|
|
update_installer_status_win("Could not find a suitable disk for installation.");
|
134 |
|
|
return;
|
135 |
|
|
}
|
136 |
|
|
write_out_pc_sysinstaller_config($disk);
|
137 |
|
|
update_installer_status_win("Beginning installation on disk {$disk}.");
|
138 |
|
|
start_installation();
|
139 |
|
|
}
|
140 |
|
|
|
141 |
5d4f96c6
|
Scott Ullrich
|
function body_html() {
|
142 |
|
|
$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
|
143 |
|
|
if(strstr($pfSversion, "1.2"))
|
144 |
|
|
$one_two = true;
|
145 |
|
|
$pgtitle = "pfSense: Installer";
|
146 |
|
|
include("head.inc");
|
147 |
|
|
echo <<<EOF
|
148 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
149 |
|
|
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
|
150 |
|
|
<script type="text/javascript">
|
151 |
|
|
function getinstallerprogress() {
|
152 |
|
|
url = 'installer.php';
|
153 |
|
|
pars = 'state=update_installer_status';
|
154 |
|
|
callajax(url, pars, installcallback);
|
155 |
|
|
}
|
156 |
|
|
function callajax(url, pars, activitycallback) {
|
157 |
|
|
var myAjax = new Ajax.Request(
|
158 |
|
|
url,
|
159 |
|
|
{
|
160 |
|
|
method: 'post',
|
161 |
|
|
parameters: pars,
|
162 |
|
|
onComplete: activitycallback
|
163 |
|
|
});
|
164 |
|
|
}
|
165 |
|
|
function installcallback(transport) {
|
166 |
|
|
this.document.forms[0].installeroutput.value=transport.responseText;
|
167 |
|
|
setTimeout('getinstallerprogress()', 1000);
|
168 |
|
|
}
|
169 |
|
|
</script>
|
170 |
|
|
EOF;
|
171 |
|
|
include("fbegin.inc");
|
172 |
58fdcb9c
|
Scott Ullrich
|
|
173 |
309b3a20
|
Scott Ullrich
|
if($one_two)
|
174 |
5d4f96c6
|
Scott Ullrich
|
echo "<p class=\"pgtitle\">{$pgtitle}</font></p>";
|
175 |
58fdcb9c
|
Scott Ullrich
|
|
176 |
5d4f96c6
|
Scott Ullrich
|
if ($savemsg) print_info_box($savemsg);
|
177 |
58fdcb9c
|
Scott Ullrich
|
}
|
178 |
|
|
|
179 |
5d4f96c6
|
Scott Ullrich
|
function end_html() {
|
180 |
|
|
echo "</form>";
|
181 |
|
|
include("fend.inc");
|
182 |
|
|
echo "</body>";
|
183 |
|
|
echo "</html>";
|
184 |
58fdcb9c
|
Scott Ullrich
|
}
|
185 |
|
|
|
186 |
|
|
function template() {
|
187 |
5d4f96c6
|
Scott Ullrich
|
body_html();
|
188 |
|
|
echo <<<EOF
|
189 |
|
|
<div id="mainlevel">
|
190 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
191 |
|
|
<tr>
|
192 |
|
|
<td>
|
193 |
|
|
<div id="mainarea">
|
194 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
195 |
|
|
<tr>
|
196 |
|
|
<td class="tabcont" >
|
197 |
|
|
<form action="installer.php" method="post">
|
198 |
|
|
<div id="pfsensetemplate">
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
</div>
|
202 |
|
|
</td>
|
203 |
|
|
</tr>
|
204 |
|
|
</table>
|
205 |
|
|
</div>
|
206 |
|
|
</td>
|
207 |
|
|
</tr>
|
208 |
|
|
</table>
|
209 |
|
|
</div>
|
210 |
58fdcb9c
|
Scott Ullrich
|
EOF;
|
211 |
5d4f96c6
|
Scott Ullrich
|
end_html();
|
212 |
58fdcb9c
|
Scott Ullrich
|
}
|
213 |
|
|
|
214 |
|
|
function quickeasyinstall_gui() {
|
215 |
5d4f96c6
|
Scott Ullrich
|
body_html();
|
216 |
58fdcb9c
|
Scott Ullrich
|
echo <<<EOF
|
217 |
5d4f96c6
|
Scott Ullrich
|
<div id="mainlevel">
|
218 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
219 |
|
|
<tr>
|
220 |
|
|
<td>
|
221 |
|
|
<div id="mainarea">
|
222 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
223 |
|
|
<tr>
|
224 |
|
|
<td class="tabcont" >
|
225 |
|
|
<form action="installer.php" method="post" state="step1_post">
|
226 |
|
|
<div id="pfsenseinstaller">
|
227 |
|
|
Starting Installer... Please wait...<p/>
|
228 |
|
|
{{ Insert progressbar here }}<p/>
|
229 |
|
|
<textarea name='installeroutput' id='installeroutput' rows="20" cols="80">
|
230 |
|
|
</textarea>
|
231 |
|
|
</div>
|
232 |
|
|
</td>
|
233 |
|
|
</tr>
|
234 |
|
|
</table>
|
235 |
|
|
</div>
|
236 |
|
|
</td>
|
237 |
|
|
</tr>
|
238 |
|
|
</table>
|
239 |
|
|
</div>
|
240 |
|
|
<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
|
241 |
58fdcb9c
|
Scott Ullrich
|
EOF;
|
242 |
5d4f96c6
|
Scott Ullrich
|
end_html();
|
243 |
58fdcb9c
|
Scott Ullrich
|
}
|
244 |
|
|
|
245 |
|
|
function installer_main() {
|
246 |
5d4f96c6
|
Scott Ullrich
|
body_html();
|
247 |
|
|
$disk = installer_find_first_disk();
|
248 |
|
|
if(!$disk)
|
249 |
|
|
echo "WARNING: Could not find any suitable disks for installation.";
|
250 |
|
|
echo <<<EOF
|
251 |
|
|
<div id="mainlevel">
|
252 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
253 |
|
|
<tr>
|
254 |
|
|
<td>
|
255 |
|
|
<div id="mainarea">
|
256 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
257 |
|
|
<tr>
|
258 |
|
|
<td class="tabcont" >
|
259 |
|
|
<form action="installer.php" method="post" state="step1_post">
|
260 |
|
|
<div id="pfsenseinstaller">
|
261 |
|
|
<a onclick="return confirm('Are you sure you want to install pfSense to $disk?')"> href='installer.php?state=quickeasyinstall'>Quick/Easy installation</a>
|
262 |
|
|
</p>
|
263 |
|
|
</div>
|
264 |
|
|
</td>
|
265 |
|
|
</tr>
|
266 |
|
|
</table>
|
267 |
|
|
</div>
|
268 |
|
|
</td>
|
269 |
|
|
</tr>
|
270 |
|
|
</table>
|
271 |
|
|
</div>
|
272 |
58fdcb9c
|
Scott Ullrich
|
EOF;
|
273 |
5d4f96c6
|
Scott Ullrich
|
end_html();
|
274 |
58fdcb9c
|
Scott Ullrich
|
}
|
275 |
|
|
|
276 |
5d4f96c6
|
Scott Ullrich
|
?>
|