Enforce semicolon, fix format globally

pull/1477/head^2
Louis Lam 2022-04-14 00:30:32 +08:00
parent 6f72ca481f
commit 649f3106e1
50 changed files with 184 additions and 198 deletions

View File

@ -1,4 +1,9 @@
module.exports = { module.exports = {
ignorePatterns: [
"test/*",
"server/modules/apicache/*",
"src/util.js"
],
root: true, root: true,
env: { env: {
browser: true, browser: true,
@ -34,7 +39,7 @@ module.exports = {
}, },
], ],
quotes: ["warn", "double"], quotes: ["warn", "double"],
semi: "warn", semi: "error",
"vue/html-indent": ["warn", 4], // default: 2 "vue/html-indent": ["warn", 4], // default: 2
"vue/max-attributes-per-line": "off", "vue/max-attributes-per-line": "off",
"vue/singleline-html-element-content-newline": "off", "vue/singleline-html-element-content-newline": "off",

View File

@ -3,4 +3,4 @@ module.exports = {
name: "uptime-kuma", name: "uptime-kuma",
script: "./server/server.js", script: "./server/server.js",
}] }]
} };

View File

@ -1,6 +1,6 @@
const pkg = require("../../package.json"); const pkg = require("../../package.json");
const fs = require("fs"); const fs = require("fs");
const child_process = require("child_process"); const childProcess = require("child_process");
const util = require("../../src/util"); const util = require("../../src/util");
util.polyfill(); util.polyfill();
@ -32,7 +32,7 @@ if (! exists) {
function commit(version) { function commit(version) {
let msg = "Update to " + version; let msg = "Update to " + version;
let res = child_process.spawnSync("git", ["commit", "-m", msg, "-a"]); let res = childProcess.spawnSync("git", ["commit", "-m", msg, "-a"]);
let stdout = res.stdout.toString().trim(); let stdout = res.stdout.toString().trim();
console.log(stdout); console.log(stdout);
@ -40,15 +40,15 @@ function commit(version) {
throw new Error("commit error"); throw new Error("commit error");
} }
res = child_process.spawnSync("git", ["push", "origin", "master"]); res = childProcess.spawnSync("git", ["push", "origin", "master"]);
console.log(res.stdout.toString().trim()); console.log(res.stdout.toString().trim());
} }
function tag(version) { function tag(version) {
let res = child_process.spawnSync("git", ["tag", version]); let res = childProcess.spawnSync("git", ["tag", version]);
console.log(res.stdout.toString().trim()); console.log(res.stdout.toString().trim());
res = child_process.spawnSync("git", ["push", "origin", version]); res = childProcess.spawnSync("git", ["push", "origin", version]);
console.log(res.stdout.toString().trim()); console.log(res.stdout.toString().trim());
} }
@ -57,7 +57,7 @@ function tagExists(version) {
throw new Error("invalid version"); throw new Error("invalid version");
} }
let res = child_process.spawnSync("git", ["tag", "-l", version]); let res = childProcess.spawnSync("git", ["tag", "-l", version]);
return res.stdout.toString().trim() === version; return res.stdout.toString().trim() === version;
} }

View File

@ -4,21 +4,21 @@ const util = require("../src/util");
util.polyfill(); util.polyfill();
const oldVersion = pkg.version const oldVersion = pkg.version;
const newVersion = oldVersion + "-nightly" const newVersion = oldVersion + "-nightly";
console.log("Old Version: " + oldVersion) console.log("Old Version: " + oldVersion);
console.log("New Version: " + newVersion) console.log("New Version: " + newVersion);
if (newVersion) { if (newVersion) {
// Process package.json // Process package.json
pkg.version = newVersion pkg.version = newVersion;
pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion) pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion);
pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion) pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion);
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n") fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
// Process README.md // Process README.md
if (fs.existsSync("README.md")) { if (fs.existsSync("README.md")) {
fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion)) fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion));
} }
} }

View File

@ -26,7 +26,7 @@ server.on("request", (request, send, rinfo) => {
ttl: 300, ttl: 300,
address: "1.2.3.4" address: "1.2.3.4"
}); });
} if (question.type === Packet.TYPE.AAAA) { } else if (question.type === Packet.TYPE.AAAA) {
response.answers.push({ response.answers.push({
name: question.name, name: question.name,
type: question.type, type: question.type,

View File

@ -534,18 +534,18 @@ class Monitor extends BeanModel {
* @returns {Promise<object>} * @returns {Promise<object>}
*/ */
async updateTlsInfo(checkCertificateResult) { async updateTlsInfo(checkCertificateResult) {
let tls_info_bean = await R.findOne("monitor_tls_info", "monitor_id = ?", [ let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
this.id, this.id,
]); ]);
if (tls_info_bean == null) { if (tlsInfoBean == null) {
tls_info_bean = R.dispense("monitor_tls_info"); tlsInfoBean = R.dispense("monitor_tls_info");
tls_info_bean.monitor_id = this.id; tlsInfoBean.monitor_id = this.id;
} else { } else {
// Clear sent history if the cert changed. // Clear sent history if the cert changed.
try { try {
let oldCertInfo = JSON.parse(tls_info_bean.info_json); let oldCertInfo = JSON.parse(tlsInfoBean.info_json);
let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo; let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo;
@ -567,8 +567,8 @@ class Monitor extends BeanModel {
} }
tls_info_bean.info_json = JSON.stringify(checkCertificateResult); tlsInfoBean.info_json = JSON.stringify(checkCertificateResult);
await R.store(tls_info_bean); await R.store(tlsInfoBean);
return checkCertificateResult; return checkCertificateResult;
} }

View File

@ -6,7 +6,7 @@ class Apprise extends NotificationProvider {
name = "apprise"; name = "apprise";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let s = child_process.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL]) 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";
@ -16,7 +16,7 @@ class Apprise extends NotificationProvider {
return "Sent Successfully"; return "Sent Successfully";
} }
throw new Error(output) throw new Error(output);
} else { } else {
return "No output from apprise"; return "No output from apprise";
} }

View File

@ -21,8 +21,7 @@ class Bark extends NotificationProvider {
name = "Bark"; name = "Bark";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
try { let barkEndpoint = notification.barkEndpoint;
var barkEndpoint = notification.barkEndpoint;
// check if the endpoint has a "/" suffix, if so, delete it first // check if the endpoint has a "/" suffix, if so, delete it first
if (barkEndpoint.endsWith("/")) { if (barkEndpoint.endsWith("/")) {
@ -43,10 +42,6 @@ class Bark extends NotificationProvider {
let title = "UptimeKuma Message"; let title = "UptimeKuma Message";
return await this.postNotification(title, msg, barkEndpoint); return await this.postNotification(title, msg, barkEndpoint);
} }
} catch (error) {
throw error;
}
} }
// add additional parameter for better on device styles (iOS 15 optimized) // add additional parameter for better on device styles (iOS 15 optimized)

View File

@ -12,7 +12,7 @@ class ClickSendSMS extends NotificationProvider {
let config = { let config = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString('base64'), "Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString("base64"),
"Accept": "text/json", "Accept": "text/json",
} }
}; };

View File

@ -17,8 +17,8 @@ class Discord extends NotificationProvider {
let discordtestdata = { let discordtestdata = {
username: discordDisplayName, username: discordDisplayName,
content: msg, content: msg,
} };
await axios.post(notification.discordWebhookUrl, discordtestdata) await axios.post(notification.discordWebhookUrl, discordtestdata);
return okMsg; return okMsg;
} }
@ -61,13 +61,13 @@ class Discord extends NotificationProvider {
}, },
], ],
}], }],
} };
if (notification.discordPrefixMessage) { if (notification.discordPrefixMessage) {
discorddowndata.content = notification.discordPrefixMessage; discorddowndata.content = notification.discordPrefixMessage;
} }
await axios.post(notification.discordWebhookUrl, discorddowndata) await axios.post(notification.discordWebhookUrl, discorddowndata);
return okMsg; return okMsg;
} else if (heartbeatJSON["status"] == UP) { } else if (heartbeatJSON["status"] == UP) {
@ -96,17 +96,17 @@ class Discord extends NotificationProvider {
}, },
], ],
}], }],
} };
if (notification.discordPrefixMessage) { if (notification.discordPrefixMessage) {
discordupdata.content = notification.discordPrefixMessage; discordupdata.content = notification.discordPrefixMessage;
} }
await axios.post(notification.discordWebhookUrl, discordupdata) await axios.post(notification.discordWebhookUrl, discordupdata);
return okMsg; return okMsg;
} }
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }

View File

@ -13,11 +13,11 @@ class GoogleChat extends NotificationProvider {
try { try {
// Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic // Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic
let textMsg = '' let textMsg = "";
if (heartbeatJSON && heartbeatJSON.status === UP) { if (heartbeatJSON && heartbeatJSON.status === UP) {
textMsg = `✅ Application is back online\n`; textMsg = "✅ Application is back online\n";
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) { } else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
textMsg = `🔴 Application went down\n`; textMsg = "🔴 Application went down\n";
} }
if (monitorJSON && monitorJSON.name) { if (monitorJSON && monitorJSON.name) {

View File

@ -15,7 +15,7 @@ class Gotify extends NotificationProvider {
"message": msg, "message": msg,
"priority": notification.gotifyPriority || 8, "priority": notification.gotifyPriority || 8,
"title": "Uptime-Kuma", "title": "Uptime-Kuma",
}) });
return okMsg; return okMsg;

View File

@ -25,8 +25,8 @@ class Line extends NotificationProvider {
"text": "Test Successful!" "text": "Test Successful!"
} }
] ]
} };
await axios.post(lineAPIUrl, testMessage, config) await axios.post(lineAPIUrl, testMessage, config);
} else if (heartbeatJSON["status"] == DOWN) { } else if (heartbeatJSON["status"] == DOWN) {
let downMessage = { let downMessage = {
"to": notification.lineUserID, "to": notification.lineUserID,
@ -36,8 +36,8 @@ class Line extends NotificationProvider {
"text": "UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] "text": "UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
} }
] ]
} };
await axios.post(lineAPIUrl, downMessage, config) await axios.post(lineAPIUrl, downMessage, config);
} else if (heartbeatJSON["status"] == UP) { } else if (heartbeatJSON["status"] == UP) {
let upMessage = { let upMessage = {
"to": notification.lineUserID, "to": notification.lineUserID,
@ -47,12 +47,12 @@ class Line extends NotificationProvider {
"text": "UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] "text": "UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
} }
] ]
} };
await axios.post(lineAPIUrl, upMessage, config) await axios.post(lineAPIUrl, upMessage, config);
} }
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }
} }

View File

@ -8,15 +8,15 @@ class LunaSea extends NotificationProvider {
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully."; let okMsg = "Sent Successfully.";
let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
try { try {
if (heartbeatJSON == null) { if (heartbeatJSON == null) {
let testdata = { let testdata = {
"title": "Uptime Kuma Alert", "title": "Uptime Kuma Alert",
"body": "Testing Successful.", "body": "Testing Successful.",
} };
await axios.post(lunaseadevice, testdata) await axios.post(lunaseadevice, testdata);
return okMsg; return okMsg;
} }
@ -24,8 +24,8 @@ class LunaSea extends NotificationProvider {
let downdata = { let downdata = {
"title": "UptimeKuma Alert: " + monitorJSON["name"], "title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
} };
await axios.post(lunaseadevice, downdata) await axios.post(lunaseadevice, downdata);
return okMsg; return okMsg;
} }
@ -33,13 +33,13 @@ class LunaSea extends NotificationProvider {
let updata = { let updata = {
"title": "UptimeKuma Alert: " + monitorJSON["name"], "title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
} };
await axios.post(lunaseadevice, updata) await axios.post(lunaseadevice, updata);
return okMsg; return okMsg;
} }
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }

View File

@ -25,11 +25,11 @@ class NotificationProvider {
if (typeof error.response.data === "string") { if (typeof error.response.data === "string") {
msg += error.response.data; msg += error.response.data;
} else { } else {
msg += JSON.stringify(error.response.data) msg += JSON.stringify(error.response.data);
} }
} }
throw new Error(msg) throw new Error(msg);
} }
} }

View File

@ -30,7 +30,7 @@ class Octopush extends NotificationProvider {
"purpose": "alert", "purpose": "alert",
"sender": notification.octopushSenderName "sender": notification.octopushSenderName
}; };
await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config) await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config);
} else if (notification.octopushVersion == 1) { } else if (notification.octopushVersion == 1) {
let data = { let data = {
"user_login": notification.octopushDMLogin, "user_login": notification.octopushDMLogin,
@ -49,7 +49,7 @@ class Octopush extends NotificationProvider {
}, },
params: data params: data
}; };
await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config) await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config);
} else { } else {
throw new Error("Unknown Octopush version!"); throw new Error("Unknown Octopush version!");
} }

View File

@ -12,7 +12,7 @@ class PromoSMS extends NotificationProvider {
let config = { let config = {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString('base64'), "Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString("base64"),
"Accept": "text/json", "Accept": "text/json",
} }
}; };

View File

@ -23,26 +23,26 @@ class Pushbullet extends NotificationProvider {
"type": "note", "type": "note",
"title": "Uptime Kuma Alert", "title": "Uptime Kuma Alert",
"body": "Testing Successful.", "body": "Testing Successful.",
} };
await axios.post(pushbulletUrl, testdata, config) await axios.post(pushbulletUrl, testdata, config);
} else if (heartbeatJSON["status"] == DOWN) { } else if (heartbeatJSON["status"] == DOWN) {
let downdata = { let downdata = {
"type": "note", "type": "note",
"title": "UptimeKuma Alert: " + monitorJSON["name"], "title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
} };
await axios.post(pushbulletUrl, downdata, config) await axios.post(pushbulletUrl, downdata, config);
} else if (heartbeatJSON["status"] == UP) { } else if (heartbeatJSON["status"] == UP) {
let updata = { let updata = {
"type": "note", "type": "note",
"title": "UptimeKuma Alert: " + monitorJSON["name"], "title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
} };
await axios.post(pushbulletUrl, updata, config) await axios.post(pushbulletUrl, updata, config);
} }
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }
} }

View File

@ -19,10 +19,10 @@ class Pushy extends NotificationProvider {
"badge": 1, "badge": 1,
"sound": "ping.aiff" "sound": "ping.aiff"
} }
}) });
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }
} }

View File

@ -2,7 +2,7 @@ const NotificationProvider = require("./notification-provider");
const axios = require("axios"); const axios = require("axios");
const Slack = require("./slack"); const Slack = require("./slack");
const { setting } = require("../util-server"); const { setting } = require("../util-server");
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util"); const { getMonitorRelativeURL, DOWN } = require("../../src/util");
class RocketChat extends NotificationProvider { class RocketChat extends NotificationProvider {

View File

@ -16,10 +16,10 @@ class Signal extends NotificationProvider {
}; };
let config = {}; let config = {};
await axios.post(notification.signalURL, data, config) await axios.post(notification.signalURL, data, config);
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }
} }

View File

@ -12,10 +12,10 @@ class TechulusPush extends NotificationProvider {
await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, { await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, {
"title": "Uptime-Kuma", "title": "Uptime-Kuma",
"body": msg, "body": msg,
}) });
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }
} }

View File

@ -14,12 +14,12 @@ class Telegram extends NotificationProvider {
chat_id: notification.telegramChatID, chat_id: notification.telegramChatID,
text: msg, text: msg,
}, },
}) });
return okMsg; return okMsg;
} catch (error) { } catch (error) {
let msg = (error.response.data.description) ? error.response.data.description : "Error without description" let msg = (error.response.data.description) ? error.response.data.description : "Error without description";
throw new Error(msg) throw new Error(msg);
} }
} }
} }

View File

@ -24,17 +24,17 @@ class Webhook extends NotificationProvider {
config = { config = {
headers: finalData.getHeaders(), headers: finalData.getHeaders(),
} };
} else { } else {
finalData = data; finalData = data;
} }
await axios.post(notification.webhookURL, finalData, config) await axios.post(notification.webhookURL, finalData, config);
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error) this.throwGeneralAxiosError(error);
} }
} }

View File

@ -26,7 +26,7 @@ class WeCom extends NotificationProvider {
composeMessage(heartbeatJSON, msg) { composeMessage(heartbeatJSON, msg) {
let title; let title;
if (msg != null && heartbeatJSON != null && heartbeatJSON['status'] == UP) { if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == UP) {
title = "UptimeKuma Monitor Up"; title = "UptimeKuma Monitor Up";
} }
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) { if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) {

View File

@ -105,27 +105,27 @@ class Notification {
} }
static async save(notification, notificationID, userID) { static async save(notification, notificationID, userID) {
let bean let bean;
if (notificationID) { if (notificationID) {
bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
notificationID, notificationID,
userID, userID,
]) ]);
if (! bean) { if (! bean) {
throw new Error("notification not found") throw new Error("notification not found");
} }
} else { } else {
bean = R.dispense("notification") bean = R.dispense("notification");
} }
bean.name = notification.name; bean.name = notification.name;
bean.user_id = userID; bean.user_id = userID;
bean.config = JSON.stringify(notification); bean.config = JSON.stringify(notification);
bean.is_default = notification.isDefault || false; bean.is_default = notification.isDefault || false;
await R.store(bean) await R.store(bean);
if (notification.applyExisting) { if (notification.applyExisting) {
await applyNotificationEveryMonitor(bean.id, userID); await applyNotificationEveryMonitor(bean.id, userID);
@ -138,13 +138,13 @@ class Notification {
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
notificationID, notificationID,
userID, userID,
]) ]);
if (! bean) { if (! bean) {
throw new Error("notification not found") throw new Error("notification not found");
} }
await R.trash(bean) await R.trash(bean);
} }
static checkApprise() { static checkApprise() {
@ -171,17 +171,17 @@ async function applyNotificationEveryMonitor(notificationID, userID) {
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [ let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
monitors[i].id, monitors[i].id,
notificationID, notificationID,
]) ]);
if (! checkNotification) { if (! checkNotification) {
let relation = R.dispense("monitor_notification"); let relation = R.dispense("monitor_notification");
relation.monitor_id = monitors[i].id; relation.monitor_id = monitors[i].id;
relation.notification_id = notificationID; relation.notification_id = notificationID;
await R.store(relation) await R.store(relation);
} }
} }
} }
module.exports = { module.exports = {
Notification, Notification,
} };

View File

@ -4,20 +4,20 @@ const saltRounds = 10;
exports.generate = function (password) { exports.generate = function (password) {
return bcrypt.hashSync(password, saltRounds); return bcrypt.hashSync(password, saltRounds);
} };
exports.verify = function (password, hash) { exports.verify = function (password, hash) {
if (isSHA1(hash)) { if (isSHA1(hash)) {
return passwordHashOld.verify(password, hash) return passwordHashOld.verify(password, hash);
} }
return bcrypt.compareSync(password, hash); return bcrypt.compareSync(password, hash);
} };
function isSHA1(hash) { function isSHA1(hash) {
return (typeof hash === "string" && hash.startsWith("sha1")) return (typeof hash === "string" && hash.startsWith("sha1"));
} }
exports.needRehash = function (hash) { exports.needRehash = function (hash) {
return isSHA1(hash); return isSHA1(hash);
} };

View File

@ -49,13 +49,13 @@ class Prometheus {
if (typeof tlsInfo !== "undefined") { if (typeof tlsInfo !== "undefined") {
try { try {
let is_valid = 0; let isValid = 0;
if (tlsInfo.valid == true) { if (tlsInfo.valid == true) {
is_valid = 1; isValid = 1;
} else { } else {
is_valid = 0; isValid = 0;
} }
monitor_cert_is_valid.set(this.monitorLabelValues, is_valid); monitor_cert_is_valid.set(this.monitorLabelValues, isValid);
} catch (e) { } catch (e) {
log.error("prometheus", "Caught error"); log.error("prometheus", "Caught error");
log.error("prometheus", e); log.error("prometheus", e);

View File

@ -1,5 +1,5 @@
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { checkLogin, setSettings, setSetting } = require("../util-server"); const { checkLogin, setSetting } = require("../util-server");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const { log } = require("../../src/util"); const { log } = require("../../src/util");
const ImageDataURI = require("../image-data-uri"); const ImageDataURI = require("../image-data-uri");

View File

@ -4,7 +4,7 @@ const { R } = require("redbean-node");
const { log, genSecret } = require("../src/util"); const { log, genSecret } = require("../src/util");
const passwordHash = require("./password-hash"); const passwordHash = require("./password-hash");
const { Resolver } = require("dns"); const { Resolver } = require("dns");
const child_process = require("child_process"); const childProcess = require("child_process");
const iconv = require("iconv-lite"); const iconv = require("iconv-lite");
const chardet = require("chardet"); const chardet = require("chardet");
const fs = require("fs"); const fs = require("fs");
@ -345,7 +345,7 @@ exports.doubleCheckPassword = async (socket, currentPassword) => {
exports.startUnitTest = async () => { exports.startUnitTest = async () => {
console.log("Starting unit test..."); console.log("Starting unit test...");
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm"; const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
const child = child_process.spawn(npm, ["run", "jest"]); const child = childProcess.spawn(npm, ["run", "jest"]);
child.stdout.on("data", (data) => { child.stdout.on("data", (data) => {
console.log(data.toString()); console.log(data.toString());

View File

@ -25,7 +25,7 @@
</template> </template>
<script> <script>
import { Modal } from "bootstrap" import { Modal } from "bootstrap";
export default { export default {
props: { props: {
@ -46,15 +46,15 @@ export default {
modal: null, modal: null,
}), }),
mounted() { mounted() {
this.modal = new Modal(this.$refs.modal) this.modal = new Modal(this.$refs.modal);
}, },
methods: { methods: {
show() { show() {
this.modal.show() this.modal.show();
}, },
yes() { yes() {
this.$emit("yes"); this.$emit("yes");
}, },
}, },
} };
</script> </script>

View File

@ -5,7 +5,7 @@
<script lang="ts"> <script lang="ts">
import { sleep } from "../util.ts" import { sleep } from "../util.ts";
export default { export default {
@ -25,12 +25,12 @@ export default {
return { return {
output: "", output: "",
frameDuration: 30, frameDuration: 30,
} };
}, },
computed: { computed: {
isNum() { isNum() {
return typeof this.value === "number" return typeof this.value === "number";
}, },
}, },
@ -45,7 +45,7 @@ export default {
} else { } else {
for (let i = 1; i < frames; i++) { for (let i = 1; i < frames; i++) {
this.output += step; this.output += step;
await sleep(15) await sleep(15);
} }
} }
@ -59,5 +59,5 @@ export default {
methods: {}, methods: {},
} };
</script> </script>

View File

@ -4,12 +4,12 @@
<script> <script>
import dayjs from "dayjs"; import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime" import relativeTime from "dayjs/plugin/relativeTime";
import utc from "dayjs/plugin/utc" import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone" // dependent on utc plugin import timezone from "dayjs/plugin/timezone"; // dependent on utc plugin
dayjs.extend(utc) dayjs.extend(utc);
dayjs.extend(timezone) dayjs.extend(timezone);
dayjs.extend(relativeTime) dayjs.extend(relativeTime);
export default { export default {
props: { props: {
@ -29,5 +29,5 @@ export default {
} }
}, },
}, },
} };
</script> </script>

View File

@ -38,7 +38,7 @@ export default {
beatMargin: 4, beatMargin: 4,
move: false, move: false,
maxBeat: -1, maxBeat: -1,
} };
}, },
computed: { computed: {
@ -69,12 +69,12 @@ export default {
if (start < 0) { if (start < 0) {
// Add empty placeholder // Add empty placeholder
for (let i = start; i < 0; i++) { for (let i = start; i < 0; i++) {
placeholders.push(0) placeholders.push(0);
} }
start = 0; start = 0;
} }
return placeholders.concat(this.beatList.slice(start)) return placeholders.concat(this.beatList.slice(start));
}, },
wrapStyle() { wrapStyle() {
@ -84,7 +84,7 @@ export default {
return { return {
padding: `${topBottom}px ${leftRight}px`, padding: `${topBottom}px ${leftRight}px`,
width: "100%", width: "100%",
} };
}, },
barStyle() { barStyle() {
@ -94,12 +94,12 @@ export default {
return { return {
transition: "all ease-in-out 0.25s", transition: "all ease-in-out 0.25s",
transform: `translateX(${width}px)`, transform: `translateX(${width}px)`,
} };
} }
return { return {
transform: "translateX(0)", transform: "translateX(0)",
} };
}, },
@ -109,7 +109,7 @@ export default {
height: this.beatHeight + "px", height: this.beatHeight + "px",
margin: this.beatMargin + "px", margin: this.beatMargin + "px",
"--hover-scale": this.hoverScale, "--hover-scale": this.hoverScale,
} };
}, },
}, },
@ -120,7 +120,7 @@ export default {
setTimeout(() => { setTimeout(() => {
this.move = false; this.move = false;
}, 300) }, 300);
}, },
deep: true, deep: true,
}, },
@ -162,15 +162,15 @@ export default {
methods: { methods: {
resize() { resize() {
if (this.$refs.wrap) { if (this.$refs.wrap) {
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2)) this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2));
} }
}, },
getBeatTitle(beat) { getBeatTitle(beat) {
return `${this.$root.datetime(beat.time)}` + ((beat.msg) ? ` - ${beat.msg}` : ``); return `${this.$root.datetime(beat.time)}` + ((beat.msg) ? ` - ${beat.msg}` : "");
} }
}, },
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -51,15 +51,15 @@ export default {
data() { data() {
return { return {
visibility: "password", visibility: "password",
} };
}, },
computed: { computed: {
model: { model: {
get() { get() {
return this.modelValue return this.modelValue;
}, },
set(value) { set(value) {
this.$emit("update:modelValue", value) this.$emit("update:modelValue", value);
} }
} }
}, },
@ -74,5 +74,5 @@ export default {
this.visibility = "password"; this.visibility = "password";
}, },
} }
} };
</script> </script>

View File

@ -69,7 +69,6 @@
<script lang="ts"> <script lang="ts">
import { Modal } from "bootstrap"; import { Modal } from "bootstrap";
import { ucfirst } from "../util.ts";
import Confirm from "./Confirm.vue"; import Confirm from "./Confirm.vue";
import NotificationFormList from "./notifications"; import NotificationFormList from "./notifications";

View File

@ -24,7 +24,7 @@ import timezone from "dayjs/plugin/timezone";
import "chartjs-adapter-dayjs"; import "chartjs-adapter-dayjs";
import { LineChart } from "vue-chart-3"; import { LineChart } from "vue-chart-3";
import { useToast } from "vue-toastification"; import { useToast } from "vue-toastification";
import { UP, DOWN, PENDING } from "../util.ts"; import { DOWN } from "../util.ts";
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(timezone); dayjs.extend(timezone);

View File

@ -41,7 +41,7 @@ export default {
} }
} }
} }
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -22,33 +22,33 @@ export default {
return Math.round(this.$root.uptimeList[key] * 10000) / 100 + "%"; return Math.round(this.$root.uptimeList[key] * 10000) / 100 + "%";
} }
return this.$t("notAvailableShort") return this.$t("notAvailableShort");
}, },
color() { color() {
if (this.lastHeartBeat.status === 0) { if (this.lastHeartBeat.status === 0) {
return "danger" return "danger";
} }
if (this.lastHeartBeat.status === 1) { if (this.lastHeartBeat.status === 1) {
return "primary" return "primary";
} }
if (this.lastHeartBeat.status === 2) { if (this.lastHeartBeat.status === 2) {
return "warning" return "warning";
} }
return "secondary" return "secondary";
}, },
lastHeartBeat() { lastHeartBeat() {
if (this.monitor.id in this.$root.lastHeartbeatList && this.$root.lastHeartbeatList[this.monitor.id]) { if (this.monitor.id in this.$root.lastHeartbeatList && this.$root.lastHeartbeatList[this.monitor.id]) {
return this.$root.lastHeartbeatList[this.monitor.id] return this.$root.lastHeartbeatList[this.monitor.id];
} }
return { return {
status: -1, status: -1,
} };
}, },
className() { className() {
@ -59,7 +59,7 @@ export default {
return ""; return "";
}, },
}, },
} };
</script> </script>
<style> <style>

View File

@ -28,5 +28,5 @@ export default {
this.$parent.notification.gotifyPriority = 8; this.$parent.notification.gotifyPriority = 8;
} }
}, },
} };
</script> </script>

View File

@ -63,5 +63,5 @@ export default {
components: { components: {
HiddenInput, HiddenInput,
}, },
} };
</script> </script>

View File

@ -24,7 +24,7 @@ import AliyunSMS from "./AliyunSms.vue";
import DingDing from "./DingDing.vue"; import DingDing from "./DingDing.vue";
import Bark from "./Bark.vue"; import Bark from "./Bark.vue";
import SerwerSMS from "./SerwerSMS.vue"; import SerwerSMS from "./SerwerSMS.vue";
import Stackfield from './Stackfield.vue'; import Stackfield from "./Stackfield.vue";
import WeCom from "./WeCom.vue"; import WeCom from "./WeCom.vue";
import GoogleChat from "./GoogleChat.vue"; import GoogleChat from "./GoogleChat.vue";
import Gorush from "./Gorush.vue"; import Gorush from "./Gorush.vue";

View File

@ -3,5 +3,6 @@
</template> </template>
<script> <script>
export default {} export default {};
</script> </script>

View File

@ -25,9 +25,9 @@ export default {
MonitorList, MonitorList,
}, },
data() { data() {
return {} return {};
}, },
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -118,6 +118,7 @@ export default {
return 0; return 0;
}); });
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
this.heartBeatList = result; this.heartBeatList = result;
return result; return result;

View File

@ -11,6 +11,6 @@ export default {
components: { components: {
MonitorList, MonitorList,
}, },
} };
</script> </script>

View File

@ -169,13 +169,6 @@ let getRandomBytes = ((typeof window !== 'undefined' && window.crypto)
: function () { : function () {
return require("crypto").randomBytes; return require("crypto").randomBytes;
})(); })();
/**
* Returns a random integer between min (inclusive) and max (exclusive).
* @param {number} min The minimum value.
* @param {number} max The maximum value.
*
* Generated by Trelent
*/
function getCryptoRandomInt(min, max) { function getCryptoRandomInt(min, max) {
// synchronous version of: https://github.com/joepie91/node-random-number-csprng // synchronous version of: https://github.com/joepie91/node-random-number-csprng
const range = max - min; const range = max - min;
@ -206,13 +199,6 @@ function getCryptoRandomInt(min, max) {
} }
} }
exports.getCryptoRandomInt = getCryptoRandomInt; exports.getCryptoRandomInt = getCryptoRandomInt;
/**
* Generates a random string of length `length` from the characters in `chars`.
* @param {number} length The number of characters to generate.
* @param {string} chars A string containing all the possible characters to use for generating the random string.
*
* Generated by Trelent
*/
function genSecret(length = 64) { function genSecret(length = 64) {
let secret = ""; let secret = "";
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

View File

@ -1,4 +1,4 @@
const { genSecret, sleep } = require("../src/util"); const { genSecret } = require("../src/util");
const utilServerRewire = require("../server/util-server"); const utilServerRewire = require("../server/util-server");
describe("Test parseCertificateInfo", () => { describe("Test parseCertificateInfo", () => {

View File

@ -1,7 +1,6 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const { Page, Browser } = require("puppeteer"); const { Page, Browser } = require("puppeteer");
const { sleep } = require("../src/util"); const { sleep } = require("../src/util");
const axios = require("axios");
/** /**
* Set back the correct data type for page object * Set back the correct data type for page object