From efc2cbe5e094337a0337ae287c29e73e5e38b114 Mon Sep 17 00:00:00 2001
From: Michael Seevogel <git@michaelseevogel.de>
Date: Wed, 12 Jan 2022 15:21:22 +0100
Subject: [PATCH] clean up and comments changed

---
 install/lib/install.lib.php              | 47 +++++++++++++++++-------
 server/lib/classes/monitor_tools.inc.php | 35 +++++++++++++-----
 2 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php
index 96ff4da0bd..be22aead13 100644
--- a/install/lib/install.lib.php
+++ b/install/lib/install.lib.php
@@ -315,47 +315,66 @@ function get_distname() {
                         swriteln("Operating System: Fedora 33 or compatible\n");
                 //** RHEL 7 and compatible clones
                 } elseif(preg_match('/^(?:7|7\.[0-9]{1,2})$/', $versionid[0])) {
-                        preg_match_all('/([0-9]{1,2})\.?([0-9]{0,2})\.?([0-9]*)/', file_get_contents('/etc/redhat-release'), $centos7_string);
+                        preg_match_all('/([0-9]{1,2})\.?([0-9]{0,2})\.?([0-9]*)/', file_get_contents('/etc/redhat-release'), $centos7_version);
                         $distname = $name[0];
-                        $distver = is_array($centos7_string)? implode('.', array_filter(array($centos7_string[1][0],$centos7_string[2][0],$centos7_string[3][0]),'strlen')) : $version[0];
+                        $distver = is_array($centos7_version)? implode('.', array_filter(array($centos7_version[1][0],$centos7_version[2][0],$centos7_version[3][0]),'strlen')) : $version[0];
                         $distid = 'centos72';
-                        $distbaseid = 'fedora';
-                        swriteln("Operating System: RHEL/CentOS 7 or compatible\n");
-                //** RHEL 8 and compatible clones
+			$distbaseid = 'fedora';
+                        swriteln("Operating System: " . $distname . " " .  $distver . "\n");
+		//** RHEL 8 and compatible clones
                 } elseif(preg_match('/^(?:8|8\.[0-9]{1,2})$/', $versionid[0])) {
                         $distname = $name[0];
                         $distver = $version[0];
                         $distid = 'centos80';
                         $distbaseid = 'fedora';
-                        swriteln("Operating System: RHEL/CentOS 8 or compatible\n");
-                } else {
+                        swriteln("Operating System: " . $prettyname[0] . "\n");
+		} else {
                         $distname = 'Redhat';
                         $distver = 'Unknown';
                         $distid = 'fedora9';
                         $distbaseid = 'fedora';
                         swriteln("Operating System: Redhat or compatible\n");
 		}
-	//** RHEL 6 and compatible clones
-        } elseif(file_exists('/etc/redhat-release') && !file_exists('/etc/os-release')) {
+	//** CentOS 6
+        } elseif(file_exists('/etc/redhat-release') && !file_exists('/etc/os-release') && !file_exists('/etc/els-release')) {
 
                 $content = file_get_contents('/etc/redhat-release');
 
                 if(stristr($content, 'CentOS Linux release 6') || stristr($content, 'CentOS release 6')) {
-                        $distname = 'CentOS';
-                        $distver = 'Unknown';
+                        preg_match_all('/(6\.?([0-9]{0,2})\.?(\s)?([a-zA-Z()]+))$/', $content, $centos6_version);
+                        $distname = 'CentOS Linux';
+                        $distver = is_array($centos6_version)? implode('.', array_filter(array($centos6_version[0][0]),'strlen')) : '6';
                         $distid = 'centos53';
-                        $distbaseid = 'fedora';
-                        swriteln("Operating System: CentOS/RHEL 6 or compatible\n");
+			$distbaseid = 'fedora';
+                        swriteln("Operating System: " . $distname . " " .  $distver . "\n");
+
                 } else {
                         $distname = 'Redhat';
                         $distver = 'Unknown';
                         $distid = 'fedora9';
                         $distbaseid = 'fedora';
-                        swriteln("Operating System: Redhat or compatible\n");
                 }
+	//** CentOS 6 Extended Lifecycle Support by CloudLinux
+        } elseif(file_exists('/etc/redhat-release') && file_exists('/etc/els-release') && !file_exists('/etc/os-release')) {
 
+                $content = file_get_contents('/etc/els-release');
+
+                if(stristr($content, 'CentOS Linux release 6') || stristr($content, 'CentOS release 6')) {
+                        preg_match_all('/(6)\.?([0-9]{0,2})?\.?\s([a-zA-Z(), ]+)?$/', $content, $centos6_version);
+                        $distname = 'CentOS Linux';
+                        $distver = $centos6_version[0][0];
+                        $distid = 'centos53';
+			$distbaseid = 'fedora';
+                        swriteln("Operating System: " . $distname . " " .  $distver . "\n");
+                } else {
+                        $distname = 'Redhat';
+                        $distver = 'Unknown';
+                        $distid = 'fedora9';
+                        $distbaseid = 'fedora';
+                }
         }
 
+
 	//** Gentoo
 	elseif(file_exists('/etc/gentoo-release')) {
 
diff --git a/server/lib/classes/monitor_tools.inc.php b/server/lib/classes/monitor_tools.inc.php
index 258ebd0f72..33eceeb5f4 100644
--- a/server/lib/classes/monitor_tools.inc.php
+++ b/server/lib/classes/monitor_tools.inc.php
@@ -280,7 +280,7 @@ class monitor_tools {
 	elseif(file_exists('/etc/redhat-release') && file_exists('/etc/os-release')) {
 		$content = file_get_contents('/etc/os-release');
 
-		//preg_match('/(?<=PRETTY_NAME=\").+?(?=\")/', $content, $prettyname);
+		preg_match('/(?<=PRETTY_NAME=\").+?(?=\")/', $content, $prettyname);
 		preg_match('/(?<=NAME=\").+?(?=\")/', $content, $name);
                 preg_match('/(?<=VERSION=\").+?(?=\")/', $content, $version);
 		preg_match('/(?<=VERSION_ID=\").+?(?=\")/', $content, $versionid);
@@ -297,9 +297,9 @@ class monitor_tools {
 			$distbaseid = 'fedora';
                 //** RHEL 7 and compatible clones 
 		} elseif(preg_match('/^(?:7|7\.[0-9]{1,2})$/', $versionid[0])) {
-			preg_match_all('/([0-9]{1,2})\.?([0-9]{0,2})\.?([0-9]*)/', file_get_contents('/etc/redhat-release'), $centos7_string);
+			preg_match_all('/([0-9]{1,2})\.?([0-9]{0,2})\.?([0-9]*)/', file_get_contents('/etc/redhat-release'), $centos7_version);
                         $distname = $name[0];
-                        $distver = is_array($centos7_string)? implode('.', array_filter(array($centos7_string[1][0],$centos7_string[2][0],$centos7_string[3][0]),'strlen')) : $version[0];
+                        $distver = is_array($centos7_version)? implode('.', array_filter(array($centos7_version[1][0],$centos7_version[2][0],$centos7_version[3][0]),'strlen')) : $version[0];
                         $distid = 'centos72';
                         $distbaseid = 'fedora';
 		//** RHEL 8 and compatible clones
@@ -314,24 +314,41 @@ class monitor_tools {
 			$distid = 'fedora9';
 			$distbaseid = 'fedora';
 		}
-        //** RHEL 6 and compatible clones
-	} elseif(file_exists('/etc/redhat-release') && !file_exists('/etc/os-release')) {
+        //** CentOS 6
+        } elseif(file_exists('/etc/redhat-release') && !file_exists('/etc/os-release') && !file_exists('/etc/els-release')) {
 
                 $content = file_get_contents('/etc/redhat-release');
 
                 if(stristr($content, 'CentOS Linux release 6') || stristr($content, 'CentOS release 6')) {
-                        $distname = 'CentOS';
-                        $distver = 'Unknown';
+                        preg_match_all('/(6\.?([0-9]{0,2})\.?(\s)?([a-zA-Z()]+))$/', $content, $centos6_version);
+                        $distname = 'CentOS Linux';
+                        $distver = is_array($centos6_version)? implode('.', array_filter(array($centos6_version[0][0]),'strlen')) : '6';
                         $distid = 'centos53';
                         $distbaseid = 'fedora';
-		} else {
+                } else {
                         $distname = 'Redhat';
                         $distver = 'Unknown';
                         $distid = 'fedora9';
                         $distbaseid = 'fedora';
                 }
+        //** CentOS 6 Extended Lifecycle Support by CloudLinux
+        } elseif(file_exists('/etc/redhat-release') && file_exists('/etc/els-release') && !file_exists('/etc/os-release')) {
 
-	}
+                $content = file_get_contents('/etc/els-release');
+
+                if(stristr($content, 'CentOS Linux release 6') || stristr($content, 'CentOS release 6')) {
+                        preg_match_all('/(6)\.?([0-9]{0,2})?\.?\s([a-zA-Z(), ]+)?$/', $content, $centos6_version);
+                        $distname = 'CentOS Linux';
+                        $distver = $centos6_version[0][0];
+                        $distid = 'centos53';
+                        $distbaseid = 'fedora';
+                } else {
+                        $distname = 'Redhat';
+                        $distver = 'Unknown';
+                        $distid = 'fedora9';
+                        $distbaseid = 'fedora';
+                }
+        }
 
 
 
-- 
GitLab