hasGlobalRead()) { $sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`'; $where .= ' AND `DP`.`user_id`=?'; $param[] = Auth::id(); } if (!empty($vars['location'])) { $sql .= " LEFT JOIN `devices_attribs` AS `DB` ON `DB`.`device_id`=`devices`.`device_id` AND `DB`.`attrib_type`='override_sysLocation_bool' AND `DB`.`attrib_value`='1' LEFT JOIN `devices_attribs` AS `DA` ON `devices`.`device_id`=`DA`.`device_id`"; } if (!empty($vars['group']) && is_numeric($vars['group'])) { $sql .= " LEFT JOIN `device_group_device` AS `DG` ON `DG`.`device_id`=`devices`.`device_id`"; $where .= " AND `DG`.`device_group_id`=?"; $param[] = $vars['group']; } $sql .= " WHERE $where "; if (!empty($vars['searchquery'])) { $sql .= ' AND (sysName LIKE ? OR hostname LIKE ? OR hardware LIKE ? OR os LIKE ? OR location LIKE ?)'; $param += array_fill(count($param), 5, '%' . $vars['searchquery'] . '%'); } if (!empty($vars['os'])) { $sql .= ' AND os = ?'; $param[] = $vars['os']; } if (!empty($vars['version'])) { $sql .= ' AND version = ?'; $param[] = $vars['version']; } if (!empty($vars['hardware'])) { $sql .= ' AND hardware = ?'; $param[] = $vars['hardware']; } if (!empty($vars['features'])) { $sql .= ' AND features = ?'; $param[] = $vars['features']; } if (!empty($vars['type'])) { if ($vars['type'] == 'generic') { $sql .= " AND ( type = ? OR type = '')"; $param[] = $vars['type']; } else { $sql .= ' AND type = ?'; $param[] = $vars['type']; } } if (!empty($vars['state'])) { $sql .= ' AND status= ?'; if (is_numeric($vars['state'])) { $param[] = $vars['state']; } else { $param[] = str_replace(array('up', 'down'), array(1, 0), $vars['state']); } } if (!empty($vars['disabled'])) { $sql .= ' AND disabled= ?'; $param[] = $vars['disabled']; } if (!empty($vars['ignore'])) { $sql .= ' AND `ignore`= ?'; $param[] = $vars['ignore']; } if (!empty($vars['location']) && $vars['location'] == 'Unset') { $location_filter = ''; } if (!empty($vars['location'])) { $sql .= " AND `location` = ?"; $param[] = $vars['location']; } $count_sql = "SELECT COUNT(`devices`.`device_id`) $sql"; $total = (int)dbFetchCell($count_sql, $param); if (!isset($sort) || empty($sort)) { $sort = '`hostname` 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 DISTINCT(`devices`.`device_id`),`devices`.* $sql"; if (!isset($vars['format'])) { $vars['format'] = 'list_detail'; } list($format, $subformat) = explode('_', $vars['format']); foreach (dbFetchRows($sql, $param) as $device) { if (isset($bg) && $bg == $config['list_colour']['odd']) { $bg = $config['list_colour']['even']; } else { $bg = $config['list_colour']['odd']; } if ($device['status'] == '0') { $extra = 'label-danger'; } else { $extra = 'label-success'; } if ($device['ignore'] == '1') { $extra = 'label-default'; if ($device['status'] == '1') { $extra = 'label-warning'; } } if ($device['disabled'] == '1') { $extra = 'label-default'; } $type = strtolower($device['os']); $image = getIconTag($device); if ($device['os'] == 'ios') { formatCiscoHardware($device, true); } $device['os_text'] = $config['os'][$device['os']]['text']; $port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); $sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id'])); $wireless_count = dbFetchCell('SELECT COUNT(*) FROM `wireless_sensors` WHERE `device_id` = ?', array($device['device_id'])); $actions = '
'; if (Auth::user()->hasGlobalAdmin()) { $actions .= ''; } if ($subformat == 'detail') { $actions .= '
'; } $actions .= '
'; if (isset($config['gateone']['server'])) { if ($config['gateone']['use_librenms_user'] == true) { $actions .= '
'; } else { $actions .= '
'; } } else { $actions .= '
'; } $actions .= '
'; $hostname = generate_device_link($device); if (extension_loaded('mbstring')) { $location = mb_substr($device['location'], 0, 32, 'utf8'); } else { $location = substr($device['location'], 0, 32); } if ($subformat == 'detail') { $platform = $device['hardware'] . '
' . $device['features']; $os = $device['os_text'] . '
' . $device['version']; $device['ip'] = inet6_ntop($device['ip']); $uptime = formatUptime($device['uptime'], 'short'); $hostname .= '
' . get_device_name($device); $metrics = array(); if ($port_count) { $port_widget = ''; $port_widget .= ' ' . $port_count; $port_widget .= ' '; $metrics[] = $port_widget; } if ($sensor_count) { $sensor_widget = ''; $sensor_widget .= ' ' . $sensor_count; $sensor_widget .= ' '; $metrics[] = $sensor_widget; } if ($wireless_count) { $wireless_widget = ''; $wireless_widget .= ' ' . $wireless_count; $wireless_widget .= ' '; $metrics[] = $wireless_widget; } $col_port = '
'; $col_port .= implode(count($metrics) == 2 ? '
' : '', $metrics); $col_port .= '
'; } else { $platform = $device['hardware']; $os = $device['os_text'] . ' ' . $device['version']; $uptime = formatUptime($device['uptime'], 'short'); $col_port = ''; } $response[] = array( 'extra' => $extra, 'list_type' => $subformat, 'icon' => $image, 'hostname' => $hostname, 'ports' => $col_port, 'hardware' => $platform, 'os' => $os, 'uptime' => $uptime, 'location' => $location, 'actions' => $actions, ); }//end foreach $output = array( 'current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total, ); echo _json_encode($output);