From 7656f345cd1611867e0b13cdf4752497f1e25ac3 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Mon, 28 Aug 2017 16:53:14 +0200 Subject: [PATCH] Aggiunta del test per database Aggiunta di un sistema di test per il database durante la configurazione iniziale. --- include/configuration.php | 111 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/include/configuration.php b/include/configuration.php index a5575d016..2eaa0cfe9 100644 --- a/include/configuration.php +++ b/include/configuration.php @@ -23,14 +23,74 @@ if (post('db_host') !== null) { $db_name = post('db_name'); $db_username = post('db_username'); $db_password = post('db_password'); - $_SESSION['osm_password'] = post('osm_password'); - $_SESSION['osm_email'] = post('osm_email'); $valid_config = isset($db_host) && isset($db_name) && isset($db_username) && isset($db_password); // Generazione di una nuova connessione al database $dbo = Database::getConnection(true); + // Test della configurazione + if (post('test') !== null) { + ob_end_clean(); + $state = 2; + + if ($dbo->isConnected()) { + $requirements = [ + 'SELECT', + 'INSERT', + 'UPDATE', + 'CREATE', + 'ALTER', + 'DROP', + 'CREATE VIEW', + ]; + + $db_host = str_replace('_', '\_', $db_name); + $db_name = str_replace('_', '\_', $db_name); + $db_username = str_replace('_', '\_', $db_name); + + $user = " TO '".$db_username."'@'".$db_host."'"; + $db = ' ON `'.$db_name.'`.*'; + + $results = $dbo->fetchArray('SHOW GRANTS FOR CURRENT_USER'); + foreach ($results as $result) { + if ( + str_contains($result, $find) && + ( + str_contains($result, $db) || + str_contains($result, str_replace('`'.$db_name.'`', '*', $db)) + ) + ) { + $pieces = explode(', ', explode(' ON ', str_replace('GRANT ', '', current($result)))[0]); + + if (in_array('ALL', $pieces) || in_array('ALL PRIVILEGES', $pieces)) { + break; + } + + foreach ($requirements as $key => $value) { + if (!in_array($value, $pieces)) { + $state = 1; + + break 2; + } else { + unset($requirements[$key]); + } + } + } + } + } else { + $state = 0; + } + + echo $state; + exit(); + } + + // Salvataggio dei valori da salvare successivamente + $_SESSION['osm_password'] = post('osm_password'); + $_SESSION['osm_email'] = post('osm_email'); + + // Creazione della configurazione if ($dbo->isConnected()) { // Impostazioni di configurazione strettamente necessarie al funzionamento del progetto $backup_config = ''; @@ -425,7 +525,12 @@ if (empty($creation) && (!file_exists('config.inc.php') || !$valid_config)) {
*'._('Campi obbligatori').'
-
+
+ +
+