mac to device name JS function, translation DHCP leases fix

This commit is contained in:
Jokob-sk
2023-08-23 20:00:59 +10:00
parent 64c3de0450
commit 1067211033
14 changed files with 57 additions and 33 deletions

View File

@@ -807,6 +807,7 @@ input[readonly] {
border-top:1px; border-top:1px;
border-top-color:grey; border-top-color:grey;
padding:0px; padding:0px;
padding-top:6px;
margin:0px; margin:0px;
align-items:center; align-items:center;
border-radius:20px; border-radius:20px;

View File

@@ -480,12 +480,32 @@ function navigateToDeviceWithIp (ip) {
window.open(window.location.origin +'/deviceDetails.php?mac=' + mac , "_blank"); window.open(window.location.origin +'/deviceDetails.php?mac=' + mac , "_blank");
} }
}); });
}); });
} }
// -----------------------------------------------------------------------------
function getNameByMacAddress(macAddress) {
const sessionDataKey = 'devicesListAll';
const sessionData = sessionStorage.getItem(sessionDataKey);
if (!sessionData) {
console.log(`Session variable "${sessionDataKey}" not found.`);
return "Unknown";
}
const devices = JSON.parse(sessionData);
for (const device of devices) {
if (device.mac === macAddress) {
return device.name;
}
}
return "Unknown"; // Return a default value if MAC address is not found
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function isEmpty(value) function isEmpty(value)
{ {

View File

@@ -470,7 +470,7 @@
"PIALERT_WEB_PROTECTION_name" : "Enable login", "PIALERT_WEB_PROTECTION_name" : "Enable login",
"PIALERT_WEB_PROTECTION_description" : "When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.", "PIALERT_WEB_PROTECTION_description" : "When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.",
"PIALERT_WEB_PASSWORD_name" : "Login password", "PIALERT_WEB_PASSWORD_name" : "Login password",
"PIALERT_WEB_PASSWORD_description" : "The default password is <code>123456</code>. To change the password run <code>/home/pi/pialert/back/pialert-cli</code> in the container", "PIALERT_WEB_PASSWORD_description" : "The default password is <code>123456</code>. To change the password run <code>/home/pi/pialert/back/pialert-cli</code> in the container or use the <a onclick=\"toggleAllSettings()\" href=\"#SETPWD_RUN\"><code>SETPWD_RUN</code> Set password plugin</a>.",
"INCLUDED_SECTIONS_name" : "Notify on", "INCLUDED_SECTIONS_name" : "Notify on",
"INCLUDED_SECTIONS_description" : "Specifies which events trigger notifications. Remove the event type(s) you don not want to get notified on. This setting overrides device-specific settings in the UI. (<code>CTRL + Click</code> to select/deselect).", "INCLUDED_SECTIONS_description" : "Specifies which events trigger notifications. Remove the event type(s) you don not want to get notified on. This setting overrides device-specific settings in the UI. (<code>CTRL + Click</code> to select/deselect).",
"DAYS_TO_KEEP_EVENTS_name" : "Delete events older than", "DAYS_TO_KEEP_EVENTS_name" : "Delete events older than",

View File

@@ -96,7 +96,7 @@ More on specifics below.
| 8 | `ForeignKey` | no | A foreign key that can be used to link to the parent object (usually a MAC address) | | 8 | `ForeignKey` | no | A foreign key that can be used to link to the parent object (usually a MAC address) |
> [!NOTE] > [!NOTE]
> De-duplication is run once an hour on the `Plugins_Objects` database table and duplicate entries with the same value in columns `Object_PrimaryID`, `Object_SecondaryID`, `Plugin` (auto-filled based on `unique_prefix` of the plugin), `UserData` (can be populated with the `"type": "textboxsave"` column type) are removed. > De-duplication is run once an hour on the `Plugins_Objects` database table and duplicate entries with the same value in columns `Object_PrimaryID`, `Object_SecondaryID`, `Plugin` (auto-filled based on `unique_prefix` of the plugin), `UserData` (can be populated with the `"type": "textbox_save"` column type) are removed.
# config.json structure # config.json structure
@@ -349,7 +349,7 @@ This approach is used to implement the `DHCPLSS` plugin. The script parses all s
"mapped_to_column": "DHCP_MAC", "mapped_to_column": "DHCP_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -533,17 +533,17 @@ You can have any `"function": "my_custom_name"` custom name, however, the ones l
The UI will adjust how columns are displayed in the UI based on the definition of the `database_column_definitions` object. These are the supported form controls and related functionality: The UI will adjust how columns are displayed in the UI based on the definition of the `database_column_definitions` object. These are the supported form controls and related functionality:
- Only columns with `"show": true` and also with at least an English translation will be shown in the UI. - Only columns with `"show": true` and also with at least an English translation will be shown in the UI.
- Supported types: `label`, `text`, `threshold`, `replace`, `deviceip`, `devicemac`, `url`. Check for details below, how columns behave based on the type. - Supported types: `label`, `text`, `threshold`, `replace`, `device_ip`, `device_mac`, `url`. Check for details below, how columns behave based on the type.
- `label` makes a column display only - `label` makes a column display only
- `text` makes a column editable and a save icon is displayed next to it. - `text` makes a column editable and a save icon is displayed next to it.
- See below for information on `threshold`, `replace` - See below for information on `threshold`, `replace`
- The `options` property is used in conjunction with these types: - The `options` property is used in conjunction with these types:
- `threshold` - The `options` array contains objects from lowest `maximum` to highest with corresponding `hexColor` used for the value background color if it's less than the specified `maximum`, but more than the previous one in the `options` array - `threshold` - The `options` array contains objects from lowest `maximum` to highest with corresponding `hexColor` used for the value background color if it's less than the specified `maximum`, but more than the previous one in the `options` array
- `replace` - The `options` array contains objects with an `equals` property, that is compared to the "value" and if the values are the same, the string in `replacement` is displayed in the UI instead of the actual "value" - `replace` - The `options` array contains objects with an `equals` property, that is compared to the "value" and if the values are the same, the string in `replacement` is displayed in the UI instead of the actual "value"
- `devicemac` - The value is considered to be a Mac address and a link pointing to the device with the given Mac address is generated. - `device_mac` - The value is considered to be a Mac address and a link pointing to the device with the given Mac address is generated.
- `deviceip` - The value is considered to be an IP address and a link pointing to the device with the given IP is generated. The IP is checked against the last detected IP addresses and translated into a Mac address that is then used for the link itself. - `device_ip` - The value is considered to be an IP address and a link pointing to the device with the given IP is generated. The IP is checked against the last detected IP addresses and translated into a Mac address that is then used for the link itself.
- `url` - The value is considered to be a URL so a link is generated. - `url` - The value is considered to be a URL so a link is generated.
- `textboxsave` - An editable and saveable text box is generated that saves values in the database. Primarily intended for the `UserData` database column in the `Plugins_Objects` table. - `textbox_save` - An editable and saveable text box is generated that saves values in the database. Primarily intended for the `UserData` database column in the `Plugins_Objects` table.
```json ```json

View File

@@ -216,7 +216,7 @@
"mapped_to_column": "cur_MAC", "mapped_to_column": "cur_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_name_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -234,7 +234,7 @@
"mapped_to_column": "cur_IP", "mapped_to_column": "cur_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -82,7 +82,7 @@
"mapped_to_column": "DHCP_MAC", "mapped_to_column": "DHCP_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -100,7 +100,7 @@
"mapped_to_column": "DHCP_IP", "mapped_to_column": "DHCP_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -221,7 +221,7 @@
"column": "UserData", "column": "UserData",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": false, "show": false,
"type": "textboxsave", "type": "textbox_save",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -445,11 +445,11 @@
} ] , } ] ,
"description":[{ "description":[{
"language_code":"en_us", "language_code":"en_us",
"string" : "Envíe una notificación solo en estos estados. <code>new</code> significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). <code>watched-changed</code> significa que las columnas <code>Watched_ValueN</code> seleccionadas cambiaron." "string" : "Send a notification only on these statuses. <code>new</code> means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. <code>watched-changed</code> means that selected <code>Watched_ValueN</code> columns changed."
}, },
{ {
"language_code":"es_es", "language_code":"es_es",
"string" : "." "string" : "Envíe una notificación solo en estos estados. <code>new</code> significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). <code>watched-changed</code> significa que las columnas <code>Watched_ValueN</code> seleccionadas cambiaron."
}] }]
} }
] ]

View File

@@ -70,7 +70,7 @@
"column": "Object_PrimaryID", "column": "Object_PrimaryID",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -206,7 +206,7 @@
"column": "UserData", "column": "UserData",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "textboxsave", "type": "textbox_save",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -223,7 +223,7 @@
"column": "ForeignKey", "column": "ForeignKey",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -205,7 +205,7 @@
"mapped_to_column": "cur_MAC", "mapped_to_column": "cur_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -223,7 +223,7 @@
"mapped_to_column": "cur_IP", "mapped_to_column": "cur_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -95,7 +95,7 @@
"mapped_to_column": "DHCP_MAC", "mapped_to_column": "DHCP_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -113,7 +113,7 @@
"mapped_to_column": "DHCP_IP", "mapped_to_column": "DHCP_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -234,7 +234,7 @@
"column": "UserData", "column": "UserData",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": false, "show": false,
"type": "textboxsave", "type": "textbox_save",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -226,7 +226,7 @@
"mapped_to_column": "DHCP_MAC", "mapped_to_column": "DHCP_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -244,7 +244,7 @@
"mapped_to_column": "DHCP_IP", "mapped_to_column": "DHCP_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -117,7 +117,7 @@
"mapped_to_column": "DHCP_MAC", "mapped_to_column": "DHCP_MAC",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "devicemac", "type": "device_mac",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -135,7 +135,7 @@
"mapped_to_column": "DHCP_IP", "mapped_to_column": "DHCP_IP",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "deviceip", "type": "device_ip",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],
@@ -256,7 +256,7 @@
"column": "UserData", "column": "UserData",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": false, "show": false,
"type": "textboxsave", "type": "textbox_save",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -241,7 +241,7 @@
"column": "UserData", "column": "UserData",
"css_classes": "col-sm-2", "css_classes": "col-sm-2",
"show": true, "show": true,
"type": "textboxsave", "type": "textbox_save",
"default_value":"", "default_value":"",
"options": [], "options": [],
"localized": ["name"], "localized": ["name"],

View File

@@ -65,7 +65,7 @@ function getFormControl(dbColumnDef, value, index) {
case 'label': case 'label':
result = `<span>${value}<span>`; result = `<span>${value}<span>`;
break; break;
case 'textboxsave': case 'textbox_save':
value = value == 'null' ? '' : value; // hide 'null' values value = value == 'null' ? '' : value; // hide 'null' values
@@ -81,10 +81,13 @@ function getFormControl(dbColumnDef, value, index) {
case 'url': case 'url':
result = `<span><a href="${value}" target="_blank">${value}</a><span>`; result = `<span><a href="${value}" target="_blank">${value}</a><span>`;
break; break;
case 'devicemac': case 'device_name_mac':
result = `<span class="anonymizeMac"><a href="/deviceDetails.php?mac=${value}" target="_blank">${getNameByMacAddress(value)}</a><span>`;
break;
case 'device_mac':
result = `<span class="anonymizeMac"><a href="/deviceDetails.php?mac=${value}" target="_blank">${value}</a><span>`; result = `<span class="anonymizeMac"><a href="/deviceDetails.php?mac=${value}" target="_blank">${value}</a><span>`;
break; break;
case 'deviceip': case 'device_ip':
result = `<span class="anonymizeIp"><a href="#" onclick="navigateToDeviceWithIp('${value}')" >${value}</a><span>`; result = `<span class="anonymizeIp"><a href="#" onclick="navigateToDeviceWithIp('${value}')" >${value}</a><span>`;
break; break;
case 'threshold': case 'threshold':