mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-19 10:46:48 +02:00
Merge e668c8b261
into 443d5cf554
This commit is contained in:
commit
961d83ac04
3 changed files with 25 additions and 10 deletions
|
@ -1,10 +1,10 @@
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const fs = require("fs");
|
const fsAsync = require("fs").promises;
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const Database = require("./database");
|
const Database = require("./database");
|
||||||
const { axiosAbortSignal } = require("./util-server");
|
const { axiosAbortSignal, fsExists } = require("./util-server");
|
||||||
|
|
||||||
class DockerHost {
|
class DockerHost {
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class DockerHost {
|
||||||
options.socketPath = dockerHost.dockerDaemon;
|
options.socketPath = dockerHost.dockerDaemon;
|
||||||
} else if (dockerHost.dockerType === "tcp") {
|
} else if (dockerHost.dockerType === "tcp") {
|
||||||
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
|
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
|
||||||
options.httpsAgent = new https.Agent(DockerHost.getHttpsAgentOptions(dockerHost.dockerType, options.baseURL));
|
options.httpsAgent = new https.Agent(await DockerHost.getHttpsAgentOptions(dockerHost.dockerType, options.baseURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -141,9 +141,9 @@ class DockerHost {
|
||||||
* File names can also be overridden via 'DOCKER_TLS_FILE_NAME_(CA|KEY|CERT)'.
|
* File names can also be overridden via 'DOCKER_TLS_FILE_NAME_(CA|KEY|CERT)'.
|
||||||
* @param {string} dockerType i.e. "tcp" or "socket"
|
* @param {string} dockerType i.e. "tcp" or "socket"
|
||||||
* @param {string} url The docker host URL rewritten to https://
|
* @param {string} url The docker host URL rewritten to https://
|
||||||
* @returns {object} HTTP agent options
|
* @returns {Promise<object>} HTTP agent options
|
||||||
*/
|
*/
|
||||||
static getHttpsAgentOptions(dockerType, url) {
|
static async getHttpsAgentOptions(dockerType, url) {
|
||||||
let baseOptions = {
|
let baseOptions = {
|
||||||
maxCachedSessions: 0,
|
maxCachedSessions: 0,
|
||||||
rejectUnauthorized: true
|
rejectUnauthorized: true
|
||||||
|
@ -156,10 +156,10 @@ class DockerHost {
|
||||||
let certPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCert);
|
let certPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCert);
|
||||||
let keyPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameKey);
|
let keyPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameKey);
|
||||||
|
|
||||||
if (dockerType === "tcp" && fs.existsSync(caPath) && fs.existsSync(certPath) && fs.existsSync(keyPath)) {
|
if (dockerType === "tcp" && await fsExists(caPath) && await fsExists(certPath) && await fsExists(keyPath)) {
|
||||||
let ca = fs.readFileSync(caPath);
|
let ca = await fsAsync.readFile(caPath);
|
||||||
let key = fs.readFileSync(keyPath);
|
let key = await fsAsync.readFile(keyPath);
|
||||||
let cert = fs.readFileSync(certPath);
|
let cert = await fsAsync.readFile(certPath);
|
||||||
certOptions = {
|
certOptions = {
|
||||||
ca,
|
ca,
|
||||||
key,
|
key,
|
||||||
|
|
|
@ -746,7 +746,7 @@ class Monitor extends BeanModel {
|
||||||
} else if (dockerHost._dockerType === "tcp") {
|
} else if (dockerHost._dockerType === "tcp") {
|
||||||
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
||||||
options.httpsAgent = new https.Agent(
|
options.httpsAgent = new https.Agent(
|
||||||
DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL)
|
await DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ const radiusClient = require("node-radius-client");
|
||||||
const redis = require("redis");
|
const redis = require("redis");
|
||||||
const oidc = require("openid-client");
|
const oidc = require("openid-client");
|
||||||
const tls = require("tls");
|
const tls = require("tls");
|
||||||
|
const { exists } = require("fs");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
dictionaries: {
|
dictionaries: {
|
||||||
|
@ -1096,3 +1097,17 @@ module.exports.axiosAbortSignal = (timeoutMs) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async version of fs.existsSync
|
||||||
|
* @param {PathLike} path File path
|
||||||
|
* @returns {Promise<boolean>} True if file exists, false otherwise
|
||||||
|
*/
|
||||||
|
function fsExists(path) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
exists(path, function (exists) {
|
||||||
|
resolve(exists);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
module.exports.fsExists = fsExists;
|
||||||
|
|
Loading…
Add table
Reference in a new issue