-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.23.X' into 1.23.13-to-2.0.0
# Conflicts: # .github/workflows/auto-test.yml # package-lock.json # package.json # server/database.js # server/model/monitor.js # server/monitor-types/real-browser-monitor-type.js # server/util-server.js # test/cypress/unit/i18n.spec.js
- Loading branch information
Showing
13 changed files
with
151 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
BEGIN TRANSACTION; | ||
|
||
PRAGMA writable_schema = TRUE; | ||
|
||
UPDATE | ||
SQLITE_MASTER | ||
SET | ||
sql = replace(sql, | ||
'monitor_id INTEGER NOT NULL', | ||
'monitor_id INTEGER NOT NULL REFERENCES [monitor] ([id]) ON DELETE CASCADE ON UPDATE CASCADE' | ||
) | ||
WHERE | ||
name = 'monitor_tls_info' | ||
AND type = 'table'; | ||
|
||
PRAGMA writable_schema = RESET; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,12 +245,12 @@ class Monitor extends BeanModel { | |
/** | ||
* Encode user and password to Base64 encoding | ||
* for HTTP "basic" auth, as per RFC-7617 | ||
* @param {string} user Username to encode | ||
* @param {string} pass Password to encode | ||
* @returns {string} Encoded username:password | ||
* @param {string|null} user - The username (nullable if not changed by a user) | ||
* @param {string|null} pass - The password (nullable if not changed by a user) | ||
* @returns {string} | ||
Check warning on line 250 in server/model/monitor.js GitHub Actions / check-linters
|
||
*/ | ||
encodeBase64(user, pass) { | ||
return Buffer.from(user + ":" + pass).toString("base64"); | ||
return Buffer.from(`${user || ""}:${pass || ""}`).toString("base64"); | ||
} | ||
|
||
/** | ||
|
@@ -533,6 +533,18 @@ class Monitor extends BeanModel { | |
} | ||
} | ||
|
||
let tlsInfo = {}; | ||
// Store tlsInfo when secureConnect event is emitted | ||
// The keylog event listener is a workaround to access the tlsSocket | ||
options.httpsAgent.once("keylog", async (line, tlsSocket) => { | ||
tlsSocket.once("secureConnect", async () => { | ||
tlsInfo = checkCertificate(tlsSocket); | ||
tlsInfo.valid = tlsSocket.authorized || false; | ||
|
||
await this.handleTlsInfo(tlsInfo); | ||
}); | ||
}); | ||
|
||
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`); | ||
log.debug("monitor", `[${this.name}] Axios Request`); | ||
|
||
|
@@ -542,31 +554,19 @@ class Monitor extends BeanModel { | |
bean.msg = `${res.status} - ${res.statusText}`; | ||
bean.ping = dayjs().valueOf() - startTime; | ||
|
||
// Check certificate if https is used | ||
let certInfoStartTime = dayjs().valueOf(); | ||
if (this.getUrl()?.protocol === "https:") { | ||
log.debug("monitor", `[${this.name}] Check cert`); | ||
try { | ||
let tlsInfoObject = checkCertificate(res); | ||
tlsInfo = await this.updateTlsInfo(tlsInfoObject); | ||
// fallback for if kelog event is not emitted, but we may still have tlsInfo, | ||
// e.g. if the connection is made through a proxy | ||
if (this.getUrl()?.protocol === "https:" && tlsInfo.valid === undefined) { | ||
const tlsSocket = res.request.res.socket; | ||
|
||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) { | ||
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`); | ||
await this.checkCertExpiryNotifications(tlsInfoObject); | ||
} | ||
if (tlsSocket) { | ||
tlsInfo = checkCertificate(tlsSocket); | ||
tlsInfo.valid = tlsSocket.authorized || false; | ||
|
||
} catch (e) { | ||
if (e.message !== "No TLS certificate in response") { | ||
log.error("monitor", "Caught error"); | ||
log.error("monitor", e.message); | ||
} | ||
await this.handleTlsInfo(tlsInfo); | ||
} | ||
} | ||
|
||
if (process.env.TIMELOGGER === "1") { | ||
log.debug("monitor", "Cert Info Query Time: " + (dayjs().valueOf() - certInfoStartTime) + "ms"); | ||
} | ||
|
||
if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) { | ||
log.info("monitor", res.data); | ||
} | ||
|
@@ -599,8 +599,12 @@ class Monitor extends BeanModel { | |
let data = res.data; | ||
|
||
// convert data to object | ||
if (typeof data === "string") { | ||
data = JSON.parse(data); | ||
if (typeof data === "string" && res.headers["content-type"] !== "application/json") { | ||
try { | ||
data = JSON.parse(data); | ||
} catch (_) { | ||
// Failed to parse as JSON, just process it as a string | ||
} | ||
} | ||
|
||
let expression = jsonata(this.jsonPath); | ||
|
@@ -1615,6 +1619,20 @@ class Monitor extends BeanModel { | |
return oAuthAccessToken; | ||
} | ||
|
||
/** | ||
* Store TLS certificate information and check for expiry | ||
* @param {Object} tlsInfo Information about the TLS connection | ||
Check failure on line 1624 in server/model/monitor.js GitHub Actions / check-linters
|
||
* @returns {Promise<void>} | ||
*/ | ||
async handleTlsInfo(tlsInfo) { | ||
await this.updateTlsInfo(tlsInfo); | ||
this.prometheus?.update(null, tlsInfo); | ||
|
||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) { | ||
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`); | ||
await this.checkCertExpiryNotifications(tlsInfo); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Monitor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,21 +653,27 @@ const parseCertificateInfo = function (info) { | |
|
||
/** | ||
* Check if certificate is valid | ||
* @param {object} res Response object from axios | ||
* @returns {object} Object containing certificate information | ||
* @throws No socket was found to check certificate for | ||
* @param {tls.TLSSocket} socket TLSSocket, which may or may not be connected | ||
* @returns {Object} Object containing certificate information | ||
Check failure on line 657 in server/util-server.js GitHub Actions / check-linters
|
||
*/ | ||
exports.checkCertificate = function (res) { | ||
if (!res.request.res.socket) { | ||
throw new Error("No socket found"); | ||
exports.checkCertificate = function (socket) { | ||
let certInfoStartTime = dayjs().valueOf(); | ||
|
||
// Return null if there is no socket | ||
if (socket === undefined || socket == null) { | ||
return null; | ||
} | ||
|
||
const info = res.request.res.socket.getPeerCertificate(true); | ||
const valid = res.request.res.socket.authorized || false; | ||
const info = socket.getPeerCertificate(true); | ||
const valid = socket.authorized || false; | ||
|
||
log.debug("cert", "Parsing Certificate Info"); | ||
const parsedInfo = parseCertificateInfo(info); | ||
|
||
if (process.env.TIMELOGGER === "1") { | ||
log.debug("monitor", "Cert Info Query Time: " + (dayjs().valueOf() - certInfoStartTime) + "ms"); | ||
} | ||
|
||
return { | ||
valid: valid, | ||
certInfo: parsedInfo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.