import { NextResponse } from 'next/server';
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

export async function GET() {
    try {
        const { stdout, stderr } = await execAsync('ps -fu $(whoami) || ps aux');
        return NextResponse.json({
            success: true,
            user: process.env.USER || 'unknown',
            stdout,
            stderr
        });
    } catch (e: any) {
        return NextResponse.json({
            success: false,
            message: e.message,
            stack: e.stack
        });
    }
}
