PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/yousef_fadila/vtiger
PHP | 237 lines | 194 code | 28 blank | 15 comment | 14 complexity | 8d915432142299fab2019fa4cc33e37e MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. // phpSysInfo - A PHP System Information Script
  3. // http://phpsysinfo.sourceforge.net/
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program; if not, write to the Free Software
  14. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. // $Id: class.Darwin.inc.php,v 1.26 2006/04/15 21:42:20 bigmichi1 Exp $
  16. if (!defined('IN_PHPSYSINFO')) {
  17. die("No Hacking");
  18. }
  19. require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
  20. $error->addError("WARN", "The Darwin version of phpSysInfo is work in progress, some things currently don't work");
  21. class sysinfo extends bsd_common {
  22. var $cpu_regexp;
  23. var $scsi_regexp;
  24. // Our contstructor
  25. // this function is run on the initialization of this class
  26. function sysinfo () {
  27. // $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
  28. // $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
  29. $this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
  30. }
  31. function grab_key ($key) {
  32. $s = execute_program('sysctl', $key);
  33. $s = ereg_replace($key . ': ', '', $s);
  34. $s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
  35. return $s;
  36. }
  37. function grab_ioreg ($key) {
  38. $s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
  39. $s = ereg_replace('\|', '', $s);
  40. $s = ereg_replace('\+\-\o', '', $s);
  41. $s = ereg_replace('[ ]+', '', $s);
  42. $s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
  43. return $s;
  44. }
  45. function get_sys_ticks () {
  46. $a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds)
  47. $sys_ticks = time() - $a;
  48. return $sys_ticks;
  49. }
  50. function cpu_info () {
  51. $results = array();
  52. // $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
  53. // $results['model'] = $this->grab_key('hw.machine');
  54. $results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
  55. $results['cpus'] = $this->grab_key('hw.ncpu');
  56. $results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
  57. $results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
  58. $results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache
  59. if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
  60. if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5
  61. return $results;
  62. }
  63. // get the pci device information out of ioreg
  64. function pci () {
  65. $results = array();
  66. $s = $this->grab_ioreg('IOPCIDevice');
  67. $lines = split("\n", $s);
  68. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  69. $ar_buf = preg_split("/\s+/", $lines[$i], 19);
  70. $results[$i] = $ar_buf[0];
  71. }
  72. asort($results);
  73. return array_values(array_unique($results));
  74. }
  75. // get the ide device information out of ioreg
  76. function ide () {
  77. $results = array();
  78. // ioreg | grep "Media <class IOMedia>"
  79. $s = $this->grab_ioreg('IOATABlockStorageDevice');
  80. $lines = split("\n", $s);
  81. $j = 0;
  82. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  83. $ar_buf = preg_split("/\/\//", $lines[$i], 19);
  84. if ($ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
  85. $results[$j++]['model'] = $ar_buf[0];
  86. }
  87. }
  88. asort($results);
  89. return array_values(array_unique($results));
  90. }
  91. function memory () {
  92. $s = $this->grab_key('hw.memsize');
  93. $results['ram'] = array();
  94. $pstat = execute_program('vm_stat'); // use darwin's vm_stat
  95. $lines = split("\n", $pstat);
  96. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  97. $ar_buf = preg_split("/\s+/", $lines[$i], 19);
  98. if ($i == 1) {
  99. $results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
  100. }
  101. }
  102. $results['ram']['total'] = $s / 1024;
  103. $results['ram']['shared'] = 0;
  104. $results['ram']['buffers'] = 0;
  105. $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
  106. $results['ram']['cached'] = 0;
  107. $results['ram']['t_used'] = $results['ram']['used'];
  108. $results['ram']['t_free'] = $results['ram']['free'];
  109. $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
  110. // need to fix the swap info...
  111. $pstat = execute_program('swapinfo', '-k');
  112. $lines = split("\n", $pstat);
  113. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  114. $ar_buf = preg_split("/\s+/", $lines[$i], 6);
  115. if ($i == 0) {
  116. $results['swap']['total'] = 0;
  117. $results['swap']['used'] = 0;
  118. $results['swap']['free'] = 0;
  119. } else {
  120. $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
  121. $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
  122. $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
  123. }
  124. }
  125. $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
  126. return $results;
  127. }
  128. function network () {
  129. $netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
  130. $lines = split("\n", $netstat);
  131. $results = array();
  132. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  133. $ar_buf = preg_split("/\s+/", $lines[$i]);
  134. if (!empty($ar_buf[0])) {
  135. $results[$ar_buf[0]] = array();
  136. $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
  137. $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
  138. $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
  139. $results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
  140. $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
  141. $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
  142. $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
  143. $results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
  144. $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
  145. $results[$ar_buf[0]]['drop'] = $ar_buf[10];
  146. }
  147. }
  148. return $results;
  149. }
  150. function filesystems () {
  151. $df = execute_program('df', '-k');
  152. $mounts = split("\n", $df);
  153. $fstype = array();
  154. $s = execute_program('mount');
  155. $lines = explode("\n", $s);
  156. $i = 0;
  157. while (list(, $line) = each($lines)) {
  158. ereg('(.*) \((.*)\)', $line, $a);
  159. $m = explode(' ', $a[0]);
  160. $fsdev[$m[0]] = $a[2];
  161. }
  162. for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
  163. $ar_buf = preg_split("/\s+/", $mounts[$i], 6);
  164. switch ($ar_buf[0]) {
  165. case 'automount': // skip the automount entries
  166. case 'devfs': // skip the dev filesystem
  167. case 'fdesc': // skip the fdesc
  168. case 'procfs': // skip the proc filesystem
  169. case '<volfs>': // skip the vol filesystem
  170. continue 2;
  171. break;
  172. }
  173. if (hide_mount($ar_buf[5])) {
  174. continue;
  175. }
  176. $results[$j] = array();
  177. $results[$j]['disk'] = $ar_buf[0];
  178. $results[$j]['size'] = $ar_buf[1];
  179. $results[$j]['used'] = $ar_buf[2];
  180. $results[$j]['free'] = $ar_buf[3];
  181. $results[$j]['percent'] = $ar_buf[4];
  182. $results[$j]['mount'] = $ar_buf[5];
  183. ($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] : $results[$j]['fstype'] = $fsdev[$ar_buf[0]];
  184. $j++;
  185. }
  186. return $results;
  187. }
  188. function distroicon () {
  189. $result = 'Darwin.png';
  190. return($result);
  191. }
  192. }
  193. ?>