diff --git a/app/Http/Controllers/LegacyController.php b/app/Http/Controllers/LegacyController.php index dded0d8bae..fb57e8d0df 100644 --- a/app/Http/Controllers/LegacyController.php +++ b/app/Http/Controllers/LegacyController.php @@ -49,11 +49,10 @@ class LegacyController extends Controller $vars['page'] = basename($vars['page'] ?? ''); if ($vars['page'] && is_file("includes/html/pages/" . $vars['page'] . ".inc.php")) { require "includes/html/pages/" . $vars['page'] . ".inc.php"; - } elseif (Config::has('front_page') && is_file('includes/html/' . Config::get('front_page'))) { - require 'includes/html/' . Config::get('front_page'); } else { - require 'includes/html/pages/front/default.php'; + return abort(404); } + $html = ob_get_clean(); ob_end_clean(); diff --git a/app/Http/Controllers/OverviewController.php b/app/Http/Controllers/OverviewController.php new file mode 100644 index 0000000000..da5d6f2b0e --- /dev/null +++ b/app/Http/Controllers/OverviewController.php @@ -0,0 +1,171 @@ +exists("overview.custom.$view")) { + return view("overview.custom.$view"); + } elseif (method_exists($this, $view)) { + return $this->{$view}($request); + } + + return $this->default($request); + } + + public function default(Request $request) + { + $user = Auth::user(); + $dashboards = Dashboard::allAvailable($user)->with('user:user_id,username')->get()->keyBy('dashboard_id'); + + // Split dashboards into user owned or shared + list($user_dashboards, $shared_dashboards) = $dashboards->partition(function ($dashboard) use ($user) { + return $dashboard->user_id == $user->user_id; + }); + + + + if (!empty($request->dashboard) && isset($dashboards[$request->dashboard])) { + // specific dashboard + $dashboard = $dashboards[$request->dashboard]; + } else { + $user_default_dash = (int)UserPref::getPref($user, 'dashboard'); + $global_default = (int)Config::get('webui.default_dashboard_id'); + + // load user default + if (isset($dashboards[$user_default_dash])) { + $dashboard = $dashboards[$user_default_dash]; + // load global default + } elseif (isset($dashboards[$global_default])) { + $dashboard = $dashboards[$global_default]; + // load users first dashboard + } elseif (!empty($user_dashboards)) { + $dashboard = $user_dashboards->first(); + } + + // specific dashboard was requested, but doesn't exist + if (isset($dashboard) && !empty($request->dashboard)) { + Toastr::error( + "Dashboard #$request->dashboard does not exist! Loaded + ".htmlentities($dashboard->dashboard_name)." instead.", + "Requested Dashboard Not Found!" + ); + } + } + + if (!isset($dashboard)) { + $dashboard = Dashboard::create([ + 'dashboard_name' => 'Default', + 'user_id' => $user->user_id, + ]); + } + + $data = $dashboard + ->widgets() + ->select(['user_widget_id','users_widgets.widget_id','title','widget','col','row','size_x','size_y','refresh']) + ->join('widgets', 'widgets.widget_id', '=', 'users_widgets.widget_id') + ->get(); + + if ($data->isEmpty()) { + $data[] = array('user_widget_id'=>'0', + 'widget_id'=>1, + 'title'=>'Add a widget', + 'widget'=>'placeholder', + 'col'=>1, + 'row'=>1, + 'size_x'=>6, + 'size_y'=>2, + 'refresh'=>60 + ); + } + + $bare = $request->bare; + $data = serialize(json_encode($data)); + $dash_config = unserialize(stripslashes($data)); + $widgets = Widget::select('widget_id', 'widget_title')->orderBy('widget_title')->get(); + + return view('overview.default', compact('bare', 'dash_config', 'dashboard', 'user_dashboards', 'shared_dashboards', 'widgets')); + } + + public function simple(Request $request) + { + //TODO: All below missing D.ignore = '0' check + $ports_down = []; + $bgp_down = []; + $devices_uptime = []; + $syslog = []; + + $devices_down = Device::hasAccess(Auth::user()) + ->isDown() + ->limit(Config::get('front_page_down_box_limit')) + ->get(); + + if (Config::get('warn.ifdown')) { + $ports_down = Port::hasAccess(Auth::user()) + ->isDown() + ->limit(Config::get('front_page_down_box_limit')) + ->with('device') + ->get(); + } + + $services_down = Service::hasAccess(Auth::user()) + ->isCritical() + ->limit(Config::get('front_page_down_box_limit')) + ->with('device') + ->get(); + + + // TODO: is inAlarm() equal to: bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' ? + if (Config::get('enable_bgp')) { + $bgp_down = BgpPeer::hasAccess(Auth::user()) + ->inAlarm() + ->limit(Config::get('front_page_down_box_limit')) + ->with('device') + ->get(); + } + + if (filter_var(Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false + && Config::get('uptime_warning') > 0 + ) { + $devices_uptime = Device::hasAccess(Auth::user()) + ->isUp() + ->whereUptime(Config::get('uptime_warning')) + ->limit(Config::get('front_page_down_box_limit')) + ->get(); + + $devices_uptime = $devices_uptime->reject(function ($device) { + $device->loadOs(); // TODO: needed? + return Config::get("os.{$device->os}.bad_uptime") == true; + }); + } + + if (Config::get('enable_syslog')) { + $syslog = Syslog::hasAccess(Auth::user()) + ->orderBy('timestamp', 'desc') + ->limit(20) + ->with('device') + ->get(); + } + + return view('overview.simple', compact('devices_down', 'ports_down', 'services_down', 'bgp_down', 'devices_uptime', 'syslog')); + } +} diff --git a/app/Models/Device.php b/app/Models/Device.php index 6240f730b8..934bf17fb6 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -542,6 +542,14 @@ class Device extends BaseModel ]); } + public function scopeWhereUptime($query, $uptime, $modifier = '<') + { + return $query->where([ + ['uptime', '>', 0], + ['uptime', $modifier, $uptime] + ]); + } + public function scopeCanPing(Builder $query) { return $query->where('disabled', 0) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 08d6b37b6d..567dc75aae 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -229,19 +229,12 @@ Set how often pages are refreshed in seconds. The default is every 5 minutes. Some pages don't refresh at all by design. ```php -$config['front_page'] = "pages/front/default.php"; -$config['front_page_settings']['top']['ports'] = 10; -$config['front_page_settings']['top']['devices'] = 10; -$config['front_page_down_box_limit'] = 10; -$config['vertical_summary'] = 0; // Enable to use vertical summary on front page instead of horizontal -$config['top_ports'] = 1; // This enables the top X ports box -$config['top_devices'] = 1; // This enables the top X devices box +$config['front_page'] = "default"; ``` -A number of home pages are provided within the install and can be -found in html/pages/front/. You can change the default by setting -`front_page`. The other options are used to alter the look of those -pages that support it (default.php supports these options). +You can create your own front page by adding a blade file in `resources/views/overview/custom/` +and setting `front_page` to it's name. +For example, if you create `resources/views/overview/custom/foobar.blade.php`, set `front_page` to `foobar`. ```php // This option exists in the web UI, edit it under Global Settings -> webui diff --git a/html/js/jquery.mapael.js b/html/js/jquery.mapael.js deleted file mode 100644 index 1879f32bdd..0000000000 --- a/html/js/jquery.mapael.js +++ /dev/null @@ -1,1248 +0,0 @@ -/** -* -* Jquery Mapael - Dynamic maps jQuery plugin (based on raphael.js) -* Requires jQuery and raphael.js -* -* Version: 1.0.1 -* -* Copyright (c) 2015 Vincent Brouté (http://www.vincentbroute.fr/mapael) -* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). -* -*/ -(function($) { - - "use strict"; - - $.fn.mapael = function(options) { - - // Extend legend default options with user options - options = $.extend(true, {}, $.fn.mapael.defaultOptions, options); - - for (var type in options.legend) { - if ($.isArray(options.legend[type])) { - for (var i = 0; i < options.legend[type].length; ++i) - options.legend[type][i] = $.extend(true, {}, $.fn.mapael.legendDefaultOptions[type], options.legend[type][i]); - } else { - options.legend[type] = $.extend(true, {}, $.fn.mapael.legendDefaultOptions[type], options.legend[type]); - } - } - - return this.each(function() { - - var $self = $(this) - , $container = $("." + options.map.cssClass, this).empty() - , $tooltip = $("
").addClass(options.map.tooltip.cssClass).css("display", "none").appendTo(options.map.tooltip.target || $container) - , mapConf = $.fn.mapael.maps[options.map.name] - , paper = new Raphael($container[0], mapConf.width, mapConf.height) - , elemOptions = {} - , resizeTO = 0 - , areas = {} - , plots = {} - , legends = [] - , id = 0; - - options.map.tooltip.css && $tooltip.css(options.map.tooltip.css); - paper.setViewBox(0, 0, mapConf.width, mapConf.height, false); - - // Draw map areas - for (id in mapConf.elems) { - elemOptions = $.fn.mapael.getElemOptions( - options.map.defaultArea - , (options.areas[id] ? options.areas[id] : {}) - , options.legend.area - ); - areas[id] = {"mapElem" : paper.path(mapConf.elems[id]).attr(elemOptions.attrs)}; - } - - // Init map areas in a second loop (prevent texts to be hidden by map elements) - for (id in mapConf.elems) { - elemOptions = $.fn.mapael.getElemOptions( - options.map.defaultArea - , (options.areas[id] ? options.areas[id] : {}) - , options.legend.area - ); - $.fn.mapael.initElem(paper, areas[id], elemOptions, $tooltip, id); - } - - // Draw links - $.fn.mapael.drawLinksCollection(paper, options, mapConf.getCoords, $tooltip); - - // Draw plots - for (id in options.plots) { - plots[id] = $.fn.mapael.drawPlot(id, options, mapConf, paper, $tooltip); - } - - /** - * Zoom on the map at a specific level focused on specific coordinates - * If no coordinates are specified, the zoom will be focused on the center of the map - * options : - * "level" : level of the zoom between 0 and maxLevel - * "x" or "latitude" : x coordinate or latitude of the point to focus on - * "y" or "longitude" : y coordinate or longitude of the point to focus on - * "fixedCenter" : set to true in order to preserve the position of x,y in the canvas when zoomed - */ - $self.on("zoom", function(e, zoomOptions) { - var newLevel = Math.min(Math.max(zoomOptions.level, 0), options.map.zoom.maxLevel) - , panX = 0 - , panY = 0 - , previousZoomLevel = (1 + $self.data("zoomLevel") * options.map.zoom.step) - , zoomLevel = (1 + newLevel * options.map.zoom.step) - , offsetX = 0 - , offsetY = 0 - , coords = {}; - - if (typeof zoomOptions.latitude != "undefined" && typeof zoomOptions.longitude != "undefined") { - coords = mapConf.getCoords(zoomOptions.latitude, zoomOptions.longitude); - zoomOptions.x = coords.x; - zoomOptions.y = coords.y; - } - - if (typeof zoomOptions.x == "undefined") - zoomOptions.x = paper._viewBox[0] + paper._viewBox[2] / 2; - - if (typeof zoomOptions.y == "undefined") - zoomOptions.y = (paper._viewBox[1] + paper._viewBox[3] / 2); - - // Update zoom level of the map - if (newLevel == 0) { - paper.setViewBox(panX, panY, mapConf.width, mapConf.height); - } else { - if (typeof zoomOptions.fixedCenter != 'undefined' && zoomOptions.fixedCenter == true) { - if (zoomLevel == previousZoomLevel) return; - - offsetX = $self.data("panX") + ((zoomOptions.x - $self.data("panX")) * (zoomLevel - previousZoomLevel)) / zoomLevel; - offsetY = $self.data("panY") + ((zoomOptions.y - $self.data("panY")) * (zoomLevel - previousZoomLevel)) / zoomLevel; - - panX = Math.min(Math.max(0, offsetX), (mapConf.width - (mapConf.width / zoomLevel))); - panY = Math.min(Math.max(0, offsetY), (mapConf.height - (mapConf.height / zoomLevel))); - } else { - panX = Math.min(Math.max(0, zoomOptions.x - (mapConf.width / zoomLevel)/2), (mapConf.width - (mapConf.width / zoomLevel))); - panY = Math.min(Math.max(0, zoomOptions.y - (mapConf.height / zoomLevel)/2), (mapConf.height - (mapConf.height / zoomLevel))); - } - - paper.setViewBox(panX, panY, mapConf.width / zoomLevel, mapConf.height / zoomLevel); - } - $self.data({"zoomLevel" : newLevel, "panX" : panX, "panY" : panY, "zoomX" : zoomOptions.x, "zoomY" : zoomOptions.y}); - }); - - /** - * Update the zoom level of the map on mousewheel - */ - options.map.zoom.enabled && options.map.zoom.mousewheel && $self.on("mousewheel", function(e) { - var offset = $container.offset(), - initFactor = (options.map.width) ? ($.fn.mapael.maps[options.map.name].width / options.map.width) : ($.fn.mapael.maps[options.map.name].width / $container.width()) - , zoomLevel = (e.deltaY > 0) ? 1 : -1 - , zoomFactor = 1 / (1 + ($self.data("zoomLevel")) * options.map.zoom.step) - , x = zoomFactor * initFactor * (e.clientX + $(window).scrollLeft() - offset.left) + $self.data("panX") - , y = zoomFactor * initFactor * (e.clientY + $(window).scrollTop() - offset.top) + $self.data("panY"); - - $self.trigger("zoom", {fixedCenter : true, "level" : $self.data("zoomLevel") + zoomLevel, "x" : x, "y" : y}); - - return false; - }); - - // Enable zoom - if (options.map.zoom.enabled) - $.fn.mapael.initZoom($container, paper, mapConf.width, mapConf.height, options.map.zoom); - - // Set initial zoom - if (typeof options.map.zoom.init != "undefined") { - $self.trigger("zoom", options.map.zoom.init); - } - - // Create the legends for areas - $.merge(legends, $.fn.mapael.createLegends($self, options, "area", areas, 1)); - - /** - * - * Update the current map - * Refresh attributes and tooltips for areas and plots - * @param updatedOptions options to update for plots and areas - * @param newPlots new plots to add to the map - * @param deletedPlotsplots to delete from the map - * @param opt option for the refresh : - * opt.animDuration animation duration in ms (default = 0) - * opt.resetAreas true to reset previous areas options - * opt.resetPlots true to reset previous plots options - * opt.afterUpdate Hook that allows to add custom processing on the map - */ - $self.on("update", function(e, updatedOptions, newPlots, deletedPlots, opt) { - var i = 0 - , id = 0 - , animDuration = 0 - , elemOptions = {}; - - // Reset hidden map elements (when user click on legend elements) - legends.forEach(function(el) { - el.forEach && el.forEach(function(el) { - if(typeof el.hidden != "undefined" && el.hidden == true) { - $(el.node).trigger("click"); - } - }) - }); - - if (typeof opt != "undefined") { - (opt.resetAreas) && (options.areas = {}); - (opt.resetPlots) && (options.plots = {}); - (opt.animDuration) && (animDuration = opt.animDuration); - } - - $.extend(true, options, updatedOptions); - - // Delete plots - if (typeof deletedPlots == "object") { - for (;i < deletedPlots.length; i++) { - if (typeof plots[deletedPlots[i]] != "undefined") { - if (animDuration > 0) { - (function(plot) { - plot.mapElem.animate({"opacity":0}, animDuration, "linear", function() {plot.mapElem.remove();}); - if (plot.textElem) { - plot.textElem.animate({"opacity":0}, animDuration, "linear", function() {plot.textElem.remove();}); - } - })(plots[deletedPlots[i]]); - } else { - plots[deletedPlots[i]].mapElem.remove(); - if (plots[deletedPlots[i]].textElem) { - plots[deletedPlots[i]].textElem.remove(); - } - } - delete plots[deletedPlots[i]]; - } - } - } - - // New plots - if (typeof newPlots == "object") { - for (id in newPlots) { - if (typeof plots[id] == "undefined") { - options.plots[id] = newPlots[id]; - plots[id] = $.fn.mapael.drawPlot(id, options, mapConf, paper, $tooltip); - if (animDuration > 0) { - plots[id].mapElem.attr({opacity : 0}); - plots[id].textElem.attr({opacity : 0}); - plots[id].mapElem.animate({"opacity": (typeof plots[id].mapElem.originalAttrs.opacity != "undefined") ? plots[id].mapElem.originalAttrs.opacity : 1}, animDuration); - plots[id].textElem.animate({"opacity": (typeof plots[id].textElem.originalAttrs.opacity != "undefined") ? plots[id].textElem.originalAttrs.opacity : 1}, animDuration); - } - } - } - } - - // Update areas attributes and tooltips - for (id in areas) { - elemOptions = $.fn.mapael.getElemOptions( - options.map.defaultArea - , (options.areas[id] ? options.areas[id] : {}) - , options.legend.area - ); - - $.fn.mapael.updateElem(elemOptions, areas[id], $tooltip, animDuration); - } - - // Update plots attributes and tooltips - for (id in plots) { - elemOptions = $.fn.mapael.getElemOptions( - options.map.defaultPlot - , (options.plots[id] ? options.plots[id] : {}) - , options.legend.plot - ); - if (elemOptions.type == "square") { - elemOptions.attrs.width = elemOptions.size; - elemOptions.attrs.height = elemOptions.size; - elemOptions.attrs.x = plots[id].mapElem.attrs.x - (elemOptions.size - plots[id].mapElem.attrs.width) / 2; - elemOptions.attrs.y = plots[id].mapElem.attrs.y - (elemOptions.size - plots[id].mapElem.attrs.height) / 2; - } else if (elemOptions.type == "image") { - elemOptions.attrs.x = plots[id].mapElem.attrs.x - (elemOptions.width - plots[id].mapElem.attrs.width) / 2; - elemOptions.attrs.y = plots[id].mapElem.attrs.y - (elemOptions.height - plots[id].mapElem.attrs.height) / 2; - } else { // Default : circle - elemOptions.attrs.r = elemOptions.size / 2; - } - - $.fn.mapael.updateElem(elemOptions, plots[id], $tooltip, animDuration); - } - - if(typeof opt != "undefined") - opt.afterUpdate && opt.afterUpdate($self, paper, areas, plots, options); - }); - - // Handle resizing of the map - if (options.map.width) { - paper.setSize(options.map.width, mapConf.height * (options.map.width / mapConf.width)); - - // Create the legends for plots taking into account the scale of the map - $.merge(legends, $.fn.mapael.createLegends($self, options, "plot", plots, (options.map.width / mapConf.width))); - } else { - $(window).on("resize", function() { - clearTimeout(resizeTO); - resizeTO = setTimeout(function(){$container.trigger("resizeEnd");}, 150); - }); - - // Create the legends for plots taking into account the scale of the map - var createPlotLegend = function() { - $.merge(legends, $.fn.mapael.createLegends($self, options, "plot", plots, ($container.width() / mapConf.width))); - - $container.unbind("resizeEnd", createPlotLegend); - }; - - $container.on("resizeEnd", function() { - var containerWidth = $container.width(); - if (paper.width != containerWidth) { - paper.setSize(containerWidth, mapConf.height * (containerWidth / mapConf.width)); - } - }).on("resizeEnd", createPlotLegend).trigger("resizeEnd"); - } - - // Hook that allows to add custom processing on the map - options.map.afterInit && options.map.afterInit($self, paper, areas, plots, options); - - $(paper.desc).append(" and Mapael (http://www.vincentbroute.fr/mapael/)"); - }); - }; - - /** - * Init the element "elem" on the map (drawing, setting attributes, events, tooltip, ...) - */ - $.fn.mapael.initElem = function(paper, elem, options, $tooltip, id) { - var bbox = {}, textPosition = {}; - if (typeof options.value != "undefined") - elem.value = options.value; - - // Init attrsHover - $.fn.mapael.setHoverOptions(elem.mapElem, options.attrs, options.attrsHover); - - // Init the label related to the element - if (options.text && typeof options.text.content != "undefined") { - // Set a text label in the area - bbox = elem.mapElem.getBBox(); - textPosition = $.fn.mapael.getTextPosition(bbox, options.text.position, options.text.margin); - options.text.attrs["text-anchor"] = textPosition.textAnchor; - elem.textElem = paper.text(textPosition.x, textPosition.y, options.text.content).attr(options.text.attrs); - $.fn.mapael.setHoverOptions(elem.textElem, options.text.attrs, options.text.attrsHover); - options.eventHandlers && $.fn.mapael.setEventHandlers(id, options, elem.mapElem, elem.textElem); - $.fn.mapael.setHover(paper, elem.mapElem, elem.textElem); - $(elem.textElem.node).attr("data-id", id); - } else { - options.eventHandlers && $.fn.mapael.setEventHandlers(id, options, elem.mapElem); - $.fn.mapael.setHover(paper, elem.mapElem); - } - - // Init the tooltip - if (options.tooltip && options.tooltip.content) { - elem.mapElem.tooltipContent = options.tooltip.content; - $.fn.mapael.setTooltip(elem.mapElem, $tooltip); - - if (options.text && typeof options.text.content != "undefined") { - elem.textElem.tooltipContent = options.tooltip.content; - $.fn.mapael.setTooltip(elem.textElem, $tooltip); - } - } - - // Init the link - if (options.href) { - elem.mapElem.href = options.href; - elem.mapElem.target = options.target; - $.fn.mapael.setHref(elem.mapElem); - - if (options.text && typeof options.text.content != "undefined") { - elem.textElem.href = options.href; - elem.textElem.target = options.target; - $.fn.mapael.setHref(elem.textElem); - } - } - - $(elem.mapElem.node).attr("data-id", id); - }; - - /** - * Draw all links between plots on the paper - */ - $.fn.mapael.drawLinksCollection = function(paper, options, getCoords, $tooltip) { - var p1 = {} - , p2 = {} - , elemOptions = {} - , coordsP1 = {} - , coordsP2 ={}; - - for (var id in options.links) { - elemOptions = $.fn.mapael.getElemOptions(options.map.defaultLink, options.links[id], {}); - - if (typeof options.links[id].between[0] == 'string') { - p1 = options.plots[options.links[id].between[0]]; - } else { - p1 = options.links[id].between[0]; - } - - if (typeof options.links[id].between[1] == 'string') { - p2 = options.plots[options.links[id].between[1]]; - } else { - p2 = options.links[id].between[1]; - } - - if (typeof p1.latitude != "undefined" && typeof p1.longitude != "undefined") { - coordsP1 = getCoords(p1.latitude, p1.longitude); - } else { - coordsP1.x = p1.x; - coordsP1.y = p1.y; - } - - if (typeof p2.latitude != "undefined" && typeof p2.longitude != "undefined") { - coordsP2 = getCoords(p2.latitude, p2.longitude); - } else { - coordsP2.x = p2.x; - coordsP2.y = p2.y; - } - $.fn.mapael.drawLink(id, paper, coordsP1.x, coordsP1.y, coordsP2.x, coordsP2.y, elemOptions, $tooltip); - } - }; - - /** - * Draw a curved link between two couples of coordinates a(xa,ya) and b(xb, yb) on the paper - */ - $.fn.mapael.drawLink = function(id, paper, xa, ya, xb, yb, elemOptions, $tooltip) { - var elem = {} - - // Compute the "curveto" SVG point, d(x,y) - // c(xc, yc) is the center of (xa,ya) and (xb, yb) - , xc = (xa + xb) / 2 - , yc = (ya + yb) / 2 - - // Equation for (cd) : y = acd * x + bcd (d is the cure point) - , acd = - 1 / ((yb - ya) / (xb - xa)) - , bcd = yc - acd * xc - - // dist(c,d) = dist(a,b) (=abDist) - , abDist = Math.sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya)) - - // Solution for equation dist(cd) = sqrt((xd - xc)² + (yd - yc)²) - // dist(c,d)² = (xd - xc)² + (yd - yc)² - // We assume that dist(c,d) = dist(a,b) - // so : (xd - xc)² + (yd - yc)² - dist(a,b)² = 0 - // With the factor : (xd - xc)² + (yd - yc)² - (factor*dist(a,b))² = 0 - // (xd - xc)² + (acd*xd + bcd - yc)² - (factor*dist(a,b))² = 0 - , a = 1 + acd*acd - , b = -2 * xc + 2*acd*bcd - 2 * acd*yc - , c = xc*xc + bcd*bcd - bcd*yc - yc*bcd + yc*yc - ((elemOptions.factor*abDist) * (elemOptions.factor*abDist)) - , delta = b*b - 4*a*c - , x = 0 - , y = 0; - - // There are two solutions, we choose one or the other depending on the sign of the factor - if (elemOptions.factor > 0) { - x = (-b + Math.sqrt(delta)) / (2*a); - y = acd * x + bcd; - } else { - x = (-b - Math.sqrt(delta)) / (2*a); - y = acd * x + bcd; - } - - elem.mapElem = paper.path("m "+xa+","+ya+" C "+x+","+y+" "+xb+","+yb+" "+xb+","+yb+"").attr(elemOptions.attrs); - $.fn.mapael.initElem(paper, elem, elemOptions, $tooltip, id); - - return elem; - }; - - /** - * Update the element "elem" on the map with the new elemOptions options - */ - $.fn.mapael.updateElem = function(elemOptions, elem, $tooltip, animDuration) { - var bbox, textPosition, plotOffset; - if (typeof elemOptions.value != "undefined") - elem.value = elemOptions.value; - - // Update the label - if (elem.textElem) { - if (typeof elemOptions.text != "undefined" && typeof elemOptions.text.content != "undefined" && elemOptions.text.content != elem.textElem.attrs.text) - elem.textElem.attr({text : elemOptions.text.content}); - - bbox = elem.mapElem.getBBox(); - if (elemOptions.size) { - plotOffset = (elemOptions.size - bbox.height) / 2; - bbox.x -= plotOffset; - bbox.x2 += plotOffset; - bbox.y -= plotOffset; - bbox.y2 += plotOffset; - } - textPosition = $.fn.mapael.getTextPosition(bbox, elemOptions.text.position, elemOptions.text.margin); - if (textPosition.x != elem.textElem.attrs.x || textPosition.y != elem.textElem.attrs.y) { - if (animDuration > 0) { - elem.textElem.attr({"text-anchor" : textPosition.textAnchor}); - elem.textElem.animate({x : textPosition.x, y : textPosition.y}, animDuration); - } else - elem.textElem.attr({x : textPosition.x, y : textPosition.y, "text-anchor" : textPosition.textAnchor}); - } - - $.fn.mapael.setHoverOptions(elem.textElem, elemOptions.text.attrs, elemOptions.text.attrsHover); - if (animDuration > 0) - elem.textElem.animate(elemOptions.text.attrs, animDuration); - else - elem.textElem.attr(elemOptions.text.attrs); - } - - // Update elements attrs and attrsHover - $.fn.mapael.setHoverOptions(elem.mapElem, elemOptions.attrs, elemOptions.attrsHover); - if (animDuration > 0) - elem.mapElem.animate(elemOptions.attrs, animDuration); - else - elem.mapElem.attr(elemOptions.attrs); - - // Update the tooltip - if (elemOptions.tooltip && typeof elemOptions.tooltip.content != "undefined") { - if (typeof elem.mapElem.tooltipContent == "undefined") { - $.fn.mapael.setTooltip(elem.mapElem, $tooltip); - (elem.textElem) && $.fn.mapael.setTooltip(elem.textElem, $tooltip); - } - elem.mapElem.tooltipContent = elemOptions.tooltip.content; - (elem.textElem) && (elem.textElem.tooltipContent = elemOptions.tooltip.content); - } - - // Update the link - if (typeof elemOptions.href != "undefined") { - if (typeof elem.mapElem.href == "undefined") { - $.fn.mapael.setHref(elem.mapElem); - (elem.textElem) && $.fn.mapael.setHref(elem.textElem); - } - elem.mapElem.href = elemOptions.href; - elem.mapElem.target = elemOptions.target; - if (elem.textElem) { - elem.textElem.href = elemOptions.href; - elem.textElem.target = elemOptions.target; - } - } - }; - - /** - * Draw the plot - */ - $.fn.mapael.drawPlot = function(id, options, mapConf, paper, $tooltip) { - var plot = {} - , coords = {} - , elemOptions = $.fn.mapael.getElemOptions( - options.map.defaultPlot - , (options.plots[id] ? options.plots[id] : {}) - , options.legend.plot - ); - - if (typeof elemOptions.x != "undefined" && typeof elemOptions.y != "undefined") - coords = {x : elemOptions.x, y : elemOptions.y}; - else - coords = mapConf.getCoords(elemOptions.latitude, elemOptions.longitude); - - if (elemOptions.type == "square") { - plot = {"mapElem" : paper.rect( - coords.x - (elemOptions.size / 2) - , coords.y - (elemOptions.size / 2) - , elemOptions.size - , elemOptions.size - ).attr(elemOptions.attrs)}; - } else if (elemOptions.type == "image") { - plot = { - "mapElem" : paper.image( - elemOptions.url - , coords.x - elemOptions.width / 2 - , coords.y - elemOptions.height / 2 - , elemOptions.width - , elemOptions.height - ).attr(elemOptions.attrs) - }; - } else { // Default = circle - plot = {"mapElem" : paper.circle(coords.x, coords.y, elemOptions.size / 2).attr(elemOptions.attrs)}; - } - - $.fn.mapael.initElem(paper, plot, elemOptions, $tooltip, id); - - return plot; - }; - - /** - * Set target link on elem - */ - $.fn.mapael.setHref = function(elem) { - elem.attr({cursor : "pointer"}); - $(elem.node).bind("click", function() { - if (!$.fn.mapael.panning && elem.href) - window.open(elem.href, elem.target); - }); - }; - - /** - * Set a tooltip for the areas and plots - * @param elem area or plot element - * @param $tooltip the tooltip container - * @param content the content to set in the tooltip - */ - $.fn.mapael.setTooltip = function(elem, $tooltip) { - var tooltipTO = 0 - , $container = $tooltip.parent() - , containerY2 = $container.offset().left + $container.width(); - - $(elem.node).on("mouseover", function(e) { - tooltipTO = setTimeout( - function() { - elem.tooltipContent && $tooltip.html(elem.tooltipContent).css("display", "block"); - $tooltip.css({"left" : Math.min(containerY2 - $tooltip.outerWidth() - 5, e.pageX + 10 - $(window).scrollLeft()), "top" : e.pageY + 20 - $(window).scrollTop()}); - } - , 120 - ); - }).on("mouseout", function(e) { - clearTimeout(tooltipTO); - $tooltip.css("display", "none"); - }).on("mousemove", function(e) { - $tooltip.css({"left" : Math.min(containerY2 - $tooltip.outerWidth() - 5, e.pageX + 10 - $(window).scrollLeft()), "top" : e.pageY + 20 - $(window).scrollTop()}); - }); - }; - - /** - * Set user defined handlers for events on areas and plots - * @param id the id of the element - * @param elemOptions the element parameters - * @param mapElem the map element to set callback on - * @param textElem the optional text within the map element - */ - $.fn.mapael.setEventHandlers = function(id, elemOptions, mapElem, textElem) { - for(var event in elemOptions.eventHandlers) { - (function(event) { - $(mapElem.node).on(event, function(e) {!$.fn.mapael.panning && elemOptions.eventHandlers[event](e, id, mapElem, textElem, elemOptions)}); - textElem && $(textElem.node).on(event, function(e) {!$.fn.mapael.panning && elemOptions.eventHandlers[event](e, id, mapElem, textElem, elemOptions)}); - })(event); - } - }; - - $.fn.mapael.panning = false; - - /** - * Init zoom and panning for the map - * @param $container - * @param paper - * @param mapWidth - * @param mapHeight - * @param options - */ - $.fn.mapael.initZoom = function($container, paper, mapWidth, mapHeight, options) { - var $parentContainer = $container.parent() - , $zoomIn = $("
").addClass(options.zoomInCssClass).html("+") - , $zoomOut = $("
").addClass(options.zoomOutCssClass).html("−") - , mousedown = false - , previousX = 0 - , previousY = 0; - - // Zoom - $parentContainer.data("zoomLevel", 0).data({"panX" : 0, "panY" : 0}); - $container.append($zoomIn).append($zoomOut); - - $zoomIn.on("click", function() {$parentContainer.trigger("zoom", {"level" : $parentContainer.data("zoomLevel") + 1});}); - $zoomOut.on("click", function() {$parentContainer.trigger("zoom", {"level" : $parentContainer.data("zoomLevel") - 1});}); - - // Panning - $("body").on("mouseup", function(e) { - mousedown = false; - setTimeout(function () {$.fn.mapael.panning = false;}, 50); - }); - - $container.on("mousedown", function(e) { - mousedown = true; - previousX = e.pageX; - previousY = e.pageY; - return false; - }).on("mousemove", function(e) { - var currentLevel = $parentContainer.data("zoomLevel"); - if (mousedown && currentLevel != 0) { - var offsetX = (previousX - e.pageX) / (1 + (currentLevel * options.step)) * (mapWidth / paper.width) - , offsetY = (previousY - e.pageY) / (1 + (currentLevel * options.step)) * (mapHeight / paper.height) - , panX = Math.min(Math.max(0, paper._viewBox[0] + offsetX), (mapWidth - paper._viewBox[2])) - , panY = Math.min(Math.max(0, paper._viewBox[1] + offsetY), (mapHeight - paper._viewBox[3])); - - if (Math.abs(offsetX) > 5 || Math.abs(offsetY) > 5) { - $parentContainer.data({"panX" : panX, "panY" : panY}); - - paper.setViewBox(panX, panY, paper._viewBox[2], paper._viewBox[3]); - - previousX = e.pageX; - previousY = e.pageY; - $.fn.mapael.panning = true; - } - } - return false; - }); - }; - - /** - * Draw a legend for areas and / or plots - * @param legendOptions options for the legend to draw - * @param $container the map container - * @param options map options object - * @param legendType the type of the legend : "area" or "plot" - * @param elems collection of plots or areas on the maps - * @param legendIndex index of the legend in the conf array - */ - $.fn.mapael.drawLegend = function (legendOptions, $container, options, legendType, elems, scale, legendIndex) { - var $legend = {} - , paper = {} - , width = 0 - , height = 0 - , title = {} - , elem = {} - , elemBBox = {} - , label = {} - , i = 0 - , x = 0 - , y = 0 - , yCenter = 0 - , sliceAttrs = [] - , length = 0; - - if (!legendOptions.slices || !legendOptions.display) - return; - - $legend = $("." + legendOptions.cssClass, $container).empty(); - paper = new Raphael($legend.get(0)); - height = width = 0; - - // Set the title of the legend - if(legendOptions.title) { - title = paper.text(legendOptions.marginLeftTitle, 0, legendOptions.title).attr(legendOptions.titleAttrs); - title.attr({y : 0.5 * title.getBBox().height}); - - width = legendOptions.marginLeftTitle + title.getBBox().width; - height += legendOptions.marginBottomTitle + title.getBBox().height; - } - - // Calculate attrs (and width, height and r (radius)) for legend elements, and yCenter for horizontal legends - for(i = 0, length = legendOptions.slices.length; i < length; ++i) { - if (typeof legendOptions.slices[i].legendSpecificAttrs == "undefined") - legendOptions.slices[i].legendSpecificAttrs = {}; - - sliceAttrs[i] = $.extend( - {} - , (legendType == "plot") ? options.map["defaultPlot"].attrs : options.map["defaultArea"].attrs - , legendOptions.slices[i].attrs - , legendOptions.slices[i].legendSpecificAttrs - ); - - if (legendType == "area") { - if (typeof sliceAttrs[i].width == "undefined") - sliceAttrs[i].width = 30; - if (typeof sliceAttrs[i].height == "undefined") - sliceAttrs[i].height = 20; - } else if (legendOptions.slices[i].type == "square") { - if (typeof sliceAttrs[i].width == "undefined") - sliceAttrs[i].width = legendOptions.slices[i].size; - if (typeof sliceAttrs[i].height == "undefined") - sliceAttrs[i].height = legendOptions.slices[i].size; - } else if (legendOptions.slices[i].type == "image") { - if (typeof sliceAttrs[i].width == "undefined") - sliceAttrs[i].width = legendOptions.slices[i].width; - if (typeof sliceAttrs[i].height == "undefined") - sliceAttrs[i].height = legendOptions.slices[i].height; - } else { - if (typeof sliceAttrs[i].r == "undefined") - sliceAttrs[i].r = legendOptions.slices[i].size / 2; - } - - if(legendOptions.slices[i].type == "image" || legendType == "area") { - yCenter = Math.max(yCenter, legendOptions.marginBottomTitle + title.getBBox().height + scale * sliceAttrs[i].height/2); - } else { - yCenter = Math.max(yCenter, legendOptions.marginBottomTitle + title.getBBox().height + scale * sliceAttrs[i].r); - } - } - - if (legendOptions.mode == "horizontal") { - width = legendOptions.marginLeft; - } - - // Draw legend elements (circle, square or image in vertical or horizontal mode) - for(i = 0, length = legendOptions.slices.length; i < length; ++i) { - if (typeof legendOptions.slices[i].display == "undefined" || legendOptions.slices[i].display == true) { - if(legendType == "area") { - if (legendOptions.mode == "horizontal") { - x = width + legendOptions.marginLeft; - y = yCenter - (0.5 * scale * sliceAttrs[i].height); - } else { - x = legendOptions.marginLeft; - y = height; - } - - elem = paper.rect(x, y, scale * (sliceAttrs[i].width), scale * (sliceAttrs[i].height)); - } else if(legendOptions.slices[i].type == "square") { - if (legendOptions.mode == "horizontal") { - x = width + legendOptions.marginLeft; - y = yCenter - (0.5 * scale * sliceAttrs[i].height); - } else { - x = legendOptions.marginLeft; - y = height; - } - - elem = paper.rect(x, y, scale * (sliceAttrs[i].width), scale * (sliceAttrs[i].height)); - - } else if(legendOptions.slices[i].type == "image") { - if (legendOptions.mode == "horizontal") { - x = width + legendOptions.marginLeft; - y = yCenter - (0.5 * scale * sliceAttrs[i].height); - } else { - x = legendOptions.marginLeft; - y = height; - } - - elem = paper.image( - legendOptions.slices[i].url, x, y, scale * sliceAttrs[i].width, scale * sliceAttrs[i].height); - } else { - if (legendOptions.mode == "horizontal") { - x = width + legendOptions.marginLeft + scale * (sliceAttrs[i].r); - y = yCenter; - } else { - x = legendOptions.marginLeft + scale * (sliceAttrs[i].r); - y = height + scale * (sliceAttrs[i].r); - } - elem = paper.circle(x, y, scale * (sliceAttrs[i].r)); - } - - // Set attrs to the element drawn above - delete sliceAttrs[i].width; - delete sliceAttrs[i].height; - delete sliceAttrs[i].r; - elem.attr(sliceAttrs[i]); - elemBBox = elem.getBBox(); - - // Draw the label associated with the element - if (legendOptions.mode == "horizontal") { - x = width + legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel; - y = yCenter; - } else { - x = legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel; - y = height + (elemBBox.height / 2); - } - - label = paper.text(x, y, legendOptions.slices[i].label).attr(legendOptions.labelAttrs); - - // Update the width and height for the paper - if (legendOptions.mode == "horizontal") { - width += legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel + label.getBBox().width; - if(legendOptions.slices[i].type == "image" || legendType == "area") { - height = Math.max(height, legendOptions.marginBottom + title.getBBox().height + elemBBox.height); - } else { - height = Math.max(height, legendOptions.marginBottomTitle + legendOptions.marginBottom + title.getBBox().height + elemBBox.height); - } - } else { - width = Math.max(width, legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel + label.getBBox().width); - height += legendOptions.marginBottom + elemBBox.height; - } - - $(elem.node).attr({"data-type": "elem", "data-index": i, "data-hidden": 0}); - $(label.node).attr({"data-type": "label", "data-index": i, "data-hidden": 0}); - - // Hide map elements when the user clicks on a legend item - if (legendOptions.hideElemsOnClick.enabled) { - // Hide/show elements when user clicks on a legend element - label.attr({cursor:"pointer"}); - elem.attr({cursor:"pointer"}); - - $.fn.mapael.setHoverOptions(elem, sliceAttrs[i], sliceAttrs[i]); - $.fn.mapael.setHoverOptions(label, legendOptions.labelAttrs, legendOptions.labelAttrsHover); - $.fn.mapael.setHover(paper, elem, label); - $.fn.mapael.handleClickOnLegendElem($container, legendOptions, legendOptions.slices[i], label, elem, elems, legendIndex); - } - } - } - - // VMLWidth option allows you to set static width for the legend - // only for VML render because text.getBBox() returns wrong values on IE6/7 - if (Raphael.type != "SVG" && legendOptions.VMLWidth) - width = legendOptions.VMLWidth; - - paper.setSize(width, height); - return paper; - }; - - /** - * Allow to hide elements of the map when the user clicks on a related legend item - * @param $container the map container - * @param legendOptions options for the legend to draw - * @param sliceOptions options of the slice - * @param label label of the legend item - * @param elem element of the legend item - * @param elems collection of plots or areas displayed on the map - * @param legendIndex index of the legend in the conf array - */ - $.fn.mapael.handleClickOnLegendElem = function($container, legendOptions, sliceOptions, label, elem, elems, legendIndex) { - var hideMapElems = function(e, hideOtherElems) { - var elemValue = 0 - , hidden = $(label.node).attr('data-hidden') - , hiddenNewAttr = (hidden == 0) ? {"data-hidden": 1} : {"data-hidden": 0}; - - if (hidden == 0) { - label.animate({"opacity":0.5}, 300); - } else { - label.animate({"opacity":1}, 300); - } - - for (var id in elems) { - if ($.isArray(elems[id].value)) { - elemValue = elems[id].value[legendIndex]; - } else { - elemValue = elems[id].value; - } - - if ((typeof sliceOptions.sliceValue != "undefined" && elemValue == sliceOptions.sliceValue) - || ((typeof sliceOptions.sliceValue == "undefined") - && (typeof sliceOptions.min == "undefined" || elemValue >= sliceOptions.min) - && (typeof sliceOptions.max == "undefined" || elemValue < sliceOptions.max)) - ) { - (function(id) { - if (hidden == 0) { - elems[id].mapElem.animate({"opacity":legendOptions.hideElemsOnClick.opacity}, 300, "linear", function() {(legendOptions.hideElemsOnClick.opacity == 0) && elems[id].mapElem.hide();}); - elems[id].textElem && elems[id].textElem.animate({"opacity":legendOptions.hideElemsOnClick.opacity}, 300, "linear", function() {(legendOptions.hideElemsOnClick.opacity == 0) && elems[id].textElem.hide();}); - } else { - if (legendOptions.hideElemsOnClick.opacity == 0) { - elems[id].mapElem.show(); - elems[id].textElem && elems[id].textElem.show(); - } - elems[id].mapElem.animate({"opacity":typeof elems[id].mapElem.originalAttrs.opacity != "undefined" ? elems[id].mapElem.originalAttrs.opacity : 1}, 300); - elems[id].textElem && elems[id].textElem.animate({"opacity":typeof elems[id].textElem.originalAttrs.opacity != "undefined" ? elems[id].textElem.originalAttrs.opacity : 1}, 300); - } - })(id); - } - } - - $(elem.node).attr(hiddenNewAttr); - $(label.node).attr(hiddenNewAttr); - - if ((typeof hideOtherElems === "undefined" || hideOtherElems === true) - && typeof legendOptions.exclusive !== "undefined" && legendOptions.exclusive === true - ) { - $("[data-type='elem'][data-hidden=0]", $container).each(function() { - if ($(this).attr('data-index') !== $(elem.node).attr('data-index')) { - $(this).trigger('click', false); - } - }); - } - }; - $(label.node).on("click", hideMapElems); - $(elem.node).on("click", hideMapElems); - - if (typeof sliceOptions.hidden !== "undefined" && sliceOptions.hidden === true) { - $(elem.node).trigger('click', false); - } - }; - - /** - * Create all legends for a specified type (area or plot) - * @param $container the map container - * @param options map options - * @param legendType the type of the legend : "area" or "plot" - * @param elems collection of plots or areas displayed on the map - * @param scale scale ratio of the map - */ - $.fn.mapael.createLegends = function ($container, options, legendType, elems, scale) { - var legends = []; - - if ($.isArray(options.legend[legendType])) { - for (var j = 0; j < options.legend[legendType].length; ++j) { - legends.push($.fn.mapael.drawLegend(options.legend[legendType][j], $container, options, legendType, elems, scale, j)); - } - } else { - legends.push($.fn.mapael.drawLegend(options.legend[legendType], $container, options, legendType, elems, scale)); - } - return legends; - }; - - /** - * Set the attributes on hover and the attributes to restore for a map element - * @param elem the map element - * @param originalAttrs the original attributes to restore on mouseout event - * @param attrsHover the attributes to set on mouseover event - */ - $.fn.mapael.setHoverOptions = function (elem, originalAttrs, attrsHover) { - // Disable transform option on hover for VML (IE<9) because of several bugs - if (Raphael.type != "SVG") delete attrsHover.transform; - elem.attrsHover = attrsHover; - - if (elem.attrsHover.transform) elem.originalAttrs = $.extend({transform : "s1"}, originalAttrs); - else elem.originalAttrs = originalAttrs; - }; - - /** - * Set the hover behavior (mouseover & mouseout) for plots and areas - * @param paper Raphael paper object - * @param mapElem the map element - * @param textElem the optional text element (within the map element) - */ - $.fn.mapael.setHover = function (paper, mapElem, textElem) { - var $mapElem = {} - , $textElem = {} - , hoverTO = 0 - , overBehaviour = function() {hoverTO = setTimeout(function () {$.fn.mapael.elemHover(paper, mapElem, textElem);}, 120);} - , outBehaviour = function () {clearTimeout(hoverTO);$.fn.mapael.elemOut(paper, mapElem, textElem);}; - - $mapElem = $(mapElem.node); - $mapElem.on("mouseover", overBehaviour); - $mapElem.on("mouseout", outBehaviour); - - if (textElem) { - $textElem = $(textElem.node); - $textElem.on("mouseover", overBehaviour); - $(textElem.node).on("mouseout", outBehaviour); - } - }; - - /** - * Set he behaviour for "mouseover" event - * @param paper paper Raphael paper object - * @param mapElem mapElem the map element - * @param textElem the optional text element (within the map element) - */ - $.fn.mapael.elemHover = function (paper, mapElem, textElem) { - mapElem.animate(mapElem.attrsHover, mapElem.attrsHover.animDuration); - textElem && textElem.animate(textElem.attrsHover, textElem.attrsHover.animDuration); - paper.safari(); - }; - - /** - * Set he behaviour for "mouseout" event - * @param paper Raphael paper object - * @param mapElem the map element - * @param textElem the optional text element (within the map element) - */ - $.fn.mapael.elemOut = function (paper, mapElem, textElem) { - mapElem.animate(mapElem.originalAttrs, mapElem.attrsHover.animDuration); - textElem && textElem.animate(textElem.originalAttrs, textElem.attrsHover.animDuration); - paper.safari(); - }; - - /** - * Get element options by merging default options, element options and legend options - * @param defaultOptions - * @param elemOptions - * @param legendOptions - */ - $.fn.mapael.getElemOptions = function(defaultOptions, elemOptions, legendOptions) { - var options = $.extend(true, {}, defaultOptions, elemOptions); - if (typeof options.value != "undefined") { - if ($.isArray(legendOptions)) { - for (var i = 0, length = legendOptions.length;i= legend.slices[i].min) - && (typeof legend.slices[i].max == "undefined" || value < legend.slices[i].max)) - ) { - return legend.slices[i]; - } - } - return {}; - }; - - // Default map options - $.fn.mapael.defaultOptions = { - map : { - cssClass : "map" - , tooltip : { - cssClass : "mapTooltip", - target: null - } - , defaultArea : { - attrs : { - fill : "#343434" - , stroke : "#5d5d5d" - , "stroke-width" : 1 - , "stroke-linejoin" : "round" - } - , attrsHover : { - fill : "#f38a03" - , animDuration : 300 - } - , text : { - position : "inner" - , margin : 10 - , attrs : { - "font-size" : 15 - , fill : "#c7c7c7" - } - , attrsHover : { - fill : "#eaeaea" - , "animDuration" : 300 - } - } - , target : "_self" - } - , defaultPlot : { - type : "circle" - , size : 15 - , attrs : { - fill : "#0088db" - , stroke : "#fff" - , "stroke-width" : 0 - , "stroke-linejoin" : "round" - } - , attrsHover : { - "stroke-width" : 3 - , animDuration : 300 - } - , text : { - position : "right" - , margin : 10 - , attrs : { - "font-size" : 15 - , fill : "#c7c7c7" - } - , attrsHover : { - fill : "#eaeaea" - , animDuration : 300 - } - } - , target : "_self" - } - , defaultLink : { - factor : 0.5 - , attrs : { - stroke : "#0088db" - , "stroke-width" : 2 - } - , attrsHover : { - animDuration : 300 - } - , text : { - position : "inner" - , margin : 10 - , attrs : { - "font-size" : 15 - , fill : "#c7c7c7" - } - , attrsHover : { - fill : "#eaeaea" - , animDuration : 300 - } - } - , target : "_self" - } - , zoom : { - enabled : false - , maxLevel : 5 - , step : 0.25 - , zoomInCssClass : "zoomIn" - , zoomOutCssClass : "zoomOut" - , mousewheel : true - } - } - , legend : { - area : [] - , plot : [] - } - , areas : {} - , plots : {} - , links : {} - }; - - $.fn.mapael.legendDefaultOptions = { - area : { - cssClass : "areaLegend" - , display : true - , marginLeft : 10 - , marginLeftTitle : 5 - , marginBottomTitle: 10 - , marginLeftLabel : 10 - , marginBottom : 10 - , titleAttrs : { - "font-size" : 16 - , fill : "#343434" - , "text-anchor" : "start" - } - , labelAttrs : { - "font-size" : 12 - , fill : "#343434" - , "text-anchor" : "start" - } - , labelAttrsHover : { - fill : "#787878" - , animDuration : 300 - } - , hideElemsOnClick : { - enabled : true - , opacity : 0.2 - } - , slices : [] - , mode : "vertical" - } - , plot : { - cssClass : "plotLegend" - , display : true - , marginLeft : 10 - , marginLeftTitle : 5 - , marginBottomTitle: 10 - , marginLeftLabel : 10 - , marginBottom : 10 - , titleAttrs : { - "font-size" : 16 - , fill : "#343434" - , "text-anchor" : "start" - } - , labelAttrs : { - "font-size" : 12 - , fill : "#343434" - , "text-anchor" : "start" - } - , labelAttrsHover : { - fill : "#787878" - , animDuration : 300 - } - , hideElemsOnClick : { - enabled : true - , opacity : 0.2 - } - , slices : [] - , mode : "vertical" - } - }; -})(jQuery); diff --git a/html/mix-manifest.json b/html/mix-manifest.json index 8f4d5e172d..c10d753ea3 100644 --- a/html/mix-manifest.json +++ b/html/mix-manifest.json @@ -3,10 +3,10 @@ "/css/app.css": "/css/app.css?id=5da3bf931f2f95a17884", "/js/manifest.js": "/js/manifest.js?id=3c768977c2574a34506e", "/js/vendor.js": "/js/vendor.js?id=29212a758157c575d7f8", - "/js/lang/de.js": "/js/lang/de.js?id=18b0b0e06813d1afed92", - "/js/lang/en.js": "/js/lang/en.js?id=41955f4356f6511b76b6", - "/js/lang/fr.js": "/js/lang/fr.js?id=4f329163511445d92a17", - "/js/lang/ru.js": "/js/lang/ru.js?id=e10e85f321f1395378b6", - "/js/lang/uk.js": "/js/lang/uk.js?id=c8d4937e3ca47b60b7ac", - "/js/lang/zh-TW.js": "/js/lang/zh-TW.js?id=8020327e80ac10c0c615" + "/js/lang/de.js": "/js/lang/de.js?id=8c1c390a5f45ac01d54b", + "/js/lang/en.js": "/js/lang/en.js?id=14d93644610d1daa14af", + "/js/lang/fr.js": "/js/lang/fr.js?id=21b66f3f48a3f67ba443", + "/js/lang/ru.js": "/js/lang/ru.js?id=1a4435677a27aa615af1", + "/js/lang/uk.js": "/js/lang/uk.js?id=6ce358a9e9387947ee03", + "/js/lang/zh-TW.js": "/js/lang/zh-TW.js?id=3ad4a3e6a5a59165e806" } diff --git a/includes/html/common/availability-map.inc.php b/includes/html/common/availability-map.inc.php index 9ce74c943c..fbe54e0337 100644 --- a/includes/html/common/availability-map.inc.php +++ b/includes/html/common/availability-map.inc.php @@ -66,7 +66,7 @@ if (defined('SHOW_SETTINGS')) {
-
+
diff --git a/includes/html/common/device-summary-horiz.inc.php b/includes/html/common/device-summary-horiz.inc.php deleted file mode 100644 index 3b54fbebba..0000000000 --- a/includes/html/common/device-summary-horiz.inc.php +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - ' . (\LibreNMS\Config::get('summary_errors') ? '' : '') . ' - - - - - - - - - - - ' . (\LibreNMS\Config::get('summary_errors') ? '' : '') . ' - - - - - - - - - ' . (\LibreNMS\Config::get('summary_errors') ? '' : '') . ' - '; -if (\LibreNMS\Config::get('show_services')) { - $temp_output .= ' - - - - - - - - ' . (\LibreNMS\Config::get('summary_errors') ? '' : '') . ' - '; -} -$temp_output .= ' - -
 TotalUpDownIgnoredDisabledErrored
Devices'.$devices['count'].' '.$devices['up'].' '.$devices['down'].' '.$devices['ignored'].' '.$devices['disabled'].'-
Ports'.$ports['count'].' '.$ports['up'].' '.$ports['down'].' '.$ports['ignored'].' '.$ports['shutdown'].' ' . $ports['errored'] . '
Services'.$services['count'].''.$services['up'].' '.$services['down'].' '.$services['ignored'].' '.$services['disabled'].'-
-
-'; - -unset($common_output); -$common_output[] = $temp_output; diff --git a/includes/html/common/device-summary-vert.inc.php b/includes/html/common/device-summary-vert.inc.php deleted file mode 100644 index 60f037f61c..0000000000 --- a/includes/html/common/device-summary-vert.inc.php +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - -'; - -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -$temp_output .= ' - - - - - - - -'; -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -$temp_output .= ' - - - - - -'; - -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -$temp_output .= ' - - - - - -'; - -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -$temp_output .= ' - - - - - -'; - -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -if (Config::get('summary_errors')) { - $temp_output .= ' - - - - - -'; - if (Config::get('show_services')) { - $temp_output .= ' - -'; - } -} - -$temp_output .= ' - - - - - -'; - -if (Config::get('show_services')) { - $temp_output .= ' - -'; -} - -$temp_output .= ' - - -
SummaryDevicesPortsServices
Up'. $devices['up'] .''. $ports['up'] .''. $services['up'] .'
Down'. $devices['down'] .''. $ports['down'] .''. $services['down'] .'
Ignored'. $devices['ignored'] .''. $ports['ignored'] .''. $services['ignored'] .'
Disabled/Shutdown'. $devices['disabled'] .''. $ports['shutdown'] .''. $services['disabled'] .'
Errored- '.$ports['errored'].'-
Total'. $devices['count'] .''. $ports['count'] .''. $services['count'] .'
-
-'; - -unset($common_output); -$common_output[] = $temp_output; diff --git a/includes/html/common/globe.inc.php b/includes/html/common/globe.inc.php deleted file mode 100644 index 312692d9bf..0000000000 --- a/includes/html/common/globe.inc.php +++ /dev/null @@ -1,106 +0,0 @@ - - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* - * Custom Frontpage - * @author f0o - * @copyright 2014 f0o, LibreNMS - * @license GPL - * @package LibreNMS - * @subpackage Frontpage - */ - -$temp_output .= " - -
-"; - -unset($common_output); -$common_output[] = $temp_output; diff --git a/includes/html/front/boxes.inc.php b/includes/html/front/boxes.inc.php deleted file mode 100644 index 28d85c82d6..0000000000 --- a/includes/html/front/boxes.inc.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * 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. - */ - -echo ' -
-'; - -foreach (get_matching_files(\LibreNMS\Config::get('html_dir') . '/includes/front/', '/^top_.*\.php$/') as $file) { - if (($file == 'top_ports.inc.php' && \LibreNMS\Config::get('top_ports') == 0) || ($file == 'top_device_bits.inc.php' && \LibreNMS\Config::get('top_devices') == 0)) { - } else { - echo "
\n"; - include_once $file; - echo "
\n"; - } -} - -echo "
\n"; diff --git a/includes/html/front/top_device_bits.inc.php b/includes/html/front/top_device_bits.inc.php deleted file mode 100644 index 6903a7caa4..0000000000 --- a/includes/html/front/top_device_bits.inc.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * 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. - */ - -$minutes = 15; -$seconds = ($minutes * 60); -$top = \LibreNMS\Config::get('front_page_settings.top.devices'); -if (Auth::user()->hasGlobalRead()) { - $query = " - SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total - FROM ports as p, devices as d - WHERE d.device_id = p.device_id - AND unix_timestamp() - p.poll_time < $seconds - AND ( p.ifInOctets_rate > 0 - OR p.ifOutOctets_rate > 0 ) - GROUP BY d.device_id - ORDER BY total desc - LIMIT $top - "; -} else { - $query = " - SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total - FROM ports as p, devices as d, `devices_perms` AS `P` - WHERE `P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id` AND - d.device_id = p.device_id - AND unix_timestamp() - p.poll_time < $seconds - AND ( p.ifInOctets_rate > 0 - OR p.ifOutOctets_rate > 0 ) - GROUP BY d.device_id - ORDER BY total desc - LIMIT $top - "; - $param[] = array(Auth::id()); -}//end if - -echo "Top $top devices (last $minutes minutes)\n"; -echo "\n"; -foreach (dbFetchRows($query, $param) as $result) { - echo ''.''.''."\n"; -} - -echo "
'.generate_device_link($result, shorthost($result['hostname'])).''.generate_device_link($result, generate_minigraph_image($result, \LibreNMS\Config::get('time.day'), \LibreNMS\Config::get('time.now'), 'device_bits', 'no', 150, 21, '&', 'top10'), array(), 0, 0, 0).'
\n"; diff --git a/includes/html/front/top_ports.inc.php b/includes/html/front/top_ports.inc.php deleted file mode 100644 index 014839e16d..0000000000 --- a/includes/html/front/top_ports.inc.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * 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. - */ - -$minutes = 15; -$seconds = ($minutes * 60); -$top = \LibreNMS\Config::get('front_page_settings.top.ports'); -if (Auth::user()->hasGlobalRead()) { - $query = " - SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total - FROM ports as p, devices as d - WHERE d.device_id = p.device_id - AND unix_timestamp() - p.poll_time < $seconds - AND ( p.ifInOctets_rate > 0 - OR p.ifOutOctets_rate > 0 ) - ORDER BY total desc - LIMIT $top - "; -} else { - $query = " - SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total - FROM ports as I, devices as d, - `devices_perms` AS `P`, `ports_perms` AS `PP` - WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `d`.`device_id`)) AND - d.device_id = I.device_id - AND unix_timestamp() - I.poll_time < $seconds - AND ( I.ifInOctets_rate > 0 - OR I.ifOutOctets_rate > 0 ) - ORDER BY total desc - LIMIT $top - "; - $param[] = array( - Auth::id(), - Auth::id(), - ); -}//end if - -echo "Top $top ports (last $minutes minutes)\n"; -echo "\n"; -foreach (dbFetchRows($query, $param) as $result) { - $result = cleanPort($result); - echo ''.''.''.''."\n"; -} - -echo "
'.generate_device_link($result, shorthost($result['hostname'])).''.generate_port_link($result).''.generate_port_link($result, generate_port_thumbnail($result)).'
\n"; diff --git a/includes/html/pages/front/default.php b/includes/html/pages/front/default.php deleted file mode 100644 index dcebac2513..0000000000 --- a/includes/html/pages/front/default.php +++ /dev/null @@ -1,258 +0,0 @@ -
- -
- - $content -
"; -}//end generate_front_box() - - -echo ' -
-'; -if (Config::get('vertical_summary')) { - echo '
'; -} else { - echo '
'; -} - -echo ' -
-
-'; - -echo '
'; - -echo '
'; - -$count_boxes = 0; - -// Device down boxes -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT " . Config::get('front_page_down_box_limit'); -} else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . Auth::id() . "' AND D.status = '0' AND D.ignore = '0' LIMIT" . Config::get('front_page_down_box_limit'); -} - -foreach (dbFetchRows($sql) as $device) { - generate_front_box( - 'device-down', - generate_device_link($device, shorthost($device['hostname'])) . '
- Device Down
- ' . truncate($device['location'], 20) . '' - ); - ++$count_boxes; -} - -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT " . Config::get('front_page_down_box_limit'); -} else { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . Auth::id() . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0' AND `D`.`status` = '1' LIMIT " . Config::get('front_page_down_box_limit'); -} - -// These things need to become more generic, and more manageable across different frontpages... rewrite inc :> -// Port down boxes -if (Config::get('warn.ifdown')) { - foreach (dbFetchRows($sql) as $interface) { - if (!$interface['deleted']) { - $interface = cleanPort($interface); - generate_front_box( - 'alert alert-danger', - generate_device_link($interface, shorthost($interface['hostname'])) . "
- Port Down
- - " . generate_port_link($interface, substr(makeshortif($interface['label']), 0, 13)) . '
- ' . ($interface['ifAlias'] ? '' . substr($interface['ifAlias'], 0, 20) . '' : '') - ); - ++$count_boxes; - } - } -} - -/* - FIXME service permissions? seem nonexisting now.. */ -// Service down boxes -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = '2' AND D.ignore = '0' AND S.service_ignore = '0' LIMIT " . Config::get('front_page_down_box_limit'); - $param[] = ''; -} else { - $sql = "SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '2' LIMIT " . Config::get('front_page_down_box_limit'); - $param[] = Auth::id(); -} - -foreach (dbFetchRows($sql, $param) as $service) { - generate_front_box( - 'service-down', - generate_device_link($service, shorthost($service['hostname'])) . '
- Service Down - ' . $service['service_type'] . '
- ' . truncate($interface['ifAlias'], 20) . '' - ); - ++$count_boxes; -} - -// BGP neighbour down boxes -if (Config::get('enable_bgp')) { - if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . Config::get('front_page_down_box_limit'); - } else { - $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . Auth::id() . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . Config::get('front_page_down_box_limit'); - } - - foreach (dbFetchRows($sql) as $peer) { - generate_front_box( - 'bgp-down', - generate_device_link($peer, shorthost($peer['hostname'])) . "
- BGP Down - " . $peer['bgpPeerIdentifier'] . '
- AS' . substr($peer['bgpPeerRemoteAs'] . ' ' . $peer['astext'], 0, 14) . '' - ); - ++$count_boxes; - } -} - -// Device rebooted boxes -if (filter_var(Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false && Config::get('uptime_warning') > 0 && !Config::get("os.{$device['os']}.bad_uptime")) { - if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . Config::get('uptime_warning') . "' AND D.ignore = 0 LIMIT " . Config::get('front_page_down_box_limit'); - } else { - $sql = "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . Auth::id() . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" . Config::get('uptime_warning') . "' AND D.ignore = 0 LIMIT " . Config::get('front_page_down_box_limit'); - } - - foreach (dbFetchRows($sql) as $device) { - generate_front_box( - 'device-rebooted', - generate_device_link($device, shorthost($device['hostname'])) . '
- Device Rebooted
- ' . formatUptime($device['uptime'], 'short') . '' - ); - ++$count_boxes; - } -} - -if ($count_boxes == 0) { - echo "
Nothing here yet

This is where status notifications about devices and services would normally go. You might have none - because you run such a great network, or perhaps you've just started using " . Config::get('project_name') . ". If you're new to " . Config::get('project_name') . ', you might - want to start by adding one or more devices in the Devices menu.

'; -} - -echo '
'; -echo '
'; -echo '
'; -echo ' -
-
-'; - -if (Config::get('vertical_summary')) { - echo '
'; - include_once 'includes/html/device-summary-vert.inc.php'; - echo implode('', $common_output); -} else { - echo '
'; - include_once 'includes/html/common/device-summary-horiz.inc.php'; - echo implode('', $common_output); -} - -echo ' -
-
-
-
-'; - -if (Config::get('enable_syslog')) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '" . Config::get('dateformat.mysql.compact') . "') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; - - echo '
-
-
-   -
-
-
-
-
-
- Syslog entries -
- '; - - foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; - } - - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; -} else { - if (Auth::user()->hasGlobalRead()) { - $query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15'; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . Auth::id() . ' ORDER BY `datetime` DESC LIMIT 0,15'; - $alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ' . Auth::id() . ' ORDER BY `time_logged` DESC LIMIT 0,15'; - } - - echo '
-
-
-   -
-
-
-
-
-
- Alertlog entries -
- '; - - foreach (dbFetchRows($alertquery) as $alert_entry) { - include 'includes/html/print-alerts.inc.php'; - } - - echo '
-
-
-
-
-
- Eventlog entries -
- '; - - foreach (dbFetchRows($query) as $entry) { - include 'includes/html/print-event.inc.php'; - } - - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; -}//end if - -?> - -
- -
diff --git a/includes/html/pages/front/demo.php b/includes/html/pages/front/demo.php deleted file mode 100644 index 9957591d2c..0000000000 --- a/includes/html/pages/front/demo.php +++ /dev/null @@ -1,177 +0,0 @@ -
- -
- - - '; - -$dev_list = array( - '6' => 'Central Fileserver', - '7' => 'NE61 Fileserver', - '34' => 'DE56 Fileserver', -); - -foreach ($dev_list as $device_id => $descr) { - echo ''; -}//end foreach - -echo '
- -
'; - echo "
".$descr.'
'; - $graph_array['height'] = '100'; - $graph_array['width'] = '310'; - $graph_array['to'] = \LibreNMS\Config::get('time.now'); - $graph_array['device'] = $device_id; - $graph_array['type'] = 'device_bits'; - $graph_array['from'] = \LibreNMS\Config::get('time.day'); - $graph_array['legend'] = 'no'; - $graph_array['popup_title'] = $descr; - // $graph_array['link'] = generate_device_link($device_id); - print_graph_popup($graph_array); - - $graph_array['height'] = '50'; - $graph_array['width'] = '180'; - - echo "
"; - $graph_array['type'] = 'device_ucd_memory'; - print_graph_popup($graph_array); - echo '
'; - - echo "
"; - $graph_array['type'] = 'device_processor'; - print_graph_popup($graph_array); - echo '
'; - - echo "
"; - $graph_array['type'] = 'device_storage'; - print_graph_popup($graph_array); - echo '
'; - - echo "
"; - $graph_array['type'] = 'device_diskio'; - print_graph_popup($graph_array); - echo '
'; - - echo '
'; - -?> - - - - - - '0' AND A.attrib_value < '86400'"; - -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; - } -} - -$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id'])) { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device Down
- ".truncate($device['location'], 35).' -
'; - } -} - -if (\LibreNMS\Config::get('warn.ifdown')) { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
- ".generate_device_link($interface, shorthost($interface['hostname']))."
- Port Down
- ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
- '.truncate($interface['ifAlias'], 15).' -
'; - } - } -} - -$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - if (device_permitted($service['device_id'])) { - echo "
- ".generate_device_link($service, shorthost($service['hostname']))."
- Service Down
- ".$service['service_type'].'
- '.truncate($interface['ifAlias'], 15).' -
'; - } -} - -$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
- ".generate_device_link($peer, shorthost($peer['hostname']))."
- BGP Down
- ".$peer['bgpPeerIdentifier'].'
- AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
'; - } -} - -if (filter_var(\LibreNMS\Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false && \LibreNMS\Config::get('uptime_warning') > 0) { - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE - A.attrib_value < '" . \LibreNMS\Config::get('uptime_warning') . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < \LibreNMS\Config::get('uptime_warning') && $device['attrib_type'] == 'uptime') { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device
Rebooted

- ".formatUptime($device['attrib_value']).' -
'; - } - } -} - -echo " -
$errorboxes
- -

Recent Syslog Messages

- "; - -$sql = "SELECT *, DATE_FORMAT(timestamp, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') AS date from `syslog` ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; -} - -echo '
'; - -?> - - - - - diff --git a/includes/html/pages/front/example2.php b/includes/html/pages/front/example2.php deleted file mode 100644 index 5f7b29142d..0000000000 --- a/includes/html/pages/front/example2.php +++ /dev/null @@ -1,155 +0,0 @@ -
- -
- - - -?> - '0' AND A.attrib_value < '86400'"; - -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; - } -} - -$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - echo "
-
".generate_device_link($device, shorthost($device['hostname']))."
- Device Down - ".truncate($device['location'], 20).' -
'; -} - -$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; -foreach (dbFetchRows($sql) as $interface) { - echo "
-
".generate_device_link($interface, shorthost($interface['hostname']))."
- Port Down - ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
- '.truncate($interface['ifAlias'], 20).' -
'; -} - -$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - echo "
-
".generate_device_link($service, shorthost($service['hostname']))."
- Service Down - ".$service['service_type'].'
- '.truncate($interface['ifAlias'], 20).' -
'; -} - -$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - echo "
-
".generate_device_link($peer, shorthost($peer['hostname']))."
- BGP Down - ".$peer['bgpPeerIdentifier'].'
- AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
'; -} - -if (filter_var(\LibreNMS\Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false && \LibreNMS\Config::get('uptime_warning') > 0) { - $sql = "SELECT * FROM `devices` AS D, devices_attribs AS A WHERE A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value < '" . \LibreNMS\Config::get('uptime_warning') . "'"; - foreach (dbFetchRows($sql) as $device) { - echo "
-
".generate_device_link($device, shorthost($device['hostname']))."
- Device
Rebooted

- ".formatUptime($device['attrib_value']).' -
'; - } -} - -echo " - -
$errorboxes
- -

Recent Syslog Messages

- - "; - -$sql = "SELECT *, DATE_FORMAT(timestamp, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; -echo '
-
Devices with Alerts
Host
Int
Srv
'; -foreach (dbFetchRows($sql) as $entry) { - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; -} - -echo '
'; - -echo '
- - - '; - -// this stuff can be customised to show whatever you want.... -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'L2TP: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= \LibreNMS\Config::get('mydomain') . "' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['l2tp'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= \LibreNMS\Config::get('mydomain') . "' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Server: thlon-pbx%' AND I.device_id = D.device_id AND D.hostname LIKE '%"; - $sql .= \LibreNMS\Config::get('mydomain') . "' ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['voip'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - if ($ports['transit']) { - echo "', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >" . "
Internet Transit
" . "
"; - } - - if ($ports['l2tp']) { - echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >" . "
L2TP ADSL
" . "
"; - } - - if ($ports['voip']) { - echo "', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 250);\" onmouseout=\"return nd();\" >" . "
VoIP to PSTN
" . "
"; - } -}//end if - -// END VOSTRON -?> - - - - - diff --git a/includes/html/pages/front/globe.php b/includes/html/pages/front/globe.php deleted file mode 100644 index ea851304ae..0000000000 --- a/includes/html/pages/front/globe.php +++ /dev/null @@ -1,134 +0,0 @@ -
- -
- - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* - * Custom Frontpage - * @author f0o - * @copyright 2014 f0o, LibreNMS - * @license GPL - * @package LibreNMS - * @subpackage Frontpage - */ - -?> - - - - -
-
-'; - -include_once 'includes/html/common/globe.inc.php'; -echo implode(',', $common_output); - -echo ' -
-
-
-
-
'; - include_once("includes/html/device-summary-vert.inc.php"); -echo '
-
-
-
'; - include_once("includes/html/front/boxes.inc.php"); -echo '
-
-
-
-
-
-
'; - $device['device_id'] = '-1'; - require_once('includes/html/common/alerts.inc.php'); - echo implode('', $common_output); - unset($device['device_id']); -echo '
-
-
'; - -//From default.php - This code is not part of above license. -if (\LibreNMS\Config::get('enable_syslog')) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') AS date from syslog ORDER BY seq DESC LIMIT 20"; - echo('
-
-
-   -
-
-
-
-
-
- Syslog entries -
- '); - - foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; - } - echo("
"); - echo("
"); - echo("
"); - echo("
"); - echo("
"); -} else { - if (Auth::user()->hasGlobalAdmin()) { - $query = "SELECT *,DATE_FORMAT(datetime, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = - P.device_id AND P.user_id = " . Auth::id() . " ORDER BY `datetime` DESC LIMIT 0,15"; - } - - echo('
-
-
-   -
-
-
-
-
-
- Eventlog entries -
- '); - - foreach (dbFetchRows($query) as $entry) { - include 'includes/html/print-event.inc.php'; - } - - echo("
"); - echo("
"); - echo("
"); - echo("
"); - echo("
"); -} diff --git a/includes/html/pages/front/jt.php b/includes/html/pages/front/jt.php deleted file mode 100644 index 1ece2a9604..0000000000 --- a/includes/html/pages/front/jt.php +++ /dev/null @@ -1,227 +0,0 @@ -
- -
- - - - - - - -
- 0) { - $uptimesql = " AND A.attrib_value < '" . Config::get('uptime_warning') . "'"; -} - -$sql = "SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql; - -foreach (dbFetchRows($sql) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; - } -} - -$sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; -foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id'])) { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device Down
- ".truncate($device['location'], 35).' -
'; - } -} - -if (Config::get('warn.ifdown')) { - $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; - foreach (dbFetchRows($sql) as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
- ".generate_device_link($interface, shorthost($interface['hostname']))."
- Port Down
- ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
- '.truncate($interface['ifAlias'], 15).' -
'; - } - } -} - -$sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; -foreach (dbFetchRows($sql) as $service) { - if (device_permitted($service['device_id'])) { - echo "
- ".generate_device_link($service, shorthost($service['hostname']))."
- Service Down
- ".$service['service_type'].'
- '.truncate($interface['ifAlias'], 15).' -
'; - } -} - -$sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; -foreach (dbFetchRows($sql) as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
- ".generate_device_link($peer, shorthost($peer['hostname']))."
- BGP Down
- ".$peer['bgpPeerIdentifier'].'
- AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
'; - } -} - -if (filter_var(Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false && Config::get('uptime_warning') > 0) { - $sql = "SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < '" . Config::get('uptime_warning') . "' AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'"; - foreach (dbFetchRows($sql) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < Config::get('uptime_warning') && $device['attrib_type'] == 'uptime') { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device
Rebooted

- ".formatUptime($device['attrib_value']).' -
'; - } - } -} - -echo " - -
$errorboxes
- -

Recent Syslog Messages

- - "; - -$sql = "SELECT *, DATE_FORMAT(timestamp, '" . Config::get('dateformat.mysql.compact') . "') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; -} - -echo '
'; - -echo '
- -
'; - -// this stuff can be customised to show whatever you want.... -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['peering'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $ports['broadband'] = '3294,3295,688,3534'; - $ports['wave_broadband'] = '827'; - - $ports['new_broadband'] = '3659,4149,4121,4108,3676,4135'; - - echo "'; - - echo "'; - - echo "
"; - - if ($ports['broadband'] && $ports['wave_broadband'] && $ports['new_broadband']) { - echo ""; - } - - echo "'; -}//end if - -?> -
diff --git a/includes/html/pages/front/map.php b/includes/html/pages/front/map.php deleted file mode 100644 index e74130a5b9..0000000000 --- a/includes/html/pages/front/map.php +++ /dev/null @@ -1,218 +0,0 @@ -
- -
- - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . */ - -/** - * Custom Frontpage - * @author f0o - * @copyright 2014 f0o, LibreNMS - * @license GPL - * @package LibreNMS - * @subpackage Frontpage - */ - -use LibreNMS\Config; - -if (Config::get('map.engine') == 'leaflet') { - require_once 'includes/html/common/worldmap.inc.php'; - echo implode('', $common_output); -} else { - if (Config::has('mapael.default_map') && is_file(Config::get('html_dir') . '/js/' . Config::get('mapael.default_map'))) { - $default_map = Config::get('mapael.default_map'); - } else { - $default_map = 'maps/world_countries.js'; - } - $map_tmp = preg_split("/\//", $default_map); - $map_name = $map_tmp[count($map_tmp)-1]; - $map_name = str_replace('.js', '', $map_name); - - $map_width = (int)Config::get('mapael.map_width', 800); - $default_zoom = Config::get('mapael.default_zoom', 0); - - - if (Config::has('mapael.default_lat') && Config::has('mapael.default_lng')) { - $init_zoom = "init: { - latitude: " . Config::has('mapael.default_lat') . ", - longitude: " . Config::has('mapael.default_lng') . ", - level: $default_zoom - }\n"; - } - - - -?> - - - - - - - -
-
-
- Alternative content for the map -
-
-
- -
-
'; - include_once 'includes/html/front/boxes.inc.php'; -echo '
-
-
-
'; - include_once 'includes/html/common/device-summary-vert.inc.php'; - echo implode('', $common_output); -echo '
-
-
-
'; - $device['device_id'] = '-1'; - require_once 'includes/html/common/alerts.inc.php'; - echo implode('', $common_output); - unset($device['device_id']); -echo '
-
-
'; - -//From default.php - This code is not part of above license. -if (Config::get('enable_syslog')) { - $sql = "SELECT *, DATE_FORMAT(timestamp, '" . Config::get('dateformat.mysql.compact') . "') AS date from syslog ORDER BY seq DESC LIMIT 20"; - - echo('
-
-
-   -
-
-
-
-
-
- Syslog entries -
- '); - - foreach (dbFetchRows($sql) as $entry) { - $entry = array_merge($entry, device_by_id_cache($entry['device_id'])); - - unset($syslog_output); - include("includes/html/print-syslog.inc.php"); - echo $syslog_output; - } - echo("
"); - echo("
"); - echo("
"); - echo("
"); - echo("
"); -} else { - if (Auth::user()->hasGlobalAdmin()) { - $query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - } else { - $query = "SELECT *,DATE_FORMAT(datetime, '" . Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = - P.device_id AND P.user_id = " . Auth::id() . " ORDER BY `datetime` DESC LIMIT 0,15"; - } - - echo('
-
-
-   -
-
-
-
-
-
- Eventlog entries -
- '); - - foreach (dbFetchRows($query) as $entry) { - include 'includes/html/print-event.inc.php'; - } - - echo("
"); - echo("
"); - echo("
"); - echo("
"); - echo("
"); -} -?> diff --git a/includes/html/pages/front/tiles.php b/includes/html/pages/front/tiles.php deleted file mode 100644 index 7dabc36a6c..0000000000 --- a/includes/html/pages/front/tiles.php +++ /dev/null @@ -1,697 +0,0 @@ - - * - * 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. - */ - -use LibreNMS\Config; - -/* - * Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html - */ - -$no_refresh = true; -$default_dash = get_user_pref('dashboard', 0); - -require_once 'includes/html/modal/alert_notes.inc.php'; -require_once 'includes/html/modal/alert_ack.inc.php'; - -// get all dashboards this user can access and put them into two lists user_dashboards and shared_dashboards -$dashboards = get_dashboards(); -list($user_dashboards, $shared_dashboards) = array_reduce($dashboards, function ($ret, $dash) { - if ($dash['user_id'] == Auth::id()) { - $ret[0][] = $dash; - } else { - $ret[1][] = $dash; - } - return $ret; -}, array()); - -// if the default dashboard doesn't exist, set it to the global default or to 0 -if (!isset($dashboards[$default_dash])) { - $global_default = (int)Config::get('webui.default_dashboard_id'); - $default_dash = isset($dashboards[$global_default]) ? $global_default : 0; -} - -// if there are no possible dashboards, add one -if ($default_dash == 0 && empty($user_dashboards)) { - $new_dash = array( - 'dashboard_name'=>'Default', - 'user_id'=>Auth::id(), - ); - - $dashboard_id = dbInsert($new_dash, 'dashboards'); - $new_dash['dashboard_id'] = $dashboard_id; - $new_dash['username'] = Auth::user()->username; - $vars['dashboard'] = $new_dash; - - if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?', array(Auth::id(),0)) == 1) { - dbUpdate(array('dashboard_id'=>$dashboard_id), 'users_widgets', 'user_id = ? && dashboard_id = ?', array(Auth::id(), 0)); - } -} else { - // load a dashboard - $orig = $vars['dashboard']; - if (!empty($orig) && isset($dashboards[$orig])) { - // specific dashboard - $vars['dashboard'] = $dashboards[$orig]; - } else { - // load a default dashboard - $vars['dashboard'] = $default_dash == 0 ? current($user_dashboards) : $dashboards[$default_dash]; - - // $dashboard was requested, but doesn't exist - if (!empty($orig)) { - Toastr::error('Dashboard #' . $orig . - ' does not exist! Loaded ' . htmlentities($vars['dashboard']['dashboard_name']) . - ' instead.', 'Requested Dashboard Not Found!'); - } - } -} - -$data = dbFetchRows( - 'SELECT `user_widget_id`,`users_widgets`.`widget_id`,`title`,`widget`,`col`,`row`,`size_x`,`size_y`,`refresh` FROM `users_widgets` - LEFT JOIN `widgets` ON `widgets`.`widget_id`=`users_widgets`.`widget_id` WHERE `dashboard_id`=?', - array($vars['dashboard']['dashboard_id']) -); -if (empty($data)) { - $data[] = array('user_widget_id'=>'0','widget_id'=>1,'title'=>'Add a widget','widget'=>'placeholder','col'=>1,'row'=>1,'size_x'=>6,'size_y'=>2,'refresh'=>60); -} - -$data = serialize(json_encode($data)); -$dash_config = unserialize(stripslashes($data)); - -if (empty($vars['bare']) || $vars['bare'] == "no") { - ?> -
-
-
- -
- - -
- - - -
-
-
-
-
-
-
- -
-
- - New Dashboard - - - - - -
-
-
-
-
-
-
-
- -
-
-
-
- -
-
- - Dashboard Name - - - - - - -
-
-
-
-
-
- - - -
-
-
-
- Add Widgets -
- - -
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- - - - - -
- -
- - diff --git a/includes/html/pages/front/traffic.php b/includes/html/pages/front/traffic.php deleted file mode 100644 index 9391d6b6c3..0000000000 --- a/includes/html/pages/front/traffic.php +++ /dev/null @@ -1,188 +0,0 @@ -
- -
- - - - - - - -
- 0) { - $uptimesql = ' AND A.attrib_value < ?'; - $param = [Config::get('uptime_warning')]; -} - -foreach (dbFetchRows("SELECT * FROM `devices` AS D, `devices_attribs` AS A WHERE D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' ".$uptimesql, $param) as $device) { - unset($already); - $i = 0; - while ($i <= count($nodes)) { - $thisnode = $device['device_id']; - if ($nodes[$i] == $thisnode) { - $already = 'yes'; - } - - $i++; - } - - if (!$already) { - $nodes[] = $device['device_id']; - } -} - -foreach (dbFetchRows("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'") as $device) { - if (device_permitted($device['device_id'])) { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device Down
- ".truncate($device['location'], 35).' -
'; - } -} - -if (Config::get('warn.ifdown')) { - foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'") as $interface) { - if (port_permitted($interface['port_id'])) { - echo "
- ".generate_device_link($interface, shorthost($interface['hostname']))."
- Port Down
- ".generate_port_link($interface, makeshortif($interface['ifDescr'])).'
- '.truncate($interface['ifAlias'], 15).' -
'; - } - } -} - -foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'") as $service) { - if (device_permitted($service['device_id'])) { - echo "
- ".generate_device_link($service, shorthost($service['hostname']))."
- Service Down
- ".$service['service_type'].'
- '.truncate($interface['ifAlias'], 15).' -
'; - } -} - -foreach (dbFetchRows("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id") as $peer) { - if (device_permitted($peer['device_id'])) { - echo "
- ".generate_device_link($peer, shorthost($peer['hostname']))."
- BGP Down
- ".$peer['bgpPeerIdentifier'].'
- AS'.$peer['bgpPeerRemoteAs'].' '.truncate($peer['astext'], 10).' -
'; - } -} - -if (filter_var(Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false && Config::get('uptime_warning') > 0) { - foreach (dbFetchRows("SELECT * FROM devices_attribs AS A, `devices` AS D WHERE A.attrib_value < ? AND A.attrib_type = 'uptime' AND A.device_id = D.device_id AND ignore = '0' AND disabled = '0'", [Config::get('uptime_warning')]) as $device) { - if (device_permitted($device['device_id']) && $device['attrib_value'] < Config::get('uptime_warning') && $device['attrib_type'] == 'uptime') { - echo "
- ".generate_device_link($device, shorthost($device['hostname']))."
- Device
Rebooted

- ".formatUptime($device['attrib_value']).' -
'; - } - } -} - -echo " - -
$errorboxes
- -

Recent Syslog Messages

- - "; - -$sql = "SELECT *, DATE_FORMAT(timestamp, '" . Config::get('dateformat.mysql.compact') . "') AS date from syslog,devices WHERE syslog.device_id = devices.device_id ORDER BY seq DESC LIMIT 20"; -echo ''; -foreach (dbFetchRows($sql) as $entry) { - unset($syslog_output); - include 'includes/html/print-syslog.inc.php'; - echo $syslog_output; -} - -echo '
'; - -echo '
- -
'; - -// this stuff can be customised to show whatever you want.... -if (Auth::user()->hasGlobalRead()) { - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Transit: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['transit'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Peering: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['peering'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - $sql = "SELECT * FROM ports AS I, devices AS D WHERE `ifAlias` like 'Core: %' AND I.device_id = D.device_id ORDER BY I.ifAlias"; - unset($seperator); - foreach (dbFetchRows($sql) as $interface) { - $ports['core'] .= $seperator.$interface['port_id']; - $seperator = ','; - } - - echo "
"; - - if ($ports['peering'] && $ports['transit']) { - echo ""; - } - - echo '
'; - - echo "
"; - - if ($ports['transit']) { - echo ""; - } - - if ($ports['peering']) { - echo ""; - } - - if ($ports['core']) { - echo ""; - } - - echo '
'; -}//end if - -?> -
diff --git a/includes/html/print-alerts.inc.php b/includes/html/print-alerts.inc.php deleted file mode 100644 index 2160556b36..0000000000 --- a/includes/html/print-alerts.inc.php +++ /dev/null @@ -1,47 +0,0 @@ - - - '.$alert_entry['time_logged'].' - '; - -if (!isset($alert_entry['device'])) { - $dev = device_by_id_cache($alert_entry['device_id']); - echo ' - '.generate_device_link($dev, shorthost($dev['hostname'])).' - '; -} - -echo ''.htmlspecialchars($alert_entry['name']).''; - -echo ""; -if ($alert_state != '') { - if ($alert_state == '0') { - $fa_icon = 'check'; - $fa_color = 'success'; - $text = 'Ok'; - } elseif ($alert_state == '1') { - $fa_icon = 'remove'; - $fa_color = 'danger'; - $text = 'Alert'; - } elseif ($alert_state == '2') { - $fa_icon = 'info-circle'; - $fa_color = 'muted'; - $text = 'Ack'; - } elseif ($alert_state == '3') { - $fa_icon = 'arrow-down'; - $fa_color = 'warning'; - $text = 'Worse'; - } elseif ($alert_state == '4') { - $fa_icon = 'arrow-up'; - $fa_color = 'info'; - $text = 'Better'; - }//end if - echo " $text"; -} -echo ""; - -echo ''; diff --git a/misc/config_definitions.json b/misc/config_definitions.json index 56c6f7a828..1bea6980a7 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -1532,7 +1532,7 @@ "type": "text" }, "front_page": { - "default": "pages/front/tiles.php", + "default": "default", "type": "text" }, "front_page_down_box_limit": { diff --git a/resources/views/overview/custom/.gitignore b/resources/views/overview/custom/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/resources/views/overview/custom/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/resources/views/overview/default.blade.php b/resources/views/overview/default.blade.php new file mode 100644 index 0000000000..b9d6e587ca --- /dev/null +++ b/resources/views/overview/default.blade.php @@ -0,0 +1,606 @@ +@extends('layouts.librenmsv1') + +@section('title', __('Overview')) + +@section('content') +@if (!$bare) +
+
+
+ +
+ + +
+ + + +
+
+
+ + + +@endif + +
+ +
+@endsection + +@section('javascript') + +@endsection + +@push('scripts') + +@endpush diff --git a/resources/views/overview/simple.blade.php b/resources/views/overview/simple.blade.php new file mode 100644 index 0000000000..26c0b870ab --- /dev/null +++ b/resources/views/overview/simple.blade.php @@ -0,0 +1,124 @@ +@extends('layouts.librenmsv1') + +@section('title', __('Overview')) + +@section('content') + +
+@if (Config::get('vertical_summary')) +
+@else +
+@endif + +
+
+
+
+ + @foreach ($devices_down as $device) +
+ {!! \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) !!} +
+ @lang('Device Down') +
+ {{ \LibreNMS\Util\StringHelpers::shortenText($device->location, 20) }} +
+ @endforeach + + @foreach ($ports_down as $port) +
+ {!! \LibreNMS\Util\Url::deviceLink($port->device, $port->device->shortDisplayName()) !!} +
+ @lang('Port Down') +
+ {!! \LibreNMS\Util\Url::PortLink($port) !!} + @if($port->ifAlias) +
+ {{ \LibreNMS\Util\StringHelpers::shortenText($port->getLabel(), 20) }} + @endif +
+ @endforeach + + @foreach ($services_down as $service) +
+ {!! \LibreNMS\Util\Url::deviceLink($service->device, $service->device->shortDisplayName()) !!} + @lang('Service Down') + {{ $service->service_type }} +
+ @endforeach + + @foreach ($bgp_down as $bgp) +
+ {!! \LibreNMS\Util\Url::deviceLink($bgp->device, $bgp->device->shortDisplayName()) !!} + @lang('BGP Down') + + {{ $bgp->bgpPeerIdentifier }} + +
+ AS{{ \LibreNMS\Util\StringHelpers::shortenText($bgp->bgpPeerRemoteAs . ' ' . $bgp->astext, 14) }} +
+ @endforeach + + @foreach ($devices_uptime as $device) +
+ {!! \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) !!} + @lang('Device Rebooted') +
+ {{ $device->formatUptime(true) }} +
+ @endforeach + +@if( + empty($devices_down) && + empty($ports_down) && + empty($services_down) && + empty($bgp_down) && + empty($devices_uptime) +) +
Nothing here yet
+

+ This is where status notifications about devices and services would normally go. + You might have none because you run such a great network, or perhaps you've just started using {{ Config::get('project_name') }} + If you're new to {{ Config::get('project_name') }}, you might + want to start by adding one or more devices in the Devices menu. +

+@endif + + +@if (count($syslog)) +
+
+
+   +
+
+
+
+
+
+ @lang('Syslog entries') +
+ + @foreach ($syslog as $entry) + + + + + + @endforeach +
{{ $entry->date }}{!! \LibreNMS\Util\Url::deviceLink($entry->device) !!}{{ $entry->program }} : {{ $entry->msg }}
+
+
+
+
+@endif + +
+
+
+
+
+
+ +@endsection diff --git a/routes/web.php b/routes/web.php index 092e6ddb37..3c55a75eec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -32,6 +32,8 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () { Route::resource('users', 'UserController'); Route::get('about', 'AboutController@index'); Route::get('authlog', 'UserController@authlog'); + Route::get('overview', 'OverviewController@index'); + Route::get('/', 'OverviewController@index'); // Maps Route::group(['prefix' => 'maps', 'namespace' => 'Maps'], function () {