Firewall / Aliases - add "virtual" properties to model representing the current pf table stats and represent these in the alias grid.

This commit is contained in:
Ad Schellevis 2021-09-21 19:45:56 +02:00
parent c96e5f88b4
commit d6be0bfdb4
3 changed files with 34 additions and 1 deletions

View File

@ -60,7 +60,7 @@ class AliasController extends ApiMutableModelControllerBase
}
return $this->searchBase(
"aliases.alias",
array('enabled', 'name', 'description', 'type', 'content'),
array('enabled', 'name', 'description', 'type', 'content', 'current_items', 'last_updated'),
"name",
$filter_funct
);

View File

@ -31,6 +31,10 @@
namespace OPNsense\Firewall\FieldTypes;
use OPNsense\Base\FieldTypes\ArrayField;
use OPNsense\Base\FieldTypes\TextField;
use OPNsense\Base\FieldTypes\IntegerField;
use OPNsense\Core\Backend;
class AliasField extends ArrayField
{
@ -65,6 +69,33 @@ class AliasField extends ArrayField
]
];
private static $current_stats = null;
protected function actionPostLoadingEvent()
{
if (self::$current_stats === null) {
self::$current_stats = [];
$stats = json_decode((new Backend())->configdRun('filter diag table_size'), true);
if (!empty($stats) && !empty($stats['details'])) {
self::$current_stats = $stats['details'];
}
}
foreach ($this->internalChildnodes as $node) {
if (!$node->getInternalIsVirtual()) {
// generate new unattached fields, which are only usable to read data from (not synched to config.xml)
$current_items = new IntegerField();
$last_updated = new TextField();
if (!empty((string)$node->name) && !empty(self::$current_stats[(string)$node->name])) {
$current_items->setValue(self::$current_stats[(string)$node->name]['count']);
$last_updated->setValue(self::$current_stats[(string)$node->name]['updated']);
}
$node->addChildNode('current_items', $current_items);
$node->addChildNode('last_updated', $last_updated);
}
}
return parent::actionPostLoadingEvent();
}
/**
* create virtual alias nodes
*/

View File

@ -513,6 +513,8 @@
<th data-column-id="type" data-width="12em" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>
<th data-column-id="content" data-type="string">{{ lang._('Content') }}</th>
<th data-column-id="current_items" data-type="string">{{ lang._('Loaded#') }}</th>
<th data-column-id="last_updated" data-type="string">{{ lang._('Last updated') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>