Skip to content

Commit

Permalink
pre-code to self-define api-url.
Browse files Browse the repository at this point in the history
  • Loading branch information
HKirito committed Jun 3, 2024
1 parent a819e30 commit 3cd5519
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions lib/src/main/java/burp/MyBurpExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class MyBurpExtension implements BurpExtension, PropertyChangeListener {
@Getter
MontoyaApi montoyaApi;

// @Getter
// private String apiUrl = "PLEASE_CHANGE_ME_TO_YOUR_MODULE_API_URL";
@Getter
private String apiUrl = "PLEASE_CHANGE_ME_TO_YOUR_MODULE_API_URL";
@Getter
private String apiKey = "PLEASE_CHANGE_ME_OR_YOU_WILL_MAKE_THE_DEVELOPER_SAD";
@Getter
Expand Down Expand Up @@ -59,8 +59,8 @@ public void initialize(MontoyaApi montoyaApi) {
montoyaApi.extension().setName(EXTENSION);
logging.logToOutput("[+] Extension loaded");

// gptClient = new GPTClient(apiUrl, apiKey, model, prompt, logging);
gptClient = new GPTClient(apiKey, model, prompt, logging);
gptClient = new GPTClient(apiUrl, apiKey, model, prompt, logging);
// gptClient = new GPTClient(apiKey, model, prompt, logging);
MyScanCheck scanCheck = new MyScanCheck(gptClient, logging);

Menu menu = MyMenu.createMenu(this);
Expand All @@ -79,20 +79,20 @@ public void addPropertyChangeListener(PropertyChangeListener listener) {
public void propertyChange(PropertyChangeEvent evt) {
}

public void updateSettings(String newApiKey, String newModelId, int newMaxPromptSize, String newPrompt) {
public void updateSettings(String newApiUrl,String newApiKey, String newModelId, int newMaxPromptSize, String newPrompt) {
String[] newValues = {
newApiKey, newModelId, Integer.toString(newMaxPromptSize), newPrompt };
String[] oldValues = {
this.apiKey, this.model, Integer.toString(this.maxPromptSize), this.prompt };

// this.apiUrl = newApiUrl;
this.apiUrl = newApiUrl;
this.apiKey = newApiKey;
this.model = newModelId;
this.maxPromptSize = newMaxPromptSize;
this.prompt = newPrompt;

// this.gptClient.updateSettings(newApiUrl, newApiKey, newModelId, newMaxPromptSize, newPrompt);
this.gptClient.updateSettings(newApiKey, newModelId, newMaxPromptSize, newPrompt);
this.gptClient.updateSettings(newApiUrl, newApiKey, newModelId, newMaxPromptSize, newPrompt);
// this.gptClient.updateSettings(newApiKey, newModelId, newMaxPromptSize, newPrompt);

propertyChangeSupport.firePropertyChange("settingsChanged", oldValues, newValues);

Expand Down
22 changes: 11 additions & 11 deletions lib/src/main/java/burpgpt/gui/views/SettingsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SettingsView extends JPanel implements PropertyChangeListener {

private MyBurpExtension myBurpExtension;

// private JTextField apiUrlField;
private JTextField apiUrlField;
private JTextField apiKeyField;
private JComboBox<String> modelIdComboBox;
private JSpinner maxPromptSizeField;
Expand All @@ -53,7 +53,7 @@ public SettingsView(MyBurpExtension myBurpExtension) {

private void initComponents() {
createApiKeyField(0);
// createApiUrlField(1);
createApiUrlField(1);
createModelIdComboBox(2);
createMaxPromptSizeField(3);
createPromptField(4);
Expand All @@ -67,12 +67,12 @@ private void createApiKeyField(int y) {
add(apiKeyLabel, createGridBagConstraints(0, y));
add(apiKeyField, createGridBagConstraints(1, y));
}
// private void createApiUrlField(int y) {
// JLabel apiUrlLabel = new JLabel("API url:");
// apiUrlField = new JTextField(myBurpExtension.getApiUrl(), 20);
// add(apiUrlLabel, createGridBagConstraints(0, y));
// add(apiUrlField, createGridBagConstraints(1, y));
// }
private void createApiUrlField(int y) {
JLabel apiUrlLabel = new JLabel("API url:");
apiUrlField = new JTextField(myBurpExtension.getApiUrl(), 20);
add(apiUrlLabel, createGridBagConstraints(0, y));
add(apiUrlField, createGridBagConstraints(1, y));
}

private void createModelIdComboBox(int y) {
JLabel modelIdLabel = new JLabel("Model:");
Expand Down Expand Up @@ -119,7 +119,7 @@ private void createApplyButton(int y) {

private void applySettings() {
String newApiKey = apiKeyField.getText().trim();
// String newApiUrl = apiUrlField.getText().trim();
String newApiUrl = apiUrlField.getText().trim();
String newModelId = (String) modelIdComboBox.getSelectedItem();
int newMaxPromptSize = (int) maxPromptSizeField.getValue();
String newPromptText = promptField.getText().trim();
Expand All @@ -131,8 +131,8 @@ private void applySettings() {
return;
}

// myBurpExtension.updateSettings(newApiUrl, newApiKey, newModelId, newMaxPromptSize, newPromptText);
myBurpExtension.updateSettings(newApiKey, newModelId, newMaxPromptSize, newPromptText);
myBurpExtension.updateSettings(newApiUrl, newApiKey, newModelId, newMaxPromptSize, newPromptText);
// myBurpExtension.updateSettings(newApiKey, newModelId, newMaxPromptSize, newPromptText);

if (onApplyButtonClickListener != null) {
onApplyButtonClickListener.onApplyButtonClick();
Expand Down
20 changes: 10 additions & 10 deletions lib/src/main/java/burpgpt/http/GPTClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class GPTClient {

// private String apiUrl;
private String apiUrl;
private String apiKey;
private String model;
private int maxPromptSize;
Expand All @@ -34,8 +34,8 @@ public class GPTClient {
private final Gson gson;
private Logging logging;

public GPTClient(String apiKey, String model, String prompt, Logging logging) {
// this.apiUrl = apiUrl;
public GPTClient(String apiUrl, String apiKey, String model, String prompt, Logging logging) {
this.apiUrl = apiUrl;
this.apiKey = apiKey;
this.model = model;
this.prompt = prompt;
Expand All @@ -48,12 +48,12 @@ public GPTClient(String apiKey, String model, String prompt, Logging logging) {
gson = new Gson();
}

public void updateSettings(String newApiKey, String newModelId, int newMaxPromptSize, String newPrompt) {
public void updateSettings(String newApiUrl, String newApiKey, String newModelId, int newMaxPromptSize, String newPrompt) {
this.apiUrl = newApiUrl;
this.apiKey = newApiKey;
this.model = newModelId;
this.maxPromptSize = newMaxPromptSize;
this.prompt = newPrompt;
// this.apiUrl = newApiUrl;
}

public Pair<GPTRequest, GPTResponse> identifyVulnerabilities(HttpRequestResponse selectedMessage) throws IOException {
Expand Down Expand Up @@ -83,20 +83,20 @@ public Pair<GPTRequest, GPTResponse> identifyVulnerabilities(HttpRequestResponse
// TODO: Add a field to specify the maxTokens value
try {
GPTRequest gptRequest = new GPTRequest(selectedRequest, selectedResponse, model, 1, maxPromptSize);
// GPTResponse gptResponse = getCompletions(gptRequest,apiUrl, apiKey, model, prompt);
GPTResponse gptResponse = getCompletions(gptRequest, apiKey, model, prompt);
GPTResponse gptResponse = getCompletions(gptRequest,apiUrl, apiKey, model, prompt);
// GPTResponse gptResponse = getCompletions(gptRequest, apiKey, model, prompt);
return Pair.of(gptRequest, gptResponse);
} catch (IOException e) {
throw e;
}
}

private GPTResponse getCompletions(GPTRequest gptRequest, String apiKey, String model, String prompt)
private GPTResponse getCompletions(GPTRequest gptRequest,String apiUrl, String apiKey, String model, String prompt)
throws IOException {
gptRequest.setPrompt(prompt);

// String apiEndpoint = apiUrl;
String apiEndpoint = "https://api.openai.com/v1/completions";
String apiEndpoint = apiUrl;
// String apiEndpoint = "https://api.openai.com/v1/completions";
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
JsonObject jsonObject = new JsonObject();

Expand Down

0 comments on commit 3cd5519

Please sign in to comment.