Skip to content

feat(services): add log and login/session services - #982

Open
karlitschek wants to merge 4 commits into
masterfrom
split/05-services-logs-sessions
Open

feat(services): add log and login/session services#982
karlitschek wants to merge 4 commits into
masterfrom
split/05-services-logs-sessions

Conversation

@karlitschek

Copy link
Copy Markdown
Member

Adds four read-only service classes used by the upcoming admin dashboard cards. None are wired into existing controllers yet, so this change is a pure addition with no behavior change.

  • LogTailReader - last N WARN/ERROR entries from the JSON log
    (no shell, line-bounded)
  • LoginStats - bruteforce attempt counters and the top
    offending IPs over recent windows
  • ActivityRate - oc_activity row counts over the last hour /
    day / week
  • ActiveConnections - session counts derived from oc_authtoken

ChristophWurst added a commit that referenced this pull request May 11, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from 7684654 to b066758 Compare May 11, 2026 16:19
Adds four read-only service classes used by the upcoming admin
dashboard cards. None are wired into existing controllers yet, so
this change is a pure addition with no behavior change.

* LogTailReader     - last N WARN/ERROR entries from the JSON log
                      (no shell, line-bounded)
* LoginStats        - bruteforce attempt counters and the top
                      offending IPs over recent windows
* ActivityRate      - oc_activity row counts over the last hour /
                      day / week
* ActiveConnections - session counts derived from oc_authtoken

Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
ChristophWurst added a commit that referenced this pull request May 11, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from b066758 to b34e5c4 Compare May 11, 2026 16:25
ChristophWurst added a commit that referenced this pull request May 11, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from b34e5c4 to 8c232c6 Compare May 11, 2026 16:27
ChristophWurst added a commit that referenced this pull request May 11, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from 8c232c6 to 9a7a730 Compare May 11, 2026 16:37
ChristophWurst added a commit that referenced this pull request May 12, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from 9a7a730 to 28626fa Compare May 12, 2026 13:42
Comment thread lib/ActivityRate.php
@ChristophWurst

ChristophWurst commented May 12, 2026

Copy link
Copy Markdown
Member

Activity, auth token and rate limiting are conceptually problematic. This creates an inter app dependency where this app accesses the persistence of another app directly. The technically sound way would be to go through a public API.

Looking into these right now …

@ChristophWurst

Copy link
Copy Markdown
Member

Amended the original commit to fix the DCO and added class usage like it will be used later to avoid dead code.

@ChristophWurst ChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 functionality-wise

Needs decision conceptually

Comment thread lib/LoginStats.php
Comment thread lib/LogTailReader.php
Comment thread lib/Settings/AdminSettings.php
ChristophWurst added a commit that referenced this pull request May 12, 2026
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from 28626fa to 7fbf7cc Compare May 12, 2026 17:55
Injects LogTailReader, LoginStats, ActivityRate, and ActiveConnections —
added in #982 — into AdminSettings and passes their data to the template
params, making the services active instead of dead code.

Extracted from #977.

Co-Authored-By: Frank Karlitschek <karlitschek@users.noreply.github.com>
AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
ChristophWurst force-pushed the split/05-services-logs-sessions branch from e7fafb7 to b48f36c Compare May 12, 2026 18:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds four new read-only “metrics” services to support upcoming admin UI cards (log tail, brute force/login stats, activity rate, and active connections), along with tests, and wires them into the admin settings template parameters.

Changes:

  • Added service classes: LogTailReader, LoginStats, ActivityRate, and ActiveConnections.
  • Integrated the new services into AdminSettings::getForm() response parameters.
  • Added PHPUnit coverage for the new services and updated the Psalm baseline for DI/unused-method noise.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/psalm-baseline.xml Suppresses Psalm “PossiblyUnusedMethod::__construct” for the newly added services.
tests/lib/LogTailReaderTest.php Unit tests for log tail availability, filtering, limits, and truncation.
tests/lib/LoginStatsTest.php DB tests for bruteforce attempt counts and top IP aggregation.
tests/lib/ActivityRateTest.php DB tests for activity counts over time windows and top-actions shape.
tests/lib/ActiveConnectionsTest.php DB tests for auth token–based active connection/session counts.
lib/Settings/AdminSettings.php Injects the new services and adds their results to the admin settings template params.
lib/LogTailReader.php Implements safe log tail reading from file-based JSON log entries.
lib/LoginStats.php Implements bruteforce attempt counters and top offending IP queries.
lib/ActivityRate.php Implements activity table counting over multiple time windows plus top-actions query.
lib/ActiveConnections.php Implements auth token counting over time windows and by token type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ActivityRate.php
Comment on lines +69 to +73
$qb->select('subjectparams', 'type')
->selectAlias($qb->func()->count('activity_id'), 'count')
->from('activity')
->where($qb->expr()->gte('timestamp', $qb->createNamedParameter(time() - 86400)))
->groupBy('type', 'subjectparams')
Comment on lines 79 to +83
'slowestJobs' => $this->slowestJobs->getSlowestJobs(),
'logTail' => $this->logTailReader->recentErrors(),
'loginStats' => $this->loginStats->getStats(),
'activityRate' => $this->activityRate->getActivityRate(),
'activeConnections' => $this->activeConnections->getActiveConnections(),
Comment thread lib/LoginStats.php
Comment on lines +73 to +78
private function countAttempts(?int $sinceTimestamp = null): int {
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('id'))->from('bruteforce_attempts');
if ($sinceTimestamp !== null) {
$qb->where($qb->expr()->gte('occurred', $qb->createNamedParameter($sinceTimestamp)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants