PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/System/includes/os/class.HP-UX.inc.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 421 lines | 342 code | 53 blank | 26 comment | 53 complexity | 6898d457ac842ef3aeb2c8c751f3a675 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.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.HP-UX.inc.php,v 1.17 2006/02/11 17:31:03 bigmichi1 Exp $
  16. class sysinfo {
  17. // get our apache SERVER_NAME or vhost
  18. function vhostname () {
  19. if (! ($result = getenv('SERVER_NAME'))) {
  20. $result = 'N.A.';
  21. }
  22. return $result;
  23. }
  24. // get our canonical hostname
  25. function chostname () {
  26. return execute_program('hostname');
  27. }
  28. // get the IP address of our canonical hostname
  29. function ip_addr () {
  30. if (!($result = getenv('SERVER_ADDR'))) {
  31. $result = gethostbyname($this->chostname());
  32. }
  33. return $result;
  34. }
  35. function kernel () {
  36. return execute_program('uname', '-srvm');
  37. }
  38. function uptime () {
  39. $result = 0;
  40. $ar_buf = array();
  41. $buf = execute_program('uptime');
  42. if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
  43. $min = $ar_buf[3];
  44. $hours = $ar_buf[2];
  45. $days = $ar_buf[1];
  46. $result = $days * 86400 + $hours * 3600 + $min * 60;
  47. }
  48. return $result;
  49. }
  50. function users () {
  51. $who = split('=', execute_program('who', '-q'));
  52. $result = $who[1];
  53. return $result;
  54. }
  55. function loadavg ($bar = false) {
  56. $ar_buf = array();
  57. $buf = execute_program('uptime');
  58. if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
  59. $results['avg'] = array($ar_buf[1], $ar_buf[2], $ar_buf[3]);
  60. } else {
  61. $results['avg'] = array('N.A.', 'N.A.', 'N.A.');
  62. }
  63. return $results;
  64. }
  65. function cpu_info () {
  66. $results = array();
  67. $ar_buf = array();
  68. $bufr = rfts( '/proc/cpuinfo' );
  69. if( $bufr != "ERROR" ) {
  70. $bufe = explode( "\n", $bufr );
  71. foreach( $bufe as $buf ) {
  72. list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
  73. // All of the tags here are highly architecture dependant.
  74. // the only way I could reconstruct them for machines I don't
  75. // have is to browse the kernel source. So if your arch isn't
  76. // supported, tell me you want it written in.
  77. switch ($key) {
  78. case 'model name':
  79. $results['model'] = $value;
  80. break;
  81. case 'cpu MHz':
  82. $results['cpuspeed'] = sprintf('%.2f', $value);
  83. break;
  84. case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
  85. $results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
  86. break;
  87. case 'clock': // For PPC arch (damn borked POS)
  88. $results['cpuspeed'] = sprintf('%.2f', $value);
  89. break;
  90. case 'cpu': // For PPC arch (damn borked POS)
  91. $results['model'] = $value;
  92. break;
  93. case 'revision': // For PPC arch (damn borked POS)
  94. $results['model'] .= ' ( rev: ' . $value . ')';
  95. break;
  96. case 'cpu model': // For Alpha arch - 2.2.x
  97. $results['model'] .= ' (' . $value . ')';
  98. break;
  99. case 'cache size':
  100. $results['cache'] = $value;
  101. break;
  102. case 'bogomips':
  103. $results['bogomips'] += $value;
  104. break;
  105. case 'BogoMIPS': // For alpha arch - 2.2.x
  106. $results['bogomips'] += $value;
  107. break;
  108. case 'BogoMips': // For sparc arch
  109. $results['bogomips'] += $value;
  110. break;
  111. case 'cpus detected': // For Alpha arch - 2.2.x
  112. $results['cpus'] += $value;
  113. break;
  114. case 'system type': // Alpha arch - 2.2.x
  115. $results['model'] .= ', ' . $value . ' ';
  116. break;
  117. case 'platform string': // Alpha arch - 2.2.x
  118. $results['model'] .= ' (' . $value . ')';
  119. break;
  120. case 'processor':
  121. $results['cpus'] += 1;
  122. break;
  123. }
  124. }
  125. fclose($fd);
  126. }
  127. $keys = array_keys($results);
  128. $keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
  129. while ($ar_buf = each($keys2be)) {
  130. if (! in_array($ar_buf[1], $keys)) {
  131. $results[$ar_buf[1]] = 'N.A.';
  132. }
  133. }
  134. return $results;
  135. }
  136. function pci () {
  137. $results = array();
  138. $bufr = rfts( '/proc/pci' );
  139. if( $bufr != "ERROR" ) {
  140. $bufe = explode( "\n", $bufr );
  141. foreach( $bufe as $buf ) {
  142. if (preg_match('/Bus/', $buf)) {
  143. $device = true;
  144. continue;
  145. }
  146. if ($device) {
  147. list($key, $value) = split(': ', $buf, 2);
  148. if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
  149. $results[] = preg_replace('/\([^\)]+\)\.$/', '', trim($value));
  150. }
  151. $device = false;
  152. }
  153. }
  154. }
  155. asort($results);
  156. return $results;
  157. }
  158. function ide () {
  159. $results = array();
  160. $bufd = gdc( '/proc/ide' );
  161. foreach( $bufd as $file ) {
  162. if (preg_match('/^hd/', $file)) {
  163. $results[$file] = array();
  164. // Check if device is CD-ROM (CD-ROM capacity shows as 1024 GB)
  165. $buf = rfts( "/proc/ide/" . $file . "/media", 1 );
  166. if( $buf != "ERROR" ) {
  167. $results[$file]['media'] = trim( $buf );
  168. if ($results[$file]['media'] == 'disk') {
  169. $results[$file]['media'] = 'Hard Disk';
  170. }
  171. if ($results[$file]['media'] == 'cdrom') {
  172. $results[$file]['media'] = 'CD-ROM';
  173. }
  174. }
  175. $buf = rfts( "/proc/ide/" . $file . "/model", 1 );
  176. if( $buf != "ERROR" ) {
  177. $results[$file]['model'] = trim( $buf );
  178. if (preg_match('/WDC/', $results[$file]['model'])) {
  179. $results[$file]['manufacture'] = 'Western Digital';
  180. } elseif (preg_match('/IBM/', $results[$file]['model'])) {
  181. $results[$file]['manufacture'] = 'IBM';
  182. } elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
  183. $results[$file]['manufacture'] = 'Fujitsu';
  184. } else {
  185. $results[$file]['manufacture'] = 'Unknown';
  186. }
  187. }
  188. $buf = rfts( "/proc/ide/" . $file . "/capacity", 1 );
  189. if( $buf != "ERROR" ) {
  190. $results[$file]['capacity'] = trim( $buf );
  191. if ($results[$file]['media'] == 'CD-ROM') {
  192. unset($results[$file]['capacity']);
  193. }
  194. }
  195. }
  196. }
  197. asort($results);
  198. return $results;
  199. }
  200. function scsi () {
  201. $results = array();
  202. $dev_vendor = '';
  203. $dev_model = '';
  204. $dev_rev = '';
  205. $dev_type = '';
  206. $s = 1;
  207. $bufr = rfts( '/proc/scsi/scsi' );
  208. if( $bufr != "ERROR" ) {
  209. $bufe = explode( "\n", $bufr );
  210. foreach( $bufe as $buf ) {
  211. if (preg_match('/Vendor/', $buf)) {
  212. preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
  213. list($key, $value) = split(': ', $buf, 2);
  214. $dev_str = $value;
  215. $get_type = 1;
  216. continue;
  217. }
  218. if ($get_type) {
  219. preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
  220. $results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
  221. $results[$s]['media'] = "Hard Disk";
  222. $s++;
  223. $get_type = 0;
  224. }
  225. }
  226. }
  227. asort($results);
  228. return $results;
  229. }
  230. function usb () {
  231. $results = array();
  232. $devstring = 0;
  233. $devnum = -1;
  234. $bufr = rfts( '/proc/bus/usb/devices' );
  235. if( $bufr != "ERROR" ) {
  236. $bufe = explode( "\n", $bufr );
  237. foreach( $bufe as $buf ) {
  238. if (preg_match('/^T/', $buf)) {
  239. $devnum += 1;
  240. }
  241. if (preg_match('/^S/', $buf)) {
  242. $devstring = 1;
  243. }
  244. if ($devstring) {
  245. list($key, $value) = split(': ', $buf, 2);
  246. list($key, $value2) = split('=', $value, 2);
  247. $results[$devnum] .= " " . trim($value2);
  248. $devstring = 0;
  249. }
  250. }
  251. }
  252. return $results;
  253. }
  254. function sbus () {
  255. $results = array();
  256. $_results[0] = "";
  257. // TODO. Nothing here yet. Move along.
  258. $results = $_results;
  259. return $results;
  260. }
  261. function network () {
  262. $netstat = execute_program('netstat', '-ni | tail -n +2');
  263. $lines = split("\n", $netstat);
  264. $results = array();
  265. for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  266. $ar_buf = preg_split("/\s+/", $lines[$i]);
  267. if (!empty($ar_buf[0]) && !empty($ar_buf[3])) {
  268. $results[$ar_buf[0]] = array();
  269. $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[4];
  270. $results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
  271. $results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
  272. $results[$ar_buf[0]]['rx_drop'] = $ar_buf[8];
  273. $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[6];
  274. $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
  275. $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
  276. $results[$ar_buf[0]]['tx_drop'] = $ar_buf[8];
  277. $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
  278. $results[$ar_buf[0]]['drop'] = $ar_buf[8];
  279. }
  280. }
  281. return $results;
  282. }
  283. function memory () {
  284. $results['ram'] = array();
  285. $results['swap'] = array();
  286. $results['devswap'] = array();
  287. $bufr = rfts( '/proc/meminfo' );
  288. if( $bufr != "ERROR" ) {
  289. $bufe = explode( "\n", $bufr );
  290. foreach( $bufe as $buf ) {
  291. if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
  292. $ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
  293. $results['ram']['total'] = $ar_buf[0] / 1024;
  294. $results['ram']['used'] = $ar_buf[1] / 1024;
  295. $results['ram']['free'] = $ar_buf[2] / 1024;
  296. $results['ram']['shared'] = $ar_buf[3] / 1024;
  297. $results['ram']['buffers'] = $ar_buf[4] / 1024;
  298. $results['ram']['cached'] = $ar_buf[5] / 1024;
  299. // I don't like this since buffers and cache really aren't
  300. // 'used' per say, but I get too many emails about it.
  301. $results['ram']['t_used'] = $results['ram']['used'];
  302. $results['ram']['t_free'] = $results['ram']['total'] - $results['ram']['t_used'];
  303. $results['ram']['percent'] = round(($results['ram']['t_used'] * 100) / $results['ram']['total']);
  304. }
  305. if (preg_match('/Swap:\s+(.*)$/', $buf, $ar_buf)) {
  306. $ar_buf = preg_split('/\s+/', $ar_buf[1], 3);
  307. $results['swap']['total'] = $ar_buf[0] / 1024;
  308. $results['swap']['used'] = $ar_buf[1] / 1024;
  309. $results['swap']['free'] = $ar_buf[2] / 1024;
  310. $results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
  311. // Get info on individual swap files
  312. $swaps = rfts( '/proc/swaps' );
  313. if( $swaps != "ERROR" ) {
  314. $swapdevs = split("\n", $swaps);
  315. for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
  316. $ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
  317. $results['devswap'][$i - 1] = array();
  318. $results['devswap'][$i - 1]['dev'] = $ar_buf[0];
  319. $results['devswap'][$i - 1]['total'] = $ar_buf[2];
  320. $results['devswap'][$i - 1]['used'] = $ar_buf[3];
  321. $results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
  322. $results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) / $ar_buf[2]);
  323. }
  324. break;
  325. }
  326. }
  327. }
  328. }
  329. return $results;
  330. }
  331. function filesystems () {
  332. $df = execute_program('df', '-kP');
  333. $mounts = split("\n", $df);
  334. $fstype = array();
  335. $s = execute_program('mount', '-v');
  336. $lines = explode("\n", $s);
  337. $i = 0;
  338. while (list(, $line) = each($lines)) {
  339. $a = split(' ', $line);
  340. $fsdev[$a[0]] = $a[4];
  341. }
  342. for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
  343. $ar_buf = preg_split("/\s+/", $mounts[$i], 6);
  344. if (hide_mount($ar_buf[5])) {
  345. continue;
  346. }
  347. $results[$j] = array();
  348. $results[$j]['disk'] = $ar_buf[0];
  349. $results[$j]['size'] = $ar_buf[1];
  350. $results[$j]['used'] = $ar_buf[2];
  351. $results[$j]['free'] = $ar_buf[3];
  352. $results[$j]['percent'] = $ar_buf[4];
  353. $results[$j]['mount'] = $ar_buf[5];
  354. ($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] : $results[$j]['fstype'] = $fsdev[$ar_buf[0]];
  355. $j++;
  356. }
  357. return $results;
  358. }
  359. function distro () {
  360. $result = 'HP-UX';
  361. return($result);
  362. }
  363. function distroicon () {
  364. $result = 'unknown.png';
  365. return($result);
  366. }
  367. }
  368. ?>