From 5dfd99a55f9651b45051141a0c9142ea09c918bd Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 17 Mar 2015 19:52:14 +0000 Subject: [PATCH] update backup page, add initial support for Google Drive backup --- src/www/diag_backup.php | 76 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 8 deletions(-) diff --git a/src/www/diag_backup.php b/src/www/diag_backup.php index 58a902840..678aa7ae4 100644 --- a/src/www/diag_backup.php +++ b/src/www/diag_backup.php @@ -204,6 +204,8 @@ if ($_POST) { $mode = "download"; else if (stristr($_POST['Submit'], gettext("Restore version"))) $mode = "restore_ver"; + else if (stristr($_POST['Submit'], gettext("Setup/Test Google Drive"))) + $mode = "setup_gdrive"; if ($_POST["ver"] <> "") $ver2restore = $_POST["ver"]; @@ -266,9 +268,7 @@ if ($_POST) { exit; } - } - - if ($mode == "restore") { + }elseif ($mode == "restore") { if ($_POST['decrypt']) { if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf']) @@ -465,9 +465,7 @@ if ($_POST) { $input_errors[] = gettext("The configuration could not be restored (file upload error)."); } } - } - - if ($mode == "restore_ver") { + } elseif ($mode == "restore_ver") { $input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm"); if ($ver2restore <> "") { $conf_file = '/conf/backup/config-' . strtotime($ver2restore) . '.xml'; @@ -480,6 +478,34 @@ if ($_POST) { } else { $input_errors[] = gettext("No version selected."); } + } elseif ( $mode == "setup_gdrive" ){ + global $config; + if (!isset($config['system']['remotebackup'])) { + $config['system']['remotebackup'] = array() ; + } + $config['system']['remotebackup']['GDriveEnabled'] = $_POST['GDriveEnabled']; + $config['system']['remotebackup']['GDriveEmail'] = $_POST['GDriveEmail'] ; + $config['system']['remotebackup']['GDriveFolderID'] = $_POST['GDriveFolderID']; + $config['system']['remotebackup']['GDrivePassword'] = $_POST['GDrivePassword']; + if (is_numeric($_POST['GDriveBackupCount'])) { + $config['system']['remotebackup']['GDriveBackupCount'] = $_POST['GDriveBackupCount']; + } else { + $config['system']['remotebackup']['GDriveBackupCount'] = 30; + } + + if ( $_POST['GDrivePasswordConfirm'] != $_POST['GDrivePassword'] ) { + // log error, but continue + $input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match."); + } + + if (is_uploaded_file($_FILES['GDriveP12file']['tmp_name'])) { + $data = file_get_contents($_FILES['GDriveP12file']['tmp_name']); + $config['system']['remotebackup']['GDriveP12key'] = base64_encode($data); + } elseif ($config['system']['remotebackup']['GDriveEnabled'] != "on") { + unset($config['system']['remotebackup']['GDriveP12key']); + } + + write_config(); } } } @@ -631,7 +657,7 @@ function backuparea_change(obj) { -
+
@@ -693,6 +719,36 @@ function backuparea_change(obj) {
+ +
+
+
+

+
+ +
+
+ + + + + + + + + + + + + + + + +
>
:
" type="submit">
+
+
+
+
@@ -701,7 +757,11 @@ function backuparea_change(obj) { -
+ + + + +