commit f427787116cbef36974760e367dd5d6a9d00d8d7
parent 30279b9bd0bb7c9abab5db5fa4f6e5fef038b587
Author: Felicitus <felicitus@felicitus.org>
Date: Sun, 1 Jan 2012 19:15:54 +0100
Added a better detection for operating system and release
Diffstat:
2 files changed, 102 insertions(+), 24 deletions(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/System/SystemService.php b/src/backend/de/RaumZeitLabor/PartKeepr/System/SystemService.php
@@ -1,16 +1,12 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\System;
-use de\RaumZeitLabor\PartKeepr\Session\SessionManager;
-
-use de\RaumZeitLabor\PartKeepr\Service\AnonService;
-
-use de\RaumZeitLabor\PartKeepr\Service\RestfulService;
declare(encoding = 'UTF-8');
-use de\RaumZeitLabor\PartKeepr\Service\Service;
-use de\RaumZeitLabor\PartKeepr\PartKeepr;
-use de\RaumZeitLabor\PartKeepr\CronLogger\CronLoggerManager;
+use de\RaumZeitLabor\PartKeepr\Service\Service,
+ de\RaumZeitLabor\PartKeepr\PartKeepr,
+ de\RaumZeitLabor\PartKeepr\CronLogger\CronLoggerManager,
+ de\RaumZeitLabor\PartKeepr\Util\OS\OperatingSystem;
class SystemService extends Service {
/**
@@ -22,27 +18,15 @@ class SystemService extends Service {
public function getSystemInformation () {
$aData = array();
-
$aData[] = new SystemInformationRecord("Doctrine ORM", \Doctrine\ORM\Version::VERSION, "Libraries");
$aData[] = new SystemInformationRecord("Doctrine DBAL", \Doctrine\DBAL\Version::VERSION, "Libraries");
- $aData[] = new SystemInformationRecord("PHP", phpversion(), "System");
- $aData[] = new SystemInformationRecord("Operating System", php_uname(), "System");
+ $aData[] = new SystemInformationRecord("PHP Version", phpversion(), "System");
- if (file_exists("/etc/lsb-release")) {
- // Quick'n'dirty extract of the release information
- $aReleaseData = explode("\n", file_get_contents("/etc/lsb-release"));
-
- foreach ($aReleaseData as $releaseData) {
- if (strpos($releaseData, "DISTRIB_ID") !== false) {
- $data = explode("\"", $releaseData);
- $aData[] = new SystemInformationRecord("Distribution", $data[1], "System");
- }
- }
-
-
- }
+ $os = new OperatingSystem();
+ $aData[] = new SystemInformationRecord("Operating System Type", $os->getPlatform(), "System");
+ $aData[] = new SystemInformationRecord("Operating System Release", $os->getRelease(), "System");
$aData[] = new SystemInformationRecord("memory_limit", ini_get("memory_limit"), "PHP");
$aData[] = new SystemInformationRecord("post_max_size", ini_get("post_max_size"), "PHP");
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Util/OS/OperatingSystem.php b/src/backend/de/RaumZeitLabor/PartKeepr/Util/OS/OperatingSystem.php
@@ -0,0 +1,94 @@
+<?php
+namespace de\RaumZeitLabor\PartKeepr\Util\OS;
+
+class OperatingSystem {
+ /**
+ * Returns the platform name the system is running on.
+ *
+ * Typical return values are: "Linux", "FreeBSD", "Darwin" (Mac OSX),
+ * "Windows".
+ */
+ public function getPlatform () {
+ if (function_exists("posix_uname")) {
+ $data = posix_uname();
+
+ if (array_key_exists("sysname", $data)) {
+ return $data["sysname"];
+ }
+ }
+
+ if (\PHP_OS == "WINNT") {
+ return "Windows";
+ }
+
+ return "unknown";
+ }
+
+ /**
+ * Returns the distribution
+ * @return string string
+ */
+ public function getRelease () {
+ switch (strtolower($this->getPlatform())) {
+ case "freebsd":
+ /**
+ * Unfortunately, there's no text file on FreeBSD which tells us the release
+ * number. Thus, we hope that "release" within posix_uname() is defined.
+ */
+ if (function_exists("posix_uname")) {
+ $data = posix_uname();
+
+ if (array_key_exists("release", $data)) {
+ return $data["release"];
+ }
+ }
+ break;
+ case "darwin":
+ /**
+ * Mac stores its version number in a public readable plist file, which
+ * is in XML format.
+ */
+ $document = new \DomDocument();
+ $document->load("/System/Library/CoreServices/SystemVersion.plist");
+ $xpath = new \DOMXPath($document);
+ $entries = $xpath->query("/plist/dict/*");
+
+ $previous = "";
+ foreach ($entries as $entry) {
+ if (strpos($previous, "ProductVersion") !== false) {
+ return $entry->textContent;
+ }
+ $previous = $entry->textContent;
+ }
+ break;
+ case "linux":
+ return $this->getLinuxDistribution();
+ break;
+ default:
+ break;
+ }
+
+ return "unknown";
+ }
+
+ /**
+ * Tries to detect the distribution.
+ *
+ * Currently, we only execute lsb_release to find out the version number.
+ * As I don't have any other distributions at hand to test with, I rely
+ * on user feedback which distributions don't have lsb_release.
+ */
+ public function getLinuxDistribution () {
+ /* Try executing lsb_release */
+ $release = @exec('lsb_release -d -s', $void, $retval);
+
+ if ($retval === 0 && $release !== "")
+ {
+ return $release;
+ }
+
+ //@todo we need better handling here
+ return "unknown";
+ }
+
+}