🔃 Sync Hub v0.7.1
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"unique_prefix": "SYNC",
|
"unique_prefix": "SYNC",
|
||||||
"plugin_type": "system",
|
"plugin_type": "system",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"data_source": "template",
|
"data_source": "script",
|
||||||
"show_ui": true,
|
"show_ui": true,
|
||||||
"localized": ["display_name", "description", "icon"],
|
"localized": ["display_name", "description", "icon"],
|
||||||
"display_name": [{
|
"display_name": [{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if ($auth_header !== $expected_token) {
|
if ($auth_header !== $expected_token) {
|
||||||
http_response_code(403);
|
http_response_code(403);
|
||||||
echo 'Forbidden';
|
echo 'Forbidden';
|
||||||
write_notification("[Plugin: Sync hub API] Incorrect API Token", "alert");
|
write_notification("[Plugin: SYNC] Incorrect API Token", "alert");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
// Create the storage directory if it doesn't exist
|
// Create the storage directory if it doesn't exist
|
||||||
if (!is_dir($storage_path)) {
|
if (!is_dir($storage_path)) {
|
||||||
echo "Could not open folder: {$storage_path}";
|
echo "Could not open folder: {$storage_path}";
|
||||||
write_notification("[Plugin: Sync hub API] Could not open folder: {$storage_path}", "alert");
|
write_notification("[Plugin: SYNC] Could not open folder: {$storage_path}", "alert");
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -43,10 +43,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
file_put_contents($file_path, $data);
|
file_put_contents($file_path, $data);
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
echo 'Data received and stored successfully';
|
echo 'Data received and stored successfully';
|
||||||
write_notification("[Plugin: Sync hub API] Data received ({$plugin_folder})", "info");
|
write_notification("[Plugin: SYNC] Data received ({$plugin_folder})", "info");
|
||||||
} else {
|
} else {
|
||||||
http_response_code(405);
|
http_response_code(405);
|
||||||
echo 'Method Not Allowed';
|
echo 'Method Not Allowed';
|
||||||
write_notification("[Plugin: Sync hub API] Method Not Allowed", "alert");
|
write_notification("[Plugin: SYNC] Method Not Allowed", "alert");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from logger import mylog
|
|||||||
from const import pluginsPath, fullDbPath
|
from const import pluginsPath, fullDbPath
|
||||||
from helper import timeNowTZ, get_setting_value
|
from helper import timeNowTZ, get_setting_value
|
||||||
from cryptography import encrypt_data
|
from cryptography import encrypt_data
|
||||||
|
from notification import write_notification
|
||||||
|
|
||||||
# Define the current path and log file paths
|
# Define the current path and log file paths
|
||||||
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||||
@@ -151,6 +152,11 @@ def main():
|
|||||||
# Use executemany for batch insertion
|
# Use executemany for batch insertion
|
||||||
cursor.executemany(sql, values)
|
cursor.executemany(sql, values)
|
||||||
|
|
||||||
|
message = f'[{pluginName}] Inserted "{len(new_devices)}" new devices'
|
||||||
|
|
||||||
|
mylog('verbose', [message])
|
||||||
|
write_notification(message, 'info', timeNowTZ())
|
||||||
|
|
||||||
# Commit and close the connection
|
# Commit and close the connection
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
@@ -181,9 +187,13 @@ def send_data(api_token, file_content, encryption_key, plugin_folder, node_name,
|
|||||||
mylog('verbose', [f'[{pluginName}] response: "{response}"'])
|
mylog('verbose', [f'[{pluginName}] response: "{response}"'])
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
mylog('verbose', [f'[{pluginName}] Data for "{plugin_folder}" sent successfully'])
|
message = f'[{pluginName}] Data for "{plugin_folder}" sent successfully'
|
||||||
|
mylog('verbose', [message])
|
||||||
|
write_notification(message, 'info', timeNowTZ())
|
||||||
else:
|
else:
|
||||||
mylog('verbose', [f'[{pluginName}] Failed to send data for "{plugin_folder}"'])
|
message = f'[{pluginName}] Failed to send data for "{plugin_folder}" (Status code: {response.status_code})'
|
||||||
|
mylog('verbose', [message])
|
||||||
|
write_notification(message, 'alert', timeNowTZ())
|
||||||
|
|
||||||
# log result
|
# log result
|
||||||
plugin_objects.add_object(
|
plugin_objects.add_object(
|
||||||
|
|||||||
Reference in New Issue
Block a user