read distribution from xml and selection via selectbox

This commit is contained in:
Ante de Baas
2020-05-29 17:33:48 +02:00
parent 6128954231
commit fb35fb9a3a
2 changed files with 53 additions and 34 deletions

View File

@@ -857,14 +857,26 @@ class FroxlorInstall
} else { } else {
$diststyle = ''; $diststyle = '';
} }
$formdata .= $this->_GETsectionItemCheckbox('distribution', 'jessie', ($this->_data['distribution'] == 'jessie'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'stretch', ($this->_data['distribution'] == 'stretch'), $diststyle); // show list of available distro's
$formdata .= $this->_getSectionItemCheckbox('distribution', 'buster', ($this->_data['distribution'] == 'buster'), $diststyle); $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml');
$formdata .= $this->_getSectionItemCheckbox('distribution', 'xenial', ($this->_data['distribution'] == 'xenial'), $diststyle); foreach ($distros as $_distribution) {
$formdata .= $this->_getSectionItemCheckbox('distribution', 'bionic', ($this->_data['distribution'] == 'bionic'), $diststyle); $dist = new \Froxlor\Config\ConfigParser($_distribution);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'focal', ($this->_data['distribution'] == 'focal'), $diststyle); $dist_display = $dist->distributionName." ".$dist->distributionCodename." (" . $dist->distributionVersion . ")";
$formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel7', ($this->_data['distribution'] == 'rhel7'), $diststyle); $distributions_select_data[$dist_display] .= str_replace(".xml", "", strtolower(basename($_distribution)));
$formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel8', ($this->_data['distribution'] == 'rhel8'), $diststyle); }
// 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 // servername
if (! empty($_POST['installstep']) && $this->_data['servername'] == '') { if (! empty($_POST['installstep']) && $this->_data['servername'] == '') {
$style = 'color:red;'; $style = 'color:red;';
@@ -963,6 +975,25 @@ class FroxlorInstall
return $sectionitem; 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 * generate form checkbox field
* *
@@ -1309,34 +1340,16 @@ class FroxlorInstall
if (! empty($_POST['distribution'])) { if (! empty($_POST['distribution'])) {
$this->_data['distribution'] = $_POST['distribution']; $this->_data['distribution'] = $_POST['distribution'];
} else { } else {
$os_version = parse_ini_file('/etc/os-release', false); $os_dist = parse_ini_file('/etc/os-release', false);
if ($os_version['ID'] == 'debian') { $os_version = explode('.',$os_version['VERSION_ID'])[0];
} elseif ($os_version['ID'] == 'debian') { $distros = glob(\Froxlor\FileDir::makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . '/lib/configfiles/') . '*.xml');
if(explode('.',$os_version['VERSION_ID'])[0] == '8') { foreach ($distros as $_distribution) {
$this->_data['distribution'] = 'jessie'; $dist = new \Froxlor\Config\ConfigParser($_distribution);
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '9') { $ver = explode('.', $dist->distributionVersion)[0];
$this->_data['distribution'] = 'stretch'; if (strtolower($os_dist['ID']) == strtolower($dist->distributionName) && $os_version = $ver) { // && && $os_version == explode('.', $dist->distributionVersion)[0])
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '10') { $this->_data['distribution'] = str_replace(".xml", "", strtolower(basename($_distribution)));
$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';
} }
} }
} }

View File

@@ -0,0 +1,6 @@
<p>
<label for="{$fieldname}" class="install-block {$style}">{$fieldlabel}:</label>
<select name="{$fieldname}" id="{$fieldname}" class="dropdown">
{$options}
</select>
</p>