diff --git a/install.sh b/install.sh index 6ea7377..9f0c1b4 100644 --- a/install.sh +++ b/install.sh @@ -29,6 +29,7 @@ COLLECTOR_SRC="$SCRIPT_DIR/bin/torpanel-collect.py" COLLECTOR_BIN="/usr/local/bin/torpanel-collect.py" SVC="/etc/systemd/system/torpanel-collector.service" TIMER="/etc/systemd/system/torpanel-collector.timer" +LOGDUMP_BIN="/usr/local/bin/torpanel-logdump" export DEBIAN_FRONTEND=noninteractive @@ -137,9 +138,10 @@ info "Granting www-data access to Tor cookie" usermod -aG debian-tor www-data || true ok "Permissions set" -info "Allowing www-data to control tor (limited)" -cat > "$SUDOERS_FILE" <<'SUD' +info "Allowing www-data to control tor (limited) + read logs" +cat > "$SUDOERS_FILE" < "$LOGDUMP_BIN" <<'BASH' +#!/usr/bin/env bash +set -Eeuo pipefail +LINES="${1:-500}" +LEVEL="${2:-info}" # info|notice|warning|err|debug + +case "$LINES" in ''|*[!0-9]* ) LINES=500 ;; esac +case "$LEVEL" in debug|info|notice|warning|err) ;; * ) LEVEL=info ;; esac + +unit_guess() { + if systemctl list-units --type=service | grep -q '^tor@default\.service'; then + echo 'tor@default.service' + elif systemctl list-units --type=service | grep -q '^tor\.service'; then + echo 'tor.service' + else + echo '' + fi +} +UNIT="$(unit_guess)" + +if command -v journalctl >/dev/null 2>&1; then + if [[ -n "$UNIT" ]]; then + if journalctl -u "$UNIT" -t tor -p "$LEVEL" -n "$LINES" -o short-iso --no-pager; then + exit 0 + fi + fi + if journalctl -t tor -p "$LEVEL" -n "$LINES" -o short-iso --no-pager; then + exit 0 + fi +fi + +for f in /var/log/tor/notice.log /var/log/tor/info.log /var/log/tor/log; do + if [[ -r "$f" ]]; then + tail -n "$LINES" "$f" + exit 0 + fi +done + +echo "No Tor logs found via journal (identifier 'tor') or /var/log/tor/*. Enable file logs with: + Log notice file /var/log/tor/notice.log + Log info file /var/log/tor/info.log +and reload tor." >&2 +exit 1 +BASH +chmod 0755 "$LOGDUMP_BIN" +ok "Log dumper installed" + info "Restarting services" systemctl daemon-reload systemctl enable --now tor systemctl enable "$PHP_FPM_SVC" nginx >/dev/null systemctl restart "$PHP_FPM_SVC" systemctl restart nginx -systemctl start torpanel-collector.service +systemctl start torpanel-collector.service || true systemctl enable --now torpanel-collector.timer ok "Services running" diff --git a/web/api/tor_log.php b/web/api/tor_log.php new file mode 100644 index 0000000..78284d9 --- /dev/null +++ b/web/api/tor_log.php @@ -0,0 +1,21 @@ + 5000) $n = 5000; + +$level = isset($_GET['level']) ? strtolower($_GET['level']) : 'info'; +$allowed = ['debug','info','notice','warning','err']; +if (!in_array($level, $allowed, true)) $level = 'info'; + +$cmd = sprintf('sudo /usr/local/bin/torpanel-logdump %d %s', $n, escapeshellarg($level)); +exec($cmd . ' 2>&1', $out, $rc); + +if ($rc === 0 && !empty($out)) { + echo json_encode(['ok' => true, 'lines' => $out]); +} else { + echo json_encode(['ok' => false, 'error' => 'no_log', 'rc' => $rc]); +} \ No newline at end of file diff --git a/web/index.php b/web/index.php index a12638f..35dd2d4 100644 --- a/web/index.php +++ b/web/index.php @@ -22,6 +22,8 @@ auth_require(); Tor Relay Panel
+ + Logout
@@ -198,6 +200,32 @@ auth_require(); + + \ No newline at end of file