From 3c6af6d3f433070c3117fa0b605845099975746d Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 27 Jul 2021 19:33:44 +0200 Subject: [PATCH 1/6] Add ESLint and StyleLint --- .eslintrc.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ .stylelintrc | 3 +++ package.json | 13 +++++++--- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .stylelintrc diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..cc0f11863 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,73 @@ +module.exports = { + env: { + browser: true, + commonjs: true, + es2017: true, + node: true, + }, + extends: [ + "eslint:recommended", + "plugin:vue/vue3-recommended", + ], + parserOptions: { + ecmaVersion: 2018, + sourceType: "module", + }, + rules: { + // override/add rules settings here, such as: + // 'vue/no-unused-vars': 'error' + indent: ["error", 4], + quotes: ["warn", "double"], + //semi: ['off', 'never'], + "vue/html-indent": ["warn", 4], // default: 2 + "vue/max-attributes-per-line": "off", + "no-multi-spaces": ["error", { + ignoreEOLComments: true, + }], + "curly": "error", + "object-curly-spacing": ["error", "always"], + "object-curly-newline": ["error", { + "ObjectExpression": { + "minProperties": 1, + }, + "ObjectPattern": { + "multiline": true, + "minProperties": 2, + }, + "ImportDeclaration": { + "multiline": true, + }, + "ExportDeclaration": { + "multiline": true, + //'minProperties': 2, + }, + }], + "object-property-newline": "error", + "comma-spacing": "error", + "brace-style": "error", + "no-var": "error", + "key-spacing": "warn", + "keyword-spacing": "warn", + "space-infix-ops": "warn", + "arrow-spacing": "warn", + "no-trailing-spaces": "warn", + "space-before-blocks": "warn", + //'no-console': 'warn', + "no-extra-boolean-cast": "off", + "no-multiple-empty-lines": ["warn", { + "max": 1, + "maxBOF": 0, + }], + "lines-between-class-members": ["warn", "always", { + exceptAfterSingleLine: true, + }], + "no-unneeded-ternary": "error", + "no-else-return": ["error", { + "allowElseIf": false, + }], + "array-bracket-newline": ["error", "consistent"], + "eol-last": ["error", "always"], + //'prefer-template': 'error', + "comma-dangle": ["warn", "always-multiline"], + }, +} diff --git a/.stylelintrc b/.stylelintrc new file mode 100644 index 000000000..4d3d9d1f8 --- /dev/null +++ b/.stylelintrc @@ -0,0 +1,3 @@ +{ + "extends": "stylelint-config-recommended", +} diff --git a/package.json b/package.json index d4fe68885..7069e3edd 100644 --- a/package.json +++ b/package.json @@ -45,11 +45,16 @@ "vue-toastification": "^2.0.0-rc.1" }, "devDependencies": { - "@vitejs/plugin-legacy": "^1.4.4", - "@vitejs/plugin-vue": "^1.2.5", + "@vitejs/plugin-legacy": "^1.5.0", + "@vitejs/plugin-vue": "^1.3.0", "@vue/compiler-sfc": "^3.1.5", "core-js": "^3.15.2", - "sass": "^1.35.2", - "vite": "^2.4.2" + "eslint": "^7.31.0", + "eslint-plugin-vue": "^7.14.0", + "sass": "^1.36.0", + "stylelint": "^13.13.1", + "stylelint-config-recommended": "^5.0.0", + "stylelint-config-standard": "^22.0.0", + "vite": "^2.4.4" } } From 9648d700d7e6c8a8754ae7cbc0a4788354fa28f9 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 27 Jul 2021 19:47:13 +0200 Subject: [PATCH 2/6] Autofix on save --- server/auth.js | 16 +- server/model/heartbeat.js | 7 +- server/notification.js | 204 ++++---- server/password-hash.js | 8 +- server/ping-lite.js | 83 +-- server/server.js | 138 +++-- server/util-server.js | 17 +- server/util.js | 1 - src/App.vue | 4 +- src/components/Confirm.vue | 32 +- src/components/CountUp.vue | 22 +- src/components/Datetime.vue | 10 +- src/components/HeartbeatBar.vue | 71 ++- src/components/Login.vue | 19 +- src/components/NotificationDialog.vue | 265 +++++----- src/components/Status.vue | 20 +- src/components/Uptime.vue | 26 +- src/icon.js | 10 +- src/layouts/EmptyLayout.vue | 4 +- src/layouts/Layout.vue | 51 +- src/main.js | 57 +- src/mixins/socket.js | 56 +- src/pages/Dashboard.vue | 36 +- src/pages/DashboardHome.vue | 64 +-- src/pages/Details.vue | 101 ++-- src/pages/EditMonitor.vue | 129 +++-- src/pages/Settings.vue | 76 +-- src/pages/Setup.vue | 28 +- src/util-frontend.js | 716 +++++++++++++------------- 29 files changed, 1182 insertions(+), 1089 deletions(-) diff --git a/server/auth.js b/server/auth.js index b4d13d68a..54182bdef 100644 --- a/server/auth.js +++ b/server/auth.js @@ -1,6 +1,6 @@ -const basicAuth = require('express-basic-auth') -const passwordHash = require('./password-hash'); -const {R} = require("redbean-node"); +const basicAuth = require("express-basic-auth") +const passwordHash = require("./password-hash"); +const { R } = require("redbean-node"); /** * @@ -10,7 +10,7 @@ const {R} = require("redbean-node"); */ exports.login = async function (username, password) { let user = await R.findOne("user", " username = ? AND active = 1 ", [ - username + username, ]) if (user && passwordHash.verify(password, user.password)) { @@ -18,13 +18,13 @@ exports.login = async function (username, password) { if (passwordHash.needRehash(user.password)) { await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [ passwordHash.generate(password), - user.id + user.id, ]); } return user; - } else { - return null; } + + return null; } function myAuthorizer(username, password, callback) { @@ -36,5 +36,5 @@ function myAuthorizer(username, password, callback) { exports.basicAuth = basicAuth({ authorizer: myAuthorizer, authorizeAsync: true, - challenge: true + challenge: true, }); diff --git a/server/model/heartbeat.js b/server/model/heartbeat.js index 01fb71ff9..0e492ada1 100644 --- a/server/model/heartbeat.js +++ b/server/model/heartbeat.js @@ -1,10 +1,9 @@ const dayjs = require("dayjs"); -const utc = require('dayjs/plugin/utc') -var timezone = require('dayjs/plugin/timezone') +const utc = require("dayjs/plugin/utc") +let timezone = require("dayjs/plugin/timezone") dayjs.extend(utc) dayjs.extend(timezone) -const {BeanModel} = require("redbean-node/dist/bean-model"); - +const { BeanModel } = require("redbean-node/dist/bean-model"); /** * status: diff --git a/server/notification.js b/server/notification.js index 9da8a0dc8..f4cd08af9 100644 --- a/server/notification.js +++ b/server/notification.js @@ -1,6 +1,6 @@ const axios = require("axios"); -const {R} = require("redbean-node"); -const FormData = require('form-data'); +const { R } = require("redbean-node"); +const FormData = require("form-data"); const nodemailer = require("nodemailer"); const child_process = require("child_process"); @@ -24,7 +24,7 @@ class Notification { params: { chat_id: notification.telegramChatID, text: msg, - } + }, }) return okMsg; @@ -41,7 +41,7 @@ class Notification { await axios.post(`${notification.gotifyserverurl}/message?token=${notification.gotifyapplicationToken}`, { "message": msg, "priority": notification.gotifyPriority || 8, - "title": "Uptime-Kuma" + "title": "Uptime-Kuma", }) return okMsg; @@ -62,10 +62,10 @@ class Notification { if (notification.webhookContentType === "form-data") { finalData = new FormData(); - finalData.append('data', JSON.stringify(data)); + finalData.append("data", JSON.stringify(data)); config = { - headers: finalData.getHeaders() + headers: finalData.getHeaders(), } } else { @@ -84,63 +84,68 @@ class Notification { } else if (notification.type === "discord") { try { - // If heartbeatJSON is null, assume we're testing. - if(heartbeatJSON == null) { + // If heartbeatJSON is null, assume we're testing. + if (heartbeatJSON == null) { + let data = { + username: "Uptime-Kuma", + content: msg, + } + await axios.post(notification.discordWebhookUrl, data) + return okMsg; + } + // If heartbeatJSON is not null, we go into the normal alerting loop. + if (heartbeatJSON["status"] == 0) { + var alertColor = "16711680"; + } else if (heartbeatJSON["status"] == 1) { + var alertColor = "65280"; + } let data = { - username: 'Uptime-Kuma', - content: msg + username: "Uptime-Kuma", + embeds: [{ + title: "Uptime-Kuma Alert", + color: alertColor, + fields: [ + { + name: "Time (UTC)", + value: heartbeatJSON["time"], + }, + { + name: "Message", + value: msg, + }, + ], + }], } await axios.post(notification.discordWebhookUrl, data) return okMsg; - } - // If heartbeatJSON is not null, we go into the normal alerting loop. - if(heartbeatJSON['status'] == 0) { - var alertColor = "16711680"; - } else if(heartbeatJSON['status'] == 1) { - var alertColor = "65280"; - } - let data = { - username: 'Uptime-Kuma', - embeds: [{ - title: "Uptime-Kuma Alert", - color: alertColor, - fields: [ - { - name: "Time (UTC)", - value: heartbeatJSON["time"] - }, - { - name: "Message", - value: msg - } - ] - }] - } - await axios.post(notification.discordWebhookUrl, data) - return okMsg; - } catch(error) { - throwGeneralAxiosError(error) + } catch (error) { + throwGeneralAxiosError(error) } } else if (notification.type === "signal") { - try { - let data = { - "message": msg, - "number": notification.signalNumber, - "recipients": notification.signalRecipients.replace(/\s/g, '').split(",") - }; - let config = {}; + try { + let data = { + "message": msg, + "number": notification.signalNumber, + "recipients": notification.signalRecipients.replace(/\s/g, "").split(","), + }; + let config = {}; - await axios.post(notification.signalURL, data, config) - return okMsg; - } catch (error) { - throwGeneralAxiosError(error) - } + await axios.post(notification.signalURL, data, config) + return okMsg; + } catch (error) { + throwGeneralAxiosError(error) + } } else if (notification.type === "slack") { try { if (heartbeatJSON == null) { - let data = {'text': "Uptime Kuma Slack testing successful.", 'channel': notification.slackchannel, 'username': notification.slackusername, 'icon_emoji': notification.slackiconemo} + let data = { + "text": "Uptime Kuma Slack testing successful.", + "channel": notification.slackchannel, + "username": notification.slackusername, + "icon_emoji": notification.slackiconemo, + } await axios.post(notification.slackwebhookURL, data) return okMsg; } @@ -148,44 +153,42 @@ class Notification { const time = heartbeatJSON["time"]; let data = { "text": "Uptime Kuma Alert", - "channel":notification.slackchannel, + "channel": notification.slackchannel, "username": notification.slackusername, "icon_emoji": notification.slackiconemo, "blocks": [{ - "type": "header", - "text": { - "type": "plain_text", - "text": "Uptime Kuma Alert" - } + "type": "header", + "text": { + "type": "plain_text", + "text": "Uptime Kuma Alert", + }, + }, + { + "type": "section", + "fields": [{ + "type": "mrkdwn", + "text": "*Message*\n" + msg, }, { - "type": "section", - "fields": [{ - "type": "mrkdwn", - "text": '*Message*\n'+msg + "type": "mrkdwn", + "text": "*Time (UTC)*\n" + time, + }], + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Visit Uptime Kuma", }, - { - "type": "mrkdwn", - "text": "*Time (UTC)*\n"+time - } - ] - }, - { - "type": "actions", - "elements": [ - { - "type": "button", - "text": { - "type": "plain_text", - "text": "Visit Uptime Kuma", - }, - "value": "Uptime-Kuma", - "url": notification.slackbutton || "https://github.com/louislam/uptime-kuma" - } - ] - } - ] - } + "value": "Uptime-Kuma", + "url": notification.slackbutton || "https://github.com/louislam/uptime-kuma", + }, + ], + }], + } await axios.post(notification.slackwebhookURL, data) return okMsg; } catch (error) { @@ -193,27 +196,35 @@ class Notification { } } else if (notification.type === "pushover") { - var pushoverlink = 'https://api.pushover.net/1/messages.json' + let pushoverlink = "https://api.pushover.net/1/messages.json" try { if (heartbeatJSON == null) { - let data = {'message': "Uptime Kuma Pushover testing successful.", - 'user': notification.pushoveruserkey, 'token': notification.pushoverapptoken, 'sound':notification.pushoversounds, - 'priority': notification.pushoverpriority, 'title':notification.pushovertitle, 'retry': "30", 'expire':"3600", 'html': 1} + let data = { + "message": "Uptime Kuma Pushover testing successful.", + "user": notification.pushoveruserkey, + "token": notification.pushoverapptoken, + "sound": notification.pushoversounds, + "priority": notification.pushoverpriority, + "title": notification.pushovertitle, + "retry": "30", + "expire": "3600", + "html": 1, + } await axios.post(pushoverlink, data) return okMsg; } let data = { - "message": "Uptime Kuma Alert\n\nMessage:"+msg+ '\nTime (UTC):' +heartbeatJSON["time"], - "user":notification.pushoveruserkey, + "message": "Uptime Kuma Alert\n\nMessage:" + msg + "\nTime (UTC):" + heartbeatJSON["time"], + "user": notification.pushoveruserkey, "token": notification.pushoverapptoken, "sound": notification.pushoversounds, "priority": notification.pushoverpriority, "title": notification.pushovertitle, "retry": "30", "expire": "3600", - "html": 1 - } + "html": 1, + } await axios.post(pushoverlink, data) return okMsg; } catch (error) { @@ -291,24 +302,23 @@ class Notification { static async apprise(notification, msg) { let s = child_process.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL]) - - let output = (s.stdout) ? s.stdout.toString() : 'ERROR: maybe apprise not found'; + let output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found"; if (output) { if (! output.includes("ERROR")) { return "Sent Successfully"; - } else { - throw new Error(output) } + throw new Error(output) + } else { return "" } } static checkApprise() { - let commandExistsSync = require('command-exists').sync; - let exists = commandExistsSync('apprise'); + let commandExistsSync = require("command-exists").sync; + let exists = commandExistsSync("apprise"); return exists; } diff --git a/server/password-hash.js b/server/password-hash.js index 39bc0c20c..52e26b959 100644 --- a/server/password-hash.js +++ b/server/password-hash.js @@ -1,5 +1,5 @@ -const passwordHashOld = require('password-hash'); -const bcrypt = require('bcrypt'); +const passwordHashOld = require("password-hash"); +const bcrypt = require("bcrypt"); const saltRounds = 10; exports.generate = function (password) { @@ -9,9 +9,9 @@ exports.generate = function (password) { exports.verify = function (password, hash) { if (isSHA1(hash)) { return passwordHashOld.verify(password, hash) - } else { - return bcrypt.compareSync(password, hash); } + + return bcrypt.compareSync(password, hash); } function isSHA1(hash) { diff --git a/server/ping-lite.js b/server/ping-lite.js index e290d8876..337bc0d3d 100644 --- a/server/ping-lite.js +++ b/server/ping-lite.js @@ -1,9 +1,9 @@ // https://github.com/ben-bradley/ping-lite/blob/master/ping-lite.js // Fixed on Windows -var spawn = require('child_process').spawn, - events = require('events'), - fs = require('fs'), +let spawn = require("child_process").spawn, + events = require("events"), + fs = require("fs"), WIN = /^win/.test(process.platform), LIN = /^linux/.test(process.platform), MAC = /^darwin/.test(process.platform); @@ -11,8 +11,9 @@ var spawn = require('child_process').spawn, module.exports = Ping; function Ping(host, options) { - if (!host) - throw new Error('You must specify a host to ping!'); + if (!host) { + throw new Error("You must specify a host to ping!"); + } this._host = host; this._options = options = (options || {}); @@ -20,26 +21,24 @@ function Ping(host, options) { events.EventEmitter.call(this); if (WIN) { - this._bin = 'c:/windows/system32/ping.exe'; - this._args = (options.args) ? options.args : [ '-n', '1', '-w', '5000', host ]; + this._bin = "c:/windows/system32/ping.exe"; + this._args = (options.args) ? options.args : [ "-n", "1", "-w", "5000", host ]; this._regmatch = /[><=]([0-9.]+?)ms/; - } - else if (LIN) { - this._bin = '/bin/ping'; - this._args = (options.args) ? options.args : [ '-n', '-w', '2', '-c', '1', host ]; + } else if (LIN) { + this._bin = "/bin/ping"; + this._args = (options.args) ? options.args : [ "-n", "-w", "2", "-c", "1", host ]; this._regmatch = /=([0-9.]+?) ms/; // need to verify this - } - else if (MAC) { - this._bin = '/sbin/ping'; - this._args = (options.args) ? options.args : [ '-n', '-t', '2', '-c', '1', host ]; + } else if (MAC) { + this._bin = "/sbin/ping"; + this._args = (options.args) ? options.args : [ "-n", "-t", "2", "-c", "1", host ]; this._regmatch = /=([0-9.]+?) ms/; - } - else { - throw new Error('Could not detect your ping binary.'); + } else { + throw new Error("Could not detect your ping binary."); } - if (!fs.existsSync(this._bin)) - throw new Error('Could not detect '+this._bin+' on your system'); + if (!fs.existsSync(this._bin)) { + throw new Error("Could not detect " + this._bin + " on your system"); + } this._i = 0; @@ -51,48 +50,56 @@ Ping.prototype.__proto__ = events.EventEmitter.prototype; // SEND A PING // =========== Ping.prototype.send = function(callback) { - var self = this; + let self = this; callback = callback || function(err, ms) { - if (err) return self.emit('error', err); - else return self.emit('result', ms); + if (err) { + return self.emit("error", err); + } + return self.emit("result", ms); }; - var _ended, _exited, _errored; + let _ended, _exited, _errored; this._ping = spawn(this._bin, this._args); // spawn the binary - this._ping.on('error', function(err) { // handle binary errors + this._ping.on("error", function(err) { // handle binary errors _errored = true; callback(err); }); - this._ping.stdout.on('data', function(data) { // log stdout - this._stdout = (this._stdout || '') + data; + this._ping.stdout.on("data", function(data) { // log stdout + this._stdout = (this._stdout || "") + data; }); - this._ping.stdout.on('end', function() { + this._ping.stdout.on("end", function() { _ended = true; - if (_exited && !_errored) onEnd.call(self._ping); + if (_exited && !_errored) { + onEnd.call(self._ping); + } }); - this._ping.stderr.on('data', function(data) { // log stderr - this._stderr = (this._stderr || '') + data; + this._ping.stderr.on("data", function(data) { // log stderr + this._stderr = (this._stderr || "") + data; }); - this._ping.on('exit', function(code) { // handle complete + this._ping.on("exit", function(code) { // handle complete _exited = true; - if (_ended && !_errored) onEnd.call(self._ping); + if (_ended && !_errored) { + onEnd.call(self._ping); + } }); function onEnd() { - var stdout = this.stdout._stdout, + let stdout = this.stdout._stdout, stderr = this.stderr._stderr, ms; - if (stderr) + if (stderr) { return callback(new Error(stderr)); - else if (!stdout) - return callback(new Error('No stdout detected')); + } + if (!stdout) { + return callback(new Error("No stdout detected")); + } ms = stdout.match(self._regmatch); // parse out the ##ms response ms = (ms && ms[1]) ? Number(ms[1]) : ms; @@ -104,7 +111,7 @@ Ping.prototype.send = function(callback) { // CALL Ping#send(callback) ON A TIMER // =================================== Ping.prototype.start = function(callback) { - var self = this; + let self = this; this._i = setInterval(function() { self.send(callback); }, (self._options.interval || 5000)); diff --git a/server/server.js b/server/server.js index 2014d927f..5b76b7966 100644 --- a/server/server.js +++ b/server/server.js @@ -1,23 +1,23 @@ console.log("Welcome to Uptime Kuma ") console.log("Importing libraries") -const express = require('express'); -const http = require('http'); +const express = require("express"); +const http = require("http"); const { Server } = require("socket.io"); const dayjs = require("dayjs"); -const {R} = require("redbean-node"); -const jwt = require('jsonwebtoken'); +const { R } = require("redbean-node"); +const jwt = require("jsonwebtoken"); const Monitor = require("./model/monitor"); const fs = require("fs"); -const {getSettings} = require("./util-server"); -const {Notification} = require("./notification") -const gracefulShutdown = require('http-graceful-shutdown'); +const { getSettings } = require("./util-server"); +const { Notification } = require("./notification") +const gracefulShutdown = require("http-graceful-shutdown"); const Database = require("./database"); -const {sleep} = require("./util"); -const args = require('args-parser')(process.argv); -const prometheusAPIMetrics = require('prometheus-api-metrics'); +const { sleep } = require("./util"); +const args = require("args-parser")(process.argv); +const prometheusAPIMetrics = require("prometheus-api-metrics"); const { basicAuth } = require("./auth"); -const {login} = require("./auth"); -const version = require('../package.json').version; +const { login } = require("./auth"); +const version = require("../package.json").version; const hostname = args.host || "0.0.0.0" const port = args.port || 3001 @@ -63,12 +63,12 @@ let needSetup = false; // Normal Router here - app.use('/', express.static("dist")); + app.use("/", express.static("dist")); // Basic Auth Router here // For testing - basicAuthRouter.get('/test-auth', (req, res) => { + basicAuthRouter.get("/test-auth", (req, res) => { res.end("OK") }); @@ -77,12 +77,12 @@ let needSetup = false; basicAuthRouter.use(prometheusAPIMetrics()) // Universal Route Handler, must be at the end - app.get('*', function(request, response, next) { - response.sendFile(process.cwd() + '/dist/index.html'); + app.get("*", function(request, response, next) { + response.sendFile(process.cwd() + "/dist/index.html"); }); console.log("Adding socket handler") - io.on('connection', async (socket) => { + io.on("connection", async (socket) => { socket.emit("info", { version, @@ -95,7 +95,7 @@ let needSetup = false; socket.emit("setup") } - socket.on('disconnect', () => { + socket.on("disconnect", () => { totalClient--; }); @@ -109,7 +109,7 @@ let needSetup = false; console.log("Username from JWT: " + decoded.username) let user = await R.findOne("user", " username = ? AND active = 1 ", [ - decoded.username + decoded.username, ]) if (user) { @@ -121,13 +121,13 @@ let needSetup = false; } else { callback({ ok: false, - msg: "The user is inactive or deleted." + msg: "The user is inactive or deleted.", }) } } catch (error) { callback({ ok: false, - msg: "Invalid token." + msg: "Invalid token.", }) } @@ -144,13 +144,13 @@ let needSetup = false; callback({ ok: true, token: jwt.sign({ - username: data.username - }, jwtSecret) + username: data.username, + }, jwtSecret), }) } else { callback({ ok: false, - msg: "Incorrect username or password." + msg: "Incorrect username or password.", }) } @@ -181,13 +181,13 @@ let needSetup = false; callback({ ok: true, - msg: "Added Successfully." + msg: "Added Successfully.", }); } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -214,13 +214,13 @@ let needSetup = false; callback({ ok: true, msg: "Added Successfully.", - monitorID: bean.id + monitorID: bean.id, }); } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -257,14 +257,14 @@ let needSetup = false; callback({ ok: true, msg: "Saved.", - monitorID: bean.id + monitorID: bean.id, }); } catch (e) { console.error(e) callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -288,7 +288,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -302,13 +302,13 @@ let needSetup = false; callback({ ok: true, - msg: "Resumed Successfully." + msg: "Resumed Successfully.", }); } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -321,14 +321,13 @@ let needSetup = false; callback({ ok: true, - msg: "Paused Successfully." + msg: "Paused Successfully.", }); - } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -346,12 +345,12 @@ let needSetup = false; await R.exec("DELETE FROM monitor WHERE id = ? AND user_id = ? ", [ monitorID, - socket.userID + socket.userID, ]); callback({ ok: true, - msg: "Deleted Successfully." + msg: "Deleted Successfully.", }); await sendMonitorList(socket); @@ -359,7 +358,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -373,19 +372,19 @@ let needSetup = false; } let user = await R.findOne("user", " id = ? AND active = 1 ", [ - socket.userID + socket.userID, ]) if (user && passwordHash.verify(password.currentPassword, user.password)) { await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [ passwordHash.generate(password.newPassword), - socket.userID + socket.userID, ]); callback({ ok: true, - msg: "Password has been updated successfully." + msg: "Password has been updated successfully.", }) } else { throw new Error("Incorrect current password") @@ -394,7 +393,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -403,7 +402,6 @@ let needSetup = false; try { checkLogin(socket) - callback({ ok: true, data: await getSettings(type), @@ -412,7 +410,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -433,7 +431,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -453,7 +451,7 @@ let needSetup = false; } catch (e) { callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -466,7 +464,7 @@ let needSetup = false; callback({ ok: true, - msg + msg, }); } catch (e) { @@ -474,7 +472,7 @@ let needSetup = false; callback({ ok: false, - msg: e.message + msg: e.message, }); } }); @@ -499,7 +497,7 @@ let needSetup = false; async function updateMonitorNotification(monitorID, notificationIDList) { R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [ - monitorID + monitorID, ]) for (let notificationID in notificationIDList) { @@ -532,7 +530,7 @@ async function sendMonitorList(socket) { async function sendNotificationList(socket) { let result = []; let list = await R.find("notification", " user_id = ? ", [ - socket.userID + socket.userID, ]); for (let bean of list) { @@ -562,7 +560,7 @@ async function getMonitorJSONList(userID) { let result = {}; let monitorList = await R.find("monitor", " user_id = ? ", [ - userID + userID, ]) for (let monitor of monitorList) { @@ -585,8 +583,8 @@ async function initDatabase() { } console.log("Connecting to Database") - R.setup('sqlite', { - filename: Database.path + R.setup("sqlite", { + filename: Database.path, }); console.log("Connected") @@ -598,7 +596,7 @@ async function initDatabase() { await R.autoloadModels("./server/model"); let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [ - "jwtSecret" + "jwtSecret", ]); if (! jwtSecretBean) { @@ -629,11 +627,11 @@ async function startMonitor(userID, monitorID) { await R.exec("UPDATE monitor SET active = 1 WHERE id = ? AND user_id = ? ", [ monitorID, - userID + userID, ]); let monitor = await R.findOne("monitor", " id = ? ", [ - monitorID + monitorID, ]) if (monitor.id in monitorList) { @@ -655,7 +653,7 @@ async function pauseMonitor(userID, monitorID) { await R.exec("UPDATE monitor SET active = 0 WHERE id = ? AND user_id = ? ", [ monitorID, - userID + userID, ]); if (monitorID in monitorList) { @@ -684,13 +682,13 @@ async function sendHeartbeatList(socket, monitorID) { ORDER BY time DESC LIMIT 100 `, [ - monitorID + monitorID, ]) let result = []; for (let bean of list) { - result.unshift(bean.toJSON()) + result.unshift(bean.toJSON()) } socket.emit("heartbeatList", monitorID, result) @@ -703,23 +701,20 @@ async function sendImportantHeartbeatList(socket, monitorID) { ORDER BY time DESC LIMIT 500 `, [ - monitorID + monitorID, ]) socket.emit("importantHeartbeatList", monitorID, list) } - - const startGracefulShutdown = async () => { - console.log('Shutdown requested'); - + console.log("Shutdown requested"); await (new Promise((resolve) => { server.close(async function () { - console.log('Stopped Express.'); + console.log("Stopped Express."); process.exit(0) - setTimeout(async () =>{ + setTimeout(async () => { await R.close(); console.log("Stopped DB") @@ -729,11 +724,10 @@ const startGracefulShutdown = async () => { }); })); - } async function shutdownFunction(signal) { - console.log('Called signal: ' + signal); + console.log("Called signal: " + signal); console.log("Stopping all monitors") for (let id in monitorList) { @@ -745,14 +739,14 @@ async function shutdownFunction(signal) { } function finalFunction() { - console.log('Graceful Shutdown') + console.log("Graceful Shutdown") } gracefulShutdown(server, { - signals: 'SIGINT SIGTERM', + signals: "SIGINT SIGTERM", timeout: 30000, // timeout: 30 secs development: false, // not in dev mode forceExit: true, // triggers process.exit() at the end of shutdown process onShutdown: shutdownFunction, // shutdown function (async) - e.g. for cleanup DB, ... - finally: finalFunction // finally function (sync) - e.g. for logging + finally: finalFunction, // finally function (sync) - e.g. for logging }); diff --git a/server/util-server.js b/server/util-server.js index f03823d3a..43aa5ccfb 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -1,6 +1,6 @@ -const tcpp = require('tcp-ping'); +const tcpp = require("tcp-ping"); const Ping = require("./ping-lite"); -const {R} = require("redbean-node"); +const { R } = require("redbean-node"); exports.tcping = function (hostname, port) { return new Promise((resolve, reject) => { @@ -41,13 +41,13 @@ exports.ping = function (hostname) { exports.setting = async function (key) { return await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [ - key + key, ]) } exports.setSetting = async function (key, value) { let bean = await R.findOne("setting", " `key` = ? ", [ - key + key, ]) if (! bean) { bean = R.dispense("setting") @@ -59,7 +59,7 @@ exports.setSetting = async function (key, value) { exports.getSettings = async function (type) { let list = await R.getAll("SELECT * FROM setting WHERE `type` = ? ", [ - type + type, ]) let result = {}; @@ -71,7 +71,6 @@ exports.getSettings = async function (type) { return result; } - // ssl-checker by @dyaa // param: res - response object from axios // return an object containing the certificate information @@ -97,7 +96,9 @@ exports.checkCertificate = function (res) { } = res.request.res.socket.getPeerCertificate(false); if (!valid_from || !valid_to || !subjectaltname) { - throw { message: 'No TLS certificate in response' }; + throw { + message: "No TLS certificate in response", + }; } const valid = res.request.res.socket.authorized || false; @@ -118,4 +119,4 @@ exports.checkCertificate = function (res) { issuer, fingerprint, }; -} \ No newline at end of file +} diff --git a/server/util.js b/server/util.js index 081561bf9..6e90dc42b 100644 --- a/server/util.js +++ b/server/util.js @@ -23,4 +23,3 @@ exports.debug = (msg) => { console.log(msg) } } - diff --git a/src/App.vue b/src/App.vue index 1f05560e6..974757a63 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,9 +3,7 @@ diff --git a/src/components/Confirm.vue b/src/components/Confirm.vue index ecf165a00..36d3781a6 100644 --- a/src/components/Confirm.vue +++ b/src/components/Confirm.vue @@ -50,7 +50,3 @@ export default { }, } - - diff --git a/src/components/CountUp.vue b/src/components/CountUp.vue index 1d2a4c556..c63aea14b 100644 --- a/src/components/CountUp.vue +++ b/src/components/CountUp.vue @@ -12,11 +12,11 @@ export default { props: { value: [String, Number], time: { - Number, + type: Number, default: 0.3, }, unit: { - String, + type: String, default: "ms", }, }, @@ -61,7 +61,3 @@ export default { } - - diff --git a/src/components/Datetime.vue b/src/components/Datetime.vue index 365e9fca3..84093afb1 100644 --- a/src/components/Datetime.vue +++ b/src/components/Datetime.vue @@ -35,7 +35,3 @@ export default { }, } - - diff --git a/src/components/HeartbeatBar.vue b/src/components/HeartbeatBar.vue index 7ee94317d..bfcb90850 100644 --- a/src/components/HeartbeatBar.vue +++ b/src/components/HeartbeatBar.vue @@ -69,7 +69,7 @@ export default { let width if (this.maxBeat > 0) { width = (this.beatWidth + this.beatMargin * 2) * this.maxBeat + (leftRight * 2) + "px" - } { + } else { width = "100%" } diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 3adbe4af1..83a0d1800 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -496,7 +496,3 @@ export default { }, } - - diff --git a/src/components/Status.vue b/src/components/Status.vue index c0549821b..a8f2ea596 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -17,8 +17,8 @@ export default { } if (this.status === 2) { return "warning" } - return "secondary" + return "secondary" }, text() { @@ -29,8 +29,8 @@ export default { } if (this.status === 2) { return "Pending" } - return "Unknown" + return "Unknown" }, }, } diff --git a/src/components/Uptime.vue b/src/components/Uptime.vue index e9c6f5830..411ff95d5 100644 --- a/src/components/Uptime.vue +++ b/src/components/Uptime.vue @@ -8,7 +8,7 @@ export default { monitor: Object, type: String, pill: { - Boolean, + type: Boolean, default: false, }, }, @@ -57,7 +57,3 @@ export default { }, } - - diff --git a/src/layouts/EmptyLayout.vue b/src/layouts/EmptyLayout.vue index 6f9965873..a16d42085 100644 --- a/src/layouts/EmptyLayout.vue +++ b/src/layouts/EmptyLayout.vue @@ -5,7 +5,3 @@ - - diff --git a/src/main.js b/src/main.js index e76db1edf..6eb296dc2 100644 --- a/src/main.js +++ b/src/main.js @@ -91,4 +91,3 @@ app.use(Toast, options); app.component("FontAwesomeIcon", FontAwesomeIcon) app.mount("#app") - diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 85cb4e2c3..585b929ea 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -254,8 +254,8 @@ export default { if (this.userTimezone === "auto") { return dayjs.tz.guess() } - return this.userTimezone + return this.userTimezone }, lastHeartbeatList() { @@ -322,4 +322,3 @@ export default { }, } - diff --git a/src/pages/DashboardHome.vue b/src/pages/DashboardHome.vue index 657a3a490..1fd4f6028 100644 --- a/src/pages/DashboardHome.vue +++ b/src/pages/DashboardHome.vue @@ -146,7 +146,9 @@ export default { result.sort((a, b) => { if (a.time > b.time) { return -1; - } if (a.time < b.time) { + } + + if (a.time < b.time) { return 1; } diff --git a/src/pages/Details.vue b/src/pages/Details.vue index a83e238fc..20ce046df 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -45,7 +45,7 @@
-

Avg.{{ pingTitle }}

+

Avg. {{ pingTitle }}

(24-hour)

@@ -61,7 +61,7 @@
-

CertExp.

+

Cert Exp.

()

{{ certInfo.daysRemaining }} days From d97091af5173a93e6a3e231eb23f8e446dc4198b Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 27 Jul 2021 20:02:20 +0200 Subject: [PATCH 4/6] Missing this --- server/notification.js | 2 +- server/ping-lite.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/notification.js b/server/notification.js index f4cd08af9..f25ca80a7 100644 --- a/server/notification.js +++ b/server/notification.js @@ -309,8 +309,8 @@ class Notification { if (! output.includes("ERROR")) { return "Sent Successfully"; } - throw new Error(output) + throw new Error(output) } else { return "" } diff --git a/server/ping-lite.js b/server/ping-lite.js index 337bc0d3d..0b9a7401a 100644 --- a/server/ping-lite.js +++ b/server/ping-lite.js @@ -97,6 +97,7 @@ Ping.prototype.send = function(callback) { if (stderr) { return callback(new Error(stderr)); } + if (!stdout) { return callback(new Error("No stdout detected")); } From be1fc0c2b66ccd5db5de5ca65e4acd76aae9e362 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 27 Jul 2021 20:03:53 +0200 Subject: [PATCH 5/6] Missing this part 2 --- src/components/Status.vue | 16 ++++++++++++---- src/components/Uptime.vue | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/Status.vue b/src/components/Status.vue index a8f2ea596..ff430558e 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -12,9 +12,13 @@ export default { color() { if (this.status === 0) { return "danger" - } if (this.status === 1) { + } + + if (this.status === 1) { return "primary" - } if (this.status === 2) { + } + + if (this.status === 2) { return "warning" } @@ -24,9 +28,13 @@ export default { text() { if (this.status === 0) { return "Down" - } if (this.status === 1) { + } + + if (this.status === 1) { return "Up" - } if (this.status === 2) { + } + + if (this.status === 2) { return "Pending" } diff --git a/src/components/Uptime.vue b/src/components/Uptime.vue index 411ff95d5..393496238 100644 --- a/src/components/Uptime.vue +++ b/src/components/Uptime.vue @@ -28,9 +28,13 @@ export default { color() { if (this.lastHeartBeat.status === 0) { return "danger" - } if (this.lastHeartBeat.status === 1) { + } + + if (this.lastHeartBeat.status === 1) { return "primary" - } if (this.lastHeartBeat.status === 2) { + } + + if (this.lastHeartBeat.status === 2) { return "warning" } From d54bc866b4c0d5b452468610757c794a0d7f0155 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 27 Jul 2021 22:23:46 +0200 Subject: [PATCH 6/6] Fix block-no-empty error from Stylelint --- src/layouts/Layout.vue | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index 546c0ffe0..8e725500a 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -155,10 +155,6 @@ export default { color: white; } -main { - -} - footer { color: #AAA; font-size: 13px;