Merge pull request #849 from daxara/detect_distr
Detect distribution upon installation and set setting-defaults (if any) for that distribution
This commit is contained in:
@@ -159,6 +159,7 @@ class FroxlorInstall
|
|||||||
$this->_guessServerName();
|
$this->_guessServerName();
|
||||||
$this->_guessServerIP();
|
$this->_guessServerIP();
|
||||||
$this->_guessWebserver();
|
$this->_guessWebserver();
|
||||||
|
$this->_guessDistribution();
|
||||||
|
|
||||||
$this->_getPostField('mysql_host', '127.0.0.1');
|
$this->_getPostField('mysql_host', '127.0.0.1');
|
||||||
$this->_getPostField('mysql_database', 'froxlor');
|
$this->_getPostField('mysql_database', 'froxlor');
|
||||||
@@ -504,6 +505,17 @@ class FroxlorInstall
|
|||||||
$this->_updateSetting($upd_stmt, 'error', 'system', 'errorlog_level');
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->_updateSetting($upd_stmt, $this->_data['activate_newsfeed'], 'admin', 'show_news_feed');
|
$this->_updateSetting($upd_stmt, $this->_data['activate_newsfeed'], 'admin', 'show_news_feed');
|
||||||
$this->_updateSetting($upd_stmt, dirname(dirname(dirname(__FILE__))), 'system', 'letsencryptchallengepath');
|
$this->_updateSetting($upd_stmt, dirname(dirname(dirname(__FILE__))), 'system', 'letsencryptchallengepath');
|
||||||
|
|
||||||
@@ -840,6 +852,32 @@ class FroxlorInstall
|
|||||||
*/
|
*/
|
||||||
$section = $this->_lng['install']['serversettings'];
|
$section = $this->_lng['install']['serversettings'];
|
||||||
eval("\$formdata .= \"" . $this->_getTemplate("datasection") . "\";");
|
eval("\$formdata .= \"" . $this->_getTemplate("datasection") . "\";");
|
||||||
|
// distribution
|
||||||
|
if (! empty($_POST['installstep']) && $this->_data['distribution'] == '') {
|
||||||
|
$diststyle = 'color:red;';
|
||||||
|
} else {
|
||||||
|
$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
|
// servername
|
||||||
if (! empty($_POST['installstep']) && $this->_data['servername'] == '') {
|
if (! empty($_POST['installstep']) && $this->_data['servername'] == '') {
|
||||||
$style = 'color:red;';
|
$style = 'color:red;';
|
||||||
@@ -861,12 +899,12 @@ class FroxlorInstall
|
|||||||
$websrvstyle = '';
|
$websrvstyle = '';
|
||||||
}
|
}
|
||||||
// apache
|
// apache
|
||||||
$formdata .= $this->_getSectionItemCheckbox('apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle);
|
$formdata .= $this->_getSectionItemCheckbox('webserver', 'apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle);
|
||||||
$formdata .= $this->_getSectionItemCheckbox('apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle);
|
$formdata .= $this->_getSectionItemCheckbox('webserver', 'apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle);
|
||||||
// lighttpd
|
// lighttpd
|
||||||
$formdata .= $this->_getSectionItemCheckbox('lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle);
|
$formdata .= $this->_getSectionItemCheckbox('webserver', 'lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle);
|
||||||
// nginx
|
// nginx
|
||||||
$formdata .= $this->_getSectionItemCheckbox('nginx', ($this->_data['webserver'] == 'nginx'), $websrvstyle);
|
$formdata .= $this->_getSectionItemCheckbox('webserver', 'nginx', ($this->_data['webserver'] == 'nginx'), $websrvstyle);
|
||||||
// webserver-user
|
// webserver-user
|
||||||
if (! empty($_POST['installstep']) && $this->_data['httpuser'] == '') {
|
if (! empty($_POST['installstep']) && $this->_data['httpuser'] == '') {
|
||||||
$style = 'color:red;';
|
$style = 'color:red;';
|
||||||
@@ -918,7 +956,7 @@ class FroxlorInstall
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate form radio field for webserver-selection
|
* generate form radio field
|
||||||
*
|
*
|
||||||
* @param string $fieldname
|
* @param string $fieldname
|
||||||
* @param boolean $checked
|
* @param boolean $checked
|
||||||
@@ -926,8 +964,9 @@ class FroxlorInstall
|
|||||||
*
|
*
|
||||||
* @return string
|
* @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];
|
$fieldlabel = $this->_lng['install'][$fieldname];
|
||||||
if ($checked) {
|
if ($checked) {
|
||||||
$checked = 'checked="checked"';
|
$checked = 'checked="checked"';
|
||||||
@@ -937,6 +976,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
|
||||||
*
|
*
|
||||||
@@ -1273,6 +1331,30 @@ class FroxlorInstall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get/guess linux distribution
|
||||||
|
*/
|
||||||
|
private function _guessDistribution()
|
||||||
|
{
|
||||||
|
// post
|
||||||
|
if (! empty($_POST['distribution'])) {
|
||||||
|
$this->_data['distribution'] = $_POST['distribution'];
|
||||||
|
} else {
|
||||||
|
$os_dist = parse_ini_file('/etc/os-release', false);
|
||||||
|
$os_version = explode('.',$os_version['VERSION_ID'])[0];
|
||||||
|
|
||||||
|
$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) {
|
||||||
|
$this->_data['distribution'] = str_replace(".xml", "", strtolower(basename($_distribution)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if POST field is set and get value for the
|
* check if POST field is set and get value for the
|
||||||
* internal data array, if not set use either '' or $default if != null
|
* internal data array, if not set use either '' or $default if != null
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ $lng['install']['admin_pass1'] = 'Administrator Password';
|
|||||||
$lng['install']['admin_pass2'] = 'Administrator-Password (confirm)';
|
$lng['install']['admin_pass2'] = 'Administrator-Password (confirm)';
|
||||||
$lng['install']['activate_newsfeed'] = 'Enable the official newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
|
$lng['install']['activate_newsfeed'] = 'Enable the official newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
|
||||||
$lng['install']['serversettings'] = 'Server settings';
|
$lng['install']['serversettings'] = 'Server settings';
|
||||||
|
$lng['install']['distribution'] = 'Distribution';
|
||||||
$lng['install']['servername'] = 'Server name (FQDN, no ip-address)';
|
$lng['install']['servername'] = 'Server name (FQDN, no ip-address)';
|
||||||
$lng['install']['serverip'] = 'Server IP';
|
$lng['install']['serverip'] = 'Server IP';
|
||||||
$lng['install']['webserver'] = 'Webserver';
|
$lng['install']['webserver'] = 'Webserver';
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ $lng['install']['admin_user'] = 'Nom d\'utilisateur administrateur';
|
|||||||
$lng['install']['admin_pass1'] = 'Mot de passe administrateur';
|
$lng['install']['admin_pass1'] = 'Mot de passe administrateur';
|
||||||
$lng['install']['admin_pass2'] = 'Mot de passe administrateur (confirmez)';
|
$lng['install']['admin_pass2'] = 'Mot de passe administrateur (confirmez)';
|
||||||
$lng['install']['serversettings'] = 'Réglages serveur';
|
$lng['install']['serversettings'] = 'Réglages serveur';
|
||||||
|
$lng['install']['distribution'] = 'Distribution';
|
||||||
$lng['install']['servername'] = 'Nom du serveur (FQDN, pas d\'adresse IP)';
|
$lng['install']['servername'] = 'Nom du serveur (FQDN, pas d\'adresse IP)';
|
||||||
$lng['install']['serverip'] = 'Adresse IP du serveur';
|
$lng['install']['serverip'] = 'Adresse IP du serveur';
|
||||||
$lng['install']['webserver'] = 'Serveur Web';
|
$lng['install']['webserver'] = 'Serveur Web';
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ $lng['install']['admin_pass1'] = 'Administrator-Passwort';
|
|||||||
$lng['install']['admin_pass2'] = 'Administrator-Passwort (Bestätigung)';
|
$lng['install']['admin_pass2'] = 'Administrator-Passwort (Bestätigung)';
|
||||||
$lng['install']['activate_newsfeed'] = 'Aktiviere das offizielle Newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
|
$lng['install']['activate_newsfeed'] = 'Aktiviere das offizielle Newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
|
||||||
$lng['install']['serversettings'] = 'Servereinstellungen';
|
$lng['install']['serversettings'] = 'Servereinstellungen';
|
||||||
|
$lng['install']['distribution'] = 'Distribution';
|
||||||
$lng['install']['servername'] = 'Servername (FQDN, keine IP-Adresse)';
|
$lng['install']['servername'] = 'Servername (FQDN, keine IP-Adresse)';
|
||||||
$lng['install']['serverip'] = 'Server-IP';
|
$lng['install']['serverip'] = 'Server-IP';
|
||||||
$lng['install']['webserver'] = 'Webserver';
|
$lng['install']['webserver'] = 'Webserver';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<p>
|
<p>
|
||||||
<label for="{$fieldname}" class="install-block {$style}">{$this->_lng['install']['webserver']} {$fieldlabel}:</label>
|
<label for="{$fieldname}" class="install-block {$style}">{$groupname} {$fieldlabel}:</label>
|
||||||
<input type="radio" name="webserver" id="{$fieldname}" value="{$fieldname}" {$checked} /><span>{$fieldlabel}</span>
|
<input type="radio" name="{$groupname}" id="{$fieldname}" value="{$fieldname}" {$checked} /><span>{$fieldlabel}</span>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
6
install/templates/dataitemselect.tpl
Normal file
6
install/templates/dataitemselect.tpl
Normal 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>
|
||||||
@@ -39,6 +39,13 @@ class ConfigParser
|
|||||||
*/
|
*/
|
||||||
private $services = array();
|
private $services = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holding the available defaults in the XML
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $defaults = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the parsed SimpleXMLElement for usage
|
* Store the parsed SimpleXMLElement for usage
|
||||||
*
|
*
|
||||||
@@ -147,7 +154,7 @@ class ConfigParser
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function parse()
|
private function parseServices()
|
||||||
{
|
{
|
||||||
// We only want to parse the stuff one time
|
// We only want to parse the stuff one time
|
||||||
if ($this->isparsed == true) {
|
if ($this->isparsed == true) {
|
||||||
@@ -174,6 +181,29 @@ class ConfigParser
|
|||||||
return true;
|
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
|
* Return all services defined by the XML
|
||||||
*
|
*
|
||||||
@@ -184,9 +214,25 @@ class ConfigParser
|
|||||||
public function getServices()
|
public function getServices()
|
||||||
{
|
{
|
||||||
// Let's parse this shit(!)
|
// Let's parse this shit(!)
|
||||||
$this->parse();
|
$this->parseServices();
|
||||||
|
|
||||||
// Return our carefully searched for services
|
// Return our carefully searched for services
|
||||||
return $this->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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,39 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<froxlor>
|
<froxlor>
|
||||||
<distribution name="RHEL" version="7"
|
<distribution name="CentOS" version="7"
|
||||||
defaulteditor="/usr/bin/nano">
|
defaulteditor="/usr/bin/nano">
|
||||||
|
<defaults>
|
||||||
|
<property>
|
||||||
|
<varname>apacheconf_vhost</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>/etc/httpd/conf.d/</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<varname>apacheconf_diroptions</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>/etc/httpd/conf.d/</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<varname>apacheconf_htpasswddir</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>/etc/httpd/froxlor-htpasswd/</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<varname>apachereload_command</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>systemctl reload-or-restart httpd.service</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<varname>bindreload_command</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>systemctl reload-or-restart named.service</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<varname>crondreload</varname>
|
||||||
|
<settinggroup>system</settinggroup>
|
||||||
|
<value>systemctl reload-or-restart crond.service</value>
|
||||||
|
</property>
|
||||||
|
</defaults>
|
||||||
<services>
|
<services>
|
||||||
<!-- HTTP -->
|
<!-- HTTP -->
|
||||||
<service type="http" title="{{lng.admin.configfiles.http}}">
|
<service type="http" title="{{lng.admin.configfiles.http}}">
|
||||||
|
|||||||
Reference in New Issue
Block a user