Settings changes, NEWDEV work, DOCS

This commit is contained in:
Jokob-sk
2023-07-15 09:35:28 +10:00
parent 388844f2bc
commit 4d433b633f
15 changed files with 219 additions and 167 deletions
+3 -3
View File
@@ -274,11 +274,11 @@ function saveSettings()
{ {
if($group == $setting[0]) if($group == $setting[0])
{ {
if($setting[2] == 'text' or $setting[2] == 'password' or $setting[2] == 'readonly' or $setting[2] == 'selecttext') if($setting[2] == 'text' or $setting[2] == 'password' or $setting[2] == 'readonly' or $setting[2] == 'text.select')
{ {
$val = encode_single_quotes($setting[3]); $val = encode_single_quotes($setting[3]);
$txt = $txt.$setting[1]."='".$val."'\n" ; $txt = $txt.$setting[1]."='".$val."'\n" ;
} elseif($setting[2] == 'integer' or $setting[2] == 'selectinteger') } elseif($setting[2] == 'integer' or $setting[2] == 'integer.select')
{ {
$txt = $txt.$setting[1]."=".$setting[3]."\n" ; $txt = $txt.$setting[1]."=".$setting[3]."\n" ;
} elseif($setting[2] == 'boolean') } elseif($setting[2] == 'boolean')
@@ -289,7 +289,7 @@ function saveSettings()
$val = "True"; $val = "True";
} }
$txt = $txt.$setting[1]."=".$val."\n" ; $txt = $txt.$setting[1]."=".$val."\n" ;
}elseif($setting[2] == 'multiselect' or $setting[2] == 'subnets' or $setting[2] == 'list') }elseif($setting[2] == 'text.multiselect' or $setting[2] == 'subnets' or $setting[2] == 'list')
{ {
$temp = '['; $temp = '[';
+25 -19
View File
@@ -142,35 +142,35 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// text - textbox // text - textbox
if($set['Type'] == 'text' || $set['Type'] == 'string' || $set['Type'] == 'date-time' ) if($set['Type'] == 'text' || $set['Type'] == 'string' || $set['Type'] == 'date-time' )
{ {
$input = '<input class="form-control" onChange="settingsChanged()" id="'.$set['Code_Name'].'" value="'.$set['Value'].'"/>'; $input = '<input class="form-control" onChange="settingsChanged()" my-data-type="'.$set['Type'].'" id="'.$set['Code_Name'].'" value="'.$set['Value'].'"/>';
} }
// password - hidden text // password - hidden text
elseif ($set['Type'] == 'password') elseif ($set['Type'] == 'password')
{ {
$input = '<input onChange="settingsChanged()" class="form-control input" id="'.$set['Code_Name'].'" type="password" value="'.$set['Value'].'"/>'; $input = '<input onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="form-control input" id="'.$set['Code_Name'].'" type="password" value="'.$set['Value'].'"/>';
} }
// readonly // readonly
elseif ($set['Type'] == 'readonly') elseif ($set['Type'] == 'readonly')
{ {
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" value="'.$set['Value'].'" readonly/>'; $input = '<input class="form-control input" my-data-type="'.$set['Type'].'" id="'.$set['Code_Name'].'" value="'.$set['Value'].'" readonly/>';
} }
// boolean - checkbox // boolean - checkbox
elseif ($set['Type'] == 'boolean') elseif ($set['Type'] == 'boolean' || $set['Type'] == 'integer.checkbox')
{ {
$checked = ""; $checked = "";
if ($set['Value'] == "True") { $checked = "checked";}; if ($set['Value'] == "True" || $set['Value'] == "1") { $checked = "checked";};
$input = '<input onChange="settingsChanged()" class="checkbox" id="'.$set['Code_Name'].'" type="checkbox" value="'.$set['Value'].'" '.$checked.' />'; $input = '<input onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="checkbox" id="'.$set['Code_Name'].'" type="checkbox" value="'.$set['Value'].'" '.$checked.' />';
} }
// integer - number input // integer - number input
elseif ($set['Type'] == 'integer') elseif ($set['Type'] == 'integer')
{ {
$input = '<input onChange="settingsChanged()" class="form-control" id="'.$set['Code_Name'].'" type="number" value="'.$set['Value'].'"/>'; $input = '<input onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="form-control" id="'.$set['Code_Name'].'" type="number" value="'.$set['Value'].'"/>';
} }
// selecttext - dropdown // text.select - dropdown
elseif ($set['Type'] == 'selecttext') elseif ($set['Type'] == 'text.select')
{ {
$input = '<select onChange="settingsChanged()" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">'; $input = '<select onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
$values = createArray($set['Value']); $values = createArray($set['Value']);
$options = createArray($set['Options']); $options = createArray($set['Options']);
@@ -186,10 +186,10 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
} }
$input = $input.'</select>'; $input = $input.'</select>';
} }
// selectinteger - dropdown // integer.select - dropdown
elseif ($set['Type'] == 'selectinteger') elseif ($set['Type'] == 'integer.select')
{ {
$input = '<select onChange="settingsChanged()" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">'; $input = '<select onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
$values = createArray($set['Value']); $values = createArray($set['Value']);
$options = createArray($set['Options']); $options = createArray($set['Options']);
@@ -206,10 +206,10 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
} }
$input = $input.'</select>'; $input = $input.'</select>';
} }
// multiselect // text.multiselect
elseif ($set['Type'] == 'multiselect') elseif ($set['Type'] == 'text.multiselect')
{ {
$input = '<select onChange="settingsChanged()" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple>'; $input = '<select onChange="settingsChanged()" my-data-type="'.$set['Type'].'" class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple>';
$values = createArray($set['Value']); $values = createArray($set['Value']);
$options = createArray($set['Options']); $options = createArray($set['Options']);
@@ -243,7 +243,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// list all interfaces as options // list all interfaces as options
$input = $input.'<div class="form-group"> $input = $input.'<div class="form-group">
<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>'; <select class="form-control" my-data-type="'.$set['Type'].'" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>';
$options = createArray($set['Value']); $options = createArray($set['Value']);
@@ -274,7 +274,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// list all interfaces as options // list all interfaces as options
$input = $input.'<div class="form-group"> $input = $input.'<div class="form-group">
<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>'; <select class="form-control" my-data-type="'.$set['Type'].'" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>';
$options = createArray($set['Value']); $options = createArray($set['Value']);
@@ -423,7 +423,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
// generate javascript to collect values // generate javascript to collect values
<?php <?php
$noConversion = array('text', 'integer', 'password', 'readonly', 'selecttext', 'selectinteger', 'multiselect'); $noConversion = array('text', 'integer', 'password', 'readonly', 'text.select', 'integer.select', 'text.multiselect');
foreach ($settings as $set) { foreach ($settings as $set) {
if(in_array($set['Type'] , $noConversion)) if(in_array($set['Type'] , $noConversion))
@@ -436,6 +436,12 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
echo 'temp = $("#'.$set["Code_Name"].'").is(":checked") ;'; echo 'temp = $("#'.$set["Code_Name"].'").is(":checked") ;';
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", "'.$set["Type"].'", temp ]);'; echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", "'.$set["Type"].'", temp ]);';
} }
elseif ($set['Type'] == "integer.checkbox")
{
echo 'temp = $("#'.$set["Code_Name"].'").is(":checked") ;';
echo 'temp ? temp = 1 : temp = 0;';
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", "'.$set["Type"].'", temp ]);';
}
elseif ($set["Code_Name"] == "SCAN_SUBNETS") elseif ($set["Code_Name"] == "SCAN_SUBNETS")
{ {
echo "var temps = []; echo "var temps = [];
+60 -30
View File
@@ -194,18 +194,55 @@ def create_new_devices (db):
# arpscan - Create new devices # arpscan - Create new devices
mylog('debug','[New Devices] 2 Create devices') mylog('debug','[New Devices] 2 Create devices')
# default New Device values preparation
newDevColumns = """dev_AlertEvents,
dev_AlertDeviceDown,
dev_PresentLastScan,
dev_Archived,
dev_NewDevice,
dev_SkipRepeated,
dev_ScanCycle,
dev_Owner,
dev_DeviceType,
dev_Favorite,
dev_Group,
dev_Comments,
dev_LogEvents,
dev_Location,
dev_Network_Node_MAC_ADDR,
dev_Icon"""
newDevDefaults = f"""{get_setting_value('NEWDEV_dev_AlertEvents')},
{get_setting_value('NEWDEV_dev_AlertDeviceDown')},
{get_setting_value('NEWDEV_dev_PresentLastScan')},
{get_setting_value('NEWDEV_dev_Archived')},
{get_setting_value('NEWDEV_dev_NewDevice')},
{get_setting_value('NEWDEV_dev_SkipRepeated')},
{get_setting_value('NEWDEV_dev_ScanCycle')},
'{get_setting_value('NEWDEV_dev_Owner')}',
'{get_setting_value('NEWDEV_dev_DeviceType')}',
{get_setting_value('NEWDEV_dev_Favorite')},
'{get_setting_value('NEWDEV_dev_Group')}',
'{get_setting_value('NEWDEV_dev_Comments')}',
{get_setting_value('NEWDEV_dev_LogEvents')},
'{get_setting_value('NEWDEV_dev_Location')}',
'{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}',
'{get_setting_value('NEWDEV_dev_Icon')}'
"""
sqlQuery = f"""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor, sqlQuery = f"""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
dev_LastIP, dev_FirstConnection, dev_LastConnection, dev_LastIP, dev_FirstConnection, dev_LastConnection,
dev_AlertEvents, dev_AlertDeviceDown, dev_PresentLastScan, dev_Archived, dev_NewDevice, dev_SkipRepeated, dev_ScanCycle, dev_Owner, dev_DeviceType, dev_Favorite, dev_Group, dev_Comments, dev_LogEvents, dev_Location, dev_Network_Node_MAC_ADDR, dev_Icon) {newDevColumns})
SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?, SELECT cur_MAC, '(unknown)', cur_Vendor, cur_IP, ?, ?,
{get_setting_value('NEWDEV_dev_AlertEvents')}, {get_setting_value('NEWDEV_dev_AlertDeviceDown')}, 1, {get_setting_value('NEWDEV_dev_Archived')}, {get_setting_value('NEWDEV_dev_NewDevice')}, {get_setting_value('NEWDEV_dev_SkipRepeated')}, {get_setting_value('NEWDEV_dev_ScanCycle')}, '{get_setting_value('NEWDEV_dev_Owner')}', '{get_setting_value('NEWDEV_dev_DeviceType')}',{get_setting_value('NEWDEV_dev_Favorite')}, '{get_setting_value('NEWDEV_dev_Group')}', '{get_setting_value('NEWDEV_dev_Comments')}', {get_setting_value('NEWDEV_dev_LogEvents')}, '{get_setting_value('NEWDEV_dev_Location')}', '{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}', '{get_setting_value('NEWDEV_dev_Icon')}' {newDevDefaults}
FROM CurrentScan FROM CurrentScan
WHERE cur_ScanCycle = ? WHERE cur_ScanCycle = ?
AND NOT EXISTS (SELECT 1 FROM Devices AND NOT EXISTS (SELECT 1 FROM Devices
WHERE dev_MAC = cur_MAC) """ WHERE dev_MAC = cur_MAC) """
mylog('debug',f'[New Devices] 2 Create devices SQL: {sqlQuery}') mylog('debug',f'[New Devices] 2 Create devices SQL: {sqlQuery}')
sql.execute (sqlQuery,
(startTime, startTime, conf.cycle) ) sql.execute (sqlQuery, (startTime, startTime, conf.cycle) )
# Pi-hole - Insert events for new devices # Pi-hole - Insert events for new devices
# NOT STRICYLY NECESARY (Devices can be created through Current_Scan) # NOT STRICYLY NECESARY (Devices can be created through Current_Scan)
@@ -224,19 +261,24 @@ def create_new_devices (db):
# Pi-hole - Create New Devices # Pi-hole - Create New Devices
# Bugfix #2 - Pi-hole devices w/o IP # Bugfix #2 - Pi-hole devices w/o IP
mylog('debug','[New Devices] 4 Pi-hole Create devices') mylog('debug','[New Devices] 4 Pi-hole Create devices')
sql.execute (f"""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
sqlQuery = f"""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
dev_LastIP, dev_FirstConnection, dev_LastConnection, dev_LastIP, dev_FirstConnection, dev_LastConnection,
dev_AlertEvents, dev_AlertDeviceDown, dev_PresentLastScan, dev_Archived, dev_NewDevice, dev_SkipRepeated, dev_ScanCycle) {newDevColumns})
SELECT PH_MAC, PH_Name, PH_Vendor, IFNULL (PH_IP,'-'), SELECT PH_MAC, PH_Name, PH_Vendor, IFNULL (PH_IP,'-'),
?, ?, ?, ?,
{get_setting_value('NEWDEV_dev_AlertEvents')}, {get_setting_value('NEWDEV_dev_AlertDeviceDown')}, 1, {get_setting_value('NEWDEV_dev_Archived')}, {get_setting_value('NEWDEV_dev_NewDevice')}, {get_setting_value('NEWDEV_dev_SkipRepeated')}, {get_setting_value('NEWDEV_dev_ScanCycle')} {newDevDefaults}
FROM PiHole_Network FROM PiHole_Network
WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE NOT EXISTS (SELECT 1 FROM Devices
WHERE dev_MAC = PH_MAC) """, WHERE dev_MAC = PH_MAC) """
(startTime, startTime) )
mylog('debug',f'[New Devices] 4 Create devices SQL: {sqlQuery}')
sql.execute (sqlQuery, (startTime, startTime) )
# DHCP Leases - Insert events for new devices # DHCP Leases - Insert events for new devices
mylog('debug','[New Devices] 5 DHCP Leases Events') mylog('debug','[New Devices] 5 DHCP Leases Events')
sql.execute ("""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, sql.execute ("""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
eve_EventType, eve_AdditionalInfo, eve_EventType, eve_AdditionalInfo,
eve_PendingAlertEmail) eve_PendingAlertEmail)
@@ -248,15 +290,10 @@ def create_new_devices (db):
# DHCP Leases - Create New Devices # DHCP Leases - Create New Devices
mylog('debug','[New Devices] 6 DHCP Leases Create devices') mylog('debug','[New Devices] 6 DHCP Leases Create devices')
# BUGFIX #23 - Duplicated MAC in DHCP.Leases
# TEST - Force Duplicated MAC sqlQuery = f"""INSERT INTO Devices (dev_MAC, dev_name, dev_LastIP,
# sql.execute ("""INSERT INTO DHCP_Leases VALUES
# (1610700000, 'TEST1', '10.10.10.1', 'Test 1', '*')""")
# sql.execute ("""INSERT INTO DHCP_Leases VALUES
# (1610700000, 'TEST2', '10.10.10.2', 'Test 2', '*')""")
sql.execute (f"""INSERT INTO Devices (dev_MAC, dev_name, dev_LastIP,
dev_Vendor, dev_FirstConnection, dev_LastConnection, dev_Vendor, dev_FirstConnection, dev_LastConnection,
dev_AlertEvents, dev_AlertDeviceDown, dev_PresentLastScan, dev_Archived, dev_NewDevice, dev_SkipRepeated, dev_ScanCycle) {newDevColumns})
SELECT DISTINCT DHCP_MAC, SELECT DISTINCT DHCP_MAC,
(SELECT DHCP_Name FROM DHCP_Leases AS D2 (SELECT DHCP_Name FROM DHCP_Leases AS D2
WHERE D2.DHCP_MAC = D1.DHCP_MAC WHERE D2.DHCP_MAC = D1.DHCP_MAC
@@ -265,22 +302,15 @@ def create_new_devices (db):
WHERE D2.DHCP_MAC = D1.DHCP_MAC WHERE D2.DHCP_MAC = D1.DHCP_MAC
ORDER BY DHCP_DateTime DESC LIMIT 1), ORDER BY DHCP_DateTime DESC LIMIT 1),
'(unknown)', ?, ?, '(unknown)', ?, ?,
{get_setting_value('NEWDEV_dev_AlertEvents')}, {get_setting_value('NEWDEV_dev_AlertDeviceDown')}, 1, {get_setting_value('NEWDEV_dev_Archived')}, {get_setting_value('NEWDEV_dev_NewDevice')}, {get_setting_value('NEWDEV_dev_SkipRepeated')}, {get_setting_value('NEWDEV_dev_ScanCycle')} {newDevDefaults}
FROM DHCP_Leases AS D1 FROM DHCP_Leases AS D1
WHERE NOT EXISTS (SELECT 1 FROM Devices WHERE NOT EXISTS (SELECT 1 FROM Devices
WHERE dev_MAC = DHCP_MAC) """, WHERE dev_MAC = DHCP_MAC) """
(startTime, startTime) )
mylog('debug',f'[New Devices] 6 Create devices SQL: {sqlQuery}')
sql.execute (sqlQuery, (startTime, startTime) )
# sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
# dev_LastIP, dev_FirstConnection, dev_LastConnection,
# dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
# dev_PresentLastScan)
# SELECT DHCP_MAC, DHCP_Name, '(unknown)', DHCP_IP, ?, ?,
# 1, 1, 0, 1
# FROM DHCP_Leases
# WHERE NOT EXISTS (SELECT 1 FROM Devices
# WHERE dev_MAC = DHCP_MAC) """,
# (startTime, startTime) )
mylog('debug','[New Devices] New Devices end') mylog('debug','[New Devices] New Devices end')
db.commitDB() db.commitDB()
+17 -18
View File
@@ -72,27 +72,27 @@ def importConfigs (db):
# General # General
conf.ENABLE_ARPSCAN = ccd('ENABLE_ARPSCAN', True , c_d, 'Enable arpscan', 'boolean', '', 'General', ['run']) conf.ENABLE_ARPSCAN = ccd('ENABLE_ARPSCAN', True , c_d, 'Enable arpscan', 'boolean', '', 'General', ['run'])
conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', 'subnets', '', 'General') conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', 'subnets', '', 'General')
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', 'selecttext', "['none', 'minimal', 'verbose', 'debug']", 'General') conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', 'text.select', "['none', 'minimal', 'verbose', 'debug']", 'General')
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General') conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General')
conf.ENABLE_PLUGINS = ccd('ENABLE_PLUGINS', True , c_d, 'Enable plugins', 'boolean', '', 'General') conf.ENABLE_PLUGINS = ccd('ENABLE_PLUGINS', True , c_d, 'Enable plugins', 'boolean', '', 'General')
conf.PIALERT_WEB_PROTECTION = ccd('PIALERT_WEB_PROTECTION', False , c_d, 'Enable logon', 'boolean', '', 'General') conf.PIALERT_WEB_PROTECTION = ccd('PIALERT_WEB_PROTECTION', False , c_d, 'Enable logon', 'boolean', '', 'General')
conf.PIALERT_WEB_PASSWORD = ccd('PIALERT_WEB_PASSWORD', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92' , c_d, 'Logon password', 'readonly', '', 'General') conf.PIALERT_WEB_PASSWORD = ccd('PIALERT_WEB_PASSWORD', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92' , c_d, 'Logon password', 'readonly', '', 'General')
conf.INCLUDED_SECTIONS = ccd('INCLUDED_SECTIONS', ['internet', 'new_devices', 'down_devices', 'events', 'ports'] , c_d, 'Notify on', 'multiselect', "['internet', 'new_devices', 'down_devices', 'events', 'ports', 'plugins']", 'General') conf.INCLUDED_SECTIONS = ccd('INCLUDED_SECTIONS', ['internet', 'new_devices', 'down_devices', 'events', 'ports'] , c_d, 'Notify on', 'text.multiselect', "['internet', 'new_devices', 'down_devices', 'events', 'ports', 'plugins']", 'General')
conf.SCAN_CYCLE_MINUTES = ccd('SCAN_CYCLE_MINUTES', 5 , c_d, 'Scan cycle delay (m)', 'integer', '', 'General') conf.SCAN_CYCLE_MINUTES = ccd('SCAN_CYCLE_MINUTES', 5 , c_d, 'Scan cycle delay (m)', 'integer', '', 'General')
conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://pi.alert/' , c_d, 'PiAlert URL', 'text', '', 'General') conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://pi.alert/' , c_d, 'PiAlert URL', 'text', '', 'General')
conf.DIG_GET_IP_ARG = ccd('DIG_GET_IP_ARG', '-4 myip.opendns.com @resolver1.opendns.com' , c_d, 'DIG arguments', 'text', '', 'General') conf.DIG_GET_IP_ARG = ccd('DIG_GET_IP_ARG', '-4 myip.opendns.com @resolver1.opendns.com' , c_d, 'DIG arguments', 'text', '', 'General')
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'selecttext', "['English', 'German', 'Spanish']", 'General') conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'text.select', "['English', 'German', 'Spanish']", 'General')
conf.UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'multiselect', "['online', 'offline', 'archived']", 'General') conf.UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'text.multiselect', "['online', 'offline', 'archived']", 'General')
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', 'integer', '', 'General') conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', 'integer', '', 'General')
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', 'integer', "0", 'General') conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', 'integer', "0", 'General')
# # New device defaults # # New device defaults
# conf.NEWDEV_SCAN = ccd('NEWDEV_SCAN', 1 , c_d, 'Scan Device', 'selectinteger', "['0', '1']", 'NewDeviceDefaults') # conf.NEWDEV_SCAN = ccd('NEWDEV_SCAN', 1 , c_d, 'Scan Device', 'integer.select', "['0', '1']", 'NewDeviceDefaults')
# conf.NEWDEV_ALERT_ALL = ccd('NEWDEV_ALERT_ALL', 0 , c_d, 'Alert All Events', 'selectinteger', "['0', '1']", 'NewDeviceDefaults') # conf.NEWDEV_ALERT_ALL = ccd('NEWDEV_ALERT_ALL', 0 , c_d, 'Alert All Events', 'integer.select', "['0', '1']", 'NewDeviceDefaults')
# conf.NEWDEV_ALERT_DWN = ccd('NEWDEV_ALERT_DWN', 0 , c_d, 'Alert Down', 'selectinteger', "['0', '1']", 'NewDeviceDefaults') # conf.NEWDEV_ALERT_DWN = ccd('NEWDEV_ALERT_DWN', 0 , c_d, 'Alert Down', 'integer.select', "['0', '1']", 'NewDeviceDefaults')
# conf.NEWDEV_NEWDEV = ccd('NEWDEV_NEWDEV', 1 , c_d, 'New Device', 'selectinteger', "['0', '1']", 'NewDeviceDefaults') # conf.NEWDEV_NEWDEV = ccd('NEWDEV_NEWDEV', 1 , c_d, 'New Device', 'integer.select', "['0', '1']", 'NewDeviceDefaults')
# conf.NEWDEV_ARCHIVED = ccd('NEWDEV_ARCHIVED', 0 , c_d, 'Archived', 'selectinteger', "['0', '1']", 'NewDeviceDefaults') # conf.NEWDEV_ARCHIVED = ccd('NEWDEV_ARCHIVED', 0 , c_d, 'Archived', 'integer.select', "['0', '1']", 'NewDeviceDefaults')
# conf.NEWDEV_SKIPNTF = ccd('NEWDEV_SKIPNTF', 0 , c_d, 'Skip repeated notifications for', 'selectinteger', "['0', '1', '8', '24', '168']", 'NewDeviceDefaults') # conf.NEWDEV_SKIPNTF = ccd('NEWDEV_SKIPNTF', 0 , c_d, 'Skip repeated notifications for', 'integer.select', "['0', '1', '8', '24', '168']", 'NewDeviceDefaults')
# Email # Email
conf.REPORT_MAIL = ccd('REPORT_MAIL', False , c_d, 'Enable email', 'boolean', '', 'Email', ['test']) conf.REPORT_MAIL = ccd('REPORT_MAIL', False , c_d, 'Enable email', 'boolean', '', 'Email', ['test'])
@@ -109,15 +109,15 @@ def importConfigs (db):
# Webhooks # Webhooks
conf.REPORT_WEBHOOK = ccd('REPORT_WEBHOOK', False , c_d, 'Enable Webhooks', 'boolean', '', 'Webhooks', ['test']) conf.REPORT_WEBHOOK = ccd('REPORT_WEBHOOK', False , c_d, 'Enable Webhooks', 'boolean', '', 'Webhooks', ['test'])
conf.WEBHOOK_URL = ccd('WEBHOOK_URL', '' , c_d, 'Target URL', 'text', '', 'Webhooks') conf.WEBHOOK_URL = ccd('WEBHOOK_URL', '' , c_d, 'Target URL', 'text', '', 'Webhooks')
conf.WEBHOOK_PAYLOAD = ccd('WEBHOOK_PAYLOAD', 'json' , c_d, 'Payload type', 'selecttext', "['json', 'html', 'text']", 'Webhooks') conf.WEBHOOK_PAYLOAD = ccd('WEBHOOK_PAYLOAD', 'json' , c_d, 'Payload type', 'text.select', "['json', 'html', 'text']", 'Webhooks')
conf.WEBHOOK_REQUEST_METHOD = ccd('WEBHOOK_REQUEST_METHOD', 'GET' , c_d, 'Req type', 'selecttext', "['GET', 'POST', 'PUT']", 'Webhooks') conf.WEBHOOK_REQUEST_METHOD = ccd('WEBHOOK_REQUEST_METHOD', 'GET' , c_d, 'Req type', 'text.select', "['GET', 'POST', 'PUT']", 'Webhooks')
conf.WEBHOOK_SIZE = ccd('WEBHOOK_SIZE', 1024 , c_d, 'Payload size', 'integer', '', 'Webhooks') conf.WEBHOOK_SIZE = ccd('WEBHOOK_SIZE', 1024 , c_d, 'Payload size', 'integer', '', 'Webhooks')
# Apprise # Apprise
conf.REPORT_APPRISE = ccd('REPORT_APPRISE', False , c_d, 'Enable Apprise', 'boolean', '', 'Apprise', ['test']) conf.REPORT_APPRISE = ccd('REPORT_APPRISE', False , c_d, 'Enable Apprise', 'boolean', '', 'Apprise', ['test'])
conf.APPRISE_HOST = ccd('APPRISE_HOST', '' , c_d, 'Apprise host URL', 'text', '', 'Apprise') conf.APPRISE_HOST = ccd('APPRISE_HOST', '' , c_d, 'Apprise host URL', 'text', '', 'Apprise')
conf.APPRISE_URL = ccd('APPRISE_URL', '' , c_d, 'Apprise notification URL', 'text', '', 'Apprise') conf.APPRISE_URL = ccd('APPRISE_URL', '' , c_d, 'Apprise notification URL', 'text', '', 'Apprise')
conf.APPRISE_PAYLOAD = ccd('APPRISE_PAYLOAD', 'html' , c_d, 'Payload type', 'selecttext', "['html', 'text']", 'Apprise') conf.APPRISE_PAYLOAD = ccd('APPRISE_PAYLOAD', 'html' , c_d, 'Payload type', 'text.select', "['html', 'text']", 'Apprise')
# NTFY # NTFY
conf.REPORT_NTFY = ccd('REPORT_NTFY', False , c_d, 'Enable NTFY', 'boolean', '', 'NTFY', ['test']) conf.REPORT_NTFY = ccd('REPORT_NTFY', False , c_d, 'Enable NTFY', 'boolean', '', 'NTFY', ['test'])
@@ -136,8 +136,8 @@ def importConfigs (db):
conf.MQTT_PORT = ccd('MQTT_PORT', 1883 , c_d, 'MQTT broker port', 'integer', '', 'MQTT') conf.MQTT_PORT = ccd('MQTT_PORT', 1883 , c_d, 'MQTT broker port', 'integer', '', 'MQTT')
conf.MQTT_USER = ccd('MQTT_USER', '' , c_d, 'MQTT user', 'text', '', 'MQTT') conf.MQTT_USER = ccd('MQTT_USER', '' , c_d, 'MQTT user', 'text', '', 'MQTT')
conf.MQTT_PASSWORD = ccd('MQTT_PASSWORD', '' , c_d, 'MQTT password', 'password', '', 'MQTT') conf.MQTT_PASSWORD = ccd('MQTT_PASSWORD', '' , c_d, 'MQTT password', 'password', '', 'MQTT')
conf.MQTT_QOS = ccd('MQTT_QOS', 0 , c_d, 'MQTT Quality of Service', 'selectinteger', "['0', '1', '2']", 'MQTT') conf.MQTT_QOS = ccd('MQTT_QOS', 0 , c_d, 'MQTT Quality of Service', 'integer.select', "['0', '1', '2']", 'MQTT')
conf.MQTT_DELAY_SEC = ccd('MQTT_DELAY_SEC', 2 , c_d, 'MQTT delay', 'selectinteger', "['2', '3', '4', '5']", 'MQTT') conf.MQTT_DELAY_SEC = ccd('MQTT_DELAY_SEC', 2 , c_d, 'MQTT delay', 'integer.select', "['2', '3', '4', '5']", 'MQTT')
# DynDNS # DynDNS
conf.DDNS_ACTIVE = ccd('DDNS_ACTIVE', False , c_d, 'Enable DynDNS', 'boolean', '', 'DynDNS') conf.DDNS_ACTIVE = ccd('DDNS_ACTIVE', False , c_d, 'Enable DynDNS', 'boolean', '', 'DynDNS')
@@ -154,7 +154,7 @@ def importConfigs (db):
conf.PHOLUS_ACTIVE = ccd('PHOLUS_ACTIVE', False , c_d, 'Enable Pholus scans', 'boolean', '', 'Pholus') conf.PHOLUS_ACTIVE = ccd('PHOLUS_ACTIVE', False , c_d, 'Enable Pholus scans', 'boolean', '', 'Pholus')
conf.PHOLUS_TIMEOUT = ccd('PHOLUS_TIMEOUT', 20 , c_d, 'Pholus timeout', 'integer', '', 'Pholus') conf.PHOLUS_TIMEOUT = ccd('PHOLUS_TIMEOUT', 20 , c_d, 'Pholus timeout', 'integer', '', 'Pholus')
conf.PHOLUS_FORCE = ccd('PHOLUS_FORCE', False , c_d, 'Pholus force check', 'boolean', '', 'Pholus') conf.PHOLUS_FORCE = ccd('PHOLUS_FORCE', False , c_d, 'Pholus force check', 'boolean', '', 'Pholus')
conf.PHOLUS_RUN = ccd('PHOLUS_RUN', 'once' , c_d, 'Pholus enable schedule', 'selecttext', "['disabled', 'once', 'schedule']", 'Pholus') conf.PHOLUS_RUN = ccd('PHOLUS_RUN', 'once' , c_d, 'Pholus enable schedule', 'text.select', "['disabled', 'once', 'schedule']", 'Pholus')
conf.PHOLUS_RUN_TIMEOUT = ccd('PHOLUS_RUN_TIMEOUT', 600 , c_d, 'Pholus timeout schedule', 'integer', '', 'Pholus') conf.PHOLUS_RUN_TIMEOUT = ccd('PHOLUS_RUN_TIMEOUT', 600 , c_d, 'Pholus timeout schedule', 'integer', '', 'Pholus')
conf.PHOLUS_RUN_SCHD = ccd('PHOLUS_RUN_SCHD', '0 4 * * *' , c_d, 'Pholus schedule', 'text', '', 'Pholus') conf.PHOLUS_RUN_SCHD = ccd('PHOLUS_RUN_SCHD', '0 4 * * *' , c_d, 'Pholus schedule', 'text', '', 'Pholus')
conf.PHOLUS_DAYS_DATA = ccd('PHOLUS_DAYS_DATA', 0 , c_d, 'Pholus keep days', 'integer', '', 'Pholus') conf.PHOLUS_DAYS_DATA = ccd('PHOLUS_DAYS_DATA', 0 , c_d, 'Pholus keep days', 'integer', '', 'Pholus')
@@ -162,7 +162,7 @@ def importConfigs (db):
# Nmap # Nmap
conf.NMAP_ACTIVE = ccd('NMAP_ACTIVE', True , c_d, 'Enable Nmap scans', 'boolean', '', 'Nmap') conf.NMAP_ACTIVE = ccd('NMAP_ACTIVE', True , c_d, 'Enable Nmap scans', 'boolean', '', 'Nmap')
conf.NMAP_TIMEOUT = ccd('NMAP_TIMEOUT', 150 , c_d, 'Nmap timeout', 'integer', '', 'Nmap') conf.NMAP_TIMEOUT = ccd('NMAP_TIMEOUT', 150 , c_d, 'Nmap timeout', 'integer', '', 'Nmap')
conf.NMAP_RUN = ccd('NMAP_RUN', 'disabled' , c_d, 'Nmap enable schedule', 'selecttext', "['disabled', 'once', 'schedule']", 'Nmap') conf.NMAP_RUN = ccd('NMAP_RUN', 'disabled' , c_d, 'Nmap enable schedule', 'text.select', "['disabled', 'once', 'schedule']", 'Nmap')
conf.NMAP_RUN_SCHD = ccd('NMAP_RUN_SCHD', '0 2 * * *' , c_d, 'Nmap schedule', 'text', '', 'Nmap') conf.NMAP_RUN_SCHD = ccd('NMAP_RUN_SCHD', '0 2 * * *' , c_d, 'Nmap schedule', 'text', '', 'Nmap')
conf.NMAP_ARGS = ccd('NMAP_ARGS', '-p -10000' , c_d, 'Nmap custom arguments', 'text', '', 'Nmap') conf.NMAP_ARGS = ccd('NMAP_ARGS', '-p -10000' , c_d, 'Nmap custom arguments', 'text', '', 'Nmap')
@@ -190,7 +190,6 @@ def importConfigs (db):
# Plugins START # Plugins START
# ----------------- # -----------------
if conf.ENABLE_PLUGINS:
conf.plugins = get_plugins_configs() conf.plugins = get_plugins_configs()
mylog('none', ['[Config] Plugins: Number of dynamically loaded plugins: ', len(conf.plugins)]) mylog('none', ['[Config] Plugins: Number of dynamically loaded plugins: ', len(conf.plugins)])
+2 -2
View File
@@ -281,8 +281,8 @@ def plugin_param_from_glob_set(globalSetting):
setTyp = globalSetting[3] # setting type setTyp = globalSetting[3] # setting type
noConversion = ['text', 'integer', 'boolean', 'password', 'readonly', 'selectinteger', 'selecttext' ] noConversion = ['text', 'integer', 'boolean', 'password', 'readonly', 'integer.select', 'text.select', 'integer.checkbox' ]
arrayConversion = ['multiselect', 'list'] arrayConversion = ['text.multiselect', 'list']
if setTyp in noConversion: if setTyp in noConversion:
return setVal return setVal
+29 -22
View File
@@ -12,13 +12,16 @@
### SQL query based plugins ### SQL query based plugins
- [nmap_services (NMAPSERV)](https://github.com/jokob-sk/Pi.Alert/blob/main/pialert/plugins/nmap_services/) - [nmap_services (NMAPSERV)](https://github.com/jokob-sk/Pi.Alert/blob/main/pialert/plugins/nmap_services/)
### template based plugins
- [newdev_template (NEWDEV)](https://github.com/jokob-sk/Pi.Alert/blob/main/pialert/plugins/newdev_template/)
## 🌟 Create a custom plugin: Overview ## 🌟 Create a custom plugin: Overview
| ![Screen 1][screen1] | ![Screen 2][screen2] | | ![Screen 1][screen1] | ![Screen 2][screen2] |
|----------------------|----------------------| |----------------------|----------------------|
| ![Screen 3][screen3] | ![Screen 4][screen4] | | ![Screen 3][screen3] | ![Screen 4][screen4] |
PiAlert comes with a plugin system to feed events from third-party scripts into the UI and then send notifications, if desired. The highlighted functionality this plugin system supports, is dynamic creation of a simple UI to interact with the discovered objects, a mechanism to surface settings of plugins in the UI, or to import objects into existing PiAlert database tables. (Currently update/overwriting of existing objects is not supported.) PiAlert comes with a plugin system to feed events from third-party scripts into the UI and then send notifications, if desired. The highlighted functionality this plugin system supports, is dynamic creation of a simple UI to interact with the discovered objects, a mechanism to surface settings of plugins in the UI, or to import objects into existing PiAlert database tables. (Currently, update/overwriting of existing objects is not supported.)
Example use cases for plugins could be: Example use cases for plugins could be:
@@ -27,15 +30,15 @@ Example use cases for plugins could be:
* Creating ad-hoc UI tables from existing data in the PiAlert database, e.g. to show all open ports on devices, to list devices that disconnected in the last hour, etc. * Creating ad-hoc UI tables from existing data in the PiAlert database, e.g. to show all open ports on devices, to list devices that disconnected in the last hour, etc.
* Using other device discovery methods on the network and importing the data as new devices * Using other device discovery methods on the network and importing the data as new devices
* Creating a script to create FAKE devices based on user input via custom settings * Creating a script to create FAKE devices based on user input via custom settings
* ...at this point the limitation is mostly the creativity than the capability (there might be edge cases and need to support more form controls for user input off custom settings, but you probably get the idea) * ...at this point the limitation is mostly the creativity than the capability (there might be edge cases and a need to support more form controls for user input off custom settings, but you probably get the idea)
If you wish to develop a plugin, please check the existing plugin structure. Once the settings are saved by the user they need to be removed from the `pialert.conf` file manually if you want to re-initialize them from the `config.json` of the plugin. If you wish to develop a plugin, please check the existing plugin structure. Once the settings are saved by the user they need to be removed from the `pialert.conf` file manually if you want to re-initialize them from the `config.json` of the plugin.
Again, please read the below carefully if you'd like to contribute with a plugin yourself. This documentation file might be outdated, so double check the sample plugins as well. Again, please read the below carefully if you'd like to contribute with a plugin yourself. This documentation file might be outdated, so double-check the sample plugins as well.
## ⚠ Disclaimer ## ⚠ Disclaimer
Experimental feature used also to speed up development and to make the app more maintainable. Follow the below very carefully and check example plugin(s) if you'd like to write one yourself. Plugin UI is not my priority right now, happy to approve PRs if you are interested in extending/improvintg the UI experience. Example improvements for the taking: Follow the below very carefully and check example plugin(s) if you'd like to write one yourself. Plugin UI is not my priority right now, happy to approve PRs if you are interested in extending/improving the UI experience. Example improvements for the taking:
* Making the tables sortable/filterable * Making the tables sortable/filterable
* Using the same approach to display table data as in the Devices section (solves above) * Using the same approach to display table data as in the Devices section (solves above)
@@ -48,7 +51,7 @@ These issues will be hopefully fixed with time, so please don't report them. Ins
* Existing plugin objects sometimes not interpreted correctly and a new object is created instead, resulting in duplicate entries. * Existing plugin objects sometimes not interpreted correctly and a new object is created instead, resulting in duplicate entries.
* Occasional (experienced twice) hanging of processing plugin script file. * Occasional (experienced twice) hanging of processing plugin script file.
* UI displaying outdated values until the API endpoints get refreshed. UI displays outdated values until the API endpoints get refreshed.
## Plugin file structure overview ## Plugin file structure overview
@@ -84,21 +87,22 @@ More on specifics below.
## Supported data sources ## Supported data sources
Currently only two data sources are supported: Currently, only 3 data sources are supported:
- Script - Script
- SQL query on the PiAlert database - SQL query on the PiAlert database
- Template
You need to set the `data_source` to either `pialert-db-query` or `python-script`: You need to set the `data_source` to `pialert-db-query`, `python-script`, or `template`:
```json ```json
"data_source": "pialert-db-query" "data_source": "pialert-db-query"
``` ```
Any of the above datasources have to return a "table" of the exact structure as outlined above. Any of the above data sources have to return a "table" of the exact structure as outlined above.
### "data_source": "python-script" ### "data_source": "python-script"
If the datasource is set to `python-script` the `CMD` setting (that you specify in the `settings` array section in the `config.json`) needs to contain a executable linux command, that generates a `last_result.log` file. This file needs to be stored in the same folder as the plugin. If the `data_source` is set to `python-script` the `CMD` setting (that you specify in the `settings` array section in the `config.json`) needs to contain an executable Linux command, that generates a `last_result.log` file. This file needs to be stored in the same folder as the plugin.
The content of the `last_result.log` file needs to contain the columns as defined in the "Column order and values" section above. The order of columns can't be changed. After every scan it should contain only the results from the latest scan/execution. The content of the `last_result.log` file needs to contain the columns as defined in the "Column order and values" section above. The order of columns can't be changed. After every scan it should contain only the results from the latest scan/execution.
@@ -140,7 +144,7 @@ https://www.google.com|null|2023-01-02 15:56:30|200|0.7898|
### "data_source": "pialert-db-query" ### "data_source": "pialert-db-query"
If the datasource is set to `pialert-db-query` the `CMD` setting needs to contain a SQL query rendering the columns as defined in the "Column order and values" section above. The order of columns is important. If the `data_source` is set to `pialert-db-query` the `CMD` setting needs to contain a SQL query rendering the columns as defined in the "Column order and values" section above. The order of columns is important.
This SQL query is executed on the `pialert.db` SQLite database file. This SQL query is executed on the `pialert.db` SQLite database file.
@@ -185,6 +189,10 @@ Required `CMD` setting example with above query (you can set `"type": "label"` i
} }
``` ```
### "data_source": "template"
Used to initialize internal settings. Check the `newdev_template` plugin for details.
### Mapping the plugin results into a database table ### Mapping the plugin results into a database table
PiAlert will take the results of the plugin execution and insert these results into a database table, if a plugin contains the property `"mapped_to_table"` in the `config.json` root. The mapping of the columns is defined in the `database_column_definitions` array. PiAlert will take the results of the plugin execution and insert these results into a database table, if a plugin contains the property `"mapped_to_table"` in the `config.json` root. The mapping of the columns is defined in the `database_column_definitions` array.
@@ -230,8 +238,7 @@ This approach is used to implement the `DHCPLSS` plugin. The script parses all s
The `params` array in the `config.json` is used to enable the user to change the parameters of the executed script. For example, the user wants to monitor a specific URL. The `params` array in the `config.json` is used to enable the user to change the parameters of the executed script. For example, the user wants to monitor a specific URL.
##### Example: ##### Example:
Passing user-defined settings to a command. Let's say, you want to have a script, that is called with a user-defined parameter called `urls`:
Passing user defined settings to a command. Let's say, you want to have a script, that is called with a user-defined parameter called `urls`:
```bash ```bash
root@server# python3 /home/pi/pialert/pialert/plugins/website_monitor/script.py urls=https://google.com,https://duck.com root@server# python3 /home/pi/pialert/pialert/plugins/website_monitor/script.py urls=https://google.com,https://duck.com
@@ -290,8 +297,8 @@ Below are some general additional notes, when definig `params`:
- `"name":"name_value"` - is used as a wildcard replacement in the `CMD` setting value by using curly brackets `{name_value}`. The wildcard is replaced by the result of the `"value" : "param_value"` and `"type":"type_value"` combo configuration below. - `"name":"name_value"` - is used as a wildcard replacement in the `CMD` setting value by using curly brackets `{name_value}`. The wildcard is replaced by the result of the `"value" : "param_value"` and `"type":"type_value"` combo configuration below.
- `"type":"<sql|setting>"` - is used to specify the type of the params, currently only 2 supported (`sql`,`setting`). - `"type":"<sql|setting>"` - is used to specify the type of the params, currently only 2 supported (`sql`,`setting`).
- `"type":"sql"` - will execute the SQL query specified in the `value` property. The sql query needs to return only one column. The column is flattened and separated by commas (`,`), e.g: `SELECT dev_MAC from DEVICES` -> `Internet,74:ac:74:ac:74:ac,44:44:74:ac:74:ac`. This is then used to replace the wildcards in the `CMD` setting. - `"type":"sql"` - will execute the SQL query specified in the `value` property. The sql query needs to return only one column. The column is flattened and separated by commas (`,`), e.g: `SELECT dev_MAC from DEVICES` -> `Internet,74:ac:74:ac:74:ac,44:44:74:ac:74:ac`. This is then used to replace the wildcards in the `CMD` setting.
- `"type":"setting"` - The setting code name. A combination of the value from `unique_prefix` + `_` + `function` value, or otherwise the code name you can find in the Settings page under the Setting dispaly name, e.g. `SCAN_CYCLE_MINUTES`. - `"type":"setting"` - The setting code name. A combination of the value from `unique_prefix` + `_` + `function` value, or otherwise the code name you can find in the Settings page under the Setting display name, e.g. `SCAN_CYCLE_MINUTES`.
- `"value" : "param_value"` - Needs to contain a setting code name or sql query without wildcards. - `"value" : "param_value"` - Needs to contain a setting code name or SQL query without wildcards.
Example: Example:
@@ -317,10 +324,10 @@ Example:
``` ```
#### Setting object struncture #### Setting object structure
- `"function": "<see Supported settings function values>"` - What function the setting drives or a simple unique code name - `"function": "<see Supported settings function values>"` - What function the setting drives or a simple unique code name
- `"type": "<text|integer|boolean|password|readonly|selectinteger|selecttext|multiselect|list>"` - The form control used for the setting displayed in the Settings page and what values are accepted. - `"type": "<text|integer|boolean|password|readonly|integer.select|text.select|text.multiselect|list|integer.checkbox>"` - The form control used for the setting displayed in the Settings page and what values are accepted.
- `"localized"` - a list of properties on the current JSON level which need to be localized - `"localized"` - a list of properties on the current JSON level which need to be localized
- `"name"` and `"description"` - Displayed in the Settings page. An array of localized strings. (see Localized strings below). - `"name"` and `"description"` - Displayed in the Settings page. An array of localized strings. (see Localized strings below).
@@ -346,7 +353,7 @@ Example:
```json ```json
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -362,7 +369,7 @@ Example:
``` ```
##### Localized strings ##### Localized strings
- `"language_code":"<en_us|es_es|de_de>"` - code name of the language string. Only these three currently supported. At least the `"language_code":"en_us"` variant has to be defined. - `"language_code":"<en_us|es_es|de_de>"` - code name of the language string. Only these three are currently supported. At least the `"language_code":"en_us"` variant has to be defined.
- `"string"` - The string to be displayed in the given language. - `"string"` - The string to be displayed in the given language.
Example: Example:
@@ -377,7 +384,7 @@ Example:
``` ```
##### UI settings in database_column_definitions ##### UI settings in database_column_definitions
The UI will adjust how columns are displayed in the UI based on the definition of the `database_column_definitions` object. Thease 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`, `deviceip`, `devicemac`, `url`. Check for details below, how columns behave based on the type.
@@ -387,9 +394,9 @@ The UI will adjust how columns are displayed in the UI based on the definition o
- 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. - `devicemac` - 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 cheked against the last detected IP addresses and translated into a mac address that is then used for the link itself. - `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.
- `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.
```json ```json
+3 -3
View File
@@ -215,7 +215,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -294,7 +294,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1", "Watched_Value4"], "default_value":["Watched_Value1", "Watched_Value4"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -309,7 +309,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],
+3 -3
View File
@@ -205,7 +205,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -269,7 +269,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1"], "default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -284,7 +284,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],
+11 -1
View File
@@ -1 +1,11 @@
Template for new devices ## Overview
A simple template-based plugin for new devices. You can change the default values for newly detected devices.
### Usage
- Head to **Settings** > **New Devices** to adjust the default values.
### Notes
- This plugin generates editable settings taht are then used in the `device.py` script to initialize new values.
+26 -26
View File
@@ -22,7 +22,7 @@
"settings":[ "settings":[
{ {
"function": "dev_MAC", "function": "dev_MAC",
"type": "label", "type": "readonly",
"maxLength": 50, "maxLength": 50,
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -42,7 +42,7 @@
}, },
{ {
"function": "dev_Name", "function": "dev_Name",
"type": "label", "type": "readonly",
"maxLength": 50, "maxLength": 50,
"default_value": "(unknown)", "default_value": "(unknown)",
"options": [], "options": [],
@@ -102,7 +102,7 @@
}, },
{ {
"function": "dev_Vendor", "function": "dev_Vendor",
"type": "label", "type": "readonly",
"maxLength": 250, "maxLength": 250,
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -122,7 +122,7 @@
}, },
{ {
"function": "dev_Favorite", "function": "dev_Favorite",
"type": "integer", "type": "integer.checkbox",
"default_value": 0, "default_value": 0,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -180,7 +180,7 @@
}, },
{ {
"function": "dev_FirstConnection", "function": "dev_FirstConnection",
"type": "label", "type": "readonly",
"format": "date-time", "format": "date-time",
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -200,7 +200,7 @@
}, },
{ {
"function": "dev_LastConnection", "function": "dev_LastConnection",
"type": "label", "type": "readonly",
"format": "date-time", "format": "date-time",
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -220,7 +220,7 @@
}, },
{ {
"function": "dev_LastIP", "function": "dev_LastIP",
"type": "label", "type": "readonly",
"maxLength": 50, "maxLength": 50,
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -240,7 +240,7 @@
}, },
{ {
"function": "dev_StaticIP", "function": "dev_StaticIP",
"type": "label", "type": "integer.checkbox",
"default_value": 0, "default_value": 0,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -253,13 +253,13 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether the device has a static IP address. Uneditable - Autodetected." "string": "Indicates whether the device has a static IP address."
} }
] ]
}, },
{ {
"function": "dev_ScanCycle", "function": "dev_ScanCycle",
"type": "integer", "type": "integer.checkbox",
"default_value": 1, "default_value": 1,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -272,13 +272,13 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "The default value of the <code>Scan device</code> dropdown. Select <code>1</code> if newly discovered devices should be scanned (this will result in <code>Yes</code> being selected in the dropdown) or <code>0</code>, if not." "string": "The default value of the <code>Scan device</code> dropdown. Enable if newly discovered devices should be scanned."
} }
] ]
}, },
{ {
"function": "dev_LogEvents", "function": "dev_LogEvents",
"type": "integer", "type": "integer.checkbox",
"default_value": 1, "default_value": 1,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -296,7 +296,7 @@
}, },
{ {
"function": "dev_AlertEvents", "function": "dev_AlertEvents",
"type": "integer", "type": "integer.checkbox",
"default_value": 1, "default_value": 1,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -309,13 +309,13 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether events related to the device should trigger alerts. The default value of the <code>Alert All Events</code> checkbox (<code>1</code> is checked, <code>0</code> is unchecked)." "string": "Indicates whether events related to the device should trigger alerts. The default value of the <code>Alert All Events</code> checkbox."
} }
] ]
}, },
{ {
"function": "dev_AlertDeviceDown", "function": "dev_AlertDeviceDown",
"type": "integer", "type": "integer.checkbox",
"default_value": 0, "default_value": 0,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -328,7 +328,7 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether an alert should be triggered when the device goes down. The default value of the <code>Alert Down</code> checkbox (<code>1</code> is checked, <code>0</code> is unchecked)." "string": "Indicates whether an alert should be triggered when the device goes down. The default value of the <code>Alert Down</code> checkbox."
} }
] ]
}, },
@@ -347,13 +347,13 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "The default value of the <code>Skip repeated notifications for</code> dropdown. Select the number of <b>hours</b> for which repeated notifications should be ignored for." "string": "The default value of the <code>Skip repeated notifications for</code> dropdown. Enter number of <b>hours</b> for which repeated notifications should be ignored for. If you enter <code>0</code> then you get notified on all events."
} }
] ]
}, },
{ {
"function": "dev_LastNotification", "function": "dev_LastNotification",
"type": "label", "type": "readonly",
"format": "date-time", "format": "date-time",
"default_value": "", "default_value": "",
"options": [], "options": [],
@@ -373,7 +373,7 @@
}, },
{ {
"function": "dev_PresentLastScan", "function": "dev_PresentLastScan",
"type": "label", "type": "integer.checkbox",
"default_value": 1, "default_value": 1,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -386,13 +386,13 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether the device was present in the last scan. Uneditable - Autodetected." "string": "Indicates whether the device should be marked as present after detected in a scan."
} }
] ]
}, },
{ {
"function": "dev_NewDevice", "function": "dev_NewDevice",
"type": "integer", "type": "integer.checkbox",
"default_value": true, "default_value": true,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -405,7 +405,7 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether the device is considered a new device. The default value of the <code>New Device</code> checkbox (<code>1</code> is checked, <code>0</code> is unchecked)." "string": "Indicates whether the device is considered a new device. The default value of the <code>New Device</code> checkbox."
} }
] ]
}, },
@@ -431,7 +431,7 @@
}, },
{ {
"function": "dev_Archived", "function": "dev_Archived",
"type": "integer", "type": "integer.checkbox",
"default_value": 0, "default_value": 0,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -444,7 +444,7 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Indicates whether the device is archived. The default value of the <code>Archived</code> checkbox (<code>1</code> is checked, <code>0</code> is unchecked)." "string": "Indicates whether the device is archived. The default value of the <code>Archived</code> checkbox."
} }
] ]
}, },
@@ -469,7 +469,7 @@
}, },
{ {
"function": "dev_Network_Node_port", "function": "dev_Network_Node_port",
"type": "label", "type": "readonly",
"default_value": 0, "default_value": 0,
"options": [], "options": [],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -501,7 +501,7 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "The icon associated with the device." "string": "The icon associated with the device. Check the <a href=\"https://github.com/jokob-sk/Pi.Alert/blob/main/docs/ICONS.md\" target=\"_blank\">documentation on icons</a> for more details."
} }
] ]
} }
+3 -3
View File
@@ -204,7 +204,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -249,7 +249,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1"], "default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -264,7 +264,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],
+3 -3
View File
@@ -216,7 +216,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -295,7 +295,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1"], "default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -310,7 +310,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],
+1 -1
View File
@@ -35,7 +35,7 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "always_after_scan"], "options": ["disabled", "once", "always_after_scan"],
"localized": ["name", "description"], "localized": ["name", "description"],
+4 -4
View File
@@ -246,7 +246,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -306,7 +306,7 @@
}, },
{ {
"function": "protocol", "function": "protocol",
"type": "selecttext", "type": "text.select",
"default_value":"https://", "default_value":"https://",
"options": ["https://", "http://"], "options": ["https://", "http://"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -415,7 +415,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1", "Watched_Value4"], "default_value":["Watched_Value1", "Watched_Value4"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -430,7 +430,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],
+3 -3
View File
@@ -240,7 +240,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"type": "selecttext", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -319,7 +319,7 @@
}, },
{ {
"function": "WATCH", "function": "WATCH",
"type": "multiselect", "type": "text.multiselect",
"default_value":["Watched_Value1"], "default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"localized": ["name", "description"], "localized": ["name", "description"],
@@ -334,7 +334,7 @@
}, },
{ {
"function": "REPORT_ON", "function": "REPORT_ON",
"type": "multiselect", "type": "text.multiselect",
"default_value":["new","watched-changed"], "default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed"], "options": ["new","watched-changed","watched-not-changed"],
"localized": ["name", "description"], "localized": ["name", "description"],