diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2010-12-17 21:49:37 -0500 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2010-12-17 21:49:37 -0500 |
commit | 8b590740699239ce269a9e1844e94e592112e470 (patch) | |
tree | 0902b967f72c653320883cdc4fa24bf09a168fc1 /usr | |
parent | 86b521eae397fac576ac2abf73c945892bf688fc (diff) | |
download | pfsense-8b590740699239ce269a9e1844e94e592112e470.zip pfsense-8b590740699239ce269a9e1844e94e592112e470.tar.gz |
Auto set 256 and remaining to /
Diffstat (limited to 'usr')
-rw-r--r-- | usr/local/www/installer/index.php | 914 | ||||
-rw-r--r-- | usr/local/www/installer/installer.php | 965 |
2 files changed, 966 insertions, 913 deletions
diff --git a/usr/local/www/installer/index.php b/usr/local/www/installer/index.php index 13443dc..2c7dd90 100644 --- a/usr/local/www/installer/index.php +++ b/usr/local/www/installer/index.php @@ -1,917 +1,5 @@ <?php -/* - index.php (pfSense installer) - part of pfSense (http://www.pfsense.com/) - Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com> - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ - -$nocsrf = true; - -require("globals.inc"); -require("guiconfig.inc"); - -define('PC_SYSINSTALL', '/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh'); - -if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") { - Header("Location: /index.php"); - exit; -} - -// Main switch dispatcher -switch ($_REQUEST['state']) { - case "update_installer_status": - update_installer_status(); - exit; - case "custominstall": - installer_custom(); - exit; - case "begin_install": - installing_gui(); - begin_install(); - exit; - case "verify_before_install": - verify_before_install(); - exit; - default: - installer_main(); -} - -function write_out_pc_sysinstaller_config($disks, $bootmanager = "bsd") { - $diskareas = ""; - $fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w"); - if(!$fd) { - return true; - } - if($bootmanager == "") - $bootmanager = "none"; - $numdisks = -1; - $lastdisk = ""; - $diskdefs = ""; - // First make sure we have a boot partition if any slices are encrypted - foreach($disks as $disksa) { - $fstype = $disksa['fstype']; - if(stristr($fstype,".eli")) - $diskareas .= "disk{$numdisks}-part=UFS 500 /boot\n"; - } - // Run through the disks and create the conf areas for pc-sysinstaller - foreach($disks as $disksa) { - $fstype = $disksa['fstype']; - $size = $disksa['size']; - $mountpoint = $disksa['mountpoint']; - $disk = $disksa['disk']; - if($disk <> $lastdisk) { - $lastdisk = $disk; - $numdisks++; - $diskdefs .= "disk{$numdisks}={$disk}\n"; - } - $diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n"; - if($encpass) - $diskareas .= "encpass={$encpass}\n"; - } - - $config = <<<EOF -# Sample configuration file for an installation using pc-sysinstall - -installMode=fresh -installInteractive=yes -installType=FreeBSD -installMedium=LiveCD - -# Set the disk parameters -{$diskdefs} -partition=all -bootManager={$bootmanager} -commitDiskPart - -# Setup the disk label -# All sizes are expressed in MB -# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP -# Size 0 means use the rest of the slice size -# Alternatively, you can append .eli to any of -# the above filesystem types to encrypt that disk. -# If you with to use a passphrase with this -# encrypted partition, on the next line -# the flag "encpass=" should be entered: -# encpass=mypass -# disk0-part=UFS 500 /boot -# disk0-part=UFS.eli 500 / -# disk0-part=UFS.eli 500 /usr -{$diskareaspre} -{$diskareas} -{$diskareaspass} - -# Do it now! -commitDiskLabel - -# Set if we are installing via optical, USB, or FTP -installType=FreeBSD - -packageType=cpdup - -# Optional Components -cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var - -# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh -EOF; - fwrite($fd, $config); - fclose($fd); - return; -} - -function start_installation() { - global $g, $fstype; - if(file_exists("/tmp/install_complete")) - return; - $ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'"); - if($ps_running) - return; - $fd = fopen("/tmp/installer.sh", "w"); - if(!$fd) { - die(gettext("Could not open /tmp/installer.sh for writing")); - exit; - } - fwrite($fd, "rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n"); - fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n"); - fwrite($fd, "chmod a+rx /usr/local/bin/after_installation_routines.sh\n"); - fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n"); - fwrite($fd, "mkdir /mnt/tmp\n"); -// fwrite($fd, "umount /mnt\n"); - fwrite($fd, "touch /tmp/install_complete\n"); - fclose($fd); - exec("chmod a+rx /tmp/installer.sh"); - mwexec_bg("sh /tmp/installer.sh"); -} - -function installer_find_first_disk() { - global $g, $fstype; - $disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`; - return $disk; -} - -function pcsysinstall_get_disk_info($diskname) { - global $g, $fstype; - $disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`); - $disks_array = array(); - foreach($disk as $d) { - if(!$d) - continue; - $disks_info = split(":", $d); - $tmp_array = array(); - if($disks_info[0] == $diskname) { - $disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`); - foreach($disk_info as $di) { - $di_s = split("=", $di); - if($di_s[0]) - $tmp_array[$di_s[0]] = $di_s[1]; - } - $tmp_array['disk'] = trim($disks_info[0]); - $tmp_array['desc'] = trim(htmlentities($disks_info[1])); - return $tmp_array; - } - } -} - -// Return an array with all disks information. -function installer_find_all_disks() { - global $g, $fstype; - $disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`); - $disks_array = array(); - foreach($disk as $d) { - if(!$d) - continue; - $disks_info = split(":", $d); - $tmp_array = array(); - $disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`); - foreach($disk_info as $di) { - $di_s = split("=", $di); - if($di_s[0]) - $tmp_array[$di_s[0]] = $di_s[1]; - } - $tmp_array['disk'] = trim($disks_info[0]); - $tmp_array['desc'] = trim(htmlentities($disks_info[1])); - $disks_array[] = $tmp_array; - } - return $disks_array; -} - -function update_installer_status() { - global $g, $fstype; - // Ensure status files exist - if(!file_exists("/tmp/installer_installer_running")) - touch("/tmp/installer_installer_running"); - $status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`; - $status = str_replace("\n", "\\n", $status); - $status = str_replace("\n", "\\r", $status); - echo "this.document.forms[0].installeroutput.value='$status';\n"; - echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n"; - // Find out installer progress - $progress = "5"; - if(strstr($status, "Running: dd")) - $progress = "6"; - if(strstr($status, "Running: gpart create -s GPT")) - $progress = "7"; - if(strstr($status, "Running: gpart bootcode")) - $progress = "7"; - if(strstr($status, "Running: newfs -U")) - $progress = "8"; - if(strstr($status, "Running: sync")) - $progress = "9"; - if(strstr($status, "/boot /mnt/boot")) - $progress = "10"; - if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT")) - $progress = "11"; - if(strstr($status, "/bin /mnt/bin")) - $progress = "12"; - if(strstr($status, "/conf /mnt/conf")) - $progress = "15"; - if(strstr($status, "/conf.default /mnt/conf.default")) - $progress = "20"; - if(strstr($status, "/dev /mnt/dev")) - $progress = "25"; - if(strstr($status, "/etc /mnt/etc")) - $progress = "30"; - if(strstr($status, "/home /mnt/home")) - $progress = "35"; - if(strstr($status, "/kernels /mnt/kernels")) - $progress = "40"; - if(strstr($status, "/libexec /mnt/libexec")) - $progress = "50"; - if(strstr($status, "/lib /mnt/lib")) - $progress = "60"; - if(strstr($status, "/root /mnt/root")) - $progress = "70"; - if(strstr($status, "/sbin /mnt/sbin")) - $progress = "75"; - if(strstr($status, "/sys /mnt/sys")) - $progress = "80"; - if(strstr($status, "/usr /mnt/usr")) - $progress = "95"; - if(strstr($status, "/usr /mnt/usr")) - $progress = "90"; - if(strstr($status, "/var /mnt/var")) - $progress = "95"; - if(strstr($status, "cap_mkdb /etc/login.conf")) - $progress = "96"; - if(strstr($status, "Setting hostname")) - $progress = "97"; - if(strstr($status, "umount -f /mnt")) - $progress = "98"; - if(strstr($status, "umount -f /mnt")) - $progress = "99"; - if(strstr($status, "Installation finished")) - $progress = "100"; - // Check for error and bail if we see one. - if(stristr($status, "error")) { - $error = true; - echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred. Aborting installation. <a href=\"/installer\">Back</a> to webInstaller'; "; - echo "\$('progressbar').style.width='100%';\n"; - unlink_if_exists("/tmp/install_complete"); - return; - } - $running_old = trim(file_get_contents("/tmp/installer_installer_running")); - if($installer_running <> "running") { - $ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'"); - if($ps_running) { - $running = "\$('installerrunning').innerHTML='<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\"> <font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'; "; - if($running_old <> $running) { - echo $running; - file_put_contents("/tmp/installer_installer_running", "$running"); - } - } - } - if($progress) - echo "\$('progressbar').style.width='{$progress}%';\n"; - if(file_exists("/tmp/install_complete")) { - echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed. Please <a href=\"reboot.php\">reboot</a> to continue';\n"; - echo "\$('pbdiv').Fade();\n"; - unlink_if_exists("/tmp/installer.sh"); - file_put_contents("/tmp/installer_installer_running", "finished"); - } -} - -function update_installer_status_win($status) { - global $g, $fstype; - echo "<script type=\"text/javascript\">\n"; - echo " \$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n"; - echo "</script>"; -} - -function begin_install() { - global $g; - if(file_exists("/tmp/install_complete")) - return; - unlink_if_exists("/tmp/install_complete"); - update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk)); - start_installation(); -} - -function head_html() { - global $g, $fstype; - echo <<<EOF -<html> - <head> - <style type='text/css'> - a:link { - color: #000000; - text-decoration:underline; - font-size:14; - } - a:visited { - color: #000000; - text-decoration:underline; - font-size:14; - } - a:hover { - color: #FFFF00; - text-decoration: none; - font-size:14; - } - a:active { - color: #FFFF00; - text-decoration:underline; - font-size:14; - } - </style> - </head> -EOF; - -} - -function body_html() { - global $g, $fstype; - $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); - if(strstr($pfSversion, "1.2")) - $one_two = true; - $pgtitle = array("{$g['product_name']}", gettext("Installer")); - include("head.inc"); - echo <<<EOF - <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> - <script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script> - <script type="text/javascript"> - function getinstallerprogress() { - url = '/installer/index.php'; - pars = 'state=update_installer_status'; - callajax(url, pars, installcallback); - } - function callajax(url, pars, activitycallback) { - var myAjax = new Ajax.Request( - url, - { - method: 'post', - parameters: pars, - onComplete: activitycallback - }); - } - function installcallback(transport) { - setTimeout('getinstallerprogress()', 2000); - eval(transport.responseText); - } - </script> -EOF; - - if($one_two) - echo "<p class=\"pgtitle\">{$pgtitle}</font></p>"; - - if ($savemsg) print_info_box($savemsg); -} - -function end_html() { - global $g, $fstype; - echo "</form>"; - echo "</body>"; - echo "</html>"; -} - -function template() { - global $g, $fstype; - head_html(); - body_html(); - echo <<<EOF - <div id="mainlevel"> - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td> - <div id="mainarea"> - <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td class="tabcont" > - <form action="index.php" method="post"> - <div id="pfsensetemplate"> - - - </div> - </td> - </tr> - </table> - </div> - </td> - </tr> - </table> - </div> -EOF; - end_html(); -} - -function verify_before_install() { - global $g, $fstype; - head_html(); - body_html(); - page_table_start(); - echo "\n<!--" . print_r($_REQUEST, true) . " -->\n"; - $disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk'])); - $disksize = format_bytes($disk['size'] * 1048576); - $bootmanager = htmlspecialchars($_REQUEST['bootmanager']); - $disks = array(); - // Loop through posted items and create an array - for($x=1; isset($_REQUEST['fstype' . $x]); $x++) { - $tmparray = array(); - if($_REQUEST['fstype'] <> "SWAP") - $tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x]; - $tmparray['disk'] = $_REQUEST['disk' . $x]; - $tmparray['fstype'] = $_REQUEST['fstype' . $x]; - $tmparray['size'] = $_REQUEST['size' . $x]; - $tmparray['encpass'] = $_REQUEST['encpass' . $x]; - $disks[] = $tmparray; - } - echo "\n<!-- " . print_r($disks, true) . " --> \n"; - echo <<<EOFAMBAC - <form method="post" action="index.php"> - <input type="hidden" name="fstype" value="{$fstype_echo}"> - <input type="hidden" name="disk" value="{$disk_echo}"> - <input type="hidden" name="state" value="begin_install"> - <input type="hidden" name="swapsize" value="{$swapsize}"> - <input type="hidden" name="encpass" value="{$encpass}"> - <input type="hidden" name="bootmanager" value="{$bootmanager}"> - <div id="mainlevel"> - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td> - <div id="mainarea"> - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td > - <div> - <center> - <div id="pfsensetemplate"> - <table bgcolor="FFFF00" width="800" height="30" cellpadding="2" style="border:1px dashed;"> - <tr valign="middle"> - <td> - <center><b>Please verify that the following is correct:</b></center> - </td> - </tr> - </table> - <p/> - <table width='100%'> - <tr><td colspan='5' align="center"><b>Boot manager: {$bootmanager}</td></tr> - <tr><td colspan='5'><hr></td></tr> - <tr> - <td> - <b>Mount point</b> - </td> - <td> - <b>Filesysyem type</b> - </td> - <td> - <b>Disk</b> - </td> - <td> - <b>Size</b> - </td> - <td> - <b>Encryption password</b> - </td> - -EOFAMBAC; - - foreach($disks as $disk) { - $desc = pcsysinstall_get_disk_info($disk['disk']); - echo "<tr>"; - echo "<td>{$disk['mountpoint']}</td>"; - echo "<td>{$disk['fstype']}</td>"; - echo "<td>{$disk['disk']} {$desc['desc']}</td>"; - echo "<td>{$disk['size']}</td>"; - echo "<td>{$disk['encpass']}</td>"; - echo "</tr>"; - } - -echo <<<EOFAMB - <tr><td colspan='5'><hr></td></tr> - </table> - </div> - </center> - </div> - </td> - </tr> - </table> - </div> - <center> - <p/> - <input type="button" value="Cancel" onClick="javascript:document.location='/installer';"> - <input type="submit" value="Begin installation"> - </center> - </td> - </tr> - </table> - </div> - -EOFAMB; - - page_table_end(); - end_html(); - write_out_pc_sysinstaller_config($disks, $bootmanager); - -} - -function installing_gui() { - global $g, $fstype; - head_html(); - body_html(); - echo "<form action=\"index.php\" method=\"post\" state=\"step1_post\">"; - page_table_start(); - echo <<<EOF - <center> - <table width="100%"> - <tr><td> - <div id="mainlevel"> - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td> - <div id="mainarea"> - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td> - <div id="pfsenseinstaller" width="100%"> - <div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000"> - <table> - <tr> - <td valign="middle"> - <img src="/themes/{$g['theme']}/images/misc/loader.gif"> - </td> - <td valign="middle"> - <font size="2"><b>Starting Installer... Please wait... - </td> - </tr> - </table> - </div> - <div id='pbdiv'> - <br/> - <center> - <table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'> - <tr> - <td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'> - </td> - <td> - <table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'> - <td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left"> - <img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'> - </td> - </table> - </td> - <td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'> - </td> - </tr> - </table> - <br/> - </div> - <textarea name='installeroutput' id='installeroutput' rows="31" cols="90"> - </textarea> - </div> - </td> - </tr> - </table> - </div> - </td> - </tr> - </table> - </div> - </td></tr> - </table> - </center> - <script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script> - -EOF; - page_table_end(); - end_html(); -} - -function page_table_start($pgtitle = "") { - global $g, $fstype; - if($pgtitle == "") - $pgtitle = "{$g['product_name']} installer"; - echo <<<EOF - <center> - <img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/> - <table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000"> - <tr height="10" bgcolor="#990000"> - <td style="border-bottom:1px solid #000000"> - <font color='white'> - <b> - {$pgtitle} - </b> - </font> - </td> - </tr> - <tr> - <td> - -EOF; - -} - -function page_table_end() { - global $g, $fstype; - echo <<<EOF - </td> - </tr> - </table> - </center> - -EOF; - -} - -function installer_custom() { - global $g, $fstype; - if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) - unlink("/tmp/.pc-sysinstall/pc-sysinstall.log"); - head_html(); - body_html(); - page_table_start(); - echo <<<EOF - <script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script> - <script type="text/javascript"> - // Setup rowhelper data types - rowname[0] = "mountpoint"; - rowtype[0] = "textbox"; - rowsize[0] = "8"; - rowname[1] = "fstype"; - rowtype[1] = "select"; - rowsize[1] = "1"; - rowname[2] = "disk"; - rowtype[2] = "select"; - rowsize[2] = "1"; - rowname[3] = "size"; - rowtype[3] = "textbox"; - rowsize[3] = "8"; - rowname[4] = "encpass"; - rowtype[4] = "textbox"; - rowsize[4] = "8"; - field_counter_js = 5; - rows = 1; - totalrows = 1; - loaded = 1; - </script> - <form action="index.php" method="post"> - <input type="hidden" name="state" value="verify_before_install"> - <div id="mainlevel"> - <center> - <table width="100%" border="0" cellpadding="5" cellspacing="0"> - <tr> - <td> - <center> - <div id="mainarea"> - <center> - <table width="100%" border="0" cellpadding="5" cellspacing="5"> - <tr> - <td> - <div id="pfsenseinstaller"> - <center> - <div id='loadingdiv'> - <img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait... - </div> -EOF; - ob_flush(); - $disks = installer_find_all_disks(); - if(!$disks) { - $custom_txt = gettext("ERROR: Could not find any suitable disks for installation."); - } else { - // Prepare disk selection dropdown - $custom_txt = <<<EOF - <center> - <table> - <tr> - <td align='right'> - Boot manager: - </td> - <td> - <select name='bootmanager'> - <option value='bsd'> - BSD - </option> - <option value='none'> - None - </select> - </td> - </tr> - </table> - <hr> - <table id='maintable'><tbody> - <tr> - <td> - <b>Mount point</b> - </td> - <td> - <b>Filesysyem type</b> - </td> - <td> - <b>Disk</b> - </td> - <td> - <b>Size</b> - </td> - <td> - <b>Encryption password</b> - </td> - <td> - - </td> - </tr> - <tr> - -EOF; - // Mount point - $custom_txt .= "<td><input size='8' id='mountpoint1' name='mountpoint1' value='/'></td>"; - // File system type - $custom_txt .= "<td><select onChange='javascript:onfstypeChange()' id='fstype1' name='fstype1'>"; - $select_txt .= "<option value='UFS'>UFS</option>"; - $select_txt .= "<option value='UFS+S'>UFS + Softupdates</option>"; - $select_txt .= "<option value='UFS.eli'>Encrypted UFS</option>"; - $select_txt .= "<option value='UFS+S.eli'>Encrypted UFS + Softupdates</option>"; - $release = php_uname("r"); - $release = $release[0]; - if($release == "9") { - $select_txt .= "<option value='UFS+J'>UFS + Journaling</option>"; - $select_txt .= "<option value='UFS+J.eli'>Encrypted UFS + Journaling</option>"; - } - if(file_exists("/boot/gptzfsboot")) { - $select_txt .= "<option value='ZFS'>ZFS</option>"; - $select_txt .= "<option value='ZFS.eli'>Encrypted ZFS</option>"; - } - $select_txt .= "<option value='SWAP'>SWAP</option>"; - $custom_txt .= "{$select_txt}</select>\n"; - $custom_txt .= "</td>"; - $custom_txt .= "<td><select id='disk1' name='disk1'>\n"; - foreach($disks as $disk) { - $disksize = format_bytes($disk['size'] * 1048576); - $custom_disks .= "<option value='{$disk['disk']}'>{$disk['disk']} - {$disksize} - {$disk['desc']}</option>"; - } - $custom_txt .= "{$custom_disks}</select></td>\n"; - - $custom_txt .= "<td><input name='size1' id='size1' size='8' type='text' value='200M'></td>"; - - $custom_txt .= "<td>"; - $custom_txt .= "<input name='encpass1' size='8' id='encpass1'>"; - $custom_txt .= "</td>"; - - $custom_txt .= "<td>"; - $custom_txt .= "<div id=\"addrowbutton\">"; - $custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">"; - $custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>"; - $custom_txt .= "</div>"; - $custom_txt .= "</td>"; - - $custom_txt .= "</tr>"; - $custom_txt .= "<tfoot></tfoot></tbody></table>"; - } - echo <<<EOF - - <tr> - <td colspan='4'> - <script type="text/javascript"> - \$('loadingdiv').style.visibility='hidden'; - </script> - <div id='contentdiv' style="display:none;"> - <p/> - {$custom_txt}<p/> - <hr><p/> - <input type="button" value="Cancel" onClick="javascript:document.location='/index.php';">   - <input type="submit" value="Next"> - </div> - <script type="text/javascript"> - \$('contentdiv').appear(); - function onfstypeChange() { - var fstype = \$F('fstype'); - if(fstype.substring(fstype.length - 4) == ".eli") { - //\$('encpass').disabled = 0; - alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!'); - } else { - //\$('encpass').disabled = 1; - } - } - onfstypeChange(); - </script> - </center> - </td></tr> - </table> - </div> - </td> - </tr> - </table> - </div> - </td> - </tr> - </table> - </div> - <script type="text/javascript"> - <!-- - newrow[1] = "{$select_txt}"; - newrow[2] = "{$custom_disks}"; - --> - </script> - - -EOF; - page_table_end(); - end_html(); -} - -function installer_main() { - global $g, $fstype; - if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) - unlink("/tmp/.pc-sysinstall/pc-sysinstall.log"); - head_html(); - body_html(); - $disk = installer_find_first_disk(); - // Only enable ZFS if this exists. The install will fail otherwise. - if(file_exists("/boot/gptzfsboot")) - $zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"index.php?state=verify_before_install&fstype=ZFS&swapsize=200M\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>"; - page_table_start(); - echo <<<EOF - <form action="index.php" method="post" state="step1_post"> - <div id="mainlevel"> - <center> - <b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/> - <font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font> - <table width="100%" border="0" cellpadding="5" cellspacing="0"> - <tr> - <td> - <center> - <div id="mainarea"> - <br/> - <center> - Please select an installer option to begin: - <p/> - <table width="100%" border="0" cellpadding="5" cellspacing="5"> - <tr> - <td> - <div id="pfsenseinstaller"> - <center> -EOF; - if(!$disk) { - echo gettext("ERROR: Could not find any suitable disks for installation."); - echo "</div></td></tr></table></div></table></div>"; - end_html(); - exit; - } - echo <<<EOF - - <table cellspacing="5" cellpadding="5" style="border: 1px dashed;"> - <tr bgcolor="#CECECE"><td align="center"> - <a href="index.php?state=verify_before_install&disk={$disk}&fstype=UFS&swapsize=200M">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a> - </td></tr> - {$zfs_enabled} - <tr bgcolor="#AAAAAA"><td align="center"> - <a href="index.php?state=custominstall">Custom installation of {$g['product_name']}</a> - </td></tr> - <tr bgcolor="#CECECE"><td align="center"> - <a href='/'>Cancel and return to Dashboard</a> - </td></tr> - </table> - </center> - </div> - </td> - </tr> - </table> - </div> - </td> - </tr> - </table> - </div> -EOF; - page_table_end(); - end_html(); -} +Header("Location: installer.php"); ?>
\ No newline at end of file diff --git a/usr/local/www/installer/installer.php b/usr/local/www/installer/installer.php new file mode 100644 index 0000000..aee2e61 --- /dev/null +++ b/usr/local/www/installer/installer.php @@ -0,0 +1,965 @@ +<?php +/* + installer.php (pfSense installer) + part of pfSense (http://www.pfsense.com/) + Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +$nocsrf = true; + +require("globals.inc"); +require("guiconfig.inc"); + +define('PC_SYSINSTALL', '/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh'); + +if($g['platform'] == "pfSense" or $g['platform'] == "nanobsd") { + Header("Location: /installer.php"); + exit; +} + +// Main switch dispatcher +switch ($_REQUEST['state']) { + case "update_installer_status": + update_installer_status(); + exit; + case "custominstall": + installer_custom(); + exit; + case "begin_install": + installing_gui(); + begin_install(); + exit; + case "verify_before_install": + verify_before_install(); + exit; + default: + installer_main(); +} + +function write_out_pc_sysinstaller_config($disks, $bootmanager = "bsd") { + $diskareas = ""; + $fd = fopen("/usr/sbin/pc-sysinstall/examples/pfSense-install.cfg", "w"); + if(!$fd) { + return true; + } + if($bootmanager == "") + $bootmanager = "none"; + $numdisks = -1; + $lastdisk = ""; + $diskdefs = ""; + // First make sure we have a boot partition if any slices are encrypted + foreach($disks as $disksa) { + $fstype = $disksa['fstype']; + if(stristr($fstype,".eli")) + $diskareas .= "disk{$numdisks}-part=UFS 500 /boot\n"; + } + // Run through the disks and create the conf areas for pc-sysinstaller + foreach($disks as $disksa) { + $fstype = $disksa['fstype']; + $size = $disksa['size']; + $mountpoint = $disksa['mountpoint']; + $disk = $disksa['disk']; + if($disk <> $lastdisk) { + $lastdisk = $disk; + $numdisks++; + $diskdefs .= "disk{$numdisks}={$disk}\n"; + } + $diskareas .= "disk{$numdisks}-part={$fstype} {$size} {$mountpoint} \n"; + if($encpass) + $diskareas .= "encpass={$encpass}\n"; + } + + $config = <<<EOF +# Sample configuration file for an installation using pc-sysinstall + +installMode=fresh +installInteractive=yes +installType=FreeBSD +installMedium=LiveCD + +# Set the disk parameters +{$diskdefs} +partition=all +bootManager={$bootmanager} +commitDiskPart + +# Setup the disk label +# All sizes are expressed in MB +# Avail FS Types, UFS, UFS+S, UFS+J, ZFS, SWAP +# Size 0 means use the rest of the slice size +# Alternatively, you can append .eli to any of +# the above filesystem types to encrypt that disk. +# If you with to use a passphrase with this +# encrypted partition, on the next line +# the flag "encpass=" should be entered: +# encpass=mypass +# disk0-part=UFS 500 /boot +# disk0-part=UFS.eli 500 / +# disk0-part=UFS.eli 500 /usr +{$diskareaspre} +{$diskareas} +{$diskareaspass} + +# Do it now! +commitDiskLabel + +# Set if we are installing via optical, USB, or FTP +installType=FreeBSD + +packageType=cpdup + +# Optional Components +cpdupPaths=boot,COPYRIGHT,bin,conf,conf.default,dev,etc,home,kernels,libexec,lib,root,sbin,usr,var + +# runExtCommand=chmod a+rx /usr/local/bin/after_installation_routines.sh ; cd / ; /usr/local/bin/after_installation_routines.sh +EOF; + fwrite($fd, $config); + fclose($fd); + return; +} + +function start_installation() { + global $g, $fstype; + if(file_exists("/tmp/install_complete")) + return; + $ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'"); + if($ps_running) + return; + $fd = fopen("/tmp/installer.sh", "w"); + if(!$fd) { + die(gettext("Could not open /tmp/installer.sh for writing")); + exit; + } + fwrite($fd, "rm /tmp/.pc-sysinstall/pc-sysinstall.log 2>/dev/null\n"); + fwrite($fd, "/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh -c /usr/sbin/pc-sysinstall/examples/pfSense-install.cfg \n"); + fwrite($fd, "chmod a+rx /usr/local/bin/after_installation_routines.sh\n"); + fwrite($fd, "cd / && /usr/local/bin/after_installation_routines.sh\n"); + fwrite($fd, "mkdir /mnt/tmp\n"); +// fwrite($fd, "umount /mnt\n"); + fwrite($fd, "touch /tmp/install_complete\n"); + fclose($fd); + exec("chmod a+rx /tmp/installer.sh"); + mwexec_bg("sh /tmp/installer.sh"); +} + +function installer_find_first_disk() { + global $g, $fstype; + $disk = `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list | head -n1 | cut -d':' -f1`; + return trim($disk); +} + +function pcsysinstall_get_disk_info($diskname) { + global $g, $fstype; + $disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`); + $disks_array = array(); + foreach($disk as $d) { + $disks_info = split(":", $d); + $tmp_array = array(); + if($disks_info[0] == $diskname) { + $disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`); + $disk_info_split = split("=", $disk_info); + foreach($disk_info as $di) { + $di_s = split("=", $di); + if($di_s[0]) + $tmp_array[$di_s[0]] = $di_s[1]; + } + $tmp_array['disk'] = trim($disks_info[0]); + $tmp_array['desc'] = trim(htmlentities($disks_info[1])); + return $tmp_array; + } + } +} + +// Return an array with all disks information. +function installer_find_all_disks() { + global $g, $fstype; + $disk = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-list`); + $disks_array = array(); + foreach($disk as $d) { + if(!$d) + continue; + $disks_info = split(":", $d); + $tmp_array = array(); + $disk_info = split("\n", `/usr/sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh disk-info {$disks_info[0]}`); + foreach($disk_info as $di) { + $di_s = split("=", $di); + if($di_s[0]) + $tmp_array[$di_s[0]] = $di_s[1]; + } + $tmp_array['disk'] = trim($disks_info[0]); + $tmp_array['desc'] = trim(htmlentities($disks_info[1])); + $disks_array[] = $tmp_array; + } + return $disks_array; +} + +function update_installer_status() { + global $g, $fstype; + // Ensure status files exist + if(!file_exists("/tmp/installer_installer_running")) + touch("/tmp/installer_installer_running"); + $status = `cat /tmp/.pc-sysinstall/pc-sysinstall.log`; + $status = str_replace("\n", "\\n", $status); + $status = str_replace("\n", "\\r", $status); + echo "this.document.forms[0].installeroutput.value='$status';\n"; + echo "this.document.forms[0].installeroutput.scrollTop = this.document.forms[0].installeroutput.scrollHeight;\n"; + // Find out installer progress + $progress = "5"; + if(strstr($status, "Running: dd")) + $progress = "6"; + if(strstr($status, "Running: gpart create -s GPT")) + $progress = "7"; + if(strstr($status, "Running: gpart bootcode")) + $progress = "7"; + if(strstr($status, "Running: newfs -U")) + $progress = "8"; + if(strstr($status, "Running: sync")) + $progress = "9"; + if(strstr($status, "/boot /mnt/boot")) + $progress = "10"; + if(strstr($status, "/COPYRIGHT /mnt/COPYRIGHT")) + $progress = "11"; + if(strstr($status, "/bin /mnt/bin")) + $progress = "12"; + if(strstr($status, "/conf /mnt/conf")) + $progress = "15"; + if(strstr($status, "/conf.default /mnt/conf.default")) + $progress = "20"; + if(strstr($status, "/dev /mnt/dev")) + $progress = "25"; + if(strstr($status, "/etc /mnt/etc")) + $progress = "30"; + if(strstr($status, "/home /mnt/home")) + $progress = "35"; + if(strstr($status, "/kernels /mnt/kernels")) + $progress = "40"; + if(strstr($status, "/libexec /mnt/libexec")) + $progress = "50"; + if(strstr($status, "/lib /mnt/lib")) + $progress = "60"; + if(strstr($status, "/root /mnt/root")) + $progress = "70"; + if(strstr($status, "/sbin /mnt/sbin")) + $progress = "75"; + if(strstr($status, "/sys /mnt/sys")) + $progress = "80"; + if(strstr($status, "/usr /mnt/usr")) + $progress = "95"; + if(strstr($status, "/usr /mnt/usr")) + $progress = "90"; + if(strstr($status, "/var /mnt/var")) + $progress = "95"; + if(strstr($status, "cap_mkdb /etc/login.conf")) + $progress = "96"; + if(strstr($status, "Setting hostname")) + $progress = "97"; + if(strstr($status, "umount -f /mnt")) + $progress = "98"; + if(strstr($status, "umount -f /mnt")) + $progress = "99"; + if(strstr($status, "Installation finished")) + $progress = "100"; + // Check for error and bail if we see one. + if(stristr($status, "error")) { + $error = true; + echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"2\"><b>An error occurred. Aborting installation. <a href=\"/installer\">Back</a> to webInstaller'; "; + echo "\$('progressbar').style.width='100%';\n"; + unlink_if_exists("/tmp/install_complete"); + return; + } + $running_old = trim(file_get_contents("/tmp/installer_installer_running")); + if($installer_running <> "running") { + $ps_running = exec("ps awwwux | grep -v grep | grep 'sh /tmp/installer.sh'"); + if($ps_running) { + $running = "\$('installerrunning').innerHTML='<table><tr><td valign=\"middle\"><img src=\"/themes/{$g['theme']}/images/misc/loader.gif\"></td><td valign=\"middle\"> <font size=\"2\"><b>Installer running ({$progress}% completed)...</td></tr></table>'; "; + if($running_old <> $running) { + echo $running; + file_put_contents("/tmp/installer_installer_running", "$running"); + } + } + } + if($progress) + echo "\$('progressbar').style.width='{$progress}%';\n"; + if(file_exists("/tmp/install_complete")) { + echo "\$('installerrunning').innerHTML='<img class=\"infoboxnpimg\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\"> <font size=\"+1\">Installation completed. Please <a href=\"reboot.php\">reboot</a> to continue';\n"; + echo "\$('pbdiv').Fade();\n"; + unlink_if_exists("/tmp/installer.sh"); + file_put_contents("/tmp/installer_installer_running", "finished"); + } +} + +function update_installer_status_win($status) { + global $g, $fstype; + echo "<script type=\"text/javascript\">\n"; + echo " \$('installeroutput').value = '" . str_replace(htmlentities($status), "\n", "") . "';\n"; + echo "</script>"; +} + +function begin_install() { + global $g; + if(file_exists("/tmp/install_complete")) + return; + unlink_if_exists("/tmp/install_complete"); + update_installer_status_win(sprintf(gettext("Beginning installation on disk %s."),$disk)); + start_installation(); +} + +function head_html() { + global $g, $fstype; + echo <<<EOF +<html> + <head> + <style type='text/css'> + a:link { + color: #000000; + text-decoration:underline; + font-size:14; + } + a:visited { + color: #000000; + text-decoration:underline; + font-size:14; + } + a:hover { + color: #FFFF00; + text-decoration: none; + font-size:14; + } + a:active { + color: #FFFF00; + text-decoration:underline; + font-size:14; + } + </style> + </head> +EOF; + +} + +function body_html() { + global $g, $fstype; + $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); + if(strstr($pfSversion, "1.2")) + $one_two = true; + $pgtitle = array("{$g['product_name']}", gettext("Installer")); + include("head.inc"); + echo <<<EOF + <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> + <script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script> + <script type="text/javascript"> + function getinstallerprogress() { + url = '/installer/installer.php'; + pars = 'state=update_installer_status'; + callajax(url, pars, installcallback); + } + function callajax(url, pars, activitycallback) { + var myAjax = new Ajax.Request( + url, + { + method: 'post', + parameters: pars, + onComplete: activitycallback + }); + } + function installcallback(transport) { + setTimeout('getinstallerprogress()', 2000); + eval(transport.responseText); + } + </script> +EOF; + + if($one_two) + echo "<p class=\"pgtitle\">{$pgtitle}</font></p>"; + + if ($savemsg) print_info_box($savemsg); +} + +function end_html() { + global $g, $fstype; + echo "</form>"; + echo "</body>"; + echo "</html>"; +} + +function template() { + global $g, $fstype; + head_html(); + body_html(); + echo <<<EOF + <div id="mainlevel"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> + <div id="mainarea"> + <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="tabcont" > + <form action="installer.php" method="post"> + <div id="pfsensetemplate"> + + + </div> + </td> + </tr> + </table> + </div> + </td> + </tr> + </table> + </div> +EOF; + end_html(); +} + +function verify_before_install() { + global $g, $fstype; + head_html(); + body_html(); + page_table_start(); + echo "\n<!--" . print_r($_REQUEST, true) . " -->\n"; + $disk = pcsysinstall_get_disk_info(htmlspecialchars($_REQUEST['disk'])); + $disksize = format_bytes($disk['size'] * 1048576); + $bootmanager = htmlspecialchars($_REQUEST['bootmanager']); + $disks = array(); + // Loop through posted items and create an array + for($x=1; isset($_REQUEST['fstype' . $x]); $x++) { + $tmparray = array(); + if($_REQUEST['fstype'] <> "SWAP") + $tmparray['mountpoint'] = $_REQUEST['mountpoint' . $x]; + else + $tmparray['mountpoint'] = "none"; + $tmparray['disk'] = $_REQUEST['disk' . $x]; + $tmparray['fstype'] = $_REQUEST['fstype' . $x]; + $tmparray['size'] = $_REQUEST['size' . $x]; + $tmparray['encpass'] = $_REQUEST['encpass' . $x]; + $disks[] = $tmparray; + } + echo "\n<!-- " . print_r($disks, true) . " --> \n"; + echo <<<EOFAMBAC + <form method="post" action="installer.php"> + <input type="hidden" name="fstype" value="{$fstype_echo}"> + <input type="hidden" name="disk" value="{$disk_echo}"> + <input type="hidden" name="state" value="begin_install"> + <input type="hidden" name="swapsize" value="{$swapsize}"> + <input type="hidden" name="encpass" value="{$encpass}"> + <input type="hidden" name="bootmanager" value="{$bootmanager}"> + <div id="mainlevel"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> + <div id="mainarea"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td > + <div> + <center> + <div id="pfsensetemplate"> + <table bgcolor="FFFF00" width="800" height="30" cellpadding="2" style="border:1px dashed;"> + <tr valign="middle"> + <td> + <center><b>Please verify that the following is correct:</b></center> + </td> + </tr> + </table> + <p/> + <table width='100%'> + <tr><td colspan='5' align="center"><b>Boot manager: {$bootmanager}</td></tr> + <tr><td colspan='5'><hr></td></tr> + <tr> + <td> + <b>Mount point</b> + </td> + <td> + <b>Filesysyem type</b> + </td> + <td> + <b>Disk</b> + </td> + <td> + <b>Size</b> + </td> + <td> + <b>Encryption password</b> + </td> + +EOFAMBAC; + + foreach($disks as $disk) { + $desc = pcsysinstall_get_disk_info($disk['disk']); + echo "<tr>"; + echo "<td>{$disk['mountpoint']}</td>"; + echo "<td>{$disk['fstype']}</td>"; + echo "<td>{$disk['disk']} {$desc['desc']}</td>"; + echo "<td>{$disk['size']}</td>"; + echo "<td>{$disk['encpass']}</td>"; + echo "</tr>"; + } + +echo <<<EOFAMB + <tr><td colspan='5'><hr></td></tr> + </table> + </div> + </center> + </div> + </td> + </tr> + </table> + </div> + <center> + <p/> + <input type="button" value="Cancel" onClick="javascript:document.location='/installer';"> + <input type="submit" value="Begin installation"> + </center> + </td> + </tr> + </table> + </div> + +EOFAMB; + + page_table_end(); + end_html(); + write_out_pc_sysinstaller_config($disks, $bootmanager); + +} + +function installing_gui() { + global $g, $fstype; + head_html(); + body_html(); + echo "<form action=\"installer.php\" method=\"post\" state=\"step1_post\">"; + page_table_start(); + echo <<<EOF + <center> + <table width="100%"> + <tr><td> + <div id="mainlevel"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> + <div id="mainarea"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td> + <div id="pfsenseinstaller" width="100%"> + <div id='installerrunning' width='100%' style="padding:8px; border:1px dashed #000000"> + <table> + <tr> + <td valign="middle"> + <img src="/themes/{$g['theme']}/images/misc/loader.gif"> + </td> + <td valign="middle"> + <font size="2"><b>Starting Installer... Please wait... + </td> + </tr> + </table> + </div> + <div id='pbdiv'> + <br/> + <center> + <table id='pbtable' height='15' width='640' border='0' colspacing='0' cellpadding='0' cellspacing='0'> + <tr> + <td background="/themes/the_wall/images/misc/bar_left.gif" height='15' width='5'> + </td> + <td> + <table id="progholder" name="progholder" height='15' width='630' border='0' colspacing='0' cellpadding='0' cellspacing='0'> + <td background="/themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left"> + <img src='/themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'> + </td> + </table> + </td> + <td background="/themes/the_wall/images/misc/bar_right.gif" height='15' width='5'> + </td> + </tr> + </table> + <br/> + </div> + <textarea name='installeroutput' id='installeroutput' rows="31" cols="90"> + </textarea> + </div> + </td> + </tr> + </table> + </div> + </td> + </tr> + </table> + </div> + </td></tr> + </table> + </center> + <script type="text/javascript">setTimeout('getinstallerprogress()', 250);</script> + +EOF; + page_table_end(); + end_html(); +} + +function page_table_start($pgtitle = "") { + global $g, $fstype; + if($pgtitle == "") + $pgtitle = "{$g['product_name']} installer"; + echo <<<EOF + <center> + <img border="0" src="/themes/{$g['theme']}/images/logo.gif"></a><br/> + <table cellpadding="6" cellspacing="0" width="550" style="border:1px solid #000000"> + <tr height="10" bgcolor="#990000"> + <td style="border-bottom:1px solid #000000"> + <font color='white'> + <b> + {$pgtitle} + </b> + </font> + </td> + </tr> + <tr> + <td> + +EOF; + +} + +function page_table_end() { + global $g, $fstype; + echo <<<EOF + </td> + </tr> + </table> + </center> + +EOF; + +} + +function installer_custom() { + global $g, $fstype; + if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) + unlink("/tmp/.pc-sysinstall/pc-sysinstall.log"); + head_html(); + body_html(); + page_table_start(); + echo <<<EOF + <script type="text/javascript" src="/javascript/row_helper_dynamic.js"></script> + <script type="text/javascript"> + // Setup rowhelper data types + rowname[0] = "mountpoint"; + rowtype[0] = "textbox"; + rowsize[0] = "8"; + rowname[1] = "fstype"; + rowtype[1] = "select"; + rowsize[1] = "1"; + rowname[2] = "disk"; + rowtype[2] = "select"; + rowsize[2] = "1"; + rowname[3] = "size"; + rowtype[3] = "textbox"; + rowsize[3] = "8"; + rowname[4] = "encpass"; + rowtype[4] = "textbox"; + rowsize[4] = "8"; + field_counter_js = 5; + rows = 1; + totalrows = 1; + loaded = 1; + </script> + <form action="installer.php" method="post"> + <input type="hidden" name="state" value="verify_before_install"> + <div id="mainlevel"> + <center> + <table width="100%" border="0" cellpadding="5" cellspacing="0"> + <tr> + <td> + <center> + <div id="mainarea"> + <center> + <table width="100%" border="0" cellpadding="5" cellspacing="5"> + <tr> + <td> + <div id="pfsenseinstaller"> + <center> + <div id='loadingdiv'> + <img src="/themes/{$g['theme']}/images/misc/loader.gif"> Probing disks, please wait... + </div> +EOF; + ob_flush(); + $disks = installer_find_all_disks(); + if(!$disks) { + $custom_txt = gettext("ERROR: Could not find any suitable disks for installation."); + } else { + // Prepare disk selection dropdown + $custom_txt = <<<EOF + <center> + <table> + <tr> + <td align='right'> + Boot manager: + </td> + <td> + <select name='bootmanager'> + <option value='bsd'> + BSD + </option> + <option value='none'> + None + </select> + </td> + </tr> + </table> + <hr> + <table id='maintable'><tbody> + <tr> + <td> + <b>Mount point</b> + </td> + <td> + <b>Filesysyem type</b> + </td> + <td> + <b>Disk</b> + </td> + <td> + <b>Size</b> + </td> + <td> + <b>Encryption password</b> + </td> + <td> + + </td> + </tr> + <tr> + +EOF; + + // Output disk editor rows + $first_disk = trim(installer_find_first_disk()); + $disk_info = pcsysinstall_get_disk_info($first_disk); + $size = $disk_info['size']; + $first_disk_size = $size - 256; + echo "\n\n<!-- $first_disk - " . print_r($disk_info, true) . " - $size - $first_disk_size -->\n\n"; + $custom_txt .= return_rowhelper_row("1", "/", "UFS", $first_disk, "{$first_disk_size}", ""); + $custom_txt .= return_rowhelper_row("2", "none", "SWAP", $first_disk, "256", ""); + + $custom_txt .= "</tr>"; + $custom_txt .= "<tfoot></tfoot></tbody></table>"; + } + echo <<<EOF + + <tr> + <td colspan='4'> + <script type="text/javascript"> + \$('loadingdiv').style.visibility='hidden'; + </script> + <div id='contentdiv' style="display:none;"> + <p/> + {$custom_txt}<p/> + <hr><p/> + <input type="button" value="Cancel" onClick="javascript:document.location='/installer.php';">   + <input type="submit" value="Next"> + </div> + <script type="text/javascript"> + \$('contentdiv').appear(); + function onfstypeChange() { + var fstype = \$F('fstype'); + if(fstype.substring(fstype.length - 4) == ".eli") { + //\$('encpass').disabled = 0; + alert('NOTE: If you define a disk encryption password you will need to enter it on *EVERY* bootup!'); + } else { + //\$('encpass').disabled = 1; + } + } + onfstypeChange(); + </script> + </center> + </td></tr> + </table> + </div> + </td> + </tr> + </table> + </center> + <span class="vexpl"> + <span class="red"> + <strong> + NOTES: + </strong> + </span> + <br/>* Sizes are in megabytes. + <br/>* Encryption password field should only be used if a encrypted filesystem was chosen + </span> + </strong> + </div> + </td> + </tr> + </table> + </div> + </center> + <script type="text/javascript"> + <!-- + newrow[1] = "{$select_txt}"; + newrow[2] = "{$custom_disks}"; + --> + </script> + + +EOF; + page_table_end(); + end_html(); +} + +function installer_main() { + global $g, $fstype; + if(file_exists("/tmp/.pc-sysinstall/pc-sysinstall.log")) + unlink("/tmp/.pc-sysinstall/pc-sysinstall.log"); + head_html(); + body_html(); + $disk = installer_find_first_disk(); + // Only enable ZFS if this exists. The install will fail otherwise. + if(file_exists("/boot/gptzfsboot")) + $zfs_enabled = "<tr bgcolor=\"#9A9A9A\"><td align=\"center\"><a href=\"installer.php?state=verify_before_install&fstype=ZFS&swapsize=200M\">Easy installation of {$g['product_name']} using the ZFS filesystem on disk {$disk}</a></td></tr>"; + page_table_start(); + echo <<<EOF + <form action="installer.php" method="post" state="step1_post"> + <div id="mainlevel"> + <center> + <b><font face="arial" size="+2">Welcome to the {$g['product_name']} webInstaller!</b></font><p/> + <font face="arial" size="+1">This utility will install {$g['product_name']} to a hard disk, flash drive, etc.</font> + <table width="100%" border="0" cellpadding="5" cellspacing="0"> + <tr> + <td> + <center> + <div id="mainarea"> + <br/> + <center> + Please select an installer option to begin: + <p/> + <table width="100%" border="0" cellpadding="5" cellspacing="5"> + <tr> + <td> + <div id="pfsenseinstaller"> + <center> +EOF; + if(!$disk) { + echo gettext("ERROR: Could not find any suitable disks for installation."); + echo "</div></td></tr></table></div></table></div>"; + end_html(); + exit; + } + echo <<<EOF + + <table cellspacing="5" cellpadding="5" style="border: 1px dashed;"> + <tr bgcolor="#CECECE"><td align="center"> + <a href="installer.php?state=verify_before_install&disk={$disk}&fstype=UFS&swapsize=200M">Easy installation of {$g['product_name']} using the UFS filesystem on disk {$disk}</a> + </td></tr> + {$zfs_enabled} + <tr bgcolor="#AAAAAA"><td align="center"> + <a href="installer.php?state=custominstall">Custom installation of {$g['product_name']}</a> + </td></tr> + <tr bgcolor="#CECECE"><td align="center"> + <a href='/'>Cancel and return to Dashboard</a> + </td></tr> + </table> + </center> + </div> + </td> + </tr> + </table> + </div> + </td> + </tr> + </table> + </div> +EOF; + page_table_end(); + end_html(); +} + +function return_rowhelper_row($rownum, $mountpoint, $fstype, $disk, $size, $encpass) { + global $g; + // Slice #2 - SWAP + // Mount point + $disks = installer_find_all_disks(); + $custom_txt .= "<tr>"; + $custom_txt .= "<td><input size='8' id='mountpoint{$rownum}' name='mountpoint{$rownum}' value='{$mountpoint}'></td>"; + // File system type + $types = array( + 'UFS' => 'UFS', + 'UFS+S' => 'UFS + Softupdates', + 'UFS.eli' => 'Encrypted UFS', + 'UFS+S.eli' => 'Encrypted UFS + Softupdates', + 'SWAP' => 'SWAP' + ); + $release = php_uname("r"); + $release = $release[0]; + if($release == "9") { + $types['UFS+J'] = "UFS + Journaling"; + $types['UFS+J.eli'] = "Encrypted UFS + Journaling"; + } + if(file_exists("/boot/gptzfsboot")) { + $types['ZFS'] = "Zetabyte Filesystem"; + $types['ZFS.eli'] = "Encrypted Zetabyte Filesystem"; + } + $custom_txt .= "<td><select onChange='javascript:onfstypeChange()' id='fstype{$rownum}' name='fstype{$rownum}'>"; + foreach($types as $desc => $type) { + if($type == $fstype) + $SELECTED="SELECTED"; + else + $SELECTED=""; + $select_txt .= "<option value='$type' $SELECTED>$desc</option>"; + } + $custom_txt .= "{$select_txt}</select>\n"; + $custom_txt .= "</td>"; + $custom_txt .= "<td><select id='disk{$rownum}' name='disk{$rownum}'>\n"; + foreach($disks as $dsk) { + $disksize = format_bytes($dsk['size'] * 1048576); + if($disk == $dsk['disk']) + $SELECTED="SELECTED"; + else + $SELECTED=""; + $custom_disks .= "<option value='{$dsk['disk']}' $SELECTED>{$dsk['disk']} - {$disksize} - {$dsk['desc']}</option>"; + } + $custom_txt .= "{$custom_disks}</select></td>\n"; + + $custom_txt .= "<td><input name='size{$rownum}' id='size{$rownum}' size='8' type='text' value='{$size}'></td>"; + + $custom_txt .= "<td>"; + $custom_txt .= "<input id='encpass{$rownum}' name='encpass{$rownum}' size='8' value='{$encpass}'>"; + $custom_txt .= "</td>"; + + // Add Rowhelper + button + if($rownum == 1) { + $custom_txt .= "<td>"; + $custom_txt .= "<div id=\"addrowbutton\">"; + $custom_txt .= "<a onclick=\"javascript:addRowTo('maintable', 'formfldalias'); return false;\" href=\"#\">"; + $custom_txt .= "<img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" alt=\"\" title=\"add another entry\" /></a>"; + $custom_txt .= "</div>"; + $custom_txt .= "</td>"; + } + + $custom_txt .= "</tr>"; + return $custom_txt; +} + +?>
\ No newline at end of file |