diff --git a/config.js b/config.js index 0998188..159e420 100644 --- a/config.js +++ b/config.js @@ -1,3 +1,5 @@ +import { SocksProxyAgent } from 'socks-proxy-agent'; + export default { interval : 1440, // Interval in minutes between each pulse; 1 day (24 * 60) nDataPoints : 90, // Number of datapoints to display on the dashboard @@ -50,43 +52,43 @@ export default { validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] }, { - id : 'airin', // optional - name : 'Airin', // optional - link : 'https://airin.marcus7i.net', // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false - url : 'https://airin.marcus7i.net', // required + id : 'btcnd-onion', // optional + name : 'Bitcoin Node (Onion)', // optional + link : false, // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false + url : 'erkuzp5gzrcjqtrcuiku5whcjnioalwskgo3hjg5oq2mmailml7k7jad.onion:8333', // required request : { // optional, fetch options method: 'GET', + agent: new SocksProxyAgent('socks5h://127.0.0.1:9050') }, - mustFind : 'Airin', // optional, String | Array | Regex | Function | AsyncFunction - mustNotFind : ["Page not found", "cloudflare"], // optional, String | Array | Regex | Function | AsyncFunction - customCheck : async (content, response)=>{return true;}, // optional, Function | AsyncFunction -> Run your own custom checks return false in case of errors - validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] - }, - { - id : 'anywave', // optional - name : 'Anywave', // optional - link : 'https://anywave.marcus7i.net', // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false - url : 'https://anywave.marcus7i.net', // required - request : { // optional, fetch options - method: 'GET', + customCheck: async (content, response) => { + // Bitcoin protocol version check + try { + const net = require('net'); + return new Promise((resolve) => { + const socket = new net.Socket(); + socket.setTimeout(5000); // 5 second timeout + + socket.on('connect', () => { + socket.destroy(); + resolve(true); + }); + + socket.on('error', () => { + resolve(false); + }); + + socket.on('timeout', () => { + socket.destroy(); + resolve(false); + }); + + socket.connect(8333, '127.0.0.1'); + }); + } catch (e) { + return false; + } }, - mustFind : 'Anywave', // optional, String | Array | Regex | Function | AsyncFunction - mustNotFind : ["Page not found", "cloudflare"], // optional, String | Array | Regex | Function | AsyncFunction - customCheck : async (content, response)=>{return true;}, // optional, Function | AsyncFunction -> Run your own custom checks return false in case of errors - validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] - }, - { - id : 'btcnd', // optional - name : 'Bitcoin Node', // optional - link : 'https://btcnd.marcus7i.net', // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false - url : 'https://btcnd.marcus7i.net', // required - request : { // optional, fetch options - method: 'GET', - }, - mustFind : 'Anywave', // optional, String | Array | Regex | Function | AsyncFunction - mustNotFind : ["Page not found", "cloudflare"], // optional, String | Array | Regex | Function | AsyncFunction - customCheck : async (content, response)=>{return true;}, // optional, Function | AsyncFunction -> Run your own custom checks return false in case of errors - validStatus : [200, 520], // optional, Which http status should be considered non errors [defaults to 200-299] + validStatus : [200, 'SOCKET'], // optional, Which http status should be considered non errors [defaults to 200-299] }, { id : 'fs', // optional @@ -167,17 +169,42 @@ export default { validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] }, { - id : 'xmrnd', // optional - name : 'Monero Node', // optional - link : 'https://xmrnd.marcus7i.net', // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false + id : 'xmrnd-onion', // optional + name : 'Monero Node (Onion)', // optional + link : false, // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by setting it to false url : 'https://xmrnd.marcus7i.net', // required request : { // optional, fetch options method: 'GET', + agent: new SocksProxyAgent('socks5h://127.0.0.1:9050') }, - mustFind : '', // optional, String | Array | Regex | Function | AsyncFunction - mustNotFind : ["Page not found", "cloudflare"], // optional, String | Array | Regex | Function | AsyncFunction - customCheck : async (content, response)=>{return true;}, // optional, Function | AsyncFunction -> Run your own custom checks return false in case of errors - validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] + customCheck: async (content, response) => { + try { + const net = require('net'); + return new Promise((resolve) => { + const socket = new net.Socket(); + socket.setTimeout(5000); + + socket.on('connect', () => { + socket.destroy(); + resolve(true); + }); + + socket.on('error', () => { + resolve(false); + }); + + socket.on('timeout', () => { + socket.destroy(); + resolve(false); + }); + + socket.connect(18081, '127.0.0.1'); + }); + } catch (e) { + return false; + } + }, + validStatus : [200, 'SOCKET'], // optional, Which http status should be considered non errors [defaults to 200-299] } ] } diff --git a/package-lock.json b/package-lock.json index 9b121c5..c5b983e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,105 @@ "": { "name": "aPulse", "version": "1.0.0", - "license": "Apache-2.0" + "license": "Apache-2.0", + "dependencies": { + "socks-proxy-agent": "^8.0.5" + } + }, + "node_modules/agent-base": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", + "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/ip-address": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", + "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "license": "MIT", + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "license": "MIT" + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "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==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", + "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", + "license": "MIT", + "dependencies": { + "ip-address": "^9.0.5", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks-proxy-agent": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "^4.3.4", + "socks": "^2.8.3" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", + "license": "BSD-3-Clause" } } } diff --git a/package.json b/package.json index 0021816..5837ae3 100644 --- a/package.json +++ b/package.json @@ -9,5 +9,8 @@ "start": "node watcher.js" }, "author": "ybouane", - "license": "Apache-2.0" + "license": "Apache-2.0", + "dependencies": { + "socks-proxy-agent": "^8.0.5" + } }