PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/System/includes/os/class.parseProgs.inc.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 133 lines | 103 code | 25 blank | 5 comment | 23 complexity | 950570eebcb7976d685f1cd0a7a33e9c MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. class Parser {
  3. var $debug = false;
  4. var $df_param;
  5. function parse_lspci() {
  6. $results = array();
  7. if ($_results = execute_program('lspci', '', $this->debug)) {
  8. $lines = split("\n", $_results);
  9. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  10. list($addr, $name) = explode(' ', trim($lines[$i]), 2);
  11. //if (!preg_match('/bridge/i', $name) && !preg_match('/USB/i', $name)) {
  12. // remove all the version strings
  13. $name = preg_replace('/\(.*\)/', '', $name);
  14. // is addr really usefull for this??? i think it's not
  15. // $results[] = $addr . ' ' . $name;
  16. $results[] = $name;
  17. //}
  18. }
  19. }
  20. if( empty( $results ) ) {
  21. return false;
  22. } else {
  23. asort( $results );
  24. return $results;
  25. }
  26. }
  27. function parse_pciconf() {
  28. $results = array();
  29. if($buf = execute_program("pciconf", "-lv", $this->debug)) {
  30. $buf = explode("\n", $buf); $s = 0;
  31. foreach($buf as $line) {
  32. if (preg_match("/(.*) = '(.*)'/", $line, $strings)) {
  33. if (trim($strings[1]) == "vendor") {
  34. $results[$s] = trim($strings[2]);
  35. } elseif (trim($strings[1]) == "device") {
  36. $results[$s] .= " - " . trim($strings[2]);
  37. $s++;
  38. }
  39. }
  40. }
  41. }
  42. if( empty( $results ) ) {
  43. return false;
  44. } else {
  45. asort( $results );
  46. return $results;
  47. }
  48. }
  49. function parse_filesystems() {
  50. global $show_bind, $show_inodes;
  51. $j = 0;
  52. $df = execute_program('df', '-k' . $this->df_param );
  53. $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
  54. if( $show_inodes ) {
  55. $df2 = execute_program('df', '-i' . $this->df_param );
  56. $df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY);
  57. }
  58. $mount = execute_program('mount');
  59. $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
  60. foreach( $df as $df_line) {
  61. $df_buf1 = preg_split("/(\%\s)/", $df_line, 2);
  62. if( count($df_buf1) != 2) {
  63. continue;
  64. }
  65. preg_match("/(.*)(\s+)(([0-9]+)(\s+)([0-9]+)(\s+)([0-9]+)(\s+)([0-9]+)$)/", $df_buf1[0], $df_buf2);
  66. $df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]);
  67. if( $show_inodes ) {
  68. preg_match_all("/([0-9]+)%/", $df2[$j + 1], $inode_buf, PREG_SET_ORDER);
  69. }
  70. if( count($df_buf) == 6 ) {
  71. if( hide_mount( $df_buf[5] ) ) {
  72. continue;
  73. }
  74. $df_buf[0] = trim( str_replace("\$", "\\$", $df_buf[0] ) );
  75. $df_buf[5] = trim( $df_buf[5] );
  76. $current = 0;
  77. foreach( $mount as $mount_line ) {
  78. $current++;
  79. if ( preg_match("#" . $df_buf[0] . " on " . $df_buf[5] . " type (.*) \((.*)\)#", $mount_line, $mount_buf) ) {
  80. $mount_buf[1] .= "," . $mount_buf[2];
  81. } elseif ( !preg_match("#" . $df_buf[0] . "(.*) on " . $df_buf[5] . " \((.*)\)#", $mount_line, $mount_buf) ) {
  82. continue;
  83. }
  84. if ( $show_bind || !stristr($mount_buf[2], "bind")) {
  85. $results[$j] = array();
  86. $results[$j]['disk'] = str_replace( "\\$", "\$", $df_buf[0] );
  87. $results[$j]['size'] = $df_buf[1];
  88. $results[$j]['used'] = $df_buf[2];
  89. $results[$j]['free'] = $df_buf[3];
  90. $results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
  91. $results[$j]['mount'] = $df_buf[5];
  92. $results[$j]['fstype'] = substr( $mount_buf[1], 0, strpos( $mount_buf[1], "," ) );
  93. $results[$j]['options'] = substr( $mount_buf[1], strpos( $mount_buf[1], "," ) + 1, strlen( $mount_buf[1] ) );
  94. if( $show_inodes && isset($inode_buf[ count( $inode_buf ) - 1][1]) ) {
  95. $results[$j]['inodes'] = $inode_buf[ count( $inode_buf ) - 1][1];
  96. }
  97. $j++;
  98. unset( $mount[$current - 1] );
  99. sort( $mount );
  100. break;
  101. }
  102. }
  103. }
  104. }
  105. return $results;
  106. }
  107. }
  108. ?>