Service stack (backend): - webserver.ts rewritten: apache2/php-fpm routes replacing nginx; per-account Apache log endpoint; PHP-FPM reload per version; apache2ctl configtest/reload - accounts.ts: added PUT /:id/shell to toggle /bin/bash vs /usr/sbin/nologin, runs usermod -s and writes audit log New UI features (nixserver): - ShellAccess page: grant/revoke SSH access per account via AccountPicker - ApacheLogs page: live log viewer (access/error) per account; replaces stub - NginxLogs: re-exports ApacheLogs (NixPanel uses Apache, not NGINX) - WebServer page: shows apache2, php8.2-fpm, php8.3-fpm status with reload buttons; config test; Apache log viewer Bug fixes: - Accounts.tsx: Lucide icon size prop type widened (string|number); removed unused Users import; dropped duplicate NGINX log card - Removed soon badge from ShellAccess and ApacheLogs entries Project: - CHANGELOG.md created with full history from 0.2.x through 0.4.0 - All packages bumped from 0.3.2 to 0.4.0
115 lines
4.5 KiB
TypeScript
115 lines
4.5 KiB
TypeScript
import { useState } from 'react'
|
|
import { Link } from 'react-router-dom'
|
|
import { ChevronLeft, FileText, RefreshCw } from 'lucide-react'
|
|
import { api } from '../../api/client'
|
|
import AccountPicker, { type PickedAccount } from './AccountPicker'
|
|
|
|
export default function ApacheLogs() {
|
|
const [selected, setSelected] = useState<PickedAccount | null>(null)
|
|
const [logType, setLogType] = useState<'access' | 'error'>('access')
|
|
const [lines, setLines] = useState<string[]>([])
|
|
const [loading, setLoading] = useState(false)
|
|
const [error, setError] = useState('')
|
|
|
|
const fetchLogs = async (username: string, type: 'access' | 'error') => {
|
|
setLoading(true); setError('')
|
|
try {
|
|
const r = await api.get(`/nixserver/webserver/accounts/${username}/logs/${type}`)
|
|
setLines(r.data.data.lines ?? [])
|
|
} catch (e: unknown) {
|
|
setError((e as { response?: { data?: { error?: string } } })?.response?.data?.error ?? 'Failed to load logs')
|
|
setLines([])
|
|
} finally { setLoading(false) }
|
|
}
|
|
|
|
const handleSelect = (acc: PickedAccount) => {
|
|
setSelected(acc)
|
|
setLines([])
|
|
setError('')
|
|
fetchLogs(acc.username, logType)
|
|
}
|
|
|
|
const handleTabChange = (type: 'access' | 'error') => {
|
|
setLogType(type)
|
|
if (selected) fetchLogs(selected.username, type)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<div className="flex items-center gap-2 text-sm">
|
|
<Link to="/accounts" className="flex items-center gap-1 text-[#64748b] hover:text-white transition-colors">
|
|
<ChevronLeft size={14} /> Accounts
|
|
</Link>
|
|
<span className="text-[#2a2d3e]">/</span>
|
|
<span className="text-white">Apache Log Viewer</span>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-white text-xl font-semibold">Apache Log Viewer</h1>
|
|
<p className="text-[#64748b] text-sm">View Apache access and error logs per hosting account.</p>
|
|
</div>
|
|
{selected && (
|
|
<button
|
|
onClick={() => fetchLogs(selected.username, logType)}
|
|
className="p-2 text-[#64748b] hover:text-white border border-[#2a2d3e] rounded-lg"
|
|
>
|
|
<RefreshCw size={16} className={loading ? 'animate-spin' : ''} />
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div className="bg-[#1a1d27] border border-[#2a2d3e] rounded-xl p-5 space-y-4">
|
|
<AccountPicker onSelect={handleSelect} selected={selected} />
|
|
|
|
{selected && (
|
|
<div className="space-y-3 pt-2 border-t border-[#2a2d3e]">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-2">
|
|
<FileText size={14} className="text-indigo-400" />
|
|
<span className="text-[#94a3b8] text-sm font-mono">/home/{selected.username}/logs/</span>
|
|
</div>
|
|
<div className="flex gap-1 bg-[#0f1117] border border-[#2a2d3e] rounded-lg p-0.5">
|
|
{(['access', 'error'] as const).map(t => (
|
|
<button
|
|
key={t}
|
|
onClick={() => handleTabChange(t)}
|
|
className={`px-3 py-1 text-xs rounded ${logType === t ? 'bg-indigo-600 text-white' : 'text-[#64748b] hover:text-white'}`}
|
|
>
|
|
{t}.log
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="bg-red-500/10 border border-red-500/20 text-red-400 text-xs px-3 py-2 rounded">
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<div className="bg-[#0f1117] border border-[#2a2d3e] rounded-xl overflow-hidden">
|
|
<div className="max-h-96 overflow-y-auto">
|
|
{loading ? (
|
|
<div className="flex items-center justify-center h-32 text-[#64748b] text-sm">Loading logs...</div>
|
|
) : lines.length === 0 ? (
|
|
<div className="flex items-center justify-center h-32 text-[#64748b] text-sm">No log entries found</div>
|
|
) : (
|
|
<pre className="p-4 text-xs text-[#64748b] font-mono leading-relaxed whitespace-pre-wrap">
|
|
{lines.join('\n')}
|
|
</pre>
|
|
)}
|
|
</div>
|
|
{lines.length > 0 && (
|
|
<div className="border-t border-[#2a2d3e] px-4 py-2 text-xs text-[#64748b]">
|
|
Showing last {lines.length} lines
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|