/branches/namiltd-ini/plugins/quotas/class.quotas.inc.php

# · PHP · 132 lines · 74 code · 4 blank · 54 comment · 12 complexity · 9e9f7384b72e4edbd69f5ea36d62cb00 MD5 · raw file

  1. <?php
  2. /**
  3. * Quotas Plugin
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PSI_Plugin_Quotas
  9. * @author Michael Cramer <BigMichi1@users.sourceforge.net>
  10. * @copyright 2009 phpSysInfo
  11. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  12. * @version SVN: $Id: class.quotas.inc.php 661 2012-08-27 11:26:39Z namiltd $
  13. * @link http://phpsysinfo.sourceforge.net
  14. */
  15. /**
  16. * Quotas Plugin, which displays all quotas on the machine
  17. * display all quotas in a sortable table with the current values which are determined by
  18. * calling the "repquota" command line utility, another way is to provide
  19. * a file with the output of the repquota utility, so there is no need to run a execute by the
  20. * webserver, the format of the command is written down in the quota.config.php file, where also
  21. * the method of getting the information is configured
  22. *
  23. * @category PHP
  24. * @package PSI_Plugin_Quotas
  25. * @author Michael Cramer <BigMichi1@users.sourceforge.net>
  26. * @copyright 2009 phpSysInfo
  27. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  28. * @version Release: 3.0
  29. * @link http://phpsysinfo.sourceforge.net
  30. */
  31. class Quotas extends PSI_Plugin
  32. {
  33. /**
  34. * variable, which holds the content of the command
  35. * @var array
  36. */
  37. private $_filecontent = array();
  38. /**
  39. * variable, which holds the result before the xml is generated out of this array
  40. * @var array
  41. */
  42. private $_result = array();
  43. /**
  44. * read the data into an internal array and also call the parent constructor
  45. *
  46. * @param String $enc target encoding
  47. */
  48. public function __construct($enc)
  49. {
  50. parent::__construct(__CLASS__, $enc);
  51. switch (strtolower(PSI_PLUGIN_QUOTAS_ACCESS)) {
  52. case 'command':
  53. CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);
  54. break;
  55. case 'data':
  56. CommonFunctions::rfts(APP_ROOT."/data/quotas.txt", $buffer);
  57. break;
  58. default:
  59. $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_QUOTAS_ACCESS");
  60. break;
  61. }
  62. if (trim($buffer) != "") {
  63. $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
  64. unset($this->_filecontent[0]);
  65. } else {
  66. $this->_filecontent = array();
  67. }
  68. }
  69. /**
  70. * doing all tasks to get the required informations that the plugin needs
  71. * result is stored in an internal array<br>the array is build like a tree,
  72. * so that it is possible to get only a specific process with the childs
  73. *
  74. * @return void
  75. */
  76. public function execute()
  77. {
  78. $i = 0;
  79. $quotas = array();
  80. foreach ($this->_filecontent as $thisline) {
  81. $thisline = preg_replace("/([\s]--)/", "", $thisline);
  82. $thisline = preg_split("/(\s)/e", $thisline, -1, PREG_SPLIT_NO_EMPTY);
  83. if (count($thisline) == 7) {
  84. $quotas[$i]['user'] = str_replace("--", "", $thisline[0]);
  85. $quotas[$i]['byte_used'] = $thisline[1] * 1024;
  86. $quotas[$i]['byte_soft'] = $thisline[2] * 1024;
  87. $quotas[$i]['byte_hard'] = $thisline[3] * 1024;
  88. if ($thisline[3] != 0) {
  89. $quotas[$i]['byte_percent_used'] = round((($quotas[$i]['byte_used'] / $quotas[$i]['byte_hard']) * 100), 1);
  90. } else {
  91. $quotas[$i]['byte_percent_used'] = 0;
  92. }
  93. $quotas[$i]['file_used'] = $thisline[4];
  94. $quotas[$i]['file_soft'] = $thisline[5];
  95. $quotas[$i]['file_hard'] = $thisline[6];
  96. if ($thisline[6] != 0) {
  97. $quotas[$i]['file_percent_used'] = round((($quotas[$i]['file_used'] / $quotas[$i]['file_hard']) * 100), 1);
  98. } else {
  99. $quotas[$i]['file_percent_used'] = 0;
  100. }
  101. $i++;
  102. }
  103. }
  104. $this->_result = $quotas;
  105. }
  106. /**
  107. * generates the XML content for the plugin
  108. *
  109. * @return SimpleXMLElement entire XML content for the plugin
  110. */
  111. public function xml()
  112. {
  113. foreach ($this->_result as $quota) {
  114. $quotaChild = $this->xml->addChild("Quota");
  115. $quotaChild->addAttribute("User", $quota['user']);
  116. $quotaChild->addAttribute("ByteUsed", $quota['byte_used']);
  117. $quotaChild->addAttribute("ByteSoft", $quota['byte_soft']);
  118. $quotaChild->addAttribute("ByteHard", $quota['byte_hard']);
  119. $quotaChild->addAttribute("BytePercentUsed", $quota['byte_percent_used']);
  120. $quotaChild->addAttribute("FileUsed", $quota['file_used']);
  121. $quotaChild->addAttribute("FileSoft", $quota['file_soft']);
  122. $quotaChild->addAttribute("FileHard", $quota['file_hard']);
  123. $quotaChild->addAttribute("FilePercentUsed", $quota['file_percent_used']);
  124. }
  125. return $this->xml->getSimpleXmlElement();
  126. }
  127. }
  128. ?>