Skip to content

Commit

Permalink
improve script status code + challenge match + docker image multi pla…
Browse files Browse the repository at this point in the history
…tform
  • Loading branch information
unixfox committed Jan 13, 2024
1 parent be9bb9d commit 6fa1257
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Docker build tor single hop image

on:
workflow_dispatch:
push:

jobs:

build:

runs-on: 'ubuntu-latest'

steps:

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Check Out Repo
uses: actions/checkout@v3

- name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
version: latest

- name: Build and push docker image
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: quay.io/unixfox/pupflare:latest, quay.io/unixfox/pupflare:master
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
Send your request to the server with the port 3000 and add your URL to the "url" query string like this:
`http://localhost:3000/?url=https://example.org`

To show the browser window, set the environment variable `PUPPETEER_HEADFUL=1`. To use a proxy,
set the `PUPPETEER_PROXY` environment variable, for example `PUPPETEER_PROXY=localhost:8080`. To specify user data directory, set `PUPPETEER_USERDATADIR=/path/to/dir`.
This script has been configured to wait for the cloudflare challenge to pass but, you can configure the "match" for anything else using the environment variable `CHALLENGE_MATCH`.
If the website that you are targeting have a protection page with "please wait" in the HTML code then launch the script like this:
```
CHALLENGE_MATCH="please wait" npm start
```

To show the browser window, set the environment variable `PUPPETEER_HEADFUL=1`.

To use a proxy,
set the `PUPPETEER_PROXY` environment variable, for example `PUPPETEER_PROXY=localhost:8080`.

To specify user data directory, set `PUPPETEER_USERDATADIR=/path/to/dir`.

To enable debugging: `DEBUG=true` and debugging with body in the logs: `DEBUG_BODY=true`

# Docker
Available as a Docker image here: https://quay.io/repository/unixfox/pupflare
Available as a Docker image here: https://quay.io/repository/unixfox/pupflare (linux/amd64,linux/arm/v7,linux/arm64)


```
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive"
let response;
let tryCount = 0;
response = await page.goto(url, { timeout: 30000, waitUntil: 'domcontentloaded' });
ctx.status = response.status();
responseBody = await response.text();
responseData = await response.buffer();
while (responseBody.includes("challenge-running") && tryCount <= 10) {
while (responseBody.includes(process.env.CHALLENGE_MATCH || "challenge-platform") && tryCount <= 10) {
newResponse = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' });
if (newResponse) response = newResponse;
responseBody = await response.text();
Expand All @@ -114,8 +115,10 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive"
}

await page.close();
responseHeadersToRemove.forEach(header => delete responseHeaders[header]);
Object.keys(responseHeaders).forEach(header => ctx.set(header, jsesc(responseHeaders[header])));
if (responseHeaders) {
responseHeadersToRemove.forEach(header => delete responseHeaders[header]);
Object.keys(responseHeaders).forEach(header => ctx.set(header, jsesc(responseHeaders[header])));
}
if (process.env.DEBUG) {
console.log(`[DEBUG] response headers: \n${JSON.stringify(responseHeaders)}`);
}
Expand Down

0 comments on commit 6fa1257

Please sign in to comment.