2 Commits

6 changed files with 70 additions and 77 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
node_modules/ node_modules/
web-ext-artifacts/ web-ext-artifacts/
*.swp *.swp
package.json
package-lock.json

View File

@@ -12,6 +12,7 @@ var global_ws = null;
var container_count = 0; var container_count = 0;
var proxy_map = {}; var proxy_map = {};
var proxy_map_http_attempts = new Map();
var web_response_whitelist = ["main_frame", "xmlhttprequest"]; var web_response_whitelist = ["main_frame", "xmlhttprequest"];
@@ -201,6 +202,12 @@ function attach_ws_events(ws){
ws.addEventListener("open", async function(){ ws.addEventListener("open", async function(){
// clean up internal previous garbage
webreq_completed = new Map();
proxy_map = {};
proxy_map_http_attempts = new Map();
web_response_whitelist = ["main_frame", "xmlhttprequest"];
console.log("ws: connected"); console.log("ws: connected");
await set_status(STATUS_CONNECTED); await set_status(STATUS_CONNECTED);
}); });
@@ -421,6 +428,15 @@ function attach_ws_events(ws){
break; break;
case "container_delete": case "container_delete":
// clear http proxy cache
try{
await browser.webRequest.handlerBehaviorChanged();
}catch(err){
console.log("warn: http proxy cache flush failed: " + err);
}
var deleted_containers = 0; var deleted_containers = 0;
switch(typeof msg.id){ switch(typeof msg.id){
@@ -505,7 +521,6 @@ function attach_ws_events(ws){
ws.addEventListener("close", async function(e){ ws.addEventListener("close", async function(e){
console.log("ws: offline"); console.log("ws: offline");
webreq_completed = new Map();
await set_status(STATUS_OFFLINE); await set_status(STATUS_OFFLINE);
}); });
} }
@@ -604,6 +619,7 @@ browser.webRequest.onBeforeRequest.addListener(
resolve_func({success: false}); resolve_func({success: false});
webreq_completed.delete(details.requestId); webreq_completed.delete(details.requestId);
proxy_map_http_attempts.delete(details.requestId);
return; return;
} }
@@ -643,6 +659,7 @@ browser.webRequest.onBeforeRequest.addListener(
resolve_func({success: false}); resolve_func({success: false});
webreq_completed.delete(details.requestId); webreq_completed.delete(details.requestId);
proxy_map_http_attempts.delete(details.requestId);
} }
}, },
{ urls: ["<all_urls>"] }, { urls: ["<all_urls>"] },
@@ -690,6 +707,7 @@ browser.webRequest.onCompleted.addListener(
// clean up // clean up
webreq_completed.delete(details.requestId); webreq_completed.delete(details.requestId);
proxy_map_http_attempts.delete(details.requestId);
}, },
{ urls: ["<all_urls>"] } { urls: ["<all_urls>"] }
); );
@@ -703,9 +721,12 @@ browser.webRequest.onErrorOccurred.addListener(
if(!web_response_whitelist.includes(page.type)){ if(!web_response_whitelist.includes(page.type)){
webreq_completed.delete(page.requestId); webreq_completed.delete(page.requestId);
proxy_map_http_attempts.delete(page.requestId);
return; return;
} }
const proxy_config = proxy_map[page.cookieStoreId];
send_event( send_event(
global_ws, global_ws,
{ {
@@ -719,6 +740,7 @@ browser.webRequest.onErrorOccurred.addListener(
); );
webreq_completed.delete(page.requestId); webreq_completed.delete(page.requestId);
proxy_map_http_attempts.delete(page.requestId);
}, },
{ urls: ["<all_urls>"] } { urls: ["<all_urls>"] }
); );
@@ -726,6 +748,22 @@ browser.webRequest.onErrorOccurred.addListener(
browser.proxy.onRequest.addListener(function(request){ browser.proxy.onRequest.addListener(function(request){
const proxy_config = proxy_map[request.cookieStoreId]; const proxy_config = proxy_map[request.cookieStoreId];
if(
proxy_config &&
(
proxy_config.type == "http" ||
proxy_config.type == "https"
)
){
return {
type: proxy_config.type,
host: proxy_config.host,
port: proxy_config.port
};
}
if(proxy_config){ if(proxy_config){
return proxy_config; return proxy_config;
@@ -762,6 +800,31 @@ browser.webRequest.onAuthRequired.addListener(
proxy_config.password proxy_config.password
){ ){
// check if creds have been tried before...
var attempts = proxy_map_http_attempts.get(details.requestId);
if(typeof attempts == "undefined"){
proxy_map_http_attempts.set(details.requestId, 1);
}else{
send_event(
global_ws,
{
"action": "dom_load_fail",
"data": {
id: details.tabId,
url: details.url,
error: "HTTP proxy refused the connection"
}
}
);
webreq_completed.delete(details.requestId);
proxy_map_http_attempts.delete(details.requestId);
return;
}
return { return {
authCredentials: { authCredentials: {
username: proxy_config.username, username: proxy_config.username,

View File

@@ -2,7 +2,7 @@ const fplay = require("./lib/fplay.js");
var port = 3030; var port = 3030;
var timeout = 30000; var timeout = 30000;
var password = process.env.FOURPLAY_PASSWORD || "cnc"; var password = "cnc";
fplay.event.on("server_ready", function(){ fplay.event.on("server_ready", function(){

View File

@@ -1,13 +1,11 @@
const http = require("http"); const http = require("http");
const { WebSocketServer } = require("ws"); const { WebSocketServer } = require("ws");
const {FOURPLAY_PORT = 3000, FOURPLAY_COMMAND_TIMEOUT = 5000, FOURPLAY_PASSWORD = "cnc"} = process.env;
var fplay = {}; var fplay = {};
fplay.PORT = FOURPLAY_PORT; fplay.PORT = 3030;
fplay.COMMAND_TIMEOUT = FOURPLAY_COMMAND_TIMEOUT; fplay.COMMAND_TIMEOUT = 5000;
fplay.PASSWORD = FOURPLAY_PASSWORD; fplay.PASSWORD = "cnc";
const { EventEmitter } = require("events"); const { EventEmitter } = require("events");
fplay.event = new EventEmitter(); fplay.event = new EventEmitter();
@@ -560,8 +558,4 @@ fplay.init = function(port = 3030, password = "cnc", command_timeout = 5000){
}); });
} }
process.on('SIGINT', function() {
process.exit();
});
module.exports = fplay; module.exports = fplay;

View File

@@ -1,37 +0,0 @@
{
"name": "@lawlers/4play",
"version": "1.2.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lawlers/4play",
"version": "1.2.5",
"license": "AGPL-3.0-only",
"dependencies": {
"ws": "^8.21.1"
}
},
"node_modules/ws": {
"version": "8.21.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.2.tgz",
"integrity": "sha512-54dMVAo4WIe6SKy3vBgN+9bJZqqQ8IMRevAkOLQALhi49qkkQDQfWdAZ8KQlXiEabw88ARXXdUrlvtbKQX+aKw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

View File

@@ -1,29 +0,0 @@
{
"name": "@lawlers/4play",
"version": "1.2.5",
"description": "4play and dominate",
"keywords": [
"4play",
"fplay",
"foreplay",
"browser-automation",
"puppeteer",
"selenium",
"playwright",
"firefox"
],
"repository": {
"type": "git",
"url": "https://git.lolcat.ca/lolcat/4play"
},
"license": "AGPL-3.0-only",
"author": "lolcat",
"type": "commonjs",
"main": "fplay.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"ws": "^8.21.1"
}
}