diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml new file mode 100644 index 0000000..09f7a6c --- /dev/null +++ b/.github/workflows/build-docker-image.yaml @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 1f9ec65..01ac29b 100644 --- a/README.md +++ b/README.md @@ -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) ``` diff --git a/index.js b/index.js index 202077e..4a4381c 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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)}`); }