🔃 Sync Hub v0.53

This commit is contained in:
jokob-sk
2024-06-04 19:58:48 +10:00
parent 2c8c998a97
commit bac8ac30aa
5 changed files with 63 additions and 48 deletions

View File

@@ -4,25 +4,25 @@
require '/app/front/php/server/init.php';
function decrypt_data($encoded_data, $key) {
// Base64 decode the encrypted data
$data = base64_decode($encoded_data);
// function decrypt_data($encoded_data, $key) {
// // Base64 decode the encrypted data
// $data = base64_decode($encoded_data);
// Extract the IV and the ciphertext
$iv = substr($data, 0, 16);
$ciphertext = substr($data, 16);
// // Extract the IV and the ciphertext
// $iv = substr($data, 0, 16);
// $ciphertext = substr($data, 16);
// Derive the key using SHA-256
$key = hash('sha256', $key, true);
// // Derive the key using SHA-256
// $key = hash('sha256', $key, true);
// Decrypt the ciphertext using AES-256-CBC
$decrypted_data = openssl_decrypt($ciphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
// // Decrypt the ciphertext using AES-256-CBC
// $decrypted_data = openssl_decrypt($ciphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
// Remove padding
$decrypted_data = rtrim($decrypted_data, "\0");
// // Remove padding
// $decrypted_data = rtrim($decrypted_data, "\0");
return $decrypted_data;
}
// return $decrypted_data;
// }
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve the authorization header
@@ -43,14 +43,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$plugin_folder = $_POST['plugin_folder'] ?? '';
$node_name = $_POST['node_name'] ?? '';
$decoded_data = decrypt_data($data, getSettingValue('SYNC_encryption_key'));
// $decoded_data = decrypt_data($data, getSettingValue('SYNC_encryption_key'));
if ($decoded_data === false or $decoded_data === null) {
write_notification("[Plugin: Sync hub API] Bad Request: Decryption failed", "alert");
http_response_code(400);
echo 'Bad Request: Decryption failed';
exit;
}
// if ($decoded_data === false or $decoded_data === null) {
// write_notification("[Plugin: Sync hub API] Bad Request: Decryption failed", "alert");
// http_response_code(400);
// echo 'Bad Request: Decryption failed';
// exit;
// }
$storage_path = "/app/front/plugins/{$plugin_folder}";
@@ -64,14 +64,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Generate a unique file path to avoid overwriting existing files
$files = glob("{$storage_path}/last_result.{$node_name}.*.log");
$files = array_filter($files, function($file) {
return preg_match('/last_result\.\d+\.log$/', basename($file));
});
// $files = array_filter($files, function($file) {
// return preg_match('/last_result\.\d+\.log$/', basename($file));
// });
$file_count = count($files) + 1;
$file_path = "{$storage_path}/last_result.{$node_name}.{$file_count}.log";
// Save the decoded data to the file
file_put_contents($file_path, $decoded_data);
file_put_contents($file_path, $data);
http_response_code(200);
echo 'Data received and stored successfully';
} else {