2018-11-04 17:46:33 +01:00
backupApp . controller ( "ExportController" , function ( $scope , $routeParams , AppService , DialogService , gettextCatalog ) {
$scope . ExportType = "file" ;
2018-11-04 16:51:40 +01:00
$scope . ExportPasswords = true ;
2015-11-28 23:54:26 +01:00
$scope . Connecting = false ;
$scope . BackupID = $routeParams . backupid ;
$scope . Completed = false ;
$scope . doExport = function () {
2018-11-04 16:51:40 +01:00
// Helper function(s)
2018-11-04 17:17:59 +01:00
function warnUnencryptedPasswords ( continuation ) {
2018-11-04 17:53:41 +01:00
if ( $scope . ExportType === "file" && $scope . ExportPasswords && ! $scope . fileEncrypted ) {
2018-11-04 17:46:33 +01:00
DialogService . dialog ( gettextCatalog . getString ( "Not using encryption" ), gettextCatalog . getString ( "The configuration should be kept safe. Are you sure you want to save an unencrypted file containing your passwords?" ), [ gettextCatalog . getString ( "Cancel" ), gettextCatalog . getString ( "Yes, I understand the risk" )], function ( ix ) {
2018-11-04 17:53:41 +01:00
if ( ix === 0 ) {
2018-11-04 17:33:23 +01:00
$scope . CurrentStep = 0 ;
} else {
continuation ();
}
2018-11-04 16:51:40 +01:00
});
} else {
continuation ();
}
2015-11-28 23:54:26 +01:00
}
2018-11-04 16:51:40 +01:00
// The actual export function to call after all checks pass
2018-11-04 17:17:59 +01:00
function getExport () {
2018-11-04 17:53:41 +01:00
if ( $scope . ExportType === "commandline" ) {
2018-11-04 16:51:40 +01:00
$scope . Connecting = true ;
2018-11-04 17:46:33 +01:00
AppService . get ( "/backup/" + $scope . BackupID + "/export?cmdline=true&export-passwords=" + encodeURIComponent ( $scope . ExportPasswords )). then (
2018-11-04 16:51:40 +01:00
function ( resp ) {
$scope . Connecting = false ;
$scope . Completed = true ;
$scope . CommandLine = resp . data . Command ;
},
function ( resp ) {
$scope . Connecting = false ;
2023-12-12 23:17:12 +01:00
var message = AppService . responseErrorMessage ( resp );
2018-11-04 16:51:40 +01:00
2018-12-12 11:39:03 -02:00
DialogService . dialog ( gettextCatalog . getString ( "Error" ), gettextCatalog . getString ( "Failed to connect: {{message}}" , { message : message }));
2018-11-04 16:51:40 +01:00
}
);
} else {
$scope . DownloadURL = AppService . get_export_url ( $scope . BackupID , $scope . UseEncryption ? $scope . Passphrase : null , $scope . ExportPasswords );
$scope . Completed = true ;
}
2018-11-04 17:33:23 +01:00
}
2018-11-04 16:51:40 +01:00
// Make checks that do not require user input
$scope . fileEncrypted = false ;
2018-11-04 17:53:41 +01:00
if ( $scope . UseEncryption && $scope . ExportType === "file" ) {
2018-12-22 19:17:49 +01:00
if ( typeof $scope . Passphrase === "undefined" || $scope . Passphrase . trim (). length === 0 ) {
2018-11-04 17:46:33 +01:00
DialogService . dialog ( gettextCatalog . getString ( "No passphrase entered" ), gettextCatalog . getString ( "To export without a passphrase, uncheck the \"Encrypt file\" box" ));
2018-11-04 16:51:40 +01:00
return ;
2018-12-22 19:17:49 +01:00
} else if ( $scope . Passphrase !== $scope . ConfirmPassphrase ) {
DialogService . dialog ( gettextCatalog . getString ( "Error" ), gettextCatalog . getString ( "The passwords do not match" ));
2018-12-22 18:41:36 +01:00
return ;
2018-11-04 17:33:23 +01:00
} else {
2018-11-04 16:51:40 +01:00
$scope . fileEncrypted = true ;
}
}
2015-11-28 23:54:26 +01:00
2018-11-04 16:51:40 +01:00
// Chain various checks that require user input
warnUnencryptedPasswords ( function () { getExport (); });
2018-11-04 17:46:33 +01:00
};
2016-09-15 11:39:27 +02:00
});