PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/appserv/lib/phpsysinfo/includes/os/class.SunOS.inc.php

http://openbiz-cubi.googlecode.com/
PHP | 281 lines | 253 code | 0 blank | 28 comment | 0 complexity | a5f33de60e7e4966aa94cfaf3b68387d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * SunOS System Class
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PSI_OS
  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.SunOS.inc.php 522 2011-11-08 18:21:09Z jacky672 $
  13. * @link http://phpsysinfo.sourceforge.net
  14. */
  15. /**
  16. * SunOS sysinfo class
  17. * get all the required information from SunOS systems
  18. *
  19. * @category PHP
  20. * @package PSI_OS
  21. * @author Michael Cramer <BigMichi1@users.sourceforge.net>
  22. * @copyright 2009 phpSysInfo
  23. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  24. * @version Release: 3.0
  25. * @link http://phpsysinfo.sourceforge.net
  26. */
  27. class SunOS extends OS
  28. {
  29. /**
  30. * add warning to errors
  31. */
  32. public function __construct()
  33. {
  34. $this->error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
  35. }
  36. /**
  37. * Extract kernel values via kstat() interface
  38. *
  39. * @param string $key key for kstat programm
  40. *
  41. * @return string
  42. */
  43. private function _kstat($key)
  44. {
  45. if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG)) {
  46. list($key, $value) = preg_split("/\t/", trim($m), 2);
  47. return $value;
  48. } else {
  49. return '';
  50. }
  51. }
  52. /**
  53. * Virtual Host Name
  54. *
  55. * @return void
  56. */
  57. private function _hostname()
  58. {
  59. if (PSI_USE_VHOST === true) {
  60. $this->sys->setHostname(getenv('SERVER_NAME'));
  61. } else {
  62. if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
  63. $ip = gethostbyname($result);
  64. if ($ip != $result) {
  65. $this->sys->setHostname(gethostbyaddr($ip));
  66. }
  67. }
  68. }
  69. }
  70. /**
  71. * IP of the Virtual Host Name
  72. *
  73. * @return void
  74. */
  75. private function _ip()
  76. {
  77. if (PSI_USE_VHOST === true) {
  78. $this->sys->setIp(gethostbyname($this->_hostname()));
  79. } else {
  80. if (!($result = getenv('SERVER_ADDR'))) {
  81. $this->sys->setIp(gethostbyname($this->_hostname()));
  82. } else {
  83. $this->sys->setIp($result);
  84. }
  85. }
  86. }
  87. /**
  88. * Kernel Version
  89. *
  90. * @return void
  91. */
  92. private function _kernel()
  93. {
  94. if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG)) {
  95. if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG)) {
  96. $this->sys->setKernel($os.' '.$version);
  97. } else {
  98. $this->sys->setKernel($os);
  99. }
  100. }
  101. }
  102. /**
  103. * UpTime
  104. * time the system is running
  105. *
  106. * @return void
  107. */
  108. private function _uptime()
  109. {
  110. $this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
  111. }
  112. /**
  113. * Number of Users
  114. *
  115. * @return void
  116. */
  117. private function _users()
  118. {
  119. if (CommonFunctions::executeProgram('who', '-q', $buf, PSI_DEBUG)) {
  120. $who = preg_split('/=/', $buf);
  121. $this->sys->setUsers($who[1]);
  122. }
  123. }
  124. /**
  125. * Processor Load
  126. * optionally create a loadbar
  127. *
  128. * @return void
  129. */
  130. private function _loadavg()
  131. {
  132. $load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
  133. $load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
  134. $load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
  135. $this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
  136. }
  137. /**
  138. * CPU information
  139. *
  140. * @return void
  141. */
  142. private function _cpuinfo()
  143. {
  144. $dev = new CpuDevice();
  145. if (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG)) {
  146. $dev->setModel(trim($buf));
  147. }
  148. $dev->setCpuSpeed($this->_kstat('cpu_info:0:cpu_info0:clock_MHz'));
  149. $dev->setCache($this->_kstat('cpu_info:0:cpu_info0:cpu_type') * 1024);
  150. $this->sys->setCpus($dev);
  151. }
  152. /**
  153. * Network devices
  154. *
  155. * @return void
  156. */
  157. private function _network()
  158. {
  159. if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
  160. $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
  161. foreach ($lines as $line) {
  162. $ar_buf = preg_split("/\s+/", $line);
  163. if (! empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
  164. $dev = new NetDevice();
  165. $dev->setName($ar_buf[0]);
  166. $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
  167. preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
  168. $prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
  169. $cnt = $this->_kstat($prefix.'drop');
  170. if ($cnt > 0) {
  171. $dev->setDrops($cnt);
  172. }
  173. $cnt = $this->_kstat($prefix.'obytes64');
  174. if ($cnt > 0) {
  175. $dev->setTxBytes($cnt);
  176. }
  177. $cnt = $this->_kstat($prefix.'rbytes64');
  178. if ($cnt > 0) {
  179. $dev->setRxBytes($cnt);
  180. }
  181. $this->sys->setNetDevices($dev);
  182. }
  183. }
  184. }
  185. }
  186. /**
  187. * Physical memory information and Swap Space information
  188. *
  189. * @return void
  190. */
  191. private function _memory()
  192. {
  193. $pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
  194. $this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
  195. $this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
  196. $this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
  197. $dev = new DiskDevice();
  198. $dev->setName('SWAP');
  199. $dev->setFsType('swap');
  200. $dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
  201. $dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
  202. $dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
  203. $this->sys->setSwapDevices($dev);
  204. }
  205. /**
  206. * filesystem information
  207. *
  208. * @return void
  209. */
  210. private function _filesystems()
  211. {
  212. if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
  213. $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
  214. foreach ($mounts as $mount) {
  215. $ar_buf = preg_split('/\s+/', $mount, 6);
  216. $dev = new DiskDevice();
  217. $dev->setName($ar_buf[0]);
  218. $dev->setTotal($ar_buf[1] * 1024);
  219. $dev->setUsed($ar_buf[2] * 1024);
  220. $dev->setFree($ar_buf[3] * 1024);
  221. $dev->setMountPoint($ar_buf[5]);
  222. if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
  223. $mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
  224. foreach ($mounttypes as $type) {
  225. $ty_buf = preg_split('/:/', $type, 2);
  226. if ($ty_buf == $dev->getName()) {
  227. $dev->setFsType($ty_buf[1]);
  228. break;
  229. }
  230. }
  231. }
  232. $this->sys->setDiskDevices($dev);
  233. }
  234. }
  235. }
  236. /**
  237. * Distribution Icon
  238. *
  239. * @return void
  240. */
  241. private function _distro()
  242. {
  243. $this->sys->setDistribution('SunOS');
  244. $this->sys->setDistributionIcon('SunOS.png');
  245. }
  246. /**
  247. * get the information
  248. *
  249. * @see PSI_Interface_OS::build()
  250. *
  251. * @return Void
  252. */
  253. function build()
  254. {
  255. $this->_ip();
  256. $this->_hostname();
  257. $this->_distro();
  258. $this->_kernel();
  259. $this->_uptime();
  260. $this->_users();
  261. $this->_loadavg();
  262. $this->_cpuinfo();
  263. $this->_network();
  264. $this->_memory();
  265. $this->_filesystems();
  266. }
  267. }
  268. ?>