Skip to content

Commit

Permalink
Merge branch 'louislam:master' into ntfy-bearer-authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
sharknoon authored Mar 21, 2023
2 parents e8814e8 + 7231763 commit 442f54d
Show file tree
Hide file tree
Showing 39 changed files with 1,723 additions and 164 deletions.
13 changes: 13 additions & 0 deletions db/patch-monitor-tls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;

ALTER TABLE monitor
ADD tls_ca TEXT default null;

ALTER TABLE monitor
ADD tls_cert TEXT default null;

ALTER TABLE monitor
ADD tls_key TEXT default null;

COMMIT;
3 changes: 2 additions & 1 deletion extra/deploy-demo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const prompt = (query) => new Promise((resolve) => rl.question(query, resolve));
});
console.log(result.stdout + result.stderr);

/*
result = await ssh.execCommand("pm2 restart 1", {
cwd,
});
console.log(result.stdout + result.stderr);
console.log(result.stdout + result.stderr);*/

} catch (e) {
console.log(e);
Expand Down
2 changes: 1 addition & 1 deletion extra/sort-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lines = lines.filter((line) => line !== "");
lines = [ ...new Set(lines) ];

// Remove @weblate and @UptimeKumaBot
lines = lines.filter((line) => line !== "@weblate" && line !== "@UptimeKumaBot");
lines = lines.filter((line) => line !== "@weblate" && line !== "@UptimeKumaBot" && line !== "@louislam");

// Sort the lines
lines = lines.sort();
Expand Down
50 changes: 11 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uptime-kuma",
"version": "1.21.0-beta.0",
"version": "1.21.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,7 +39,7 @@
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --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",
"setup": "git checkout 1.20.2 && npm ci --production && npm run download-dist",
"setup": "git checkout 1.21.0 && npm ci --production && npm run download-dist",
"download-dist": "node extra/download-dist.js",
"mark-as-nightly": "node extra/mark-as-nightly.js",
"reset-password": "node extra/reset-password.js",
Expand Down Expand Up @@ -69,7 +69,7 @@
},
"dependencies": {
"@grpc/grpc-js": "~1.7.3",
"@louislam/ping": "~0.4.2-mod.2",
"@louislam/ping": "~0.4.4-mod.0",
"@louislam/sqlite3": "15.1.2",
"args-parser": "~1.3.0",
"axios": "~0.27.0",
Expand Down
1 change: 1 addition & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Database {
"patch-http-body-encoding.sql": true,
"patch-add-description-monitor.sql": true,
"patch-api-key-table.sql": true,
"patch-monitor-tls.sql": true,
};

/**
Expand Down
29 changes: 26 additions & 3 deletions server/model/maintenance_timeslot.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ class MaintenanceTimeslot extends BeanModel {
bean.start_date = maintenance.start_date;
bean.end_date = maintenance.end_date;
bean.generated_next = true;
return await R.store(bean);

if (!await this.isDuplicateTimeslot(bean)) {
await R.store(bean);
return bean;
} else {
log.debug("maintenance", "Duplicate timeslot, skip");
return null;
}

} else if (maintenance.strategy === "recurring-interval") {
// Prevent dead loop, in case interval_day is not set
Expand Down Expand Up @@ -144,6 +151,15 @@ class MaintenanceTimeslot extends BeanModel {
}
}

static async isDuplicateTimeslot(timeslot) {
let bean = await R.findOne("maintenance_timeslot", "maintenance_id = ? AND start_date = ? AND end_date = ?", [
timeslot.maintenance_id,
timeslot.start_date,
timeslot.end_date
]);
return bean !== null;
}

/**
* Generate a next timeslot for all recurring types
* @param maintenance
Expand All @@ -161,7 +177,7 @@ class MaintenanceTimeslot extends BeanModel {

// Keep generating from the first possible date, until it is ok
while (true) {
log.debug("timeslot", "startDateTime: " + startDateTime.format());
//log.debug("timeslot", "startDateTime: " + startDateTime.format());

// Handling out of effective date range
if (startDateTime.diff(dayjs.utc(maintenance.end_date)) > 0) {
Expand Down Expand Up @@ -193,7 +209,14 @@ class MaintenanceTimeslot extends BeanModel {
bean.start_date = localToUTC(startDateTime);
bean.end_date = localToUTC(endDateTime);
bean.generated_next = false;
return await R.store(bean);

if (!await this.isDuplicateTimeslot(bean)) {
await R.store(bean);
return bean;
} else {
log.debug("maintenance", "Duplicate timeslot, skip");
return null;
}
}
}

Expand Down
18 changes: 16 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class Monitor extends BeanModel {
mqttPassword: this.mqttPassword,
authWorkstation: this.authWorkstation,
authDomain: this.authDomain,
tlsCa: this.tlsCa,
tlsCert: this.tlsCert,
tlsKey: this.tlsKey,
};
}

Expand Down Expand Up @@ -331,6 +334,18 @@ class Monitor extends BeanModel {
options.httpsAgent = new https.Agent(httpsAgentOptions);
}

if (this.auth_method === "mtls") {
if (this.tlsCert !== null && this.tlsCert !== "") {
options.httpsAgent.options.cert = Buffer.from(this.tlsCert);
}
if (this.tlsCa !== null && this.tlsCa !== "") {
options.httpsAgent.options.ca = Buffer.from(this.tlsCa);
}
if (this.tlsKey !== null && this.tlsKey !== "") {
options.httpsAgent.options.key = Buffer.from(this.tlsKey);
}
}

log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
log.debug("monitor", `[${this.name}] Axios Request`);

Expand Down Expand Up @@ -836,7 +851,6 @@ class Monitor extends BeanModel {
domain: this.authDomain,
workstation: this.authWorkstation ? this.authWorkstation : undefined
});

} else {
res = await axios.request(options);
}
Expand Down Expand Up @@ -1251,7 +1265,7 @@ class Monitor extends BeanModel {
for (let notification of notificationList) {
try {
log.debug("monitor", "Sending to " + notification.name);
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will be expired in ${daysRemaining} days`);
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will expire in ${daysRemaining} days`);
sent = true;
} catch (e) {
log.error("monitor", "Cannot send cert notification to " + notification.name);
Expand Down
3 changes: 3 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ let needSetup = false;
bean.headers = monitor.headers;
bean.basic_auth_user = monitor.basic_auth_user;
bean.basic_auth_pass = monitor.basic_auth_pass;
bean.tlsCa = monitor.tlsCa;
bean.tlsCert = monitor.tlsCert;
bean.tlsKey = monitor.tlsKey;
bean.interval = monitor.interval;
bean.retryInterval = monitor.retryInterval;
bean.resendInterval = monitor.resendInterval;
Expand Down
1 change: 1 addition & 0 deletions server/uptime-kuma-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class UptimeKumaServer {

/** Load the timeslots for maintenance */
async generateMaintenanceTimeslots() {
log.debug("maintenance", "Routine: Generating Maintenance Timeslots");

// Prevent #2776
// Remove duplicate maintenance_timeslot with same start_date, end_date and maintenance_id
Expand Down
3 changes: 3 additions & 0 deletions server/util-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ exports.redisPingAsync = function (dsn) {
});
client.connect().then(() => {
client.ping().then((res, err) => {
if (client.isOpen) {
client.disconnect();
}
if (err) {
reject(err);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/components/notifications/LunaSea.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<template>
<div class="mb-3">
<label for="lunasea-notification-target" class="form-label">{{ $t("Target") }}<span style="color: red;"><sup>*</sup></span></label>
<label for="lunasea-notification-target" class="form-label">{{ $t("lunaseaTarget") }}<span style="color: red;"><sup>*</sup></span></label>
<div class="form-text">
<p>
<select id="lunasea-notification-target" v-model="$parent.notification.lunaseaTarget" class="form-select" required>
<option value="device">Device</option>
<option value="user">User</option>
<option value="device">{{ $t("lunaseaDeviceID") }}</option>
<option value="user">{{ $t("lunaseaUserID") }}</option>
</select>
</p>
</div>
<div v-if="$parent.notification.lunaseaTarget === 'device'">
<label for="lunasea-device" class="form-label">{{ $t("Device ID") }}<span style="color: red;"><sup>*</sup></span></label>
<label for="lunasea-device" class="form-label">{{ $t("lunaseaDeviceID") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="lunasea-device" v-model="$parent.notification.lunaseaDevice" type="text" class="form-control">
</div>
<div v-if="$parent.notification.lunaseaTarget === 'user'">
<label for="lunasea-device" class="form-label">{{ $t("User ID") }}<span style="color: red;"><sup>*</sup></span></label>
<label for="lunasea-device" class="form-label">{{ $t("lunaseaUserID") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="lunasea-device" v-model="$parent.notification.lunaseaUserID" type="text" class="form-control">
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/notifications/SMTP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
(leave blank for default one)<br />
{{NAME}}: Service Name<br />
{{HOSTNAME_OR_URL}}: Hostname or URL<br />
{{URL}}: URL<br />
{{STATUS}}: Status<br />
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const languageList = {
"el-GR": "Ελληνικά",
"yue": "繁體中文 (廣東話 / 粵語)",
"ro": "Limba română",
"ur": "Urdu"
"ur": "Urdu",
"ge": "ქართული"
};

let messages = {
Expand Down
Loading

0 comments on commit 442f54d

Please sign in to comment.