📦 EqualifyEverything / scan

📄 axe.py · 54 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54import json
import subprocess
from flask import Flask, request, jsonify

with open('scans/axe.json') as f:
    header_mapping = json.load(f)

app = Flask(__name__)

def process_response(response_dict, mapping):
    processed = {}
    for key, value in response_dict.items():
        if isinstance(value, dict):
            for inner_key, inner_value in value.items():
                combined_key = f"{key}.{inner_key}"
                new_key = mapping.get(combined_key)
                if new_key:
                    processed[new_key] = inner_value
                else:
                    processed[combined_key] = inner_value
        else:
            new_key = mapping.get(key)
            if new_key:
                processed[new_key] = value
            else:
                processed[key] = value
    return processed


@app.route('/axe')
def axe_scan():
    url = request.args.get('url')
    cmd = f'axe {url} --chromedriver-path /usr/local/bin/chromedriver --chrome-options="no-sandbox" --stdout'
    output = subprocess.check_output(cmd, shell=True)
    response = json.loads(output.decode('utf-8'))

    # Check if the response is a list and get the first item
    if isinstance(response, list) and len(response) > 0:
        response = response[0]
 # with open('../maps/axe.json') as f:
    # Define header mapping
    with open('scans/axe.json') as f:
        header_mapping = json.load(f)

    # Process response
    transformed_response = process_response(response, header_mapping)

    # Return transformed response
    return jsonify(transformed_response)


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=8083)