🔺GraphQL v0.1 + Devices table rebuild + removal of backend compatible scripts

This commit is contained in:
jokob-sk
2024-11-10 21:22:45 +11:00
parent 3cf3305b8f
commit 0bc8b39cec
76 changed files with 1622 additions and 2878 deletions

View File

@@ -31,9 +31,10 @@ The plugin operates in three different modes based on the configuration settings
#### Node (Source) Settings `[n]`
- **API Token** `[n,h]`: `API_TOKEN` (has to be same across all nodes)
- **When to Run** `[n,h]`: `SYNC_RUN`
- **Schedule** `[n,h]`: `SYNC_RUN_SCHD`
- **API Token** `[n,h]`: `SYNC_api_token`
- **Encryption Key** `[n,h]`: `SYNC_encryption_key`
- **Node Name** `[n]`: `SYNC_node_name`
- **Hub URL** `[n]`: `SYNC_hub_url`
@@ -42,9 +43,10 @@ The plugin operates in three different modes based on the configuration settings
#### Hub (Target) Settings `[h]`
- **API Token** `[n,h]`: `API_TOKEN` (has to be same across all nodes)
- **When to Run** `[n,h]`: `SYNC_RUN`
- **Schedule** `[n,h]`: `SYNC_RUN_SCHD`
- **API Token** `[n,h]`: `SYNC_api_token`
- **Encryption Key** `[n,h]`: `SYNC_encryption_key`
- **Nodes to Pull From** `[h]`: `SYNC_nodes`

View File

@@ -110,46 +110,6 @@
}
]
},
{
"function": "api_token",
"type": {
"dataType": "string",
"elements": [
{
"elementType": "input",
"elementHasInputValue": 1,
"elementOptions": [{ "cssClasses": "col-xs-12" }],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "getStringKey": "Gen_Generate" },
{ "customParams": "SYNC_api_token" },
{ "onClick": "generateApiToken(this, 20)" },
{ "cssClasses": "col-xs-12" }
],
"transformers": []
}
]
},
"maxLength": 50,
"default_value": "",
"options": [],
"localized": ["name", "description"],
"name": [
{
"language_code": "en_us",
"string": "API token [n,h]"
}
],
"description": [
{
"language_code": "en_us",
"string": "API token to secure communication, you can generate one or enter any value. It's sent in the request header. The API token needs to be the same on the hub and on the nodes."
}
]
},
{
"function": "encryption_key",
"type": {

View File

@@ -11,7 +11,7 @@ function checkAuthorization($method) {
// Retrieve the authorization header
$headers = apache_request_headers();
$auth_header = $headers['Authorization'] ?? '';
$expected_token = 'Bearer ' . getSettingValue('SYNC_api_token');
$expected_token = 'Bearer ' . getSettingValue('API_TOKEN');
// Verify the authorization token
if ($auth_header !== $expected_token) {

View File

@@ -42,7 +42,7 @@ def main():
# Retrieve configuration settings
plugins_to_sync = get_setting_value('SYNC_plugins')
api_token = get_setting_value('SYNC_api_token')
api_token = get_setting_value('API_TOKEN')
encryption_key = get_setting_value('SYNC_encryption_key')
hub_url = get_setting_value('SYNC_hub_url')
node_name = get_setting_value('SYNC_node_name')
@@ -165,7 +165,7 @@ def main():
conn = sqlite3.connect(fullDbPath)
cursor = conn.cursor()
# Collect all unique dev_MAC values from the JSON files
# Collect all unique devMac values from the JSON files
unique_mac_addresses = set()
device_data = []
@@ -188,9 +188,9 @@ def main():
with open(file_path, 'r') as f:
data = json.load(f)
for device in data['data']:
if device['dev_MAC'] not in unique_mac_addresses:
device['dev_SyncHubNodeName'] = tmp_SyncHubNodeName
unique_mac_addresses.add(device['dev_MAC'])
if device['devMac'] not in unique_mac_addresses:
device['devSyncHubNode'] = tmp_SyncHubNodeName
unique_mac_addresses.add(device['devMac'])
device_data.append(device)
# Rename the file to "processed_" + current name
@@ -204,27 +204,27 @@ def main():
os.rename(file_path, new_file_path)
if len(device_data) > 0:
# Retrieve existing dev_MAC values from the Devices table
# Retrieve existing devMac values from the Devices table
placeholders = ', '.join('?' for _ in unique_mac_addresses)
cursor.execute(f'SELECT dev_MAC FROM Devices WHERE dev_MAC IN ({placeholders})', tuple(unique_mac_addresses))
cursor.execute(f'SELECT devMac FROM Devices WHERE devMac IN ({placeholders})', tuple(unique_mac_addresses))
existing_mac_addresses = set(row[0] for row in cursor.fetchall())
# insert devices into the lats_result.log to manage state
for device in device_data:
if device['dev_PresentLastScan'] == 1:
if device['devPresentLastScan'] == 1:
plugin_objects.add_object(
primaryId = device['dev_MAC'],
secondaryId = device['dev_LastIP'],
watched1 = device['dev_Name'],
watched2 = device['dev_Vendor'],
watched3 = device['dev_SyncHubNodeName'],
watched4 = device['dev_GUID'],
primaryId = device['devMac'],
secondaryId = device['devLastIP'],
watched1 = device['devName'],
watched2 = device['devVendor'],
watched3 = device['devSyncHubNode'],
watched4 = device['devGUID'],
extra = '',
foreignKey = device['dev_GUID'])
foreignKey = device['devGUID'])
# Filter out existing devices
new_devices = [device for device in device_data if device['dev_MAC'] not in existing_mac_addresses]
new_devices = [device for device in device_data if device['devMac'] not in existing_mac_addresses]
# Remove 'rowid' key if it exists
for device in new_devices: