Skip to content

Commit

Permalink
Merge pull request #14 from izzatbey:bug-fixing
Browse files Browse the repository at this point in the history
Fix Bug in getReport
  • Loading branch information
izzatbey authored Feb 19, 2025
2 parents 69630b1 + 326e68a commit efbf3ba
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 67 deletions.
32 changes: 18 additions & 14 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ReportController extends Controller
*/
public function getReport(Request $request): JsonResponse
{
Log::info('Request' . $request);
$rawJson = $request->getContent();
$event = json_decode($rawJson, true);

Expand Down Expand Up @@ -66,6 +67,7 @@ public function getReport(Request $request): JsonResponse
Log::error('Invalid snort priority', ['priority' => $event['snort_priority']]);
return response()->json(['error' => 'Invalid snort priority'], 400);
}
Log::info('Priority:', ['priority' => $priority]);

$classification = Classification::firstOrCreate(
[
Expand Down Expand Up @@ -495,30 +497,32 @@ public function destroy($id)
private function createOrUpdateIdentity($ipAddress): Identity
{
$lookupUrl = env('LOOKUP_URL');
if (!empty($ipAddress)) {
$response = Http::get($lookupUrl, ['ip' => $ipAddress]);

if ($response->successful()) {
$data = $response->json();
$country = $data['region']['country']['names']['en'] ?? 'Unknown';
} else {
$country = 'Unknown';
$country = 'Undefined';

if (!empty($ipAddress)) {
if (!empty($lookupUrl)) {
$response = Http::get($lookupUrl, ['ip' => $ipAddress]);
Log::info('Lookup response:', ['response' => $response]);
if ($response->successful()) {
$data = $response->json();
// If country name is empty, default to "Undefined"
$countryLookup = $data['region']['country']['names']['en'] ?? '';
$country = empty($countryLookup) ? 'Undefined' : $countryLookup;
}
}

$identity = Identity::firstOrCreate(
['ip_address' => $ipAddress],
[
'ip_address' => $ipAddress,
'country_name' => $country,
],
[
'ip_address' => $ipAddress,
'ip_address' => $ipAddress,
'country_name' => $country,
]
);

return $identity;
}

return $identity;
throw new \InvalidArgumentException("IP address is required");
}
}

46 changes: 23 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ services:
- pgsql
- redis

report-api:
image: ghcr.io/mata-elang-stable/report-api-services:latest
build: .
depends_on:
- pgsql
- web
- redis
- chromium
env_file:
- .env
volumes:
- report_data:/var/www/html/
deploy:
restart_policy:
condition: on-failure
delay: 15s
mode: replicated
replicas: 1
resources:
limits:
cpus: "0.5"
memory: 1G
# report-api:
# image: ghcr.io/mata-elang-stable/report-api-services:latest
# build: .
# depends_on:
# - pgsql
# - web
# - redis
# - chromium
# env_file:
# - .env
# volumes:
# - report_data:/var/www/html/
# deploy:
# restart_policy:
# condition: on-failure
# delay: 15s
# mode: replicated
# replicas: 1
# resources:
# limits:
# cpus: "0.5"
# memory: 1G

web:
image: nginx:alpine
restart: unless-stopped
Expand Down
11 changes: 6 additions & 5 deletions resources/views/reports/alert_report.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>
<div class="header">
{{-- <img src="{{ asset('images/logo.png') }}" alt="Logo Mata Elang" class="logo"> --}}
<img src="{{ asset('images/logo.png') }}" alt="Logo Mata Elang" class="logo">
{{-- <img src="https://drive.fadhilyori.my.id/s/yBQ7YCercsaHNEq/download/mata-elang-csrg-logo.png" alt="Logo" class="logo"> --}}
<div class="title-section">
<h1 class="title">Mata Elang Report</h1>
Expand All @@ -15,19 +15,20 @@
</div>
</div>
<hr/>

<div class="grid-container">
<div class="top-row">
<div class="box total-events-box">
<h3>Total Events</h3>
<h3 class="card-label">Total Events</h3>
<p class="event-count">{{ $data['totalEvents'] }}</p>
</div>
<div class="box priority-box">
<h3>Top Priority</h3>
<div class="priority-list">
@foreach($data['priorityCounts'] as $priority => $count)
@foreach(['Critical', 'High', 'Medium', 'Low'] as $priority)
<div class="priority-item">
<span class="priority-label {{ strtolower($priority) }}">{{ $priority }}</span>
<span class="priority-count">{{ $count }}</span>
<span class="priority-count">{{ $data['priorityCounts'][$priority] ?? 0 }}</span>
</div>
@endforeach
</div>
Expand All @@ -50,7 +51,7 @@
@foreach($data['topAlertData'] as $alert)
<tr>
<td>
<span class="priority-badge {{ strtolower($alert['priority']) }}">
<span class="priority-label {{ strtolower($alert['priority']) }}">
{{ $alert['priority'] }}
</span>
</td>
Expand Down
47 changes: 24 additions & 23 deletions resources/views/reports/report-style.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
font-size: 16px;
}
/* Priority Box */
.card-label {
font-size: 14px;
font-weight: bold;
}
.priority-item {
display: flex;
justify-content: space-between;
Expand All @@ -78,10 +82,18 @@
font-size: 12px;
}
.priority-label.critical {
background-color: #6813b8;
}
.priority-label.high {
background-color: #dc3545;
}
.priority-label.medium {
background-color: #dc8635;
}
.priority-label.low {
background-color: #ffc107;
}
Expand Down Expand Up @@ -120,40 +132,29 @@
font-size: 12px;
}
.total-events-box {
display: flex;
flex-direction: column;
height: 90%;
padding: 15px;
text-align: center;
}
.total-events-box h3 {
margin: 0;
margin-bottom: 10px;
font-size: 16px;
}
.total-events-box .event-count {
/* Take up remaining space and center the number vertically */
flex: 1;
display: flex;
align-items: center;
justify-content: center;
font-size: 48px;
font-weight: bold;
margin: 0;
margin-top: 25px;
line-height: 1;
}
/* Force background printing */
* {
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
}
/* Specific print styles */
@media print {
.priority-label.critical,
.priority-badge.critical {
background-color: #6813b8; !important;
color: white !important;
}
.priority-label.high,
.priority-badge.high {
background-color: #dc3545 !important;
Expand Down Expand Up @@ -259,11 +260,11 @@
.source-ip-box {
break-inside: avoid;
}
.ip-table {
break-inside: auto;
}
.ip-table tr {
break-inside: avoid;
}
Expand Down Expand Up @@ -345,7 +346,7 @@
.bottom-grid {
break-inside: avoid;
}
.box {
break-inside: avoid;
}
Expand Down Expand Up @@ -432,7 +433,7 @@
.ports-grid {
break-inside: avoid;
}
.box {
break-inside: avoid;
}
Expand All @@ -441,4 +442,4 @@
.page-break {
page-break-before: always; /* Or use page-break-after: always */
}
</style>
</style>
3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
});

Route::get('/reports/{id}/view', [ReportController::class, 'viewReport'])
->name('reports.view')
->middleware('signed');
->name('reports.view');

0 comments on commit efbf3ba

Please sign in to comment.