1 | 1 | | package com.nccgroup.loggerplusplus.exports; |
2 | 2 | | |
3 | 3 | | import com.coreyd97.BurpExtenderUtilities.Alignment; |
| 4 | + | import com.coreyd97.BurpExtenderUtilities.ComponentGroup; |
4 | 5 | | import com.coreyd97.BurpExtenderUtilities.PanelBuilder; |
5 | 6 | | import com.coreyd97.BurpExtenderUtilities.Preferences; |
| 7 | + | import com.nccgroup.loggerplusplus.LoggerPlusPlus; |
| 8 | + | import com.nccgroup.loggerplusplus.filter.logfilter.LogFilter; |
| 9 | + | import com.nccgroup.loggerplusplus.filter.parser.ParseException; |
| 10 | + | import com.nccgroup.loggerplusplus.filterlibrary.FilterLibraryController; |
6 | 11 | | import com.nccgroup.loggerplusplus.logentry.LogEntryField; |
| 12 | + | import com.nccgroup.loggerplusplus.util.Globals; |
7 | 13 | | import com.nccgroup.loggerplusplus.util.MoreHelp; |
| 14 | + | import org.apache.commons.lang3.StringUtils; |
8 | 15 | | |
9 | 16 | | import javax.swing.*; |
10 | 17 | | import java.awt.*; |
11 | 18 | | import java.awt.event.ActionEvent; |
| 19 | + | import java.awt.event.WindowAdapter; |
| 20 | + | import java.awt.event.WindowEvent; |
12 | 21 | | import java.util.List; |
13 | 22 | | import java.util.Objects; |
14 | 23 | | |
| skipped 36 lines |
51 | 60 | | if (ElasticAuthType.ApiKey.equals(authType)) { |
52 | 61 | | authUserLabel.setText("Key ID: "); |
53 | 62 | | authPassLabel.setText("Key Secret: "); |
| 63 | + | userPanel.remove(username); |
| 64 | + | passPanel.remove(password); |
54 | 65 | | userPanel.add(apiKeyId, BorderLayout.CENTER); |
55 | 66 | | passPanel.add(apiKeySecret, BorderLayout.CENTER); |
56 | 67 | | } else if (ElasticAuthType.Basic.equals(authType)) { |
57 | 68 | | authUserLabel.setText("Username: "); |
58 | 69 | | authPassLabel.setText("Password: "); |
| 70 | + | userPanel.remove(apiKeyId); |
| 71 | + | passPanel.remove(apiKeySecret); |
59 | 72 | | userPanel.add(username, BorderLayout.CENTER); |
60 | 73 | | passPanel.add(password, BorderLayout.CENTER); |
61 | 74 | | } |
| skipped 43 lines |
105 | 118 | | } |
106 | 119 | | }); |
107 | 120 | | |
| 121 | + | |
| 122 | + | String projectPreviousFilterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER_PROJECT_PREVIOUS); |
| 123 | + | String filterString = preferences.getSetting(Globals.PREF_ELASTIC_FILTER); |
| 124 | + | if (projectPreviousFilterString != null && !Objects.equals(projectPreviousFilterString, filterString)) { |
| 125 | + | int res = JOptionPane.showConfirmDialog(LoggerPlusPlus.instance.getLoggerFrame(), |
| 126 | + | "Looks like the log filter has been changed since you last used this Burp project.\n" + |
| 127 | + | "Do you want to restore the previous filter used by the project?\n" + |
| 128 | + | "\n" + |
| 129 | + | "Previously used filter: " + projectPreviousFilterString + "\n" + |
| 130 | + | "Current filter: " + filterString, "ElasticSearch Exporter Log Filter", |
| 131 | + | JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); |
| 132 | + | if (res == JOptionPane.YES_OPTION) { |
| 133 | + | preferences.setSetting(PREF_ELASTIC_FILTER, projectPreviousFilterString); |
| 134 | + | } |
| 135 | + | } |
| 136 | + | |
| 137 | + | JTextField filterField = PanelBuilder.createPreferenceTextField(preferences, PREF_ELASTIC_FILTER); |
| 138 | + | filterField.setMinimumSize(new Dimension(600, 0)); |
| 139 | + | |
108 | 140 | | JCheckBox autostartGlobal = PanelBuilder.createPreferenceCheckBox(preferences, PREF_ELASTIC_AUTOSTART_GLOBAL); |
109 | 141 | | JCheckBox autostartProject = PanelBuilder.createPreferenceCheckBox(preferences, PREF_ELASTIC_AUTOSTART_PROJECT); |
110 | 142 | | |
| skipped 8 lines |
119 | 151 | | } |
120 | 152 | | }); |
121 | 153 | | |
| 154 | + | // new JComponent[]{new JLabel("Address: "), addressField}, |
| 155 | + | // new JComponent[]{new JLabel("Port: "), elasticPortSpinner}, |
| 156 | + | // new JComponent[]{new JLabel("Protocol: "), protocolSelector}, |
122 | 157 | | |
123 | | - | this.add(PanelBuilder.build(new JComponent[][]{ |
124 | | - | new JComponent[]{new JLabel("Address: "), addressField}, |
125 | | - | new JComponent[]{new JLabel("Port: "), elasticPortSpinner}, |
126 | | - | new JComponent[]{new JLabel("Protocol: "), protocolSelector}, |
| 158 | + | ComponentGroup connectionGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Connection"); |
| 159 | + | connectionGroup.addComponentWithLabel("Address: ", addressField); |
| 160 | + | connectionGroup.addComponentWithLabel("Port: ", elasticPortSpinner); |
| 161 | + | connectionGroup.addComponentWithLabel("Protocol: ", protocolSelector); |
| 162 | + | connectionGroup.addComponentWithLabel("Index: ", indexNameField); |
| 163 | + | |
| 164 | + | ComponentGroup authGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Authentication"); |
| 165 | + | authGroup.add(PanelBuilder.build(new Component[][]{ |
127 | 166 | | new JComponent[]{new JLabel("Auth: "), elasticAuthType}, |
128 | 167 | | new JComponent[]{authUserLabel, userPanel}, |
129 | | - | new JComponent[]{authPassLabel, passPanel}, |
130 | | - | new JComponent[]{new JLabel("Index: "), indexNameField}, |
| 168 | + | new JComponent[]{authPassLabel, passPanel} |
| 169 | + | }, new int[][]{ |
| 170 | + | new int[]{0, 1}, |
| 171 | + | new int[]{0, 1}, |
| 172 | + | new int[]{0, 1} |
| 173 | + | }, Alignment.FILL, 1, 1)); |
| 174 | + | |
| 175 | + | ComponentGroup miscGroup = new ComponentGroup(ComponentGroup.Orientation.VERTICAL, "Misc"); |
| 176 | + | miscGroup.add(PanelBuilder.build(new Component[][]{ |
131 | 177 | | new JComponent[]{new JLabel("Upload Frequency (Seconds): "), elasticDelaySpinner}, |
132 | 178 | | new JComponent[]{new JLabel("Exported Fields: "), configureFieldsButton}, |
| 179 | + | new JComponent[]{new JLabel("Log Filter: "), filterField}, |
133 | 180 | | new JComponent[]{new JLabel("Autostart Exporter (All Projects): "), autostartGlobal}, |
134 | 181 | | new JComponent[]{new JLabel("Autostart Exporter (This Project): "), autostartProject}, |
135 | 182 | | }, new int[][]{ |
| skipped 1 lines |
137 | 184 | | new int[]{0, 1}, |
138 | 185 | | new int[]{0, 1}, |
139 | 186 | | new int[]{0, 1}, |
140 | | - | new int[]{0, 1}, |
141 | | - | new int[]{0, 1}, |
| 187 | + | new int[]{0, 1} |
| 188 | + | }, Alignment.FILL, 1, 1)); |
| 189 | + | |
| 190 | + | |
| 191 | + | this.add(PanelBuilder.build(new JComponent[][]{ |
| 192 | + | new JComponent[]{connectionGroup}, |
| 193 | + | new JComponent[]{authGroup}, |
| 194 | + | new JComponent[]{miscGroup} |
| 195 | + | }, new int[][]{ |
| 196 | + | new int[]{1}, |
| 197 | + | new int[]{1}, |
| 198 | + | new int[]{1}, |
142 | 199 | | }, Alignment.CENTER, 1.0, 1.0, 5, 5), BorderLayout.CENTER); |
143 | 200 | | |
144 | 201 | | setAuthFields.run(); |
| 202 | + | |
| 203 | + | this.setMinimumSize(new Dimension(600, 200)); |
145 | 204 | | |
146 | 205 | | this.pack(); |
147 | 206 | | this.setResizable(true); |
148 | | - | this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
| 207 | + | this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
| 208 | + | |
| 209 | + | this.addWindowListener(new WindowAdapter() { |
| 210 | + | @Override |
| 211 | + | public void windowClosing(WindowEvent e) { |
| 212 | + | String logFilter = preferences.getSetting(PREF_ELASTIC_FILTER); |
| 213 | + | |
| 214 | + | if (!StringUtils.isBlank(logFilter)) { |
| 215 | + | FilterLibraryController libraryController = elasticExporter.getExportController() |
| 216 | + | .getLoggerPlusPlus().getLibraryController(); |
| 217 | + | try { |
| 218 | + | new LogFilter(libraryController, logFilter); |
| 219 | + | } catch (ParseException ex) { |
| 220 | + | JOptionPane.showMessageDialog(ElasticExporterConfigDialog.this, |
| 221 | + | "Cannot save Elastic Exporter configuration. The chosen log filter is invalid: \n" + |
| 222 | + | ex.getMessage(), "Invalid Elastic Exporter Configuration", JOptionPane.ERROR_MESSAGE); |
| 223 | + | return; |
| 224 | + | } |
| 225 | + | } |
| 226 | + | ElasticExporterConfigDialog.this.dispose(); |
| 227 | + | super.windowClosing(e); |
| 228 | + | } |
| 229 | + | }); |
149 | 230 | | } |
150 | 231 | | } |
151 | 232 | | |