- DiscordBotProject: new project type (discord-bot), auto-detects from main.py + cogs/ - botcontrol API: start/stop/restart/status via sudo systemctl - botconfig API: atomic read/write of config.json; CRUD for streamers, RSS feeds, Mastodon accounts, and LinkedIn pages; tokens masked in GET responses - botlogs API: tail log file (path via project_settings.bot_log_file) - Tab partials: _tab_bot (process control), _tab_botconfig (structured editor), _tab_logs (log viewer with auto-refresh) - view.php: register bot/botconfig/logs tabs with labels, icons, and groups - app.js: bot control panel, config editor with account/page dropdowns in RSS modal, Mastodon accounts CRUD, LinkedIn pages CRUD; audit labels/icons for all new actions - CLAUDE.md: document Discord Bot integration, sudoers requirement, API actions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
$pid = (int)($_GET['project_id'] ?? 0);
|
|
|
|
$stmt = $db->prepare('SELECT * FROM projects WHERE id = ? AND is_active = 1');
|
|
$stmt->execute([$pid]);
|
|
$project = $stmt->fetch();
|
|
if (!$project) { http_response_code(404); echo json_encode(['error' => 'Project not found']); exit; }
|
|
|
|
// Log file path from project settings (default: logs/bashybot.log)
|
|
$psStmt = $db->prepare('SELECT value FROM project_settings WHERE project_id = ? AND key = ?');
|
|
$psStmt->execute([$pid, 'bot_log_file']);
|
|
$row = $psStmt->fetch();
|
|
$rel = $row ? $row['value'] : 'logs/bashybot.log';
|
|
|
|
$base = realpath($project['path']);
|
|
$logPath = realpath($base . '/' . ltrim($rel, '/'));
|
|
|
|
if (!$logPath || strpos($logPath, $base) !== 0 || !is_file($logPath)) {
|
|
echo json_encode(['lines' => [], 'error' => 'Log file not found: ' . htmlspecialchars($rel)]);
|
|
exit;
|
|
}
|
|
|
|
$lines = (int)($_GET['lines'] ?? 100);
|
|
$lines = max(10, min(500, $lines));
|
|
|
|
$output = [];
|
|
exec('tail -n ' . $lines . ' ' . escapeshellarg($logPath) . ' 2>&1', $output);
|
|
|
|
echo json_encode(['lines' => $output]);
|