aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/freenas/www/disks_manage_init.php500
1 files changed, 400 insertions, 100 deletions
diff --git a/packages/freenas/www/disks_manage_init.php b/packages/freenas/www/disks_manage_init.php
index 278efdd5..a3032d83 100644
--- a/packages/freenas/www/disks_manage_init.php
+++ b/packages/freenas/www/disks_manage_init.php
@@ -49,6 +49,365 @@ require_once("guiconfig.inc");
require_once("freenas_guiconfig.inc");
require_once("freenas_functions.inc");
+define("DONE_PARAGRAPH", "
+ <p>
+ <span class='red' style='font-family: Courier, monospace; font-size: small;'><strong>Done!</strong></span>
+ </p>
+ ");
+define("DISK_DETAILS_PARA", "
+ <p style='font-size: small;'>
+ <strong>Disk initialization details</strong> (use the toggle icon to unveil detailed infos):
+ </p>
+ ");
+
+function create_format_output($disk, $type, $notinitmbr) {
+ $ddetails = DISK_DETAILS_PARA;
+ $dopara = DONE_PARAGRAPH;
+
+ ob_end_flush();
+
+ $retvalue =<<<EOD
+{$ddetails}
+
+EOD;
+
+ // Erase MBR if not checked
+ if (!$notinitmbr) {
+ $button = create_toggle_button("Erasing MBR and all paritions", "mbr_out");
+ $a_out = exec_command_and_return_text_array("dd if=/dev/zero of=" . escapeshellarg($disk) . " bs=32k count=640");
+ $diskinit_str = implode("\n", $a_out);
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="mbr_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ } else {
+ $diskinit_str = "Keeping the MBR and all partitions";
+ $retvalue .=<<<EOD
+ <div id="mbr_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ } // end if
+
+ switch ($type) {
+ case "ufs":
+ $button = create_toggle_button("Creating one parition", "ufs_fdisk_out");
+ /* Initialize disk */
+ $a_out = exec_command_and_return_text_array("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufs_fdisk_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Initializing parition", "ufs_dd_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufs_dd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating BSD label", "ufs_label_out");
+ /* Create s1 label */
+ $a_out = exec_command_and_return_text_array("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufs_label_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating Filesystem", "ufs_newfs_out");
+ /* Create filesystem */
+ $a_out = exec_command_and_return_text_array("/sbin/newfs -U " . escapeshellarg($disk) . "s1");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufs_newfs_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+
+ break; // end case "ufs":
+ case "ufs_no_su":
+ $button = create_toggle_button("Creating one parition", "ufsn_fdisk_out");
+ /* Initialize disk */
+ $a_out = exec_command_and_return_text_array("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsn_fdisk_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ $button = create_toggle_button("Initializing parition", "ufsn_dd_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsn_dd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ $button = create_toggle_button("Creating BSD label", "ufsn_label_out");
+ /* Create s1 label */
+ $a_out = exec_command_and_return_text_array("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsn_label_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ $button = create_toggle_button("Creating Filesystem", "ufsn_newfs_out");
+ /* Create filesystem */
+ $a_out = exec_command_and_return_text_array("/sbin/newfs -m 0 " . escapeshellarg($disk) . "s1");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsn_newfs_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+
+ break; // end ufs_no_su
+ case "ufsgpt":
+ $button = create_toggle_button("Destroying old GTP information", "ufsg_gptd_out");
+ /* Destroy GPT partition table */
+ $a_out = exec_command_and_return_text_array("/sbin/gpt destroy " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsg_gptd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating GPT partition", "ufsg_gptc_out");
+ /* Create GPT partition table */
+ $a_out = exec_command_and_return_text_array("/sbin/gpt create -f " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+ $a_out = exec_command_and_return_text_array("/sbin/gpt add -t ufs " . escapeshellarg($disk));
+ $diskinit_str .= implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsg_gptc_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating Filesystem with Soft Updates", "ufsg_newfs_out");
+ /* Create filesystem */
+ $a_out = exec_command_and_return_text_array("/sbin/newfs -U " . escapeshellarg($disk) . "p1");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsg_newfs_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+
+ break; // end case "ufsgpt":
+ case "ufsgpt_no_su":
+ $button = create_toggle_button("Destroying old GTP information", "ufsgn_gpt_out");
+ /* Destroy GPT partition table */
+ $a_out = exec_command_and_return_text_array("/sbin/gpt destroy " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsgn_gpt_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating GPT partition", "ufsgn_gptc_out");
+ /* Create GPT partition table */
+ $a_out = exec_command_and_return_text_array("/sbin/gpt create -f " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+ $a_out = exec_command_and_return_text_array("/sbin/gpt add -t ufs " . escapeshellarg($disk));
+ $diskinit_str .= implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsgn_gptc_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ $button = create_toggle_button("Creating Filesystem without Soft Updates", "ufsgn_newfs_out");
+ /* Create filesystem */
+ $a_out = exec_command_and_return_text_array("/sbin/newfs -m 0 " . escapeshellarg($disk) . "p1");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="ufsgn_newfs_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+
+ break; // end case "ufsgpt_no_su":
+ case "softraid":
+ $button = create_toggle_button("Initializing disk", "softr_fdisk_out");
+ /* Initialize disk */
+ $a_out = exec_command_and_return_text_array("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="softr_fdisk_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Initializing partition", "softr_dd_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="softr_dd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+ $button = create_toggle_button("Delete old gmirror information", "softr_dd_out");
+ /* Delete old gmirror information */
+ $a_out = exec_command_and_return_text_array("/sbin/gmirror clear " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="softr_dd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+
+ break; // end case "softraid":
+ case "msdos":
+ $button = create_toggle_button("Initialize disk", "dos_fdisk_out");
+ /* Initialize disk */
+ $a_out = exec_command_and_return_text_array("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="dos_fdisk_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Initialize partion", "dos_dd_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="dos_dd_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating BSD label", "dos_label_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="dos_label_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+
+EOD;
+
+ $button = create_toggle_button("Creating Filesystem", "dos_newfs_out");
+ /* Initialise the partition (optional) */
+ $a_out = exec_command_and_return_text_array("/sbin/newfs_msdos -F 32 " . escapeshellarg($disk) . "s1");
+ $diskinit_str = implode("\n", $a_out);
+
+ $retvalue .=<<<EOD
+ {$button}
+ <div id="dos_newfs_out" style="display: none; font-family: Courier, monospace; font-size: small;">
+ <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre>
+ </div>
+{$dopara}
+
+EOD;
+ break; // end case "msdos":
+ } // end switch
+
+ return $retvalue;
+}
+
+function create_toggle_button($title, $totoggle) {
+ global $g;
+
+ $returnval =<<<EOD
+ <table cellpadding="0" cellspacing="0" border="0" style="padding-bottom: 8px;">
+ <tr>
+ <td align="left" valign="middle" style="padding-right: 5px;">
+ <img src='/themes/{$g['theme']}/images/misc/bullet_toggle_plus.png' alt='' border='0' style='border: solid 1px silver; cursor: pointer;' onclick='toggle_cmdout(this, "{$totoggle}");' />
+ </td>
+ <td align="left" valign="middle" style='font-family: Courier, monospace; font-size: small;'>
+ {$title}:
+ </td>
+ </tr>
+ </table>
+EOD;
+
+ return $returnval;
+}
+
if (!is_array($freenas_config['disks']['disk']))
$freenas_config['disks']['disk'] = array();
@@ -184,6 +543,9 @@ if (! empty($_POST))
}
write_config();
+
+ echo create_format_output($disk, $type, $notinitmbr);
+ exit; // cause of Ajax
}
}
}
@@ -217,6 +579,16 @@ function disk_change() {
<?php endforeach; ?>
}
}
+
+function toggle_cmdout(image, totoggle) {
+ var plusSrc = "/themes/<?= $g['theme'] ?>/images/misc/bullet_toggle_plus.png";
+ var minusSrc = "/themes/<?= $g['theme'] ?>/images/misc/bullet_toggle_minus.png";
+ var currentSrc = image.src;
+ var newSrc = (currentSrc.indexOf("plus") >= 0) ? minusSrc : plusSrc;
+
+ image.src = newSrc;
+ Effect.toggle(totoggle, 'appear', { duration: 0.75 });
+}
// -->
</script>
</head>
@@ -246,6 +618,30 @@ function disk_change() {
<div id="mainarea">
<form id="iform" name="iform" action="disks_manage_init.php" method="post">
<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
+ <script type="text/javascript">
+ function execFormat() {
+ var to_insert = "<div style='visibility:hidden' id='loading' name='loading'><img src='/themes/nervecenter/images/misc/loader_tab.gif' /></div>";
+ new Insertion.Before('doFormatSubmit', to_insert);
+
+ $("doFormatSubmit").style.visibility = "hidden";
+ $('loading').style.visibility = 'visible';
+
+ new Ajax.Request(
+ "<?=$_SERVER['SCRIPT_NAME'];?>", {
+ method : "post",
+ parameters : Form.serialize($("iform")),
+ onSuccess : execFormatComplete
+ }
+ );
+ }
+
+ function execFormatComplete(req) {
+ $("formatOutputTD").innerHTML = req.responseText;
+ $('loading').style.visibility = 'hidden';
+ $("doFormatSubmit").style.visibility = 'visible';
+ $("formatOutputTD").style.visibility = 'visible';
+ }
+ </script>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Disk");?></td>
<td width="78%" class="vtable">
@@ -278,108 +674,12 @@ function disk_change() {
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
- <input id="submitt" name="Submitt" type="submit" class="formbtn" value="<?=gettext("Format disk!");?>" />
+ <input id="doFormatSubmit" name="doFormatSubmit" type="button" class="formbtn" value="<?=gettext("Format disk!");?>" onclick="execFormat();" />
</td>
</tr>
<tr>
- <td valign="top" colspan="2">
- <?
- if ($do_format) {
- echo "<strong>Disk initialization details:</strong>";
- echo('<pre style="font-size: small; border: solid 1px silver; padding: 4px;">');
- ob_end_flush();
-
- /* Erase MBR if not checked*/
- if (!$notinitmbr) {
- echo "Erasing MBR\n";
- system("dd if=/dev/zero of=" . escapeshellarg($disk) . " bs=32k count=640");
- }
- else {
- echo "Keeping the MBR and all partitions\n";
- }
-
- switch ($type)
- {
- case "ufs":
- /* Initialize disk */
- echo "Creating one parition:\n";
- system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
- /* Initialise the partition (optional) */
- echo "Initializing parition:\n";
- system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
- /* Create s1 label */
- echo "Creating BSD label:\n";
- system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
- // Create filesystem
- echo "Creating Filesystem:\n";
- system("/sbin/newfs -U " . escapeshellarg($disk) . "s1");
- echo "Done!\n";
- break;
- case "ufs_no_su":
- /* Initialize disk */
- echo "Creating one parition:\n";
- system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
- /* Initialise the partition (optional) */
- echo "Initializing parition:\n";
- system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
- /* Create s1 label */
- echo "Creating BSD label:\n";
- system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
- // Create filesystem
- echo "Creating Filesystem:\n";
- system("/sbin/newfs -m 0 " . escapeshellarg($disk) . "s1");
- echo "Done!\n";
- break;
- case "ufsgpt":
- /* Create GPT partition table */
- echo "Destroying old GTP information:\n";
- system("/sbin/gpt destroy " . escapeshellarg($disk));
- echo "Creating GPT partition:\n";
- system("/sbin/gpt create -f " . escapeshellarg($disk));
- system("/sbin/gpt add -t ufs " . escapeshellarg($disk));
- // Create filesystem
- echo "Creating Filesystem with Soft Updates:\n";
- system("/sbin/newfs -U " . escapeshellarg($disk) . "p1");
- echo "Done!\n";
- break;
- case "ufsgpt_no_su":
- /* Create GPT partition table */
- echo "Destroying old GTP information:\n";
- system("/sbin/gpt destroy " . escapeshellarg($disk));
- echo "Creating GPT partition:\n";
- system("/sbin/gpt create -f " . escapeshellarg($disk));
- system("/sbin/gpt add -t ufs " . escapeshellarg($disk));
- // Create filesystem
- echo "Creating Filesystem without Soft Updates:\n";
- system("/sbin/newfs -m 0 " . escapeshellarg($disk) . "p1");
- echo "Done!\n";
- break;
- case "softraid":
- /* Initialize disk */
- system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
- /* Initialise the partition (optional) */
- system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
- /* Delete old gmirror information */
- system("/sbin/gmirror clear " . escapeshellarg($disk));
- echo "Done!\n";
- break;
- case "msdos":
- /* Initialize disk */
- system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
- /* Initialise the partition (optional) */
- system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
- /* Create s1 label */
- system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
- // Create filesystem
- system("/sbin/newfs_msdos -F 32 " . escapeshellarg($disk) . "s1");
- echo "Done!\n";
- break;
- }
-
- echo('</pre>');
- }
- ?>
- </td>
+ <!-- Format Output Container - Do Not Delete -->
+ <td id="formatOutputTD" valign="top" colspan="2" style="visibility: hidden; border: solid 1px silver; vertical-align: middle; width: 100%"></td>
</tr>
<tr>
<td align="left" valign="top" colspan="2">
@@ -397,7 +697,7 @@ function disk_change() {
</form>
</div>
</td>
- </tr>
+ </tr>
</table>
<?php include("fend.inc"); ?>
<?= checkForInputErrors(); ?>