SysteminfoController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. class SysteminfoController
  3. {
  4. public static function Run ($argv)
  5. {
  6. $infoCtrl = new SysteminfoController();
  7. echo implode("\r\n", $infoCtrl->Info()) . "\r\n";
  8. }
  9. private $patterns;
  10. public function __construct ()
  11. {
  12. $this->patterns = array(
  13. 'Computername' => '/Hostname:\s+([^\n\r]*)/im',
  14. 'Domaene' => '/Dom.ne:\s+([^\n\r]*)/im',
  15. 'IP-Adresse' => '/(LAN-Verbindung|Ethernet\s?\d|Local Area)[^[]*\[01\]:\s([\d\.]+)/im',
  16. 'System' => '/Betriebssystemname:\s+([^\n\r]*)/im',
  17. 'Build' => '/Betriebssystemversion:\s+([^\n\r]*)/im',
  18. 'Installation' => '/Installationsdatum:\s+([^\n\r]*)/im',
  19. 'Prozessor' => '/Prozessor\(en\):[^\[]*\[01\]:\s([^\n\r]+)/im',
  20. 'RAM gesamt' => '/ter physikalischer Speicher:\s+([^\n\r]*)/im',
  21. 'RAM frei' => '/gbarer physikalischer Speicher:\s+([^\n\r]*)/im',
  22. 'Laufzeit' => '/System\w+zeit:\s+([^\n\r]*)/im'
  23. );
  24. }
  25. public function Info ()
  26. {
  27. $systemLog = dirname(__FILE__) . "/../../../logs/system.info.log";
  28. if (file_exists($systemLog) && filemtime($systemLog) + 23 * 60 * 60 > strtotime("now")) {
  29. $output = file_get_contents($systemLog);
  30. } else {
  31. $output = array();
  32. exec("systeminfo", $output);
  33. $output = implode("\r\n", $output);
  34. file_put_contents($systemLog, $output);
  35. }
  36. $result = array();
  37. $match = array();
  38. foreach ($this->patterns as $name => $p) {
  39. if (preg_match($p, $output, $match)) {
  40. $value = array_pop($match);
  41. $value = str_replace("\xA9", '', $value);
  42. if ($name == "Laufzeit" && preg_match('/(\d+)\.(\d+)\.(\d+), (\d+):(\d+):(\d+)/', $value, $match)) {
  43. $time = strtotime("now") - mktime($match[4], $match[5], $match[6], $match[2], $match[1], $match[3]);
  44. $days = floor($time / (24 * 60 * 60));
  45. $time -= $days * 24 * 60 * 60;
  46. $hours = floor($time / (60 * 60));
  47. $time -= $hours * 60 * 60;
  48. $minutes = $time / 60;
  49. $value .= sprintf(" (%d Tage, %d Stunden, %d Minuten)", $days, $hours, $minutes);
  50. }
  51. $result[] = str_pad($name.":", 15) . $value;
  52. }
  53. }
  54. $disk = substr(dirname(__FILE__), 0, 2);
  55. $result[] = str_pad("Festplatte " . $disk, 15) . $this->HumanSize(disk_free_space($disk)) . " frei";
  56. return $result;
  57. }
  58. private function HumanSize($bytes)
  59. {
  60. $type = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  61. $index = 0;
  62. while($bytes >= 1024)
  63. {
  64. $bytes /= 1024;
  65. $index++;
  66. }
  67. return("" . number_format($bytes, 2, ",", "") . " " . $type[$index]);
  68. }
  69. }