Skip to content

Commit

Permalink
Merge branch 'master' into feature/run_tests_through_kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Jan 21, 2025
2 parents f6a8ff4 + d531838 commit bcf7528
Show file tree
Hide file tree
Showing 37 changed files with 1,144 additions and 721 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ public static Bson prepareTestingRunResultCustomSorting(String sortKey, int sort
Bson sortStage = null;
if (TestingRunIssues.KEY_SEVERITY.equals(sortKey)) {
sortStage = (sortOrder == 1) ?
Aggregates.sort(Sorts.ascending("severityValue", TestingRunResult.END_TIMESTAMP)) :
Aggregates.sort(Sorts.descending("severityValue", TestingRunResult.END_TIMESTAMP));
Aggregates.sort(Sorts.ascending("severityValue")) :
Aggregates.sort(Sorts.descending("severityValue"));
} else if ("time".equals(sortKey)) {
sortStage = (sortOrder == 1) ?
Aggregates.sort(Sorts.ascending(TestingRunResult.END_TIMESTAMP)) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,47 @@ public SuspectSampleDataAction() {
}

public String fetchSampleData() {
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl()));
HttpPost post = new HttpPost(
String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl()));
post.addHeader("Authorization", "Bearer " + this.getApiToken());
post.addHeader("Content-Type", "application/json");

System.out.print("API Token: " + this.getApiToken());
Map<String, Object> filter = new HashMap<>();
if (this.ips != null && !this.ips.isEmpty()) {
filter.put("ips", this.ips);
}

if (this.urls != null && !this.urls.isEmpty()) {
filter.put("urls", this.urls);
}

Map<String, Integer> time_range = new HashMap<>();
if (this.startTimestamp > 0) {
time_range.put("start", this.startTimestamp);
}

if (this.endTimestamp > 0) {
time_range.put("end", this.endTimestamp);
}

filter.put("detected_at_time_range", time_range);

Map<String, Object> body = new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
put("sort", sort);
put("filter", filter);
}
};
String msg = objectMapper.valueToTree(body).toString();

System.out.println("Request body for list malicious requests" + msg);

StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);

try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<ListMaliciousRequestsResponse>toProtoMessage(
ListMaliciousRequestsResponse.class, responseBody)
.ifPresent(
Expand All @@ -83,6 +100,7 @@ public String fetchSampleData() {
smr.getCountry(),
smr.getDetectedAt()))
.collect(Collectors.toList());
this.total = m.getTotal();
});
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -100,8 +118,6 @@ public String fetchFilters() {
try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<FetchAlertFiltersResponse>toProtoMessage(
FetchAlertFiltersResponse.class, responseBody)
.ifPresent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ public ThreatActorAction() {
}

public String getActorsCountPerCounty() {
HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl()));
HttpGet get =
new HttpGet(
String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl()));
get.addHeader("Authorization", "Bearer " + this.getApiToken());
get.addHeader("Content-Type", "application/json");

try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<ThreatActorByCountryResponse>toProtoMessage(
ThreatActorByCountryResponse.class, responseBody)
ThreatActorByCountryResponse.class, responseBody)
.ifPresent(
m -> {
this.actorsCountPerCountry = m.getCountriesList().stream()
.map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount()))
.collect(Collectors.toList());
this.actorsCountPerCountry =
m.getCountriesList().stream()
.map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount()))
.collect(Collectors.toList());
});
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -64,42 +65,45 @@ public String getActorsCountPerCounty() {
}

public String fetchThreatActors() {
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl()));
HttpPost post =
new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl()));
post.addHeader("Authorization", "Bearer " + this.getApiToken());
post.addHeader("Content-Type", "application/json");

Map<String, Object> body = new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
}
};
Map<String, Object> body =
new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
put("sort", sort);
}
};
String msg = objectMapper.valueToTree(body).toString();

System.out.println("Request body for list threat actors" + msg);

StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);

try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<ListThreatActorResponse>toProtoMessage(
ListThreatActorResponse.class, responseBody)
ListThreatActorResponse.class, responseBody)
.ifPresent(
m -> {
this.actors = m.getActorsList().stream()
.map(
smr -> new DashboardThreatActor(
smr.getId(),
smr.getLatestApiEndpoint(),
smr.getLatestApiIp(),
URLMethods.Method.fromString(smr.getLatestApiMethod()),
smr.getDiscoveredAt(),
smr.getCountry()))
.collect(Collectors.toList());
this.actors =
m.getActorsList().stream()
.map(
smr ->
new DashboardThreatActor(
smr.getId(),
smr.getLatestApiEndpoint(),
smr.getLatestApiIp(),
URLMethods.Method.fromString(smr.getLatestApiMethod()),
smr.getDiscoveredAt(),
smr.getCountry()))
.collect(Collectors.toList());

this.total = m.getTotal();
});
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,26 @@ public ThreatApiAction() {
}

public String fetchThreatCategoryCount() {
HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl()));
HttpGet get =
new HttpGet(
String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl()));
get.addHeader("Authorization", "Bearer " + this.getApiToken());
get.addHeader("Content-Type", "application/json");

try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<ThreatCategoryWiseCountResponse>toProtoMessage(
ThreatCategoryWiseCountResponse.class, responseBody)
ThreatCategoryWiseCountResponse.class, responseBody)
.ifPresent(
m -> {
this.categoryCounts = m.getCategoryWiseCountsList().stream()
.map(
smr -> new ThreatCategoryCount(
smr.getCategory(), smr.getSubCategory(), smr.getCount()))
.collect(Collectors.toList());
this.categoryCounts =
m.getCategoryWiseCountsList().stream()
.map(
smr ->
new ThreatCategoryCount(
smr.getCategory(), smr.getSubCategory(), smr.getCount()))
.collect(Collectors.toList());
});
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -66,41 +68,44 @@ public String fetchThreatCategoryCount() {
}

public String fetchThreatApis() {
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl()));
HttpPost post =
new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl()));
post.addHeader("Authorization", "Bearer " + this.getApiToken());
post.addHeader("Content-Type", "application/json");

Map<String, Object> body = new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
}
};
Map<String, Object> body =
new HashMap<String, Object>() {
{
put("skip", skip);
put("limit", LIMIT);
put("sort", sort);
}
};
String msg = objectMapper.valueToTree(body).toString();

System.out.println("Request body for list threat actors" + msg);

StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
post.setEntity(requestEntity);

try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
String responseBody = EntityUtils.toString(resp.getEntity());

System.out.println(responseBody);

ProtoMessageUtils.<ListThreatApiResponse>toProtoMessage(
ListThreatApiResponse.class, responseBody)
ListThreatApiResponse.class, responseBody)
.ifPresent(
m -> {
this.apis = m.getApisList().stream()
.map(
smr -> new DashboardThreatApi(
smr.getEndpoint(),
URLMethods.Method.fromString(smr.getMethod()),
smr.getActorsCount(),
smr.getRequestsCount(),
smr.getDiscoveredAt()))
.collect(Collectors.toList());
this.apis =
m.getApisList().stream()
.map(
smr ->
new DashboardThreatApi(
smr.getEndpoint(),
URLMethods.Method.fromString(smr.getMethod()),
smr.getActorsCount(),
smr.getRequestsCount(),
smr.getDiscoveredAt()))
.collect(Collectors.toList());

this.total = m.getTotal();
});
} catch (Exception e) {
e.printStackTrace();
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/src/main/java/com/akto/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ public static BasicDBObject extractJsonResponse(String message, boolean isReques
public static float calculateRiskValueForSeverity(String severity){
float riskScore = 0 ;
switch (severity) {
case "CRITICAL":
case "HIGH":
riskScore += 100;
break;
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7926,4 +7926,4 @@

</package>

</struts>
</struts>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import api from '../../../../signup/api';
import func from '@/util/func';
import SemiCircleProgress from '../../shared/SemiCircleProgress';
import { usePolling } from '../../../../main/PollingProvider';
import { debounce, get } from 'lodash';
import { debounce } from 'lodash';
import LocalStore from '../../../../main/LocalStorageStore';
import homeFunctions from '../../../../dashboard/pages/home/module';

Expand Down
Loading

0 comments on commit bcf7528

Please sign in to comment.