예제 #1
0
        public virtual ActionResult Backup(string ID)
        {
            try
            {
                // Preset form.
                BackupSubmission backupSubmission = new BackupSubmission();
                backupSubmission.Method = "Save";

                // Fetch database info.
                DatabaseInfo database = MgmtMdl.GetDatabase(ID);
                backupSubmission.Database = database;

                // Verify user privileges.
                if (database.Owner != User.Identity.GetADUsername())
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "You do not have permisson to access the <strong>" + database.Name + "</strong> database.";
                    return(RedirectToAction("Index", "View"));
                }

                return(View("Backup", backupSubmission));
            }
            catch (Exception e)
            {
                System.Web.HttpContext.Current.Session["ErrorInfo"] = e.ToString();
                return(RedirectToAction("Error", "View"));
            }
        }
예제 #2
0
        public virtual ActionResult Backup(BackupSubmission backupSubmission, string ID)
        {
            try
            {
                // Reattach database info to submission.
                backupSubmission.Database = MgmtMdl.GetDatabase(ID);

                // Verify data.
                if (!ModelState.IsValid) // Invalid HTML form.
                {
                    return(View(backupSubmission));
                }
                if (backupSubmission.Nickname != null)
                {
                    Match DatabaseNameVerification = Regex.Match(backupSubmission.Nickname, @"^[0-9A-Za-z_]+$");
                    if (!DatabaseNameVerification.Success) // Invalid database name.
                    {
                        System.Web.HttpContext.Current.Session["StatusMessage"] = "Backup nickname contains invalid characters.";
                        return(View(backupSubmission));
                    }
                }

                // Compile file save location.
                string nickname = "";
                if (backupSubmission.Nickname != null)
                {
                    nickname = "_" + backupSubmission.Nickname;
                }
                string filename = backupSubmission.Database.Name + "_" + backupSubmission.Database.Host.Hostname.Substring(0, backupSubmission.Database.Host.Hostname.IndexOf('.')) + "_" + backupSubmission.Database.Host.Version + "_" + DateTime.Now.ToString("yyyyMMdd-HHmm") + nickname + "." + backupSubmission.Database.Host.Protocol.ToLower();
                string filepath = "";
                if (backupSubmission.Method == "Save")
                {
                    MgmtMdl.VerifyBackupDirectory(User.Identity.GetADUsername(), true);
                    filepath = @"Backups\" + User.Identity.GetADUsername() + @"\" + filename;
                }
                else
                {
                    filepath = @"Tmp\Downloads\" + filename;
                }

                // Attempt to backup the database.
                IntfcMdl.Backup(backupSubmission, filepath);
                if (backupSubmission.Method == "Download")
                {
                    filename = MgmtMdl.ZipForDownload(filename);
                }

                // Redirect and display success message.
                if (backupSubmission.Method == "Save")
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "The database <strong>" + backupSubmission.Database.Name + "</strong> was backed up to <strong>" + filename + "</strong>.";
                }
                else
                {
                    System.Web.HttpContext.Current.Session["DownloadPath"]  = "/Tmp/Downloads/" + filename;
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "The database <strong>" + backupSubmission.Database.Name + "</strong> was backed up to <a href='/Tmp/Downloads/" + filename + "' target=\"_blank\"><strong><u>" + filename + "</u></strong></a>.";
                }
                System.Web.HttpContext.Current.Session["StatusStyle"] = "success";
                return(RedirectToAction("Database", "View", new { id = backupSubmission.Database.DatabaseID }));
            }
            catch (Exception e)
            {
                System.Web.HttpContext.Current.Session["ErrorInfo"] = e.ToString();
                return(RedirectToAction("Error", "View"));
            }
        }