mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-10-01 01:25:45 -04:00
Compare commits
No commits in common. "806eb799c1ef9e067ebe4a9cbea653436f79460b" and "ce82ad1c12f221ce940549994c26648c46179ca5" have entirely different histories.
806eb799c1
...
ce82ad1c12
@ -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, PENDING, flipStatus, log } = require("../../src/util");
|
||||
const { UP, MAINTENANCE, DOWN, 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 DOWN:
|
||||
case 0:
|
||||
badgeValues.color = downColor;
|
||||
badgeValues.message = downLabel;
|
||||
break;
|
||||
case UP:
|
||||
case 1:
|
||||
badgeValues.color = upColor;
|
||||
badgeValues.message = upLabel;
|
||||
break;
|
||||
case PENDING:
|
||||
case 2:
|
||||
badgeValues.color = pendingColor;
|
||||
badgeValues.message = pendingLabel;
|
||||
break;
|
||||
case MAINTENANCE:
|
||||
case 3:
|
||||
badgeValues.color = maintenanceColor;
|
||||
badgeValues.message = maintenanceLabel;
|
||||
break;
|
||||
|
@ -949,14 +949,6 @@ 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 = `((^${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\\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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}))|:)))(%.+)?\\s*$))`;
|
||||
// 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,10 +9,6 @@ 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;
|
||||
@ -27,10 +23,6 @@ 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