<?php
/*
 * script to be used as ajax poll request to get current status of an action
 */
if (array_key_exists("ajax", $_GET)) {

    // see pages/act_build.php
    $sOutDir = sys_get_temp_dir(); // ... is /tmp
    $sTmpFile = $sOutDir . "/" 
            . preg_replace('/[^a-z0-9\-\_]/', '_', $_GET["ajax"]); 
    
    // ----------------------------------------------------------------------

    $sProcesses = "<h2 class=\"warning\">please wait ...</h2>"
            . shell_exec("uptime") . "<br><pre>"
            . shell_exec("ps -f | egrep -v '/(apache|httpd)' | fgrep -v 'ps -f' | fgrep -v grep")
            . "</pre>";

    $sOut = file_exists($sTmpFile) ? file_get_contents($sTmpFile) : "waiting for " . $sTmpFile;
    
    // ----------------------------------------------------------------------
    // output
    // ----------------------------------------------------------------------
    echo $sProcesses
        . '<div style="margin-left: 3em; border-left: 5px dotted #eee; padding-left: 1em;">'
        . $sOut
        . '</div><div style="clear: both;"></div>'
    ;
}