mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-10-01 01:25:45 -04:00
Compare commits
4 Commits
ce82ad1c12
...
806eb799c1
Author | SHA1 | Date | |
---|---|---|---|
|
806eb799c1 | ||
|
c699868bb9 | ||
|
95c934e08b | ||
|
348d0170fa |
@ -4,7 +4,7 @@ const { R } = require("redbean-node");
|
||||
const apicache = require("../modules/apicache");
|
||||
const Monitor = require("../model/monitor");
|
||||
const dayjs = require("dayjs");
|
||||
const { UP, MAINTENANCE, DOWN, flipStatus, log } = require("../../src/util");
|
||||
const { UP, MAINTENANCE, DOWN, PENDING, flipStatus, log } = require("../../src/util");
|
||||
const StatusPage = require("../model/status_page");
|
||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||
const { makeBadge } = require("badge-maker");
|
||||
@ -147,19 +147,19 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
|
||||
|
||||
badgeValues.label = label ?? "";
|
||||
switch (state) {
|
||||
case 0:
|
||||
case DOWN:
|
||||
badgeValues.color = downColor;
|
||||
badgeValues.message = downLabel;
|
||||
break;
|
||||
case 1:
|
||||
case UP:
|
||||
badgeValues.color = upColor;
|
||||
badgeValues.message = upLabel;
|
||||
break;
|
||||
case 2:
|
||||
case PENDING:
|
||||
badgeValues.color = pendingColor;
|
||||
badgeValues.message = pendingLabel;
|
||||
break;
|
||||
case 3:
|
||||
case MAINTENANCE:
|
||||
badgeValues.color = maintenanceColor;
|
||||
badgeValues.message = maintenanceLabel;
|
||||
break;
|
||||
|
@ -949,6 +949,14 @@ message HealthCheckResponse {
|
||||
this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4);
|
||||
}
|
||||
|
||||
if (this.monitor.hostname) {
|
||||
this.monitor.hostname = this.monitor.hostname.trim();
|
||||
}
|
||||
|
||||
if (this.monitor.url) {
|
||||
this.monitor.url = this.monitor.url.trim();
|
||||
}
|
||||
|
||||
if (this.isAdd) {
|
||||
this.$root.add(this.monitor, async (res) => {
|
||||
|
||||
|
@ -88,7 +88,7 @@ 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 = `((^\\s*${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]))\\s*$)|(^\\s*((([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-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){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_])$`;
|
||||
|
||||
|
@ -9,6 +9,10 @@ describe("Test util-frontend.js", () => {
|
||||
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;
|
||||
@ -23,6 +27,10 @@ describe("Test util-frontend.js", () => {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user