let user decide whether an existing database should be backup'ed and removed when installing froxlor; dont rely on parse_ini_file for OS check; enhance mysqldump so there is no issues with complex passwords and bash-escaping
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -163,6 +163,7 @@ class FroxlorInstall
|
|||||||
|
|
||||||
$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');
|
||||||
|
$this->_getPostField('mysql_forcecreate', '0');
|
||||||
$this->_getPostField('mysql_unpriv_user', 'froxlor');
|
$this->_getPostField('mysql_unpriv_user', 'froxlor');
|
||||||
$this->_getPostField('mysql_unpriv_pass');
|
$this->_getPostField('mysql_unpriv_pass');
|
||||||
$this->_getPostField('mysql_root_user', 'root');
|
$this->_getPostField('mysql_root_user', 'root');
|
||||||
@@ -246,10 +247,12 @@ class FroxlorInstall
|
|||||||
$content .= $this->_status_message('green', "OK");
|
$content .= $this->_status_message('green', "OK");
|
||||||
// check for existing db and create backup if so
|
// check for existing db and create backup if so
|
||||||
$content .= $this->_backupExistingDatabase($db_root);
|
$content .= $this->_backupExistingDatabase($db_root);
|
||||||
// create unprivileged user and the database itself
|
if (!$this->_abort) {
|
||||||
$content .= $this->_createDatabaseAndUser($db_root);
|
// create unprivileged user and the database itself
|
||||||
// importing data to new database
|
$content .= $this->_createDatabaseAndUser($db_root);
|
||||||
$content .= $this->_importDatabaseData();
|
// importing data to new database
|
||||||
|
$content .= $this->_importDatabaseData();
|
||||||
|
}
|
||||||
if (! $this->_abort) {
|
if (! $this->_abort) {
|
||||||
// create DB object for new database
|
// create DB object for new database
|
||||||
$options = array(
|
$options = array(
|
||||||
@@ -733,12 +736,16 @@ class FroxlorInstall
|
|||||||
));
|
));
|
||||||
$rows = $db_root->query("SELECT FOUND_ROWS()")->fetchColumn();
|
$rows = $db_root->query("SELECT FOUND_ROWS()")->fetchColumn();
|
||||||
|
|
||||||
|
$content .= $this->_status_message('begin', $this->_lng['install']['check_db_exists']);
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
if ($result_stmt !== false && $rows > 0) {
|
if ($result_stmt !== false && $rows > 0) {
|
||||||
$tables_exist = true;
|
$tables_exist = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tables_exist) {
|
if ($tables_exist && (int)$this->_data['mysql_forcecreate'] > 0) {
|
||||||
|
// set status
|
||||||
|
$content .= $this->_status_message('orange', 'exists (' . $this->_data['mysql_database'] . ')');
|
||||||
// tell what's going on
|
// tell what's going on
|
||||||
$content .= $this->_status_message('begin', $this->_lng['install']['backup_old_db']);
|
$content .= $this->_status_message('begin', $this->_lng['install']['backup_old_db']);
|
||||||
|
|
||||||
@@ -755,17 +762,29 @@ class FroxlorInstall
|
|||||||
$mysql_dump = '/usr/local/bin/mysqldump';
|
$mysql_dump = '/usr/local/bin/mysqldump';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create temporary .cnf file
|
||||||
|
$cnffilename = "/tmp/froxlor_dump.cnf";
|
||||||
|
$dumpcnf = "[mysqldump]".PHP_EOL."password=\"".$this->_data['mysql_root_pass']."\"".PHP_EOL;
|
||||||
|
file_put_contents($cnffilename, $dumpcnf);
|
||||||
|
|
||||||
if ($do_backup) {
|
if ($do_backup) {
|
||||||
$command = $mysql_dump . " " . escapeshellarg($this->_data['mysql_database']) . " -u " . escapeshellarg($this->_data['mysql_root_user']) . " --password='" . escapeshellarg($this->_data['mysql_root_pass']) . "' --result-file=" . $filename;
|
$command = $mysql_dump . " --defaults-extra-file=" . $cnffilename . " " . escapeshellarg($this->_data['mysql_database']) . " -u " . escapeshellarg($this->_data['mysql_root_user']) . " --result-file=" . $filename;
|
||||||
$output = exec($command);
|
$output = [];
|
||||||
if (stristr($output, "error")) {
|
exec($command, $output);
|
||||||
|
@unlink($cnffilename);
|
||||||
|
if (stristr(implode(" ", $output), "error") || !file_exists($filename)) {
|
||||||
$content .= $this->_status_message('red', $this->_lng['install']['backup_failed']);
|
$content .= $this->_status_message('red', $this->_lng['install']['backup_failed']);
|
||||||
|
$this->_abort = true;
|
||||||
} else {
|
} else {
|
||||||
$content .= $this->_status_message('green', 'OK (' . $filename . ')');
|
$content .= $this->_status_message('green', 'OK (' . $filename . ')');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$content .= $this->_status_message('red', $this->_lng['install']['backup_binary_missing']);
|
$content .= $this->_status_message('red', $this->_lng['install']['backup_binary_missing']);
|
||||||
|
$this->_abort = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$content .= $this->_status_message('red', $this->_lng['install']['db_exists']);
|
||||||
|
$this->_abort = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
@@ -801,6 +820,8 @@ class FroxlorInstall
|
|||||||
$formdata .= $this->_getSectionItemString('mysql_host', true);
|
$formdata .= $this->_getSectionItemString('mysql_host', true);
|
||||||
// database
|
// database
|
||||||
$formdata .= $this->_getSectionItemString('mysql_database', true);
|
$formdata .= $this->_getSectionItemString('mysql_database', true);
|
||||||
|
// database overwrite if exists?
|
||||||
|
$formdata .= $this->_getSectionItemYesNo('mysql_forcecreate', false);
|
||||||
// unpriv-user has to be different from root
|
// unpriv-user has to be different from root
|
||||||
if ($this->_data['mysql_unpriv_user'] == $this->_data['mysql_root_user']) {
|
if ($this->_data['mysql_unpriv_user'] == $this->_data['mysql_root_user']) {
|
||||||
$style = 'blue';
|
$style = 'blue';
|
||||||
@@ -1363,7 +1384,14 @@ class FroxlorInstall
|
|||||||
|
|
||||||
// read os-release
|
// read os-release
|
||||||
if (file_exists('/etc/os-release')) {
|
if (file_exists('/etc/os-release')) {
|
||||||
$os_dist = parse_ini_file('/etc/os-release', false);
|
$os_dist_content = file_get_contents('/etc/os-release');
|
||||||
|
$os_dist_arr = explode("\n", $os_dist_content);
|
||||||
|
$os_dist = [];
|
||||||
|
foreach ($os_dist_arr as $os_dist_line) {
|
||||||
|
if (empty(trim($os_dist_line))) continue;
|
||||||
|
$tmp = explode("=", $os_dist_line);
|
||||||
|
$os_dist[$tmp[0]] = str_replace('"', "", trim($tmp[1]));
|
||||||
|
}
|
||||||
if (is_array($os_dist) && array_key_exists('ID', $os_dist) && array_key_exists('VERSION_ID', $os_dist)) {
|
if (is_array($os_dist) && array_key_exists('ID', $os_dist) && array_key_exists('VERSION_ID', $os_dist)) {
|
||||||
$os_version = explode('.', $os_dist['VERSION_ID'])[0];
|
$os_version = explode('.', $os_dist['VERSION_ID'])[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ $lng['install']['welcometext'] = 'Thank you for choosing Froxlor. Please fill ou
|
|||||||
$lng['install']['database'] = 'Database connection';
|
$lng['install']['database'] = 'Database connection';
|
||||||
$lng['install']['mysql_host'] = 'MySQL-Hostname';
|
$lng['install']['mysql_host'] = 'MySQL-Hostname';
|
||||||
$lng['install']['mysql_database'] = 'Database name';
|
$lng['install']['mysql_database'] = 'Database name';
|
||||||
|
$lng['install']['mysql_forcecreate'] = 'Backup and overwrite database if exists?';
|
||||||
$lng['install']['mysql_unpriv_user'] = 'Username for the unprivileged MySQL-account';
|
$lng['install']['mysql_unpriv_user'] = 'Username for the unprivileged MySQL-account';
|
||||||
$lng['install']['mysql_unpriv_pass'] = 'Password for the unprivileged MySQL-account';
|
$lng['install']['mysql_unpriv_pass'] = 'Password for the unprivileged MySQL-account';
|
||||||
$lng['install']['mysql_root_user'] = 'Username for the MySQL-root-account';
|
$lng['install']['mysql_root_user'] = 'Username for the MySQL-root-account';
|
||||||
@@ -79,6 +80,8 @@ $lng['install']['testing_mysql_fail'] = 'There seems to be a problem with the da
|
|||||||
$lng['install']['backup_old_db'] = 'Creating backup of old database...';
|
$lng['install']['backup_old_db'] = 'Creating backup of old database...';
|
||||||
$lng['install']['backup_binary_missing'] = 'Could not find mysqldump';
|
$lng['install']['backup_binary_missing'] = 'Could not find mysqldump';
|
||||||
$lng['install']['backup_failed'] = 'Could not backup database';
|
$lng['install']['backup_failed'] = 'Could not backup database';
|
||||||
|
$lng['install']['check_db_exists'] = 'Checking database...';
|
||||||
|
$lng['install']['db_exists'] = 'Unable to create database. A database with the same name exists and should not be overwritten';
|
||||||
$lng['install']['prepare_db'] = 'Preparing database...';
|
$lng['install']['prepare_db'] = 'Preparing database...';
|
||||||
$lng['install']['create_mysqluser_and_db'] = 'Creating database and username...';
|
$lng['install']['create_mysqluser_and_db'] = 'Creating database and username...';
|
||||||
$lng['install']['testing_new_db'] = 'Testing if database and user have been created correctly...';
|
$lng['install']['testing_new_db'] = 'Testing if database and user have been created correctly...';
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ $lng['install']['welcometext'] = 'Vielen Dank dass Sie sich für Froxlor entschi
|
|||||||
$lng['install']['database'] = 'Datenbankverbindung';
|
$lng['install']['database'] = 'Datenbankverbindung';
|
||||||
$lng['install']['mysql_host'] = 'MySQL-Hostname';
|
$lng['install']['mysql_host'] = 'MySQL-Hostname';
|
||||||
$lng['install']['mysql_database'] = 'Datenbank Name';
|
$lng['install']['mysql_database'] = 'Datenbank Name';
|
||||||
|
$lng['install']['mysql_forcecreate'] = 'Datenbank sichern und überschreiben wenn vorhanden?';
|
||||||
$lng['install']['mysql_unpriv_user'] = 'Benutzername für den unprivilegierten MySQL-Account';
|
$lng['install']['mysql_unpriv_user'] = 'Benutzername für den unprivilegierten MySQL-Account';
|
||||||
$lng['install']['mysql_unpriv_pass'] = 'Passwort für den unprivilegierten MySQL-Account';
|
$lng['install']['mysql_unpriv_pass'] = 'Passwort für den unprivilegierten MySQL-Account';
|
||||||
$lng['install']['mysql_root_user'] = 'Benutzername für den MySQL-Root-Account';
|
$lng['install']['mysql_root_user'] = 'Benutzername für den MySQL-Root-Account';
|
||||||
@@ -79,6 +80,8 @@ $lng['install']['testing_mysql_fail'] = 'Bei der Verwendung der Datenbank gibt e
|
|||||||
$lng['install']['backup_old_db'] = 'Sicherung vorheriger Datenbank...';
|
$lng['install']['backup_old_db'] = 'Sicherung vorheriger Datenbank...';
|
||||||
$lng['install']['backup_binary_missing'] = 'Konnte mysqldump nicht finden';
|
$lng['install']['backup_binary_missing'] = 'Konnte mysqldump nicht finden';
|
||||||
$lng['install']['backup_failed'] = 'Sicherung fehlgeschlagen';
|
$lng['install']['backup_failed'] = 'Sicherung fehlgeschlagen';
|
||||||
|
$lng['install']['check_db_exists'] = 'Databenbank wird geprüft...';
|
||||||
|
$lng['install']['db_exists'] = 'Datenbank kann nicht erstellt werden. Eine Datenbank mit dem selben Namen existiert bereits und soll nicht überschrieben werden.';
|
||||||
$lng['install']['prepare_db'] = 'Datenbank wird vorbereitet...';
|
$lng['install']['prepare_db'] = 'Datenbank wird vorbereitet...';
|
||||||
$lng['install']['create_mysqluser_and_db'] = 'Erstelle Datenbank und Benutzer...';
|
$lng['install']['create_mysqluser_and_db'] = 'Erstelle Datenbank und Benutzer...';
|
||||||
$lng['install']['testing_new_db'] = 'Teste, ob Datenbank und Benutzer korrekt angelegt wurden...';
|
$lng['install']['testing_new_db'] = 'Teste, ob Datenbank und Benutzer korrekt angelegt wurden...';
|
||||||
|
|||||||
Reference in New Issue
Block a user