Merge branch '1.23.X' into 1.23.X-merge-to-2.X.X

# Conflicts:
#	.github/workflows/auto-test.yml
#	extra/reset-password.js
#	package-lock.json
#	package.json
#	server/routers/status-page-router.js
#	server/server.js
#	server/socket-handlers/general-socket-handler.js
#	server/uptime-kuma-server.js
#	src/components/ActionInput.vue
#	src/util.js
#	src/util.ts
This commit is contained in:
Louis Lam 2023-12-11 02:13:47 +08:00
commit 869ee8ec50
26 changed files with 251 additions and 94 deletions

View File

@ -84,7 +84,7 @@ module.exports = {
"checkLoops": false, "checkLoops": false,
}], }],
"space-before-blocks": "warn", "space-before-blocks": "warn",
//'no-console': 'warn', //"no-console": "warn",
"no-extra-boolean-cast": "off", "no-extra-boolean-cast": "off",
"no-multiple-empty-lines": [ "warn", { "no-multiple-empty-lines": [ "warn", {
"max": 1, "max": 1,
@ -96,7 +96,8 @@ module.exports = {
"no-unneeded-ternary": "error", "no-unneeded-ternary": "error",
"array-bracket-newline": [ "error", "consistent" ], "array-bracket-newline": [ "error", "consistent" ],
"eol-last": [ "error", "always" ], "eol-last": [ "error", "always" ],
//'prefer-template': 'error', //"prefer-template": "error",
"template-curly-spacing": [ "warn", "never" ],
"comma-dangle": [ "warn", "only-multiline" ], "comma-dangle": [ "warn", "only-multiline" ],
"no-empty": [ "error", { "no-empty": [ "error", {
"allowEmptyCatch": true "allowEmptyCatch": true

View File

@ -27,10 +27,10 @@ jobs:
steps: steps:
- run: git config --global core.autocrlf false # Mainly for Windows - run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }} - name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
- run: npm install npm@9 -g - run: npm install npm@9 -g
@ -55,10 +55,10 @@ jobs:
steps: steps:
- run: git config --global core.autocrlf false # Mainly for Windows - run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node }} - name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
- run: npm install npm@9 -g - run: npm install npm@9 -g
@ -69,40 +69,39 @@ jobs:
steps: steps:
- run: git config --global core.autocrlf false # Mainly for Windows - run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Use Node.js 20 - name: Use Node.js 20
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
- run: npm install - run: npm install
- run: npm run lint - run: npm run lint:prod
# TODO: Temporarily disable, as it cannot pass the test in 2.0.0 yet e2e-tests:
# e2e-tests: needs: [ check-linters ]
# needs: [ check-linters ] runs-on: ubuntu-latest
# runs-on: ubuntu-latest steps:
# steps: - run: git config --global core.autocrlf false # Mainly for Windows
# - run: git config --global core.autocrlf false # Mainly for Windows - uses: actions/checkout@v4
# - uses: actions/checkout@v3
# - name: Use Node.js 14
# - name: Use Node.js 14 uses: actions/setup-node@v4
# uses: actions/setup-node@v3 with:
# with: node-version: 14
# node-version: 14 - run: npm install
# - run: npm install - run: npm run build
# - run: npm run build - run: npm run cy:test
# - run: npm run cy:test
frontend-unit-tests: frontend-unit-tests:
needs: [ check-linters ] needs: [ check-linters ]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- run: git config --global core.autocrlf false # Mainly for Windows - run: git config --global core.autocrlf false # Mainly for Windows
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Use Node.js 14 - name: Use Node.js 14
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 14 node-version: 14
- run: npm install - run: npm install

View File

@ -14,10 +14,10 @@ jobs:
node-version: [16] node-version: [16]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
cache: 'npm' cache: 'npm'

View File

@ -6,7 +6,7 @@ on:
pull_request: pull_request:
branches: branches:
- master - master
- 2.0.X - 1.23.X
workflow_dispatch: workflow_dispatch:
permissions: permissions:
@ -17,11 +17,11 @@ jobs:
json-yaml-validate: json-yaml-validate:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: json-yaml-validate - name: json-yaml-validate
id: json-yaml-validate id: json-yaml-validate
uses: GrantBirki/json-yaml-validate@v1.3.0 uses: GrantBirki/json-yaml-validate@v2.4.0
with: with:
comment: "true" # enable comment mode comment: "true" # enable comment mode
exclude_file: ".github/config/exclude.txt" # gitignore style file for exclusions exclude_file: ".github/config/exclude.txt" # gitignore style file for exclusions

View File

@ -2,7 +2,6 @@ import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import visualizer from "rollup-plugin-visualizer"; import visualizer from "rollup-plugin-visualizer";
import viteCompression from "vite-plugin-compression"; import viteCompression from "vite-plugin-compression";
import commonjs from "vite-plugin-commonjs";
const postCssScss = require("postcss-scss"); const postCssScss = require("postcss-scss");
const postcssRTLCSS = require("postcss-rtlcss"); const postcssRTLCSS = require("postcss-rtlcss");
@ -21,7 +20,6 @@ export default defineConfig({
"CODESPACE_NAME": JSON.stringify(process.env.CODESPACE_NAME), "CODESPACE_NAME": JSON.stringify(process.env.CODESPACE_NAME),
}, },
plugins: [ plugins: [
commonjs(),
vue(), vue(),
visualizer({ visualizer({
filename: "tmp/dist-stats.html" filename: "tmp/dist-stats.html"

View File

@ -6,7 +6,7 @@
* Deprecated: Changed to healthcheck.go, it will be deleted in the future. * Deprecated: Changed to healthcheck.go, it will be deleted in the future.
* This script should be run after a period of time (180s), because the server may need some time to prepare. * This script should be run after a period of time (180s), because the server may need some time to prepare.
*/ */
const { FBSD } = require("../server/util-server"); const FBSD = /^freebsd/.test(process.platform);
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

View File

@ -5,6 +5,8 @@ const { R } = require("redbean-node");
const readline = require("readline"); const readline = require("readline");
const { initJWTSecret } = require("../server/util-server"); const { initJWTSecret } = require("../server/util-server");
const User = require("../server/model/user"); const User = require("../server/model/user");
const { io } = require("socket.io-client");
const { localWebSocketURL } = require("../server/config");
const args = require("args-parser")(process.argv); const args = require("args-parser")(process.argv);
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@ -50,6 +52,9 @@ const main = async () => {
// Reset all sessions by reset jwt secret // Reset all sessions by reset jwt secret
await initJWTSecret(); await initJWTSecret();
// Disconnect all other socket clients of the user
await disconnectAllSocketClients(user.username, password);
} }
break; break;
} else { } else {
@ -57,6 +62,7 @@ const main = async () => {
} }
} }
console.log("Password reset successfully."); console.log("Password reset successfully.");
} }
} catch (e) { } catch (e) {
console.error("Error: " + e.message); console.error("Error: " + e.message);
@ -81,6 +87,45 @@ function question(question) {
}); });
} }
function disconnectAllSocketClients(username, password) {
return new Promise((resolve) => {
console.log("Connecting to " + localWebSocketURL + " to disconnect all other socket clients");
// Disconnect all socket connections
const socket = io(localWebSocketURL, {
transports: [ "websocket" ],
reconnection: false,
timeout: 5000,
});
socket.on("connect", () => {
socket.emit("login", {
username,
password,
}, (res) => {
if (res.ok) {
console.log("Logged in.");
socket.emit("disconnectOtherSocketClients");
} else {
console.warn("Login failed.");
console.warn("Please restart the server to disconnect all sessions.");
}
socket.close();
});
});
socket.on("connect_error", function () {
// The localWebSocketURL is not guaranteed to be working for some complicated Uptime Kuma setup
// Ask the user to restart the server manually
console.warn("Failed to connect to " + localWebSocketURL);
console.warn("Please restart the server to disconnect all sessions manually.");
resolve();
});
socket.on("disconnect", () => {
resolve();
});
});
}
if (!process.env.TEST_BACKEND) { if (!process.env.TEST_BACKEND) {
main(); main();
} }

View File

@ -11,10 +11,12 @@
}, },
"scripts": { "scripts": {
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint:js-prod": "npm run lint:js -- --max-warnings 0",
"lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .", "lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .",
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore", "lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
"lint-fix:style": "stylelint \"**/*.{vue,css,scss}\" --fix --ignore-path .gitignore", "lint-fix:style": "stylelint \"**/*.{vue,css,scss}\" --fix --ignore-path .gitignore",
"lint": "npm run lint:js && npm run lint:style", "lint": "npm run lint:js && npm run lint:style",
"lint:prod": "npm run lint:js-prod && npm run lint:style",
"dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"", "dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"",
"start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js", "start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js",
"start-frontend-devcontainer": "cross-env NODE_ENV=development DEVCONTAINER=1 vite --host --config ./config/vite.config.js", "start-frontend-devcontainer": "cross-env NODE_ENV=development DEVCONTAINER=1 vite --host --config ./config/vite.config.js",
@ -44,7 +46,7 @@
"build-docker-nightly-local": "npm run build && docker build -f docker/dockerfile -t louislam/uptime-kuma:nightly2 --target nightly .", "build-docker-nightly-local": "npm run build && docker build -f docker/dockerfile -t louislam/uptime-kuma:nightly2 --target nightly .",
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test2 --target pr-test2 . --push", "build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test2 --target pr-test2 . --push",
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain", "upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
"setup": "git checkout 1.23.8 && npm ci --production && npm run download-dist", "setup": "git checkout 1.23.9 && npm ci --production && npm run download-dist",
"download-dist": "node extra/download-dist.js", "download-dist": "node extra/download-dist.js",
"mark-as-nightly": "node extra/mark-as-nightly.js", "mark-as-nightly": "node extra/mark-as-nightly.js",
"reset-password": "node extra/reset-password.js", "reset-password": "node extra/reset-password.js",
@ -191,7 +193,6 @@
"typescript": "~4.4.4", "typescript": "~4.4.4",
"v-pagination-3": "~0.1.7", "v-pagination-3": "~0.1.7",
"vite": "~4.4.1", "vite": "~4.4.1",
"vite-plugin-commonjs": "^0.8.0",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vue": "~3.3.4", "vue": "~3.3.4",
"vue-chartjs": "~5.2.0", "vue-chartjs": "~5.2.0",

View File

@ -1,10 +1,9 @@
<svg width="640" height="640" viewBox="0 0 640 640" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="640" height="640" viewBox="0 0 640 640" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path d="M490.4 235.64C544.09 358.38 544.09 435.34 490.4 466.5C409.85 513.24 199.96 527.49 139.54 455.64C99.2601 407.74 99.2601 334.4 139.54 235.64C180.5 168.18 238.71 134.45 314.17 134.45C389.64 134.45 448.38 168.18 490.4 235.64Z" fill="url(#paint0_linear_381_799)"/> <g transform="matrix(1 0 0 1 320 320)">
<path d="M490.4 235.64C544.09 358.38 544.09 435.34 490.4 466.5C409.85 513.24 199.96 527.49 139.54 455.64C99.2601 407.74 99.2601 334.4 139.54 235.64C180.5 168.18 238.71 134.45 314.17 134.45C389.64 134.45 448.38 168.18 490.4 235.64Z" stroke="#F2F2F2" stroke-opacity="0.51" stroke-width="200"/> <linearGradient id="S3" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1 0 0 1 -319.99875 -320.0001577393)" x1="259.78" y1="261.15" x2="463.85" y2="456.49">
<defs>
<linearGradient id="paint0_linear_381_799" x1="259.78" y1="261.15" x2="463.85" y2="456.49" gradientUnits="userSpaceOnUse">
<stop stop-color="#5CDD8B"/> <stop stop-color="#5CDD8B"/>
<stop offset="1" stop-color="#86E6A9"/> <stop offset="1" stop-color="#86E6A9"/>
</linearGradient> </linearGradient>
</defs> <path style="stroke: rgb(242,242,242); stroke-opacity: 0.51; stroke-width: 200; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: url(#S3); fill-rule: nonzero; opacity: 1;" transform=" translate(0, 0)" d="M 170.40125 -84.36016 C 224.09125 38.37984 224.09125 115.33984 170.40125 146.49984 C 89.85125000000001 193.23984000000002 -120.03875 207.48984000000002 -180.45875 135.63984 C -220.73875 87.73983999999999 -220.73875 14.399839999999998 -180.45875 -84.36016000000001 C -139.49875 -151.82016 -81.28875000000001 -185.55016 -5.828750000000014 -185.55016 C 69.64124999999999 -185.55016 128.38125 -151.82016000000002 170.40124999999998 -84.36016000000001 z" stroke-linecap="round" />
</g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 893 B

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,29 +1,42 @@
const isFreeBSD = /^freebsd/.test(process.platform);
// Interop with browser // Interop with browser
const args = (typeof process !== "undefined") ? require("args-parser")(process.argv) : {}; const args = (typeof process !== "undefined") ? require("args-parser")(process.argv) : {};
const demoMode = args["demo"] || false;
const badgeConstants = { // If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
naColor: "#999", // Dual-stack support for (::)
defaultUpColor: "#66c20a", // Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD
defaultWarnColor: "#eed202", let hostEnv = isFreeBSD ? null : process.env.HOST;
defaultDownColor: "#c2290a", const hostname = args.host || process.env.UPTIME_KUMA_HOST || hostEnv;
defaultPendingColor: "#f8a306",
defaultMaintenanceColor: "#1747f5", const port = [ args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001 ]
defaultPingColor: "blue", // as defined by badge-maker / shields.io .map(portValue => parseInt(portValue))
defaultStyle: "flat", .find(portValue => !isNaN(portValue));
defaultPingValueSuffix: "ms",
defaultPingLabelSuffix: "h", const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
defaultUptimeValueSuffix: "%", const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
defaultUptimeLabelSuffix: "h", const sslKeyPassphrase = args["ssl-key-passphrase"] || process.env.UPTIME_KUMA_SSL_KEY_PASSPHRASE || process.env.SSL_KEY_PASSPHRASE || undefined;
defaultCertExpValueSuffix: " days",
defaultCertExpLabelSuffix: "h", const isSSL = sslKey && sslCert;
// Values Come From Default Notification Times
defaultCertExpireWarnDays: "14", function getLocalWebSocketURL() {
defaultCertExpireDownDays: "7" const protocol = isSSL ? "wss" : "ws";
}; const host = hostname || "localhost";
return `${protocol}://${host}:${port}`;
}
const localWebSocketURL = getLocalWebSocketURL();
const demoMode = args["demo"] || false;
module.exports = { module.exports = {
args, args,
hostname,
port,
sslKey,
sslCert,
sslKeyPassphrase,
isSSL,
localWebSocketURL,
demoMode, demoMode,
badgeConstants,
}; };

View File

@ -11,11 +11,10 @@ const { R } = require("redbean-node");
const apicache = require("../modules/apicache"); const apicache = require("../modules/apicache");
const Monitor = require("../model/monitor"); const Monitor = require("../model/monitor");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const { UP, MAINTENANCE, DOWN, PENDING, flipStatus, log } = require("../../src/util"); const { UP, MAINTENANCE, DOWN, PENDING, flipStatus, log, badgeConstants } = require("../../src/util");
const StatusPage = require("../model/status_page"); const StatusPage = require("../model/status_page");
const { UptimeKumaServer } = require("../uptime-kuma-server"); const { UptimeKumaServer } = require("../uptime-kuma-server");
const { makeBadge } = require("badge-maker"); const { makeBadge } = require("badge-maker");
const { badgeConstants } = require("../config");
const { Prometheus } = require("../prometheus"); const { Prometheus } = require("../prometheus");
const Database = require("../database"); const Database = require("../database");
const { UptimeCalculator } = require("../uptime-calculator"); const { UptimeCalculator } = require("../uptime-calculator");

View File

@ -4,7 +4,7 @@ const { UptimeKumaServer } = require("../uptime-kuma-server");
const StatusPage = require("../model/status_page"); const StatusPage = require("../model/status_page");
const { allowDevAllOrigin, sendHttpError } = require("../util-server"); const { allowDevAllOrigin, sendHttpError } = require("../util-server");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { badgeConstants } = require("../config"); const { badgeConstants } = require("../../src/util");
const { makeBadge } = require("badge-maker"); const { makeBadge } = require("badge-maker");
const { UptimeCalculator } = require("../uptime-calculator"); const { UptimeCalculator } = require("../uptime-calculator");

View File

@ -46,8 +46,13 @@ if (! process.env.NODE_ENV) {
process.env.NODE_ENV = "production"; process.env.NODE_ENV = "production";
} }
if (!process.env.UPTIME_KUMA_WS_ORIGIN_CHECK) {
process.env.UPTIME_KUMA_WS_ORIGIN_CHECK = "cors-like";
}
log.info("server", "Env: " + process.env.NODE_ENV); log.info("server", "Env: " + process.env.NODE_ENV);
log.debug("server", "Inside Container: " + (process.env.UPTIME_KUMA_IS_CONTAINER === "1")); log.debug("server", "Inside Container: " + (process.env.UPTIME_KUMA_IS_CONTAINER === "1"));
log.info("server", "WebSocket Origin Check: " + process.env.UPTIME_KUMA_WS_ORIGIN_CHECK);
const checkVersion = require("./check-version"); const checkVersion = require("./check-version");
log.info("server", "Uptime Kuma Version: " + checkVersion.version); log.info("server", "Uptime Kuma Version: " + checkVersion.version);
@ -72,8 +77,7 @@ const notp = require("notp");
const base32 = require("thirty-two"); const base32 = require("thirty-two");
const { UptimeKumaServer } = require("./uptime-kuma-server"); const { UptimeKumaServer } = require("./uptime-kuma-server");
const server = UptimeKumaServer.getInstance();
const server = UptimeKumaServer.getInstance(args);
const io = module.exports.io = server.io; const io = module.exports.io = server.io;
const app = server.app; const app = server.app;
@ -82,7 +86,7 @@ const Monitor = require("./model/monitor");
const User = require("./model/user"); const User = require("./model/user");
log.debug("server", "Importing Settings"); log.debug("server", "Importing Settings");
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, FBSD, doubleCheckPassword, startE2eTests, shake256, SHAKE256_LENGTH, allowDevAllOrigin, const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, doubleCheckPassword, startE2eTests, shake256, SHAKE256_LENGTH, allowDevAllOrigin,
} = require("./util-server"); } = require("./util-server");
log.debug("server", "Importing Notification"); log.debug("server", "Importing Notification");
@ -100,19 +104,13 @@ const { apiAuth } = require("./auth");
const { login } = require("./auth"); const { login } = require("./auth");
const passwordHash = require("./password-hash"); const passwordHash = require("./password-hash");
// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise. const hostname = config.hostname;
// Dual-stack support for (::)
// Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD
let hostEnv = FBSD ? null : process.env.HOST;
let hostname = args.host || process.env.UPTIME_KUMA_HOST || hostEnv;
if (hostname) { if (hostname) {
log.info("server", "Custom hostname: " + hostname); log.info("server", "Custom hostname: " + hostname);
} }
const port = [ args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001 ] const port = config.port;
.map(portValue => parseInt(portValue))
.find(portValue => !isNaN(portValue));
const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false; const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false;
const cloudflaredToken = args["cloudflared-token"] || process.env.UPTIME_KUMA_CLOUDFLARED_TOKEN || undefined; const cloudflaredToken = args["cloudflared-token"] || process.env.UPTIME_KUMA_CLOUDFLARED_TOKEN || undefined;
@ -1265,6 +1263,8 @@ let needSetup = false;
let user = await doubleCheckPassword(socket, password.currentPassword); let user = await doubleCheckPassword(socket, password.currentPassword);
await user.resetPassword(password.newPassword); await user.resetPassword(password.newPassword);
server.disconnectAllSocketClient(user.id, socket.id);
callback({ callback({
ok: true, ok: true,
msg: "successAuthChangePassword", msg: "successAuthChangePassword",

View File

@ -109,4 +109,14 @@ module.exports.generalSocketHandler = (socket, server) => {
msg: "Not found", msg: "Not found",
}); });
}); });
// Disconnect all other socket clients of the user
socket.on("disconnectOtherSocketClients", async () => {
try {
checkLogin(socket);
server.disconnectAllSocketClients(socket.userID, socket.id);
} catch (e) {
log.warn("disconnectAllSocketClients", e.message);
}
});
}; };

View File

@ -4,7 +4,7 @@ const fs = require("fs");
const http = require("http"); const http = require("http");
const { Server } = require("socket.io"); const { Server } = require("socket.io");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { log } = require("../src/util"); const { log, isDev } = require("../src/util");
const Database = require("./database"); const Database = require("./database");
const util = require("util"); const util = require("util");
const { Settings } = require("./settings"); const { Settings } = require("./settings");
@ -12,6 +12,7 @@ const dayjs = require("dayjs");
const childProcessAsync = require("promisify-child-process"); const childProcessAsync = require("promisify-child-process");
const path = require("path"); const path = require("path");
const axios = require("axios"); const axios = require("axios");
const { isSSL, sslKey, sslCert, sslKeyPassphrase } = require("./config");
// DO NOT IMPORT HERE IF THE MODULES USED `UptimeKumaServer.getInstance()`, put at the bottom of this file instead. // DO NOT IMPORT HERE IF THE MODULES USED `UptimeKumaServer.getInstance()`, put at the bottom of this file instead.
/** /**
@ -67,9 +68,9 @@ class UptimeKumaServer {
* @param {object} args Arguments to pass to instance constructor * @param {object} args Arguments to pass to instance constructor
* @returns {UptimeKumaServer} Server instance * @returns {UptimeKumaServer} Server instance
*/ */
static getInstance(args) { static getInstance() {
if (UptimeKumaServer.instance == null) { if (UptimeKumaServer.instance == null) {
UptimeKumaServer.instance = new UptimeKumaServer(args); UptimeKumaServer.instance = new UptimeKumaServer();
} }
return UptimeKumaServer.instance; return UptimeKumaServer.instance;
} }
@ -77,7 +78,7 @@ class UptimeKumaServer {
/** /**
* @param {object} args Arguments to initialise server with * @param {object} args Arguments to initialise server with
*/ */
constructor(args) { constructor() {
// SSL // SSL
const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined; const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined; const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
@ -91,7 +92,7 @@ class UptimeKumaServer {
log.info("server", "Creating express and socket.io instance"); log.info("server", "Creating express and socket.io instance");
this.app = express(); this.app = express();
if (sslKey && sslCert) { if (isSSL) {
log.info("server", "Server Type: HTTPS"); log.info("server", "Server Type: HTTPS");
this.httpServer = https.createServer({ this.httpServer = https.createServer({
key: fs.readFileSync(sslKey), key: fs.readFileSync(sslKey),
@ -119,7 +120,41 @@ class UptimeKumaServer {
UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType(); UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType();
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType(); UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
this.io = new Server(this.httpServer); this.io = new Server(this.httpServer, {
allowRequest: (req, callback) => {
let isOriginValid = true;
const bypass = isDev || process.env.UPTIME_KUMA_WS_ORIGIN_CHECK === "bypass";
if (!bypass) {
let host = req.headers.host;
// If this is set, it means the request is from the browser
let origin = req.headers.origin;
// If this is from the browser, check if the origin is allowed
if (origin) {
try {
let originURL = new URL(origin);
if (host !== originURL.host) {
isOriginValid = false;
log.error("auth", `Origin (${origin}) does not match host (${host}), IP: ${req.socket.remoteAddress}`);
}
} catch (e) {
// Invalid origin url, probably not from browser
isOriginValid = false;
log.error("auth", `Invalid origin url (${origin}), IP: ${req.socket.remoteAddress}`);
}
} else {
log.info("auth", `Origin is not set, IP: ${req.socket.remoteAddress}`);
}
} else {
log.debug("auth", "Origin check is bypassed");
}
callback(null, isOriginValid);
}
});
} }
/** /**
@ -424,6 +459,25 @@ class UptimeKumaServer {
getUserAgent() { getUserAgent() {
return "Uptime-Kuma/" + require("../package.json").version; return "Uptime-Kuma/" + require("../package.json").version;
} }
/**
* Force connected sockets of a user to refresh and disconnect.
* Used for resetting password.
* @param {string} userID
* @param {string?} currentSocketID
*/
disconnectAllSocketClients(userID, currentSocketID = undefined) {
for (const socket of this.io.sockets.sockets.values()) {
if (socket.userID === userID && socket.id !== currentSocketID) {
try {
socket.emit("refresh");
socket.disconnect();
} catch (e) {
}
}
}
}
} }
module.exports = { module.exports = {

View File

@ -1,14 +1,13 @@
const tcpp = require("tcp-ping"); const tcpp = require("tcp-ping");
const ping = require("@louislam/ping"); const ping = require("@louislam/ping");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { log, genSecret } = require("../src/util"); const { log, genSecret, badgeConstants } = require("../src/util");
const passwordHash = require("./password-hash"); const passwordHash = require("./password-hash");
const { Resolver } = require("dns"); const { Resolver } = require("dns");
const childProcess = 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 chroma = require("chroma-js"); const chroma = require("chroma-js");
const { badgeConstants } = require("./config");
const mssql = require("mssql"); const mssql = require("mssql");
const { Client } = require("pg"); const { Client } = require("pg");
const postgresConParse = require("pg-connection-string").parse; const postgresConParse = require("pg-connection-string").parse;

View File

@ -8,7 +8,7 @@
:placeholder="placeholder" :placeholder="placeholder"
:disabled="!enabled" :disabled="!enabled"
> >
<button class="btn btn-outline-primary" :aria-label="actionAriaLabel" @click="action()"> <button type="button" class="btn btn-outline-primary" :aria-label="actionAriaLabel" @click="action()">
<font-awesome-icon :icon="icon" /> <font-awesome-icon :icon="icon" />
</button> </button>
</div> </div>

View File

@ -3,7 +3,7 @@
<select :id="id" ref="select" v-model="model" class="form-select" :disabled="disabled" :required="required"> <select :id="id" ref="select" v-model="model" class="form-select" :disabled="disabled" :required="required">
<option v-for="option in options" :key="option" :value="option.value" :disabled="option.disabled">{{ option.label }}</option> <option v-for="option in options" :key="option" :value="option.value" :disabled="option.disabled">{{ option.label }}</option>
</select> </select>
<button class="btn btn-outline-primary" :class="{ disabled: actionDisabled }" :aria-label="actionAriaLabel" @click="action()"> <button type="button" class="btn btn-outline-primary" :class="{ disabled: actionDisabled }" :aria-label="actionAriaLabel" @click="action()">
<font-awesome-icon :icon="icon" aria-hidden="true" /> <font-awesome-icon :icon="icon" aria-hidden="true" />
</button> </button>
</div> </div>

View File

@ -135,7 +135,7 @@
<script lang="ts"> <script lang="ts">
import { Modal } from "bootstrap"; import { Modal } from "bootstrap";
import CopyableInput from "./CopyableInput.vue"; import CopyableInput from "./CopyableInput.vue";
import { default as serverConfig } from "../../server/config.js"; import { badgeConstants } from "../util.ts";
export default { export default {
components: { components: {
@ -230,7 +230,7 @@ export default {
"labelColor", "labelColor",
], ],
}, },
badgeConstants: serverConfig.badgeConstants, badgeConstants,
}; };
}, },

View File

@ -29,10 +29,10 @@ export default {
}, },
computed: { computed: {
startDateTime() { startDateTime() {
return dayjs(this.maintenance.timeslotList[0].startDate).tz(this.maintenance.timezone).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND); return dayjs(this.maintenance.timeslotList[0].startDate).tz(this.maintenance.timezone, true).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND);
}, },
endDateTime() { endDateTime() {
return dayjs(this.maintenance.timeslotList[0].endDate).tz(this.maintenance.timezone).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND); return dayjs(this.maintenance.timeslotList[0].endDate).tz(this.maintenance.timezone, true).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND);
} }
}, },
}; };

View File

@ -16,7 +16,10 @@
</a> </a>
<form> <form>
<input <input
v-model="searchText" class="form-control search-input" :placeholder="$t('Search...')" v-model="searchText"
class="form-control search-input"
:placeholder="$t('Search...')"
:aria-label="$t('Search monitored sites')"
autocomplete="off" autocomplete="off"
/> />
</form> </form>

View File

@ -13,6 +13,15 @@
<div class="mb-3"> <div class="mb-3">
<label for="ntfy-priority" class="form-label">{{ $t("Priority") }}</label> <label for="ntfy-priority" class="form-label">{{ $t("Priority") }}</label>
<input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1"> <input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1">
<div class="form-text">
<p v-if="$parent.notification.ntfyPriority >= 5">
{{ $t("ntfyPriorityHelptextAllEvents") }}
</p>
<i18n-t v-else tag="p" keypath="ntfyPriorityHelptextAllExceptDown">
<code>DOWN</code>
<code>{{ $parent.notification.ntfyPriority + 1 }}</code>
</i18n-t>
</div>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="authentication-method" class="form-label">{{ $t("ntfyAuthenticationMethod") }}</label> <label for="authentication-method" class="form-label">{{ $t("ntfyAuthenticationMethod") }}</label>

View File

@ -192,6 +192,7 @@
"Pink": "Pink", "Pink": "Pink",
"Custom": "Custom", "Custom": "Custom",
"Search...": "Search…", "Search...": "Search…",
"Search monitored sites": "Search monitored sites",
"Avg. Ping": "Avg. Ping", "Avg. Ping": "Avg. Ping",
"Avg. Response": "Avg. Response", "Avg. Response": "Avg. Response",
"Entry Page": "Entry Page", "Entry Page": "Entry Page",
@ -783,6 +784,8 @@
"lunaseaDeviceID": "Device ID", "lunaseaDeviceID": "Device ID",
"lunaseaUserID": "User ID", "lunaseaUserID": "User ID",
"ntfyAuthenticationMethod": "Authentication Method", "ntfyAuthenticationMethod": "Authentication Method",
"ntfyPriorityHelptextAllEvents": "All events are send with the maximum priority",
"ntfyPriorityHelptextAllExceptDown": "All events are send with this priority, except {0}-events, which have a priority of {1}",
"ntfyUsernameAndPassword": "Username and Password", "ntfyUsernameAndPassword": "Username and Password",
"twilioAccountSID": "Account SID", "twilioAccountSID": "Account SID",
"twilioApiKey": "Api Key (optional)", "twilioApiKey": "Api Key (optional)",

View File

@ -288,6 +288,10 @@ export default {
socket.on("initServerTimezone", () => { socket.on("initServerTimezone", () => {
socket.emit("initServerTimezone", dayjs.tz.guess()); socket.emit("initServerTimezone", dayjs.tz.guess());
}); });
socket.on("refresh", () => {
location.reload();
});
}, },
/** /**

View File

@ -900,9 +900,8 @@ import DockerHostDialog from "../components/DockerHostDialog.vue";
import RemoteBrowserDialog from "../components/RemoteBrowserDialog.vue"; import RemoteBrowserDialog from "../components/RemoteBrowserDialog.vue";
import ProxyDialog from "../components/ProxyDialog.vue"; import ProxyDialog from "../components/ProxyDialog.vue";
import TagsManager from "../components/TagsManager.vue"; import TagsManager from "../components/TagsManager.vue";
import { genSecret, isDev, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } from "../util.ts"; import { genSecret, isDev, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND, sleep } from "../util.ts";
import { hostNameRegexPattern } from "../util-frontend"; import { hostNameRegexPattern } from "../util-frontend";
import { sleep } from "../util";
import HiddenInput from "../components/HiddenInput.vue"; import HiddenInput from "../components/HiddenInput.vue";
const toast = useToast; const toast = useToast;

View File

@ -98,6 +98,27 @@ const consoleLevelColors : Record<string, string> = {
* @param s input status: UP or DOWN * @param s input status: UP or DOWN
* @returns {number} UP or DOWN * @returns {number} UP or DOWN
*/ */
export const badgeConstants = {
naColor: "#999",
defaultUpColor: "#66c20a",
defaultWarnColor: "#eed202",
defaultDownColor: "#c2290a",
defaultPendingColor: "#f8a306",
defaultMaintenanceColor: "#1747f5",
defaultPingColor: "blue", // as defined by badge-maker / shields.io
defaultStyle: "flat",
defaultPingValueSuffix: "ms",
defaultPingLabelSuffix: "h",
defaultUptimeValueSuffix: "%",
defaultUptimeLabelSuffix: "h",
defaultCertExpValueSuffix: " days",
defaultCertExpLabelSuffix: "h",
// Values Come From Default Notification Times
defaultCertExpireWarnDays: "14",
defaultCertExpireDownDays: "7"
};
/** Flip the status of s */
export function flipStatus(s: number) { export function flipStatus(s: number) {
if (s === UP) { if (s === UP) {
return DOWN; return DOWN;