From 6207bae03a00c885654a6970ef7e09c1607562f5 Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 27 Mar 2015 16:28:09 +0000 Subject: [PATCH] Switched to using Jquery Bootgrid for tables --- .scrutinizer.yml | 2 +- doc/General/Credits.md | 4 + html/ajax_table.php | 49 +++++++ html/css/jquery.bootgrid.min.css | 1 + html/includes/table/eventlog.inc.php | 66 ++++++++++ html/includes/table/poll-log.inc.php | 42 ++++++ html/index.php | 2 + html/js/jquery.bootgrid.min.js | 1 + html/pages/eventlog.inc.php | 123 +++++------------- html/pages/poll-log.inc.php | 59 ++++----- lib/jquery-bootgrid/dist/jquery.bootgrid.js | 3 +- .../dist/jquery.bootgrid.min.js | 2 +- 12 files changed, 224 insertions(+), 130 deletions(-) create mode 100644 html/ajax_table.php create mode 120000 html/css/jquery.bootgrid.min.css create mode 100644 html/includes/table/eventlog.inc.php create mode 100644 html/includes/table/poll-log.inc.php create mode 120000 html/js/jquery.bootgrid.min.js diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 88512ae66..ae5f57668 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -5,4 +5,4 @@ imports: # FIXME: find a way to keep excluded_paths list sorted filter: - excluded_paths: [ html/includes/geshi/*, html/includes/jpgraph/*, html/js/*, includes/phpmailer/*, html/css/*, html/includes/Slim/*, includes/console_color.php, includes/console_table.php, html/lib/* ] + excluded_paths: [ html/includes/geshi/*, html/includes/jpgraph/*, html/js/*, includes/phpmailer/*, html/css/*, html/includes/Slim/*, includes/console_color.php, includes/console_table.php, html/lib/*, lib/* ] diff --git a/doc/General/Credits.md b/doc/General/Credits.md index ed1b32ffb..fbbdf090c 100644 --- a/doc/General/Credits.md +++ b/doc/General/Credits.md @@ -18,6 +18,10 @@ LibreNMS ships with the following software components: http://www.javascripttoolbox.com/lib/mktree/ MIT and GPL License +- Jquery Bootgrid + http://www.jquery-bootgrid.com/ + MIT License + Other components (needs details filled in): - JpGraph (html/includes/jpgraph): QPL 1.0 license diff --git a/html/ajax_table.php b/html/ajax_table.php new file mode 100644 index 000000000..7f906e64a --- /dev/null +++ b/html/ajax_table.php @@ -0,0 +1,49 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if (isset($_REQUEST['debug'])) +{ + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); +} + +include_once("../includes/defaults.inc.php"); +include_once("../config.php"); +include_once("../includes/definitions.inc.php"); +include_once("includes/functions.inc.php"); +include_once("../includes/functions.php"); +include_once("includes/authenticate.inc.php"); + +$current = $_POST['current']; +settype($current,"integer"); +$rowCount = $_POST['rowCount']; +settype($rowCount,"integer"); +if (isset($_POST['sort']) && is_array($_POST['sort'])) { + foreach ($_POST['sort'] as $k=>$v) { + $sort .= " $k $v"; + } +} +$searchPhrase = mres($_POST['searchPhrase']); +$id = mres($_POST['id']); + +if (isset($id)) { + if (file_exists("includes/table/$id.inc.php")) { + require_once "includes/table/$id.inc.php"; + } +} + +?> diff --git a/html/css/jquery.bootgrid.min.css b/html/css/jquery.bootgrid.min.css new file mode 120000 index 000000000..1eb80bea8 --- /dev/null +++ b/html/css/jquery.bootgrid.min.css @@ -0,0 +1 @@ +../../lib/jquery-bootgrid/dist/jquery.bootgrid.min.css \ No newline at end of file diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php new file mode 100644 index 000000000..88b33132b --- /dev/null +++ b/html/includes/table/eventlog.inc.php @@ -0,0 +1,66 @@ += '5') { + $sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where"; +} else { + $sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?"; + $param[] = $_SESSION['user_id']; +} + +$count_sql = "SELECT COUNT(datetime) $sql"; +$total = dbFetchCell($count_sql,$param); + +if (isset($searchPhrase) && !empty($searchPhrase)) { + $sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `E`.`datetime` LIKE '%$searchPhrase%' OR `E`.`message` LIKE '%$searchPhrase%' OR `E`.`type` LIKE '%$searchPhrase%')"; +} + +if (!isset($sort) || empty($sort)) { + $sort = 'datetime DESC'; +} + +$sql .= " ORDER BY $sort"; + +if (isset($current)) { + $limit_low = ($current * $rowCount) - ($rowCount); + $limit_high = $rowCount; +} + +if ($rowCount != -1) { + $sql .= " LIMIT $limit_low,$limit_high"; +} + +$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate $sql"; + +foreach (dbFetchRows($sql,$param) as $eventlog) { + $dev = device_by_id_cache($eventlog['host']); + if ($eventlog['type'] == "interface") { + $this_if = ifLabel(getifbyid($eventlog['reference'])); + $type = "".generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).""; + } else { + $type = "System"; + } + + $response[] = array('datetime'=>$eventlog['humandate'], + 'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])), + 'type'=>$type, + 'message'=>htmlspecialchars($eventlog['message'])); +} + +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +echo _json_encode($output); + +?> diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php new file mode 100644 index 000000000..53ccaa613 --- /dev/null +++ b/html/includes/table/poll-log.inc.php @@ -0,0 +1,42 @@ + " 'graphs', 'group' => 'poller')). "'>" .$device['hostname']. "", + 'last_polled' => $device['last_polled'], + 'last_polled_timetaken' => $device['last_polled_timetaken']); +} + +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +echo _json_encode($output); + +?> diff --git a/html/index.php b/html/index.php index 895263fd0..3a589e7f8 100755 --- a/html/index.php +++ b/html/index.php @@ -164,6 +164,7 @@ if (empty($config['favicon'])) { + @@ -179,6 +180,7 @@ if (empty($config['favicon'])) { +