Sign inSign up

advancedthreatanalytics/ata_phantomjs

By advancedthreatanalytics

•Updated over 6 years ago

ata_phantomjs is a Node.js based image to obtain screenshot of a given URL

Image
0

5.7K

advancedthreatanalytics/ata_phantomjs repository overview

Codebuild Master Status

⁠ATA PhantomJS Tool

ata_phantomjs is a Node.js app meant to mirror and extend the functionality of the ata_webkit2png⁠ app.

⁠Testing this locally

If you don't understand this, please talk to me so you can understand this.

  1. Setup a SSH tunnel locally --> Runserver
  2. Setup Local Grunt - grunt live works fine
  3. Change your settings.js to point to docker (Assuming docker resolves to your localhost)
  4. Start this container docker-compose up -d --build && docker-compose -f logs
  5. Run test.py which does the same thing as what happens in production

You should see images in the /opt/images directory which will be mapped to your local ./tmp

⁠Setup and Running

Clone the repo and run docker-compose up to build the image and start up the container. Port 8080 is exposed for the API which can be reached here:

http://localhost:8080/⁠

⁠Usage on a local machine

If you set up this container locally, you might want to test reports generation functionality on ata_portal⁠ project.

Issue desciption:

Automated making of page screenshots can fail locally with strange error: "Could not capture image" text inside of output file instead of actual image content. This happens if PhantomJS is not able to open localhost URL from within a container.

How to fix:

Add such string to the bottom to your docker-compose.yml file:

    network_mode: "host"

Then rebuild and rerun a container to allow connection to the host.

⁠API Endpoints

⁠POST /

Capture any given web page as an image.

⁠Payload
{
  url: [URL of page to capture],                                     # required
  dimensions: ['<width>x<height>'|'<width>'|'auto'],                 # required
  wait: [time in seconds to wait before capturing image],            # default: 200 ms
  scale: [scaling, e.g., 1 (for 1x), 2 (for 2x - Retina), etc.],     # default: 1
  elem: [DOM selector ID of element to capture]                      # default: null
}
⁠Example
import requests

url = 'http://localhost:8080/'

resp = requests.post(url=url, json={
  'url': 'https://www.google.com/search?source=hp&q=hp',
  'dimensions': '1200x800',
  'wait': 2,
  'scale': 2,
  'elem': 'hplogo'
})
⁠POST /ping/

Test whether service is up and running.

⁠Example
import requests

url = 'http://localhost:8080/ping'

resp = requests.post(url=url, json={})
resp.json()['status'] == 'ok'

Tag summary

Content type

Image

Digest

Size

396.3 MB

Last updated

over 7 years ago

docker pull advancedthreatanalytics/ata_phantomjs