From 67d74406bdf7348a9fb2c4e0b1b8907ef536cb15 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 13:36:31 +0200 Subject: [PATCH 01/14] 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}

From 0bb48a3cdff529a54ae3a1829bb36d1a990b4203 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 13:45:46 +0200 Subject: [PATCH 02/14] fix nginx capitalisation. --- install/lib/class.FroxlorInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 27854ad3..cf583d31 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -881,7 +881,7 @@ class FroxlorInstall // lighttpd $formdata .= $this->_getSectionItemCheckbox('webserver', 'lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle); // nginx - $formdata .= $this->_getSectionItemCheckbox('webserver', '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;'; From 022ed1a9a8c3ab2ba70c72a126948cc45c927deb Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 14:59:40 +0200 Subject: [PATCH 03/14] add setting defaults per distribution when given --- install/lib/class.FroxlorInstall.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index cf583d31..f0ed0e53 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -505,6 +505,15 @@ class FroxlorInstall $this->_updateSetting($upd_stmt, 'error', 'system', 'errorlog_level'); } + if (file_exists(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml')) { + $xml = simplexml_load_file(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml'); + foreach($xml->distribution->defaults->propery as $property) { + $this->_updateSetting($upd_stmt, $property->value[0], $property->group[0], $property->name[0]); + } + } else { + exit('Failed to open distribution XML file.'); + } + $this->_updateSetting($upd_stmt, $this->_data['activate_newsfeed'], 'admin', 'show_news_feed'); $this->_updateSetting($upd_stmt, dirname(dirname(dirname(__FILE__))), 'system', 'letsencryptchallengepath'); From 498ff15e988aeebfd26160f254efd936e704e798 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 14:59:48 +0200 Subject: [PATCH 04/14] add redhat defaults --- lib/configfiles/rhel7.xml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/configfiles/rhel7.xml b/lib/configfiles/rhel7.xml index 29c92104..c95388f1 100644 --- a/lib/configfiles/rhel7.xml +++ b/lib/configfiles/rhel7.xml @@ -2,6 +2,38 @@ + + + apacheconf_vhost + system + /etc/httpd/conf.d/ + + + apacheconf_diroptions + system + /etc/httpd/conf.d/ + + + apacheconf_htpasswddir + system + /etc/httpd/froxlor-htpasswd/ + + + apachereload_command + system + systemctl reload-or-restart httpd.service + + + bindreload_command + system + systemctl reload-or-restart named.service + + + crondreload + system + systemctl reload-or-restart crond.service + + From cb1df3a7e04779a3d83593f34e8cb58021c2c94a Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 15:29:53 +0200 Subject: [PATCH 05/14] show failue as nice red message --- install/lib/class.FroxlorInstall.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index f0ed0e53..25b2f814 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -511,7 +511,8 @@ class FroxlorInstall $this->_updateSetting($upd_stmt, $property->value[0], $property->group[0], $property->name[0]); } } else { - exit('Failed to open distribution XML file.'); + $content .= $this->_status_message('red', 'Failed setting distribution defaults.'); + return $content; } $this->_updateSetting($upd_stmt, $this->_data['activate_newsfeed'], 'admin', 'show_news_feed'); From 27f0c4eb5302c36c398e3971bcb8fc34ff09f19f Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 15:42:38 +0200 Subject: [PATCH 06/14] remove distribution names from language files --- install/lng/english.lng.php | 8 -------- install/lng/french.lng.php | 8 -------- install/lng/german.lng.php | 8 -------- 3 files changed, 24 deletions(-) diff --git a/install/lng/english.lng.php b/install/lng/english.lng.php index 0b04e3c1..69c06ced 100644 --- a/install/lng/english.lng.php +++ b/install/lng/english.lng.php @@ -64,14 +64,6 @@ $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 2eb6cb96..a3aacc6a 100644 --- a/install/lng/french.lng.php +++ b/install/lng/french.lng.php @@ -54,14 +54,6 @@ $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 24554712..bc31c4e2 100644 --- a/install/lng/german.lng.php +++ b/install/lng/german.lng.php @@ -64,14 +64,6 @@ $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'; From f4d4490d0877d0033164c58fcbf3a732e4215874 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 15:45:04 +0200 Subject: [PATCH 07/14] change property tagnames --- lib/configfiles/rhel7.xml | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/configfiles/rhel7.xml b/lib/configfiles/rhel7.xml index c95388f1..f472fba8 100644 --- a/lib/configfiles/rhel7.xml +++ b/lib/configfiles/rhel7.xml @@ -3,36 +3,36 @@ - - apacheconf_vhost - system + + apacheconf_vhost + system /etc/httpd/conf.d/ - - - apacheconf_diroptions - system + + + apacheconf_diroptions + system /etc/httpd/conf.d/ - - - apacheconf_htpasswddir - system + + + apacheconf_htpasswddir + system /etc/httpd/froxlor-htpasswd/ - - - apachereload_command - system + + + apachereload_command + system systemctl reload-or-restart httpd.service - - - bindreload_command - system + + + bindreload_command + system systemctl reload-or-restart named.service - - - crondreload - system + + + crondreload + system systemctl reload-or-restart crond.service - + From 6128954231d175bbeafd5d5a6f2260fc232a47ac Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 15:54:37 +0200 Subject: [PATCH 08/14] rename propery to property --- install/lib/class.FroxlorInstall.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 25b2f814..c270462b 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -507,7 +507,7 @@ class FroxlorInstall if (file_exists(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml')) { $xml = simplexml_load_file(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml'); - foreach($xml->distribution->defaults->propery as $property) { + foreach($xml->distribution->defaults->property as $property) { $this->_updateSetting($upd_stmt, $property->value[0], $property->group[0], $property->name[0]); } } else { @@ -1308,7 +1308,7 @@ class FroxlorInstall // post if (! empty($_POST['distribution'])) { $this->_data['distribution'] = $_POST['distribution']; - } else { + } else { $os_version = parse_ini_file('/etc/os-release', false); if ($os_version['ID'] == 'debian') { From fb35fb9a3a5de362c836028ecb702240b60b554b Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 17:33:48 +0200 Subject: [PATCH 09/14] read distribution from xml and selection via selectbox --- install/lib/class.FroxlorInstall.php | 81 ++++++++++++++++------------ install/templates/dataitemselect.tpl | 6 +++ 2 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 install/templates/dataitemselect.tpl diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index c270462b..ce632f14 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -857,14 +857,26 @@ class FroxlorInstall } 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); + + // show list of available distro's + $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml'); + foreach ($distros as $_distribution) { + $dist = new \Froxlor\Config\ConfigParser($_distribution); + $dist_display = $dist->distributionName." ".$dist->distributionCodename." (" . $dist->distributionVersion . ")"; + $distributions_select_data[$dist_display] .= str_replace(".xml", "", strtolower(basename($_distribution))); + } + + // sort by distribution name + ksort($distributions_select_data); + + foreach ($distributions_select_data as $dist_display => $dist_index) { + // create select-box-option + $distributions_select .= \Froxlor\UI\HTML::makeoption($dist_display, $dist_index, $this->_data['distribution']); + //$this->_data['distribution'] + } + + $formdata .= $this->_getSectionItemSelectbox('distribution', $distributions_select, $diststyle); + // servername if (! empty($_POST['installstep']) && $this->_data['servername'] == '') { $style = 'color:red;'; @@ -963,6 +975,25 @@ class FroxlorInstall return $sectionitem; } + /** + * generate form selectbox + * + * @param string $fieldname + * @param boolean $options + * @param string $style + * + * @return string + */ + private function _getSectionItemSelectbox($fieldname = null, $options = null, $style = "") + { + $groupname = $this->_lng['install'][$groupname]; + $fieldlabel = $this->_lng['install'][$fieldname]; + + $sectionitem = ""; + eval("\$sectionitem .= \"" . $this->_getTemplate("dataitemselect") . "\";"); + return $sectionitem; + } + /** * generate form checkbox field * @@ -1309,34 +1340,16 @@ class FroxlorInstall if (! empty($_POST['distribution'])) { $this->_data['distribution'] = $_POST['distribution']; } else { - $os_version = parse_ini_file('/etc/os-release', false); - if ($os_version['ID'] == 'debian') { + $os_dist = parse_ini_file('/etc/os-release', false); + $os_version = explode('.',$os_version['VERSION_ID'])[0]; - } 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'; + $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml'); + foreach ($distros as $_distribution) { + $dist = new \Froxlor\Config\ConfigParser($_distribution); + $ver = explode('.', $dist->distributionVersion)[0]; + if (strtolower($os_dist['ID']) == strtolower($dist->distributionName) && $os_version = $ver) { // && && $os_version == explode('.', $dist->distributionVersion)[0]) + $this->_data['distribution'] = str_replace(".xml", "", strtolower(basename($_distribution))); } - } else { - // we don't need to bail out, since unknown does not affect any critical installation routines - $this->_data['distribution'] = 'unknown'; } } } diff --git a/install/templates/dataitemselect.tpl b/install/templates/dataitemselect.tpl new file mode 100644 index 00000000..91701bc6 --- /dev/null +++ b/install/templates/dataitemselect.tpl @@ -0,0 +1,6 @@ +

+ + +

From 60578a5d31184fe37631d7ebd571c10e06ad8c90 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 29 May 2020 17:46:38 +0200 Subject: [PATCH 10/14] rename to CentOS because its most likely to be used --- lib/configfiles/rhel7.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/configfiles/rhel7.xml b/lib/configfiles/rhel7.xml index f472fba8..833ab185 100644 --- a/lib/configfiles/rhel7.xml +++ b/lib/configfiles/rhel7.xml @@ -1,6 +1,6 @@ - From 86155f7a9c39aeb20ff5c4f69ec024e9648d79e2 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 30 May 2020 09:11:43 +0200 Subject: [PATCH 11/14] use Distribution in german language --- install/lng/german.lng.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/lng/german.lng.php b/install/lng/german.lng.php index bc31c4e2..4c0aaf68 100644 --- a/install/lng/german.lng.php +++ b/install/lng/german.lng.php @@ -63,7 +63,7 @@ $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']['distribution'] = 'Distribution'; $lng['install']['servername'] = 'Servername (FQDN, keine IP-Adresse)'; $lng['install']['serverip'] = 'Server-IP'; $lng['install']['webserver'] = 'Webserver'; From 0fde1ce7e9e805921c37fbf3e94d5d02d008f06b Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 30 May 2020 09:15:15 +0200 Subject: [PATCH 12/14] remove dev comment --- install/lib/class.FroxlorInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index ce632f14..0e4bb52b 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -1347,7 +1347,7 @@ class FroxlorInstall foreach ($distros as $_distribution) { $dist = new \Froxlor\Config\ConfigParser($_distribution); $ver = explode('.', $dist->distributionVersion)[0]; - if (strtolower($os_dist['ID']) == strtolower($dist->distributionName) && $os_version = $ver) { // && && $os_version == explode('.', $dist->distributionVersion)[0]) + if (strtolower($os_dist['ID']) == strtolower($dist->distributionName) && $os_version = $ver) { $this->_data['distribution'] = str_replace(".xml", "", strtolower(basename($_distribution))); } } From 1454d8d40fe71fee247f423d36951ae8f42d961d Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 30 May 2020 10:08:05 +0200 Subject: [PATCH 13/14] get defaults from configparser --- install/lib/class.FroxlorInstall.php | 11 ++++++ lib/Froxlor/Config/ConfigParser.php | 50 ++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 0e4bb52b..0ca253ce 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -505,6 +505,17 @@ class FroxlorInstall $this->_updateSetting($upd_stmt, 'error', 'system', 'errorlog_level'); } + $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml'); + foreach ($distros as $_distribution) { + if($this->_data['distribution'] == str_replace(".xml", "", strtolower(basename($_distribution)))) { + $dist = new \Froxlor\Config\ConfigParser($_distribution); + $defaults = $dist->getDefaults(); + foreach ($defaults->property as $property) { + $this->_updateSetting($upd_stmt, $property->value, $property->settinggroup, $property->varname); + } + } + } + if (file_exists(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml')) { $xml = simplexml_load_file(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml'); foreach($xml->distribution->defaults->property as $property) { diff --git a/lib/Froxlor/Config/ConfigParser.php b/lib/Froxlor/Config/ConfigParser.php index ca995d7c..c881bcdd 100644 --- a/lib/Froxlor/Config/ConfigParser.php +++ b/lib/Froxlor/Config/ConfigParser.php @@ -39,6 +39,13 @@ class ConfigParser */ private $services = array(); + /** + * Holding the available defaults in the XML + * + * @var array + */ + private $defaults = array(); + /** * Store the parsed SimpleXMLElement for usage * @@ -147,7 +154,7 @@ class ConfigParser * * @return bool */ - private function parse() + private function parseServices() { // We only want to parse the stuff one time if ($this->isparsed == true) { @@ -174,6 +181,29 @@ class ConfigParser return true; } + /** + * Parse the XML and populate $this->services + * + * @return bool + */ + private function parseDefaults() + { + // We only want to parse the stuff one time + if ($this->isparsed == true) { + return true; + } + + // Get all defaults + $defaults = $this->xml->xpath('//defaults'); + foreach ($defaults as $default) { + $this->defaults = $default; + } + + // Switch flag to indicate we parsed our data + $this->isparsed = true; + return true; + } + /** * Return all services defined by the XML * @@ -184,9 +214,25 @@ class ConfigParser public function getServices() { // Let's parse this shit(!) - $this->parse(); + $this->parseServices(); // Return our carefully searched for services return $this->services; } + + /** + * Return all defaults defined by the XML + * + * The array will hold ConfigDefaults - Objects for further handling + * + * @return array + */ + public function getDefaults() + { + // Let's parse this shit(!) + $this->parseDefaults(); + + // Return our carefully searched for defaults + return $this->defaults; + } } From 6ccfb7efbb013386a79c7d37ff95e83ebc2738b1 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sat, 30 May 2020 10:10:57 +0200 Subject: [PATCH 14/14] remove old code --- install/lib/class.FroxlorInstall.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/install/lib/class.FroxlorInstall.php b/install/lib/class.FroxlorInstall.php index 0ca253ce..b9ab4dc0 100644 --- a/install/lib/class.FroxlorInstall.php +++ b/install/lib/class.FroxlorInstall.php @@ -516,16 +516,6 @@ class FroxlorInstall } } - if (file_exists(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml')) { - $xml = simplexml_load_file(dirname(__DIR__).'/../lib/configfiles/'.$this->_data['distribution'].'.xml'); - foreach($xml->distribution->defaults->property as $property) { - $this->_updateSetting($upd_stmt, $property->value[0], $property->group[0], $property->name[0]); - } - } else { - $content .= $this->_status_message('red', 'Failed setting distribution defaults.'); - return $content; - } - $this->_updateSetting($upd_stmt, $this->_data['activate_newsfeed'], 'admin', 'show_news_feed'); $this->_updateSetting($upd_stmt, dirname(dirname(dirname(__FILE__))), 'system', 'letsencryptchallengepath');