mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
sysutils/dmidecode: new dashboard widget (#4554)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
PLUGIN_NAME= dmidecode
|
||||
PLUGIN_VERSION= 1.1
|
||||
PLUGIN_REVISION= 1
|
||||
PLUGIN_VERSION= 1.2
|
||||
PLUGIN_COMMENT= Display hardware information on the dashboard
|
||||
PLUGIN_DEPENDS= dmidecode
|
||||
PLUGIN_MAINTAINER= evbevz@gmail.com
|
||||
|
||||
+14
-22
@@ -2,6 +2,7 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2019 Smart-Soft
|
||||
* Copyright (C) 2025 Neil Merchant
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -26,27 +27,18 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
require_once("widgets/include/dmidecode.inc");
|
||||
namespace OPNsense\DmiDecode\Api;
|
||||
|
||||
$hardwareData = parse_ini_string(configd_run("dmidecode system"), FALSE, INI_SCANNER_RAW);
|
||||
$biosData = parse_ini_string(configd_run("dmidecode bios"), FALSE, INI_SCANNER_RAW);
|
||||
use OPNsense\Base\ApiControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
?>
|
||||
<table class="table table-striped table-condensed">
|
||||
<tbody>
|
||||
<tr><th colspan="2"><?=gettext("Platform");?></th></tr>
|
||||
<?php foreach($hardwareData as $key => $val) { ?>
|
||||
<tr>
|
||||
<td style="width: 30%;"><?=gettext($key);?></td>
|
||||
<td><?=html_safe($val);?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr><th colspan="2"><?=gettext("BIOS");?></th></tr>
|
||||
<?php foreach($biosData as $key => $val) { ?>
|
||||
<tr>
|
||||
<td style="width: 30%;"><?=gettext($key);?></td>
|
||||
<td><?=html_safe($val);?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
class ServiceController extends ApiControllerBase
|
||||
{
|
||||
public function getAction()
|
||||
{
|
||||
$system = parse_ini_string(trim((new Backend())->configdRun('dmidecode system')), false, INI_SCANNER_RAW);
|
||||
$bios = parse_ini_string(trim((new Backend())->configdRun('dmidecode bios')), false, INI_SCANNER_RAW);
|
||||
$status = "ok";
|
||||
return ["status" => $status, "system" => $system, "bios" => $bios];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<acl>
|
||||
<page-service-dmidecode>
|
||||
<name>Service: DMI Decoder Widget</name>
|
||||
<patterns>
|
||||
<pattern>api/dmidecode/service/get</pattern>
|
||||
</patterns>
|
||||
</page-service-dmidecode>
|
||||
</acl>
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Neil Merchant
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
export default class DmiDecode extends BaseTableWidget {
|
||||
constructor() {
|
||||
super();
|
||||
this.title = 'DmiDecode Data';
|
||||
}
|
||||
|
||||
getMarkup() {
|
||||
let $container = $('<div></div>');
|
||||
// make table for system output, add header
|
||||
let $system_table = super.createTable('system-table', { headerPosition: 'left' });
|
||||
$container.append(`<h3>${this.translations.system}</h3>`)
|
||||
$container.append($system_table);
|
||||
// same for bios output
|
||||
let $bios_table = super.createTable('bios-table', { headerPosition: 'left' });
|
||||
$container.append(`<h3>${this.translations.bios}</h3>`)
|
||||
$container.append($bios_table);
|
||||
return $container;
|
||||
}
|
||||
|
||||
async onMarkupRendered() {
|
||||
const dmiData = await this.ajaxCall('/api/dmidecode/service/get');
|
||||
if (!dmiData || dmiData?.status !== 'ok') {
|
||||
this.displayError('dmi lookup failed');
|
||||
return;
|
||||
}
|
||||
this.processDMIData(dmiData);
|
||||
}
|
||||
|
||||
processDMIData(data) {
|
||||
const sysrows = [];
|
||||
for (const [key, value] of Object.entries(data.system)) {
|
||||
const row = [];
|
||||
// try to find translation for key, fallback to output value
|
||||
// have to split on spaces here because those aren't valid in xml tags
|
||||
const translationIndex = key.split(" ")[0]
|
||||
const dispKey = this.translations[translationIndex] || key
|
||||
row.push(`<div><b>${dispKey}</b></div>`, `<div>${value}</div>`);
|
||||
sysrows.push(row);
|
||||
}
|
||||
const biosrows = [];
|
||||
for (const [key, value] of Object.entries(data.bios)) {
|
||||
const row = [];
|
||||
// try to find translation for key, fallback to output value
|
||||
// have to split on spaces here because those aren't valid in xml tags
|
||||
const translationIndex = key.split(" ")[0]
|
||||
const dispKey = this.translations[translationIndex] || key
|
||||
row.push(`<div><b>${dispKey}</b></div>`, `<div>${value}</div>`);
|
||||
biosrows.push(row);
|
||||
}
|
||||
super.updateTable('system-table', sysrows);
|
||||
super.updateTable('bios-table', biosrows);
|
||||
}
|
||||
|
||||
displayError(message) {
|
||||
// if something went wrong, display error message in system table
|
||||
const $error = $(`
|
||||
<div>
|
||||
${message}
|
||||
</div>
|
||||
`);
|
||||
$('#system-table').empty().append($error);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<metadata>
|
||||
<dmidecode>
|
||||
<filename>DmiDecode.js</filename>
|
||||
<endpoints>
|
||||
<endpoint>/api/dmidecode/service/get</endpoint>
|
||||
</endpoints>
|
||||
<translations>
|
||||
<title>Hardware Information</title>
|
||||
<system>Platform</system>
|
||||
<bios>BIOS</bios>
|
||||
<Manufacturer>Manufacturer</Manufacturer>
|
||||
<Product>Product Name</Product>
|
||||
<Version>Version</Version>
|
||||
<Serial>Serial Number</Serial>
|
||||
<Family>Family</Family>
|
||||
<Vendor>Vendor</Vendor>
|
||||
<Release>Release Date</Release>
|
||||
</translations>
|
||||
</dmidecode>
|
||||
</metadata>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
$dmidecode_title = gettext('Hardware information');
|
||||
Reference in New Issue
Block a user