diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 4d2105d4..87e7f5ff 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -16,7 +16,6 @@ Please delete any options that are not relevant.
- User interface (UI)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
-- Translation update
- Other
- This change requires a documentation update
diff --git a/.github/workflows/auto-test.yml b/.github/workflows/auto-test.yml
index b49a253c..94462712 100644
--- a/.github/workflows/auto-test.yml
+++ b/.github/workflows/auto-test.yml
@@ -6,8 +6,12 @@ name: Auto Test
on:
push:
branches: [ master ]
+ paths-ignore:
+ - '*.md'
pull_request:
branches: [ master ]
+ paths-ignore:
+ - '*.md'
jobs:
auto-test:
@@ -18,7 +22,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
- node: [ 14, 16, 17, 18 ]
+ node: [ 14, 16, 18, 19 ]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
@@ -36,6 +40,7 @@ jobs:
env:
HEADLESS_TEST: 1
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
+
check-linters:
runs-on: ubuntu-latest
@@ -66,3 +71,19 @@ jobs:
- run: npm install
- run: npm run build
- run: npm run cy:test
+
+ frontend-unit-tests:
+ needs: [ check-linters ]
+ runs-on: ubuntu-latest
+ steps:
+ - run: git config --global core.autocrlf false # Mainly for Windows
+ - uses: actions/checkout@v3
+
+ - name: Use Node.js 14
+ uses: actions/setup-node@v3
+ with:
+ node-version: 14
+ cache: 'npm'
+ - run: npm install
+ - run: npm run build
+ - run: npm run cy:run:unit
diff --git a/.github/workflows/close-incorrect-issue.yml b/.github/workflows/close-incorrect-issue.yml
index 026022df..762bc968 100644
--- a/.github/workflows/close-incorrect-issue.yml
+++ b/.github/workflows/close-incorrect-issue.yml
@@ -1,4 +1,3 @@
-
name: Close Incorrect Issue
on:
@@ -12,13 +11,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
- node-version: [16.x]
+ node-version: [16]
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v2
+ uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
diff --git a/.github/workflows/stale-bot.yml b/.github/workflows/stale-bot.yml
index 5b4568e1..b39f68fc 100644
--- a/.github/workflows/stale-bot.yml
+++ b/.github/workflows/stale-bot.yml
@@ -3,13 +3,13 @@ on:
workflow_dispatch:
schedule:
- cron: '0 */6 * * *'
-#Run every 6 hours
+#Run every 6 hours
jobs:
stale:
runs-on: ubuntu-latest
steps:
- - uses: actions/stale@v5
+ - uses: actions/stale@v7
with:
stale-issue-message: 'We are clearing up our old issues and your ticket has been open for 3 months with no activity. Remove stale label or comment or this will be closed in 2 days.'
close-issue-message: 'This issue was closed because it has been stalled for 2 days with no activity.'
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 12fd6ed4..3f455092 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,6 +1,6 @@
# Project Info
-First of all, thank you everyone who made pull requests for Uptime Kuma, I never thought GitHub Community can be that nice! And also because of this, I also never thought other people actually read my code and edit my code. It is not structured and commented so well, lol. Sorry about that.
+First of all, I want to thank everyone who made pull requests for Uptime Kuma. I never thought the GitHub Community would be so nice! Because of this, I also never thought that other people would actually read and edit my code. It is not very well structured or commented, sorry about that.
The project was created with vite.js (vue3). Then I created a subdirectory called "server" for server part. Both frontend and backend share the same package.json.
@@ -17,8 +17,11 @@ The frontend code build into "dist" directory. The server (express.js) exposes t
## Directories
+- config (dev config files)
- data (App data)
+- db (Base database and migration scripts)
- dist (Frontend build)
+- docker (Dockerfiles)
- extra (Extra useful scripts)
- public (Frontend resources for dev only)
- server (Server source code)
@@ -27,20 +30,23 @@ The frontend code build into "dist" directory. The server (express.js) exposes t
## Can I create a pull request for Uptime Kuma?
-Yes or no, it depends on what you will try to do. Since I don't want to waste your time, be sure to **create an empty draft pull request or open an issue, so we can discuss first**. Especially for a large pull request or you don't know it will be merged or not.
+Yes or no, it depends on what you will try to do. Since I don't want to waste your time, be sure to **create an empty draft pull request or open an issue, so we can have a discussion first**. Especially for a large pull request or you don't know it will be merged or not.
Here are some references:
✅ Usually Accept:
-- Bug/Security fix
-- Translations
+- Bug fix
+- Security fix
- Adding notification providers
+- Adding new language files (You should go to https://weblate.kuma.pet for existing languages)
+- Adding new language keys: `$t("...")`
⚠️ Discussion First
- Large pull requests
- New features
❌ Won't Merge
+- A dedicated pr for translating existing languages (You can now translate on https://weblate.kuma.pet)
- Do not pass auto test
- Any breaking changes
- Duplicated pull request
@@ -48,8 +54,13 @@ Here are some references:
- UI/UX is not close to Uptime Kuma
- Existing logic is completely modified or deleted for no reason
- A function that is completely out of scope
+- Convert existing code into other programming languages
- Unnecessary large code changes (Hard to review, causes code conflicts to other pull requests)
+The above cases cannot cover all situations.
+
+I (@louislam) have the final say. If your pull request does not meet my expectations, I will reject it, no matter how much time you spend on it. Therefore, it is essential to have a discussion beforehand.
+
I will mark your pull request in the [milestones](https://github.com/louislam/uptime-kuma/milestones), if I am plan to review and merge it.
Also, please don't rush or ask for ETA, because I have to understand the pull request, make sure it is no breaking changes and stick to my vision of this project, especially for large pull requests.
@@ -72,13 +83,13 @@ Before deep into coding, discussion first is preferred. Creating an empty pull r
## Project Styles
-I personally do not like something need to learn so much and need to config so much before you can finally start the app.
+I personally do not like something that requires so many configurations before you can finally start the app. I hope Uptime Kuma installation could be as easy as like installing a mobile app.
-- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
+- Easy to install for non-Docker users, no native build dependency is needed (for x86_64/armv7/arm64), no extra config, no extra effort required to get it running
- Single container for Docker users, no very complex docker-compose file. Just map the volume and expose the port, then good to go
-- Settings should be configurable in the frontend. Environment variable is not encouraged, unless it is related to startup such as `DATA_DIR`.
+- Settings should be configurable in the frontend. Environment variable is not encouraged, unless it is related to startup such as `DATA_DIR`
- Easy to use
-- The web UI styling should be consistent and nice.
+- The web UI styling should be consistent and nice
## Coding Styles
@@ -87,7 +98,7 @@ I personally do not like something need to learn so much and need to config so m
- Follow ESLint
- Methods and functions should be documented with JSDoc
-## Name convention
+## Name Conventions
- Javascript/Typescript: camelCaseType
- SQLite: snake_case (Underscore)
@@ -101,7 +112,7 @@ I personally do not like something need to learn so much and need to config so m
- IDE that supports ESLint and EditorConfig (I am using IntelliJ IDEA)
- A SQLite GUI tool (SQLite Expert Personal is suggested)
-## Install dependencies
+## Install Dependencies for Development
```bash
npm ci
@@ -119,6 +130,12 @@ Port `3000` and port `3001` will be used.
npm run dev
```
+But sometimes, you would like to keep restart the server, but not the frontend, you can run these command in two terminals:
+```
+npm run start-frontend-dev
+npm run start-server-dev
+```
+
## Backend Server
It binds to `0.0.0.0:3001` by default.
@@ -134,12 +151,15 @@ express.js is used for:
### Structure in /server/
+- jobs/ (Jobs that are running in another process)
- model/ (Object model, auto mapping to the database table name)
- modules/ (Modified 3rd-party modules)
+- monitor_types (Monitor Types)
- notification-providers/ (individual notification logic)
- routers/ (Express Routers)
- socket-handler (Socket.io Handlers)
-- server.js (Server entry point and main logic)
+- server.js (Server entry point)
+- uptime-kuma-server.js (UptimeKumaServer class, main logic should be here, but some still in `server.js`)
## Frontend Dev Server
@@ -172,15 +192,11 @@ The data and socket logic are in `src/mixins/socket.js`.
## Unit Test
-It is an end-to-end testing. It is using Jest and Puppeteer.
-
```bash
npm run build
npm test
```
-By default, the Chromium window will be shown up during the test. Specifying `HEADLESS_TEST=1` for terminal environments.
-
## Dependencies
Both frontend and backend share the same package.json. However, the frontend dependencies are eventually not used in the production environment, because it is usually also baked into dist files. So:
@@ -194,18 +210,12 @@ Both frontend and backend share the same package.json. However, the frontend dep
### Update Dependencies
-Install `ncu`
-https://github.com/raineorshine/npm-check-updates
-
-```bash
-ncu -u -t patch
-npm install
-```
-
Since previously updating Vite 2.5.10 to 2.6.0 broke the application completely, from now on, it should update patch release version only.
Patch release = the third digit ([Semantic Versioning](https://semver.org/))
+If for maybe security reasons, a library must be updated. Then you must need to check if there are any breaking changes.
+
## Translations
Please read: https://github.com/louislam/uptime-kuma/tree/master/src/languages
diff --git a/README.md b/README.md
index 55a6ec50..cdefe6a0 100644
--- a/README.md
+++ b/README.md
@@ -1,38 +1,39 @@
# Uptime Kuma
-[](https://github.com/sponsors/louislam)
+[](https://github.com/sponsors/louislam)
+
+
+
## 🥔 Live Demo
Try it!
- Tokyo Demo Server: https://demo.uptime.kuma.pet (Sponsored by [Uptime Kuma Sponsors](https://github.com/louislam/uptime-kuma#%EF%B8%8F-sponsors))
-- Europe Demo Server: https://demo.uptime-kuma.karimi.dev:27000 (Provided by [@mhkarimi1383](https://github.com/mhkarimi1383))
It is a temporary live demo, all data will be deleted after 10 minutes. Use the one that is closer to you, but I suggest that you should install and try it out for the best demo experience.
## ⭐ Features
-* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / Ping / DNS Record / Push / Steam Game Server / Docker Containers.
-* Fancy, Reactive, Fast UI/UX.
-* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications).
-* 20 second intervals.
-* [Multi Languages](https://github.com/louislam/uptime-kuma/tree/master/src/languages)
-* Multiple Status Pages
-* Map Status Page to Domain
-* Ping Chart
-* Certificate Info
-* Proxy Support
-* 2FA available
+* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / Ping / DNS Record / Push / Steam Game Server / Docker Containers
+* Fancy, Reactive, Fast UI/UX
+* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
+* 20 second intervals
+* [Multi Languages](https://github.com/louislam/uptime-kuma/tree/master/src/lang)
+* Multiple status pages
+* Map status pages to specific domains
+* Ping chart
+* Certificate info
+* Proxy support
+* 2FA support
## 🔧 How to Install
@@ -44,14 +45,14 @@ docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name upti
⚠️ Please use a **local volume** only. Other types such as NFS are not supported.
-Browse to http://localhost:3001 after starting.
+Uptime Kuma is now running on http://localhost:3001
### 💪🏻 Non-Docker
Required Tools:
- [Node.js](https://nodejs.org/en/download/) >= 14
- [Git](https://git-scm.com/downloads)
-- [pm2](https://pm2.keymetrics.io/) - For run in background
+- [pm2](https://pm2.keymetrics.io/) - For running Uptime Kuma in the background
```bash
# Update your npm to the latest version
@@ -73,7 +74,7 @@ pm2 start server/server.js --name uptime-kuma
```
-Browse to http://localhost:3001 after starting.
+Uptime Kuma is now running on http://localhost:3001
More useful PM2 Commands
@@ -171,7 +172,7 @@ Check out the latest beta release here: https://github.com/louislam/uptime-kuma/
If you want to report a bug or request a new feature, feel free to open a [new issue](https://github.com/louislam/uptime-kuma/issues).
### Translations
-If you want to translate Uptime Kuma into your language, please read: https://github.com/louislam/uptime-kuma/tree/master/src/languages
+If you want to translate Uptime Kuma into your language, please visit [Weblate Readme](https://github.com/louislam/uptime-kuma/blob/master/src/lang/README.md).
Feel free to correct my grammar in this README, source code, or wiki, as my mother language is not English and my grammar is not that great.
diff --git a/SECURITY.md b/SECURITY.md
index d5941a97..657aa3eb 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -2,9 +2,9 @@
## Reporting a Vulnerability
-Please report security issues to uptime@kuma.pet.
+Please report security issues to https://github.com/louislam/uptime-kuma/security/advisories/new.
-Do not use the issue tracker or discuss it in the public as it will cause more damage.
+Do not use the public issue tracker or discuss it in the public as it will cause more damage.
## Supported Versions
diff --git a/config/cypress.frontend.config.js b/config/cypress.frontend.config.js
new file mode 100644
index 00000000..eecdcb8d
--- /dev/null
+++ b/config/cypress.frontend.config.js
@@ -0,0 +1,10 @@
+const { defineConfig } = require("cypress");
+
+module.exports = defineConfig({
+ e2e: {
+ supportFile: false,
+ specPattern: [
+ "test/cypress/unit/**/*.js"
+ ],
+ }
+});
diff --git a/db/patch-add-gamedig-monitor.sql b/db/patch-add-gamedig-monitor.sql
new file mode 100644
index 00000000..061bed30
--- /dev/null
+++ b/db/patch-add-gamedig-monitor.sql
@@ -0,0 +1,5 @@
+BEGIN TRANSACTION;
+
+ ALTER TABLE monitor
+ ADD game VARCHAR(255);
+ COMMIT
diff --git a/db/patch-ping-packet-size.sql b/db/patch-ping-packet-size.sql
new file mode 100644
index 00000000..d65ec8ed
--- /dev/null
+++ b/db/patch-ping-packet-size.sql
@@ -0,0 +1,5 @@
+-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
+BEGIN TRANSACTION;
+ALTER TABLE monitor
+ ADD packet_size INTEGER DEFAULT 56 NOT NULL;
+COMMIT;
diff --git a/docker/builder-go.dockerfile b/docker/builder-go.dockerfile
new file mode 100644
index 00000000..1d25843b
--- /dev/null
+++ b/docker/builder-go.dockerfile
@@ -0,0 +1,16 @@
+############################################
+# Build in Golang
+# Run npm run build-healthcheck-armv7 in the host first, another it will be super slow where it is building the armv7 healthcheck
+############################################
+FROM golang:1.19-buster
+WORKDIR /app
+ARG TARGETPLATFORM
+COPY ./extra/ ./extra/
+
+# Compile healthcheck.go
+RUN apt update && \
+ apt --yes --no-install-recommends install curl && \
+ curl -sL https://deb.nodesource.com/setup_18.x | bash && \
+ apt --yes --no-install-recommends install nodejs && \
+ node ./extra/build-healthcheck.js $TARGETPLATFORM && \
+ apt --yes remove nodejs
diff --git a/docker/debian-base.dockerfile b/docker/debian-base.dockerfile
index 1f0a83fd..8b5df5be 100644
--- a/docker/debian-base.dockerfile
+++ b/docker/debian-base.dockerfile
@@ -10,8 +10,8 @@ WORKDIR /app
# Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them.
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 \
- sqlite3 iputils-ping util-linux dumb-init && \
- pip3 --no-cache-dir install apprise==1.2.0 && \
+ sqlite3 iputils-ping util-linux dumb-init git && \
+ pip3 --no-cache-dir install apprise==1.2.1 && \
rm -rf /var/lib/apt/lists/* && \
apt --yes autoremove
diff --git a/docker/dockerfile b/docker/dockerfile
index acba709e..328733cb 100644
--- a/docker/dockerfile
+++ b/docker/dockerfile
@@ -1,19 +1,9 @@
############################################
# Build in Golang
# Run npm run build-healthcheck-armv7 in the host first, another it will be super slow where it is building the armv7 healthcheck
+# Check file: builder-go.dockerfile
############################################
-FROM golang:1.19.4-buster AS build_healthcheck
-WORKDIR /app
-ARG TARGETPLATFORM
-COPY ./extra/ ./extra/
-
-# Compile healthcheck.go
-RUN apt update
-RUN apt --yes --no-install-recommends install curl
-RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
-RUN apt --yes --no-install-recommends install nodejs
-RUN node -v
-RUN node ./extra/build-healthcheck.js $TARGETPLATFORM
+FROM louislam/uptime-kuma:builder-go AS build_healthcheck
############################################
# Build in Node.js
@@ -22,10 +12,13 @@ FROM louislam/uptime-kuma:base-debian AS build
WORKDIR /app
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
+COPY .npmrc .npmrc
+COPY package.json package.json
+COPY package-lock.json package-lock.json
+RUN npm ci --omit=dev
COPY . .
COPY --from=build_healthcheck /app/extra/healthcheck /app/extra/healthcheck
-RUN npm ci --production && \
- chmod +x /app/extra/entrypoint.sh
+RUN chmod +x /app/extra/entrypoint.sh
############################################
# ⭐ Main Image (Slim)
diff --git a/extra/beta/update-version.js b/extra/beta/update-version.js
index df2cb40a..7abac5ef 100644
--- a/extra/beta/update-version.js
+++ b/extra/beta/update-version.js
@@ -32,6 +32,10 @@ if (! exists) {
process.exit(1);
}
+/**
+ * Commit updated files
+ * @param {string} version Version to update to
+ */
function commit(version) {
let msg = "Update to " + version;
@@ -47,6 +51,10 @@ function commit(version) {
console.log(res.stdout.toString().trim());
}
+/**
+ * Create a tag with the specified version
+ * @param {string} version Tag to create
+ */
function tag(version) {
let res = childProcess.spawnSync("git", [ "tag", version ]);
console.log(res.stdout.toString().trim());
@@ -55,6 +63,11 @@ function tag(version) {
console.log(res.stdout.toString().trim());
}
+/**
+ * Check if a tag exists for the specified version
+ * @param {string} version Version to check
+ * @returns {boolean} Does the tag already exist
+ */
function tagExists(version) {
if (! version) {
throw new Error("invalid version");
diff --git a/extra/download-cloudflared.js b/extra/download-cloudflared.js
index 41519b7c..74b9bad2 100644
--- a/extra/download-cloudflared.js
+++ b/extra/download-cloudflared.js
@@ -25,6 +25,10 @@ if (platform === "linux/amd64") {
const file = fs.createWriteStream("cloudflared.deb");
get("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-" + arch + ".deb");
+/**
+ * Download specified file
+ * @param {string} url URL to request
+ */
function get(url) {
http.get(url, function (res) {
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
diff --git a/extra/healthcheck.go b/extra/healthcheck.go
index 779b1583..f79b3e65 100644
--- a/extra/healthcheck.go
+++ b/extra/healthcheck.go
@@ -1,3 +1,7 @@
+/*
+ * If changed, have to run `npm run build-docker-builder-go`.
+ * This script should be run after a period of time (180s), because the server may need some time to prepare.
+ */
package main
import (
@@ -7,12 +11,17 @@ import (
"net/http"
"os"
"runtime"
+ "strings"
"time"
)
func main() {
isFreeBSD := runtime.GOOS == "freebsd"
+ // Is K8S + uptime-kuma as the container name
+ // See #2083
+ isK8s := strings.HasPrefix(os.Getenv("UPTIME_KUMA_PORT"), "tcp://")
+
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
@@ -40,7 +49,11 @@ func main() {
hostname = "127.0.0.1"
}
- port := os.Getenv("UPTIME_KUMA_PORT")
+ port := ""
+ // UPTIME_KUMA_PORT is override by K8S unexpectedly,
+ if !isK8s {
+ port = os.Getenv("UPTIME_KUMA_PORT")
+ }
if len(port) == 0 {
port = os.Getenv("PORT")
}
diff --git a/extra/healthcheck.js b/extra/healthcheck.js
index 9b95cf26..40691418 100644
--- a/extra/healthcheck.js
+++ b/extra/healthcheck.js
@@ -19,17 +19,17 @@ if (sslKey && sslCert) {
// 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.
// Dual-stack support for (::)
-let hostname = process.env.UPTIME_KUMA_HOST;
+let hostname = process.env.UPTIME_KUMA_SERVICE_HOST || process.env.UPTIME_KUMA_HOST || "::";
// Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD
if (!hostname && !FBSD) {
hostname = process.env.HOST;
}
-const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001);
+const port = parseInt(process.env.UPTIME_KUMA_SERVICE_PORT || process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001);
let options = {
- host: hostname || "127.0.0.1",
+ host: hostname,
port: port,
timeout: 28 * 1000,
};
diff --git a/extra/mark-as-nightly.js b/extra/mark-as-nightly.js
index ebc67da3..ada2aca8 100644
--- a/extra/mark-as-nightly.js
+++ b/extra/mark-as-nightly.js
@@ -1,11 +1,12 @@
const pkg = require("../package.json");
const fs = require("fs");
const util = require("../src/util");
+const dayjs = require("dayjs");
util.polyfill();
const oldVersion = pkg.version;
-const newVersion = oldVersion + "-nightly-" + util.genSecret(8);
+const newVersion = oldVersion + "-nightly-" + dayjs().format("YYYYMMDDHHmmss");
console.log("Old Version: " + oldVersion);
console.log("New Version: " + newVersion);
diff --git a/extra/remove-2fa.js b/extra/remove-2fa.js
index 0f3f6346..f88c43fc 100644
--- a/extra/remove-2fa.js
+++ b/extra/remove-2fa.js
@@ -43,6 +43,11 @@ const main = async () => {
console.log("Finished.");
};
+/**
+ * Ask question of user
+ * @param {string} question Question to ask
+ * @returns {Promise+ {{ plugin.description }} +
+ {{ $t("Version") }}: {{ plugin.version }} Repo ++ {{ $t("wayToGetKookGuildID") }} +
+{{ $t("Powered by") }} {{ $t("Uptime Kuma" ) }} @@ -310,6 +321,8 @@ import ImageCropUpload from "vue-image-crop-upload"; import { PrismEditor } from "vue-prism-editor"; import "vue-prism-editor/dist/prismeditor.min.css"; // import the styles somewhere import { useToast } from "vue-toastification"; +import { marked } from "marked"; +import DOMPurify from "dompurify"; import Confirm from "../components/Confirm.vue"; import PublicGroupList from "../components/PublicGroupList.vue"; import MaintenanceTime from "../components/MaintenanceTime.vue"; @@ -477,6 +490,13 @@ export default { return this.overallStatus === STATUS_PAGE_MAINTENANCE; }, + incidentHTML() { + return DOMPurify.sanitize(marked(this.incident.content)); + }, + + footerHTML() { + return DOMPurify.sanitize(marked(this.config.footerText)); + }, }, watch: { @@ -836,6 +856,15 @@ export default { this.config.domainNameList.splice(index, 1); }, + /** + * Generate sanitized HTML from maintenance description + * @param {string} description + * @returns {string} Sanitized HTML + */ + maintenanceHTML(description) { + return DOMPurify.sanitize(marked(description)); + }, + } }; diff --git a/src/router.js b/src/router.js index 38048826..35647511 100644 --- a/src/router.js +++ b/src/router.js @@ -18,12 +18,14 @@ import NotFound from "./pages/NotFound.vue"; import DockerHosts from "./components/settings/Docker.vue"; import MaintenanceDetails from "./pages/MaintenanceDetails.vue"; import ManageMaintenance from "./pages/ManageMaintenance.vue"; +import Plugins from "./components/settings/Plugins.vue"; // Settings - Sub Pages import Appearance from "./components/settings/Appearance.vue"; import General from "./components/settings/General.vue"; const Notifications = () => import("./components/settings/Notifications.vue"); import ReverseProxy from "./components/settings/ReverseProxy.vue"; +import Tags from "./components/settings/Tags.vue"; import MonitorHistory from "./components/settings/MonitorHistory.vue"; const Security = () => import("./components/settings/Security.vue"); import Proxies from "./components/settings/Proxies.vue"; @@ -95,6 +97,10 @@ const routes = [ path: "reverse-proxy", component: ReverseProxy, }, + { + path: "tags", + component: Tags, + }, { path: "monitor-history", component: MonitorHistory, @@ -115,6 +121,10 @@ const routes = [ path: "backup", component: Backup, }, + { + path: "plugins", + component: Plugins, + }, { path: "about", component: About, diff --git a/src/util-frontend.js b/src/util-frontend.js index 3323f327..882ee291 100644 --- a/src/util-frontend.js +++ b/src/util-frontend.js @@ -78,3 +78,45 @@ export function getResBaseURL() { return ""; } } + +/** + * + * @param {} mqtt wheather or not the regex should take into account the fact that it is an mqtt uri + * @returns RegExp The requested regex + */ +export function hostNameRegexPattern(mqtt = false) { + // mqtt, mqtts, ws and wss schemes accepted by mqtt.js (https://github.com/mqttjs/MQTT.js/#connect) + const mqttSchemeRegexPattern = "((mqtt|ws)s?:\\/\\/)?"; + // Source: https://digitalfortress.tech/tips/top-15-commonly-used-regex/ + const ipRegexPattern = `((^${mqtt ? mqttSchemeRegexPattern : ""}((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$)|(^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?$))`; + // Source: https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address + const hostNameRegexPattern = `^${mqtt ? mqttSchemeRegexPattern : ""}([a-zA-Z0-9])?(([a-zA-Z0-9_]|[a-zA-Z0-9_][a-zA-Z0-9\\-_]*[a-zA-Z0-9_])\\.)*([A-Za-z0-9_]|[A-Za-z0-9_][A-Za-z0-9\\-_]*[A-Za-z0-9_])$`; + + return `${ipRegexPattern}|${hostNameRegexPattern}`; +} + +/** + * Get the tag color options + * Shared between components + * @returns {Object[]} + */ +export function colorOptions(self) { + return [ + { name: self.$t("Gray"), + color: "#4B5563" }, + { name: self.$t("Red"), + color: "#DC2626" }, + { name: self.$t("Orange"), + color: "#D97706" }, + { name: self.$t("Green"), + color: "#059669" }, + { name: self.$t("Blue"), + color: "#2563EB" }, + { name: self.$t("Indigo"), + color: "#4F46E5" }, + { name: self.$t("Purple"), + color: "#7C3AED" }, + { name: self.$t("Pink"), + color: "#DB2777" }, + ]; +} diff --git a/src/util.js b/src/util.js index f157e9e9..6b8f8f37 100644 --- a/src/util.js +++ b/src/util.js @@ -106,7 +106,13 @@ class Logger { } module = module.toUpperCase(); level = level.toUpperCase(); - const now = dayjs.tz(new Date()).format(); + let now; + if (dayjs.tz) { + now = dayjs.tz(new Date()).format(); + } + else { + now = dayjs().format(); + } const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg; if (level === "INFO") { console.info(formattedMessage); @@ -309,6 +315,11 @@ function getMonitorRelativeURL(id) { return "/dashboard/" + id; } exports.getMonitorRelativeURL = getMonitorRelativeURL; +/** + * Get relative path for maintenance + * @param id ID of maintenance + * @returns Formatted relative path + */ function getMaintenanceRelativeURL(id) { return "/maintenance/" + id; } @@ -355,6 +366,11 @@ function parseTimeFromTimeObject(obj) { return result; } exports.parseTimeFromTimeObject = parseTimeFromTimeObject; +/** + * Convert ISO date to UTC + * @param input Date + * @returns ISO Date time + */ function isoToUTCDateTime(input) { return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT); } @@ -373,6 +389,12 @@ function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) { return dayjs.utc(input).local().format(format); } exports.utcToLocal = utcToLocal; +/** + * Convert local datetime to UTC + * @param input Local date + * @param format Format to return + * @returns Date in requested format + */ function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) { return dayjs(input).utc().format(format); } diff --git a/src/util.ts b/src/util.ts index 6d3aabeb..e8a2706e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -122,7 +122,12 @@ class Logger { module = module.toUpperCase(); level = level.toUpperCase(); - const now = dayjs.tz(new Date()).format(); + let now; + if (dayjs.tz) { + now = dayjs.tz(new Date()).format(); + } else { + now = dayjs().format(); + } const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg; if (level === "INFO") { @@ -347,6 +352,11 @@ export function getMonitorRelativeURL(id: string) { return "/dashboard/" + id; } +/** + * Get relative path for maintenance + * @param id ID of maintenance + * @returns Formatted relative path + */ export function getMaintenanceRelativeURL(id: string) { return "/maintenance/" + id; } @@ -400,7 +410,11 @@ export function parseTimeFromTimeObject(obj : any) { return result; } - +/** + * Convert ISO date to UTC + * @param input Date + * @returns ISO Date time + */ export function isoToUTCDateTime(input : string) { return dayjs(input).utc().format(SQL_DATETIME_FORMAT); } @@ -419,6 +433,12 @@ export function utcToLocal(input : string, format = SQL_DATETIME_FORMAT) { return dayjs.utc(input).local().format(format); } +/** + * Convert local datetime to UTC + * @param input Local date + * @param format Format to return + * @returns Date in requested format + */ export function localToUTC(input : string, format = SQL_DATETIME_FORMAT) { return dayjs(input).utc().format(format); } diff --git a/test/cypress/unit/i18n.spec.js b/test/cypress/unit/i18n.spec.js new file mode 100644 index 00000000..da63d95a --- /dev/null +++ b/test/cypress/unit/i18n.spec.js @@ -0,0 +1,44 @@ +import { currentLocale } from "../../../src/i18n"; + +describe("Test i18n.js", () => { + + it("currentLocale()", () => { + const setLanguage = (language) => { + Object.defineProperty(window.navigator, 'language', { + value: language, + writable: true + }); + } + setLanguage('en-EN'); + + expect(currentLocale()).equal("en"); + + setLanguage('zh-HK'); + expect(currentLocale()).equal("zh-HK"); + + // Note that in Safari on iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc. + // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language + setLanguage('zh-hk'); + expect(currentLocale()).equal("en"); + + setLanguage('en-US'); + expect(currentLocale()).equal("en"); + + setLanguage('ja-ZZ'); + expect(currentLocale()).equal("ja"); + + setLanguage('zz-ZZ'); + expect(currentLocale()).equal("en"); + + setLanguage('zz-ZZ'); + expect(currentLocale()).equal("en"); + + setLanguage('en'); + localStorage.locale = "en"; + expect(currentLocale()).equal("en"); + + localStorage.locale = "zh-HK"; + expect(currentLocale()).equal("zh-HK"); + }); + +}); \ No newline at end of file diff --git a/test/cypress/unit/util-frontend.spec.js b/test/cypress/unit/util-frontend.spec.js new file mode 100644 index 00000000..9bfd4bec --- /dev/null +++ b/test/cypress/unit/util-frontend.spec.js @@ -0,0 +1,41 @@ +import { hostNameRegexPattern } from "../../../src/util-frontend"; + +describe("Test util-frontend.js", () => { + + describe("hostNameRegexPattern()", () => { + it('should return a valid regex for non mqtt hostnames', () => { + const regex = new RegExp(hostNameRegexPattern(false)); + + expect(regex.test("www.test.com")).to.be.true; + expect(regex.test("127.0.0.1")).to.be.true; + expect(regex.test("192.168.1.156")).to.be.true; + expect(regex.test(" 192.168.1.145")).to.be.false; + expect(regex.test("192.168.1.145 ")).to.be.false; + expect(regex.test(" fe80::3282:3ff:ae28:592")).to.be.false; + expect(regex.test("fe80::3282:3ff:ae28:592 ")).to.be.false; + + ["mqtt", "mqtts", "ws", "wss"].forEach(schema => { + expect(regex.test(`${schema}://www.test.com`)).to.be.false; + expect(regex.test(`${schema}://127.0.0.1`)).to.be.false; + }); + }); + it('should return a valid regex for mqtt hostnames', () => { + const hostnameString = hostNameRegexPattern(false); + console.log('*********', hostnameString, '***********'); + const regex = new RegExp(hostNameRegexPattern(true)); + + expect(regex.test("www.test.com")).to.be.true; + expect(regex.test("127.0.0.1")).to.be.true; + expect(regex.test("192.168.1.156")).to.be.true; + expect(regex.test(" 192.168.1.145")).to.be.false; + expect(regex.test("192.168.1.145 ")).to.be.false; + expect(regex.test(" fe80::3282:3ff:ae28:592")).to.be.false; + expect(regex.test("fe80::3282:3ff:ae28:592 ")).to.be.false; + + ["mqtt", "mqtts", "ws", "wss"].forEach(schema => { + expect(regex.test(`${schema}://www.test.com`)).to.be.true; + expect(regex.test(`${schema}://127.0.0.1`)).to.be.true; + }); + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index c5454642..441d846e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "module": "commonjs", "lib": [ "es2020", - "DOM", + "DOM" ], "removeComments": false, "preserveConstEnums": true,