package com.aktaion.shell;

import com.aktaion.ml.weka.randomforest.ClassLabel;
import com.aktaion.ml.weka.randomforest.RandomForestLogic;
import com.aktaion.ml.weka.randomforest.WekaUtilities;
import scala.Option;

import java.util.Scanner;

public class UserInteractionLogic {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("*************************");
        System.out.println("*************************");
        System.out.println("** Aktaion Version 0.1 **");
        System.out.println("*************************");
        System.out.println("*************************");
        System.out.println("1: Analyze Bro HTTP Sample");
        System.out.println("2: Analyze PCAP Sample (Bro must be installed)");
        System.out.println("3: Demo (Unix/OS X System)");
        System.out.print("Enter Execution Choice [1-3]: ");

        int userChoice = scanner.nextInt();

        if (userChoice == 1) {
            System.out.print("Specify Input Path: ");
            String fileInputPath = scanner.next();
            System.out.print("Specify Output Path: ");
            String fileOutputPath = scanner.next();
        } else if (userChoice == 2) {
            System.out.print("Specify Input PCAP Path: ");
            String fileInputPath = scanner.next();
            //CommandLineUtils.executeBroSimpleDebugLogic(fileInputPath);
        } else if (userChoice == 3) {

            //does not work on windows determines where the path to the Jar is
            String dataPath = CommandLineUtils.tryToFindPathToDataInSourceCode(4);

            /**
             * Step 1: (Only Need to Perform Once)
             *
             * Train a model by scoring a whole directory of files
             * in this case we have extracts from 300+ exploit samples
             * with a .webgateway extension
             */
            String trainDirectory = dataPath + "proxyData/exploitData/";
            String trainDataOutFileName = dataPath + "demoData/demoExploitData.arff";
            String saveModelFileName = dataPath + "demoData/model.test";

            WekaUtilities.extractDirectoryToWekaFormat(trainDirectory,
                    trainDataOutFileName,
                    ".webgateway",
                    ClassLabel.EXPLOIT(), 5);
            RandomForestLogic.trainWekaRandomForest(trainDataOutFileName, saveModelFileName, 10, 100);


            /**
             * Step 2: get a PCAP file to score and convert it to bro logs
             */
            String demoInputFileName = dataPath + "demoData/demoExploitPcap.pcap"; //change to whatever pcap we want to score
            String extractedFile = CommandLineUtils.extractBroFilesFromPcap(demoInputFileName);

            /**
             *  Step 3a: Score Malicious File Extract the IOCs from the scored file
             */
            Option<RandomForestLogic.IocsExtracted> output = RandomForestLogic.scoreBroHttpFile(extractedFile, saveModelFileName, 5);

            /**
             * Step 3b: Score Benign Traffic File
             */
              //  RandomForestLogic.scoreBroHttpFile(dataPath + "demoData/BENIGNEATOhttp.log", saveModelFileName,5);
                //todo train the model on benign traffic


            /**
             *  Step 4: Pass the ioc data to an active defense script for
             *  automated Group Policy Object generation in Active Directory
             *  (see https://technet.microsoft.com/en-us/library/hh147307(v=ws.10).aspx for an intro)
             */

                PythonCommandLineLogic.passIocsToActiveDefenseScript(output,4);


        }
    }
}

@@ -269,24 +269,227 @@
 ionLogic %7B%0A%0A
+    private static void pressAnyKeyToContinue() %7B%0A        System.out.println(%22Press any key to continue...%22);%0A        try %7B%0A            System.in.read();%0A        %7D catch (Exception e) %7B%0A        %7D%0A    %7D%0A%0A
     public s
@@ -1552,82 +1552,8 @@
 ();%0A
-            //CommandLineUtils.executeBroSimpleDebugLogic(fileInputPath);%0A
     
@@ -1586,17 +1586,16 @@
 == 3) %7B%0A
-%0A
         
@@ -2559,16 +2559,52 @@
 , 100);%0A
+            pressAnyKeyToContinue();
 %0A%0A      
@@ -2925,16 +2925,53 @@
 leName);
+%0A            pressAnyKeyToContinue();
 %0A%0A      
@@ -3213,16 +3213,53 @@
 ame, 5);
+%0A            pressAnyKeyToContinue();
 %0A%0A      
@@ -3346,18 +3346,16 @@
         
-  
 //  Rand
@@ -3461,20 +3461,16 @@
         
-    
 //todo t
@@ -3503,17 +3503,16 @@
 raffic%0A%0A
-%0A
         
@@ -3788,21 +3788,16 @@
      */%0A
-%0A    
         
@@ -3864,14 +3864,13 @@
 put,
+ 
 4);%0A
-%0A%0A
     
@@ -3881,10 +3881,12 @@
 %7D%0A    %7D%0A
+%0A%0A
 %7D%0A

Break up demo into steps.