diff --git a/package-lock.json b/package-lock.json index 6ba2b32ab..3d389ac5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "mongodb": "~4.17.1", "mqtt": "~4.3.7", "mssql": "~8.1.4", - "mysql2": "~2.3.3", + "mysql2": "~3.6.2", "nanoid": "~3.3.4", "node-cloudflared-tunnel": "~1.0.9", "node-radius-client": "~1.0.0", @@ -14418,16 +14418,16 @@ } }, "node_modules/mysql2": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.3.3.tgz", - "integrity": "sha512-wxJUev6LgMSgACDkb/InIFxDprRa6T95+VEoR+xPvtngtccNH2dGjEB/fVZ8yg1gWv1510c9CvXuJHi5zUm0ZA==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.2.tgz", + "integrity": "sha512-m5erE6bMoWfPXW1D5UrVwlT8PowAoSX69KcZzPuARQ3wY1RJ52NW9PdvdPo076XiSIkQ5IBTis7hxdlrQTlyug==", "dependencies": { - "denque": "^2.0.1", + "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", - "long": "^4.0.0", - "lru-cache": "^6.0.0", - "named-placeholders": "^1.1.2", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" }, @@ -14435,27 +14435,14 @@ "node": ">= 8.0" } }, - "node_modules/mysql2/node_modules/long": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", - "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" - }, "node_modules/mysql2/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dependencies": { - "yallist": "^4.0.0" - }, + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", "engines": { - "node": ">=10" + "node": ">=16.14" } }, - "node_modules/mysql2/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, "node_modules/named-placeholders": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", diff --git a/package.json b/package.json index 21f01fe39..141283f5a 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "simple-mqtt-server": "node extra/simple-mqtt-server.js", "simple-mongo": "docker run --rm -p 27017:27017 mongo", "simple-postgres": "docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres", + "simple-mariadb": "docker run --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mariadb# mariadb", "update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix", "ncu-patch": "npm-check-updates -u -t patch", "release-final": "node ./extra/test-docker.js && node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js", @@ -113,7 +114,7 @@ "mongodb": "~4.17.1", "mqtt": "~4.3.7", "mssql": "~8.1.4", - "mysql2": "~2.3.3", + "mysql2": "~3.6.2", "nanoid": "~3.3.4", "node-cloudflared-tunnel": "~1.0.9", "node-radius-client": "~1.0.0", diff --git a/server/model/monitor.js b/server/model/monitor.js index c83ece49e..7fffe630c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -756,7 +756,7 @@ class Monitor extends BeanModel { } else if (this.type === "sqlserver") { let startTime = dayjs().valueOf(); - await mssqlQuery(this.databaseConnectionString, this.databaseQuery); + await mssqlQuery(this.databaseConnectionString, this.databaseQuery || "SELECT 1"); bean.msg = ""; bean.status = UP; @@ -795,7 +795,7 @@ class Monitor extends BeanModel { } else if (this.type === "postgres") { let startTime = dayjs().valueOf(); - await postgresQuery(this.databaseConnectionString, this.databaseQuery); + await postgresQuery(this.databaseConnectionString, this.databaseQuery || "SELECT 1"); bean.msg = ""; bean.status = UP; @@ -803,7 +803,11 @@ class Monitor extends BeanModel { } else if (this.type === "mysql") { let startTime = dayjs().valueOf(); - bean.msg = await mysqlQuery(this.databaseConnectionString, this.databaseQuery); + // Use `radius_password` as `password` field, since there are too many unnecessary fields + // TODO: rename `radius_password` to `password` later for general use + let mysqlPassword = this.radiusPassword; + + bean.msg = await mysqlQuery(this.databaseConnectionString, this.databaseQuery || "SELECT 1", mysqlPassword); bean.status = UP; bean.ping = dayjs().valueOf() - startTime; } else if (this.type === "mongodb") { diff --git a/server/util-server.js b/server/util-server.js index 9e4946e60..bab804053 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -468,11 +468,15 @@ exports.postgresQuery = function (connectionString, query) { * Run a query on MySQL/MariaDB * @param {string} connectionString The database connection string * @param {string} query The query to validate the database with + * @param {?string} password The password to use * @returns {Promise<(string)>} */ -exports.mysqlQuery = function (connectionString, query) { +exports.mysqlQuery = function (connectionString, query, password = undefined) { return new Promise((resolve, reject) => { - const connection = mysql.createConnection(connectionString); + const connection = mysql.createConnection({ + uri: connectionString, + password + }); connection.on("error", (err) => { reject(err); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 1f64172d9..1a02832c1 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -370,6 +370,15 @@ + + +