From 96e8116a2b52745368ee2a62c8a7eda93f6346a0 Mon Sep 17 00:00:00 2001 From: nilsteampassnet Date: Tue, 7 Jun 2016 18:00:46 +0200 Subject: [PATCH] 2.1.26 Cosmetic in code Fix SQL error during installation in case of MySQL (instead of MariaDB) Fix for SQL error during CSV import in case of MySQL (instead of MariaDB) --- .../libraries/Database/Meekrodb/db.class.php | 30 +++++++++++-------- install/install.js | 28 +++++++++-------- install/install.queries.php | 12 ++++---- install/upgrade_run_2.1.26.php | 1 + items.load.php | 5 ++++ sources/import.queries.php | 3 +- 6 files changed, 46 insertions(+), 33 deletions(-) diff --git a/includes/libraries/Database/Meekrodb/db.class.php b/includes/libraries/Database/Meekrodb/db.class.php index e0f695feb..05ef54f5c 100644 --- a/includes/libraries/Database/Meekrodb/db.class.php +++ b/includes/libraries/Database/Meekrodb/db.class.php @@ -190,7 +190,7 @@ public function nonSQLError($message) { } $error_handler = is_callable($this->nonsql_error_handler) ? $this->nonsql_error_handler : 'meekrodb_error_handler'; - + call_user_func($error_handler, array( 'type' => 'nonsql', 'error' => $message @@ -611,17 +611,17 @@ protected function queryHelper() { if ($this->error_handler) { $db_error = $db->error; $db_errno = $db->errno; - $db->query( - "INSERT INTO ".$GLOBALS['pre']."log_system SET - date=".time().", - qui=".$_SESSION['user_id'].", - label='Query: ".addslashes($sql)."
Error: ".addslashes($db_error)."
@ ".$_SERVER['REQUEST_URI']."', - type='error'", - MYSQLI_USE_RESULT - ); + $db->query( + "INSERT INTO ".$GLOBALS['pre']."log_system SET + date=".time().", + qui=".$_SESSION['user_id'].", + label='Query: ".addslashes($sql)."
Error: ".addslashes($db_error)."
@ ".$_SERVER['REQUEST_URI']."', + type='error'", + MYSQLI_USE_RESULT + ); $error_handler = is_callable($this->error_handler) ? $this->error_handler : 'meekrodb_error_handler'; - + call_user_func($error_handler, array( 'type' => 'sql', 'query' => $sql, @@ -629,9 +629,9 @@ protected function queryHelper() { 'code' => $db_errno )); } - + if ($this->throw_exception_on_error) { - $e = new MeekroDBException($db->error, $sql, $db->errno); + $e = new MeekroDBException($db_error, $sql, $db_errno); throw $e; } } else if ($this->success_handler) { @@ -910,15 +910,19 @@ public static function reIndex() { } function meekrodb_error_handler($params) { - if (isset($params['query'])) $out[] = "QUERY: " . $params['query']; + /*if (isset($params['query'])) $out[] = "QUERY: " . $params['query']; if (isset($params['error'])) $out[] = "ERROR: " . $params['error']; $out[] = ""; + if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { echo implode("\n", $out); } else { echo implode("
\n", $out); } + */ + + echo prepareExchangedData('[{"error" : "'.$params['error'].'"}]', "encode"); die; } diff --git a/install/install.js b/install/install.js index c65da66f7..931ed5927 100644 --- a/install/install.js +++ b/install/install.js @@ -1,10 +1,10 @@ /** - * @file install.js - * @author Nils Laumaillé - * @version 2.1.22 - * @copyright (c) 2009-2011 Nils Laumaillé - * @licensing GNU AFFERO GPL 3.0 - * @link http://www.teampass.net + * @file install.js + * @author Nils Laumaillé + * @version 2.1.22 + * @copyright (c) 2009-2011 Nils Laumaillé + * @licensing GNU AFFERO GPL 3.0 + * @link http://www.teampass.net * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -119,6 +119,7 @@ function CheckPage() $("#step_result").html("Please wait "); var globalResult = true; $("#step_res").val("true"); + $('#pop_db').html(""); var ajaxReqs = []; for (index = 0; index < tasks.length; ++index) { var tsk = tasks[index].split("*");//console.log(tsk[1]); @@ -152,11 +153,12 @@ function CheckPage() $("#step_result").html(data[0].result); } } else { - // ignore setting error if regarding setting permissions (step 6, index 2) - if (step+data[0].index != "62") { - $("#step_res").val("false"); - } + // ignore setting error if regarding setting permissions (step 6, index 2) + if (step+data[0].index != "62") { + $("#step_res").val("false"); + } $("#res"+step+"_check"+data[0].index).html(" "+data[0].error+""); + $('#pop_db').append('
  •  Error on task `'+data[0].table+'`. '+data[0].error+'
  • '); if (data[0].result != undefined && data[0].result != "" ) { $("#step_result").html(data[0].result); } @@ -169,7 +171,7 @@ function CheckPage() setTimeout(function(){ // all requests are complete if ($("#step_res").val() == "false") { - data = $.parseJSON(data.responseText); + data = $.parseJSON(data.responseText); $("#step_error").show().html("At least one task has failed! Please correct and relaunch. "); $("#res_"+step).html(""); } else { @@ -179,8 +181,8 @@ function CheckPage() $("#but_next").show(); // Hide restart button at end of step 6 if successful if (step == "7") { - $("#but_restart").prop("disabled", true); - $("#but_restart").hide(); + $("#but_restart").prop("disabled", true); + $("#but_restart").hide(); } } $("#step_result").html(""); diff --git a/install/install.queries.php b/install/install.queries.php index 85ac06f26..e25dfd5f2 100644 --- a/install/install.queries.php +++ b/install/install.queries.php @@ -516,7 +516,7 @@ function chmod_r($dir, $dirPermissions, $filePermissions) { `folder` varchar(300) NOT NULL, `author` varchar(50) NOT NULL, `renewal_period` tinyint(4) NOT NULL DEFAULT '0', - `timestamp` varchar(50) NOT NULL + `timestamp` varchar(50) DEFAULT NULL ) CHARSET=utf8;" ); } else if ($task == "roles_title") { @@ -723,26 +723,26 @@ function chmod_r($dir, $dirPermissions, $filePermissions) { $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `".$var['tbl_prefix']."users` WHERE login = 'admin'")); if ($tmp[0] == 0 || empty($tmp[0])) { $mysqli_result = mysqli_query($dbTmp, - "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES (NULL, 'admin', '".bCrypt($var['admin_pwd'],'13' )."', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')" + "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES ('1', 'admin', '".bCrypt($var['admin_pwd'],'13' )."', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')" ); } else { $mysqli_result = mysqli_query($dbTmp, "UPDATE `".$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'],'13' )."' WHERE login = 'admin' AND id = '1'"); } - - // check that API doesn't exist + + // check that API doesn't exist $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `".$var['tbl_prefix']."users` WHERE id = '9999999'")); if ($tmp[0] == 0 || empty($tmp[0])) { $mysqli_result = mysqli_query($dbTmp, "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `read_only`) VALUES ('9999999', 'API', '1')" ); - } + } } } // answer back if ($mysqli_result) { echo '[{"error" : "", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'", "table" : "'.$task.'"}]'; } else { - echo '[{"error" : "true", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'", "table" : "'.$task.'"}]'; + echo '[{"error" : "'.$mysqli_result.'", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'", "table" : "'.$task.'"}]'; } } else { echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]'; diff --git a/install/upgrade_run_2.1.26.php b/install/upgrade_run_2.1.26.php index 5b60813f1..7ca04a92f 100644 --- a/install/upgrade_run_2.1.26.php +++ b/install/upgrade_run_2.1.26.php @@ -162,6 +162,7 @@ function tableExists($tablename, $database = false) mysqli_query($dbTmp, "ALTER TABLE `".$_SESSION['tbl_prefix']."cache` MODIFY label VARCHAR(100)"); mysqli_query($dbTmp, "ALTER TABLE `".$_SESSION['tbl_prefix']."cache` MODIFY restricted_to DEFAULT NULL"); mysqli_query($dbTmp, "ALTER TABLE `".$_SESSION['tbl_prefix']."cache` MODIFY tags DEFAULT NULL"); +mysqli_query($dbTmp, "ALTER TABLE `".$_SESSION['tbl_prefix']."cache` MODIFY timestamp DEFAULT NULL"); // add Estonia mysqli_query($dbTmp, "INSERT INTO `".$_SESSION['tbl_prefix']."languages` VALUES (null, 'estonia', 'Estonia', 'ee', 'ee.png')"); diff --git a/items.load.php b/items.load.php index 53be0960a..ec44f9f9a 100644 --- a/items.load.php +++ b/items.load.php @@ -1180,6 +1180,11 @@ function(data) { $("#div_dialog_message").show(); return; } + + if (data.error != "") { + $("#div_dialog_message_text").html("An error appears. Answer from Server cannot be parsed!

    Returned data:
    "+data.error); + $("#div_dialog_message").show(); + } // reset password shown info $("#pw_shown").val("0"); diff --git a/sources/import.queries.php b/sources/import.queries.php index 7ced928c8..bc741de3f 100644 --- a/sources/import.queries.php +++ b/sources/import.queries.php @@ -309,7 +309,8 @@ function sanitiseString($str, $crLFReplacement) { 'perso' => $personalFolder == 0 ? 0 : 1, 'login' => $item[1], 'folder' => $data_fld['title'], - 'author' => $_SESSION['user_id'] + 'author' => $_SESSION['user_id'], + 'timestamp' => time() ) ); }