import logging
from time import sleep
from sniffer import Sniffer
from flask import Flask, request, jsonify

app = Flask(__name__)

sniffers = {}
INTERFACE = 'wlan0'  # Capturing interface, should be same for all sniffers


level = logging.DEBUG
logger = logging.getLogger('sniffer')
logger.setLevel(level)
FORMAT = '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
logging.basicConfig(format=FORMAT)


@app.route('/start', methods=['POST'])
def start():
    '''
    Take the victim's IP and the hostname of the endpoint that is being
    attacked and set a sniffer on all TLS connections between them.

    Arguments:
    source_ip -- the local network IP of the victim, e.g. 192.168.1.66
    destination_host -- the hostname of the attacked endpoint, e.g. dimkarakostas.com

    Status code for the request:
            409: a sniffer on the same source_ip and destination host already exists
            400: parameters were not properly set
            201: a new sniffer for those arguments has been created
    '''
    data = request.get_json()
    source_ip = data['source_ip']
    destination_host = data['destination_host']

    # Check if a same sniffer already exists
    if (source_ip, destination_host) in sniffers:
        err = '409 - Sniffer (source_ip: {}, destination_host: {}) already exists.'.format(source_ip, destination_host)
        logger.warning(err)
        return str(err), 409

    params = {'source_ip': source_ip,
              'destination_host': destination_host,
              'interface': INTERFACE}

    # Check if parameters are invalid
    try:
        sniffer = Sniffer(params)
    except AssertionError, err:
        logger.warning(err)
        return str(err), 400

    sniffers[(source_ip, destination_host)] = sniffer

    # Start the new sniffer thread and block until it has come to life
    sniffer.start()
    while not sniffer.is_alive():
        sleep(0.01)
    msg = 'Sniffer (source_ip: {}, destination_host: {}) is alive.'.format(source_ip, destination_host)
    logger.debug(msg)

    return msg, 201


@app.route('/get_capture')
def get_capture():
    return 'Not implemented', 200


@app.route('/delete_sniffer')
def delete_sniffer():
    return 'Not implemented', 200


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

@@ -2057,35 +2057,8 @@
 1%0A%0A%0A
-@app.route('/get_capture')%0A
 def 
@@ -2131,69 +2131,1405 @@
 lete
-_sniffer')%0Adef delete_sniffer():%0A    return 'Not implemented'
+', methods=%5B'POST'%5D)%0Adef delete():%0A    '''%0A    Stop a sniffer from capturing, wait for the thread to finish and delete the sniffer.%0A%0A    Arguments:%0A    source_ip -- the local network IP of the victim, e.g. 192.168.1.66%0A    destination_host -- the hostname of the attacked endpoint, e.g. dimkarakostas.com%0A%0A    Status code for the request:%0A            404: no sniffer exists with the given parameters%0A            200: sniffer was deleted successfully%0A    '''%0A    data = request.get_json()%0A    source_ip = data%5B'source_ip'%5D%0A    destination_host = data%5B'destination_host'%5D%0A%0A    logger.debug('Deleting sniffer (source_ip : %7B%7D, destination_host: %7B%7D)...'.format(source_ip, destination_host))%0A%0A    # Get the sniffer object and its source_ip and destination_host, if exists%0A    try:%0A        sniffer = sniffers%5B(source_ip, destination_host)%5D%0A    except KeyError:%0A        msg = '(get_sniff) 404 Not found: Sniffer (source_ip : %7B%7D, destination_host: %7B%7D)'.format(source_ip, destination_host)%0A        logger.warning(msg)%0A        return msg, 404%0A%0A    # Stop the sniffer capture and wait for the thread to join%0A    sniffer.stop()%0A    sniffer.join()%0A%0A    # Delete the sniffer entries from both dictionaries%0A    del sniffers%5B(source_ip, destination_host)%5D%0A%0A    msg = '(get_sniff) Sniffer (source_ip : %7B%7D, destination_host: %7B%7D) was deleted.'.format(source_ip, destination_host)%0A    logger.debug(msg)%0A%0A    return msg
 , 20

Implement delete