Projects STRLCPY LoggerPlusPlus Commits 04e3b9a1
🤬
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/CSVExporterControlPanel.java
    skipped 27 lines
    28 28   handleManualSave();
    29 29   });
    30 30   
    31  - JToggleButton autoExportButton = new JToggleButton("Auto-export as CSV");
    32  - autoExportButton.addActionListener(new AbstractAction() {
     31 + JToggleButton exportButton = new JToggleButton("Auto-export as CSV");
     32 + exportButton.addActionListener(new AbstractAction() {
    33 33   @Override
    34 34   public void actionPerformed(ActionEvent actionEvent) {
    35  - boolean newSelectedState = autoExportButton.isSelected();
    36  - if(!newSelectedState){
    37  - boolean disabled = disableExporter();
    38  - autoExportButton.setSelected(!disabled);
    39  - }else{
    40  - boolean enabled = enableExporter();
    41  - autoExportButton.setSelected(enabled);
    42  - }
     35 + boolean newSelectedState = exportButton.isSelected();
     36 + boolean operationSuccess = exportButton.isSelected() ? enableExporter() : disableExporter();
     37 + exportButton.setSelected(!newSelectedState ^ operationSuccess);
    43 38   }
    44 39   });
    45 40   
    46 41   this.add(new PanelBuilder().build(new JComponent[][]{
    47 42   new JComponent[]{manualSaveButton},
    48  - new JComponent[]{autoExportButton}
     43 + new JComponent[]{exportButton}
    49 44   }, new int[][]{
    50 45   new int[]{1},
    51 46   new int[]{1}
    52 47   }, Alignment.FILL, 1.0, 1.0), BorderLayout.CENTER);
     48 + 
     49 + this.setBorder(BorderFactory.createTitledBorder("CSV Exporter"));
    53 50   }
    54 51   
    55 52   private boolean enableExporter(){
    skipped 70 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporter.java
     1 +package com.nccgroup.loggerplusplus.exports;
     2 + 
     3 +import com.coreyd97.BurpExtenderUtilities.Preferences;
     4 +import com.nccgroup.loggerplusplus.logentry.LogEntry;
     5 +import com.nccgroup.loggerplusplus.logentry.Status;
     6 +import com.nccgroup.loggerplusplus.util.Globals;
     7 +import org.apache.http.HttpHost;
     8 +import org.elasticsearch.action.bulk.BulkItemResponse;
     9 +import org.elasticsearch.action.bulk.BulkRequest;
     10 +import org.elasticsearch.action.bulk.BulkResponse;
     11 +import org.elasticsearch.action.index.IndexAction;
     12 +import org.elasticsearch.action.index.IndexRequest;
     13 +import org.elasticsearch.action.index.IndexRequestBuilder;
     14 +import org.elasticsearch.client.*;
     15 +import org.elasticsearch.client.indices.CreateIndexRequest;
     16 +import org.elasticsearch.client.indices.GetIndexRequest;
     17 +import org.elasticsearch.common.settings.Settings;
     18 + 
     19 +import javax.swing.*;
     20 +import java.io.IOException;
     21 +import java.net.InetAddress;
     22 +import java.util.ArrayList;
     23 +import java.util.concurrent.Executors;
     24 +import java.util.concurrent.ScheduledExecutorService;
     25 +import java.util.concurrent.ScheduledFuture;
     26 +import java.util.concurrent.TimeUnit;
     27 + 
     28 +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
     29 + 
     30 +public class ElasticExporter extends LogExporter {
     31 + 
     32 + RestHighLevelClient httpClient;
     33 + ArrayList<LogEntry> pendingEntries;
     34 + private String indexName;
     35 + private boolean includeReqResp;
     36 + private ScheduledFuture indexTask;
     37 + 
     38 + private final ScheduledExecutorService executorService;
     39 + private final ElasticExporterControlPanel controlPanel;
     40 + 
     41 + protected ElasticExporter(ExportController exportController, Preferences preferences) {
     42 + super(exportController, preferences);
     43 + 
     44 + executorService = Executors.newScheduledThreadPool(1);
     45 + controlPanel = new ElasticExporterControlPanel(this);
     46 + }
     47 + 
     48 + @Override
     49 + void setup() throws Exception {
     50 + InetAddress address = InetAddress.getByName(preferences.getSetting(Globals.PREF_ELASTIC_ADDRESS));
     51 + int port = preferences.getSetting(Globals.PREF_ELASTIC_PORT);
     52 + indexName = preferences.getSetting(Globals.PREF_ELASTIC_INDEX);
     53 + String protocol = preferences.getSetting(Globals.PREF_ELASTIC_PROTOCOL).toString();
     54 + 
     55 + httpClient = new RestHighLevelClient(RestClient.builder(
     56 + new HttpHost(address, port, protocol)));
     57 + 
     58 + createIndices();
     59 + pendingEntries = new ArrayList<>();
     60 + includeReqResp = preferences.getSetting(Globals.PREF_ELASTIC_INCLUDE_REQ_RESP);
     61 + int delay = preferences.getSetting(Globals.PREF_ELASTIC_DELAY);
     62 + indexTask = executorService.scheduleAtFixedRate(this::indexPendingEntries, delay, delay, TimeUnit.SECONDS);
     63 + }
     64 + 
     65 + @Override
     66 + public void exportNewEntry(final LogEntry logEntry) {
     67 + if(logEntry.getStatus() == Status.PROCESSED) {
     68 + pendingEntries.add(logEntry);
     69 + }
     70 + }
     71 + 
     72 + @Override
     73 + public void exportUpdatedEntry(final LogEntry updatedEntry) {
     74 + if(updatedEntry.getStatus() == Status.PROCESSED) {
     75 + pendingEntries.add(updatedEntry);
     76 + }
     77 + }
     78 + 
     79 + @Override
     80 + void shutdown() throws Exception {
     81 + if(this.indexTask != null){
     82 + indexTask.cancel(true);
     83 + }
     84 + this.pendingEntries = null;
     85 + }
     86 + 
     87 + @Override
     88 + public JComponent getExportPanel() {
     89 + return controlPanel;
     90 + }
     91 + 
     92 + private void createIndices() throws IOException {
     93 + GetIndexRequest request = new GetIndexRequest(this.indexName);
     94 + 
     95 + boolean exists = httpClient.indices().exists(request, RequestOptions.DEFAULT);
     96 + 
     97 + if(!exists) {
     98 + CreateIndexRequest _request = new CreateIndexRequest(this.indexName);
     99 + httpClient.indices().create(_request, RequestOptions.DEFAULT);
     100 + }
     101 + }
     102 + 
     103 + public IndexRequest buildIndexRequest(LogEntry logEntry) throws IOException {
     104 + IndexRequest request = new IndexRequest(this.indexName).source(
     105 + jsonBuilder().startObject()
     106 + .field("protocol", logEntry.protocol)
     107 + .field("method", logEntry.method)
     108 + .field("host", logEntry.hostname)
     109 + .field("path", logEntry.url.getPath())
     110 + .field("requesttime", logEntry.formattedRequestTime.equals("") ? null : logEntry.formattedRequestTime)
     111 + .field("responsetime", logEntry.formattedResponseTime.equals("") ? null : logEntry.formattedResponseTime)
     112 + .field("responsedelay", logEntry.requestResponseDelay)
     113 + .field("status", logEntry.responseStatus)
     114 + .field("title", logEntry.title)
     115 + .field("newcookies", logEntry.newCookies)
     116 + .field("sentcookies", logEntry.sentCookies)
     117 + .field("referrer", logEntry.referrerURL)
     118 + .field("requestcontenttype", logEntry.requestContentType)
     119 + .field("requestlength", logEntry.requestLength)
     120 + .field("responselength", logEntry.responseLength)
     121 + .field("requestbody", this.includeReqResp ? new String(logEntry.requestResponse.getRequest()) : "")
     122 + .field("responsebody", this.includeReqResp ? new String(logEntry.requestResponse.getResponse()) : "")
     123 + .endObject()
     124 + );
     125 + return request;
     126 + }
     127 + 
     128 + private void indexPendingEntries(){
     129 + try {
     130 + if (this.pendingEntries.size() == 0) return;
     131 + 
     132 + BulkRequest httpBulkBuilder = new BulkRequest();
     133 + 
     134 + ArrayList<LogEntry> entriesInBulk;
     135 + synchronized (pendingEntries) {
     136 + entriesInBulk = new ArrayList<>(pendingEntries);
     137 + pendingEntries.clear();
     138 + }
     139 + 
     140 + for (LogEntry logEntry : entriesInBulk) {
     141 + try {
     142 + IndexRequest request = buildIndexRequest(logEntry);
     143 + httpBulkBuilder.add(request);
     144 + }catch (IOException e){
     145 + //Could not build index request. Ignore it?
     146 + }
     147 + }
     148 + 
     149 + try {
     150 + BulkResponse bulkResponse = httpClient.bulk(httpBulkBuilder, RequestOptions.DEFAULT);
     151 + if (bulkResponse.hasFailures()) {
     152 + for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
     153 + System.err.println(bulkItemResponse.getFailureMessage());
     154 + }
     155 + }
     156 + } catch (IOException e) {
     157 + e.printStackTrace();
     158 + }
     159 + }catch (Exception e){
     160 + e.printStackTrace();
     161 + }
     162 + }
     163 + 
     164 + public ExportController getExportController() {
     165 + return this.exportController;
     166 + }
     167 +}
     168 + 
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporterConfigDialog.java
     1 +package com.nccgroup.loggerplusplus.exports;
     2 + 
     3 +import com.coreyd97.BurpExtenderUtilities.Alignment;
     4 +import com.coreyd97.BurpExtenderUtilities.ComponentGroup;
     5 +import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
     6 +import com.coreyd97.BurpExtenderUtilities.Preferences;
     7 + 
     8 +import javax.swing.*;
     9 + 
     10 +import java.awt.*;
     11 + 
     12 +import static com.nccgroup.loggerplusplus.util.Globals.*;
     13 +import static com.nccgroup.loggerplusplus.util.Globals.PREF_ELASTIC_INCLUDE_REQ_RESP;
     14 + 
     15 +public class ElasticExporterConfigDialog extends JDialog {
     16 + 
     17 + ElasticExporterConfigDialog(Frame owner, Preferences preferences){
     18 + super(owner, "Elastic Exporter Configuration", true);
     19 + 
     20 + this.setLayout(new BorderLayout());
     21 + PanelBuilder panelBuilder = new PanelBuilder(preferences);
     22 + 
     23 + JTextField addressField = panelBuilder.createPreferenceTextField(PREF_ELASTIC_ADDRESS);
     24 + JSpinner elasticPortSpinner = panelBuilder.createPreferenceSpinner(PREF_ELASTIC_PORT);
     25 + ((SpinnerNumberModel) elasticPortSpinner.getModel()).setMaximum(65535);
     26 + ((SpinnerNumberModel) elasticPortSpinner.getModel()).setMinimum(0);
     27 + elasticPortSpinner.setEditor(new JSpinner.NumberEditor(elasticPortSpinner,"#"));
     28 + 
     29 + JComboBox<Protocol> protocolSelector = new JComboBox<>(Protocol.values());
     30 + protocolSelector.addActionListener(actionEvent -> {
     31 + preferences.setSetting(PREF_ELASTIC_PROTOCOL, protocolSelector.getSelectedItem());
     32 + });
     33 + 
     34 + //TODO Update PanelBuilder to allow labels with custom components
     35 + 
     36 + JTextField clusterNameField = panelBuilder.createPreferenceTextField(PREF_ELASTIC_CLUSTER_NAME);
     37 + JTextField indexNameField = panelBuilder.createPreferenceTextField(PREF_ELASTIC_INDEX);
     38 + JSpinner elasticDelaySpinner = panelBuilder.createPreferenceSpinner(PREF_ELASTIC_DELAY);
     39 + ((SpinnerNumberModel) elasticDelaySpinner.getModel()).setMaximum(99999);
     40 + ((SpinnerNumberModel) elasticDelaySpinner.getModel()).setMinimum(10);
     41 + ((SpinnerNumberModel) elasticDelaySpinner.getModel()).setStepSize(10);
     42 + 
     43 + JToggleButton includeRequestResponse = panelBuilder.createPreferenceCheckBox(PREF_ELASTIC_INCLUDE_REQ_RESP, "Include Request and Response");
     44 + 
     45 + this.add(panelBuilder.build(new JComponent[][]{
     46 + new JComponent[]{new JLabel("Address: "), addressField},
     47 + new JComponent[]{new JLabel("Port: "), elasticPortSpinner},
     48 + new JComponent[]{new JLabel("Protocol: "), protocolSelector},
     49 +// new JComponent[]{new JLabel("Cluster Name: "), clusterNameField},
     50 + new JComponent[]{new JLabel("Index: "), indexNameField},
     51 + new JComponent[]{new JLabel("Upload Delay (Seconds): "), elasticDelaySpinner},
     52 + new JComponent[]{includeRequestResponse, includeRequestResponse},
     53 + }, new int[][]{
     54 + new int[]{0, 1},
     55 + new int[]{0, 1},
     56 + new int[]{0, 1},
     57 + new int[]{0, 1},
     58 + new int[]{0, 1},
     59 + new int[]{0, 1},
     60 + }, Alignment.CENTER, 1.0, 1.0), BorderLayout.CENTER);
     61 + 
     62 + this.pack();
     63 + this.setResizable(true);
     64 + this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
     65 + }
     66 +}
     67 + 
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticExporterControlPanel.java
     1 +package com.nccgroup.loggerplusplus.exports;
     2 + 
     3 +import com.coreyd97.BurpExtenderUtilities.Alignment;
     4 +import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
     5 + 
     6 +import javax.swing.*;
     7 +import java.awt.*;
     8 +import java.awt.event.ActionEvent;
     9 +import java.util.concurrent.ExecutionException;
     10 + 
     11 +public class ElasticExporterControlPanel extends JPanel {
     12 + 
     13 + private final ElasticExporter elasticExporter;
     14 + private static final String STARTING_TEXT = "Starting Elastic Exporter...";
     15 + private static final String STOPPING_TEXT = "Stopping Elastic Exporter...";
     16 + private static final String START_TEXT = "Start Elastic Exporter";
     17 + private static final String STOP_TEXT = "Stop Elastic Exporter";
     18 + 
     19 + public ElasticExporterControlPanel(ElasticExporter elasticExporter){
     20 + this.elasticExporter = elasticExporter;
     21 + this.setLayout(new BorderLayout());
     22 + 
     23 + JButton showConfigDialogButton = new JButton(new AbstractAction("Configure") {
     24 + @Override
     25 + public void actionPerformed(ActionEvent actionEvent) {
     26 + new ElasticExporterConfigDialog(JOptionPane.getFrameForComponent(
     27 + ElasticExporterControlPanel.this), elasticExporter.getPreferences())
     28 + .setVisible(true);
     29 + }
     30 + });
     31 + 
     32 + JToggleButton exportButton = new JToggleButton("Start Elastic Exporter");
     33 + exportButton.addActionListener(new AbstractAction() {
     34 + @Override
     35 + public void actionPerformed(ActionEvent actionEvent) {
     36 + boolean buttonNowActive = exportButton.isSelected();
     37 + exportButton.setEnabled(false);
     38 + exportButton.setText(buttonNowActive ? STARTING_TEXT : STOPPING_TEXT);
     39 + new SwingWorker<Boolean, Void>(){
     40 + Exception exception;
     41 + 
     42 + @Override
     43 + protected Boolean doInBackground() throws Exception {
     44 + boolean success = false;
     45 + try {
     46 + if (exportButton.isSelected()) {
     47 + enableExporter();
     48 + } else {
     49 + disableExporter();
     50 + }
     51 + success = true;
     52 + }catch (Exception e){
     53 + this.exception = e;
     54 + }
     55 + return success;
     56 + }
     57 + 
     58 + @Override
     59 + protected void done() {
     60 + try {
     61 + if(exception != null){
     62 + JOptionPane.showMessageDialog(exportButton, "Could not start elastic exporter: " +
     63 + exception.getMessage(), "Elastic Exporter", JOptionPane.ERROR_MESSAGE);
     64 + }
     65 + Boolean success = get();
     66 + boolean isRunning = buttonNowActive ^ !success;
     67 + exportButton.setSelected(isRunning);
     68 + showConfigDialogButton.setEnabled(!isRunning);
     69 + 
     70 + exportButton.setText(isRunning ? STOP_TEXT : START_TEXT);
     71 + 
     72 + } catch (InterruptedException | ExecutionException e) {
     73 + e.printStackTrace();
     74 + }
     75 + exportButton.setEnabled(true);
     76 + }
     77 + }.execute();
     78 + }
     79 + });
     80 + 
     81 + this.add(new PanelBuilder().build(new JComponent[][]{
     82 + new JComponent[]{showConfigDialogButton},
     83 + new JComponent[]{exportButton}
     84 + }, new int[][]{
     85 + new int[]{1},
     86 + new int[]{1}
     87 + }, Alignment.FILL, 1.0, 1.0), BorderLayout.CENTER);
     88 + 
     89 + 
     90 + this.setBorder(BorderFactory.createTitledBorder("Elastic Exporter"));
     91 + }
     92 + 
     93 + private void enableExporter() throws Exception {
     94 + this.elasticExporter.getExportController().enableExporter(this.elasticExporter);
     95 + }
     96 + 
     97 + private void disableExporter() throws Exception {
     98 + this.elasticExporter.getExportController().disableExporter(this.elasticExporter);
     99 + }
     100 + 
     101 +}
     102 + 
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ElasticSearchLogger.java
    1  -package com.nccgroup.loggerplusplus.exports;
    2  - 
    3  -import com.nccgroup.loggerplusplus.*;
    4  -import com.nccgroup.loggerplusplus.logentry.LogEntry;
    5  -import com.nccgroup.loggerplusplus.logview.processor.LogProcessor;
    6  -import com.nccgroup.loggerplusplus.util.Globals;
    7  -import org.apache.http.HttpHost;
    8  -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
    9  -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
    10  -import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
    11  -import org.elasticsearch.action.bulk.BulkItemResponse;
    12  -import org.elasticsearch.action.bulk.BulkRequest;
    13  -import org.elasticsearch.action.bulk.BulkResponse;
    14  -import org.elasticsearch.action.index.IndexRequest;
    15  -import org.elasticsearch.action.index.IndexRequestBuilder;
    16  -import org.elasticsearch.client.*;
    17  -import org.elasticsearch.common.settings.Settings;
    18  - 
    19  -import java.io.IOException;
    20  -import java.net.InetAddress;
    21  -import java.net.UnknownHostException;
    22  -import java.util.ArrayList;
    23  -import java.util.concurrent.Executors;
    24  -import java.util.concurrent.ScheduledExecutorService;
    25  -import java.util.concurrent.ScheduledFuture;
    26  -import java.util.concurrent.TimeUnit;
    27  - 
    28  -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
    29  - 
    30  -public class ElasticSearchLogger {
    31  - //TODO REIMPLEMENT
    32  -// IndicesAdminClient adminClient;
    33  -// Client client;
    34  -// RestHighLevelClient httpClient;
    35  -// ArrayList<LogEntry> pendingEntries;
    36  -// private InetAddress address;
    37  -// private int port;
    38  -// private String clusterName;
    39  -// private boolean isEnabled;
    40  -// private String indexName;
    41  -// private boolean includeReqResp;
    42  -//
    43  -// private final ScheduledExecutorService executorService;
    44  -// private ScheduledFuture indexTask;
    45  -//
    46  -//
    47  -// public ElasticSearchLogger(LogProcessor logProcessor){
    48  -// this.isEnabled = false;
    49  -// this.indexName = "logger";
    50  -//
    51  -// logProcessor.addLogListener(this);
    52  -// executorService = Executors.newScheduledThreadPool(1);
    53  -// }
    54  -//
    55  -// public void setEnabled(boolean isEnabled) throws UnknownHostException {
    56  -// if(isEnabled){
    57  -// this.address = InetAddress.getByName(LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_ADDRESS));
    58  -// this.port = LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_PORT);
    59  -// this.clusterName = LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_CLUSTER_NAME);
    60  -// this.indexName = LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_INDEX);
    61  -// Settings settings = Settings.builder().put("cluster.name", this.clusterName).build();
    62  -//
    63  -// httpClient = new RestHighLevelClient(RestClient.builder(
    64  -// new HttpHost(this.address, this.port, "http")));
    65  -//
    66  -// createIndices();
    67  -// pendingEntries = new ArrayList<>();
    68  -// includeReqResp = LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_INCLUDE_REQ_RESP);
    69  -// int delay = LoggerPlusPlus.preferences.getSetting(Globals.PREF_ELASTIC_DELAY);
    70  -// indexTask = executorService.scheduleAtFixedRate(() -> indexPendingEntries(), delay, delay, TimeUnit.SECONDS);
    71  -// }else{
    72  -// if(this.indexTask != null){
    73  -// indexTask.cancel(true);
    74  -// }
    75  -// this.pendingEntries = null;
    76  -// this.client = null;
    77  -// this.adminClient = null;
    78  -// }
    79  -// this.isEnabled = isEnabled;
    80  -// }
    81  -//
    82  -// private void createIndices(){
    83  -// GetIndexRequest request = new GetIndexRequest();
    84  -// request.indices(this.indexName);
    85  -//
    86  -// boolean exists = false;
    87  -// try {
    88  -// exists = httpClient.indices().exists(request, RequestOptions.DEFAULT);
    89  -// } catch (IOException e) {
    90  -// e.printStackTrace();
    91  -// }
    92  -//
    93  -// if(!exists) {
    94  -// CreateIndexRequest _request = new CreateIndexRequest(this.indexName);
    95  -//
    96  -// try {
    97  -// CreateIndexResponse createIndexResponse = httpClient.indices().create(_request, RequestOptions.DEFAULT);
    98  -// } catch (IOException e) {
    99  -// e.printStackTrace();
    100  -// }
    101  -// }
    102  -// }
    103  -//
    104  -// public IndexRequest buildIndexRequest(LogEntry logEntry){
    105  -// try{
    106  -// IndexRequestBuilder requestBuilder = client.prepareIndex(this.indexName, "requestresponse")
    107  -// .setSource(
    108  -// jsonBuilder().startObject()
    109  -// .field("protocol", logEntry.protocol)
    110  -// .field("method", logEntry.method)
    111  -// .field("host", logEntry.hostname)
    112  -// .field("path", logEntry.url.getPath())
    113  -// .field("requesttime", logEntry.formattedRequestTime.equals("NA") ? null : logEntry.formattedRequestTime)
    114  -// .field("responsetime", logEntry.formattedResponseTime.equals("NA") ? null : logEntry.formattedResponseTime)
    115  -// .field("responsedelay", logEntry.requestResponseDelay)
    116  -// .field("status", logEntry.responseStatus)
    117  -// .field("title", logEntry.title)
    118  -// .field("newcookies", logEntry.newCookies)
    119  -// .field("sentcookies", logEntry.sentCookies)
    120  -// .field("referrer", logEntry.referrerURL)
    121  -// .field("requestcontenttype", logEntry.requestContentType)
    122  -// .field("requestlength", logEntry.requestLength)
    123  -// .field("responselength", logEntry.responseLength)
    124  -// .field("requestbody", this.includeReqResp ? new String(logEntry.requestResponse.getRequest()) : "")
    125  -// .field("responsebody", this.includeReqResp ? new String(logEntry.requestResponse.getResponse()) : "")
    126  -// .endObject()
    127  -// );
    128  -// return requestBuilder.request();
    129  -// } catch (IOException e) {
    130  -// e.printStackTrace();
    131  -// }
    132  -// return null;
    133  -// }
    134  -//
    135  -// private void addToPending(LogEntry logEntry){
    136  -// if(!this.isEnabled) return;
    137  -// synchronized (pendingEntries) {
    138  -// pendingEntries.add(logEntry);
    139  -// }
    140  -// }
    141  -//
    142  -// private void indexPendingEntries(){
    143  -// if(!this.isEnabled || this.pendingEntries.size() == 0) return;
    144  -//
    145  -// BulkRequest httpBulkBuilder = new BulkRequest();
    146  -//
    147  -// ArrayList<LogEntry> entriesInBulk;
    148  -// synchronized (pendingEntries){
    149  -// entriesInBulk = (ArrayList<LogEntry>) pendingEntries.clone();
    150  -// pendingEntries.clear();
    151  -// }
    152  -//
    153  -// for (LogEntry logEntry : entriesInBulk) {
    154  -// IndexRequest request = buildIndexRequest(logEntry);
    155  -// if(request != null) {
    156  -// httpBulkBuilder.add(request);
    157  -// }else{
    158  -// //Could not buildPreferences index request. Ignore it?
    159  -// }
    160  -// }
    161  -//
    162  -// try {
    163  -// BulkResponse bulkResponse = httpClient.bulk(httpBulkBuilder, RequestOptions.DEFAULT);
    164  -// if(bulkResponse.hasFailures()){
    165  -// for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
    166  -// System.err.println(bulkItemResponse.getFailureMessage());
    167  -// }
    168  -// }
    169  -// } catch (IOException e) {
    170  -// e.printStackTrace();
    171  -// }
    172  -//
    173  -//// if(resp.hasFailures()){
    174  -//// for (BulkItemResponse bulkItemResponse : resp.getItems()) {
    175  -//// System.err.println(bulkItemResponse.getFailureMessage());
    176  -//// }
    177  -//// }
    178  -// }
    179  -//
    180  -// @Override
    181  -// public void onRequestAdded(int modelIndex, LogEntry logEntry, boolean hasResponse) {
    182  -// if(!this.isEnabled) return;
    183  -// if(hasResponse){
    184  -// addToPending(logEntry);
    185  -// }
    186  -// }
    187  -//
    188  -// @Override
    189  -// public void onResponseUpdated(int modelRow, LogEntry existingEntry) {
    190  -// if(!this.isEnabled) return;
    191  -// addToPending(existingEntry);
    192  -// }
    193  -//
    194  -// @Override
    195  -// public void onRequestRemoved(int modelIndex, LogEntry logEntry) {
    196  -//
    197  -// }
    198  -//
    199  -// @Override
    200  -// public void onLogsCleared() {
    201  -//
    202  -// }
    203  -}
    204  - 
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/ExportController.java
    skipped 20 lines
    21 21   this.preferences = preferences;
    22 22   
    23 23   this.exporters = new ArrayList<>();
    24  - this.enabledExporters = Collections.synchronizedList(new ArrayList());
     24 + this.enabledExporters = Collections.synchronizedList(new ArrayList<>());
    25 25   
    26 26   initializeExporters();
    27 27   }
    28 28   
    29 29   private void initializeExporters(){
    30 30   this.exporters.add(new CSVExporter(this, preferences));
     31 + this.exporters.add(new ElasticExporter(this, preferences));
    31 32   }
    32 33   
    33 34   public List<LogExporter> getExporters() {
    skipped 34 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/exports/LogExporter.java
    skipped 45 lines
    46 46   */
    47 47   public abstract JComponent getExportPanel();
    48 48   
     49 + public Preferences getPreferences() {
     50 + return preferences;
     51 + }
    49 52  }
    50 53   
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/preferences/LoggerPreferenceFactory.java
    skipped 16 lines
    17 17  import java.util.*;
    18 18   
    19 19  import static com.nccgroup.loggerplusplus.util.Globals.*;
     20 +import static com.nccgroup.loggerplusplus.util.Globals.Protocol.HTTP;
    20 21   
    21 22  public class LoggerPreferenceFactory extends PreferenceFactory {
    22 23   
    skipped 52 lines
    75 76   prefs.registerSetting(PREF_AUTO_IMPORT_PROXY_HISTORY, Boolean.class, false, Preferences.Visibility.GLOBAL);
    76 77   prefs.registerSetting(PREF_LOG_OTHER_LIVE, Boolean.class, true, Preferences.Visibility.GLOBAL);
    77 78   prefs.registerSetting(PREF_ELASTIC_ADDRESS, String.class, "127.0.0.1", Preferences.Visibility.GLOBAL);
    78  - prefs.registerSetting(PREF_ELASTIC_PORT, Integer.class, 9300, Preferences.Visibility.GLOBAL);
     79 + prefs.registerSetting(PREF_ELASTIC_PORT, Integer.class, 9200, Preferences.Visibility.GLOBAL);
     80 + prefs.registerSetting(PREF_ELASTIC_PROTOCOL, Protocol.class, Protocol.HTTP, Preferences.Visibility.GLOBAL);
    79 81   prefs.registerSetting(PREF_ELASTIC_CLUSTER_NAME, String.class, "elasticsearch", Preferences.Visibility.GLOBAL);
    80 82   prefs.registerSetting(PREF_ELASTIC_INDEX, String.class, "logger", Preferences.Visibility.GLOBAL);
    81 83   prefs.registerSetting(PREF_ELASTIC_DELAY, Integer.class, 120, Preferences.Visibility.GLOBAL);
    skipped 9 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/preferences/PreferencesPanel.java
    skipped 38 lines
    39 39   private final Preferences preferences;
    40 40   
    41 41   private final JToggleButton tglbtnIsEnabled;
    42  - private JToggleButton btnAutoSaveLogs;
    43  - private final JToggleButton esEnabled;
    44 42   private final JLabel esValueChangeWarning = new JLabel("Warning: Changing preferences while running will disable the upload service and clear all pending groups.");
    45 43   
    46 44   
    skipped 88 lines
    135 133   LoggerImport.loadImported(requests);
    136 134   }).setEnabled(true);
    137 135   
    138  - ComponentGroup exportGroup = panelBuilder.createComponentGroup("Export");
     136 + ComponentGroup exportGroup = panelBuilder.createComponentGroup("");
    139 137   preferencesController.getLoggerPlusPlus().getExportController().getExporters().forEach(logExporter -> {
    140 138   exportGroup.addComponent(logExporter.getExportPanel());
    141 139   });
    142 140   
    143  -// exportGroup.addButton("Save log table as CSV", actionEvent -> {
    144  -//// fileLogger.saveLogs(false);
    145  -// });
    146  -// exportGroup.addButton("Save full logs as CSV (slow)", actionEvent -> {
    147  -//// fileLogger.saveLogs(true);
    148  -// });
    149  -// btnAutoSaveLogs = exportGroup.addToggleButton("Autosave as CSV", actionEvent -> {
    150  -//// fileLogger.setAutoSave(!(boolean) preferences.getSetting(PREF_AUTO_SAVE));
    151  -// });
    152  - 
    153  - ComponentGroup elasticPanel = panelBuilder.createComponentGroup("Elastic Search");
    154  - esEnabled = elasticPanel.addToggleButton("Disabled", actionEvent -> {
    155  - JToggleButton thisButton = (JToggleButton) actionEvent.getSource();
    156  - toggleEsEnabledButton(thisButton.isSelected());
    157  - });
    158  - 
    159  - JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
    160  - separator.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
    161  - elasticPanel.addComponent(separator);
    162  - 
    163  - elasticPanel.addPreferenceComponent(PREF_ELASTIC_ADDRESS, "Address: ");
    164  - JSpinner elasticPort = elasticPanel.addPreferenceComponent(PREF_ELASTIC_PORT, "Port: ");
    165  - ((SpinnerNumberModel) elasticPort.getModel()).setMaximum(65535);
    166  - ((SpinnerNumberModel) elasticPort.getModel()).setMinimum(0);
    167  - elasticPort.setEditor(new JSpinner.NumberEditor(elasticPort,"#"));
    168  - 
    169  - elasticPanel.addPreferenceComponent(PREF_ELASTIC_CLUSTER_NAME, "Cluster Name: ");
    170  - elasticPanel.addPreferenceComponent(PREF_ELASTIC_INDEX, "Index: ");
    171  - JSpinner elasticDelay = elasticPanel.addPreferenceComponent(PREF_ELASTIC_DELAY, "Upload Delay (Seconds): ");
    172  - ((SpinnerNumberModel) elasticDelay.getModel()).setMaximum(99999);
    173  - ((SpinnerNumberModel) elasticDelay.getModel()).setMinimum(10);
    174  - ((SpinnerNumberModel) elasticDelay.getModel()).setStepSize(10);
    175  - elasticPanel.addPreferenceComponent(PREF_ELASTIC_INCLUDE_REQ_RESP, "Include Request and Response: ");
    176  - 
    177 141   ComponentGroup otherPanel = panelBuilder.createComponentGroup("Other");
    178 142   JSpinner spnRespTimeout = otherPanel.addPreferenceComponent(PREF_RESPONSE_TIMEOUT, "Response Timeout (Seconds): ");
    179 143   ((SpinnerNumberModel) spnRespTimeout.getModel()).setMinimum(10);
    skipped 71 lines
    251 215   new JPanel[]{statusPanel, statusPanel},
    252 216   new JPanel[]{logFromPanel, importGroup},
    253 217   new JPanel[]{logFromPanel, exportGroup},
    254  - new JPanel[]{elasticPanel, elasticPanel},
    255 218   new JPanel[]{otherPanel, otherPanel},
    256 219   new JPanel[]{colorFilterSharing, savedFilterSharing},
    257 220   new JPanel[]{resetPanel, resetPanel},
    skipped 3 lines
    261 224   this.setViewportView(mainComponent);
    262 225   }
    263 226   
    264  - 
    265  - public void setAutoSaveBtn(boolean enabled){
    266  - btnAutoSaveLogs.setSelected(enabled);
    267  - }
    268 227   
    269 228   private void toggleEnabledButton(boolean isSelected) {
    270 229   tglbtnIsEnabled.setText(APP_NAME + (isSelected ? " is running" : " has been stopped"));
    271 230   tglbtnIsEnabled.setSelected(isSelected);
    272 231   preferences.setSetting(PREF_ENABLED, isSelected);
    273  - }
    274  - 
    275  - private void toggleEsEnabledButton(final boolean isSelected) {
    276  - new Thread(new Runnable() {
    277  - @Override
    278  - public void run() {
    279  - if(isSelected) {
    280  - esEnabled.setText("Starting...");
    281  - }
    282  - try {
    283  -// LoggerPlusPlus.instance.setEsEnabled(isSelected);//TODO FIXME
    284  - esEnabled.setText((isSelected ? "Enabled" : "Disabled"));
    285  - esEnabled.setSelected(isSelected);
    286  - if(isSelected) {
    287  - //TODO Re-Add these.
    288  -// GridBagConstraints gbc = new GridBagConstraints();
    289  -// gbc.gridx = 0;
    290  -// gbc.gridwidth = 3;
    291  -// elasticPanel.add(esValueChangeWarning, gbc);
    292  - }else{
    293  -// elasticPanel.remove(esValueChangeWarning);
    294  - }
    295  - } catch (Exception e) {
    296  - if(isSelected) {
    297  - MoreHelp.showWarningMessage("Elastic Search could not be enabled. Please check your settings.\n" + e.getMessage());
    298  - }
    299  - esEnabled.setText("Connection Failed");
    300  - esEnabled.setSelected(false);
    301  - }
    302  - }
    303  - }).start();
    304 232   }
    305 233  }
    306 234   
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/util/Globals.java
    skipped 41 lines
    42 42   public static final String PREF_AUTO_IMPORT_PROXY_HISTORY = "autoimportproxyhistory";
    43 43   public static final String PREF_ELASTIC_ADDRESS = "esAddress";
    44 44   public static final String PREF_ELASTIC_PORT = "esPort";
     45 + public static final String PREF_ELASTIC_PROTOCOL = "esProto";
    45 46   public static final String PREF_ELASTIC_CLUSTER_NAME = "esClusterName";
    46 47   public static final String PREF_ELASTIC_INDEX = "esIndex";
    47 48   public static final String PREF_ELASTIC_DELAY = "esDelay";
    skipped 4 lines
    52 53   public static final String PREF_AUTO_SCROLL = "autoScroll";
    53 54   public static final String PREF_GREP_HISTORY = "grepHistory";
    54 55   public static final String PREF_PREVIOUS_CSV_FIELDS = "previousCSVFields";
     56 + 
     57 + public enum Protocol {HTTP, HTTPS}
    55 58   
    56 59   public static final String[] VERSION_CHANGE_SETTINGS_TO_RESET = new String[]{
    57 60   PREF_LOG_TABLE_SETTINGS
    skipped 68 lines
Please wait...
Page is in error, reload to recover