diff --git a/package-lock.json b/package-lock.json index 8fb4c7a1f..cc23e5971 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,6 @@ "axios-ntlm": "1.3.0", "badge-maker": "~3.3.1", "bcryptjs": "~2.4.3", - "cacheable-lookup": "~6.0.4", "chardet": "~1.4.0", "check-password-strength": "^2.0.5", "cheerio": "~1.0.0-rc.12", @@ -5853,14 +5852,6 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "optional": true }, - "node_modules/cacheable-lookup": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz", - "integrity": "sha512-mbcDEZCkv2CZF4G01kr8eBd/5agkt9oCqz75tJMSIsquvRZ2sL6Hi5zGVKi/0OSC9oO1GHfJ2AV0ZIOY9vye0A==", - "engines": { - "node": ">=10.6.0" - } - }, "node_modules/cacheable-request": { "version": "10.2.14", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.14.tgz", diff --git a/package.json b/package.json index d278bb211..456e2c5de 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "axios-ntlm": "1.3.0", "badge-maker": "~3.3.1", "bcryptjs": "~2.4.3", - "cacheable-lookup": "~6.0.4", "chardet": "~1.4.0", "check-password-strength": "^2.0.5", "cheerio": "~1.0.0-rc.12", diff --git a/server/cacheable-dns-http-agent.js b/server/cacheable-dns-http-agent.js deleted file mode 100644 index bcc955689..000000000 --- a/server/cacheable-dns-http-agent.js +++ /dev/null @@ -1,88 +0,0 @@ -const https = require("https"); -const http = require("http"); -const CacheableLookup = require("cacheable-lookup"); -const { Settings } = require("./settings"); -const { log } = require("../src/util"); - -class CacheableDnsHttpAgent { - - static cacheable = new CacheableLookup(); - - static httpAgentList = {}; - static httpsAgentList = {}; - - static enable = false; - - /** - * Register/Disable cacheable to global agents - * @returns {void} - */ - static async update() { - log.debug("CacheableDnsHttpAgent", "update"); - let isEnable = await Settings.get("dnsCache"); - - if (isEnable !== this.enable) { - log.debug("CacheableDnsHttpAgent", "value changed"); - - if (isEnable) { - log.debug("CacheableDnsHttpAgent", "enable"); - this.cacheable.install(http.globalAgent); - this.cacheable.install(https.globalAgent); - } else { - log.debug("CacheableDnsHttpAgent", "disable"); - this.cacheable.uninstall(http.globalAgent); - this.cacheable.uninstall(https.globalAgent); - } - } - - this.enable = isEnable; - } - - /** - * Attach cacheable to HTTP agent - * @param {http.Agent} agent Agent to install - * @returns {void} - */ - static install(agent) { - this.cacheable.install(agent); - } - - /** - * @param {https.AgentOptions} agentOptions Options to pass to HTTPS agent - * @returns {https.Agent} The new HTTPS agent - */ - static getHttpsAgent(agentOptions) { - if (!this.enable) { - return new https.Agent(agentOptions); - } - - let key = JSON.stringify(agentOptions); - if (!(key in this.httpsAgentList)) { - this.httpsAgentList[key] = new https.Agent(agentOptions); - this.cacheable.install(this.httpsAgentList[key]); - } - return this.httpsAgentList[key]; - } - - /** - * @param {http.AgentOptions} agentOptions Options to pass to the HTTP agent - * @returns {https.Agents} The new HTTP agent - */ - static getHttpAgent(agentOptions) { - if (!this.enable) { - return new http.Agent(agentOptions); - } - - let key = JSON.stringify(agentOptions); - if (!(key in this.httpAgentList)) { - this.httpAgentList[key] = new http.Agent(agentOptions); - this.cacheable.install(this.httpAgentList[key]); - } - return this.httpAgentList[key]; - } - -} - -module.exports = { - CacheableDnsHttpAgent, -}; diff --git a/server/model/monitor.js b/server/model/monitor.js index e0b52062c..6e2bcf5c0 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -15,7 +15,6 @@ const { demoMode } = require("../config"); const version = require("../../package.json").version; const apicache = require("../modules/apicache"); const { UptimeKumaServer } = require("../uptime-kuma-server"); -const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent"); const { DockerHost } = require("../docker"); const Gamedig = require("gamedig"); const jsonata = require("jsonata"); @@ -24,6 +23,8 @@ const crypto = require("crypto"); const { UptimeCalculator } = require("../uptime-calculator"); const { CookieJar } = require("tough-cookie"); const { HttpsCookieAgent } = require("http-cookie-agent/http"); +const https = require("https"); +const http = require("http"); const rootCertificates = rootCertificatesFingerprints(); @@ -667,12 +668,12 @@ class Monitor extends BeanModel { headers: { "Accept": "*/*", }, - httpsAgent: CacheableDnsHttpAgent.getHttpsAgent({ + httpsAgent: new https.Agent({ maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) rejectUnauthorized: !this.getIgnoreTls(), secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT, }), - httpAgent: CacheableDnsHttpAgent.getHttpAgent({ + httpAgent: new http.Agent({ maxCachedSessions: 0, }), maxRedirects: this.maxredirects, @@ -719,12 +720,12 @@ class Monitor extends BeanModel { headers: { "Accept": "*/*", }, - httpsAgent: CacheableDnsHttpAgent.getHttpsAgent({ + httpsAgent: new https.Agent({ maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) rejectUnauthorized: !this.getIgnoreTls(), secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT, }), - httpAgent: CacheableDnsHttpAgent.getHttpAgent({ + httpAgent: new http.Agent({ maxCachedSessions: 0, }), }; @@ -739,7 +740,7 @@ class Monitor extends BeanModel { options.socketPath = dockerHost._dockerDaemon; } else if (dockerHost._dockerType === "tcp") { options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon); - options.httpsAgent = CacheableDnsHttpAgent.getHttpsAgent( + options.httpsAgent = new https.Agent( DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL) ); } diff --git a/server/server.js b/server/server.js index b5665fa63..098b731f9 100644 --- a/server/server.js +++ b/server/server.js @@ -144,7 +144,6 @@ const { maintenanceSocketHandler } = require("./socket-handlers/maintenance-sock const { apiKeySocketHandler } = require("./socket-handlers/api-key-socket-handler"); const { generalSocketHandler } = require("./socket-handlers/general-socket-handler"); const { Settings } = require("./settings"); -const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent"); const apicache = require("./modules/apicache"); const { resetChrome } = require("./monitor-types/real-browser-monitor-type"); const { EmbeddedMariaDB } = require("./embedded-mariadb"); @@ -1322,8 +1321,6 @@ let needSetup = false; await setSettings("general", data); server.entryPage = data.entryPage; - await CacheableDnsHttpAgent.update(); - // Also need to apply timezone globally if (data.serverTimezone) { await server.setTimezone(data.serverTimezone); diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 6a06f7da6..f3a1c7b72 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -7,7 +7,6 @@ const { R } = require("redbean-node"); const { log } = require("../src/util"); const Database = require("./database"); const util = require("util"); -const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent"); const { Settings } = require("./settings"); const dayjs = require("dayjs"); const childProcessAsync = require("promisify-child-process"); @@ -131,8 +130,6 @@ class UptimeKumaServer { // Static this.app.use("/screenshots", express.static(Database.screenshotDir)); - await CacheableDnsHttpAgent.update(); - process.env.TZ = await this.getTimezone(); dayjs.tz.setDefault(process.env.TZ); log.debug("DEBUG", "Timezone: " + process.env.TZ); diff --git a/src/components/settings/General.vue b/src/components/settings/General.vue index cec237588..487c3ba3a 100644 --- a/src/components/settings/General.vue +++ b/src/components/settings/General.vue @@ -187,46 +187,6 @@ - -
- - -
- - -
- -
- - -
-
-