Project

General

Profile

Download (7.13 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
function write_out_pc_sysinstaller_config($disk) {
33
	$fd = fopen("/PCBSD/pc-sysinstall/examples/pfSense-install.cfg", "w");
34
	if(!$fd) {
35
		return true;
36
	}
37
	$config = <<<EOF
38
# Sample configuration file for an installation using pc-sysinstall
39

    
40
installMode=fresh
41
installInteractive=yes
42
installType=FreeBSD
43
installMedium=LiveCD
44

    
45
# Set the disk parameters
46
disk0={$disk}
47
partition=all
48
bootManager=bsd
49
commitDiskPart
50

    
51
# Setup the disk label
52
# All sizes are expressed in MB
53
# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP
54
# Size 0 means use the rest of the slice size
55
disk0-part=UFS+S 0 / 
56
# Do it now!
57
commitDiskLabel
58

    
59
# Set if we are installing via optical, USB, or FTP
60
installType=FreeBSD
61

    
62
packageType=cpdup
63

    
64
# Optional Components
65
cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,sys,usr,var
66

    
67
runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh && cd / && /usr/local/bin/after_installation_routines.sh
68
EOF;
69
	fwrite($fd, $config);
70
	fclose($fd);
71
	return;
72
}
73

    
74
function start_installation() {
75
	$fd = fopen("/tmp/installer.sh", "w");
76
	fwrite($fd, "/PCBSD/pc-sysinstall/pc-sysinstall -c /PCBSD/pc-sysinstall/examples/pfSense-install.cfg && touch /tmp/install_complete");
77
	fclose($fd);
78
	exec("chmod a+rx /tmp/installer.sh");
79
	mwexec_bg("sh /tmp/installer.sh");
80
}
81

    
82
function installer_find_first_disk() {
83
	$disk = `/PCBSD/pc-sysinstall/pc-sysinstall disk-list | head -n1 | cut -d':' -f1`;
84
	return $disk;
85
}
86

    
87
function update_installer_status() {
88
	if(!file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) 
89
		return;
90
	echo `tail -n20 /tmp/.pc-sysinstall/pc-sysinstall.log`;
91
	if(file_exists("/tmp/install_complete")) {
92
		echo "Installation completed.";
93
		unlink_if_exists("/tmp/installer.sh");
94
	}
95
}
96

    
97
function update_installer_status_win($status) {
98
	echo "<script type=\"text/javascript\">\n";
99
	echo "\$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n";
100
	echo "installeroutput.scroll = installeroutput.maxScroll;\n";
101
	echo "</script>";
102
}
103

    
104
function begin_quick_easy_install() {
105
	unlink_if_exists("/tmp/install_complete");
106
	$disk = installer_find_first_disk();
107
	if(!$disk) {
108
		// XXX: hide progress bar
109
		$savemsg = "Could not find a suitable disk for installation";
110
		update_installer_status_win("Could not find a suitable disk for installation.");
111
		return;
112
	}
113
	write_out_pc_sysinstaller_config($disk);
114
	update_installer_status_win("Beginning installation on disk {$disk}.");
115
	start_installation();
116
}
117

    
118
if($_REQUEST['state'] == "update_installer_status") {
119
	update_installer_status();
120
	exit;
121
}
122

    
123
if($_REQUEST['step1_post']) {
124
	
125
}
126

    
127
if($_REQUEST['step2_post']) {
128
	
129
}
130

    
131
if($_REQUEST['step3_post']) {
132
	
133
}
134

    
135
if($_REQUEST['step4_post']) {
136
	
137
}
138

    
139
$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
140
if(strstr($pfSversion, "1.2"))
141
	$one_two = true;
142

    
143
$pgtitle = "pfSense: Installer";
144
include("head.inc");
145

    
146
?>
147
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
148
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
149
	<script type="text/javascript">
150
		function getinstallerprogress() {
151
			url = 'installer.php';
152
			pars = 'state=update_installer_status';
153
			callajax(url, pars, installcallback);
154
		}
155
		function callajax(url, pars, activitycallback) {
156
			var myAjax = new Ajax.Request(
157
				url,
158
				{
159
					method: 'post',
160
					parameters: pars,
161
					onComplete: activitycallback
162
				});
163
		}
164
		function installcallback(transport) {
165
			this.document.forms[0].installeroutput.value=transport.responseText;
166
			setTimeout('getinstallerprogress()', 1000);		
167
		}
168
</script>
169
<?php include("fbegin.inc"); ?>
170

    
171
<?php if($one_two): ?>
172
<p class="pgtitle"><?=$pgtitle?></font></p>
173
<?php endif; ?>
174

    
175
<?php if ($savemsg) print_info_box($savemsg); ?>
176

    
177
<?php
178
if($_REQUEST['state'] == "quickeasyinstall") {
179
	quickeasyinstall_gui();
180
} else {
181
	installer_main();
182
}
183

    
184
function template() {
185
echo <<<EOF
186
<div id="mainlevel">
187
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
188
 		<tr>
189
    		<td>
190
				<div id="mainarea">
191
					<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
192
						<tr>
193
     						<td class="tabcont" >
194
      							<form action="installer.php" method="post">
195
								<div id="pfsensetemplate">
196

    
197

    
198
								</div>
199
     						</td>
200
						</tr>
201
					</table>
202
				</div>
203
			</td>
204
		</tr>
205
	</table>
206
</div>
207
EOF;
208

    
209
}
210

    
211
function quickeasyinstall_gui() {
212
	echo <<<EOF
213
<div id="mainlevel">
214
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
215
 		<tr>
216
    		<td>
217
				<div id="mainarea">
218
					<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
219
						<tr>
220
     						<td class="tabcont" >
221
      							<form action="installer.php" method="post" state="step1_post">
222
								<div id="pfsenseinstaller">
223
									Starting Installer...  Please wait...<p/>
224
									{{ Insert progressbar here }}<p/>
225
									<textarea name='installeroutput' id='installeroutput' rows="20" cols="80">
226
									</textarea>
227
								</div>
228
     						</td>
229
						</tr>
230
					</table>
231
				</div>
232
			</td>
233
		</tr>
234
	</table>
235
</div>
236
<script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script>
237
EOF;
238

    
239
}
240

    
241

    
242
function installer_main() {
243
echo <<<EOF
244
<div id="mainlevel">
245
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
246
 		<tr>
247
    		<td>
248
				<div id="mainarea">
249
					<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
250
						<tr>
251
     						<td class="tabcont" >
252
      							<form action="installer.php" method="post" state="step1_post">
253
								<div id="pfsenseinstaller">
254
									<a href='installer.php?state=quickeasyinstall'>Quick/Easy installation</a> 
255
									</p>
256
								</div>
257
     						</td>
258
						</tr>
259
					</table>
260
				</div>
261
			</td>
262
		</tr>
263
	</table>
264
</div>
265
EOF;
266

    
267
}
268

    
269
?>
270

    
271
</form>
272
<?php include("fend.inc"); ?>
273
</body>
274
</html>
275

    
276
<?php
277
	if($_REQUEST['state'] == "quickeasyinstall") {
278
		begin_quick_easy_install();
279
	}
280
?>
(78-78/218)