Merge remote-tracking branch 'remote/master' into feature/add-xml-support-to-http-monitors

This commit is contained in:
Faruk Genç 2023-01-30 13:09:16 +03:00
commit 064bc00f46
9 changed files with 75 additions and 18 deletions

View File

@ -3,6 +3,6 @@ FROM node:16-alpine3.12
WORKDIR /app WORKDIR /app
# Install apprise, iputils for non-root ping, setpriv # Install apprise, iputils for non-root ping, setpriv
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib && \ RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib git && \
pip3 --no-cache-dir install apprise==1.2.1 && \ pip3 --no-cache-dir install apprise==1.2.1 && \
rm -rf /root/.cache rm -rf /root/.cache

View File

@ -10,7 +10,7 @@ WORKDIR /app
# Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them, make the base even smaller than alpine! # Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them, make the base even smaller than alpine!
RUN apt update && \ RUN apt update && \
apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \ apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
sqlite3 iputils-ping util-linux dumb-init && \ sqlite3 iputils-ping util-linux dumb-init git && \
pip3 --no-cache-dir install apprise==1.2.1 && \ pip3 --no-cache-dir install apprise==1.2.1 && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
apt --yes autoremove apt --yes autoremove

View File

@ -5,6 +5,8 @@ const badgeConstants = {
naColor: "#999", naColor: "#999",
defaultUpColor: "#66c20a", defaultUpColor: "#66c20a",
defaultDownColor: "#c2290a", defaultDownColor: "#c2290a",
defaultPendingColor: "#f8a306",
defaultMaintenanceColor: "#1747f5",
defaultPingColor: "blue", // as defined by badge-maker / shields.io defaultPingColor: "blue", // as defined by badge-maker / shields.io
defaultStyle: "flat", defaultStyle: "flat",
defaultPingValueSuffix: "ms", defaultPingValueSuffix: "ms",

View File

@ -72,6 +72,12 @@ class PluginsManager {
* @param {string} name Directory name, also known as plugin unique name * @param {string} name Directory name, also known as plugin unique name
*/ */
downloadPlugin(repoURL, name) { downloadPlugin(repoURL, name) {
if (fs.existsSync(this.pluginsDir + name)) {
log.info("plugin", "Plugin folder already exists? Removing...");
fs.rmSync(this.pluginsDir + name, {
recursive: true
});
}
log.info("plugin", "Installing plugin: " + name + " " + repoURL); log.info("plugin", "Installing plugin: " + name + " " + repoURL);
let result = Git.clone(repoURL, this.pluginsDir, name); let result = Git.clone(repoURL, this.pluginsDir, name);
log.info("plugin", "Install result: " + result); log.info("plugin", "Install result: " + result);
@ -115,13 +121,19 @@ class PluginsManager {
* @returns {Promise<[]>} * @returns {Promise<[]>}
*/ */
async fetchPluginList() { async fetchPluginList() {
const res = await axios.get("https://uptime.kuma.pet/c/plugins.json"); let remotePluginList;
const list = res.data.pluginList; try {
const res = await axios.get("https://uptime.kuma.pet/c/plugins.json");
remotePluginList = res.data.pluginList;
} catch (e) {
log.error("plugin", "Failed to fetch plugin list: " + e.message);
remotePluginList = [];
}
for (let plugin of this.pluginList) { for (let plugin of this.pluginList) {
let find = false; let find = false;
// Try to merge // Try to merge
for (let remotePlugin of list) { for (let remotePlugin of remotePluginList) {
if (remotePlugin.name === plugin.info.name) { if (remotePlugin.name === plugin.info.name) {
find = true; find = true;
remotePlugin.installed = true; remotePlugin.installed = true;
@ -136,17 +148,17 @@ class PluginsManager {
// Local plugin // Local plugin
if (!find) { if (!find) {
plugin.info.local = true; plugin.info.local = true;
list.push(plugin.info); remotePluginList.push(plugin.info);
} }
} }
// Sort Installed first, then sort by name // Sort Installed first, then sort by name
return list.sort((a, b) => { return remotePluginList.sort((a, b) => {
if (a.installed === b.installed) { if (a.installed === b.installed) {
if ( a.fullName < b.fullName ) { if (a.fullName < b.fullName) {
return -1; return -1;
} }
if ( a.fullName > b.fullName ) { if (a.fullName > b.fullName) {
return 1; return 1;
} }
return 0; return 0;
@ -191,15 +203,24 @@ class PluginWrapper {
let indexFile = this.pluginDir + "/index.js"; let indexFile = this.pluginDir + "/index.js";
let packageJSON = this.pluginDir + "/package.json"; let packageJSON = this.pluginDir + "/package.json";
log.info("plugin", "Installing dependencies");
if (fs.existsSync(indexFile)) { if (fs.existsSync(indexFile)) {
// Install dependencies // Install dependencies
childProcess.execSync("npm install", { let result = childProcess.spawnSync("npm", [ "install" ], {
cwd: this.pluginDir, cwd: this.pluginDir,
env: { env: {
...process.env,
PLAYWRIGHT_BROWSERS_PATH: "../../browsers", // Special handling for read-browser-monitor PLAYWRIGHT_BROWSERS_PATH: "../../browsers", // Special handling for read-browser-monitor
} }
}); });
if (result.stdout) {
log.info("plugin", "Install dependencies result: " + result.stdout.toString("utf-8"));
} else {
log.warn("plugin", "Install dependencies result: no output");
}
this.pluginClass = require(path.join(process.cwd(), indexFile)); this.pluginClass = require(path.join(process.cwd(), indexFile));
let pluginClassType = typeof this.pluginClass; let pluginClassType = typeof this.pluginClass;

View File

@ -111,8 +111,12 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
label, label,
upLabel = "Up", upLabel = "Up",
downLabel = "Down", downLabel = "Down",
pendingLabel = "Pending",
maintenanceLabel = "Maintenance",
upColor = badgeConstants.defaultUpColor, upColor = badgeConstants.defaultUpColor,
downColor = badgeConstants.defaultDownColor, downColor = badgeConstants.defaultDownColor,
pendingColor = badgeConstants.defaultPendingColor,
maintenanceColor = badgeConstants.defaultMaintenanceColor,
style = badgeConstants.defaultStyle, style = badgeConstants.defaultStyle,
value, // for demo purpose only value, // for demo purpose only
} = request.query; } = request.query;
@ -139,11 +143,30 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
badgeValues.color = badgeConstants.naColor; badgeValues.color = badgeConstants.naColor;
} else { } else {
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId); const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
const state = overrideValue !== undefined ? overrideValue : heartbeat.status === 1; const state = overrideValue !== undefined ? overrideValue : heartbeat.status;
badgeValues.label = label ? label : ""; badgeValues.label = label ?? "";
badgeValues.color = state ? upColor : downColor; switch (state) {
badgeValues.message = label ?? state ? upLabel : downLabel; case 0:
badgeValues.color = downColor;
badgeValues.message = downLabel;
break;
case 1:
badgeValues.color = upColor;
badgeValues.message = upLabel;
break;
case 2:
badgeValues.color = pendingColor;
badgeValues.message = pendingLabel;
break;
case 3:
badgeValues.color = maintenanceColor;
badgeValues.message = maintenanceLabel;
break;
default:
badgeValues.color = badgeConstants.naColor;
badgeValues.message = "N/A";
}
} }
// build the svg based on given values // build the svg based on given values

View File

@ -1,5 +1,6 @@
const { checkLogin } = require("../util-server"); const { checkLogin } = require("../util-server");
const { PluginManager } = require("../plugins-manager"); const { PluginsManager } = require("../plugins-manager");
const { log } = require("../../src/util.js");
/** /**
* Handlers for plugins * Handlers for plugins
@ -15,7 +16,9 @@ module.exports.pluginsHandler = (socket, server) => {
try { try {
checkLogin(socket); checkLogin(socket);
if (PluginManager.disable) { log.debug("plugin", "PluginManager.disable: " + PluginsManager.disable);
if (PluginsManager.disable) {
throw new Error("Plugin Disabled: In order to enable plugin feature, you need to use the default data directory: ./data/"); throw new Error("Plugin Disabled: In order to enable plugin feature, you need to use the default data directory: ./data/");
} }
@ -25,6 +28,7 @@ module.exports.pluginsHandler = (socket, server) => {
pluginList, pluginList,
}); });
} catch (error) { } catch (error) {
log.warn("plugin", "Error: " + error.message);
callback({ callback({
ok: false, ok: false,
msg: error.message, msg: error.message,

View File

@ -48,7 +48,7 @@ export default {
this.remotePluginList = res.pluginList; this.remotePluginList = res.pluginList;
this.remotePluginListMsg = ""; this.remotePluginListMsg = "";
} else { } else {
this.remotePluginListMsg = this.$t("loadingError") + " " + res.message; this.remotePluginListMsg = this.$t("loadingError") + " " + res.msg;
} }
}); });
} }

View File

@ -71,12 +71,16 @@
</option> </option>
</optgroup> </optgroup>
<!--
Hidden for now: Reason refer to Setting.vue
<optgroup :label="$t('Custom Monitor Type')"> <optgroup :label="$t('Custom Monitor Type')">
<option value="browser"> <option value="browser">
(Beta) HTTP(s) - Browser Engine (Chrome/Firefox) (Beta) HTTP(s) - Browser Engine (Chrome/Firefox)
</option> </option>
</optgroup> </optgroup>
</select> </select>
-->
</select>
</div> </div>
<!-- Friendly Name --> <!-- Friendly Name -->

View File

@ -113,9 +113,12 @@ export default {
backup: { backup: {
title: this.$t("Backup"), title: this.$t("Backup"),
}, },
/*
Hidden for now: Unfortunately, after some test, I found that Playwright requires a lot of libraries to be installed on the Linux host in order to start Chrome or Firefox.
It will be hard to install, so I hide this feature for now. But it still accessible via URL: /settings/plugins.
plugins: { plugins: {
title: this.$tc("plugin", 2), title: this.$tc("plugin", 2),
}, },*/
about: { about: {
title: this.$t("About"), title: this.$t("About"),
}, },