From 67d74406bdf7348a9fb2c4e0b1b8907ef536cb15 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 13:36:31 +0200 Subject: [PATCH] add os distribution detection --- install/lib/class.FroxlorInstall.php | 70 +++++++++++++++++++++++++--- install/lng/english.lng.php | 9 ++++ install/lng/french.lng.php | 9 ++++ install/lng/german.lng.php | 9 ++++ install/templates/dataitemchk.tpl | 4 +- 5 files changed, 93 insertions(+), 8 deletions(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 33dc8434..27854ad3 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -159,6 +159,7 @@ class FroxlorInstall $this->_guessServerName(); $this->_guessServerIP(); $this->_guessWebserver(); + $this->_guessDistribution(); $this->_getPostField('mysql_host', '127.0.0.1'); $this->_getPostField('mysql_database', 'froxlor'); @@ -840,6 +841,20 @@ class FroxlorInstall */ $section = $this->_lng['install']['serversettings']; eval("\$formdata .= \"" . $this->_getTemplate("datasection") . "\";"); + // distribution + if (! empty($_POST['installstep']) && $this->_data['distribution'] == '') { + $diststyle = 'color:red;'; + } else { + $diststyle = ''; + } + $formdata .= $this->_GETsectionItemCheckbox('distribution', 'jessie', ($this->_data['distribution'] == 'jessie'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'stretch', ($this->_data['distribution'] == 'stretch'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'buster', ($this->_data['distribution'] == 'buster'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'xenial', ($this->_data['distribution'] == 'xenial'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'bionic', ($this->_data['distribution'] == 'bionic'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'focal', ($this->_data['distribution'] == 'focal'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel7', ($this->_data['distribution'] == 'rhel7'), $diststyle); + $formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel8', ($this->_data['distribution'] == 'rhel8'), $diststyle); // servername if (! empty($_POST['installstep']) && $this->_data['servername'] == '') { $style = 'color:red;'; @@ -861,12 +876,12 @@ class FroxlorInstall $websrvstyle = ''; } // apache - $formdata .= $this->_getSectionItemCheckbox('apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle); - $formdata .= $this->_getSectionItemCheckbox('apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle); + $formdata .= $this->_getSectionItemCheckbox('webserver', 'apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle); + $formdata .= $this->_getSectionItemCheckbox('webserver', 'apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle); // lighttpd - $formdata .= $this->_getSectionItemCheckbox('lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle); + $formdata .= $this->_getSectionItemCheckbox('webserver', 'lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle); // nginx - $formdata .= $this->_getSectionItemCheckbox('nginx', ($this->_data['webserver'] == 'nginx'), $websrvstyle); + $formdata .= $this->_getSectionItemCheckbox('webserver', 'NGINx', ($this->_data['webserver'] == 'nginx'), $websrvstyle); // webserver-user if (! empty($_POST['installstep']) && $this->_data['httpuser'] == '') { $style = 'color:red;'; @@ -918,7 +933,7 @@ class FroxlorInstall } /** - * generate form radio field for webserver-selection + * generate form radio field * * @param string $fieldname * @param boolean $checked @@ -926,8 +941,9 @@ class FroxlorInstall * * @return string */ - private function _getSectionItemCheckbox($fieldname = null, $checked = false, $style = "") + private function _getSectionItemCheckbox($groupname = null, $fieldname = null, $checked = false, $style = "") { + $groupname = $this->_lng['install'][$groupname]; $fieldlabel = $this->_lng['install'][$fieldname]; if ($checked) { $checked = 'checked="checked"'; @@ -1273,6 +1289,48 @@ class FroxlorInstall } } + + /** + * get/guess linux distribution + */ + private function _guessDistribution() + { + // post + if (! empty($_POST['distribution'])) { + $this->_data['distribution'] = $_POST['distribution']; + } else { + $os_version = parse_ini_file('/etc/os-release', false); + if ($os_version['ID'] == 'debian') { + + } elseif ($os_version['ID'] == 'debian') { + if(explode('.',$os_version['VERSION_ID'])[0] == '8') { + $this->_data['distribution'] = 'jessie'; + } elseif(explode('.',$os_version['VERSION_ID'])[0] == '9') { + $this->_data['distribution'] = 'stretch'; + } elseif(explode('.',$os_version['VERSION_ID'])[0] == '10') { + $this->_data['distribution'] = 'buster'; + } + } elseif ($os_version['ID'] == 'ubuntu') { + if(explode('.',$os_version['VERSION_ID'])[0] == '16') { + $this->_data['distribution'] = 'xenial'; + } elseif(explode('.',$os_version['VERSION_ID'])[0] == '18') { + $this->_data['distribution'] = 'bionic'; + } elseif(explode('.',$os_version['VERSION_ID'])[0] == '20') { + $this->_data['distribution'] = 'focal'; + } + } elseif($os_version['ID'] == 'rhel' || $os_version['ID'] == 'centos' || $os_version['ID'] == 'fedora') { + if(explode('.',$os_version['VERSION_ID'])[0] == '7') { + $this->_data['distribution'] = 'rhel7'; + } elseif(explode('.',$os_version['VERSION_ID'])[0] == '8') { + $this->_data['distribution'] = 'rhel8'; + } + } else { + // we don't need to bail out, since unknown does not affect any critical installation routines + $this->_data['distribution'] = 'unknown'; + } + } + } + /** * check if POST field is set and get value for the * internal data array, if not set use either '' or $default if != null diff --git a/install/lng/english.lng.php b/install/lng/english.lng.php index e5e6b9cb..0b04e3c1 100644 --- a/install/lng/english.lng.php +++ b/install/lng/english.lng.php @@ -63,6 +63,15 @@ $lng['install']['admin_pass1'] = 'Administrator Password'; $lng['install']['admin_pass2'] = 'Administrator-Password (confirm)'; $lng['install']['activate_newsfeed'] = 'Enable the official newsfeed
(https://inside.froxlor.org/news/)'; $lng['install']['serversettings'] = 'Server settings'; +$lng['install']['distribution'] = 'Distribution'; +$lng['install']['jessie'] = 'Debian Jessie'; +$lng['install']['stretch'] = 'Debian Stretch'; +$lng['install']['buster'] = 'Debian Buster'; +$lng['install']['xenial'] = 'Ubuntu Xenial'; +$lng['install']['bionic'] = 'Ubuntu Bionic'; +$lng['install']['focal'] = 'Ubuntu Focal'; +$lng['install']['rhel7'] = 'RHEL 7'; +$lng['install']['rhel8'] = 'RHEL 8'; $lng['install']['servername'] = 'Server name (FQDN, no ip-address)'; $lng['install']['serverip'] = 'Server IP'; $lng['install']['webserver'] = 'Webserver'; diff --git a/install/lng/french.lng.php b/install/lng/french.lng.php index 42ab1d7b..2eb6cb96 100644 --- a/install/lng/french.lng.php +++ b/install/lng/french.lng.php @@ -53,6 +53,15 @@ $lng['install']['admin_user'] = 'Nom d\'utilisateur administrateur'; $lng['install']['admin_pass1'] = 'Mot de passe administrateur'; $lng['install']['admin_pass2'] = 'Mot de passe administrateur (confirmez)'; $lng['install']['serversettings'] = 'Réglages serveur'; +$lng['install']['distribution'] = 'Distribution'; +$lng['install']['jessie'] = 'Debian Jessie'; +$lng['install']['stretch'] = 'Debian Stretch'; +$lng['install']['buster'] = 'Debian Buster'; +$lng['install']['xenial'] = 'Ubuntu Xenial'; +$lng['install']['bionic'] = 'Ubuntu Bionic'; +$lng['install']['focal'] = 'Ubuntu Focal'; +$lng['install']['rhel7'] = 'RHEL 7'; +$lng['install']['rhel8'] = 'RHEL 8'; $lng['install']['servername'] = 'Nom du serveur (FQDN, pas d\'adresse IP)'; $lng['install']['serverip'] = 'Adresse IP du serveur'; $lng['install']['webserver'] = 'Serveur Web'; diff --git a/install/lng/german.lng.php b/install/lng/german.lng.php index 64b462b4..24554712 100644 --- a/install/lng/german.lng.php +++ b/install/lng/german.lng.php @@ -63,6 +63,15 @@ $lng['install']['admin_pass1'] = 'Administrator-Passwort'; $lng['install']['admin_pass2'] = 'Administrator-Passwort (Bestätigung)'; $lng['install']['activate_newsfeed'] = 'Aktiviere das offizielle Newsfeed
(https://inside.froxlor.org/news/)'; $lng['install']['serversettings'] = 'Servereinstellungen'; +$lng['install']['distribution'] = 'Verteilung'; +$lng['install']['jessie'] = 'Debian Jessie'; +$lng['install']['stretch'] = 'Debian Stretch'; +$lng['install']['buster'] = 'Debian Buster'; +$lng['install']['xenial'] = 'Ubuntu Xenial'; +$lng['install']['bionic'] = 'Ubuntu Bionic'; +$lng['install']['focal'] = 'Ubuntu Focal'; +$lng['install']['rhel7'] = 'RHEL 7'; +$lng['install']['rhel8'] = 'RHEL 8'; $lng['install']['servername'] = 'Servername (FQDN, keine IP-Adresse)'; $lng['install']['serverip'] = 'Server-IP'; $lng['install']['webserver'] = 'Webserver'; diff --git a/install/templates/dataitemchk.tpl b/install/templates/dataitemchk.tpl index 30279bfa..46c90d1c 100644 --- a/install/templates/dataitemchk.tpl +++ b/install/templates/dataitemchk.tpl @@ -1,4 +1,4 @@

- - {$fieldlabel} + + {$fieldlabel}