diff options
author | Daniel Stefan Haischt <dsh@pfsense.org> | 2007-01-10 21:22:10 +0000 |
---|---|---|
committer | Daniel Stefan Haischt <dsh@pfsense.org> | 2007-01-10 21:22:10 +0000 |
commit | 4c220daee80a863e20460950a2a49d29d5bc3075 (patch) | |
tree | 1c7e6ffbe16fc0b93139c2e05e638f3ac4c104f1 /packages/freenas | |
parent | cc4839f88c460372e7e73271990cc8b8aaf9ddd0 (diff) | |
download | pfsense-packages-4c220daee80a863e20460950a2a49d29d5bc3075.tar.gz pfsense-packages-4c220daee80a863e20460950a2a49d29d5bc3075.tar.bz2 pfsense-packages-4c220daee80a863e20460950a2a49d29d5bc3075.zip |
* added Ajax support to each *_tools.php page
Diffstat (limited to 'packages/freenas')
-rw-r--r-- | packages/freenas/pkg/freenas_guiconfig.inc | 124 | ||||
-rw-r--r-- | packages/freenas/www/disks_manage_init.php | 392 | ||||
-rw-r--r-- | packages/freenas/www/disks_manage_tools.php | 151 | ||||
-rw-r--r-- | packages/freenas/www/disks_mount_tools.php | 91 |
4 files changed, 359 insertions, 399 deletions
diff --git a/packages/freenas/pkg/freenas_guiconfig.inc b/packages/freenas/pkg/freenas_guiconfig.inc index c049659a..93e7a826 100644 --- a/packages/freenas/pkg/freenas_guiconfig.inc +++ b/packages/freenas/pkg/freenas_guiconfig.inc @@ -38,8 +38,132 @@ $d_groupconfdirty_path = $g['varrun_path'] . "/group.conf.dirty"; $d_smbshareconfdirty_path = $g['varrun_path'] . "/smbshare.conf.dirty"; $d_upnpconfdirty_path = $g['varrun_path'] . "/upnp.conf.dirty"; +/* ============================================================================= */ +/* == Constants used together with executing a UNIX command line tool == */ +/* ============================================================================= */ + +define("DONE_PARAGRAPH", " + <p> + <span class='red' style='font-family: Courier, monospace; font-size: small;'><strong>Done!</strong></span> + </p> + "); + +define("CMDOUT_PARA", " + <p style='font-size: small;'> + <strong>Command output:</strong> (use the toggle icon to unveil detailed infos): + </p> + "); + +define("CMDOUT_TOGGLE_FUNC", " +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 }); +} +"); + +define("CMDOUT_AJAX_SCRIPT", " + <script type='text/javascript'> + function execCMD() { + var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='/themes/nervecenter/images/misc/loader_tab.gif' \/><\/div>\"; + new Insertion.Before('doCMDSubmit', to_insert); + + $('doCMDSubmit').style.visibility = 'hidden'; + $('loading').style.visibility = 'visible'; + $('cmdOutputTD').innerHTML = ''; + + new Ajax.Request( + \"{$_SERVER['SCRIPT_NAME']}\", { + method : 'post', + parameters : Form.serialize($('iform')), + onSuccess : execCMDComplete, + onFailure : execCMDFailure + } + ); + } + + function execCMDFailure(req) { + if($('doCMDSubmit')) $('doCMDSubmit').style.visibility = 'visible'; + if($('loading')) $('loading').style.visibility = 'hidden'; + if($('inputerrors')) window.scrollTo(0, 0); + if($('inputerrors')) new Effect.Shake($('inputerrors')); + if($('inputerrors')) $('inputerrors').innerHTML = req.responseText; + } + + function execCMDComplete(req) { + $('cmdOutputTD').innerHTML = req.responseText; + $('loading').style.visibility = 'hidden'; + $('doCMDSubmit').style.visibility = 'visible'; + $('cmdOutputTD').style.visibility = 'visible'; + } + </script> +"); + $freenas_config =& $config['installedpackages']['freenas']['config'][0]; +/* ============================================================================= */ +/* == Functions used together with executing a UNIX command line tool == */ +/* ============================================================================= */ + +function assemble_cmdout($button, $out, $done = false) { + $dopara = DONE_PARAGRAPH; + + $retvalue =<<<EOD +{$button} +{$out} + +EOD; + + if ($done) { $retvalue .= "{$dopara}\n"; } + return $retvalue; +} + +function create_cmdout_container($id = "", $cmd = "") { + $diskinit_str = ""; + + if (is_array($cmd)) { + foreach ($cmd as $cmdline) { + $a_out = exec_command_and_return_text_array($cmdline); + $diskinit_str .= implode("\n", $a_out); + } + } else { + $a_out = exec_command_and_return_text_array($cmd); + $diskinit_str = implode("\n", $a_out); + } + + $returnval =<<<EOD + <div id="{$id}" 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; + + return $returnval; +} + +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; +} + function print_error_box_np($msg) { global $g; diff --git a/packages/freenas/www/disks_manage_init.php b/packages/freenas/www/disks_manage_init.php index f72d1505..4f55aabe 100644 --- a/packages/freenas/www/disks_manage_init.php +++ b/packages/freenas/www/disks_manage_init.php @@ -49,11 +49,6 @@ 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): @@ -62,7 +57,6 @@ define("DISK_DETAILS_PARA", " function create_format_output($disk, $type, $notinitmbr) { $ddetails = DISK_DETAILS_PARA; - $dopara = DONE_PARAGRAPH; ob_end_flush(); @@ -74,20 +68,13 @@ 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; - + $cmd = "dd if=/dev/zero of=" . escapeshellarg($disk) . " bs=32k count=640"; + $out = create_cmdout_container("mbr_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); } 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;"> + <div id="mbr_out" style="font-family: Courier, monospace; font-size: small;"> <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre> </div> @@ -98,316 +85,148 @@ EOD; case "ufs": $button = create_toggle_button("Creating one partition", "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; + $cmd = "/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk); + $out = create_cmdout_container("ufs_fdisk_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $button = create_toggle_button("Initializing partition", "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; + $cmd = "/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16"; + $out = create_cmdout_container("ufs_dd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto"; + $out = create_cmdout_container("ufs_label_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/sbin/newfs -U " . escapeshellarg($disk) . "s1"; + $out = create_cmdout_container("ufs_newfs_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); break; // end case "ufs": case "ufs_no_su": $button = create_toggle_button("Creating one partition", "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); + $cmd = "/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk); + $out = create_cmdout_container("ufsn_fdisk_out", $cmd); + $retvalue .= assemble_cmdout($button, $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 partition", "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; + $cmd = "/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16"; + $out = create_cmdout_container("ufsn_dd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + $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; + $cmd = "/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto"; + $out = create_cmdout_container("ufsn_label_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + $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; - + $cmd = "/sbin/newfs -m 0 " . escapeshellarg($disk) . "s1"; + $out = create_cmdout_container("ufsn_newfs_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + 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; + $cmd = "/sbin/gpt destroy " . escapeshellarg($disk); + $out = create_cmdout_container("ufsg_gptd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = array("/sbin/gpt create -f " . escapeshellarg($disk), + "/sbin/gpt add -t ufs " . escapeshellarg($disk)); + $out = create_cmdout_container("ufsg_gptc_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/sbin/newfs -U " . escapeshellarg($disk) . "p1"; + $out = create_cmdout_container("ufsg_newfs_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); 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; + $cmd = "/sbin/gpt destroy " . escapeshellarg($disk); + $out = create_cmdout_container("ufsgn_gpt_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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> + $cmd = array("/sbin/gpt create -f " . escapeshellarg($disk), + "/sbin/gpt add -t ufs " . escapeshellarg($disk)); + $out = create_cmdout_container("ufsgn_gptc_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); -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; + $cmd = "/sbin/newfs -m 0 " . escapeshellarg($disk) . "p1"; + $out = create_cmdout_container("ufsgn_newfs_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); 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; + $cmd = "/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk); + $out = create_cmdout_container("softr_fdisk_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16"; + $out = create_cmdout_container("softr_dd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + $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; + $cmd = "/sbin/gmirror clear " . escapeshellarg($disk); + $out = create_cmdout_container("softr_dd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); 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; + $cmd = "/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk); + $out = create_cmdout_container("dos_fdisk_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16"; + $out = create_cmdout_container("dos_dd_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $cmd = "/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto"; + $out = create_cmdout_container("dos_label_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); $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; + $a_out = "/sbin/newfs_msdos -F 32 " . escapeshellarg($disk) . "s1"; + $out = create_cmdout_container("dos_newfs_out", $cmd); + $retvalue .= assemble_cmdout($button, $out, true); + 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(); @@ -594,15 +413,7 @@ function disk_change() { } } -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 }); -} +<?= CMDOUT_TOGGLE_FUNC ?> // --> </script> </head> @@ -613,7 +424,7 @@ function toggle_cmdout(image, totoggle) { <?php if ($input_errors) print_input_errors($input_errors); ?> <?php if ($savemsg) print_info_box($savemsg); ?> <?php if($errormsg) print_error_box($errormsg);?> -<div id="inputerrors"></div> +<div id="inputerrors"></div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> @@ -631,40 +442,8 @@ function toggle_cmdout(image, totoggle) { <td> <div id="mainarea"> <form id="iform" name="iform" action="disks_manage_init.php" method="post"> + <?= CMDOUT_AJAX_SCRIPT ?> <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, - onFailure : execFormatFailure - } - ); - } - - function execFormatFailure(req) { - if($('doFormatSubmit')) $('doFormatSubmit').style.visibility = 'visible'; - if($('loading')) $('loading').style.visibility = 'hidden'; - if($('inputerrors')) window.scrollTo(0, 0); - if($('inputerrors')) new Effect.Shake($('inputerrors')); - if($('inputerrors')) $('inputerrors').innerHTML = req.responseText; - } - - 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"> @@ -697,22 +476,21 @@ function toggle_cmdout(image, totoggle) { <tr> <td width="22%" valign="top"> </td> <td width="78%"> - <input id="doFormatSubmit" name="doFormatSubmit" type="button" class="formbtn" value="<?=gettext("Format disk!");?>" onclick="execFormat();" /> + <input id="doCMDSubmit" name="doCMDSubmit" type="button" class="formbtn" value="<?=gettext("Format disk!");?>" onclick="execCMD();" /> </td> </tr> <tr> <!-- 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> + <td id="cmdOutputTD" 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"> - <span class="red"> - <strong>WARNING:</strong> - </span> - <br /> - <span class="vexpl"> - <?= gettext("This step will erase all your partition, create partition number 1 and format the hard drive with the file system specified."); ?> - </span> + <span class="red"> + <strong>WARNING:</strong> + </span> + <br /> + <span class="vexpl"> + <?= gettext("This step will erase all your partition, create partition number 1 and format the hard drive with the file system specified."); ?> </span> </td> </tr> diff --git a/packages/freenas/www/disks_manage_tools.php b/packages/freenas/www/disks_manage_tools.php index 85de9ce8..01438dab 100644 --- a/packages/freenas/www/disks_manage_tools.php +++ b/packages/freenas/www/disks_manage_tools.php @@ -49,6 +49,81 @@ require_once("guiconfig.inc"); require_once("freenas_guiconfig.inc"); require_once("freenas_functions.inc"); +function create_cmd_output(&$action, &$a_disk, &$disk, &$partition, &$umount) { + $cmdout = CMDOUT_PARA; + + ob_end_flush(); + + $retvalue =<<<EOD +{$cmdout} + +EOD; + + switch($action) + { + case "fsck": + /* Get the id of the disk. */ + $id = array_search_ex($disk, $a_disk, "name"); + /* Get the filesystem type of the disk. */ + $type = $a_disk[$id]['fstype']; + /* Check if disk is mounted. */ + $ismounted = disks_check_mount_fullname($disk.$partition); + + /* Umount disk if necessary. */ + if($umount && $ismounted) { + $diskinit_str = "<strong class='red'>" . gettext("Note") . ":</strong> " . gettext("The disk is currently mounted! The mount point will be removed temporary to perform selected command.") . "<br /><br />"; + $retvalue .=<<<EOD + <div id="ismounted_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; + + disks_umount_fullname($disk.$partition); + } + + switch($type) + { + case "": + case "ufs": + case "ufs_no_su": + case "ufsgpt": + case "ufsgpt_no_su": + $button = create_toggle_button("Checking disk", "ufsgn_fsck_out"); + $cmd = "/sbin/fsck_ufs -y -f /dev/" . escapeshellarg($disk . $partition); + $out = create_cmdout_container("ufsgn_fsck_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + break; + case "gmirror": + case "gvinum": + case "graid5": + $diskinit_str = sprintf(gettext("Use <a href='%s'>RAID tools</a> for this disk!"), "disks_raid_{$type}_tools.php"); + $retvalue .=<<<EOD + <div id="graid5_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; + break; + case "msdos": + $button = create_toggle_button("Checking disk", "dos_fsck_out"); + $cmd = "/sbin/fsck_msdosfs -y -f /dev/" . escapeshellarg($disk . $partition); + $out = create_cmdout_container("dos_fsck_out", $cmd); + $retvalue .= assemble_cmdout($button, $out); + break; + } + + /* Mount disk if necessary. */ + if($umount && $ismounted) { + disks_mount_fullname($disk.$partition); + } + + break; + } + + return $retvalue; +} + if (!is_array($freenas_config['disks']['disk'])) $freenas_config['disks']['disk'] = array(); @@ -65,6 +140,12 @@ if ($_POST) { $reqdfieldsn = explode(",", "Disk,Action"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + /* if this is an AJAX caller then handle via JSON */ + if(isAjax() && is_array($error_bucket)) { + input_errors2Ajax(NULL, $error_bucket); + exit; + } + if (!$input_errors) { $do_action = true; @@ -72,6 +153,9 @@ if ($_POST) { $action = $_POST['action']; $partition = $_POST['partition']; $umount = $_POST['umount']; + + echo create_cmd_output($action, $a_disk, $disk, $partition, $umount); + exit; // cause of Ajax } } @@ -116,6 +200,8 @@ function disk_change() { <?php endforeach; ?> } } + +<?= CMDOUT_TOGGLE_FUNC ?> // --> </script> </head> @@ -140,6 +226,7 @@ function disk_change() { <tr> <td> <div id="mainarea"> + <?= CMDOUT_AJAX_SCRIPT ?> <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0"> <tr> <td width="22%" valign="top" class="vncellreq"><?=gettext("Disk");?></td> @@ -181,68 +268,14 @@ function disk_change() { </td> </tr> <tr> - <td width="22%" valign="top" class="vncellreq"> </td> - <td width="78%" class="vtable"> - <input name="Submit" type="submit" class="formbtn" value="<?= gettext("Send Command!"); ?>" /> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input id="doCMDSubmit" name="doCMDSubmit" type="button" class="formbtn" value="<?=gettext("Send Command!");?>" onclick="execCMD();" /> </td> </tr> <tr> - <td width="22%" valign="top" class="vncellreq"> </td> - <td width="78%" class="vtable"> - <?php - if($do_action) - { - echo("<strong>" . gettext("Command output:") . "</strong><br>"); - echo('<pre>'); - ob_end_flush(); - - switch($action) - { - case "fsck": - /* Get the id of the disk. */ - $id = array_search_ex($disk, $a_disk, "name"); - /* Get the filesystem type of the disk. */ - $type = $a_disk[$id]['fstype']; - /* Check if disk is mounted. */ - $ismounted = disks_check_mount($disk,$partition); - - /* Umount disk if necessary. */ - if($umount && $ismounted) { - echo("<strong class='red'>" . gettext("Note") . ":</strong> " . gettext("The disk is currently mounted! The mount point will be removed temporary to perform selected command.") . "<br><br>"); - disks_umount_ex($disk,$partition); - } - - switch($type) - { - case "": - case "ufs": - case "ufs_no_su": - case "ufsgpt": - case "ufsgpt_no_su": - system("/sbin/fsck_ufs -y -f /dev/" . escapeshellarg($disk . $partition)); - break; - case "gmirror": - case "gvinum": - case "graid5": - $infomsg = sprintf(gettext("Use <a href='%s'>RAID tools</a> for this disk!"), "disks_raid_{$type}_tools.php"); - print_info_box_np($infomsg); - break; - case "msdos": - system("/sbin/fsck_msdosfs -y -f /dev/" . escapeshellarg($disk . $partition)); - break; - } - - /* Mount disk if necessary. */ - if($umount && $ismounted) { - disks_mount_ex($disk,$partition); - } - - break; - } - echo('</pre>'); - } - ?> - </td> + <!-- Format Output Container - Do Not Delete --> + <td id="cmdOutputTD" valign="top" colspan="2" style="visibility: hidden; border: solid 1px silver; vertical-align: middle; width: 100%"></td> </tr> </table> </div> diff --git a/packages/freenas/www/disks_mount_tools.php b/packages/freenas/www/disks_mount_tools.php index 67006981..26e7471d 100644 --- a/packages/freenas/www/disks_mount_tools.php +++ b/packages/freenas/www/disks_mount_tools.php @@ -50,6 +50,46 @@ require_once("guiconfig.inc"); require_once("freenas_guiconfig.inc"); require_once("freenas_functions.inc"); +function create_cmd_output(&$action, &$a_mount, &$fullname) { + $cmdout = CMDOUT_PARA; + + ob_end_flush(); + + $retvalue =<<<EOD +{$cmdout} + +EOD; + + /* Get the id of the mount array entry. */ + $id = array_search_ex($fullname, $a_mount, "fullname"); + /* Get the mount data. */ + $mount = $a_mount[$id]; + + switch($action) + { + case "mount": + $diskinit_str = gettext("Mounting '{$fullname}'...") . "<br />"; + $result = disks_mount_fullname($fullname); + break; + case "umount": + $diskinit_str = gettext("Umounting '{$fullname}'...") . "<br />"; + $result = disks_umount_fullname($fullname); + break; + } + + /* Display result */ + (0 == $result) ? $diskinit_str .= gettext("Successful") : $diskinit_str .= gettext("Failed"); + + $retvalue .=<<<EOD + <div id="ismounted_out" style="font-family: Courier, monospace; font-size: small;"> + <pre style="font-family: Courier, monospace; font-size: small; font-style: italic;">{$diskinit_str}</pre> + </div> + +EOD; + + return $retvalue; +} + if (!is_array($freenas_config['mounts']['mount'])) $freenas_config['mounts']['mount'] = array(); @@ -85,6 +125,9 @@ if (! empty($_POST)) $do_action = true; $fullname = $_POST['fullname']; $action = $_POST['action']; + + echo create_cmd_output($action, $a_mount, $fullname); + exit; // cause of Ajax } } @@ -107,13 +150,23 @@ if(isset($_GET['action'])) { $action = $_GET['action']; } +/* if ajax is calling, give them an update message */ +if(isAjax()) + print_info_box_np($savemsg); + include("head.inc"); /* put your custom HTML head content here */ /* using some of the $pfSenseHead function calls */ +$pfSenseHead->setCloseHead(false); echo $pfSenseHead->getHTML(); ?> - +<script type="text/javascript"> +<!-- +<?= CMDOUT_TOGGLE_FUNC ?> +// --> +</script> +</head> <body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>"> <?php include("fbegin.inc"); ?> @@ -134,6 +187,7 @@ echo $pfSenseHead->getHTML(); <tr> <td> <div id="mainarea"> + <?= CMDOUT_AJAX_SCRIPT ?> <?php if ($input_errors) print_input_errors($input_errors); ?> <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0"> <tr> @@ -160,41 +214,12 @@ echo $pfSenseHead->getHTML(); <tr> <td width="22%" valign="top"> </td> <td width="78%"> - <input name="Submit" type="submit" class="formbtn" value="<?= gettext("Send Command!"); ?>" /> + <input id="doCMDSubmit" name="doCMDSubmit" type="button" class="formbtn" value="<?=gettext("Send Command!");?>" onclick="execCMD();" /> </td> </tr> <tr> - <td valign="top" colspan="2"> - <?php if($do_action) - { - echo("<strong>" . gettext("Command output") . ": </strong><br />"); - echo('<pre>'); - ob_end_flush(); - - /* Get the id of the mount array entry. */ - $id = array_search_ex($fullname, $a_mount, "fullname"); - /* Get the mount data. */ - $mount = $a_mount[$id]; - - switch($action) - { - case "mount": - echo(gettext("Mounting '{$fullname}'...") . "<br />"); - $result = disks_mount_fullname($fullname); - break; - case "umount": - echo(gettext("Umounting '{$fullname}'...") . "<br />"); - $result = disks_umount_fullname($fullname); - break; - } - - /* Display result */ - echo((0 == $result) ? gettext("Successful") : gettext("Failed")); - - echo('</pre>'); - } - ?> - </td> + <!-- Format Output Container - Do Not Delete --> + <td id="cmdOutputTD" valign="top" colspan="2" style="visibility: hidden; border: solid 1px silver; vertical-align: middle; width: 100%"></td> </tr> </table> </div> |