* 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[] = '
'; } else { require_once 'includes/object-cache.inc.php'; $sql = dbFetchRow('SELECT `settings` FROM `users_widgets` WHERE `user_id` = ? AND `widget_id` = ?', array($_SESSION["user_id"], '1')); $widget_mode = json_decode($sql['settings']); $mode = isset($_SESSION["mapView"]) ? $_SESSION["mapView"] : $widget_mode->{'mode'}; $host_up_count = 0; $host_warn_count = 0; $host_down_count = 0; $service_up_count = 0; $service_warn_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 = 'warn'; $deviceLabel = 'label-warning'; $deviceLabelOld = 'availability-map-oldview-box-warn'; $host_warn_count++; } else { $deviceState = 'up'; $deviceLabel = 'label-success'; $deviceLabelOld = 'availability-map-oldview-box-up'; $host_up_count++; } } else { $deviceState = 'down'; $deviceLabel = 'label-danger'; $deviceLabelOld = 'availability-map-oldview-box-down'; $host_down_count++; } if ($config['webui']['old_availability_map'] == 0) { if ($directpage == "yes") { $deviceIcon = getImage($device); $temp_output[] = '
'.$deviceState.' '.$deviceIcon.'
'.$device["hostname"].'
'; } else { $temp_output[] = ' '.$deviceState.' '; } } else { $temp_output[] = '
'; } } } if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { $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`;'; $services = dbFetchRows($service_query); if (count($services) > 0) { foreach ($services as $service) { if ($service['service_status'] == '0') { $serviceLabel = "label-success"; $serviceLabelOld = 'availability-map-oldview-box-up'; $serviceState = "up"; $service_up_count++; } elseif ($service['service_status'] == '1') { $serviceLabel = "label-warning"; $serviceLabelOld = 'availability-map-oldview-box-warn'; $serviceState = "warn"; $service_warn_count++; } else { $serviceLabel = "label-danger"; $serviceLabelOld = 'availability-map-oldview-box-down'; $serviceState = "down"; $service_down_count++; } if ($config['webui']['old_availability_map'] == 0) { if ($directpage == "yes") { $deviceIcon = getImage($service); $temp_output[] = '
' . $service["service_type"] . ' ' . $serviceState . ' ' . $deviceIcon . '
' . $service["hostname"] . '
'; } else { $temp_output[] = ' ' . $service['service_type'] . ' - ' . $serviceState . ' '; } } else { $temp_output[] = '
'; } } } else { $temp_output [] = ''; } } if ($directpage == "yes") { $temp_header[] = '
Availability map for
'; } if ($mode == 0 || $mode == 2) { if ($directpage == "yes") { $headerClass = 'page-availability-report-host'; } else { $headerClass = 'widget-availability-host'; } $temp_header[] = '
Total hosts up: '.$host_up_count.' warn: '.$host_warn_count.' down: '.$host_down_count.'
'; } if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { if ($directpage == "yes") { $headerClass = 'page-availability-report-service'; } else { $headerClass = 'widget-availability-service'; } $temp_header[] = '
Total services up: '.$service_up_count.' warn: '.$service_warn_count.' down: '.$service_down_count.'
'; } $temp_header[] = '
'; $temp_header[] = '
'; $common_output = array_merge($temp_header, $temp_output); }