PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/dryden/sys/versions.class.php

https://github.com/raiman264/zpanelx
PHP | 185 lines | 81 code | 12 blank | 92 comment | 26 complexity | bd3df601588a5eeb13788c0a41b4858b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, LGPL-2.1, CC-BY-SA-4.0, GPL-3.0
  1. <?php
  2. /**
  3. * This reports on core zpanel software versions.
  4. * @package zpanelx
  5. * @subpackage dryden -> sys
  6. * @version 1.0.0
  7. * @author Bobby Allen (ballen@bobbyallen.me)
  8. * @copyright ZPanel Project (http://www.zpanelcp.com/)
  9. * @link http://www.zpanelcp.com/
  10. * @license GPL (http://www.gnu.org/licenses/gpl.html)
  11. */
  12. class sys_versions {
  13. /**
  14. * Returns the Apache HTTPd Server Version Number
  15. * @author Bobby Allen (ballen@bobbyallen.me)
  16. * @return string Apache Server version number.
  17. */
  18. static function ShowApacheVersion() {
  19. if (preg_match('|Apache\/(\d+)\.(\d+)\.(\d+)|', apache_get_version(), $apachever)) {
  20. $retval = str_replace("Apache/", "", $apachever[0]);
  21. } else {
  22. $retval = "Not found";
  23. }
  24. return $retval;
  25. }
  26. /**
  27. * Returns the PHP version number.
  28. * @author Bobby Allen (ballen@bobbyallen.me)
  29. * @return string PHP version number
  30. */
  31. static function ShowPHPVersion() {
  32. return phpversion();
  33. }
  34. /**
  35. * Returns the MySQL server version number.
  36. * @author Bobby Allen (ballen@bobbyallen.me)
  37. * @return string MySQL version number
  38. */
  39. static function ShowMySQLVersion() {
  40. global $zdbh;
  41. $retval = $zdbh->query("SHOW VARIABLES LIKE \"version\"")->Fetch();
  42. return $retval['Value'];
  43. }
  44. /**
  45. * Returns a human readable copy of the Kernal version number running on the server.
  46. * @author Bobby Allen (ballen@bobbyallen.me)
  47. * @param string $platform The OS Platform (eg. Linux or Windows)
  48. * @return string *NIX kernal version. - Will return 'N/A' for Microsoft Windows.
  49. */
  50. static function ShowOSKernalVersion($platform) {
  51. if ($platform == 'Linux') {
  52. $retval = exec('uname -r');
  53. } else {
  54. $retval = "N/A";
  55. }
  56. return $retval;
  57. }
  58. /**
  59. * Returns in human readable form the operating system platform (eg. Windows, Linux, FreeBSD, Other)
  60. * @author Bobby Allen (ballen@bobbyallen.me)
  61. * @return string Human readable OS Platform name.
  62. */
  63. static function ShowOSPlatformVersion() {
  64. $os_abbr = strtoupper(substr(PHP_OS, 0, 3));
  65. if ($os_abbr == "WIN") {
  66. $retval = "Windows";
  67. } elseif ($os_abbr == "LIN") {
  68. $retval = "Linux";
  69. } elseif ($os_abbr == "FRE") {
  70. $retval = "FreeBSD";
  71. } elseif ($os_abbr == "DAR") {
  72. $retval = "MacOSX";
  73. } else {
  74. $retval = "Other";
  75. }
  76. return $retval;
  77. }
  78. /**
  79. * Returns in human readable form the operating system name (eg. Windows, Ubuntu, CentOS, MacOSX, FreeBSD, Other)
  80. * @author Bobby Allen (ballen@bobbyallen.me)
  81. * @return string Human readable OS name.
  82. */
  83. static function ShowOSName() {
  84. preg_match_all("#(?<=\()(.*?)(?=\))#", $_SERVER['SERVER_SOFTWARE'], $osname);
  85. if (!empty($osname)) {
  86. if (strtoupper(substr($osname[0][0], 0, 3)) == "WIN") {
  87. $retval = "Windows";
  88. } else {
  89. $retval = $osname[0][0];
  90. if ($retval == "Unix") {
  91. // Lets just make sure it isn't MacOSX before we give up!
  92. if (sys_versions::ShowOSPlatformVersion() == "MacOSX") {
  93. $retval = "MacOSX";
  94. }
  95. }
  96. }
  97. //My testing shows Linux shows correct OS, WindowsXP=Win32, Windows2007/Server=WINNT -russ
  98. /*
  99. $uname = strtolower(php_uname());
  100. $retval = "";
  101. if (strpos($uname, "darwin") !== false) {
  102. $retval = "MacOSX";
  103. } else if (strpos($uname, "win") !== false) {
  104. $retval = "Windows";
  105. } else if (strpos($uname, "freebsd") !== false) {
  106. $retval = "FreeBSD";
  107. } else if (strpos($uname, "openbsd") !== false) {
  108. $retval = "OpenBSD";
  109. } else {
  110. */
  111. /**
  112. * @todo convert the bottom bit to read from a list of OS's.
  113. */
  114. /*
  115. $list = @parse_ini_file("lib/zpanel/os.ini", true);
  116. foreach ($list as $section => $distribution) {
  117. if (!isset($distribution["Files"])) {
  118. } else {
  119. $intBytes = 4096;
  120. $intLines = 0;
  121. $intCurLine = 0;
  122. $strFile = "";
  123. foreach (preg_split("/;/", $distribution["Files"], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
  124. if (file_exists($filename)) {
  125. if (isset($distribution["Name"])) {
  126. $os = $distribution["Name"];
  127. }
  128. }
  129. }
  130. if ($os == null) {
  131. $os = "Unknown";
  132. }
  133. }
  134. }
  135. */
  136. } else {
  137. $retval = "Unknown";
  138. }
  139. return $retval;
  140. }
  141. /**
  142. * Returns in human readable form the version of perl installed.
  143. * @author Bobby Allen (ballen@bobbyallen.me)
  144. * @return string Human readable Perl version number.
  145. */
  146. static function ShowPerlVersion() {
  147. ob_start();
  148. passthru("perl -v", $result);
  149. $content_grabbed = ob_get_contents();
  150. ob_end_clean();
  151. if (self::ShowOSPlatformVersion() == "Windows") {
  152. preg_match_all("#(?<=\()(.*?)(?=\))#", $content_grabbed, $perlversion);
  153. } else {
  154. preg_match_all("#(\d+).(\d+).(\d+)#", $content_grabbed, $perlversion);
  155. }
  156. if (!empty($perlversion[0]) && !empty($perlversion[0][0])) {
  157. $retval = str_replace("v", "", $perlversion[0][0]);
  158. } else {
  159. $retval = "Perl not available";
  160. }
  161. return $retval;
  162. }
  163. /**
  164. * Returns the ZPanel version (based on the DB version number.)
  165. * @author Bobby Allen (ballen@bobbyallen.me)
  166. * @return string ZPanel DB Version
  167. */
  168. static function ShowZpanelVersion() {
  169. return ctrl_options::GetSystemOption('dbversion');
  170. }
  171. }
  172. ?>