Update GDrive.php

This commit is contained in:
altoch 2026-03-21 22:02:07 +01:00 committed by GitHub
parent 4430e38986
commit 8b51924dbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,6 +89,13 @@ class GDrive extends Base implements IBackupProvider
"label" => gettext("Backup Count"),
"value" => 60
);
$fields[] = array(
"name" => "GDriveEncrypt",
"type" => "checkbox",
"label" => gettext("Encrypt backup files"),
"help" => gettext("Encrypt the configuration file before uploading to Google Drive. A password is required when enabled."),
"value" => null
);
$fields[] = array(
"name" => "GDrivePassword",
"type" => "password",
@ -202,7 +209,14 @@ class GDrive extends Base implements IBackupProvider
// backup source data to local strings (plain/encrypted)
$confdata = file_get_contents('/conf/config.xml');
$confdata_enc = $this->encrypt($confdata, (string)$config->system->remotebackup->GDrivePassword);
$confdata_enc = $confdata;
if (!empty($config->system->remotebackup->GDriveEncrypt)) {
$confdata_enc = $this->encrypt($confdata, (string)$config->system->remotebackup->GDrivePassword);
if (empty($confdata_enc)) {
syslog(LOG_ERR, "GDrive: encryption failed, aborting backup.");
return array();
}
}
// read filelist ({prefix}*.xml)
try {
@ -220,7 +234,6 @@ class GDrive extends Base implements IBackupProvider
}
krsort($configfiles);
// backup new file if changed (or if first in backup)
$target_filename = $fileprefix . time() . ".xml";
if (count($configfiles) > 1) {
@ -233,10 +246,14 @@ class GDrive extends Base implements IBackupProvider
$end_at = strpos($bck_data_enc, "\n---");
$bck_data_enc = substr($bck_data_enc, $start_at, ($end_at - $start_at));
}
$bck_data = $this->decrypt(
$bck_data_enc,
(string)$config->system->remotebackup->GDrivePassword
);
if (!empty($config->system->remotebackup->GDriveEncrypt)) {
$bck_data = $this->decrypt(
$bck_data_enc,
(string)$config->system->remotebackup->GDrivePassword
);
} else {
$bck_data = $bck_data_enc;
}
if ($bck_data == $confdata) {
$target_filename = null;
}