optional prefix gdrive backups with host and domain name, for https://github.com/opnsense/core/issues/2262

This commit is contained in:
Ad Schellevis 2018-03-16 18:59:44 +01:00
parent 6961ad48ba
commit 8c44049298
2 changed files with 16 additions and 3 deletions

View File

@ -300,6 +300,11 @@ function backup_to_google_drive()
if ($cnf->isValid()) {
$config = $cnf->object();
if (isset($config->system->remotebackup) && isset($config->system->remotebackup->GDriveEnabled) && $config->system->remotebackup->GDriveEnabled == "on") {
if (!empty($config->system->remotebackup->GDrivePrefixHostname)) {
$fileprefix = (string)$config->system->hostname . "." . (string)$config->system->domain . "-";
} else {
$fileprefix = "config-";
}
try {
$client = new Google\API\Drive();
$client->login($config->system->remotebackup->GDriveEmail->__toString(),
@ -315,7 +320,7 @@ function backup_to_google_drive()
tagfile_reformat($confdata_enc, $confdata_enc, "config.xml");
// read filelist (config-*.xml)
// read filelist ({prefix}*.xml)
try {
$files = $client->listFiles($config->system->remotebackup->GDriveFolderID->__toString());
} catch (Exception $e) {
@ -325,7 +330,7 @@ function backup_to_google_drive()
$configfiles = array();
foreach ($files as $file) {
if (fnmatch("config-*.xml", $file['title'])) {
if (fnmatch("{$fileprefix}*.xml", $file['title'])) {
$configfiles[$file['title']] = $file;
}
}
@ -333,7 +338,7 @@ function backup_to_google_drive()
// backup new file if changed (or if first in backup)
$target_filename = "config-" . time() . ".xml";
$target_filename = $fileprefix . time() . ".xml";
if (count($configfiles) > 1) {
// compare last backup with current, only save new
try {

View File

@ -113,6 +113,7 @@ $do_reboot = false;
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
$pconfig['GDriveEnabled'] = isset($config['system']['remotebackup']['GDriveEnabled']) ? $config['system']['remotebackup']['GDriveEnabled'] : null;
$pconfig['GDrivePrefixHostname'] = isset($config['system']['remotebackup']['GDrivePrefixHostname']) ? $config['system']['remotebackup']['GDrivePrefixHostname'] : null;
$pconfig['GDriveEmail'] = isset($config['system']['remotebackup']['GDriveEmail']) ? $config['system']['remotebackup']['GDriveEmail'] : null;
$pconfig['GDriveP12key'] = isset($config['system']['remotebackup']['GDriveP12key']) ? $config['system']['remotebackup']['GDriveP12key'] : null;
$pconfig['GDriveFolderID'] = isset($config['system']['remotebackup']['GDriveFolderID']) ? $config['system']['remotebackup']['GDriveFolderID'] : null;
@ -253,6 +254,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$config['system']['remotebackup'] = array() ;
}
$config['system']['remotebackup']['GDriveEnabled'] = $_POST['GDriveEnabled'];
$config['system']['remotebackup']['GDrivePrefixHostname'] = $_POST['GDrivePrefixHostname'];
$config['system']['remotebackup']['GDriveEmail'] = $_POST['GDriveEmail'] ;
$config['system']['remotebackup']['GDriveFolderID'] = $_POST['GDriveFolderID'];
$config['system']['remotebackup']['GDrivePassword'] = $_POST['GDrivePassword'];
@ -471,6 +473,12 @@ $( document ).ready(function() {
<input name="GDriveFolderID" value="<?=$pconfig['GDriveFolderID'];?>" type="text">
</td>
</tr>
<tr>
<td><?=gettext("Prefix hostname to backupfile"); ?> </td>
<td>
<input name="GDrivePrefixHostname" type="checkbox" <?=!empty($pconfig['GDrivePrefixHostname']) ? "checked" : "";?> >
</td>
</tr>
<tr>
<td><?=gettext("Backup Count"); ?> </td>
<td>