Skip to content

Send Recaptcha2 recognition requests to ZennoLab's CapMonster (Windows) with FastAPI & MongoDB Cloud.

License

Notifications You must be signed in to change notification settings

nlile/mongodb-capmonster-recapcha-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Self-Hosted CapMonster Cloud API

Send requests to a single CapMonster instance from scripts/programs on workstations/servers that do not belong to the same LAN.

ZennoLab's CapMonster is a Windows software package for recognizing captchas and is a self-hosted alternative to CapMonster.cloud. Depending on your volume, CapMonster (Windows) is even more cost-effective than CapMonster.cloud. CapMonster2 automatically intercepts captchas from local programs and can be configured to receive requests from a local network. This repo is a basic middleware that lets your CapMonster instance receive and solve ReCaptchas from anywhere.

Please be aware that the CapMonster TOS states you "may only use the software for personal purposes." This middleware should not be used for paid recognition services.

Project Structure

capmonster/local/*

server.py runs alongside a single license of ZennoLab's CapMonster 2. client.py includes examples of submitting jobs directly to the DB or API. If you're integrating this into your own applications and trust every client.py with DB rw privileges, fastapi is not necessary. However, integration into 3rd party apps will be difficult/impossible without an API endpoint.

capmonster/fastapi/*

Allows clients to make requests to a custom domain (FastAPI endpoints) that handles ReCaptcha job requests. Includes endpoints that mimic 2Captcha's API as well as verbose pydantic (JSON) response models. /local/server.py feeds queue items to a single instance of CapMonster 2.

Unlike /local/client.py, client requests do not need DB rw access. In other words, clients make requests to a custom domain/FastAPI endpoints versus submitting jobs directly into the DB.

Getting started

Requirements:

Setup & Installation

/local

  • Running instance of CapMonster with Recaptcha2 Sitekey Addon
  • Clone the full repo (Depends on schema from capmonster/fastapi/app/schema)
  • Install requirements pip install -r requirements.txt
  • Copy .env.example to .env and add your settings
  • Run python3 ./server.py

Usage

server.py must be running on the same PC as CapMonster. It listens for new jobs, submits them to CapMonster via captcha_solver.py, and updates the DB with results. captcha_solver.py uses the 2CaptchaAPI to communicate with CapMonster.

client.py is a simple implementation example. client.py can run anywhere so long as it has r/w access to the MongoDB collection server.py monitors.

/fastapi

Usage

Replace any 2Captcha API calls with FastAPI endpoints. Or, intercept applications making 2Captcha requests by editing the machine's host file.

Purging garbage

Purge garbage (old ReCaptcha jobs) in the DB after any minute interval using the remove_garbage flag locally in server or with the FastAPI endpoint /api/v1/garbage.

Production

/local/

Using Windows Task Scheduler, add "Start a Program" Tasks to launch C:\[...]\CapMonster and C:\[...]\local\server.py, triggered by sys startup.

Windows Task Scheduler

/fastapi/

docker-compose.prod.yml file includes restart: unless-stopped.

References

TODO

  • Testing
  • Prod submit job function for client.py
  • Optimize MDB connections/instances
  • FastAPI interface
    • Pydantic models already in use (schema.py)
    • Multiple Authentication/keys/users
  • Proxy username/pass
  • Pull from pool of rotating proxies if no proxy submitted