[Phpsysinfo-subversion] SF.net SVN: phpsysinfo:[165] plugins/quotas
Brought to you by:
namiltd
From: <big...@us...> - 2009-03-26 13:59:25
|
Revision: 165 http://phpsysinfo.svn.sourceforge.net/phpsysinfo/?rev=165&view=rev Author: bigmichi1 Date: 2009-03-26 13:59:00 +0000 (Thu, 26 Mar 2009) Log Message: ----------- jslint jsFile php documentation update use new translation style for plugin Modified Paths: -------------- plugins/quotas/js/quotas.js Added Paths: ----------- plugins/quotas/Quotas.config.php plugins/quotas/class.Quotas.inc.php Copied: plugins/quotas/Quotas.config.php (from rev 160, plugins/quotas/quotas.config.php) =================================================================== --- plugins/quotas/Quotas.config.php (rev 0) +++ plugins/quotas/Quotas.config.php 2009-03-26 13:59:00 UTC (rev 165) @@ -0,0 +1,21 @@ +<?php +/** + * PSSTATUS Plugin Config File + * + * PHP version 5 + * + * @category PHP + * @package PSI_Plugin_Quotas + * @author Michael Cramer <Big...@us...> + * @copyright 2009 phpSysInfo + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @version SVN: $Id$ + * @link http://phpsysinfo.sourceforge.net + */ + /** + * define how to access the repquota statistic data + * - 'command' repquota command is run everytime the block gets refreshed or build + * - 'data' (a file must be available in the data directory of the phpsysinfo installation with the filename "quotas.txt"; content is the output from "repquota -au") + */ +define('PSI_PLUGIN_QUOTAS_ACCESS', 'data'); +?> Property changes on: plugins/quotas/Quotas.config.php ___________________________________________________________________ Added: svn:mime-type + text/x-php Added: svn:keywords + Id Added: svn:mergeinfo + Added: svn:eol-style + LF Copied: plugins/quotas/class.Quotas.inc.php (from rev 160, plugins/quotas/class.quotas.inc.php) =================================================================== --- plugins/quotas/class.Quotas.inc.php (rev 0) +++ plugins/quotas/class.Quotas.inc.php 2009-03-26 13:59:00 UTC (rev 165) @@ -0,0 +1,144 @@ +<?php +/** + * QUOTAS Plugin + * + * PHP version 5 + * + * @category PHP + * @package PSI_Plugin_Quotas + * @author Michael Cramer <Big...@us...> + * @copyright 2009 phpSysInfo + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @version SVN: $Id$ + * @link http://phpsysinfo.sourceforge.net + */ + /** + * quota Plugin, which displays all quotas on the machine + * display all quotas in a sortable table with the current values which are determined by + * calling the "repquota" command line utility, another way is to provide + * a file with the output of the repquota utility, so there is no need to run a execute by the + * webserver, the format of the command is written down in the quota.config.php file, where also + * the method of getting the information is configured + * + * @category PHP + * @package PSI_Plugin_Quotas + * @author Michael Cramer <Big...@us...> + * @copyright 2009 phpSysInfo + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @version Release: 3.0 + * @link http://phpsysinfo.sourceforge.net + */ +class Quotas extends PSI_Plugin +{ + /** + * variable, which holds the content of the command + * @var array + */ + private $_filecontent = array (); + + /** + * variable, which holds the result before the xml is generated out of this array + * @var array + */ + private $_result = array (); + + /** + * controls if debugging is turned on or off, value is defined in the main config.php + * @var boolean + */ + private $_debug = PSI_DEBUG; + + /** + * read the data into an internal array and also call the parent constructor + */ + public function __construct() + { + $buffer = ""; + parent::__construct(( __CLASS__ )); + switch(PSI_PLUGIN_QUOTAS_ACCESS) { + case 'command': + execute_program("repquota", "-au", $buffer, $this->_debug); + break; + case 'data': + rfts(APP_ROOT."/data/quotas.txt", $buffer); + break; + default: + $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_QUOTAS_ACCESS"); + break; + } + if (trim($buffer) != "") { + $this->_filecontent = explode("\n", $buffer); + unset ($this->_filecontent[0]); + } else { + $this->_filecontent = array (); + } + } + + /** + * doing all tasks to get the required informations that the plugin needs + * result is stored in an internal array<br>the array is build like a tree, + * so that it is possible to get only a specific process with the childs + * + * @return void + */ + public function execute() + { + $i = 0; + if ( empty($this->_filecontent)) { + return; + } + foreach ($this->_filecontent as $thisline) { + $thisline = preg_replace("/([\s]--)/", "", $thisline); + $thisline = preg_split("/(\s)/e", $thisline, -1, PREG_SPLIT_NO_EMPTY); + if (count($thisline) == 7) { + $quotas[$i]['user'] = str_replace("--", "", $thisline[0]); + $quotas[$i]['byte_used'] = $thisline[1]*1024; + $quotas[$i]['byte_soft'] = $thisline[2]*1024; + $quotas[$i]['byte_hard'] = $thisline[3]*1024; + if ($thisline[3] != 0) { + $quotas[$i]['byte_percent_used'] = round((($quotas[$i]['byte_used']/$quotas[$i]['byte_hard'])*100), 1); + } else { + $quotas[$i]['byte_percent_used'] = 0; + } + $quotas[$i]['file_used'] = $thisline[4]; + $quotas[$i]['file_soft'] = $thisline[5]; + $quotas[$i]['file_hard'] = $thisline[6]; + if ($thisline[6] != 0) { + $quotas[$i]['file_percent_used'] = round((($quotas[$i]['file_used']/$quotas[$i]['file_hard'])*100), 1); + } else { + $quotas[$i]['file_percent_used'] = 0; + } + $i++; + } + } + $this->_result = $quotas; + } + + /** + * generates the XML content for the plugin + * + * @return SimpleXMLObject entire XML content for the plugin + */ + public function xml() + { + $rootelement = "Plugin_". __CLASS__ ; + $xml = simplexml_load_string("<?xml version='1.0'?>\n<".$rootelement."/>"); + if ( empty($this->_result)) { + return $xml; + } + foreach ($this->_result as $quota) { + $quotaChild = $xml->addChild("Quota"); + $quotaChild->addChild("User", $quota['user']); + $quotaChild->addChild("ByteUsed", $quota['byte_used']); + $quotaChild->addChild("ByteSoft", $quota['byte_soft']); + $quotaChild->addChild("ByteHard", $quota['byte_hard']); + $quotaChild->addChild("BytePercentUsed", $quota['byte_percent_used']); + $quotaChild->addChild("FileUsed", $quota['file_used']); + $quotaChild->addChild("FileSoft", $quota['file_soft']); + $quotaChild->addChild("FileHard", $quota['file_hard']); + $quotaChild->addChild("FilePercentUsed", $quota['file_percent_used']); + } + return $xml; + } +} +?> Property changes on: plugins/quotas/class.Quotas.inc.php ___________________________________________________________________ Added: svn:mime-type + text/x-php Added: svn:keywords + Id Added: svn:mergeinfo + Added: svn:eol-style + LF Modified: plugins/quotas/js/quotas.js =================================================================== --- plugins/quotas/js/quotas.js 2009-03-26 13:57:34 UTC (rev 164) +++ plugins/quotas/js/quotas.js 2009-03-26 13:59:00 UTC (rev 165) @@ -21,120 +21,129 @@ // $Id$ // -$(document).ready(function(){ - var show = false; +/*global $, jQuery, buildBlock, datetime, plugin_translate, genlang, formatBytes, createBar */ - $("#footer").before(buildBlock("quotas", "Quota Status", "001", true)); - $("#plugin_quotas").css("width","915px"); - - request(); +var quotas_show = false, quotas_table; - $("#reload_quotasTable").click(function(id) { - request(); - $("#DateTime_quotas").html("(<span id=\"lang_plugin_quotas_002\">Last Refresh</span>: " + datetime() + ")"); - }); +/** + * insert content into table + * @param {jQuery} xml plugin-XML + */ +function quotas_populate(xml) { + var plugins, quotas, quota, user = "", bused = 0, bsoft = 0, bhard = 0, bpuse = 0, fpuse = 0, fused = 0, fsoft = 0, fhard = 0; - function request(){ - $.ajax({ - url: "xml.php?plugin=quotas", - dataType: "xml", - error: function() { - $.jGrowl("Error loading XML document for Plugin quotas!"); - }, - success: function(xml) { - populateQuotas(xml); - if(show) { - plugin_translate("quotas"); - $("#plugin_quotas").show(); - } - } - }); - } + quotas_table.fnClearTable(); - function populateQuotas(xml) { - var plugins, quotas; - var html = ""; - - $("#plugin_quotas div").remove(); - html += "<table id=\"plugin_quotasTable\" cellspacing=\"0\">\n"; - html += " <thead>\n"; - html += " <tr>\n"; - html += " <th><span id=\"lang_plugin_quotas_003\">User</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_004\">Bytes Used</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_005\">Bytes Soft</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_006\">Bytes Hard</span></th>\n"; - html += " <th><span id=\"lang_plugin_quotas_007\">Bytes Used Percent</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_008\">Files Used</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_009\">Files Soft</span></th>\n"; - html += " <th class=\"right\"><span id=\"lang_plugin_quotas_010\">Files Hard</span></th>\n"; - html += " <th><span id=\"lang_plugin_quotas_011\">Files Used Percent</span></th>\n"; - html += " </tr>\n"; - html += " </thead>\n"; - html += " <tbody>\n"; - html += " </tbody>\n"; - html += "</table>\n"; - $("#plugin_quotas").append(html); - - $("Plugins",xml).each(function(id){ - plugins = $("Plugins", xml).get(id); - $("plugin_quotas", plugins).each(function(id){ - quotas = $("plugin_quotas", plugins).get(id); - $("#plugin_quotasTable tbody").append(buildTable(quotas)); - $("#plugin_quotasTable").dataTable( { - "bPaginate": false, - "bLengthChange": false, - "bFilter": false, - "bSort": true, - "bInfo": false, - "bProcessing": true, - "bAutoWidth": false, - "bStateSave": true, - "aoColumns": [ - { "sType": 'span-string' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' }, - { "sType": 'span-number' } - ] - } ); - show = true; + $("Plugins", xml).each(function quotas_getplugins(id) { + plugins = $("Plugins", xml).get(id); + $("Plugin_Quotas", plugins).each(function quotas_getplugin(idp) { + quotas = $("Plugin_Quotas", plugins).get(idp); + $("Quota", quotas).each(function quotas_getquota(idq) { + quota = $("Quota", quotas).get(idq); + user = $("User", quota).text().toString(); + bused = parseInt($("ByteUsed", quota).text().toString(), 10); + bsoft = parseInt($("ByteSoft", quota).text(), 10); + bhard = parseInt($("ByteHard", quota).text(), 10); + bpuse = parseInt($("BytePercentUsed", quota).text(), 10); + fused = parseInt($("FileUsed", quota).text(), 10); + fsoft = parseInt($("FileSoft", quota).text(), 10); + fhard = parseInt($("FileHard", quota).text(), 10); + fpuse = parseInt($("FilePercentUsed", quota).text(), 10); + + quotas_table.fnAddData(["<span style=\"display:none;\">" + user + "</span>" + user, "<span style=\"display:none;\">" + bused + "</span>" + formatBytes(bused, xml), "<span style=\"display:none;\">" + bsoft + "</span>" + formatBytes(bsoft, xml), "<span style=\"display:none;\">" + bhard + "</span>" + formatBytes(bhard, xml), "<span style=\"display:none;\">" + bpuse + "</span>" + createBar(bpuse), "<span style=\"display:none;\">" + fused + "</span>" + fused, "<span style=\"display:none;\">" + fsoft + "</span>" + fsoft, "<span style=\"display:none;\">" + fhard + "</span>" + fhard, "<span style=\"display:none;\">" + fpuse + "</span>" + createBar(fpuse)]); }); }); - } + quotas_show = true; + }); +} + +/** + * fill the plugin block with table structure + */ +function quotas_buildTable() { + var html = ""; - function buildTable(xml) { - var html = ""; - var quota; - var user, bused, bsoft, bhard, fpuse, fused, fsoft, fhard, fpuse = ""; - - $("Quota",xml).each(function(id) { - quota = $("Quota",xml).get(id); - user = $("User",quota).text(); - bused = $("ByteUsed",quota).text(); - bsoft = $("ByteSoft",quota).text(); - bhard = $("ByteHard",quota).text(); - bpuse = $("BytePercentUsed",quota).text(); - fused = $("FileUsed",quota).text(); - fsoft = $("FileSoft",quota).text(); - fhard = $("FileHard",quota).text(); - fpuse = $("FilePercentUsed",quota).text(); - - html += " <tr>\n"; - html += " <td><span style=\"display:none;\">" + user + "</span>" + user + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + bused + "</span>" + formatBytes(bused, xml) + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + bsoft + "</span>" + formatBytes(bsoft, xml) + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + bhard + "</span>" + formatBytes(bhard, xml) + "</td>\n"; - html += " <td><span style=\"display:none;\">" + bpuse + "</span>" + createBar(bpuse) + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + fused + "</span>" + fused + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + fsoft + "</span>" + fsoft + "</td>\n"; - html += " <td class=\"right\"><span style=\"display:none;\">" + fhard + "</span>" + fhard + "</td>\n"; - html += " <td><span style=\"display:none;\">" + fpuse + "</span>" + createBar(fpuse) + "</td>\n"; - html += " </tr>\n"; - }); - return html; - } -}); \ No newline at end of file + html += "<table id=\"Plugin_QuotasTable\" cellspacing=\"0\">\n"; + html += " <thead>\n"; + html += " <tr>\n"; + html += " <th>" + genlang(3, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(4, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(5, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(6, false, "Quotas") + "</th>\n"; + html += " <th>" + genlang(7, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(8, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(9, false, "Quotas") + "</th>\n"; + html += " <th class=\"right\">" + genlang(10, false, "Quotas") + "</th>\n"; + html += " <th>" + genlang(11, false, "Quotas") + "</th>\n"; + html += " </tr>\n"; + html += " </thead>\n"; + html += " <tbody>\n"; + html += " </tbody>\n"; + html += "</table>\n"; + + $("#Plugin_Quotas").append(html); + + quotas_table = $("#Plugin_QuotasTable").dataTable({ + "bPaginate": false, + "bLengthChange": false, + "bFilter": false, + "bSort": true, + "bInfo": false, + "bProcessing": true, + "bAutoWidth": false, + "bStateSave": true, + "aoColumns": [{ + "sType": 'span-string' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }, { + "sType": 'span-number' + }] + }); +} + +/** + * load the xml via ajax + */ +function quotas_request() { + $.ajax({ + url: "xml.php?plugin=Quotas", + dataType: "xml", + error: function quotas_error() { + $.jGrowl("Error loading XML document for Plugin quotas!"); + }, + success: function quotas_buildblock(xml) { + quotas_populate(xml); + if (quotas_show) { + plugin_translate("Quotas"); + $("#Plugin_Quotas").show(); + } + } + }); +} + +$(document).ready(function quotas_buildpage() { + $("#footer").before(buildBlock("Quotas", 1, true)); + $("#Plugin_Quotas").css("width", "915px"); + + quotas_buildTable(); + + quotas_request(); + + $("#Reload_QuotasTable").click(function quotas_reload(id) { + quotas_request(); + $("#DateTime_Quotas").html("(" + genlang(2, true, "Quotas") + ": " + datetime() + ")"); + }); +}); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |