mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-30 18:24:03 +00:00
Reload proxy settings for monitors in the monitorList
This commit is contained in:
parent
5027fcd320
commit
008dc27f52
2 changed files with 21 additions and 2 deletions
|
@ -3,6 +3,7 @@ const HttpProxyAgent = require("http-proxy-agent");
|
||||||
const HttpsProxyAgent = require("https-proxy-agent");
|
const HttpsProxyAgent = require("https-proxy-agent");
|
||||||
const SocksProxyAgent = require("socks-proxy-agent");
|
const SocksProxyAgent = require("socks-proxy-agent");
|
||||||
const { debug } = require("../src/util");
|
const { debug } = require("../src/util");
|
||||||
|
const server = require("./server");
|
||||||
|
|
||||||
class Proxy {
|
class Proxy {
|
||||||
|
|
||||||
|
@ -144,6 +145,22 @@ class Proxy {
|
||||||
httpsAgent
|
httpsAgent
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload proxy settings for current monitors
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async reloadProxy() {
|
||||||
|
let updatedList = await R.getAssoc("SELECT id, proxy_id FROM monitor");
|
||||||
|
|
||||||
|
for (let monitorID in server.monitorList) {
|
||||||
|
let monitor = server.monitorList[monitorID];
|
||||||
|
|
||||||
|
if (updatedList[monitorID]) {
|
||||||
|
monitor.proxy_id = updatedList[monitorID].proxy_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const { Proxy } = require("../proxy");
|
const { Proxy } = require("../proxy");
|
||||||
const { sendProxyList } = require("../client");
|
const { sendProxyList } = require("../client");
|
||||||
|
const server = require("../server");
|
||||||
|
|
||||||
module.exports.proxySocketHandler = (socket) => {
|
module.exports.proxySocketHandler = (socket) => {
|
||||||
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
||||||
|
@ -11,7 +12,8 @@ module.exports.proxySocketHandler = (socket) => {
|
||||||
await sendProxyList(socket);
|
await sendProxyList(socket);
|
||||||
|
|
||||||
if (proxy.applyExisting) {
|
if (proxy.applyExisting) {
|
||||||
// TODO: await restartMonitors(socket.userID);
|
await Proxy.reloadProxy();
|
||||||
|
await server.sendMonitorList(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
|
@ -34,7 +36,7 @@ module.exports.proxySocketHandler = (socket) => {
|
||||||
|
|
||||||
await Proxy.delete(proxyID, socket.userID);
|
await Proxy.delete(proxyID, socket.userID);
|
||||||
await sendProxyList(socket);
|
await sendProxyList(socket);
|
||||||
// TODO: await restartMonitors(socket.userID);
|
await Proxy.reloadProxy();
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
|
|
Loading…
Reference in a new issue