<?php
if (isset($_POST['run'])) {
    // Path ke shuriken.php, sesuaikan dengan lokasi kamu
    $cmd = "php shuriken image:scrape --append_query='site:pinterest.com' --keywords=crochet";

    // Jalankan 2x berurutan di background, simpan output ke file
    $fullCmd = "nohup bash -c \"$cmd && $cmd\" > output.log 2>&1 &";

    shell_exec($fullCmd);
    $status = "Perintah sedang dijalankan di latar belakang. Silakan cek hasil di bawah.";
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Eksekusi Shuriken</title>
</head>
<body>
    <h2>Eksekusi Shuriken (background)</h2>
    <form method="post">
        <button type="submit" name="run">Jalankan Perintah</button>
    </form>

    <?php if (!empty($status)): ?>
        <p><?php echo $status; ?></p>
    <?php endif; ?>

    <h3>Log Output:</h3>
    <pre>
<?php
if (file_exists("output.log")) {
    echo htmlspecialchars(file_get_contents("output.log"));
}
?>
    </pre>
</body>
</html>
