diff --git a/server/model/monitor.js b/server/model/monitor.js
index 00eb87db..bd059785 100644
--- a/server/model/monitor.js
+++ b/server/model/monitor.js
@@ -2,7 +2,7 @@ const https = require("https");
const dayjs = require("dayjs");
const axios = require("axios");
const { Prometheus } = require("../prometheus");
-const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger } = require("../../src/util");
+const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } = require("../../src/util");
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery } = require("../util-server");
const { R } = require("redbean-node");
const { BeanModel } = require("redbean-node/dist/bean-model");
@@ -1189,6 +1189,15 @@ class Monitor extends BeanModel {
LIMIT 1`, [ monitorID ]);
return maintenance.count !== 0;
}
+
+ validate() {
+ if (this.interval > MAX_INTERVAL_SECOND) {
+ throw new Error(`Interval cannot be more than ${MAX_INTERVAL_SECOND} seconds`);
+ }
+ if (this.interval < MIN_INTERVAL_SECOND) {
+ throw new Error(`Interval cannot be less than ${MIN_INTERVAL_SECOND} seconds`);
+ }
+ }
}
module.exports = Monitor;
diff --git a/server/server.js b/server/server.js
index 78f98910..0bb894f8 100644
--- a/server/server.js
+++ b/server/server.js
@@ -632,6 +632,9 @@ let needSetup = false;
bean.import(monitor);
bean.user_id = socket.userID;
+
+ bean.validate();
+
await R.store(bean);
await updateMonitorNotification(bean.id, notificationIDList);
@@ -719,6 +722,8 @@ let needSetup = false;
bean.radiusCallingStationId = monitor.radiusCallingStationId;
bean.radiusSecret = monitor.radiusSecret;
+ bean.validate();
+
await R.store(bean);
await updateMonitorNotification(bean.id, monitor.notificationIDList);
diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue
index 5a821508..bce74644 100644
--- a/src/pages/EditMonitor.vue
+++ b/src/pages/EditMonitor.vue
@@ -271,7 +271,7 @@
-
+
@@ -287,7 +287,7 @@
{{ $t("Heartbeat Retry Interval") }}
({{ $t("retryCheckEverySecond", [ monitor.retryInterval ]) }})
-
+
@@ -575,7 +575,7 @@ import NotificationDialog from "../components/NotificationDialog.vue";
import DockerHostDialog from "../components/DockerHostDialog.vue";
import ProxyDialog from "../components/ProxyDialog.vue";
import TagsManager from "../components/TagsManager.vue";
-import { genSecret, isDev } from "../util.ts";
+import { genSecret, isDev, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } from "../util.ts";
const toast = useToast();
@@ -591,6 +591,8 @@ export default {
data() {
return {
+ minInterval: MIN_INTERVAL_SECOND,
+ maxInterval: MAX_INTERVAL_SECOND,
processing: false,
monitor: {
notificationIDList: {},
diff --git a/src/util.js b/src/util.js
index 9cdecc17..2c01120b 100644
--- a/src/util.js
+++ b/src/util.js
@@ -7,7 +7,7 @@
// Backend uses the compiled file util.js
// Frontend uses util.ts
Object.defineProperty(exports, "__esModule", { value: true });
-exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
+exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
const dayjs = require("dayjs");
exports.isDev = process.env.NODE_ENV === "development";
exports.appName = "Uptime Kuma";
@@ -22,6 +22,8 @@ exports.STATUS_PAGE_MAINTENANCE = 3;
exports.SQL_DATE_FORMAT = "YYYY-MM-DD";
exports.SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = "YYYY-MM-DD HH:mm";
+exports.MAX_INTERVAL_SECOND = 2073600; // 24 days
+exports.MIN_INTERVAL_SECOND = 20; // 20 seconds
/** Flip the status of s */
function flipStatus(s) {
if (s === exports.UP) {
diff --git a/src/util.ts b/src/util.ts
index fd2b466b..726a7da3 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -26,6 +26,9 @@ export const SQL_DATE_FORMAT = "YYYY-MM-DD";
export const SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
export const SQL_DATETIME_FORMAT_WITHOUT_SECOND = "YYYY-MM-DD HH:mm";
+export const MAX_INTERVAL_SECOND = 2073600; // 24 days
+export const MIN_INTERVAL_SECOND = 20; // 20 seconds
+
/** Flip the status of s */
export function flipStatus(s: number) {
if (s === UP) {