File size: 2,131 Bytes
85c5f42
 
 
7ad0570
 
 
 
85c5f42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9cf047
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85c5f42
 
0bac7c0
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
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, render_template, request, jsonify
from form_filler import FormFiller
import threading
import os

# Specify the cache directory as an environment variable
os.environ['CACHE_FOLDER'] = os.path.join(os.getcwd(), '.cache')

app = Flask(__name__)
form_filler = FormFiller()

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/start', methods=['POST'])
def start_form_filling():
    url = request.json['url']
    iterations = int(request.json['iterations'])
    
    def run_form_filler():
        form_filler.fill_form_in_parallel(url, iterations)
    
    form_filler.total_iterations = iterations
    form_filler.iterations_left = iterations
    form_filler.responses_sent = 0
    form_filler.errors = 0
    form_filler.environment_status = []
    
    thread = threading.Thread(target=run_form_filler)
    thread.start()
    
    return jsonify({"message": "Form filling started"})

@app.route('/stop', methods=['POST'])
def stop_form_filling():
    form_filler.stop()
    return jsonify({"message": "Form filling stopped"})

@app.route('/status', methods=['GET'])
def get_status():
    with form_filler.lock:
        if form_filler.responses_sent == 0 and form_filler.errors == 0 and form_filler.iterations_left == form_filler.total_iterations:
            # This condition checks if everything is still initializing
            return jsonify({
                "total_iterations": form_filler.total_iterations,
                "responses_sent": None,  # Return None instead of 0 to indicate uninitialized
                "errors": None,
                "iterations_left": form_filler.iterations_left,
                "environment_status": None
            })
        else:
            return jsonify({
                "total_iterations": form_filler.total_iterations,
                "responses_sent": form_filler.responses_sent,
                "errors": form_filler.errors,
                "iterations_left": form_filler.iterations_left,
                "environment_status": list(form_filler.environment_status)
            })


if __name__ == '__main__':
    app.run()