Browser Farm: grid of 8 isolated Neko browsers with per-browser identity, single login, and sync control

This commit is contained in:
Muse committed 2026-12-01 21:20:41 +07:00
commit 32ac658c70
11 files changed
+2564

No files matched your search

+1
View File
@@ -0,0 +1 @@
{"browsers":[{"httpPort":18081,"id":"b1","name":"Browser 1 · Chrome Windows","uaKey":"chrome-win","udpEnd":52099,"udpStart":52000},{"httpPort":18082,"id":"b2","name":"Browser 2 · Chrome macOS","uaKey":"chrome-mac","udpEnd":52199,"udpStart":52100},{"httpPort":18083,"id":"b3","name":"Browser 3 · Edge Windows","uaKey":"edge-win","udpEnd":52299,"udpStart":52200},{"httpPort":18084,"id":"b4","name":"Browser 4 · Firefox Windows","uaKey":"firefox-win","udpEnd":52399,"udpStart":52300},{"httpPort":18085,"id":"b5","name":"Browser 5 · Chrome Linux","uaKey":"chrome-linux","udpEnd":52499,"udpStart":52400},{"httpPort":18086,"id":"b6","name":"Browser 6 · Safari macOS","uaKey":"safari-mac","udpEnd":52599,"udpStart":52500},{"httpPort":18087,"id":"b7","name":"Browser 7 · Chrome Android","uaKey":"chrome-android","udpEnd":52699,"udpStart":52600},{"httpPort":18088,"id":"b8","name":"Browser 8 · Firefox macOS","uaKey":"firefox-mac","udpEnd":52799,"udpStart":52700}],"farmName":"Browser Farm","managerPort":18080,"uaPresets":{"chrome-android":{"label":"Chrome · Android","ua":"Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36"},"chrome-linux":{"label":"Chrome · Linux","ua":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"},"chrome-mac":{"label":"Chrome · macOS","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"},"chrome-win":{"label":"Chrome · Windows","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"},"edge-win":{"label":"Edge · Windows","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"},"firefox-mac":{"label":"Firefox · macOS","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7; rv:133.0) Gecko/20100101 Firefox/133.0"},"firefox-win":{"label":"Firefox · Windows","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0"},"safari-mac":{"label":"Safari · macOS","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15"}},"vpsIp":"49.128.191.144"}
+840
View File
@@ -0,0 +1,840 @@
{
"name": "browser-farm-manager",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "browser-farm-manager",
"version": "1.0.0",
"dependencies": {
"express": "^4.19.2"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
"license": "MIT",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"license": "MIT"
},
"node_modules/body-parser": {
"version": "1.20.9",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.9.tgz",
"integrity": "sha512-FISIQxV5u91Y9gvuFq3q/tA/qTqLJn3AhRcEvyozyhJTh5OBFFtv827AdHU7Rbyct4r+Ba1/99oFa1Y3yuFsdw==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "~1.2.0",
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"on-finished": "~2.4.1",
"qs": "~6.16.0",
"raw-body": "~2.5.3",
"type-is": "~1.6.18",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
"license": "MIT",
"dependencies": {
"safe-buffer": "5.2.1"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
"license": "MIT"
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.3.tgz",
"integrity": "sha512-mIteYONiEfc4xWf2F1WXovh1c8npzS00vNeiUPdwFF+QlVJni+gNvpQltLMQhob8rew/bWWc/bGTuUr0EUGt0w==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "4.22.3",
"resolved": "https://registry.npmjs.org/express/-/express-4.22.3.tgz",
"integrity": "sha512-Bdcs4+3qlpVlx2NRn6fgX2Ue2/gGRaPeawebgclM0ERSCqDpA+owF1fdPwjJUTAJWMTuAaxjDf+hzb0/4eKvvw==",
"license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "~1.20.5",
"content-disposition": "~0.5.4",
"content-type": "~1.0.4",
"cookie": "~0.7.1",
"cookie-signature": "~1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "~1.3.1",
"fresh": "~0.5.2",
"http-errors": "~2.0.0",
"merge-descriptors": "1.0.3",
"methods": "~1.1.2",
"on-finished": "~2.4.1",
"parseurl": "~1.3.3",
"path-to-regexp": "~0.1.13",
"proxy-addr": "~2.0.7",
"qs": "~6.16.0",
"range-parser": "~1.2.1",
"safe-buffer": "5.2.1",
"send": "~0.19.0",
"serve-static": "~1.16.2",
"setprototypeof": "1.2.0",
"statuses": "~2.0.1",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"engines": {
"node": ">= 0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
"integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"on-finished": "~2.4.1",
"parseurl": "~1.3.3",
"statuses": "~2.0.2",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/merge-descriptors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"license": "MIT",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/object-inspect": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
"integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.2.tgz",
"integrity": "sha512-ATWUv387i+nLD49EiDoOft5scf32Vsdz3ktrQJG9bi7jRFmaXTssvyvj1EmeKVVgvesbqUtvQQvaS2TpTukAZQ==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz",
"integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==",
"license": "MIT"
},
"node_modules/proxy-addr": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz",
"integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/qs": {
"version": "6.16.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.16.2.tgz",
"integrity": "sha512-VYdnB5S7/0IeXzBacUtwNAaM6d7Y/PgYnNC7bJCI6meqA/OgnsQbZMtVW8Dt2D1PHgbHGtYmhSoEIgvt7xZ2ZA==",
"license": "BSD-3-Clause",
"dependencies": {
"es-define-property": "^1.0.1",
"side-channel": "^1.1.1"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/raw-body": {
"version": "2.5.3",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
"integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
"integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "~0.5.2",
"http-errors": "~2.0.1",
"mime": "1.6.0",
"ms": "2.1.3",
"on-finished": "~2.4.1",
"range-parser": "~1.2.1",
"statuses": "~2.0.2"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/send/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/serve-static": {
"version": "1.16.3",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
"integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
"license": "MIT",
"dependencies": {
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "~0.19.1"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4",
"side-channel-list": "^1.0.1",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"license": "MIT",
"dependencies": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
}
}
}
+1
View File
@@ -0,0 +1 @@
{"dependencies":{"express":"^4.19.2"},"description":"Browser Farm manager — grid UI + API for 8 isolated Neko browsers","main":"server.js","name":"browser-farm-manager","private":true,"scripts":{"start":"node server.js"},"version":"1.0.0"}
+705
View File
@@ -0,0 +1,705 @@
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Browser Farm</title>
<style>
:root{
--bg:#0b1220; --panel:#111c2e; --panel2:#0e1726; --border:#1e2c44;
--text:#e6edf7; --muted:#8fa3bf; --accent:#34d399; --accent-dark:#0f3d2e;
--danger:#f87171; --warn:#fbbf24;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{background:var(--bg);color:var(--text);font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif}
.topbar{display:flex;align-items:center;gap:12px;padding:10px 16px;background:var(--panel);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:20;flex-wrap:wrap}
.topbar h1{font-size:18px;margin:0;letter-spacing:.3px}
.topbar h1 span{color:var(--accent)}
.topbar .sub{color:var(--muted);font-size:13px}
.spacer{flex:1}
.note{margin:0;padding:8px 16px;color:var(--muted);font-size:13px;background:var(--panel2);border-bottom:1px solid var(--border)}
.note b{color:var(--text)}
button{cursor:pointer;border:1px solid var(--border);background:var(--panel2);color:var(--text);border-radius:7px;padding:6px 11px;font-size:13px}
button:hover{border-color:var(--accent)}
button.primary{background:var(--accent);border-color:var(--accent);color:#06281c;font-weight:600}
button.danger{border-color:#5b2323;color:var(--danger)}
button.danger:hover{border-color:var(--danger)}
button:disabled{opacity:.45;cursor:default}
.grid{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;padding:12px}
@media (max-width:1500px){.grid{grid-template-columns:repeat(2,1fr)}}
@media (max-width:820px){.grid{grid-template-columns:1fr}}
.cell{background:var(--panel);border:1px solid var(--border);border-radius:10px;overflow:hidden;display:flex;flex-direction:column;min-height:430px}
.cell.expanded{position:fixed;inset:0;z-index:60;border-radius:0;min-height:0}
.cell-head{padding:9px 12px;border-bottom:1px solid var(--border)}
.cell-title{display:flex;align-items:center;gap:8px;font-size:14px}
.cell-title strong{font-weight:650}
.badge{font-size:11px;font-weight:700;padding:2px 8px;border-radius:20px;letter-spacing:.3px}
.badge.running{background:var(--accent-dark);color:var(--accent)}
.badge.stopped{background:#3d1a1a;color:var(--danger)}
.badge.master{background:#3b2f0b;color:var(--warn)}
.cell.is-master{border-color:var(--warn)}
button.sync-on{background:var(--accent);border-color:var(--accent);color:#06281c;font-weight:600}
.identity{margin-top:4px;color:var(--muted);font-size:12px;word-break:break-word}
.cell-view{position:relative;flex:1;min-height:330px;background:#000}
.cell-view iframe{position:absolute;inset:0;width:100%;height:100%;border:0;display:block;background:#000}
.overlay{position:absolute;inset:0;background:rgba(4,9,18,.93);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;color:var(--muted);font-size:14px;text-align:center;padding:16px}
.overlay strong{color:var(--text);font-size:16px}
.toolbar{display:flex;gap:6px;padding:8px 10px;border-top:1px solid var(--border);flex-wrap:wrap}
.settings{display:none;padding:10px 12px;border-top:1px solid var(--border);background:var(--panel2)}
.settings.open{display:block}
.settings label{display:block;font-size:12px;color:var(--muted);margin:8px 0 3px}
.settings input,.settings select{width:100%;padding:7px 9px;border-radius:7px;border:1px solid var(--border);background:var(--bg);color:var(--text);font-size:13px}
.settings .row{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.settings .actions{display:flex;gap:8px;margin-top:12px}
.settings .msg{margin-top:8px;font-size:12px;color:var(--muted)}
.settings .msg.err{color:var(--danger)}
.banner{display:none;margin:10px 12px 0;padding:10px 12px;border:1px solid #5b2323;background:#2a1212;color:#fca5a5;border-radius:8px;font-size:13px}
.banner.show{display:block}
.login-overlay{position:fixed;inset:0;z-index:100;background:rgba(4,9,18,.97);display:flex;align-items:center;justify-content:center;padding:16px}
.login-overlay.hidden{display:none}
.login-card{width:100%;max-width:360px;background:var(--panel);border:1px solid var(--border);border-radius:12px;padding:26px 24px}
.login-card h2{margin:0 0 4px;font-size:20px}
.login-card h2 span{color:var(--accent)}
.login-card p{margin:0 0 16px;color:var(--muted);font-size:13px}
.login-card label{display:block;font-size:12px;color:var(--muted);margin:0 0 4px}
.login-card input{width:100%;padding:10px 12px;border-radius:7px;border:1px solid var(--border);background:var(--bg);color:var(--text);font-size:15px}
.login-card button{width:100%;margin-top:14px;padding:10px;font-size:15px}
.login-card .err{margin-top:10px;font-size:13px;color:var(--danger);min-height:18px}
</style>
</head>
<body>
<header class="topbar">
<h1>Browser <span>Farm</span></h1>
<span class="sub">8 browser terisolasi &middot; tiap browser identitas berbeda</span>
<div class="spacer"></div>
<button id="refreshBtn" type="button">Refresh</button>
<button id="startAllBtn" type="button" class="primary">Start semua</button>
<button id="stopAllBtn" type="button">Stop semua</button>
<button id="syncBtn" type="button" title="Saat ON, kendalikan 1 browser dan semua browser lain ikut (klik, scroll, ketik).">Sinkron: OFF</button>
</header>
<p class="note"><b>Cara pakai:</b> login sekali dengan password farm &mdash; semua browser langsung terhubung otomatis. Tiap cell adalah browser Chromium sendiri (profil, cookie, dan IP terpisah). Settings mengubah User-Agent &amp; proxy, lalu browser restart otomatis. <b>Sinkron:</b> nyalakan tombol di atas, lalu klik/ketik di satu browser — semua browser lain ikut melakukan hal yang sama. Browser yang terakhir kamu sentuh jadi Master (badge kuning).</p>
<div class="banner" id="banner"></div>
<main class="grid" id="grid"></main>
<div class="login-overlay hidden" id="loginOverlay">
<form class="login-card" id="loginForm">
<h2>Browser <span>Farm</span></h2>
<p>Masukkan password farm untuk membuka grid.</p>
<label for="loginPass">Password</label>
<input id="loginPass" type="password" autocomplete="current-password" placeholder="Password farm">
<button type="submit" class="primary">Masuk</button>
<div class="err" id="loginErr"></div>
</form>
</div>
<script>
(function () {
'use strict';
var grid = document.getElementById('grid');
var banner = document.getElementById('banner');
var loginOverlay = document.getElementById('loginOverlay');
var loginForm = document.getElementById('loginForm');
var loginPass = document.getElementById('loginPass');
var loginErr = document.getElementById('loginErr');
var cells = {}; // id -> { el, iframe, overlay, badge, identity, settingsForm, prevStatus, iframeLoaded, tokenLoaded, masterBadge, inputEl, inputPoll }
var presets = {}; // uaKey -> { label, ua }
var busy = {};
var gridStarted = false;
var pollTimer = null;
// ---- Sync control: one master drives all browsers ----
// Toggle state lives in localStorage only (per browser, not shared
// across devices). Default OFF.
var SYNC_KEY = 'farm_sync';
var syncOn = false;
try { syncOn = window.localStorage.getItem(SYNC_KEY) === 'on'; } catch (e) { syncOn = false; }
var masterId = null; // id of the cell the user last interacted with
var lastMoveMirror = 0;
var MOVE_MIRROR_MIN_MS = 16; // throttle mousemove mirroring (~60fps)
function showBanner(msg) {
banner.textContent = msg;
banner.classList.add('show');
}
function hideBanner() {
banner.classList.remove('show');
}
function showLogin(msg) {
if (msg) loginErr.textContent = msg;
loginOverlay.classList.remove('hidden');
setTimeout(function () { loginPass.focus(); }, 50);
}
function hideLogin() {
loginOverlay.classList.add('hidden');
loginErr.textContent = '';
loginPass.value = '';
}
// One farm login, then the grid starts. Called on page load and after
// every successful login (e.g. after the session expired mid-use).
function startGrid() {
if (!gridStarted) {
gridStarted = true;
loadPresets().then(function () { return refresh(); });
pollTimer = setInterval(refresh, 10000);
} else {
refresh();
}
}
function checkAuth() {
fetch('/api/me')
.then(function (r) { return r.json(); })
.then(function (j) {
if (j && j.authenticated) {
hideLogin();
startGrid();
} else {
showLogin();
}
})
.catch(function () { showLogin('Manager tidak bisa dihubungi.'); });
}
loginForm.addEventListener('submit', function (ev) {
ev.preventDefault();
var pw = loginPass.value;
if (!pw) return;
loginErr.textContent = '';
fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: pw }),
})
.then(function (r) {
if (!r.ok) throw new Error('salah');
return r.json();
})
.then(function (j) {
if (!j.ok) throw new Error('salah');
hideLogin();
startGrid();
})
.catch(function () {
loginErr.textContent = 'Password salah, coba lagi.';
loginPass.select();
});
});
function iframeUrl(b) {
// Same-origin path through the nginx /bN/ proxy (see install.sh):
// the grid must script into the Neko iframes for Sync, which needs
// same-origin. A relative path always matches the grid's origin
// (IP or domain). The token mechanism is unchanged.
var base = '/' + b.id + '/';
// The manager hands us a fresh Neko session token per browser; the
// Neko client auto-connects with ?token=... and never shows its
// login form. Without a token we fall back to the plain URL (that
// cell will show Neko's login form instead of a broken cell).
if (b.token) return base + '?token=' + encodeURIComponent(b.token);
return base;
}
function identityLine(b) {
var p = b.proxy || { type: 'direct' };
var proxyText = 'Direct';
if (p.type && p.type !== 'direct') {
proxyText = (p.type === 'socks5' ? 'SOCKS5 ' : 'HTTP ') + (p.host || '') + ':' + (p.port || '');
}
return (b.uaLabel || b.uaKey || '-') + ' · ' + proxyText;
}
function el(tag, cls, text) {
var n = document.createElement(tag);
if (cls) n.className = cls;
if (text !== undefined && text !== null) n.textContent = text;
return n;
}
function buildCell(b) {
var cell = el('section', 'cell');
cell.id = 'cell-' + b.id;
var head = el('div', 'cell-head');
var title = el('div', 'cell-title');
title.appendChild(el('strong', null, b.name));
var badge = el('span', 'badge stopped', 'Stopped');
title.appendChild(badge);
var masterBadge = el('span', 'badge master', 'Master');
masterBadge.style.display = 'none';
title.appendChild(masterBadge);
head.appendChild(title);
var identity = el('div', 'identity', identityLine(b));
head.appendChild(identity);
cell.appendChild(head);
var view = el('div', 'cell-view');
var frame = document.createElement('iframe');
frame.setAttribute('title', b.name);
frame.setAttribute('allow', 'autoplay; clipboard-read; clipboard-write; fullscreen');
frame.addEventListener('load', function () { pollForInput(b.id); });
view.appendChild(frame);
var overlay = el('div', 'overlay');
overlay.appendChild(el('strong', null, 'Browser berhenti'));
overlay.appendChild(el('span', null, 'Klik Start untuk menyalakan browser ini.'));
var ovStart = el('button', 'primary', 'Start');
ovStart.type = 'button';
ovStart.addEventListener('click', function () { doAction(b.id, 'start'); });
overlay.appendChild(ovStart);
view.appendChild(overlay);
cell.appendChild(view);
var toolbar = el('div', 'toolbar');
var acts = [
['start', 'Start', ''],
['stop', 'Stop', ''],
['restart', 'Restart', ''],
['wipe', 'Wipe', 'danger'],
['fullscreen', 'Fullscreen', ''],
['settings', 'Settings', ''],
];
acts.forEach(function (a) {
var btn = el('button', a[2], a[1]);
btn.type = 'button';
btn.dataset.act = a[0];
btn.addEventListener('click', function () { onToolbar(b.id, a[0]); });
toolbar.appendChild(btn);
});
cell.appendChild(toolbar);
var form = document.createElement('form');
form.className = 'settings';
form.addEventListener('submit', function (ev) {
ev.preventDefault();
saveSettings(b.id);
});
form.innerHTML =
'<label>User-Agent</label>' +
'<select name="ua"></select>' +
'<label>Proxy</label>' +
'<select name="proxyType">' +
'<option value="direct">Direct (tanpa proxy)</option>' +
'<option value="http">HTTP</option>' +
'<option value="socks5">SOCKS5</option>' +
'</select>' +
'<div class="row">' +
'<div><label>Host proxy</label><input name="host" type="text" placeholder="1.2.3.4" autocomplete="off"></div>' +
'<div><label>Port proxy</label><input name="port" type="number" min="1" max="65535" placeholder="8080"></div>' +
'</div>' +
'<div class="row">' +
'<div><label>Username (opsional)</label><input name="user" type="text" autocomplete="off"></div>' +
'<div><label>Password (opsional)</label><input name="pass" type="password" autocomplete="off"></div>' +
'</div>' +
'<div class="actions">' +
'<button type="submit" class="primary">Simpan &amp; Restart</button>' +
'<button type="button" class="cancelBtn">Batal</button>' +
'</div>' +
'<div class="msg"></div>';
form.querySelector('.cancelBtn').addEventListener('click', function () {
form.classList.remove('open');
});
cell.appendChild(form);
grid.appendChild(cell);
cells[b.id] = {
el: cell, iframe: frame, overlay: overlay, badge: badge,
identity: identity, form: form, prevStatus: null, iframeLoaded: false,
tokenLoaded: false, masterBadge: masterBadge, inputEl: null, inputPoll: null,
};
}
// ---- Sync control: find + watch the Neko input element ----
// The Neko Overlay (client/core/src/overlay.ts) is a wrap div holding
// a <canvas> (cursor layer) and a transparent <textarea> (the input
// layer). Every mouse/wheel/keyboard listener lives on that textarea.
// We find it by structure — a textarea whose parent also holds a
// canvas — not by class name: the Overlay sets no class names.
function findNekoInput(doc) {
try {
if (!doc) return null;
var tas = doc.querySelectorAll('textarea');
for (var i = 0; i < tas.length; i++) {
var p = tas[i].parentElement;
if (p && p.querySelector('canvas')) return tas[i];
}
return null;
} catch (e) {
return null; // cross-origin or not ready yet
}
}
// Poll for the Neko input element after an iframe (re)loads. The Neko
// client renders its overlay asynchronously, so we wait up to ~10s.
// A cell whose input never appears is simply left unmirrored.
function pollForInput(id) {
var c = cells[id];
if (!c) return;
if (c.inputPoll) { clearInterval(c.inputPoll); c.inputPoll = null; }
c.inputEl = null;
var tries = 0;
c.inputPoll = setInterval(function () {
tries++;
var input = null;
try {
if (c.iframe && c.iframe.contentDocument) input = findNekoInput(c.iframe.contentDocument);
} catch (e) { input = null; }
if (input) {
clearInterval(c.inputPoll); c.inputPoll = null;
attachSyncListeners(id, input);
return;
}
if (tries >= 20) { clearInterval(c.inputPoll); c.inputPoll = null; }
}, 500);
}
// Attach the Sync capture listeners to one cell's Neko input element.
// Listeners go on the textarea itself (same target as the Overlay's
// own listeners): the Overlay calls stopPropagation(), which blocks
// ancestors but never other listeners on the same element.
function attachSyncListeners(id, input) {
var c = cells[id];
if (!c || c.inputEl === input) return;
c.inputEl = input;
var win = input.ownerDocument.defaultView;
function handler(e) { onCellInput(id, e); }
// Mouse + wheel + keyboard: exactly the events the Overlay listens
// to. (The Overlay uses mouse events, not pointer events, so we
// mirror mouse events — a PointerEvent would be ignored by it.)
['mousemove', 'mousedown', 'wheel', 'keydown', 'keyup'].forEach(function (type) {
input.addEventListener(type, handler, false);
});
// mouseup can happen outside the textarea (the Overlay itself
// listens on window, capture). Catch every mouseup via the iframe
// window so a press that started on the video is always released.
// (Only window, not the textarea too — otherwise one release would
// mirror twice.)
if (win) win.addEventListener('mouseup', handler, true);
}
function setMaster(id) {
if (masterId === id) return;
masterId = id;
Object.keys(cells).forEach(function (k) {
var c = cells[k];
if (c.masterBadge) c.masterBadge.style.display = (k === id) ? '' : 'none';
if (c.el) c.el.classList.toggle('is-master', k === id);
});
}
function clearMaster() {
masterId = null;
Object.keys(cells).forEach(function (k) {
var c = cells[k];
if (c.masterBadge) c.masterBadge.style.display = 'none';
if (c.el) c.el.classList.remove('is-master');
});
}
// One real user interaction on a cell makes it the master and mirrors
// that input to every other cell.
function onCellInput(id, e) {
if (!syncOn) return;
// Only real user input drives Sync. Synthetic events dispatched into
// followers have isTrusted=false — ignoring them prevents feedback
// loops and stops a follower from becoming the master. (Neither the
// Neko Overlay nor its Guacamole keyboard checks isTrusted, so the
// synthetic events still reach the remote desktop.)
if (!e.isTrusted) return;
setMaster(id);
mirrorInput(id, e);
}
function mirrorInput(masterId, e) {
var master = cells[masterId];
if (!master || !master.inputEl) return;
var type = e.type;
if (type !== 'mousemove' && type !== 'mousedown' && type !== 'mouseup' &&
type !== 'wheel' && type !== 'keydown' && type !== 'keyup') return;
// Throttle mousemove mirroring (~60fps) so a fast drag does not
// flood the followers with synthetic events. Clicks, wheel and keys
// are never throttled.
if (type === 'mousemove') {
var now = Date.now();
if (now - lastMoveMirror < MOVE_MIRROR_MIN_MS) return;
lastMoveMirror = now;
}
// Relative position inside the master's input area. The Overlay maps
// clientX/clientY against its canvas rect, which equals the textarea
// rect (both fill the same box), so fractions of the textarea map
// exactly onto each follower's remote screen — even if cells render
// at slightly different sizes.
var r;
try { r = master.inputEl.getBoundingClientRect(); } catch (err) { return; }
var fx = r.width ? (e.clientX - r.left) / r.width : 0;
var fy = r.height ? (e.clientY - r.top) / r.height : 0;
fx = Math.max(0, Math.min(1, fx));
fy = Math.max(0, Math.min(1, fy));
Object.keys(cells).forEach(function (fid) {
if (fid === masterId) return;
var f = cells[fid];
if (!f || !f.inputEl) return;
if (!f._browser || f._browser.status !== 'running') return;
try {
var fwin = f.inputEl.ownerDocument.defaultView;
if (!fwin) return;
var fr = f.inputEl.getBoundingClientRect();
var cx = fr.left + fx * fr.width;
var cy = fr.top + fy * fr.height;
var mods = {
ctrlKey: !!e.ctrlKey, shiftKey: !!e.shiftKey,
altKey: !!e.altKey, metaKey: !!e.metaKey,
};
var ev = null;
if (type === 'wheel') {
ev = new fwin.WheelEvent('wheel', {
bubbles: true, cancelable: true,
clientX: cx, clientY: cy,
deltaX: e.deltaX || 0, deltaY: e.deltaY || 0, deltaMode: e.deltaMode || 0,
ctrlKey: mods.ctrlKey, shiftKey: mods.shiftKey,
altKey: mods.altKey, metaKey: mods.metaKey,
});
} else if (type === 'keydown' || type === 'keyup') {
ev = new fwin.KeyboardEvent(type, {
bubbles: true, cancelable: true,
key: e.key, code: e.code, location: e.location || 0,
ctrlKey: mods.ctrlKey, shiftKey: mods.shiftKey,
altKey: mods.altKey, metaKey: mods.metaKey,
repeat: !!e.repeat,
});
// The Neko Guacamole keyboard resolves keys from keyCode/which
// (and from key). The KeyboardEvent constructor cannot set
// keyCode/which, so shadow them so the follower maps the
// same key.
try {
Object.defineProperty(ev, 'keyCode', { value: e.keyCode || 0 });
Object.defineProperty(ev, 'which', { value: e.which || e.keyCode || 0 });
} catch (err) { /* ignore */ }
} else {
// mousemove / mousedown / mouseup
ev = new fwin.MouseEvent(type, {
bubbles: true, cancelable: true,
clientX: cx, clientY: cy,
button: (typeof e.button === 'number') ? e.button : 0,
buttons: (typeof e.buttons === 'number') ? e.buttons : 0,
ctrlKey: mods.ctrlKey, shiftKey: mods.shiftKey,
altKey: mods.altKey, metaKey: mods.metaKey,
});
}
if (ev) f.inputEl.dispatchEvent(ev);
} catch (err) {
// A follower that is not ready must never break the grid.
}
});
}
// Sync toggle: on/off, remembered in localStorage (per browser).
var syncBtn = document.getElementById('syncBtn');
function renderSyncBtn() {
syncBtn.textContent = syncOn ? 'Sinkron: ON' : 'Sinkron: OFF';
syncBtn.classList.toggle('sync-on', syncOn);
}
function setSync(on) {
syncOn = !!on;
try { window.localStorage.setItem(SYNC_KEY, syncOn ? 'on' : 'off'); } catch (e) {}
renderSyncBtn();
if (!syncOn) clearMaster();
}
syncBtn.addEventListener('click', function () { setSync(!syncOn); });
renderSyncBtn();
function fillUaOptions() {
Object.keys(cells).forEach(function (id) {
var sel = cells[id].form.querySelector('select[name="ua"]');
sel.innerHTML = '';
Object.keys(presets).forEach(function (key) {
var opt = document.createElement('option');
opt.value = key;
opt.textContent = presets[key].label || key;
sel.appendChild(opt);
});
});
}
function openSettings(id, b) {
var c = cells[id];
var sel = c.form.querySelector('select[name="ua"]');
sel.value = b.uaKey || '';
var p = b.proxy || { type: 'direct' };
c.form.querySelector('select[name="proxyType"]').value = p.type || 'direct';
c.form.querySelector('input[name="host"]').value = p.host || '';
c.form.querySelector('input[name="port"]').value = p.port || '';
c.form.querySelector('input[name="user"]').value = p.user || '';
c.form.querySelector('input[name="pass"]').value = p.pass || '';
c.form.querySelector('.msg').textContent = '';
c.form.classList.add('open');
}
function setMsg(id, text, isErr) {
var m = cells[id].form.querySelector('.msg');
m.textContent = text;
m.classList.toggle('err', !!isErr);
}
function onToolbar(id, act) {
if (act === 'fullscreen') {
var c = cells[id];
var willExpand = !c.el.classList.contains('expanded');
Object.keys(cells).forEach(function (k) { cells[k].el.classList.remove('expanded'); });
if (willExpand) c.el.classList.add('expanded');
return;
}
if (act === 'settings') {
var b = cells[id]._browser;
if (b) openSettings(id, b);
return;
}
if (act === 'wipe') {
var name = (cells[id]._browser && cells[id]._browser.name) || id;
if (!window.confirm('Hapus semua data ' + name + ' (cookies, history, login)?\nHanya browser ini yang dihapus, browser lain tidak disentuh.')) return;
}
doAction(id, act);
}
function doAction(id, action) {
if (busy[id]) return;
busy[id] = true;
fetch('/api/browsers/' + encodeURIComponent(id) + '/' + encodeURIComponent(action), { method: 'POST' })
.then(function (r) { return r.json(); })
.then(function (j) {
busy[id] = false;
if (!j.ok) throw new Error(j.error || 'gagal');
return refresh();
})
.catch(function (e) {
busy[id] = false;
showBanner('Gagal ' + action + ' ' + id + ': ' + e.message);
});
}
function saveSettings(id) {
var c = cells[id];
var f = c.form;
var proxyType = f.querySelector('select[name="proxyType"]').value;
var proxy = { type: proxyType };
if (proxyType !== 'direct') {
proxy.host = f.querySelector('input[name="host"]').value.trim();
proxy.port = Number(f.querySelector('input[name="port"]').value);
proxy.user = f.querySelector('input[name="user"]').value;
proxy.pass = f.querySelector('input[name="pass"]').value;
}
var body = {
ua: f.querySelector('select[name="ua"]').value,
proxy: proxy,
};
setMsg(id, 'Menyimpan & restart browser...', false);
fetch('/api/browsers/' + encodeURIComponent(id) + '/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
})
.then(function (r) { return r.json(); })
.then(function (j) {
if (!j.ok) throw new Error(j.error || 'gagal menyimpan');
setMsg(id, 'Tersimpan. Identitas baru: ' + (j.uaLabel || '') + ' · ' + ((j.proxy && j.proxy.type) || ''), false);
return refresh();
})
.catch(function (e) {
setMsg(id, 'Gagal: ' + e.message, true);
});
}
function updateCell(b) {
var c = cells[b.id];
if (!c) return;
c._browser = b;
var running = b.status === 'running';
c.badge.textContent = running ? 'Running' : 'Stopped';
c.badge.className = 'badge ' + (running ? 'running' : 'stopped');
c.identity.textContent = identityLine(b);
c.overlay.style.display = running ? 'none' : 'flex';
if (running) {
if (!c.iframeLoaded || c.prevStatus === 'stopped') {
// First load, or the browser came back after a stop/restart:
// (re)set the src, with the fresh token when we have one.
c.iframe.src = iframeUrl(b);
c.iframeLoaded = true;
c.tokenLoaded = !!b.token;
c.inputEl = null; // new page — the old textarea is gone; the iframe load handler re-polls for the new one
} else if (!c.tokenLoaded && b.token) {
// The token arrived after the iframe was first loaded (Neko was
// still starting). Upgrade the src once so the cell auto-connects.
// Normal polls never touch src, so a token refresh never kicks
// the user out of a running browser.
c.iframe.src = iframeUrl(b);
c.tokenLoaded = true;
c.inputEl = null;
}
}
c.prevStatus = b.status;
}
function refresh() {
return fetch('/api/browsers')
.then(function (r) {
if (r.status === 401) {
// Session expired — ask for the farm password again.
showLogin('Sesi habis, login lagi.');
throw new Error('unauthorized');
}
return r.json();
})
.then(function (j) {
hideBanner();
var list = j.browsers || [];
list.forEach(function (b) {
if (!cells[b.id]) buildCell(b);
updateCell(b);
});
})
.catch(function (e) {
if (e.message !== 'unauthorized') {
showBanner('Manager tidak bisa dihubungi: ' + e.message);
}
});
}
function loadPresets() {
return fetch('/api/ua-presets')
.then(function (r) { return r.json(); })
.then(function (j) {
presets = j.presets || {};
fillUaOptions();
})
.catch(function () { /* presets stay empty; settings still works with server validation */ });
}
document.getElementById('refreshBtn').addEventListener('click', function () { refresh(); });
document.getElementById('startAllBtn').addEventListener('click', function () {
fetch('/api/browsers/start-all', { method: 'POST' })
.then(function () { return refresh(); })
.catch(function (e) { showBanner('Gagal start semua: ' + e.message); });
});
document.getElementById('stopAllBtn').addEventListener('click', function () {
fetch('/api/browsers/stop-all', { method: 'POST' })
.then(function () { return refresh(); })
.catch(function (e) { showBanner('Gagal stop semua: ' + e.message); });
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') {
Object.keys(cells).forEach(function (k) { cells[k].el.classList.remove('expanded'); });
}
});
checkAuth();
})();
</script>
</body>
</html>
+401
View File
@@ -0,0 +1,401 @@
// Browser Farm manager — serves the grid UI and controls 8 isolated Neko
// browsers (farm-b1..farm-b8) via docker. Listens on 127.0.0.1:18080;
// nginx proxies port 80 to it. No database: per-browser runtime state lives
// in /opt/farm/<id>/meta.json, static identity in manager/config.json.
// Security: browser ids are validated strictly (^b[1-8]$) and every docker
// call uses execFile with an argument array — no user input ever reaches a
// shell. One password (FARM_PASSWORD) gates the whole grid (httpOnly
// farm_auth cookie, 7 days); the manager logs in to each Neko instance
// itself and hands the grid a ?token= URL per cell, so the user never sees
// a per-cell Neko login form.
'use strict';
const express = require('express');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const app = express();
const PORT = Number(process.env.PORT || 18080);
const HOST = process.env.HOST || '127.0.0.1';
const FARM_ROOT = process.env.FARM_ROOT || '/opt/farm';
const CONFIG_PATH = path.join(__dirname, 'config.json');
const GENERATE_SCRIPT = path.join(__dirname, '..', 'scripts', 'generate.js');
// Single password for the whole farm: the grid login AND every Neko
// instance's password. Must match FARM_PASSWORD in scripts/install.sh.
const FARM_PASSWORD = process.env.FARM_PASSWORD || 'FarmBrowser2026';
const NEKO_LOGIN_USER = 'pend';
const TOKEN_TTL_MS = 55 * 60 * 1000; // Neko tokens are re-fetched every 55 min
const SESSION_TTL_MS = 7 * 24 * 60 * 60 * 1000; // farm login lasts 7 days
// In-memory farm sessions: sessionId -> expiresAt (ms). No DB.
const sessions = new Map();
// In-memory Neko tokens: browserId -> { token, expiresAt, startedAt }.
const tokenCache = new Map();
app.use(express.json({ limit: '64kb' }));
app.use(express.static(path.join(__dirname, 'public')));
function parseCookies(req) {
const out = {};
const header = req.headers && req.headers.cookie;
if (!header) return out;
header.split(';').forEach(function (part) {
const idx = part.indexOf('=');
if (idx > 0) {
try {
out[part.slice(0, idx).trim()] = decodeURIComponent(part.slice(idx + 1).trim());
} catch (e) {
out[part.slice(0, idx).trim()] = part.slice(idx + 1).trim();
}
}
});
return out;
}
function isAuthenticated(req) {
const sid = parseCookies(req).farm_auth;
if (!sid) return false;
const exp = sessions.get(sid);
if (!exp) return false;
if (exp < Date.now()) {
sessions.delete(sid);
return false;
}
return true;
}
// Grid-level password gate for /api/*. Public: POST /api/login, GET /api/me.
// GET /health is not under /api, so it is never gated. The grid page itself
// (/) is served without auth; it calls /api/me and shows a login overlay
// when the session is missing or expired.
function requireFarmAuth(req, res, next) {
if (req.method === 'POST' && req.path === '/login') return next();
if (req.method === 'GET' && req.path === '/me') return next();
if (isAuthenticated(req)) return next();
return res.status(401).json({ ok: false, error: 'unauthorized' });
}
app.use('/api', requireFarmAuth);
function loadConfig() {
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
}
// Merge config defaults with the runtime meta.json (if it exists).
function loadBrowser(id) {
const cfg = loadConfig();
const base = (cfg.browsers || []).find((b) => b.id === id);
if (!base) return null;
let meta = {};
try {
meta = JSON.parse(fs.readFileSync(path.join(FARM_ROOT, id, 'meta.json'), 'utf8'));
} catch (e) {
// No meta yet (fresh install) — fall back to config defaults.
}
const uaKey = meta.uaKey || base.uaKey;
const preset = (cfg.uaPresets || {})[uaKey] || (cfg.uaPresets || {})[base.uaKey] || {};
return {
id: base.id,
name: meta.name || base.name,
uaKey: uaKey,
uaLabel: preset.label || uaKey,
proxy: meta.proxy || { type: 'direct' },
httpPort: base.httpPort,
udpStart: base.udpStart,
udpEnd: base.udpEnd,
};
}
function validateId(id) {
return /^b[1-8]$/.test(id || '');
}
async function dockerStatus(id) {
const name = 'farm-' + id;
try {
const { stdout } = await execFileAsync('docker', [
'inspect',
'-f',
'{{.State.Status}}|{{.State.StartedAt}}',
name,
]);
const parts = stdout.trim().split('|');
const status = parts[0] || 'stopped';
let uptime = null;
if (status === 'running' && parts[1]) {
const started = new Date(parts[1]).getTime();
if (!Number.isNaN(started)) {
uptime = Math.max(0, Math.floor((Date.now() - started) / 1000));
}
}
return { status: status, uptime: uptime, startedAt: parts[1] || null };
} catch (e) {
// Container missing, or docker unavailable — treat as stopped.
return { status: 'stopped', uptime: null, startedAt: null };
}
}
// Log in to one Neko instance and return its session token (or null).
// The Neko web client accepts ?token=... in the iframe URL and then
// auto-connects, so the user never sees a per-cell login form.
async function fetchNekoToken(httpPort) {
try {
const res = await fetch('http://127.0.0.1:' + httpPort + '/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: NEKO_LOGIN_USER, password: FARM_PASSWORD }),
signal: AbortSignal.timeout(5000),
});
if (!res.ok) return null;
const j = await res.json();
return j && typeof j.token === 'string' && j.token ? j.token : null;
} catch (e) {
console.error(
'neko login failed (port ' + httpPort + '): ' + (e && e.message ? e.message : e)
);
return null;
}
}
// Cached Neko token for one browser. Re-fetched when missing, expired, or
// when the container restarted (startedAt changed — a restart invalidates
// the old token). Returns null when Neko is not reachable yet.
async function getBrowserToken(id, httpPort, startedAt) {
const now = Date.now();
const cached = tokenCache.get(id);
if (
cached &&
cached.token &&
cached.expiresAt > now &&
cached.startedAt === startedAt
) {
return cached.token;
}
const token = await fetchNekoToken(httpPort);
if (token) {
tokenCache.set(id, { token: token, expiresAt: now + TOKEN_TTL_MS, startedAt: startedAt });
} else {
tokenCache.delete(id);
}
return token;
}
async function dockerAction(action, id) {
await execFileAsync('docker', [action, 'farm-' + id]);
}
function validateProxy(p) {
const proxy = p || { type: 'direct' };
if (!['direct', 'http', 'socks5'].includes(proxy.type)) {
return { error: 'invalid proxy type (want direct|http|socks5)' };
}
if (proxy.type === 'direct') return { proxy: { type: 'direct' } };
const host = typeof proxy.host === 'string' ? proxy.host.trim() : '';
const port = Number(proxy.port);
if (!host) return { error: 'proxy host required' };
if (!Number.isInteger(port) || port < 1 || port > 65535) {
return { error: 'proxy port invalid (want 1-65535)' };
}
return {
proxy: {
type: proxy.type,
host: host,
port: port,
user: typeof proxy.user === 'string' ? proxy.user : '',
pass: typeof proxy.pass === 'string' ? proxy.pass : '',
},
};
}
app.get('/health', (req, res) => {
res.json({ ok: true });
});
// Single grid-level login. On success sets an httpOnly farm_auth cookie
// (7 days). One password for the whole farm — no per-cell login.
app.post('/api/login', (req, res) => {
const pw = req.body && typeof req.body.password === 'string' ? req.body.password : '';
const expected = Buffer.from(FARM_PASSWORD, 'utf8');
const given = Buffer.from(pw, 'utf8');
const ok = given.length === expected.length && crypto.timingSafeEqual(given, expected);
if (!ok) {
return res.status(401).json({ ok: false, error: 'password salah' });
}
const sid = crypto.randomBytes(32).toString('hex');
sessions.set(sid, Date.now() + SESSION_TTL_MS);
res.setHeader(
'Set-Cookie',
'farm_auth=' + sid + '; HttpOnly; Path=/; Max-Age=' + Math.floor(SESSION_TTL_MS / 1000) + '; SameSite=Lax'
);
res.json({ ok: true });
});
app.get('/api/me', (req, res) => {
res.json({ authenticated: isAuthenticated(req) });
});
// UA preset list, used by the Settings dropdown in the grid UI.
app.get('/api/ua-presets', (req, res) => {
try {
const cfg = loadConfig();
res.json({ presets: cfg.uaPresets || {} });
} catch (e) {
res.status(500).json({ ok: false, error: String((e && e.message) || e) });
}
});
app.get('/api/browsers', async (req, res) => {
try {
const cfg = loadConfig();
const list = await Promise.all(
(cfg.browsers || []).map(async (b) => {
const info = loadBrowser(b.id);
const st = await dockerStatus(b.id);
// Token is only fetched when the cache is stale (missing, expired,
// or the container restarted) — never on every 10s poll.
let token = null;
if (st.status === 'running') {
token = await getBrowserToken(b.id, info.httpPort, st.startedAt);
}
return Object.assign({}, info, { status: st.status, uptime: st.uptime, token: token });
})
);
res.json({ browsers: list });
} catch (e) {
res.status(500).json({ ok: false, error: String((e && e.message) || e) });
}
});
// Start all / stop all (defined before the :id routes).
app.post('/api/browsers/start-all', async (req, res) => {
const cfg = loadConfig();
const results = [];
for (const b of cfg.browsers || []) {
try {
await dockerAction('start', b.id);
results.push({ id: b.id, ok: true });
} catch (e) {
results.push({ id: b.id, ok: false, error: String((e && e.message) || e) });
}
}
res.json({ ok: true, results: results });
});
app.post('/api/browsers/stop-all', async (req, res) => {
const cfg = loadConfig();
const results = [];
for (const b of cfg.browsers || []) {
try {
await dockerAction('stop', b.id);
results.push({ id: b.id, ok: true });
} catch (e) {
results.push({ id: b.id, ok: false, error: String((e && e.message) || e) });
}
}
res.json({ ok: true, results: results });
});
// Wipe one browser's profile (cookies, history, logins). Scope is exactly
// that browser's bind-mounted profile dir — nothing else is touched.
app.post('/api/browsers/:id/wipe', async (req, res) => {
const id = req.params.id;
if (!validateId(id)) {
return res.status(400).json({ ok: false, error: 'invalid browser id' });
}
const profileDir = path.resolve(path.join(FARM_ROOT, id, 'profile'));
const root = path.resolve(FARM_ROOT) + path.sep;
if (!profileDir.startsWith(root)) {
return res.status(400).json({ ok: false, error: 'invalid profile path' });
}
try {
try {
await dockerAction('stop', id);
} catch (e) {
// Already stopped or missing — wiping the profile is still safe.
}
await execFileAsync('rm', ['-rf', profileDir]);
await execFileAsync('mkdir', ['-p', profileDir]);
await dockerAction('start', id);
const st = await dockerStatus(id);
res.json({
ok: true,
id: id,
wiped: 'profile of farm-' + id + ' only',
scope:
'Only this browser (farm-' + id + ') profile was deleted. ' +
'Other browsers were not touched.',
status: st.status,
});
} catch (e) {
res.status(500).json({ ok: false, error: String((e && e.message) || e) });
}
});
// Change one browser's identity (UA preset + proxy), then restart it so the
// new Chromium flags take effect.
app.post('/api/browsers/:id/config', async (req, res) => {
const id = req.params.id;
if (!validateId(id)) {
return res.status(400).json({ ok: false, error: 'invalid browser id' });
}
const body = req.body || {};
const cfg = loadConfig();
if (!body.ua || !(cfg.uaPresets || {})[body.ua]) {
return res.status(400).json({ ok: false, error: 'invalid ua preset' });
}
const checked = validateProxy(body.proxy);
if (checked.error) {
return res.status(400).json({ ok: false, error: checked.error });
}
try {
// Regenerate chromium.conf + meta.json with the shared generator.
await execFileAsync(
process.execPath,
[GENERATE_SCRIPT, id, body.ua, JSON.stringify(checked.proxy)],
{ env: Object.assign({}, process.env, { FARM_ROOT: FARM_ROOT }) }
);
await dockerAction('restart', id);
const info = loadBrowser(id);
const st = await dockerStatus(id);
res.json({
ok: true,
id: id,
name: info.name,
uaKey: info.uaKey,
uaLabel: info.uaLabel,
proxy: info.proxy,
status: st.status,
});
} catch (e) {
res.status(500).json({ ok: false, error: String((e && e.message) || e) });
}
});
// Generic start/stop/restart. Defined AFTER the specific :id routes
// (/wipe and /config) so Express does not swallow those paths as an "action".
app.post('/api/browsers/:id/:action', async (req, res) => {
const id = req.params.id;
const action = req.params.action;
if (!validateId(id)) {
return res.status(400).json({ ok: false, error: 'invalid browser id' });
}
if (action !== 'start' && action !== 'stop' && action !== 'restart') {
return res.status(400).json({ ok: false, error: 'invalid action' });
}
try {
await dockerAction(action, id);
const st = await dockerStatus(id);
res.json({ ok: true, id: id, action: action, status: st.status });
} catch (e) {
res.status(500).json({ ok: false, error: String((e && e.message) || e) });
}
});
app.listen(PORT, HOST, () => {
console.log('browser-farm manager listening on ' + HOST + ':' + PORT);
});