Exemplo n.º 1
0
        private void Export(IBackup backup, RequestInfo info)
        {
            var cmdline         = Library.Utility.Utility.ParseBool(info.Request.QueryString["cmdline"].Value, false);
            var argsonly        = Library.Utility.Utility.ParseBool(info.Request.QueryString["argsonly"].Value, false);
            var exportPasswords = Library.Utility.Utility.ParseBool(info.Request.QueryString["export-passwords"].Value, false);

            if (!exportPasswords)
            {
                backup.SanitizeSettings();
                backup.SanitizeTargetUrl();
            }

            if (cmdline)
            {
                info.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, backup)) });
            }
            else if (argsonly)
            {
                var parts = Runner.GetCommandLineParts(Runner.CreateTask(DuplicatiOperation.Backup, backup));

                info.OutputOK(new {
                    Backend   = parts.First(),
                    Arguments = parts.Skip(1).Where(x => !x.StartsWith("--", StringComparison.Ordinal)),
                    Options   = parts.Skip(1).Where(x => x.StartsWith("--", StringComparison.Ordinal))
                });
            }
            else
            {
                var    passphrase = info.Request.QueryString["passphrase"].Value;
                byte[] data       = Backup.ExportToJSON(backup, passphrase);

                string filename = Library.Utility.Uri.UrlEncode(backup.Name) + "-duplicati-config.json";
                if (!string.IsNullOrWhiteSpace(passphrase))
                {
                    filename += ".aes";
                }

                info.Response.ContentLength = data.Length;
                info.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
                info.Response.ContentType = "application/octet-stream";

                info.BodyWriter.SetOK();
                info.Response.SendHeaders();
                info.Response.SendBody(data);
            }
        }
Exemplo n.º 2
0
        private void Export(IBackup backup, RequestInfo info)
        {
            var cmdline         = Library.Utility.Utility.ParseBool(info.Request.QueryString["cmdline"].Value, false);
            var argsonly        = Library.Utility.Utility.ParseBool(info.Request.QueryString["argsonly"].Value, false);
            var exportPasswords = Library.Utility.Utility.ParseBool(info.Request.QueryString["export-passwords"].Value, false);

            if (!exportPasswords)
            {
                backup.SanitizeSettings();
                backup.SanitizeTargetUrl();
            }

            if (cmdline)
            {
                info.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, backup)) });
            }
            else if (argsonly)
            {
                var parts = Runner.GetCommandLineParts(Runner.CreateTask(DuplicatiOperation.Backup, backup));

                info.OutputOK(new {
                    Backend   = parts.First(),
                    Arguments = parts.Skip(1).Where(x => !x.StartsWith("--", StringComparison.Ordinal)),
                    Options   = parts.Skip(1).Where(x => x.StartsWith("--", StringComparison.Ordinal))
                });
            }
            else
            {
                var passphrase = info.Request.QueryString["passphrase"].Value;
                var ipx        = Program.DataConnection.PrepareBackupForExport(backup);

                byte[] data;
                using (var ms = new System.IO.MemoryStream())
                    using (var sw = new System.IO.StreamWriter(ms))
                    {
                        Serializer.SerializeJson(sw, ipx, true);

                        if (!string.IsNullOrWhiteSpace(passphrase))
                        {
                            ms.Position = 0;
                            using (var ms2 = new System.IO.MemoryStream())
                                using (var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary <string, string>()))
                                {
                                    m.Encrypt(ms, ms2);
                                    data = ms2.ToArray();
                                }
                        }
                        else
                        {
                            data = ms.ToArray();
                        }
                    }

                var filename = Library.Utility.Uri.UrlEncode(backup.Name) + "-duplicati-config.json";
                if (!string.IsNullOrWhiteSpace(passphrase))
                {
                    filename += ".aes";
                }

                info.Response.ContentLength = data.Length;
                info.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
                info.Response.ContentType = "application/octet-stream";

                info.BodyWriter.SetOK();
                info.Response.SendHeaders();
                info.Response.SendBody(data);
            }
        }
Exemplo n.º 3
0
 public static void RemovePasswords(IBackup backup)
 {
     backup.SanitizeSettings();
     backup.SanitizeTargetUrl();
 }