From 21ca8bf0b09909c87cfe0a887d4d6fa26dbb7103 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 20 Sep 2018 15:33:03 -0500 Subject: [PATCH] Update syslog display and backend (#9228) * Update syslog display backend select boxes now dynamically load instead of loading all on pageload select and table ajax backends completely redone with Laravel (just syslog for now) duplicate url creation to Url utility class for now (uses Device model instead of array) build short hostname functionality into Device->displayName() helper * Fix whitespace * Some tidying up. Split out displayName() and shortDisplayName() * Enable auto-sizing. Fix small error in Url * Eager load device Use bootstrap theme for select2 --- LibreNMS/Util/Url.php | 216 ++++++++++++++++++ .../Controllers/PaginatedAjaxController.php | 125 ++++++++++ ...ontroller.php => ResolutionController.php} | 6 +- .../Controllers/Select/DeviceController.php | 50 ++++ .../Controllers/Select/SelectController.php | 90 ++++++++ .../Controllers/Select/SyslogController.php | 72 ++++++ .../Controllers/Table/SyslogController.php | 96 ++++++++ .../Controllers/Table/TableController.php | 79 +++++++ app/Models/Device.php | 28 ++- app/Models/Syslog.php | 47 ++++ database/factories/ModelFactory.php | 16 ++ html/includes/common/syslog.inc.php | 13 +- html/includes/table/syslog.inc.php | 102 --------- html/legacy_index.php | 1 + html/pages/syslog.inc.php | 122 ++++++---- resources/views/layouts/librenmsv1.blade.php | 1 + routes/web.php | 11 +- 17 files changed, 915 insertions(+), 160 deletions(-) create mode 100644 LibreNMS/Util/Url.php create mode 100644 app/Http/Controllers/PaginatedAjaxController.php rename app/Http/Controllers/{AjaxController.php => ResolutionController.php} (77%) create mode 100644 app/Http/Controllers/Select/DeviceController.php create mode 100644 app/Http/Controllers/Select/SelectController.php create mode 100644 app/Http/Controllers/Select/SyslogController.php create mode 100644 app/Http/Controllers/Table/SyslogController.php create mode 100644 app/Http/Controllers/Table/TableController.php create mode 100644 app/Models/Syslog.php delete mode 100644 html/includes/table/syslog.inc.php diff --git a/LibreNMS/Util/Url.php b/LibreNMS/Util/Url.php new file mode 100644 index 0000000000..a30d0e386e --- /dev/null +++ b/LibreNMS/Util/Url.php @@ -0,0 +1,216 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace LibreNMS\Util; + +use App\Models\Device; +use Auth; +use Carbon\Carbon; +use LibreNMS\Config; + +class Url +{ + /** + * @param Device $device + * @param string $text + * @param array $vars + * @param int $start + * @param int $end + * @param int $escape_text + * @param int $overlib + * @return string + */ + public static function deviceLink($device, $text = null, $vars = [], $start = 0, $end = 0, $escape_text = 1, $overlib = 1) + { + if (!$start) { + $start = Carbon::now()->subDay(1)->timestamp; + } + + if (!$end) { + $end = Carbon::now()->timestamp; + } + + if (!$text) { + $text = $device->displayName(); + } + + if ($escape_text) { + $text = htmlentities($text); + } + + $class = self::deviceLinkDisplayClass($device); + $graphs = self::getOverviewGraphsForDevice($device); + $url = Url::deviceUrl($device, $vars); + + // beginning of overlib box contains large hostname followed by hardware & OS details + $contents = '
' . $device->displayName() . ''; + if ($device->hardware) { + $contents .= ' - ' . htmlentities($device->hardware); + } + + if ($device->os) { + $contents .= ' - ' . htmlentities(Config::getOsSetting($device->os, 'text')); + } + + if ($device->version) { + $contents .= ' ' . htmlentities($device->version); + } + + if ($device->features) { + $contents .= ' (' . htmlentities($device->features) . ')'; + } + + if ($device->location) { + $contents .= ' - ' . htmlentities($device->location); + } + + $contents .= '
'; + + foreach ((array)$graphs as $entry) { + $graph = isset($entry['graph']) ? $entry['graph'] : 'unknown'; + $graphhead = isset($entry['text']) ? $entry['text'] : 'unknown'; + $contents .= '
'; + $contents .= '' . $graphhead . '
'; + $contents .= Url::minigraphImage($device, $start, $end, $graph); + $contents .= Url::minigraphImage($device, Carbon::now()->subWeek(1)->timestamp, $end, $graph); + $contents .= '
'; + } + + if ($overlib == 0) { + $link = $contents; + } else { + // escape quotes + $contents = str_replace(["'", '"'], "\'", $contents); + $link = Url::overlibLink($url, $text, $contents, $class); + } + + if (Auth::user()->hasGlobalRead() || $device->users()->where('devices_perms.user_id', Auth::id())->exists()) { + return $link; + } else { + return $device->displayName(); + } + } + + public static function deviceUrl($device, $vars = []) + { + return self::generate(['page' => 'device', 'device' => $device->device_id], $vars); + } + + public static function generate($vars, $new_vars = []) + { + $vars = array_merge($vars, $new_vars); + + $url = $vars['page'] . '/'; + unset($vars['page']); + + foreach ($vars as $var => $value) { + if ($value == '0' || $value != '' && !str_contains($var, 'opt') && !is_numeric($var)) { + $url .= $var . '=' . urlencode($value) . '/'; + } + } + + return $url; + } + + public static function overlibLink($url, $text, $contents, $class = null) + { + $contents = "
" . $contents . '
'; + $contents = str_replace('"', "\'", $contents); + if ($class === null) { + $output = '"; + } else { + $output .= '>'; + } + + $output .= $text . ''; + + return $output; + } + + /** + * Generate minigraph image url + * + * @param Device $device + * @param int $start + * @param int $end + * @param string $type + * @param string $legend + * @param int $width + * @param int $height + * @param string $sep + * @param string $class + * @param int $absolute_size + * @return string + */ + public static function minigraphImage($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&', $class = 'minigraph-image', $absolute_size = 0) + { + $vars = ['device=' . $device->device_id, "from=$start", "to=$end", "width=$width", "height=$height", "type=$type", "legend=$legend", "absolute=$absolute_size"]; + return ''; + } + + private static function getOverviewGraphsForDevice($device) + { + if ($device->snmp_disable) { + return Config::getOsSetting('ping', 'over'); + } + + if ($graphs = Config::getOsSetting($device->os, 'over')) { + return $graphs; + } + + if ($os_group = Config::getOsSetting($device->os, 'os_group')) { + $name = key($os_group); + if (isset($os_group[$name]['over'])) { + return $os_group[$name]['over']; + } + } + + return Config::getOsSetting('default', 'over'); + } + + /** + * @param Device $device + * @return string + */ + private static function deviceLinkDisplayClass($device) + { + if ($device->disabled) { + return 'list-device-disabled'; + } + + if ($device->ignore) { + return $device->status ? 'list-device-ignored-up' : 'list-device-ignored'; + } + + return $device->status ? 'list-device' : 'list-device-down'; + } +} diff --git a/app/Http/Controllers/PaginatedAjaxController.php b/app/Http/Controllers/PaginatedAjaxController.php new file mode 100644 index 0000000000..b813e176a3 --- /dev/null +++ b/app/Http/Controllers/PaginatedAjaxController.php @@ -0,0 +1,125 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers; + +use Illuminate\Contracts\Pagination\Paginator; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Http\Request; +use Illuminate\Support\Collection; + +abstract class PaginatedAjaxController extends Controller +{ + /** + * Base rules for this controller. + * + * @return mixed + */ + abstract protected function baseRules(); + + /** + * Defines the base query for this resource + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder + */ + abstract public function baseQuery($request); + + /** + * @param Paginator $paginator + * @return \Illuminate\Http\JsonResponse + */ + abstract protected function formatResponse($paginator); + + /** + * Defines validation rules (will override base validation rules for select2 responses too) + * + * @return array + */ + public function rules() + { + return []; + } + + /** + * Defines search fields will be searched in order + * + * @param \Illuminate\Http\Request $request + * @return array + */ + public function searchFields($request) + { + return []; + } + + /** + * Format an item for display. Default is pass-through + * + * @param Model $model + * @return array|Collection|Model + */ + public function formatItem($model) + { + return $model; + } + + /** + * @param string + * @param Builder $query + * @param array $fields + * @return Builder + */ + protected function search($search, $query, $fields) + { + if ($search) { + $query->where(function ($query) use ($fields, $search) { + /** @var Builder $query */ + foreach ($fields as $field) { + $query->orWhere($field, 'like', '%' . $search . '%'); + } + }); + } + + return $query; + } + + + /** + * Validate the given request with the given rules. + * + * @param \Illuminate\Http\Request $request + * @param array $rules + * @param array $messages + * @param array $customAttributes + * @return void + */ + public function validate(Request $request, array $rules = [], array $messages = [], array $customAttributes = []) + { + $full_rules = array_replace($this->baseRules(), $rules); + + parent::validate($request, $full_rules, $messages, $customAttributes); + } +} diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/ResolutionController.php similarity index 77% rename from app/Http/Controllers/AjaxController.php rename to app/Http/Controllers/ResolutionController.php index 72b355cf71..8a156a4b07 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/ResolutionController.php @@ -4,11 +4,9 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -class AjaxController extends Controller +class ResolutionController extends Controller { - // FIXME do not just pile functions on this controller, create separate controllers - - public function setResolution(Request $request) + public function set(Request $request) { $this->validate($request, [ 'width' => 'required|numeric', diff --git a/app/Http/Controllers/Select/DeviceController.php b/app/Http/Controllers/Select/DeviceController.php new file mode 100644 index 0000000000..67d46824c3 --- /dev/null +++ b/app/Http/Controllers/Select/DeviceController.php @@ -0,0 +1,50 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Select; + +use App\Models\Device; + +class DeviceController extends SelectController +{ + public function searchFields($request) + { + return ['hostname', 'sysName']; + } + + public function baseQuery($request) + { + return Device::hasAccess($request->user())->select('device_id', 'hostname', 'sysName'); + } + + public function formatItem($device) + { + /** @var Device $device */ + return [ + 'id' => $device->device_id, + 'text' => $device->displayName(), + ]; + } +} diff --git a/app/Http/Controllers/Select/SelectController.php b/app/Http/Controllers/Select/SelectController.php new file mode 100644 index 0000000000..b35696f854 --- /dev/null +++ b/app/Http/Controllers/Select/SelectController.php @@ -0,0 +1,90 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Select; + +use App\Http\Controllers\PaginatedAjaxController; +use Illuminate\Contracts\Pagination\Paginator; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Http\Request; + +abstract class SelectController extends PaginatedAjaxController +{ + final protected function baseRules() + { + return [ + 'limit' => 'int', + 'page' => 'int', + 'term' => 'nullable|string', + ]; + } + + /** + * The default method called by the route handler + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function __invoke(Request $request) + { + $this->validate($request, $this->rules()); + $limit = $request->get('limit', 20); + + $query = $this->search($request->get('term'), $this->baseQuery($request), $this->searchFields($request)); + $paginator = $query->simplePaginate($limit); + + return $this->formatResponse($paginator); + } + + /** + * @param Paginator $paginator + * @return \Illuminate\Http\JsonResponse + */ + protected function formatResponse($paginator) + { + return response()->json([ + 'results' => collect($paginator->items())->map([$this, 'formatItem']), + 'pagination' => ['more' => $paginator->hasMorePages()] + ]); + } + + /** + * Default item formatting, should supply at least id and text keys + * Check select2 docs. + * Default implementation uses primary key and the first value in the model + * If only one value is in the model attributes, that is the id and text. + * + * @param Model $model + * @return array + */ + public function formatItem($model) + { + $attributes = collect($model->getAttributes()); + return [ + 'id' => $attributes->count() == 1 ? $attributes->first() : $model->getKey(), + 'text' => $attributes->forget($model->getKeyName())->first(), + ]; + } +} diff --git a/app/Http/Controllers/Select/SyslogController.php b/app/Http/Controllers/Select/SyslogController.php new file mode 100644 index 0000000000..c83a9707c9 --- /dev/null +++ b/app/Http/Controllers/Select/SyslogController.php @@ -0,0 +1,72 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Select; + +class SyslogController extends SelectController +{ + /** + * Defines validation rules (will override base validation rules for select2 responses too) + * + * @return array + */ + public function rules() + { + return [ + 'field' => 'required|in:program,priority', + 'device' => 'nullable|int', + ]; + } + + /** + * Defines search fields will be searched in order + * + * @param \Illuminate\Http\Request $request + * @return array + */ + public function searchFields($request) + { + return [$request->get('field')]; + } + + /** + * Defines the base query for this resource + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder + */ + public function baseQuery($request) + { + /** @var \Illuminate\Database\Eloquent\Builder $query */ + $query = \App\Models\Syslog::hasAccess($request->user()) + ->select($request->get('field'))->distinct(); + + if ($device_id = $request->get('device')) { + $query->where('device_id', $device_id); + } + + return $query; + } +} diff --git a/app/Http/Controllers/Table/SyslogController.php b/app/Http/Controllers/Table/SyslogController.php new file mode 100644 index 0000000000..36c8f4dc1e --- /dev/null +++ b/app/Http/Controllers/Table/SyslogController.php @@ -0,0 +1,96 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Table; + +use App\Models\Syslog; +use Illuminate\Database\Eloquent\Builder; + +class SyslogController extends TableController +{ + public function searchFields($request) + { + return ['msg']; + } + + public function rules() + { + return [ + 'device' => 'nullable|int', + 'program' => 'nullable|string', + 'priority' => 'nullable|string', + 'to' => 'nullable|date', + 'from' => 'nullable|date', + ]; + } + + /** + * Defines the base query for this resource + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder + */ + public function baseQuery($request) + { + /** @var Builder $query */ + $query = Syslog::hasAccess($request->user())->with('device'); + + if ($device_id = $request->get('device')) { + $query->where('device_id', $device_id); + } + + if ($program = $request->get('program')) { + $query->where('program', $program); + } + + if ($priority = $request->get('priority')) { + $query->where('priority', $priority); + } + + if ($from = $request->get('from')) { + $query->where('timestamp', '>=', $from); + } + + if ($to = $request->get('to')) { + $query->where('timestamp', '<=', $to); + } + + return $query; + } + + public function formatItem($syslog) + { + $device = $syslog->device; + + return [ + 'timestamp' => $syslog->timestamp, + 'level' => $syslog->level, + 'device_id' => $device ? \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) : '', + 'program' => $syslog->program, + 'msg' => $syslog->msg, + 'priority' => $syslog->priority, + ]; + } +} diff --git a/app/Http/Controllers/Table/TableController.php b/app/Http/Controllers/Table/TableController.php new file mode 100644 index 0000000000..62bc04a804 --- /dev/null +++ b/app/Http/Controllers/Table/TableController.php @@ -0,0 +1,79 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Table; + +use App\Http\Controllers\PaginatedAjaxController; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Http\Request; + +abstract class TableController extends PaginatedAjaxController +{ + final protected function baseRules() + { + return [ + 'current' => 'int', + 'rowCount' => 'int', + 'searchPhrase' => 'nullable|string', + 'sort.*' => 'in:asc,desc', + ]; + } + + public function __invoke(Request $request) + { + $this->validate($request, $this->rules()); + + /** @var Builder $query */ + $query = $this->baseQuery($request); + + $this->search($request->get('searchPhrase'), $query, $this->searchFields($request)); + + $sort = $request->get('sort', []); + foreach ($sort as $column => $direction) { + $query->orderBy($column, $direction); + } + + $limit = $request->get('rowCount', 25); + $page = $request->get('current', 1); + $paginator = $query->paginate($limit, ['*'], 'page', $page); + + return $this->formatResponse($paginator); + } + + /** + * @param LengthAwarePaginator $paginator + * @return \Illuminate\Http\JsonResponse + */ + protected function formatResponse($paginator) + { + return response()->json([ + 'current' => $paginator->currentPage(), + 'rowCount' => $paginator->count(), + 'rows' => collect($paginator->items())->map([$this, 'formatItem']), + 'total' => $paginator->total(), + ]); + } +} diff --git a/app/Models/Device.php b/app/Models/Device.php index 7b85c31f89..fa601c4301 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -6,6 +6,7 @@ use Fico7489\Laravel\Pivot\Traits\PivotEventTrait; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\JoinClause; +use LibreNMS\Config; use LibreNMS\Exceptions\InvalidIpException; use LibreNMS\Util\IP; use LibreNMS\Util\IPv4; @@ -143,13 +144,38 @@ class Device extends BaseModel */ public function displayName() { - if (\LibreNMS\Config::get('force_ip_to_sysname') && $this->sysName && IP::isValid($this->hostname)) { + if (Config::get('force_ip_to_sysname') && $this->sysName && IP::isValid($this->hostname)) { return $this->sysName; } return $this->hostname; } + /** + * Get the shortened display name of this device. + * Length is always overridden by shorthost_target_length. + * + * @param int $length length to shorten to, will not break up words so may be longer + * @return string + */ + public function shortDisplayName($length = 12) + { + $name = $this->displayName(); + + // IP addresses should not be shortened + if (IP::isValid($name)) { + return $name; + } + + $length = Config::get('shorthost_target_length', $length); + if ($length < strlen($name)) { + $take = substr_count($name, '.', 0, $length) + 1; + return implode('.', array_slice(explode('.', $name), 0, $take)); + } + + return $name; + } + public function formatUptime($short = false) { $result = ''; diff --git a/app/Models/Syslog.php b/app/Models/Syslog.php new file mode 100644 index 0000000000..bd05e42bf7 --- /dev/null +++ b/app/Models/Syslog.php @@ -0,0 +1,47 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Models; + +class Syslog extends BaseModel +{ + protected $table = 'syslog'; + protected $primaryKey = 'seq'; + public $timestamps = false; + + // ---- Query scopes ---- + + public function scopeHasAccess($query, User $user) + { + return $this->hasDeviceAccess($query, $user); + } + + // ---- Define Relationships ---- + + public function device() + { + return $this->belongsTo('App\Models\Device', 'device_id', 'device_id'); + } +} diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index adc041dda1..0cbbb2a597 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -13,6 +13,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ +use Carbon\Carbon; use LibreNMS\Util\IPv4; $factory->define(App\User::class, function (Faker\Generator $faker) { @@ -82,3 +83,18 @@ $factory->define(\App\Models\Ipv4Network::class, function (Faker\Generator $fake 'ipv4_network' => $faker->ipv4 . '/' . $faker->numberBetween(0, 32), ]; }); + +$factory->define(\App\Models\Syslog::class, function (Faker\Generator $faker) { + $facilities = ['kern', 'user', 'mail', 'daemon', 'auth', 'syslog', 'lpr', 'news', 'uucp', 'cron', 'authpriv', 'ftp', 'ntp', 'security', 'console', 'solaris-cron', 'local0', 'local1', 'local2', 'local3', 'local4', 'local5', 'local6', 'local7']; + $levels = ['emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug']; + + return [ + 'facility' => $faker->randomElement($facilities), + 'priority' => $faker->randomElement($levels), + 'level' => $faker->randomElement($levels), + 'tag' => $faker->asciify(str_repeat('*', $faker->numberBetween(0, 10))), + 'timestamp' => Carbon::now(), + 'program' => $faker->asciify(str_repeat('*', $faker->numberBetween(0, 32))), + 'msg' => $faker->text(), + ]; +}); diff --git a/html/includes/common/syslog.inc.php b/html/includes/common/syslog.inc.php index 126f5b8516..d1fb34c0f8 100644 --- a/html/includes/common/syslog.inc.php +++ b/html/includes/common/syslog.inc.php @@ -37,15 +37,14 @@ var syslog_grid = $("#syslog").bootgrid({ post: function () { return { - id: "syslog", - device: "'.mres($vars['device']) .'", - program: "'.mres($vars['program']).'", - priority: "'.mres($vars['priority']).'", - to: "'.mres($vars['to']).'", - from: "'.mres($vars['from']).'", + device: "' . addcslashes($vars['device'], '"') . '", + program: "' . addcslashes($vars['program'], '"') . '", + priority: "' . addcslashes($vars['priority'], '"') . '", + to: "' . addcslashes($vars['to'], '"') . '", + from: "' . addcslashes($vars['from'], '"') . '", }; }, - url: "ajax_table.php" + url: "ajax/table/syslog" }); diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php deleted file mode 100644 index 4c24a4ff53..0000000000 --- a/html/includes/table/syslog.inc.php +++ /dev/null @@ -1,102 +0,0 @@ -= ?'; - $param[] = $vars['from']; -} - -if (!empty($vars['to'])) { - $where .= ' AND timestamp <= ?'; - $param[] = $vars['to']; -} - -if (LegacyAuth::user()->hasGlobalRead()) { - $sql = 'FROM syslog AS S'; - $sql .= ' WHERE '.$where; -} else { - $sql = 'FROM syslog AS S, devices_perms AS P '; - $sql .= 'WHERE S.device_id = P.device_id AND P.user_id = ? AND '; - $sql .= $where; - $param = array_merge(array(LegacyAuth::id()), $param); -} - -$count_sql = "SELECT COUNT(*) $sql"; -$total = dbFetchCell($count_sql, $param); -if (empty($total)) { - $total = 0; -} - -if (!isset($sort) || empty($sort)) { - $sort = 'timestamp 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 S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql"; - -foreach (dbFetchRows($sql, $param) as $syslog) { - $dev = device_by_id_cache($syslog['device_id']); - $response[] = array( - 'label' => generate_priority_label($syslog['priority']), - 'timestamp' => $syslog['date'], - 'level' => $syslog['priority'], - 'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), - 'program' => $syslog['program'], - 'msg' => display($syslog['msg']), - 'priority' => generate_priority_status($syslog['priority']), - ); -} - -$output = array( - 'current' => $current, - 'rowCount' => $rowCount, - 'rows' => $response, - 'total' => $total, -); -echo _json_encode($output); diff --git a/html/legacy_index.php b/html/legacy_index.php index 0e3d729bf1..be4e3bb7a3 100644 --- a/html/legacy_index.php +++ b/html/legacy_index.php @@ -99,6 +99,7 @@ if (empty($config['favicon'])) { + diff --git a/html/pages/syslog.inc.php b/html/pages/syslog.inc.php index 995a323efd..c22866b516 100644 --- a/html/pages/syslog.inc.php +++ b/html/pages/syslog.inc.php @@ -13,12 +13,14 @@ * @author LibreNMS Contributors */ -use LibreNMS\Authentication\LegacyAuth; +use Carbon\Carbon; +use LibreNMS\Config; $no_refresh = true; -$param = array(); +$param = []; +$device_id = (int)$vars['device']; -if ($vars['action'] == 'expunge' && LegacyAuth::user()->hasGlobalAdmin()) { +if ($vars['action'] == 'expunge' && \Auth::user()->hasGlobalAdmin()) { dbQuery('TRUNCATE TABLE `syslog`'); print_message('syslog truncated'); } @@ -35,7 +37,6 @@ $pagetitle[] = 'Syslog'; echo implode('', $common_output); ?> - diff --git a/resources/views/layouts/librenmsv1.blade.php b/resources/views/layouts/librenmsv1.blade.php index cd18ffe86f..4dea6ef8d0 100644 --- a/resources/views/layouts/librenmsv1.blade.php +++ b/resources/views/layouts/librenmsv1.blade.php @@ -37,6 +37,7 @@ + diff --git a/routes/web.php b/routes/web.php index 0af2b7f659..0f8023953d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,7 +30,16 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () { // Ajax routes Route::group(['prefix' => 'ajax'], function () { - Route::post('set_resolution', 'AjaxController@setResolution'); + Route::post('set_resolution', 'ResolutionController@set'); + + Route::group(['prefix' => 'select', 'namespace' => 'Select'], function () { + Route::get('syslog', 'SyslogController'); + Route::get('device', 'DeviceController'); + }); + + Route::group(['prefix' => 'table', 'namespace' => 'Table'], function () { + Route::post('syslog', 'SyslogController'); + }); }); // Debugbar routes need to be here because of catch-all