4 Commits

13 changed files with 112 additions and 32 deletions

View File

@@ -2,4 +2,5 @@ rm build/ -rf
mkdir -p ./build mkdir -p ./build
cd proxyserver && go build && mv proxyserver ../build/ && cd .. cd proxyserver && go build && mv proxyserver ../build/ && cd ..
cp start.sh build/start.sh cp start.sh build/start.sh
cp stop.sh build/stop.sh
cp proxyserver/config.yaml build/config.yaml cp proxyserver/config.yaml build/config.yaml

View File

@@ -14,6 +14,7 @@
"--ignore-certificate-errors", "--ignore-certificate-errors",
"--disable-dev-shm-usage", "--disable-dev-shm-usage",
"--mute-audio", "--mute-audio",
"--single-process",
"--safebrowsing-disable-auto-update", "--safebrowsing-disable-auto-update",
"--disable-gpu", "--disable-gpu",
"--no-sandbox", "--no-sandbox",

View File

@@ -1,23 +1,4 @@
var href = window.location.href;
var content = document.documentElement.innerHTML;
setTimeout(function(){
window.close();
}, 15000)
if (condition == undefined) {
condition = function () {
return true;
};
}
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
}
function Tell(backgroundType, content) { function Tell(backgroundType, content) {
try { try {
if (content == undefined) { if (content == undefined) {
@@ -30,3 +11,30 @@ function Tell(backgroundType, content) {
window.location.href = Host; window.location.href = Host;
} }
} }
try {
if (condition == undefined) {
condition = function () {
return true;
};
}
} catch (error) {
condition = function () {
return true;
};
}
var href = window.location.href;
var content = "";
if(document.contentType == "application/json") {
content = document.documentElement.innerText;
} else {
content = document.documentElement.innerHTML;
}
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
}

View File

@@ -16,8 +16,29 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
GetTask(sender); GetTask(sender);
break; break;
case BackgroundMsgType.NOTWANT: case BackgroundMsgType.NOTWANT:
task = task_manager[sender.tab.id];
if(task.data.waitcapture != undefined) {
setTimeout(function(){
CaptureContentCurrentPage(sender.tab.id);
}, task.data.waitcapture);
} else {
task.data.retry --;
if(task.data.retry >= 0) {
setTimeout(function(){
CaptureContent(task);
}, 6000)
} else {
ErrorTask(sender, request.content); ErrorTask(sender, request.content);
}
}
break; break;
case BackgroundMsgType.CLOSETAB:
delete task_manager[sender.tab.id]
chrome.tabs.remove(sender.tab.id);
default: default:
break; break;
} }
@@ -39,19 +60,33 @@ function GetTask(sender) {
}) })
} }
function CaptureContentCurrentPage(tabid) {
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "base.js" }, function(){
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
});
}
function CaptureContent(task) { function CaptureContent(task) {
if (task.code == 200) { if (task.code == 200) {
if(task.data.retry == undefined) {
task.data.retry = 1;
}
chrome.tabs.create({ url: task.data.url }, function (tab) { chrome.tabs.create({ url: task.data.url }, function (tab) {
task_manager[tab.id] = task; task_manager[tab.id] = task;
if (task.data.content_condition) { if (task.data.content_condition) {
condition = `${task.data.content_condition}` condition = `${task.data.content_condition}`;
} else {
condition = undefined;
} }
if (condition) {
if (condition != undefined) {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () { chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" }); CaptureContentCurrentPage(tab.id)
}); });
} else { } else {
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" }); CaptureContentCurrentPage(tab.id)
} }
}); });
} }
@@ -60,8 +95,10 @@ function CaptureContent(task) {
function FinishTask(sender, content) { function FinishTask(sender, content) {
var task = task_manager[sender.tab.id]; var task = task_manager[sender.tab.id];
var formdata = new FormData(); var formdata = new FormData();
formdata.append("taskid", task.data.taskid); formdata.append("taskid", task.data.taskid);
formdata.append("content", content); formdata.append("content", content);
delete task_manager[sender.tab.id]; delete task_manager[sender.tab.id];
chrome.tabs.remove(sender.tab.id); chrome.tabs.remove(sender.tab.id);
fetch(FinishTaskUrl, { method: "POST", body: formdata }).then(function (response) { fetch(FinishTaskUrl, { method: "POST", body: formdata }).then(function (response) {

View File

@@ -19,6 +19,7 @@ const BackgroundMsgType = {
CONTENT: 'content', CONTENT: 'content',
GETTASK: 'gettask', GETTASK: 'gettask',
TIMEOUT: 'timeout', TIMEOUT: 'timeout',
CLOSETAB: 'closetab',
ERROR: 'error', ERROR: 'error',
OK: 'ok', OK: 'ok',
}; };

View File

@@ -3,6 +3,10 @@ if(href.startsWith(Host)) {
setInterval(function(){ setInterval(function(){
GetTask(); GetTask();
}, 1); }, 1);
} else {
setTimeout(function(){
chrome.runtime.sendMessage({ type: BackgroundMsgType.CLOSETAB })
}, 15000)
} }
function GetTask() { function GetTask() {

View File

@@ -19,7 +19,6 @@ func CallbackServer(task *Task) {
defer task.lock.Unlock() defer task.lock.Unlock()
if callback, ok := task.data["callback"]; ok { if callback, ok := task.data["callback"]; ok {
cburl := callback.(string) cburl := callback.(string)
// log.Println(cburl)
_, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute() _, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute()
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@@ -4,7 +4,7 @@ go 1.15
require ( require (
github.com/474420502/focus v0.12.0 github.com/474420502/focus v0.12.0
github.com/474420502/requests v1.10.0 github.com/474420502/requests v1.10.1
github.com/bwmarrin/snowflake v0.3.0 github.com/bwmarrin/snowflake v0.3.0
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/go-playground/validator/v10 v10.4.1 // indirect

View File

@@ -3,6 +3,8 @@ github.com/474420502/focus v0.12.0 h1:+icbmj7IEOefvTegHt5EpcHt6WFbe2miIrceUJx2Ev
github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s= github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s=
github.com/474420502/requests v1.10.0 h1:Oz7+Nx+1iuJJUjbBH3cVmkDVosF2tyq5d72TMAoQH8I= github.com/474420502/requests v1.10.0 h1:Oz7+Nx+1iuJJUjbBH3cVmkDVosF2tyq5d72TMAoQH8I=
github.com/474420502/requests v1.10.0/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c= github.com/474420502/requests v1.10.0/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c=
github.com/474420502/requests v1.10.1 h1:k5qK8ZWPIdrG0EurJuK2hhoYFbJ9GJTe0xvrzESMFLo=
github.com/474420502/requests v1.10.1/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"strconv"
"time" "time"
"github.com/bwmarrin/snowflake" "github.com/bwmarrin/snowflake"
@@ -70,14 +71,33 @@ func PutTask(c *gin.Context) {
now := time.Now() now := time.Now()
tid := snowNode.Generate().Base64() tid := snowNode.Generate().Base64()
label := c.PostForm("label") label := c.PostForm("label")
if carrayhash := c.PostForm("carrayhash"); carrayhash != "" {
data.Store("carrayhash", carrayhash)
}
if callback := c.PostForm("callback"); callback != "" {
data.Store("callback", callback)
}
data.Store("taskid", tid) data.Store("taskid", tid)
data.Store("url", u) data.Store("url", u)
data.Store("ts", now.UnixNano()) data.Store("ts", now.UnixNano())
data.Store("label", label) data.Store("label", label)
data.Store("content_condition", c.PostForm("content_condition")) data.Store("content_condition", c.PostForm("content_condition"))
if callback := c.PostForm("callback"); callback != "" {
data.Store("callback", callback) if waitcapture, err := strconv.Atoi(c.PostForm("waitcapture")); err != nil {
data.Store("waitcapture", 1)
} else {
data.Store("waitcapture", waitcapture)
} }
if retry, err := strconv.Atoi(c.PostForm("retry")); err != nil {
data.Store("retry", 1)
} else {
data.Store("retry", retry)
}
taskQueue.Push(tid, data) taskQueue.Push(tid, data)
oplog.Write(data) oplog.Write(data)
c.JSON(http.StatusOK, Response{Code: 200, Message: "ok", Data: data}) c.JSON(http.StatusOK, Response{Code: 200, Message: "ok", Data: data})
@@ -103,7 +123,6 @@ func ContentTask(c *gin.Context) {
task.Store("status", "ready") task.Store("status", "ready")
readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化 readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化
c.JSON(200, Response{Code: 200, Data: task}) c.JSON(200, Response{Code: 200, Data: task})
// log.Println("start callback")
if label, ok := task.Load("label"); ok { if label, ok := task.Load("label"); ok {
log.Println(label.(string), tid) log.Println(label.(string), tid)
} }

2
screenlog.0 Normal file
View File

@@ -0,0 +1,2 @@
Cannot exec './proxyserver': 权限不够

View File

@@ -1,6 +1,8 @@
DISPLAY=:99 DISPLAY=:99
screen -L -dmS google-chrome-web google-chrome --load-extension=../chromeproxy --user-data-dir=/tmp/chromeproxy-userdata --ignore-certificate-errors --disable-dev-shm-usage --mute-audio --safebrowsing-disable-auto-update --disable-gpu --no-sandbox --disable-blink-features=AutomationControlled --disable-infobars --allow-running-insecure-content --disable-features=TranslateUI --test-type --no-report-upload --display=$DISPLAY rm /tmp/chromeproxy-userdata/ -rf
screen -L -dmS google-chrome-web google-chrome --load-extension=../chromeproxy --user-data-dir=/tmp/chromeproxy-userdata --ignore-certificate-errors --disable-dev-shm-usage --mute-audio --safebrowsing-disable-auto-update --disable-gpu --no-sandbox --disable-blink-features=AutomationControlled --disable-infobars --allow-running-insecure-content --disable-features=TranslateUI --test-type --no-report-upload --disable-breakpad --no-first-run --display=$DISPLAY
sleep 2s sleep 2s
echo "启动浏览器..." echo "启动浏览器..."
screen -L -dmS proxyserver ./proxyserver screen -L -dmS proxyserver ./proxyserver

4
stop.sh Normal file
View File

@@ -0,0 +1,4 @@
for quitlist in google-chrome-web proxyserver
do
screen -S $quitlist -X quit
done