Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ ISPs elsewhere can use it too.
- **Search:** menu Add-ons, then "Session records" (on ISPGrid 0.1.0, in the main menu). Search by an IP at a date and time (who had it then, sessions still online
included), or by username, device MAC or NAS over a date range. Results show the customer's current name, mobile
and address, or "Deleted customer". Export the results as CSV.
- **Accountability:** every search and export asks for a reference number and a reason, and is written to the
Activity log.
- **Accountability:** every search and export is written to the Activity log, with the reference number and reason
when staff give them. Searches by username, MAC or NAS start on the last 7 days.
- **Permissions:** "Search session records" and "Session records settings" on the Roles screen (Admin has both;
roles that had "App settings" get "Session records settings" when the add-on is updated).
- English and Hindi.
Expand Down
4 changes: 2 additions & 2 deletions lang/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"Device MAC": "डिवाइस MAC",
"Download (bytes)": "डाउनलोड (बाइट)",
"End": "समाप्त",
"Every session is kept for :days days. Each search is recorded in the Activity log with its reference and reason.": "हर सत्र :days दिन रखा जाता है। हर खोज संदर्भ और कारण के साथ गतिविधि लॉग में दर्ज होती है।",
"Export CSV": "CSV निर्यात करें",
"IP": "IP",
"IP address at a time": "किसी समय पर IP पता",
Expand All @@ -23,5 +22,6 @@
"Session records settings": "सत्र रिकॉर्ड की सेटिंग",
"Start": "शुरू",
"The number on the request you are answering.": "जिस अनुरोध का उत्तर दे रहे हैं उसकी संख्या।",
"Upload (bytes)": "अपलोड (बाइट)"
"Upload (bytes)": "अपलोड (बाइट)",
"Every session is kept for :days days. Each search is recorded in the Activity log, with the reference and reason when given.": "हर सेशन :days दिन तक रखा जाता है। हर खोज एक्टिविटी लॉग में दर्ज होती है, रेफ़रेंस और कारण दिए हों तो उनके साथ।"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section class="grid gap-6">
<div>
<x-ui.heading level="1" size="xl">{{ __('Session records') }}</x-ui.heading>
<x-ui.text muted class="mt-1">{{ __('Every session is kept for :days days. Each search is recorded in the Activity log with its reference and reason.', ['days' => $this->keepDays]) }}</x-ui.text>
<x-ui.text muted class="mt-1">{{ __('Every session is kept for :days days. Each search is recorded in the Activity log, with the reference and reason when given.', ['days' => $this->keepDays]) }}</x-ui.text>
</div>

<form wire:submit="search" class="grid gap-4">
Expand Down
16 changes: 11 additions & 5 deletions resources/views/livewire/session-records/session-records.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@
*/
public bool $searched = false;

/**
* Searches by username, MAC or NAS start on the last 7 days, still editable.
*/
public function mount(): void
{
$this->authorize('search-session-records');
$this->from = now()->subDays(7)->format('Y-m-d\TH:i');
$this->to = now()->format('Y-m-d\TH:i');
}

/**
Expand Down Expand Up @@ -103,8 +108,8 @@ protected function rules(): array
'at' => [Rule::requiredIf(! $range), 'nullable', 'date'],
'from' => [Rule::requiredIf($range), 'nullable', 'date'],
'to' => [Rule::requiredIf($range), 'nullable', 'date', 'after_or_equal:from'],
'reference' => ['required', 'string', 'max:100'],
'reason' => ['required', 'string', 'max:255'],
'reference' => ['nullable', 'string', 'max:100'],
'reason' => ['nullable', 'string', 'max:255'],
];
}

Expand Down Expand Up @@ -172,9 +177,10 @@ private function log(string $event, int $results): void
{
activity()
->event($event)
->withChanges(['attributes' => [
'reference' => $this->reference,
'reason' => $this->reason,
->withChanges(['attributes' => array_filter([
'reference' => trim($this->reference),
'reason' => trim($this->reason),
], fn (string $value): bool => $value !== '') + [
'search' => $this->query()->describe(),
'results' => $results,
]])
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/settings/settings.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form wire:submit="save" class="grid gap-3 sm:grid-cols-[1fr_auto] sm:items-end">
<x-ui.input wire:model="keepDays" type="number" min="730" max="3650" :label="__('Keep session records (days)')" :description="__('Older records are removed every night. 730 to 3650 days.')" />
<x-ui.button type="submit">{{ __('Save') }}</x-ui.button>
<x-ui.button type="submit" class="justify-self-start">{{ __('Save') }}</x-ui.button>
</form>
21 changes: 19 additions & 2 deletions tests/Feature/SearchPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,30 @@ function closedSessionWithIp(string $username): void
$page->set('value', '100.64.10.7')->assertForbidden();
});

it('needs a reference and a reason before it searches', function () {
it('searches and logs without a reference or a reason', function () {
$this->actingAs(User::factory()->create());
closedSessionWithIp('asha');

Livewire::test('ipdr::session-records')
->set('by', 'ip')->set('value', '100.64.10.7')->set('at', '2026-10-15T10:00')
->call('search')
->assertHasErrors(['reference' => 'required', 'reason' => 'required']);
->assertHasNoErrors();

$log = Activity::query()->where('event', 'session-records-searched')->sole()->attribute_changes['attributes'];
expect($log)->not->toHaveKeys(['reference', 'reason'])
->and($log['results'])->toBe(1);
});

it('starts a range search on the last 7 days', function () {
$this->travelTo('2026-10-24 13:45:00');
$this->actingAs(User::factory()->create());

Livewire::test('ipdr::session-records')
->assertSet('from', '2026-10-17T13:45')
->assertSet('to', '2026-10-24T13:45')
->set('by', 'username')->set('value', 'asha')
->call('search')
->assertHasNoErrors();
});

it('shows who had the IP, with their details, and logs the search', function () {
Expand Down