* Copyright (c) 2016 Jens Langhammer * Copyright (c) 2016 Cercel Valentin * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ if (defined('show_settings')) { $current_mode = isset($widget_settings['mode']) ? $widget_settings['mode'] : 0; $current_width = isset($widget_settings['tile_width']) ? $widget_settings['tile_width'] : 10; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = ''; $common_output[] = '
'; $common_output[] = ''; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = ''; $common_output[] = '
'; $common_output[] = ''; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = ''; $common_output[] = '
'; $common_output[] = '
'; $common_output[] = '
'; } else { require_once 'includes/object-cache.inc.php'; $mode = isset($_SESSION["mapView"]) ? $_SESSION["mapView"] : 0; $widget_mode = isset($widget_settings['mode']) ? $widget_settings['mode'] : 0; $tile_width = isset($widget_settings['tile_width']) ? $widget_settings['tile_width'] : 10; $host_up_count = 0; $host_warn_count = 0; $host_down_count = 0; $service_up_count = 0; $service_down_count = 0; if ($mode == 0 || $mode == 2) { // Only show devices if mode is 0 or 2 (Only Devices or both) $sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`'; if (is_normal_user() === true) { $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND'; $param = array( $_SESSION['user_id'] ); } else { $sql .= ' WHERE'; } $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`"; $temp_output = array(); foreach (dbFetchRows($sql, $param) as $device) { if ($device['status'] == '1') { if (($device['uptime'] < $config['uptime_warning']) && ($device['uptime'] != '0')) { $deviceState = 'warning'; $deviceLabel = 'label-warning'; $host_warn_count++; } else { $deviceState = 'up'; $deviceLabel = 'label-success'; $host_up_count++; } } else { $deviceState = 'down'; $deviceLabel = 'label-danger'; $host_down_count++; } if ($directpage == "yes") { $deviceIcon = getImage($device); $temp_output[] = ''; $temp_output[] = '
'; $temp_output[] = ''; $temp_output[] = '' . $deviceIcon . '
'; $temp_output[] = '' . $device["hostname"] . ''; $temp_output[] = '
'; } else { $temp_output[] = ''; $temp_output[] = ''; $temp_output[] = ''; } } } if ($mode == 1 || $mode == 2) { $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id`;'; foreach (dbFetchRows($service_query) as $service) { if ($service['service_status'] == '0') { $serviceLabel = "label-success"; $serviceState = "up"; $service_up_count++; } else { $serviceLabel = "label-danger"; $serviceState = "down"; $service_down_count += 1; } if ($directpage == "yes") { $deviceIcon = getImage($service); $temp_output[] = ''; $temp_output[] = '
'; $temp_output[] = ''; $temp_output[] = ''; $temp_output[] = '' . $deviceIcon . '
'; $temp_output[] = '' . $service["hostname"] . ''; $temp_output[] = '
'; } else { $temp_output[] = ''; $temp_output[] = ''; $temp_output[] = ''; } } } if ($directpage == "yes") { $temp_header[] = '
'; $temp_header[] = 'Availability map for'; $temp_header[] = '
'; $temp_header[] = '
'; } if ($mode == 0 || $mode == 2) { if ($directpage == "yes") { $temp_header[] = '
'; $temp_header[] = 'Hosts report:'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
' . $host_up_count . '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
' . $host_warn_count . '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
' . $host_down_count . '
'; $temp_header[] = '
'; $temp_header[] = '
'; } else { $temp_header[] = '
Total hosts '.$host_up_count.' '.$host_warn_count.' '.$host_down_count.'
'; } } if ($mode == 1 || $mode == 2) { if ($directpage == "yes") { $temp_header[] = '
'; $temp_header[] = 'Services report:'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
' . $service_up_count . '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
'; $temp_header[] = '
' . $service_down_count . '
'; $temp_header[] = '
'; $temp_header[] = '
'; } else { $temp_header[] = '
Total services '.$service_up_count.' '.$service_down_count.'
'; } } $temp_header[] = '
'; $temp_header[] = '
'; $common_output = array_merge($temp_header, $temp_output); }