diff --git a/app/Helpers/response_helper.php b/app/Helpers/response_helper.php index d738ce091..47de56870 100644 --- a/app/Helpers/response_helper.php +++ b/app/Helpers/response_helper.php @@ -431,7 +431,10 @@ function response_create($instance = null) $received_data = $response->meta->received_data; $response->meta->received_data = array(); } - + if ($response->meta->collection === 'devices' and $response->meta->action === 'update' and !empty($response->meta->received_data->attributes->tags)) { + $received_data = $response->meta->received_data; + $response->meta->received_data = array(); + } if ($response->meta->collection === 'search' and $response->meta->action === 'create') { $received_data = $response->meta->received_data; $response->meta->received_data = array(); @@ -515,6 +518,9 @@ function response_create($instance = null) if ($response->meta->collection === 'credentials' and $response->meta->action === 'create') { $response->meta->received_data = $received_data; } + if ($response->meta->collection === 'devices' and $response->meta->action === 'update' and !empty($received_data->attributes->tags)) { + $response->meta->received_data = $received_data; + } // TODO - Why does enterprise return this as a string? $response->meta->limit = intval($response->meta->limit); if (!empty($response->errors)) { diff --git a/app/Models/DevicesModel.php b/app/Models/DevicesModel.php index 97c540559..3d873c7d9 100644 --- a/app/Models/DevicesModel.php +++ b/app/Models/DevicesModel.php @@ -46,6 +46,11 @@ public function collection(object $resp): array $joined_tables = array(); foreach ($resp->meta->filter as $filter) { if (in_array($filter->operator, ['!=', '>=', '<=', '=', '>', '<'])) { + if ($filter->name === 'devices.tags' and $filter->operator === '=') { + $filter->function = 'like'; + $filter->operator = ''; + $filter->value = '"' . $filter->value . '"'; + } $this->builder->{$filter->function}($filter->name . ' ' . $filter->operator, $filter->value); } else { $this->builder->{$filter->function}($filter->name, $filter->value); @@ -71,9 +76,10 @@ public function collection(object $resp): array return array(); } $result = $query->getResult(); + $count = count($result); if (isset($result[0]->type) and isset($result[0]->last_seen_by) and $instance->config->product !== 'community') { - for ($i=0; $i < count($result); $i++) { + for ($i=0; $i < $count; $i++) { # BAD if ($result[$i]->last_seen_by === 'nmap' and ($result[$i]->type === 'unclassified' or $result[$i]->type === 'unknown')) { $result[$i]->audit_class = 'fa fa-times text-danger'; @@ -113,6 +119,18 @@ public function collection(object $resp): array } } } + + if (isset($result[0]->tags)) { + for ($i=0; $i < $count; $i++) { + if (!empty($result[$i]->tags)) { + $result[$i]->tags = @json_decode($result[$i]->tags); + } + if (empty($result[$i]->tags)) { + $result[$i]->tags = array(); + } + } + } + return format_data($result, $resp->meta->collection); } @@ -591,6 +609,14 @@ public function read(int $id = 0): array return array(); } $device = $query->getResult(); + if (isset($device[0]->tags)) { + if (!empty($device[0]->tags)) { + $device[0]->tags = @json_decode($device[0]->tags); + } + if (empty($device[0]->tags)) { + $device[0]->tags = array(); + } + } if (!empty($device[0]->instance_tags)) { $device[0]->instance_tags = json_decode($device[0]->instance_tags); } diff --git a/app/Models/db_upgrades/db_5.1.0.php b/app/Models/db_upgrades/db_5.1.0.php index a29e0c9aa..0e866518f 100644 --- a/app/Models/db_upgrades/db_5.1.0.php +++ b/app/Models/db_upgrades/db_5.1.0.php @@ -8,6 +8,18 @@ log_message('info', (string)$db->getLastQuery()); } +if (!$db->fieldExists('tags', 'devices')) { + $sql = "ALTER TABLE `devices` ADD `tags` text NOT NULL DEFAULT '[]' AFTER kernel_version"; + $query = $db->query($sql); + $output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; + log_message('info', (string)$db->getLastQuery()); +} + +$sql = "UPDATE `configuration` SET `value` = CONCAT(`value`, ',devices.tags') WHERE `name` = 'devices_default_retrieve_columns' AND `value` NOT LIKE '%devices.tags%'"; +$db->query($sql); +$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; +log_message('info', (string)$db->getLastQuery()); + $sql = "DELETE FROM `dashboards` WHERE `name` = 'Summary Dashboard' and `description` = 'Summary Information'"; $db->query($sql); $output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; diff --git a/app/Views/devicesCollection.php b/app/Views/devicesCollection.php index ecdbecaf7..1090caeeb 100644 --- a/app/Views/devicesCollection.php +++ b/app/Views/devicesCollection.php @@ -159,6 +159,12 @@ } } else if ($key === 'ip' and !empty($item->attributes->ip_padded)) { echo " " . $item->attributes->ip_padded . " " . $item->attributes->{$key} . " \n"; + } else if ($key === 'tags') { + echo ""; + foreach ($item->attributes->tags as $tag) { + echo ' '; + } + echo ""; } else { echo "  " . $item->attributes->{$key} . "\n"; } diff --git a/app/Views/devicesRead.php b/app/Views/devicesRead.php index 34a8194d9..6ede0c5be 100644 --- a/app/Views/devicesRead.php +++ b/app/Views/devicesRead.php @@ -56,6 +56,9 @@ snmp_oid)) { ?>
  • + product === 'enterprise') { ?> +
  • +
  • @@ -913,6 +916,25 @@ + product === 'enterprise') { ?> + + +