Advertisement
killermist

NAS4Free alternate index.php

Jun 5th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.16 KB | None | 0 0
  1. #!/usr/local/bin/php
  2. <?php
  3. /*
  4.     index.php
  5.  
  6.     Part of NAS4Free (http://www.nas4free.org).
  7.     Copyright (C) 2012 by NAS4Free Team <info@nas4free.org>.
  8.     All rights reserved.
  9.    
  10.     Modified for XHTML by Daisuke Aoyama <aoyama@peach.ne.jp>
  11.     Copyright (C) 2010-2011 Daisuke Aoyama <aoyama@peach.ne.jp>.   
  12.     All rights reserved.
  13.  
  14.     Modified by Michael Zoon (zoon01@nas4free.org)
  15.     Copyright (C) 2010-2011 Michael Zoon <zoon01@nas4free.org>.
  16.     All rights reserved.
  17.  
  18.     Portions of freenas (http://www.freenas.org).
  19.     Copyright (C) 2005-2011 by Olivier Cochard <olivier@freenas.org>.
  20.     Improved by Stefan Hendricks (info@henmedia.de)
  21.     All rights reserved.
  22.    
  23.     Portions of m0n0wall (http://m0n0.ch/wall).
  24.     Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
  25.     All rights reserved.   
  26.  
  27.     Redistribution and use in source and binary forms, with or without
  28.     modification, are permitted provided that the following conditions are met:
  29.  
  30.     1. Redistributions of source code must retain the above copyright notice, this
  31.        list of conditions and the following disclaimer.
  32.     2. Redistributions in binary form must reproduce the above copyright notice,
  33.        this list of conditions and the following disclaimer in the documentation
  34.        and/or other materials provided with the distribution.
  35.  
  36.     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  37.     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  38.     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39.     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  40.     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  41.     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44.     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45.     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.  
  47.     The views and conclusions contained in the software and documentation are those
  48.     of the authors and should not be interpreted as representing official policies,
  49.     either expressed or implied, of the NAS4Free Project.
  50. */
  51. // Configure page permission
  52. $pgperm['allowuser'] = TRUE;
  53.  
  54. require("auth.inc");
  55. require("guiconfig.inc");
  56. require("zfs.inc");
  57. require("sajax/sajax.php");
  58.  
  59. $pgtitle = array(gettext("System information"));
  60. $pgtitle_omit = true;
  61.  
  62. $smbios = get_smbios_info();
  63. $cpuinfo = system_get_cpu_info();
  64.  
  65. function update_controls() {
  66.     $sysinfo = system_get_sysinfo();
  67.     return json_encode($sysinfo);
  68. }
  69.  
  70. function zfs_zpool_get_iostat() {
  71.         // Get zpool I/O statistic informations
  72.         $cmd = "zpool iostat -v 2>&1";
  73.         if (isset($_GET['pool'])) {
  74.                 $cmd .= " {$_GET['pool']}";
  75.         }
  76.         mwexec2($cmd, $rawdata);
  77.         return implode("\n", $rawdata);
  78. }
  79.  
  80. sajax_init();
  81. sajax_export("update_controls");
  82. sajax_handle_client_request();
  83.  
  84. if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
  85.      @date_default_timezone_set(@date_default_timezone_get());
  86. ?>
  87. <?php include("fbegin.inc");?>
  88. <script type="text/javascript">//<![CDATA[
  89. <?php sajax_show_javascript();?>
  90. //]]>
  91. </script>
  92. <script type="text/javascript" src="javascript/index.js"></script>
  93. <table border="0" cellspacing="0" cellpadding="0">
  94. <td>&nbsp;</td>
  95. </table>
  96. <table border="0" cellpadding="0" cellspacing="0">
  97.   <tr>
  98.     <td class="tabcont">
  99.         <table width= border="0" cellspacing="0" cellpadding="0">
  100.               <tr>
  101.                 <td colspan="2" class="listtopic"><?=gettext("System information");?></td>
  102.               </tr>
  103.               <tr>
  104.                 <td width="25%" class="vncellt"><?=gettext("Hostname");?></td>
  105.                 <td width="75%" class="listr"><?=system_get_hostname();?></td>
  106.               </tr>
  107.               <tr>
  108.                 <td width="25%" valign="top" class="vncellt"><?=gettext("Version");?></td>
  109.                 <td width="75%" class="listr"><strong><?=get_product_version();?> <?=get_product_versionname();?></strong> (<?=gettext("revision");?> <?=get_product_revision();?>)</td>
  110.               </tr>
  111.               <tr>
  112.                 <td width="25%" valign="top" class="vncellt"><?=gettext("Built date");?></td>
  113.                 <td width="75%" class="listr"><?=get_product_buildtime();?>
  114.                 </td>
  115.               </tr>
  116.               <tr>
  117.                 <td width="25%" valign="top" class="vncellt"><?=gettext("Platform OS");?></td>
  118.                 <td width="75%" class="listr">
  119.                   <?
  120.                     exec("/sbin/sysctl -n kern.ostype", $ostype);
  121.                     exec("/sbin/sysctl -n kern.osrelease", $osrelease);
  122.                     exec("/sbin/sysctl -n kern.osrevision", $osrevision);
  123.                     echo("$ostype[0] $osrelease[0] (revision $osrevision[0])");
  124.                   ?>
  125.                 </td>
  126.               </tr>
  127.               <tr>
  128.                 <td width="25%" class="vncellt"><?=gettext("Platform");?></td>
  129.                 <td width="75%" class="listr">
  130.                     <?=sprintf(gettext("%s on %s"), $g['fullplatform'], $cpuinfo['model']);?>
  131.                 </td>
  132.               </tr>
  133.               <tr>
  134.                 <td width="25%" class="vncellt"><?=gettext("System");?></td>
  135.                 <td width="75%" class="listr"><?=htmlspecialchars($smbios['planar']['maker']);?> <?=htmlspecialchars($smbios['planar']['product']);?> <?=sprintf(gettext("Bios:"));?> <?=htmlspecialchars($smbios['bios']['version']);?> <?=htmlspecialchars($smbios['bios']['reldate']);?></td>
  136.                 </td>
  137.               </tr>
  138.               <tr>
  139.                 <td width="25%" class="vncellt"><?=gettext("System time");?></td>
  140.                 <td width="75%" class="listr">
  141.                   <input style="padding: 0; border: 0;" size="30" name="date" id="date" value="<?=htmlspecialchars(shell_exec("date"));?>" />
  142.                 </td>
  143.               </tr>
  144.               <tr>
  145.                 <td width="25%" class="vncellt"><?=gettext("System uptime");?></td>
  146.                 <td width="75%" class="listr">
  147.                         <?php $uptime = system_get_uptime();?>
  148.                         <span name="uptime" id="uptime"><?=htmlspecialchars($uptime);?></span>
  149.                 </td>
  150.               </tr>
  151.               <?php if (Session::isAdmin()):?>
  152.               <?php if ($config['lastchange']):?>
  153.             <tr>
  154.               <td width="25%" class="vncellt"><?=gettext("Last config change");?></td>
  155.               <td width="75%" class="listr">
  156.                         <input style="padding: 0; border: 0;" size="30" name="lastchange" id="lastchange" value="<?=htmlspecialchars(date("D M j G:i:s T Y", $config['lastchange']));?>" />
  157.               </td>
  158.             </tr>
  159.                 <?php endif;?>
  160.                 <?php if (!empty($cpuinfo['temperature2'])):
  161.                     echo "<tr>";
  162.                     echo "<td width='25%' class='vncellt'>".gettext("CPU temperature")."</td>";
  163.                     echo "<td width='75%' class='listr'>";
  164.                     echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td>\n";
  165.                     $cpus = system_get_cpus();
  166.                     for ($idx = 0; $idx < $cpus; $idx++) {
  167.                         echo "<tr><td>";
  168.                         echo "<input style='padding: 0; border: 0;' size='2' name='cputemp${idx}' id='cputemp${idx}' value='".htmlspecialchars($cpuinfo['temperature2'][$idx])."' />";
  169.                     echo $idx['temperature2']."&#176;C";   
  170.                     echo "</td></tr>";
  171.                     }
  172.                     echo "</table></td>";
  173.                     echo "</tr>\n";
  174.                 ?>
  175.                 <?php elseif (!empty($cpuinfo['temperature'])):?>
  176.                 <tr>
  177.                     <td width="25%" class="vncellt"><?=gettext("CPU temperature");?></td>
  178.                     <td width="75%" class="listr">
  179.                         <input style="padding: 0; border: 0;" size="30" name="cputemp" id="cputemp" value="<?=htmlspecialchars($cpuinfo['temperature']);?>" />
  180.                     </td>
  181.                 </tr>
  182.                 <?php endif;?>
  183.                 <?php if (!empty($cpuinfo['freq'])):?>
  184.                 <tr>
  185.                     <td width="25%" class="vncellt"><?=gettext("CPU frequency");?></td>
  186.                     <td width="75%" class="listr">
  187.                         <input style="padding: 0; border: 0;" size="30" name="cpufreq" id="cpufreq" value="<?=htmlspecialchars($cpuinfo['freq']);?>MHz" title="<?=sprintf(gettext("Levels (MHz/mW): %s"), $cpuinfo['freqlevels']);?>" />
  188.                     </td>
  189.                 </tr>
  190.                 <?php endif;?>
  191.                 <tr>
  192.                     <td width="25%" class="vncellt"><?=gettext("CPU usage");?></td>
  193.                     <td width="75%" class="listr">
  194.                         <table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>
  195.                         <?php
  196.                         $percentage = 0;
  197.                         echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  198.                         echo "<img src='bar_blue.gif' name='cpuusageu' id='cpuusageu' width='" . $percentage . "' class='progbarcf' alt='' />";
  199.                         echo "<img src='bar_gray.gif' name='cpuusagef' id='cpuusagef' width='" . (100 - $percentage) . "' class='progbarc' alt='' />";
  200.                         echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  201.                         ?>
  202.                         <input style="padding: 0; border: 0;" size="30" name="cpuusage" id="cpuusage" value="<?=gettext("Updating in 5 seconds.");?>" />
  203.                     </td></tr>
  204.                         <?php
  205.                         $cpus = system_get_cpus();
  206.                         if ($cpus > 1) {
  207.                             echo "<tr><td><hr size='1' /></td></tr>";
  208.                             for ($idx = 0; $idx < $cpus; $idx++) {
  209.                                 $percentage = 0;
  210.                                 echo "<tr><td>";
  211.                                 echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  212.                                 echo "<img src='bar_blue.gif' name='cpuusageu${idx}' id='cpuusageu${idx}' width='" . $percentage . "' class='progbarcf' alt='' />";
  213.                                 echo "<img src='bar_gray.gif' name='cpuusagef${idx}' id='cpuusagef${idx}' width='" . (100 - $percentage) . "' class='progbarc' alt='' />";
  214.                                 echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  215.                                 echo "<input style='padding: 0; border: 0;' size='30' name='cpuusage${idx}' id='cpuusage${idx}' value=\"".gettext("Updating in 5 seconds.")."\" />";
  216.                                 echo "</td></tr>";
  217.                             }
  218.                         }
  219.                         ?>
  220.                     </table>
  221.                     </td>
  222.                 </tr>
  223.               <tr>
  224.                 <td width="25%" class="vncellt"><?=gettext("Memory usage");?></td>
  225.                 <td width="75%" class="listr">
  226.                         <?php
  227.                         $raminfo = system_get_ram_info();
  228.                         $percentage = round(($raminfo['used'] * 100) / $raminfo['total'], 0);
  229.                         echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  230.                         echo "<img src='bar_blue.gif' name='memusageu' id='memusageu' width='" . $percentage . "' class='progbarcf' alt='' />";
  231.                         echo "<img src='bar_gray.gif' name='memusagef' id='memusagef' width='" . (100 - $percentage) . "' class='progbarc' alt='' />";
  232.                         echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  233.                         ?>
  234.                         <input style="padding: 0; border: 0;" size="30" name="memusage" id="memusage" value="<?=sprintf(gettext("%d%% of %dMiB"), $percentage, round($raminfo['physical'] / 1024 / 1024));?>" />
  235.                 </td>
  236.               </tr>
  237.                 <?php $swapinfo = system_get_swap_info(); if (!empty($swapinfo)):?>
  238.                 <tr>
  239.                     <td width="25%" class="vncellt"><?=gettext("Swap usage");?></td>
  240.                     <td width="75%" class="listr">
  241.                         <table width="100%" border="0" cellspacing="0" cellpadding="1">
  242.                             <?php
  243.                             array_sort_key($swapinfo, "device");
  244.                             $ctrlid = 0;
  245.                             foreach ($swapinfo as $swapk => $swapv) {
  246.                                 $ctrlid++;
  247.                                 $percent_used = rtrim($swapv['capacity'], "%");
  248.                                 $tooltip_used = sprintf(gettext("%sB used of %sB"), $swapv['used'], $swapv['total']);
  249.                                 $tooltip_available = sprintf(gettext("%sB available of %sB"), $swapv['avail'], $swapv['total']);
  250.  
  251.                                 echo "<tr><td><div id='swapusage'>";
  252.                                 echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  253.                                 echo "<img src='bar_blue.gif' name='swapusage_{$ctrlid}_bar_used' id='swapusage_{$ctrlid}_bar_used' width='{$percent_used}' class='progbarcf' title='{$tooltip_used}' alt='' />";
  254.                                 echo "<img src='bar_gray.gif' name='swapusage_{$ctrlid}_bar_free' id='swapusage_{$ctrlid}_bar_free' width='" . (100 - $percent_used) . "' class='progbarc' title='{$tooltip_available}' alt='' />";
  255.                                 echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  256.                                 echo sprintf(gettext("%s of %sB"),
  257.                                     "<span name='swapusage_{$ctrlid}_capacity' id='swapusage_{$ctrlid}_capacity' class='capacity'>{$swapv['capacity']}</span>",
  258.                                     $swapv['total']);
  259.                                 echo "<br />";
  260.                                 echo sprintf(gettext("Device: %s | Total: %s | Used: %s | Free: %s"),
  261.                                     "<span name='swapusage_{$ctrlid}_device' id='swapusage_{$ctrlid}_device' class='device'>{$swapv['device']}</span>",
  262.                                     "<span name='swapusage_{$ctrlid}_total' id='swapusage_{$ctrlid}_total' class='total'>{$swapv['total']}</span>",
  263.                                     "<span name='swapusage_{$ctrlid}_used' id='swapusage_{$ctrlid}_used' class='used'>{$swapv['used']}</span>",
  264.                                     "<span name='swapusage_{$ctrlid}_free' id='swapusage_{$ctrlid}_free' class='free'>{$swapv['avail']}</span>");
  265.                                 echo "</div></td></tr>";
  266.  
  267.                                 if ($ctrlid < count($swapinfo))
  268.                                         echo "<tr><td><hr size='1' /></td></tr>";
  269.                             }?>
  270.                         </table>
  271.                     </td>
  272.                 </tr>
  273.                 <?php endif;?>
  274.                 <tr>
  275.                 <td width="25%" class="vncellt"><?=gettext("Load averages");?></td>
  276.                     <td width="75%" class="listr">
  277.                         <?php
  278.                         exec("uptime", $result);
  279.                         $loadaverage = substr(strrchr($result[0], "load averages:"), 15);
  280.                         ?>
  281.                         <input style="padding: 0; border: 0;" size="14" name="loadaverage" id="loadaverage" value="<?=$loadaverage;?>" />
  282.                         <?="<small>[<a href='status_process.php'>".gettext("Show process information")."</a></small>]";?>
  283.                 </td>
  284.               </tr>
  285.                 <tr>
  286.                 <td width="25%" class="vncellt"><?=gettext("Disk space usage");?></td>
  287.                 <td width="75%" class="listr">
  288.                     <table width="100%" border="0" cellspacing="0" cellpadding="1">
  289.                       <?php
  290.                       $diskusage = system_get_mount_usage();
  291.                       if (!empty($diskusage)) {
  292.                         array_sort_key($diskusage, "name");
  293.                         $index = 0;
  294.                                 foreach ($diskusage as $diskusagek => $diskusagev) {
  295.                                     $ctrlid = get_mount_fsid($diskusagev['filesystem'], $diskusagek);
  296.                                     $percent_used = rtrim($diskusagev['capacity'],"%");
  297.                                     $tooltip_used = sprintf(gettext("%sB used of %sB"), $diskusagev['used'], $diskusagev['size']);
  298.                                     $tooltip_available = sprintf(gettext("%sB available of %sB"), $diskusagev['avail'], $diskusagev['size']);
  299.  
  300.                                     echo "<tr><td><div id='diskusage'>";
  301.                                     echo "<span name='diskusage_{$ctrlid}_name' id='diskusage_{$ctrlid}_name' class='name'>{$diskusagev['name']}</span><br />";
  302.                                     echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  303.                                     echo "<img src='bar_blue.gif' name='diskusage_{$ctrlid}_bar_used' id='diskusage_{$ctrlid}_bar_used' width='{$percent_used}' class='progbarcf' title='{$tooltip_used}' alt='' />";
  304.                                     echo "<img src='bar_gray.gif' name='diskusage_{$ctrlid}_bar_free' id='diskusage_{$ctrlid}_bar_free' width='" . (100 - $percent_used) . "' class='progbarc' title='{$tooltip_available}' alt='' />";
  305.                                     echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  306.                                     echo sprintf(gettext("%s of %sB"),
  307.                                         "<span name='diskusage_{$ctrlid}_capacity' id='diskusage_{$ctrlid}_capacity' class='capacity'>{$diskusagev['capacity']}</span>",
  308.                                         $diskusagev['size']);
  309.                                     echo "<br />";
  310.                                     echo sprintf(gettext("Total: %s | Used: %s | Free: %s"),
  311.                                         "<span name='diskusage_{$ctrlid}_total' id='diskusage_{$ctrlid}_total' class='total'>{$diskusagev['size']}</span>",
  312.                                         "<span name='diskusage_{$ctrlid}_used' id='diskusage_{$ctrlid}_used' class='used'>{$diskusagev['used']}</span>",
  313.                                         "<span name='diskusage_{$ctrlid}_free' id='diskusage_{$ctrlid}_free' class='free'>{$diskusagev['avail']}</span>");
  314.                                     echo "</div></td></tr>";
  315.  
  316.                                     if (++$index < count($diskusage))
  317.                                         echo "<tr><td><hr size='1' /></td></tr>";
  318.                                 }
  319.                             }
  320.  
  321.                             $zfspools = zfs_get_pool_list();
  322.                             if (!empty($zfspools)) {
  323.                                 array_sort_key($zfspools, "name");
  324.                                 $index = 0;
  325.  
  326.                                 if (!empty($diskusage))
  327.                                         echo "<tr><td><hr size='1' /></td></tr>";
  328.  
  329.                                 foreach ($zfspools as $poolk => $poolv) {
  330.                                     $ctrlid = $poolv['name'];
  331.                                     $percent_used = rtrim($poolv['cap'],"%");
  332.                                     $tooltip_used = sprintf(gettext("%sB used of %sB"), $poolv['used'], $poolv['size']);
  333.                                     $tooltip_available = sprintf(gettext("%sB available of %sB"), $poolv['avail'], $poolv['size']);
  334.  
  335.                                     echo "<tr><td><div id='diskusage'>";
  336.                                     echo "<span name='diskusage_{$ctrlid}_name' id='diskusage_{$ctrlid}_name' class='name'>{$poolv['name']}</span><br />";
  337.                                     echo "<img src='bar_left.gif' class='progbarl' alt='' />";
  338.                                     echo "<img src='bar_blue.gif' name='diskusage_{$ctrlid}_bar_used' id='diskusage_{$ctrlid}_bar_used' width='{$percent_used}' class='progbarcf' title='{$tooltip_used}' alt='' />";
  339.                                     echo "<img src='bar_gray.gif' name='diskusage_{$ctrlid}_bar_free' id='diskusage_{$ctrlid}_bar_free' width='" . (100 - $percent_used) . "' class='progbarc' title='{$tooltip_available}' alt='' />";
  340.                                     echo "<img src='bar_right.gif' class='progbarr' alt='' /> ";
  341.                                     echo sprintf(gettext("%s of %sB"),
  342.                                         "<span name='diskusage_{$ctrlid}_capacity' id='diskusage_{$ctrlid}_capacity' class='capacity'>{$poolv['cap']}</span>",
  343.                                         $poolv['size']);
  344.                                     echo "<br />";
  345.                                     echo sprintf(gettext("Total: %s | Used: %s | Free: %s | State: %s"),
  346.                                         "<span name='diskusage_{$ctrlid}_total' id='diskusage_{$ctrlid}_total' class='total'>{$poolv['size']}</span>",
  347.                                         "<span name='diskusage_{$ctrlid}_used' id='diskusage_{$ctrlid}_used' class='used'>{$poolv['used']}</span>",
  348.                                         "<span name='diskusage_{$ctrlid}_free' id='diskusage_{$ctrlid}_free' class='free'>{$poolv['avail']}</span>",
  349.                                         "<span name='diskusage_{$ctrlid}_state' id='diskusage_{$ctrlid}_state' class='state'><a href='disks_zfs_zpool_info.php?pool={$poolv['name']}'>{$poolv['health']}</a></span>");
  350.  
  351.                                     echo "</div></td></tr>";
  352.  
  353.                                     if (++$index < count($zfspools))
  354.                                         echo "<tr><td><hr size='1' /></td></tr>";
  355.                                 }
  356.                             }
  357.  
  358.                             if (empty($diskusage) && empty($zfspools)) {
  359.                                 echo "<tr><td>";
  360.                                 echo gettext("No disk configured");
  361.                                 echo "</td></tr>";
  362.                             }
  363.                             ?>
  364.  
  365.                         </table>
  366.                     </td>
  367.                 </tr>
  368.                 <?php endif;?>
  369.                                                         <?php /* ZFS pool IO stats */ ?>
  370.                                                                 <tr><td colspan=2 class="listr"><pre><span id="zfs_zpool_iostat"><?=zfs_zpool_get_iostat();?></span></pre></td></tr>
  371.                                                         <?php /* End of ZFS pool IO stats */ ?>
  372.             </table>
  373.         </td>
  374.     </tr>
  375. </table>
  376. <?php include("fend.inc");?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement