Пример #1
0
function loop_status($lcd)
{
    global $g;
    global $config;
    $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0];
    $lcdpanel_width = get_lcdpanel_width();
    $lcdpanel_height = get_lcdpanel_height();
    if (empty($g['product_name'])) {
        $g['product_name'] = "pfSense";
    }
    $version = @file_get_contents("/etc/version");
    $version = trim($version);
    $refresh_frequency = get_lcdpanel_refresh_frequency();
    /* keep a counter to see how many times we can loop */
    $i = 1;
    while ($i) {
        /* prepare the summary data */
        if ($lcdpanel_height >= "4") {
            $summary_states = split("/", get_pfstate());
            $lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]);
        } else {
            $lcd_summary_data = "";
        }
        $lcd_cmds = array();
        $lcd_cmds[] = "widget_set welcome_scr title_wdgt \"Welcome to\"";
        $lcd_cmds[] = "widget_set welcome_scr text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$g['product_name']} {$version}\"";
        add_summary_values($lcd_cmds, "welcome_scr", $lcd_summary_data, $lcdpanel_width);
        /* process screens to display */
        foreach ((array) $lcdproc_screens_config as $name => $screen) {
            if ($screen != "on") {
                continue;
            }
            switch ($name) {
                case "scr_time":
                    $time = date("n/j/Y H:i");
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ System Time\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$time}\"";
                    break;
                case "scr_uptime":
                    $uptime = get_uptime_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ System Uptime\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$uptime}\"";
                    break;
                case "scr_hostname":
                    exec("/bin/hostname", $output, $ret);
                    $hostname = $output[0];
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ System Name\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$hostname}\"";
                    break;
                case "scr_system":
                    $processor = cpu_usage();
                    $memory = mem_usage();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ System Stats\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"CPU {$processor}%, Mem {$memory}%\"";
                    break;
                case "scr_disk":
                    $disk = disk_usage();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ Disk Use\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"Disk {$disk}%\"";
                    break;
                case "scr_load":
                    $loadavg = get_loadavg_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ Load Averages\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$loadavg}\"";
                    break;
                case "scr_states":
                    $states = get_pfstate();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ Traffic States\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"Curr/Max {$states}\"";
                    break;
                case "scr_carp":
                    $carp = get_carp_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ CARP State\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$carp}\"";
                    break;
                case "scr_ipsec":
                    $ipsec = get_ipsec_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ IPsec Tunnels\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$ipsec}\"";
                    break;
                case "scr_slbd":
                    $slbd = get_slbd_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ Load Balancer\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$slbd}\"";
                    break;
                case "scr_interfaces":
                    $interfaces = get_interfaces_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ Interfaces\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$interfaces}\"";
                    break;
                case "scr_mbuf":
                    $mbufstats = get_mbuf_stats();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ MBuf Usage\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$mbufstats}\"";
                    break;
                case "scr_cpufrequency":
                    $cpufreq = get_cpufrequency();
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"+ CPU Frequency\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 2 \"{$cpufreq}\"";
                    break;
            }
            add_summary_values($lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width);
        }
        send_lcd_commands($lcd, $lcd_cmds);
        sleep($refresh_frequency);
        $i++;
    }
}
Пример #2
0
function loop_status($lcd)
{
    global $g;
    global $config;
    global $lcdproc_connect_errors;
    $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0];
    $lcdpanel_width = get_lcdpanel_width();
    $lcdpanel_height = get_lcdpanel_height();
    if (empty($g['product_name'])) {
        $g['product_name'] = "pfSense";
    }
    $refresh_frequency = get_lcdpanel_refresh_frequency();
    /* keep a counter to see how many times we can loop */
    $i = 1;
    while ($i) {
        /* prepare the summary data */
        if ($lcdpanel_height >= "4") {
            $summary_states = split("/", get_pfstate());
            $lcd_summary_data = sprintf("%02d%% %02d%% %6d", cpu_usage(), mem_usage(), $summary_states[0]);
            if ($lcdpanel_width > "16") {
                $lcd_summary_data = $lcd_summary_data . sprintf(" %3d%%", get_cpufrequency_perc());
            }
        } else {
            $lcd_summary_data = "";
        }
        $lcd_cmds = array();
        /* initializes the widget counter */
        $widget_counter = 0;
        /* controls the output leds */
        if (outputled_enabled_CFontz633()) {
            $led_output_value = 0;
            /* LED 1: Interface status */
            if (substr_count(get_interfaces_stats(), "Down") > 0) {
                $led_output_value = $led_output_value + pow(2, 0);
            } else {
                $led_output_value = $led_output_value + pow(2, 4);
            }
            /* LED 2: CARP status */
            switch (outputled_carp()) {
                case -1:
                    /* CARP disabled */
                /* CARP disabled */
                case 0:
                    $led_output_value = $led_output_value + pow(2, 1);
                case 1:
                    $led_output_value = $led_output_value + pow(2, 5);
            }
            /* LED 3: CPU Usage */
            if (cpu_usage() > 50) {
                $led_output_value = $led_output_value + pow(2, 2);
            } else {
                $led_output_value = $led_output_value + pow(2, 6);
            }
            /* LED 4: Gateway status */
            switch (outputled_gateway()) {
                case -1:
                    /* Gateways not configured */
                /* Gateways not configured */
                case 0:
                    $led_output_value = $led_output_value + 2 ^ 3;
                case 1:
                    $led_output_value = $led_output_value + 2 ^ 7;
            }
            /* Sends the command to the panel */
            $lcd_cmds[] = "output {$led_output_value}";
        }
        /* process screens to display */
        foreach ((array) $lcdproc_screens_config as $name => $screen) {
            if ($screen != "on") {
                continue;
            }
            switch ($name) {
                case "scr_version":
                    $version = get_version();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$version}\"";
                    break;
                case "scr_time":
                    $time = date("n/j/Y H:i");
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$time}\"";
                    break;
                case "scr_uptime":
                    $uptime = get_uptime_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$uptime}\"";
                    break;
                case "scr_hostname":
                    exec("/bin/hostname", $output, $ret);
                    $hostname = $output[0];
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$hostname}\"";
                    break;
                case "scr_system":
                    $processor = cpu_usage();
                    $memory = mem_usage();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"CPU {$processor}%, Mem {$memory}%\"";
                    break;
                case "scr_disk":
                    $disk = disk_usage();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"Disk {$disk}%\"";
                    break;
                case "scr_load":
                    $loadavg = get_loadavg_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$loadavg}\"";
                    break;
                case "scr_states":
                    $states = get_pfstate();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"Cur/Max {$states}\"";
                    break;
                case "scr_carp":
                    $carp = get_carp_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$carp}\"";
                    break;
                case "scr_ipsec":
                    $ipsec = get_ipsec_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$ipsec}\"";
                    break;
                case "scr_slbd":
                    $slbd = get_slbd_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$slbd}\"";
                    break;
                case "scr_interfaces":
                    $interfaces = get_interfaces_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$interfaces}\"";
                    break;
                case "scr_mbuf":
                    $mbufstats = get_mbuf_stats();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$mbufstats}\"";
                    break;
                case "scr_cpufrequency":
                    $cpufreq = get_cpufrequency();
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 {$lcdpanel_width} 2 h 4 \"{$cpufreq}\"";
                    break;
                case "scr_traffic":
                    get_traffic_stats($in_data, $out_data);
                    $lcd_cmds[] = "widget_set {$name} title_wdgt 1 1 \"{$in_data}\"";
                    $lcd_cmds[] = "widget_set {$name} text_wdgt 1 2 \"{$out_data}\"";
                    break;
            }
            if ($name != "scr_traffic_interface") {
                $widget_counter++;
                add_summary_values($lcd_cmds, $name, $lcd_summary_data);
            }
        }
        if (send_lcd_commands($lcd, $lcd_cmds)) {
            $lcdproc_connect_errors = 0;
            // Reset the error counter
        } else {
            //an error occurred
            return;
        }
        if ($refresh_frequency * $widget_counter > 5) {
            sleep(5);
        } else {
            sleep($refresh_frequency * $widget_counter);
        }
        $i++;
    }
}