from Spitzer.config.config import get_data
from Spitzer.command import run
from Spitzer.result import result

category = ['safe']

def exploit(url, nmap):
    print('[*] Checking headers')
    file = get_data('securityheaders')
    
    try:
        output = run(['python3',file,url], capture_output=True)
    except:
        raise
    
    options = ['WARN', 'FAIL']

    if 'FAIL' in output or 'WARN' in output:
        result.add(url, 'security headers', output)
        for line in output.splitlines():
            if any(option in line for option in options):
                #remove last part
                line = line[0:line.index(' ...'):]
                result.add(url, 'Headers' ,line)
    else:
        print('[*] No warnings or errors found')
