PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/yousef_fadila/vtiger
PHP | 238 lines | 218 code | 6 blank | 14 comment | 0 complexity | 3748e6f2caf491aa77c336b32b3b905c 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.SunOS.inc.php,v 1.22 2006/02/11 17:55:25 bigmichi1 Exp $
  16. $error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
  17. class sysinfo {
  18. // Extract kernel values via kstat() interface
  19. function kstat ($key) {
  20. $m = execute_program('kstat', "-p d $key");
  21. list($key, $value) = split("\t", trim($m), 2);
  22. return $value;
  23. }
  24. function vhostname () {
  25. if (! ($result = getenv('SERVER_NAME'))) {
  26. $result = 'N.A.';
  27. }
  28. return $result;
  29. }
  30. // get our canonical hostname
  31. function chostname () {
  32. if ($result = execute_program('uname', '-n')) {
  33. $result = gethostbyaddr(gethostbyname($result));
  34. } else {
  35. $result = 'N.A.';
  36. }
  37. return $result;
  38. }
  39. // get the IP address of our canonical hostname
  40. function ip_addr () {
  41. if (!($result = getenv('SERVER_ADDR'))) {
  42. $result = gethostbyname($this->chostname());
  43. }
  44. return $result;
  45. }
  46. function kernel () {
  47. $os = execute_program('uname', '-s');
  48. $version = execute_program('uname', '-r');
  49. return $os . ' ' . $version;
  50. }
  51. function uptime () {
  52. $result = time() - $this->kstat('unix:0:system_misc:boot_time');
  53. return $result;
  54. }
  55. function users () {
  56. $who = split('=', execute_program('who', '-q'));
  57. $result = $who[1];
  58. return $result;
  59. }
  60. function loadavg ($bar = false) {
  61. $load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
  62. $load5 = $this->kstat('unix:0:system_misc:avenrun_5min');
  63. $load15 = $this->kstat('unix:0:system_misc:avenrun_15min');
  64. $results['avg'] = array( round($load1/256, 2), round($load5/256, 2), round($load15/256, 2) );
  65. return $results;
  66. }
  67. function cpu_info () {
  68. $results = array();
  69. $ar_buf = array();
  70. $results['model'] = execute_program('uname', '-i');
  71. $results['cpuspeed'] = $this->kstat('cpu_info:0:cpu_info0:clock_MHz');
  72. $results['cache'] = $this->kstat('cpu_info:0:cpu_info0:cpu_type');
  73. $results['cpus'] = $this->kstat('unix:0:system_misc:ncpus');
  74. return $results;
  75. }
  76. function pci () {
  77. // FIXME
  78. $results = array();
  79. return $results;
  80. }
  81. function ide () {
  82. // FIXME
  83. $results = array();
  84. return $results;
  85. }
  86. function scsi () {
  87. // FIXME
  88. $results = array();
  89. return $results;
  90. }
  91. function usb () {
  92. // FIXME
  93. $results = array();
  94. return $results;
  95. }
  96. function sbus () {
  97. $results = array();
  98. $_results[0] = "";
  99. // TODO. Nothing here yet. Move along.
  100. $results = $_results;
  101. return $results;
  102. }
  103. function network () {
  104. $results = array();
  105. $netstat = execute_program('netstat', '-ni | awk \'(NF ==10){print;}\'');
  106. $lines = split("\n", $netstat);
  107. $results = array();
  108. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  109. $ar_buf = preg_split("/\s+/", $lines[$i]);
  110. if ((!empty($ar_buf[0])) && ($ar_buf[0] != 'Name')) {
  111. $results[$ar_buf[0]] = array();
  112. $results[$ar_buf[0]]['rx_bytes'] = 0;
  113. $results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
  114. $results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
  115. $results[$ar_buf[0]]['rx_drop'] = 0;
  116. $results[$ar_buf[0]]['tx_bytes'] = 0;
  117. $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
  118. $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
  119. $results[$ar_buf[0]]['tx_drop'] = 0;
  120. $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[
  121. 7];
  122. $results[$ar_buf[0]]['drop'] = 0;
  123. preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
  124. $prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
  125. $cnt = $this->kstat($prefix . 'drop');
  126. if ($cnt > 0) {
  127. $results[$ar_buf[0]]['rx_drop'] = $cnt;
  128. }
  129. $cnt = $this->kstat($prefix . 'obytes64');
  130. if ($cnt > 0) {
  131. $results[$ar_buf[0]]['tx_bytes'] = $cnt;
  132. }
  133. $cnt = $this->kstat($prefix . 'rbytes64');
  134. if ($cnt > 0) {
  135. $results[$ar_buf[0]]['rx_bytes'] = $cnt;
  136. }
  137. }
  138. }
  139. return $results;
  140. }
  141. function memory () {
  142. $results['devswap'] = array();
  143. $results['ram'] = array();
  144. $pagesize = $this->kstat('unix:0:seg_cache:slab_size');
  145. $results['ram']['total'] = $this->kstat('unix:0:system_pages:pagestotal') * $pagesize / 1024;
  146. $results['ram']['used'] = $this->kstat('unix:0:system_pages:pageslocked') * $pagesize / 1024;
  147. $results['ram']['free'] = $this->kstat('unix:0:system_pages:pagesfree') * $pagesize / 1024;
  148. $results['ram']['shared'] = 0;
  149. $results['ram']['buffers'] = 0;
  150. $results['ram']['cached'] = 0;
  151. $results['ram']['t_used'] = $results['ram']['used'] - $results['ram']['cached'] - $results['ram']['buffers'];
  152. $results['ram']['t_free'] = $results['ram']['total'] - $results['ram']['t_used'];
  153. $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
  154. $results['swap'] = array();
  155. $results['swap']['total'] = $this->kstat('unix:0:vminfo:swap_avail') / 1024 / 1024;
  156. $results['swap']['used'] = $this->kstat('unix:0:vminfo:swap_alloc') / 1024 / 1024;
  157. $results['swap']['free'] = $this->kstat('unix:0:vminfo:swap_free') / 1024 / 1024;
  158. $results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
  159. $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
  160. return $results;
  161. }
  162. function filesystems () {
  163. $df = execute_program('df', '-k');
  164. $mounts = split("\n", $df);
  165. $dftypes = execute_program('df', '-n');
  166. $mounttypes = split("\n", $dftypes);
  167. for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
  168. $ar_buf = preg_split('/\s+/', $mounts[$i], 6);
  169. $ty_buf = split(':', $mounttypes[$i-1], 2);
  170. if (hide_mount($ar_buf[5])) {
  171. continue;
  172. }
  173. $results[$j] = array();
  174. $results[$j]['disk'] = $ar_buf[0];
  175. $results[$j]['size'] = $ar_buf[1];
  176. $results[$j]['used'] = $ar_buf[2];
  177. $results[$j]['free'] = $ar_buf[3];
  178. $results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
  179. $results[$j]['mount'] = $ar_buf[5];
  180. $results[$j]['fstype'] = $ty_buf[1];
  181. $j++;
  182. }
  183. return $results;
  184. }
  185. function distro () {
  186. $result = 'SunOS';
  187. return($result);
  188. }
  189. function distroicon () {
  190. $result = 'SunOS.png';
  191. return($result);
  192. }
  193. }
  194. ?>