/**
 * fluxd
 *
 * @param $action
 */
function sa_fluxd($action = "")
{
    global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
    if ($action == "") {
        return;
    }
    switch ($action) {
        case "0":
            // fluxd-main
            $htmlTitle = "fluxd";
            break;
        case "1":
            // fluxd-log
            $htmlTitle = "fluxd - log";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"] . '.fluxd/fluxd.log'));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "2":
            // fluxd-error-log
            $htmlTitle = "fluxd - error-log";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"] . '.fluxd/fluxd-error.log'));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "3":
            // fluxd-ps
            $htmlTitle = "fluxd - ps";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | " . $cfg['bin_grep'] . " fluxd | " . $cfg['bin_grep'] . " -v grep"));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "4":
            // fluxd-status
            $htmlTitle = "fluxd - status";
            if (Fluxd::isRunning()) {
                $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
                $htmlMain .= '<pre>';
                $htmlMain .= tfb_htmlencode(Fluxd::status());
                $htmlMain .= '</pre>';
                $htmlMain .= '</div>';
            } else {
                $htmlMain .= '<br><strong>fluxd not running</strong>';
            }
            break;
        case "5":
            // fluxd-check
            $htmlTitle = "fluxd - check";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"] . " -I " . tfb_shellencode($cfg["docroot"] . "bin/fluxd") . " -I " . tfb_shellencode($cfg["docroot"] . "bin/lib") . " " . tfb_shellencode($cfg["docroot"] . "bin/fluxd/fluxd.pl") . " check"));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "6":
            // fluxd-db-debug
            $htmlTitle = "fluxd - db-debug";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"] . " -I " . tfb_shellencode($cfg["docroot"] . "bin/fluxd") . " -I " . tfb_shellencode($cfg["docroot"] . "bin/lib") . " " . tfb_shellencode($cfg["docroot"] . "bin/fluxd/fluxd.pl") . " debug db " . tfb_shellencode($cfg["docroot"]) . " " . tfb_shellencode($cfg["path"]) . " " . tfb_shellencode($cfg["bin_php"])));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
        case "9":
            // fluxd-version
            $htmlTitle = "fluxd - version";
            $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid ' . $cfg['main_bgcolor'] . '; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"] . " -I " . tfb_shellencode($cfg["docroot"] . "bin/fluxd") . " -I " . tfb_shellencode($cfg["docroot"] . "bin/lib") . " " . tfb_shellencode($cfg["docroot"] . "bin/fluxd/fluxd.pl") . " version"));
            $htmlMain .= '</pre>';
            $htmlMain .= '</div>';
            break;
    }
    printPage();
    exit;
}