PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/namiltd-ini/includes/os/class.Linux.inc.php

#
PHP | 730 lines | 590 code | 3 blank | 137 comment | 189 complexity | ec09195ff1357ea6c695864bd0a61c9b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Linux 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.Linux.inc.php 713 2012-12-05 16:26:07Z namiltd $
  13. * @link http://phpsysinfo.sourceforge.net
  14. */
  15. /**
  16. * Linux sysinfo class
  17. * get all the required information from Linux system
  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 Linux extends OS
  28. {
  29. /**
  30. * call parent constructor
  31. */
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. }
  36. /**
  37. * Hostname
  38. *
  39. * @return void
  40. */
  41. private function _hostname()
  42. {
  43. if (PSI_USE_VHOST === true) {
  44. $this->sys->setHostname(getenv('SERVER_NAME'));
  45. } else {
  46. if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1)) {
  47. $result = trim($result);
  48. $ip = gethostbyname($result);
  49. if ($ip != $result) {
  50. $this->sys->setHostname(gethostbyaddr($ip));
  51. }
  52. }
  53. }
  54. }
  55. /**
  56. * IP
  57. *
  58. * @return void
  59. */
  60. private function _ip()
  61. {
  62. if (PSI_USE_VHOST === true) {
  63. $this->sys->setIp(gethostbyname($this->sys->getHostname()));
  64. } else {
  65. if (!($result = $_SERVER['SERVER_ADDR'])) {
  66. $this->sys->setIp(gethostbyname($this->sys->getHostname()));
  67. } else {
  68. $this->sys->setIp($result);
  69. }
  70. }
  71. }
  72. /**
  73. * Kernel Version
  74. *
  75. * @return void
  76. */
  77. private function _kernel()
  78. {
  79. if (CommonFunctions::executeProgram('uname', '-r', $strBuf, PSI_DEBUG)) {
  80. $result = trim($strBuf);
  81. if (CommonFunctions::executeProgram('uname', '-v', $strBuf, PSI_DEBUG)) {
  82. if (preg_match('/SMP/', $strBuf)) {
  83. $result .= ' (SMP)';
  84. }
  85. }
  86. if (CommonFunctions::executeProgram('uname', '-m', $strBuf, PSI_DEBUG)) {
  87. $result .= ' '.trim($strBuf);
  88. }
  89. $this->sys->setKernel($result);
  90. } else {
  91. if (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
  92. if (preg_match('/version (.*?) /', $strBuf, $ar_buf)) {
  93. $result = $ar_buf[1];
  94. if (preg_match('/SMP/', $strBuf)) {
  95. $result .= ' (SMP)';
  96. }
  97. $this->sys->setKernel($result);
  98. }
  99. }
  100. }
  101. }
  102. /**
  103. * UpTime
  104. * time the system is running
  105. *
  106. * @return void
  107. */
  108. private function _uptime()
  109. {
  110. CommonFunctions::rfts('/proc/uptime', $buf, 1);
  111. $ar_buf = preg_split('/ /', $buf);
  112. $this->sys->setUptime(trim($ar_buf[0]));
  113. }
  114. /**
  115. * Number of Users
  116. *
  117. * @return void
  118. */
  119. private function _users()
  120. {
  121. if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
  122. if (strlen(trim($strBuf)) > 0) {
  123. $lines = preg_split('/\n/', $strBuf);
  124. $this->sys->setUsers(count($lines));
  125. }
  126. }
  127. }
  128. /**
  129. * Processor Load
  130. * optionally create a loadbar
  131. *
  132. * @return void
  133. */
  134. private function _loadavg()
  135. {
  136. if (CommonFunctions::rfts('/proc/loadavg', $buf)) {
  137. $result = preg_split("/\s/", $buf, 4);
  138. // don't need the extra values, only first three
  139. unset($result[3]);
  140. $this->sys->setLoad(implode(' ', $result));
  141. }
  142. if (PSI_LOAD_BAR) {
  143. $this->sys->setLoadPercent($this->_parseProcStat('cpu'));
  144. }
  145. }
  146. /**
  147. * fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
  148. *
  149. * @param String $cpuline cpu for which load should be meassured
  150. *
  151. * @return Integer
  152. */
  153. private function _parseProcStat($cpuline)
  154. {
  155. $load = 0;
  156. $load2 = 0;
  157. $total = 0;
  158. $total2 = 0;
  159. if (CommonFunctions::rfts('/proc/stat', $buf)) {
  160. $lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
  161. foreach ($lines as $line) {
  162. if (preg_match('/^'.$cpuline.' (.*)/', $line, $matches)) {
  163. $ab = 0;
  164. $ac = 0;
  165. $ad = 0;
  166. $ae = 0;
  167. sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
  168. $load = $ab + $ac + $ad; // cpu.user + cpu.sys
  169. $total = $ab + $ac + $ad + $ae; // cpu.total
  170. break;
  171. }
  172. }
  173. }
  174. // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
  175. if(PSI_LOAD_BAR) {
  176. sleep(1);
  177. }
  178. if (CommonFunctions::rfts('/proc/stat', $buf)) {
  179. $lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
  180. foreach ($lines as $line) {
  181. if (preg_match('/^'.$cpuline.' (.*)/', $line, $matches)) {
  182. $ab = 0;
  183. $ac = 0;
  184. $ad = 0;
  185. $ae = 0;
  186. sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
  187. $load2 = $ab + $ac + $ad;
  188. $total2 = $ab + $ac + $ad + $ae;
  189. break;
  190. }
  191. }
  192. }
  193. if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
  194. return (100 * ($load2 - $load)) / ($total2 - $total);
  195. }
  196. return 0;
  197. }
  198. /**
  199. * CPU information
  200. * All of the tags here are highly architecture dependant.
  201. *
  202. * @return void
  203. */
  204. private function _cpuinfo()
  205. {
  206. if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
  207. $processors = preg_split('/\s?\n\s?\n/', trim($bufr));
  208. foreach ($processors as $processor) {
  209. $dev = new CpuDevice();
  210. $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
  211. foreach ($details as $detail) {
  212. $arrBuff = preg_split('/\s+:\s+/', trim($detail));
  213. if (count($arrBuff) == 2) {
  214. switch (strtolower($arrBuff[0])) {
  215. case 'processor':
  216. if(PSI_LOAD_BAR) {
  217. $dev->setLoad($this->_parseProcStat('cpu'.trim($arrBuff[1])));
  218. }
  219. break;
  220. case 'model name':
  221. case 'cpu':
  222. $dev->setModel($arrBuff[1]);
  223. break;
  224. case 'cpu mhz':
  225. case 'clock':
  226. if ($arrBuff[1] > 0) //openSUSE fix
  227. $dev->setCpuSpeed($arrBuff[1]);
  228. break;
  229. case 'cycle frequency [hz]':
  230. $dev->setCpuSpeed($arrBuff[1] / 1000000);
  231. break;
  232. case 'cpu0clktck':
  233. $dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
  234. break;
  235. case 'l2 cache':
  236. case 'cache size':
  237. $dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
  238. break;
  239. case 'bogomips':
  240. case 'cpu0bogo':
  241. $dev->setBogomips($arrBuff[1]);
  242. break;
  243. case 'flags':
  244. if(preg_match("/ vmx/",$arrBuff[1])) {
  245. $dev->setVirt("vmx");
  246. }
  247. else if(preg_match("/ svm/",$arrBuff[1])) {
  248. $dev->setVirt("svm");
  249. }
  250. break;
  251. }
  252. }
  253. }
  254. // sparc64 specific code follows
  255. // This adds the ability to display the cache that a CPU has
  256. // Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
  257. // Modified by Tom Weustink <freshy98@gmx.net> in 2004
  258. $sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
  259. foreach ($sparclist as $name) {
  260. if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
  261. $dev->setCache(base_convert($buf, 16, 10));
  262. }
  263. }
  264. // sparc64 specific code ends
  265. // XScale detection code
  266. if ($dev->getModel() === "") {
  267. foreach ($details as $detail) {
  268. $arrBuff = preg_split('/\s+:\s+/', trim($detail));
  269. if (count($arrBuff) == 2) {
  270. switch (strtolower($arrBuff[0])) {
  271. case 'processor':
  272. $dev->setModel($arrBuff[1]);
  273. break;
  274. case 'bogomips':
  275. $dev->setCpuSpeed($arrBuff[1]); //BogoMIPS are not BogoMIPS on this CPU, it's the speed
  276. $dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
  277. break;
  278. case 'i size':
  279. case 'd size':
  280. if ($dev->getCache() === null) {
  281. $dev->setCache($arrBuff[1] * 1024);
  282. } else {
  283. $dev->setCache($dev->getCache() + ($arrBuff[1] * 1024));
  284. }
  285. break;
  286. }
  287. }
  288. }
  289. }
  290. if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)) {
  291. $dev->setTemp(substr($buf, 25, 2));
  292. }
  293. if ($dev->getModel() === "") {
  294. $dev->setModel("unknown");
  295. }
  296. $this->sys->setCpus($dev);
  297. }
  298. }
  299. }
  300. /**
  301. * PCI devices
  302. *
  303. * @return void
  304. */
  305. private function _pci()
  306. {
  307. if (!$arrResults = Parser::lspci()) {
  308. if (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
  309. $booDevice = false;
  310. $arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
  311. foreach ($arrBuf as $strLine) {
  312. if (preg_match('/Bus/', $strLine)) {
  313. $booDevice = true;
  314. continue;
  315. }
  316. if ($booDevice) {
  317. list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
  318. if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
  319. $dev = new HWDevice();
  320. $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strValue)));
  321. $this->sys->setPciDevices($dev);
  322. }
  323. $booDevice = false;
  324. }
  325. }
  326. }
  327. } else {
  328. foreach ($arrResults as $dev) {
  329. $this->sys->setPciDevices($dev);
  330. }
  331. }
  332. }
  333. /**
  334. * IDE devices
  335. *
  336. * @return void
  337. */
  338. private function _ide()
  339. {
  340. $bufd = CommonFunctions::gdc('/proc/ide', false);
  341. foreach ($bufd as $file) {
  342. if (preg_match('/^hd/', $file)) {
  343. $dev = new HWDevice();
  344. $dev->setName(trim($file));
  345. if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
  346. if (trim($buf) == 'disk') {
  347. if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
  348. $dev->setCapacity(trim($buf) * 512 / 1024);
  349. }
  350. }
  351. }
  352. if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
  353. $dev->setName($dev->getName().": ".trim($buf));
  354. }
  355. $this->sys->setIdeDevices($dev);
  356. }
  357. }
  358. }
  359. /**
  360. * SCSI devices
  361. *
  362. * @return void
  363. */
  364. private function _scsi()
  365. {
  366. $get_type = false;
  367. $device = null;
  368. if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
  369. $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  370. foreach ($bufe as $buf) {
  371. if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices)) {
  372. $get_type = true;
  373. $device = $devices;
  374. continue;
  375. }
  376. if ($get_type) {
  377. preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
  378. $dev = new HWDevice();
  379. $dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
  380. $this->sys->setScsiDevices($dev);
  381. $get_type = false;
  382. }
  383. }
  384. }
  385. }
  386. /**
  387. * USB devices
  388. *
  389. * @return array
  390. */
  391. private function _usb()
  392. {
  393. $devnum = -1;
  394. if (!CommonFunctions::executeProgram('lsusb', '', $bufr, PSI_DEBUG)) {
  395. if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
  396. $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  397. foreach ($bufe as $buf) {
  398. if (preg_match('/^T/', $buf)) {
  399. $devnum += 1;
  400. $results[$devnum] = "";
  401. } elseif (preg_match('/^S:/', $buf)) {
  402. list($key, $value) = preg_split('/: /', $buf, 2);
  403. list($key, $value2) = preg_split('/=/', $value, 2);
  404. if (trim($key) != "SerialNumber") {
  405. $results[$devnum] .= " ".trim($value2);
  406. }
  407. }
  408. }
  409. foreach ($results as $var) {
  410. $dev = new HWDevice();
  411. $dev->setName($var);
  412. $this->sys->setUsbDevices($dev);
  413. }
  414. }
  415. } else {
  416. $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  417. foreach ($bufe as $buf) {
  418. $device = preg_split("/ /", $buf, 7);
  419. if (isset($device[6]) && trim($device[6]) != "") {
  420. $dev = new HWDevice();
  421. $dev->setName(trim($device[6]));
  422. $this->sys->setUsbDevices($dev);
  423. }
  424. }
  425. }
  426. }
  427. /**
  428. * Network devices
  429. * includes also rx/tx bytes
  430. *
  431. * @return void
  432. */
  433. private function _network()
  434. {
  435. if (CommonFunctions::rfts('/proc/net/dev', $bufr)) {
  436. $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  437. foreach ($bufe as $buf) {
  438. if (preg_match('/:/', $buf)) {
  439. list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
  440. $stats = preg_split('/\s+/', trim($stats_list));
  441. $dev = new NetDevice();
  442. $dev->setName(trim($dev_name));
  443. $dev->setRxBytes($stats[0]);
  444. $dev->setTxBytes($stats[8]);
  445. $dev->setErrors($stats[2] + $stats[10]);
  446. $dev->setDrops($stats[3] + $stats[11]);
  447. if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG))) {
  448. $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
  449. foreach ($bufe2 as $buf2) {
  450. if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S*)/i', $buf2, $ar_buf2))
  451. $dev->setInfo(preg_replace('/:/', '-', $ar_buf2[1]));
  452. else if (preg_match('/^\s+inet\saddr:(\S*)\s+P-t-P:(\S*)/i', $buf2, $ar_buf2)) {
  453. if ($ar_buf2[1] != $ar_buf2[2]) {
  454. $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
  455. } else {
  456. $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
  457. }
  458. }
  459. else if (preg_match('/^\s+inet\saddr:(\S*)/i', $buf2, $ar_buf2))
  460. $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
  461. else if (preg_match('/^\s+inet6\saddr:\s([^\/]*)(.*)\s+Scope:[GH]/i', $buf2, $ar_buf2))
  462. $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
  463. }
  464. }
  465. $this->sys->setNetDevices($dev);
  466. }
  467. }
  468. }
  469. }
  470. /**
  471. * Physical memory information and Swap Space information
  472. *
  473. * @return void
  474. */
  475. private function _memory()
  476. {
  477. if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
  478. $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  479. foreach ($bufe as $buf) {
  480. if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
  481. $this->sys->setMemTotal($ar_buf[1] * 1024);
  482. } elseif (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
  483. $this->sys->setMemFree($ar_buf[1] * 1024);
  484. } elseif (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
  485. $this->sys->setMemCache($ar_buf[1] * 1024);
  486. } elseif (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
  487. $this->sys->setMemBuffer($ar_buf[1] * 1024);
  488. }
  489. }
  490. $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
  491. // values for splitting memory usage
  492. if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) {
  493. $this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
  494. }
  495. if (CommonFunctions::rfts('/proc/swaps', $bufr)) {
  496. $swaps = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
  497. unset($swaps[0]);
  498. foreach ($swaps as $swap) {
  499. $ar_buf = preg_split('/\s+/', $swap, 5);
  500. $dev = new DiskDevice();
  501. $dev->setMountPoint($ar_buf[0]);
  502. $dev->setName("SWAP");
  503. $dev->setTotal($ar_buf[2] * 1024);
  504. $dev->setUsed($ar_buf[3] * 1024);
  505. $dev->setFree($dev->getTotal() - $dev->getUsed());
  506. $this->sys->setSwapDevices($dev);
  507. }
  508. }
  509. }
  510. }
  511. /**
  512. * filesystem information
  513. *
  514. * @return void
  515. */
  516. private function _filesystems()
  517. {
  518. $arrResult = Parser::df("-P 2>/dev/null");
  519. foreach ($arrResult as $dev) {
  520. $this->sys->setDiskDevices($dev);
  521. }
  522. }
  523. /**
  524. * Distribution
  525. *
  526. * @return void
  527. */
  528. private function _distro()
  529. {
  530. $this->sys->setDistribution("Linux");
  531. $list = @parse_ini_file(APP_ROOT."/data/distros.ini", true);
  532. if (!$list) {
  533. return;
  534. }
  535. // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
  536. if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG)) {
  537. $distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
  538. foreach ($distro_tmp as $info) {
  539. $info_tmp = preg_split('/:/', $info, 2);
  540. if ( isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") &&
  541. isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "") ) {
  542. $distro[$info_tmp[0]] = trim($info_tmp[1]);
  543. }
  544. }
  545. if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) {
  546. if ( !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") ) {
  547. $this->sys->setDistribution(trim($distro_tmp[0]));
  548. if ( preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
  549. && isset($list[trim($id_buf[1])]['Image'])) {
  550. $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
  551. }
  552. }
  553. } else {
  554. if (isset($distro['Description'])) {
  555. $this->sys->setDistribution($distro['Description']);
  556. } else if (isset($distro['Distributor ID'])) {
  557. $this->sys->setDistribution($distro['Distributor ID']);
  558. }
  559. if (isset($distro['Distributor ID']) && isset($list[$distro['Distributor ID']]['Image'])) {
  560. $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
  561. }
  562. }
  563. } else {
  564. /* default error handler */
  565. if (function_exists('errorHandlerPsi')) {
  566. restore_error_handler();
  567. }
  568. /* fatal errors only */
  569. $old_err_rep = error_reporting();
  570. error_reporting(E_ERROR);
  571. // Fall back in case 'lsb_release' does not exist
  572. foreach ($list as $section=>$distribution) {
  573. if (!isset($distribution['Files'])) {
  574. continue;
  575. } else {
  576. foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
  577. if (file_exists($filename)) {
  578. if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
  579. $buf = "";
  580. }
  581. if (isset($distribution['Image'])) {
  582. $this->sys->setDistributionIcon($distribution['Image']);
  583. }
  584. if (isset($distribution['Name'])) {
  585. if (($distribution['Name'] == 'Synology') || is_null($buf) || (trim($buf) == "")) {
  586. $this->sys->setDistribution($distribution['Name']);
  587. } else {
  588. $this->sys->setDistribution($distribution['Name']." ".trim($buf));
  589. }
  590. } else {
  591. if ( is_null($buf) || (trim($buf) == "") ) {
  592. $this->sys->setDistribution($section);
  593. } else {
  594. $this->sys->setDistribution(trim($buf));
  595. }
  596. }
  597. break 2;
  598. }
  599. }
  600. }
  601. }
  602. // Otherwise, if no files found
  603. if ($this->sys->getDistribution() == "Linux") {
  604. if ( file_exists($filename="/etc/lsb-release")
  605. && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
  606. && preg_match('/^DISTRIB_ID="?([^"\n]*)"?/m', $buf, $id_buf) ) {
  607. if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]*)"?/m', $buf, $desc_buf)) {
  608. $this->sys->setDistribution(trim($desc_buf[1]));
  609. } else {
  610. if (isset($list[trim($id_buf[1])]['Name'])) {
  611. $dist = trim($list[trim($id_buf[1])]['Name']);
  612. } else {
  613. $dist = trim($id_buf[1]);
  614. }
  615. if (preg_match('/^DISTRIB_RELEASE="?([^"\n]*)"?/m', $buf, $vers_buf)) {
  616. $this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
  617. } else {
  618. $this->sys->setDistribution($dist);
  619. }
  620. }
  621. if (isset($list[trim($id_buf[1])]['Image'])) {
  622. $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
  623. }
  624. } else
  625. if ( file_exists($filename="/etc/DISTRO_SPECS")
  626. && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
  627. && preg_match('/^DISTRO_NAME=\'(.*)\'/m', $buf, $id_buf) ) {
  628. if (isset($list[trim($id_buf[1])]['Name'])) {
  629. $dist = trim($list[trim($id_buf[1])]['Name']);
  630. } else {
  631. $dist = trim($id_buf[1]);
  632. }
  633. if (preg_match('/^DISTRO_VERSION=(.*)/m', $buf, $vers_buf)) {
  634. $this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
  635. } else {
  636. $this->sys->setDistribution($dist);
  637. }
  638. if (isset($list[trim($id_buf[1])]['Image'])) {
  639. $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
  640. } else {
  641. if (isset($list['Puppy']['Image'])) {
  642. $this->sys->setDistributionIcon($list['Puppy']['Image']);
  643. }
  644. }
  645. } else
  646. if (file_exists($filename="/etc/redhat-release")) {
  647. if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
  648. $buf = "";
  649. }
  650. if ( is_null($buf) || (trim($buf) == "") ) {
  651. if (isset($list['RedHat']['Name'])) {
  652. $this->sys->setDistribution(trim($list['RedHat']['Name']));
  653. } else {
  654. $this->sys->setDistribution('RedHat');
  655. }
  656. if (isset($list['RedHat']['Image'])) {
  657. $this->sys->setDistributionIcon($list['RedHat']['Image']);
  658. }
  659. } else {
  660. $this->sys->setDistribution(trim($buf));
  661. if ( preg_match('/^(\S+)\s*/', $buf, $id_buf)
  662. && isset($list[trim($id_buf[1])]['Image'])) {
  663. $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
  664. } else {
  665. if (isset($list['RedHat']['Image'])) {
  666. $this->sys->setDistributionIcon($list['RedHat']['Image']);
  667. }
  668. }
  669. }
  670. } else
  671. if (file_exists($filename="/etc/debian_version")){
  672. if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
  673. $buf = "";
  674. }
  675. if (isset($list['Debian']['Image'])) {
  676. $this->sys->setDistributionIcon($list['Debian']['Image']);
  677. }
  678. if (isset($list['Debian']['Name'])) {
  679. if ( is_null($buf) || (trim($buf) == "")) {
  680. $this->sys->setDistribution($list['Debian']['Name']);
  681. } else {
  682. $this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
  683. }
  684. } else {
  685. if ( is_null($buf) || (trim($buf) == "") ) {
  686. $this->sys->setDistribution('Debian');
  687. } else {
  688. $this->sys->setDistribution(trim($buf));
  689. }
  690. }
  691. }
  692. }
  693. /* restore error level */
  694. error_reporting($old_err_rep);
  695. /* restore error handler */
  696. if (function_exists('errorHandlerPsi')) {
  697. set_error_handler('errorHandlerPsi');
  698. }
  699. }
  700. }
  701. /**
  702. * get the information
  703. *
  704. * @see PSI_Interface_OS::build()
  705. *
  706. * @return Void
  707. */
  708. function build()
  709. {
  710. $this->_distro();
  711. $this->_hostname();
  712. $this->_ip();
  713. $this->_kernel();
  714. $this->_uptime();
  715. $this->_users();
  716. $this->_cpuinfo();
  717. $this->_pci();
  718. $this->_ide();
  719. $this->_scsi();
  720. $this->_usb();
  721. $this->_network();
  722. $this->_memory();
  723. $this->_filesystems();
  724. $this->_loadavg();
  725. }
  726. }
  727. ?>