Feature monitor the resource over proxy #840

Open
ugurerkan wants to merge 4 commits from rebasesoftware/feature/request-with-http-proxy into master
  1. 23
      db/patch-proxy.sql
  2. 150
      package-lock.json
  3. 3
      package.json
  4. 21
      server/client.js
  5. 1
      server/database.js
  6. 31
      server/model/monitor.js
  7. 21
      server/model/proxy.js
  8. 170
      server/proxy.js
  9. 87
      server/server.js
  10. 206
      src/components/ProxyDialog.vue
  11. 7
      src/languages/en.js
  12. 11
      src/mixins/socket.js
  13. 55
      src/pages/EditMonitor.vue
  14. 27
      src/pages/Settings.vue

23
db/patch-proxy.sql

@ -0,0 +1,23 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;
CREATE TABLE proxy (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
user_id INT NOT NULL,
protocol VARCHAR(10) NOT NULL,
host VARCHAR(255) NOT NULL,
port SMALLINT NOT NULL,
auth BOOLEAN NOT NULL,
username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
active BOOLEAN NOT NULL DEFAULT 1,
'default' BOOLEAN NOT NULL DEFAULT 0,
created_date DATETIME DEFAULT (DATETIME('now')) NOT NULL
);
ALTER TABLE monitor ADD COLUMN proxy_id INTEGER REFERENCES proxy(id);
CREATE INDEX proxy_id ON monitor (proxy_id);
CREATE INDEX proxy_user_id ON proxy (user_id);
COMMIT;

150
package-lock.json

@ -1,12 +1,12 @@
{
"name": "uptime-kuma",
"version": "1.9.2",
"version": "1.10.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "uptime-kuma",
"version": "1.9.2",
"version": "1.10.0",
"license": "MIT",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "~1.2.36",
@ -31,6 +31,8 @@
"express-basic-auth": "~1.2.0",
"form-data": "~4.0.0",
"http-graceful-shutdown": "~3.1.4",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"iconv-lite": "^0.6.3",
"jsonwebtoken": "~8.5.1",
"jwt-decode": "^3.1.2",
@ -46,6 +48,7 @@
"redbean-node": "0.1.3",
"socket.io": "~4.2.0",
"socket.io-client": "~4.2.0",
"socks-proxy-agent": "^6.1.0",
"tar": "^6.1.11",
"tcp-ping": "~0.1.1",
"thirty-two": "~1.0.2",
@ -2733,12 +2736,11 @@
}
},
"node_modules/@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
"dev": true,
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
"integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==",
"engines": {
"node": ">= 6"
"node": ">= 10"
}
},
"node_modules/@types/accepts": {
@ -6931,12 +6933,11 @@
}
},
"node_modules/http-proxy-agent": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
"integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==",
"dev": true,
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz",
"integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==",
"dependencies": {
"@tootallnate/once": "1",
"@tootallnate/once": "2",
"agent-base": "6",
"debug": "4"
},
@ -7114,6 +7115,11 @@
"node": ">= 0.10"
}
},
"node_modules/ip": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
@ -9467,6 +9473,15 @@
}
}
},
"node_modules/jsdom/node_modules/@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
"dev": true,
"engines": {
"node": ">= 6"
}
},
"node_modules/jsdom/node_modules/acorn": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz",
@ -9493,6 +9508,20 @@
"node": ">= 6"
}
},
"node_modules/jsdom/node_modules/http-proxy-agent": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
"integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==",
"dev": true,
"dependencies": {
"@tootallnate/once": "1",
"agent-base": "6",
"debug": "4"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
@ -12723,6 +12752,15 @@
"node": ">=8"
}
},
"node_modules/smart-buffer": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
}
},
"node_modules/socket.io": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.2.0.tgz",
@ -12777,6 +12815,32 @@
"node": ">=10.0.0"
}
},
"node_modules/socks": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/socks/-/socks-2.6.1.tgz",
"integrity": "sha512-kLQ9N5ucj8uIcxrDwjm0Jsqk06xdpBjGNQtpXy4Q8/QY2k+fY7nZH8CARy+hkbG+SGAovmzzuauCpBlb8FrnBA==",
"dependencies": {
"ip": "^1.1.5",
"smart-buffer": "^4.1.0"
},
"engines": {
"node": ">= 10.13.0",
"npm": ">= 3.0.0"
}
},
"node_modules/socks-proxy-agent": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-6.1.0.tgz",
"integrity": "sha512-57e7lwCN4Tzt3mXz25VxOErJKXlPfXmkMLnk310v/jwW20jWRVcgsOit+xNkN3eIEdB47GwnfAEBLacZ/wVIKg==",
"dependencies": {
"agent-base": "^6.0.2",
"debug": "^4.3.1",
"socks": "^2.6.1"
},
"engines": {
"node": ">= 10"
}
},
"node_modules/sortablejs": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.14.0.tgz",
@ -16735,10 +16799,9 @@
}
},
"@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
"dev": true
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
"integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A=="
},
"@types/accepts": {
"version": "1.3.5",
@ -20011,12 +20074,11 @@
}
},
"http-proxy-agent": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
"integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==",
"dev": true,
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz",
"integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==",
"requires": {
"@tootallnate/once": "1",
"@tootallnate/once": "2",
"agent-base": "6",
"debug": "4"
}
@ -20137,6 +20199,11 @@
"resolved": "https://registry.npmjs.org/interpret/-/interpret-2.2.0.tgz",
"integrity": "sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw=="
},
"ip": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
},
"ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
@ -21902,6 +21969,12 @@
"xml-name-validator": "^3.0.0"
},
"dependencies": {
"@tootallnate/once": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz",
"integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==",
"dev": true
},
"acorn": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz",
@ -21918,6 +21991,17 @@
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"http-proxy-agent": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
"integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==",
"dev": true,
"requires": {
"@tootallnate/once": "1",
"agent-base": "6",
"debug": "4"
}
}
}
},
@ -24392,6 +24476,11 @@
}
}
},
"smart-buffer": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg=="
},
"socket.io": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.2.0.tgz",
@ -24437,6 +24526,25 @@
"debug": "~4.3.1"
}
},
"socks": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/socks/-/socks-2.6.1.tgz",
"integrity": "sha512-kLQ9N5ucj8uIcxrDwjm0Jsqk06xdpBjGNQtpXy4Q8/QY2k+fY7nZH8CARy+hkbG+SGAovmzzuauCpBlb8FrnBA==",
"requires": {
"ip": "^1.1.5",
"smart-buffer": "^4.1.0"
}
},
"socks-proxy-agent": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-6.1.0.tgz",
"integrity": "sha512-57e7lwCN4Tzt3mXz25VxOErJKXlPfXmkMLnk310v/jwW20jWRVcgsOit+xNkN3eIEdB47GwnfAEBLacZ/wVIKg==",
"requires": {
"agent-base": "^6.0.2",
"debug": "^4.3.1",
"socks": "^2.6.1"
}
},
"sortablejs": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.14.0.tgz",

3
package.json

@ -74,6 +74,8 @@
"express-basic-auth": "~1.2.0",
"form-data": "~4.0.0",
"http-graceful-shutdown": "~3.1.4",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"iconv-lite": "^0.6.3",
"jsonwebtoken": "~8.5.1",
"jwt-decode": "^3.1.2",
@ -89,6 +91,7 @@
"redbean-node": "0.1.3",
"socket.io": "~4.2.0",
"socket.io-client": "~4.2.0",
"socks-proxy-agent": "^6.1.0",
"tar": "^6.1.11",
"tcp-ping": "~0.1.1",
"thirty-two": "~1.0.2",

21
server/client.js

@ -83,6 +83,23 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove
}
/**
* Delivers proxy list
*
* @param socket
* @return {Promise<Bean[]>}
*/
async function sendProxyList(socket) {
const timeLogger = new TimeLogger();
const list = await R.find("proxy", " user_id = ? ", [socket.userID]);
io.to(socket.userID).emit("proxyList", list.map(bean => bean.export()));
timeLogger.print("Send Proxy List");
return list;
}
async function sendInfo(socket) {
socket.emit("info", {
version: checkVersion.version,
@ -95,6 +112,6 @@ module.exports = {
sendNotificationList,
sendImportantHeartbeatList,
sendHeartbeatList,
sendInfo
sendProxyList,
sendInfo,
};

1
server/database.js

@ -52,6 +52,7 @@ class Database {
"patch-http-monitor-method-body-and-headers.sql": true,
"patch-2fa-invalidate-used-token.sql": true,
"patch-notification_sent_history.sql": true,
"patch-proxy.sql": true,
}
/**

31
server/model/monitor.js

@ -11,6 +11,7 @@ const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalCli
const { R } = require("redbean-node");
const { BeanModel } = require("redbean-node/dist/bean-model");
const { Notification } = require("../notification");
const { Proxy } = require("../proxy");
const { demoMode } = require("../config");
const version = require("../../package.json").version;
const apicache = require("../modules/apicache");
@ -75,6 +76,7 @@ class Monitor extends BeanModel {
dns_resolve_server: this.dns_resolve_server,
dns_last_result: this.dns_last_result,
pushToken: this.pushToken,
proxyId: this.proxy_id,
notificationIDList,
tags: tags,
};
@ -141,6 +143,11 @@ class Monitor extends BeanModel {
// Do not do any queries/high loading things before the "bean.ping"
let startTime = dayjs().valueOf();
const httpsAgentOptions = {
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
rejectUnauthorized: !this.getIgnoreTls(),
};
debug(`[${this.name}] Prepare Options for axios`);
const options = {
url: this.url,
@ -152,17 +159,33 @@ class Monitor extends BeanModel {
"User-Agent": "Uptime-Kuma/" + version,
...(this.headers ? JSON.parse(this.headers) : {}),
},
httpsAgent: new https.Agent({
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
rejectUnauthorized: ! this.getIgnoreTls(),
}),
maxRedirects: this.maxredirects,
validateStatus: (status) => {
return checkStatusCode(status, this.getAcceptedStatuscodes());
},
};
if (this.proxy_id) {
const proxy = await R.load("proxy", this.proxy_id);
if (proxy && proxy.active) {
const { httpAgent, httpsAgent } = Proxy.createAgents(proxy, {
httpsAgentOptions: httpsAgentOptions,
});
options.proxy = false;
options.httpAgent = httpAgent;
options.httpsAgent = httpsAgent;
}
}
if (!options.httpsAgent) {
options.httpsAgent = new https.Agent(httpsAgentOptions);
}
debug(`[${this.name}] Axios Options: ${JSON.stringify(options)}`);
debug(`[${this.name}] Axios Request`);
let res = await axios.request(options);
bean.msg = `${res.status} - ${res.statusText}`;
bean.ping = dayjs().valueOf() - startTime;

21
server/model/proxy.js

@ -0,0 +1,21 @@
const { BeanModel } = require("redbean-node/dist/bean-model");
class Proxy extends BeanModel {
toJSON() {
return {
id: this._id,
userId: this._user_id,
protocol: this._protocol,
host: this._host,
port: this._port,
auth: !!this._auth,
username: this._username,
password: this._password,
active: !!this._active,
default: !!this._default,
createdDate: this._created_date,
};
}
}
module.exports = Proxy;

170
server/proxy.js

@ -0,0 +1,170 @@
const { R } = require("redbean-node");
const HttpProxyAgent = require("http-proxy-agent");
const HttpsProxyAgent = require("https-proxy-agent");
const SocksProxyAgent = require("socks-proxy-agent");
const { debug } = require("../src/util");
class Proxy {
static SUPPORTED_PROXY_PROTOCOLS = ["http", "https", "socks", "socks5", "socks4"]
/**
* Saves and updates given proxy entity
*
* @param proxy
* @param proxyID
* @param userID
* @return {Promise<Bean>}
*/
static async save(proxy, proxyID, userID) {
let bean;
if (proxyID) {
bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]);
if (!bean) {
throw new Error("proxy not found");
}
} else {
bean = R.dispense("proxy");
}
// Make sure given proxy protocol is supported
if (!this.SUPPORTED_PROXY_PROTOCOLS.includes(proxy.protocol)) {
throw new Error(`
Unsupported proxy protocol "${proxy.protocol}.
Supported protocols are ${this.SUPPORTED_PROXY_PROTOCOLS.join(", ")}."`
);
}
// When proxy is default update deactivate old default proxy
if (proxy.default) {
await R.exec("UPDATE proxy SET `default` = 0 WHERE `default` = 1");
}
bean.user_id = userID;
bean.protocol = proxy.protocol;
bean.host = proxy.host;
bean.port = proxy.port;
bean.auth = proxy.auth;
bean.username = proxy.username;
bean.password = proxy.password;
bean.active = proxy.active || true;
bean.default = proxy.default || false;
await R.store(bean);
if (proxy.applyExisting) {
await applyProxyEveryMonitor(bean.id, userID);
}
return bean;
}
/**
* Deletes proxy with given id and removes it from monitors
*
* @param proxyID
* @param userID
* @return {Promise<void>}
*/
static async delete(proxyID, userID) {
const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]);
if (!bean) {
throw new Error("proxy not found");
}
// Delete removed proxy from monitors if exists
await R.exec("UPDATE monitor SET proxy_id = null WHERE proxy_id = ?", [proxyID]);
// Delete proxy from list
await R.trash(bean);
}
/**
* Create HTTP and HTTPS agents related with given proxy bean object
*
* @param proxy proxy bean object
* @param options http and https agent options
* @return {{httpAgent: Agent, httpsAgent: Agent}}
*/
static createAgents(proxy, options) {
const { httpAgentOptions, httpsAgentOptions } = options || {};
let agent;
let httpAgent;
let httpsAgent;
const proxyOptions = {
protocol: proxy.protocol,
host: proxy.host,
port: proxy.port,
};
if (proxy.auth) {
proxyOptions.auth = `${proxy.username}:${proxy.password}`;
}
debug(`Proxy Options: ${JSON.stringify(proxyOptions)}`);
debug(`HTTP Agent Options: ${JSON.stringify(httpAgentOptions)}`);
debug(`HTTPS Agent Options: ${JSON.stringify(httpsAgentOptions)}`);
switch (proxy.protocol) {
case "http":
case "https":
httpAgent = new HttpProxyAgent({
...httpAgentOptions || {},
...proxyOptions
});
httpsAgent = new HttpsProxyAgent({
...httpsAgentOptions || {},
...proxyOptions,
});
break;
case "socks":
case "socks5":
case "socks4":
agent = new SocksProxyAgent({
...httpAgentOptions,
...httpsAgentOptions,
...proxyOptions,
});
httpAgent = agent;
httpsAgent = agent;
break;
default: throw new Error(`Unsupported proxy protocol provided. ${proxy.protocol}`);
}
return {
httpAgent,
httpsAgent
};
}
}
/**
* Applies given proxy id to monitors
*
* @param proxyID
* @param userID
* @return {Promise<void>}
*/
async function applyProxyEveryMonitor(proxyID, userID) {
// Find all monitors with id and proxy id
const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [userID]);
// Update proxy id not match with given proxy id
for (const monitor of monitors) {
if (monitor.proxy_id !== proxyID) {
await R.exec("UPDATE monitor SET proxy_id = ? WHERE id = ?", [proxyID, monitor.id]);
}
}
}
module.exports = {
Proxy,
};

87
server/server.js

@ -47,6 +47,9 @@ debug("Importing Notification");
const { Notification } = require("./notification");
Notification.init();
debug("Importing Proxy");
const { Proxy } = require("./proxy");
debug("Importing Database");
const Database = require("./database");
@ -117,7 +120,7 @@ const io = new Server(server);
module.exports.io = io;
// Must be after io instantiation
const { sendNotificationList, sendHeartbeatList, sendImportantHeartbeatList, sendInfo } = require("./client");
const { sendNotificationList, sendHeartbeatList, sendImportantHeartbeatList, sendInfo, sendProxyList } = require("./client");
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
const databaseSocketHandler = require("./socket-handlers/database-socket-handler");
@ -588,6 +591,7 @@ exports.entryPage = "dashboard";
bean.dns_resolve_type = monitor.dns_resolve_type;
bean.dns_resolve_server = monitor.dns_resolve_server;
bean.pushToken = monitor.pushToken;
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
await R.store(bean);
@ -1050,6 +1054,52 @@ exports.entryPage = "dashboard";
}
});
socket.on("addProxy", async (proxy, proxyID, callback) => {
try {
checkLogin(socket);
const proxyBean = await Proxy.save(proxy, proxyID, socket.userID);
await sendProxyList(socket);
if (proxy.applyExisting) {
await restartMonitors(socket.userID);
}
callback({
ok: true,
msg: "Saved",
id: proxyBean.id,
});
} catch (e) {
callback({
ok: false,
msg: e.message,
});
}
});
socket.on("deleteProxy", async (proxyID, callback) => {
try {
checkLogin(socket);
await Proxy.delete(proxyID, socket.userID);
await sendProxyList(socket);
await restartMonitors(socket.userID);
callback({
ok: true,
msg: "Deleted",
});
} catch (e) {
callback({
ok: false,
msg: e.message,
});
}
});
socket.on("checkApprise", async (callback) => {
try {
checkLogin(socket);
@ -1068,6 +1118,7 @@ exports.entryPage = "dashboard";
console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`);
let notificationListData = backupData.notificationList;
let proxyListData = backupData.proxyList;
let monitorListData = backupData.monitorList;
let version17x = compareVersions.compare(backupData.version, "1.7.0", ">=");
@ -1086,6 +1137,7 @@ exports.entryPage = "dashboard";
await R.exec("DELETE FROM monitor_tag");
await R.exec("DELETE FROM tag");
await R.exec("DELETE FROM monitor");
await R.exec("DELETE FROM proxy");
}
// Only starts importing if the backup file contains at least one notification
@ -1105,6 +1157,24 @@ exports.entryPage = "dashboard";
}
}
// Only starts importing if the backup file contains at least one proxy
if (proxyListData.length >= 1) {
const proxies = await R.findAll("proxy");
// Loop over proxy list and save proxies
for (const proxy of proxyListData) {
const exists = proxies.find(item => item.id === proxy.id);
// Do not process when proxy already exists in import handle is skip and keep
if (["skip", "keep"].includes(importHandle) && !exists) {
return;
}
// Save proxy as new entry if exists update exists one
await Proxy.save(proxy, exists ? proxy.id : undefined, proxy.userId);
}
}
// Only starts importing if the backup file contains at least one monitor
if (monitorListData.length >= 1) {
// Get every existing monitor name and puts them in one simple string
@ -1152,6 +1222,7 @@ exports.entryPage = "dashboard";
dns_resolve_type: monitorListData[i].dns_resolve_type,
dns_resolve_server: monitorListData[i].dns_resolve_server,
notificationIDList: {},
proxy_id: monitorListData[i].proxy_id || null,
};
if (monitorListData[i].pushToken) {
@ -1387,6 +1458,7 @@ async function afterLogin(socket, user) {
let monitorList = await sendMonitorList(socket);
sendNotificationList(socket);
sendProxyList(socket);
await sleep(500);
@ -1477,6 +1549,19 @@ async function restartMonitor(userID, monitorID) {
return await startMonitor(userID, monitorID);
}
async function restartMonitors(userID) {
// Fetch all active monitors for user
const monitors = await R.getAll("SELECT id FROM monitor WHERE active = 1 AND user_id = ?", [userID]);
for (const monitor of monitors) {
// Start updated monitor
await startMonitor(userID, monitor.id);
// Give some delays, so all monitors won't make request at the same moment when just start the server.
await sleep(getRandomInt(300, 1000));
}
}
async function pauseMonitor(userID, monitorID) {
await checkOwner(userID, monitorID);

206
src/components/ProxyDialog.vue

@ -0,0 +1,206 @@
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<template>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<form @submit.prevent="submit">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div ref="modal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="modal-dialog">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="modal-content">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="modal-header">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<h5 id="exampleModalLabel" class="modal-title">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("Setup Proxy") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</h5>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="modal-body">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="mb-3">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="proxy-protocol" class="form-label">{{ $t("Proxy Protocol") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<select id="proxy-protocol" v-model="proxy.protocol" class="form-select">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<option value="https">HTTPS</option>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<option value="http">HTTP</option>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<option value="socks">SOCKS</option>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<option value="socks5">SOCKS v5</option>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<option value="socks4">SOCKS v4</option>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</select>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="mb-3">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="proxy-host" class="form-label">{{ $t("Proxy Server") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="d-flex">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="proxy-host" v-model="proxy.host" type="text" class="form-control" required :placeholder="$t('Server Address')">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input v-model="proxy.port" type="number" class="form-control ms-2" style="width: 100px" required min="1" max="65535" :placeholder="$t('Port')">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="mb-3">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-check form-switch">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="mark-auth" v-model="proxy.auth" class="form-check-input" type="checkbox">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="mark-auth" class="form-check-label">{{ $t("Proxy server has authentication") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div v-if="proxy.auth" class="mb-3">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="proxy-username" class="form-label">{{ $t("User") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="proxy-username" v-model="proxy.username" type="text" class="form-control" required>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div v-if="proxy.auth" class="mb-3">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="proxy-password" class="form-label">{{ $t("Password") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="proxy-password" v-model="proxy.password" type="text" class="form-control" required>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="mb-3 mt-4">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<hr class="dropdown-divider mb-4">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-check form-switch">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="mark-active" v-model="proxy.active" class="form-check-input" type="checkbox">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="mark-active" class="form-check-label">{{ $t("enabled") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-text">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("enableProxyDescription") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<br />
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-check form-switch">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="mark-default" v-model="proxy.default" class="form-check-input" type="checkbox">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label for="mark-default" class="form-check-label">{{ $t("setAsDefault") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-text">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("setAsDefaultProxyDescription") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<br />
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="form-check form-switch">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<input id="apply-existing" v-model="proxy.applyExisting" class="form-check-input" type="checkbox">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<label class="form-check-label" for="apply-existing">{{ $t("Apply on all existing monitors") }}</label>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div class="modal-footer">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<button v-if="id" type="button" class="btn btn-danger" :disabled="processing" @click="deleteConfirm">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("Delete") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</button>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<button type="submit" class="btn btn-primary" :disabled="processing">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<div v-if="processing" class="spinner-border spinner-border-sm me-1"></div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("Save") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</button>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</div>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</form>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="deleteProxy">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
{{ $t("deleteProxyMsg") }}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</Confirm>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</template>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<script lang="ts">
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
import { Modal } from "bootstrap";
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
import Confirm from "./Confirm.vue";
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
export default {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
components: {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Confirm,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
props: {},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
emits: ["added"],
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
data() {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
return {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
model: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
processing: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
id: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
proxy: {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
protocol: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
host: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
port: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
auth: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
username: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
password: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
active: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
default: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
applyExisting: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
};
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
mounted() {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.modal = new Modal(this.$refs.modal);
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
methods: {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
deleteConfirm() {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.modal.hide();
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$refs.confirmDelete.show();
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
show(proxyID) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
if (proxyID) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.id = proxyID;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
for (let proxy of this.$root.proxyList) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
if (proxy.id === proxyID) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.proxy = proxy;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
break;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
} else {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.id = null;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.proxy = {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
protocol: "https",
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
host: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
port: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
auth: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
username: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
password: null,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
active: true,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
default: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
applyExisting: false,
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
};
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.modal.show();
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
submit() {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.processing = true;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$root.getSocket().emit("addProxy", this.proxy, this.id, (res) => {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$root.toastRes(res);
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.processing = false;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
if (res.ok) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.modal.hide();
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
// Emit added event, doesn't emit edit.
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
if (! this.id) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$emit("added", res.id);
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
});
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
deleteProxy() {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.processing = true;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$root.getSocket().emit("deleteProxy", this.id, (res) => {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.$root.toastRes(res);
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.processing = false;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
if (res.ok) {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
this.modal.hide();
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
});
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
},
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
};
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</script>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
<style lang="scss" scoped>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
@import "../assets/vars.scss";
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
.dark {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
.modal-dialog .form-text, .modal-dialog p {
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
color: $dark-font-color;
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
}
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```
</style>
Saibamen commented 4 years ago (Migrated from github.com)
Review
    methods: {
```suggestion methods: { ```

7
src/languages/en.js

@ -307,4 +307,11 @@ export default {
steamApiKeyDescription: "For monitoring a Steam Game Server you need a Steam Web-API key. You can register your API key here: ",
"Current User": "Current User",
recent: "Recent",
default: "Default",
enabled: "Enabled",
setAsDefault: "Set As Default",
deleteProxyMsg: "Are you sure want to delete this proxy for all monitors?",
Saibamen commented 4 years ago (Migrated from github.com)
Review

to monitor or to function (missing or?)

to monitor or to function (missing `or`?)
ugurerkan commented 4 years ago (Migrated from github.com)
Review

This is based from notification description. It is tries to explain with "must be assigned to a monitor to function" the proxy does not effect until assigned to a monitor, so I think this should be stay same but if it is not descriptive enough sure we could update.

This is based from notification description. It is tries to explain with "must be assigned to a monitor to function" the proxy does not effect until assigned to a monitor, so I think this should be stay same but if it is not descriptive enough sure we could update.
proxyDescription: "Proxies must be assigned to a monitor to function.",
enableProxyDescription: "This proxy will not effect on monitor requests until it is activated. You can control temporarily disable the proxy from all monitors by activation status.",
setAsDefaultProxyDescription: "This proxy will be enabled by default for new monitors. You can still disable the proxy separately for each monitor.",
};

11
src/mixins/socket.js

@ -33,6 +33,7 @@ export default {
uptimeList: { },
tlsInfoList: {},
notificationList: [],
proxyList: [],
connectionErrorMsg: "Cannot connect to the socket server. Reconnecting...",
};
},
@ -103,6 +104,16 @@ export default {
this.notificationList = data;
});
socket.on("proxyList", (data) => {
this.proxyList = data.map(item => {
item.auth = !!item.auth;
item.active = !!item.active;
item.default = !!item.default;
return item;
});
});
socket.on("heartbeat", (data) => {
if (! (data.monitorID in this.heartbeatList)) {
this.heartbeatList[data.monitorID] = [];

55
src/pages/EditMonitor.vue

@ -222,6 +222,32 @@
{{ $t("Setup Notification") }}
</button>
<!-- Proxies -->
<h2 class="mt-5 mb-2">{{ $t("Proxies") }}</h2>
<p v-if="$root.proxyList.length === 0">
{{ $t("Not available, please setup.") }}
</p>
<div v-if="$root.proxyList.length > 0" class="form-check form-switch my-3">
<input id="proxy-disable" v-model="monitor.proxyId" :value="null" name="proxy" class="form-check-input" type="radio">
<label class="form-check-label" for="proxy-disable">{{ $t("No Proxy") }}</label>
</div>
<div v-for="proxy in $root.proxyList" :key="proxy.id" class="form-check form-switch my-3">
<input :id="`proxy-${proxy.id}`" v-model="monitor.proxyId" :value="proxy.id" name="proxy" class="form-check-input" type="radio">
<label class="form-check-label" :for="`proxy-${proxy.id}`">
{{ proxy.host }}:{{ proxy.port }} ({{ proxy.protocol }})
<a href="#" @click="$refs.proxyDialog.show(proxy.id)">{{ $t("Edit") }}</a>
</label>
<span v-if="proxy.default === true" class="badge bg-primary ms-2">{{ $t("default") }}</span>
</div>
<button class="btn btn-primary me-2" type="button" @click="$refs.proxyDialog.show()">
{{ $t("Setup Proxy") }}
</button>
<!-- HTTP Options -->
<template v-if="monitor.type === 'http' || monitor.type === 'keyword' ">
<h2 class="mt-5 mb-2">{{ $t("HTTP Options") }}</h2>
@ -272,12 +298,14 @@
</form>
<NotificationDialog ref="notificationDialog" @added="addedNotification" />
<ProxyDialog ref="proxyDialog" @added="addedProxy" />
</div>
</transition>
</template>
<script>
import NotificationDialog from "../components/NotificationDialog.vue";
import ProxyDialog from "../components/ProxyDialog.vue";
import TagsManager from "../components/TagsManager.vue";
import CopyableInput from "../components/CopyableInput.vue";
@ -289,6 +317,7 @@ const toast = useToast();
export default {
components: {
ProxyDialog,
CopyableInput,
NotificationDialog,
TagsManager,
@ -355,6 +384,17 @@ export default {
},
watch: {
"$root.proxyList"() {
if (this.isAdd) {
if (this.$root.proxyList && !this.monitor.proxyId) {
const proxy = this.$root.proxyList.find(proxy => proxy.default);
if (proxy) {
this.monitor.proxyId = proxy.id;
}
}
}
},
"$route.fullPath"() {
this.init();
@ -426,8 +466,17 @@ export default {
accepted_statuscodes: ["200-299"],
dns_resolve_type: "A",
dns_resolve_server: "1.1.1.1",
proxyId: null,
};
if (this.$root.proxyList && !this.monitor.proxyId) {
const proxy = this.$root.proxyList.find(proxy => proxy.default);
if (proxy) {
this.monitor.proxyId = proxy.id;
}
}
for (let i = 0; i < this.$root.notificationList.length; i++) {
if (this.$root.notificationList[i].isDefault == true) {
this.monitor.notificationIDList[this.$root.notificationList[i].id] = true;
@ -519,6 +568,12 @@ export default {
addedNotification(id) {
this.monitor.notificationIDList[id] = true;
},
// Added a Proxy Event
// Enable it if the proxy is added in EditMonitor.vue
addedProxy(id) {
this.monitor.proxyId = id;
},
},
};
</script>

27
src/pages/Settings.vue

@ -270,6 +270,29 @@
</button>
</div>
<!-- Proxies -->
<div class="notification-list mt-5">
<h2>{{ $t("Proxies") }}</h2>
<p v-if="$root.proxyList.length === 0">
{{ $t("Not available, please setup.") }}
</p>
<p v-else>
{{ $t("proxyDescription") }}
</p>
<ul class="list-group mb-3" style="border-radius: 1rem;">
<li v-for="(proxy, index) in $root.proxyList" :key="index" class="list-group-item">
{{ proxy.host }}:{{ proxy.port }} ({{ proxy.protocol }})
<span v-if="proxy.default === true" class="badge bg-primary ms-2">{{ $t("Default") }}</span><br>
<a href="#" @click="$refs.proxyDialog.show(proxy.id)">{{ $t("Edit") }}</a>
</li>
</ul>
<button class="btn btn-primary me-2" type="button" @click="$refs.proxyDialog.show()">
{{ $t("Setup Proxy") }}
</button>
</div>
<!-- Info -->
<h2 class="mt-5">{{ $t("Info") }}</h2>
@ -281,6 +304,7 @@
<NotificationDialog ref="notificationDialog" />
<TwoFADialog ref="TwoFADialog" />
<ProxyDialog ref="proxyDialog" />
<Confirm ref="confirmDisableAuth" btn-style="btn-danger" :yes-text="$t('I understand, please disable')" :no-text="$t('Leave')" @yes="disableAuth">
<template v-if="$i18n.locale === 'es-ES' ">
@ -428,6 +452,7 @@ import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import NotificationDialog from "../components/NotificationDialog.vue";
import ProxyDialog from "../components/ProxyDialog.vue";
import TwoFADialog from "../components/TwoFADialog.vue";
import jwt_decode from "jwt-decode";
dayjs.extend(utc);
@ -441,6 +466,7 @@ const toast = useToast();
export default {
components: {
ProxyDialog,
NotificationDialog,
TwoFADialog,
Confirm,
@ -581,6 +607,7 @@ export default {
version: this.$root.info.version,
notificationList: this.$root.notificationList,
monitorList: monitorList,
proxyList: this.$root.proxyList,
};
exportData = JSON.stringify(exportData, null, 4);
let downloadItem = document.createElement("a");

Loading…
Cancel
Save