Exemplo n.º 1
0
 public ActionResult Index()
 {
     try
     {
         List <DatabaseInfo> databases = null;
         databases = MgmtMdl.GetDatabases("Databases.Owner", User.Identity.GetADUsername());
         return(View("Index", databases));
     }
     catch (Exception e)
     {
         System.Web.HttpContext.Current.Session["ErrorInfo"] = e.ToString();
         return(RedirectToAction("Error", "View"));
     }
 }
Exemplo n.º 2
0
        public virtual ActionResult Create(CreateSubmission createSubmission, string ID)
        {
            try
            {
                // Reattach server data to the submission.
                createSubmission.Host = MgmtMdl.GetServer(ID, User.Identity.GetADUsername());

                // Verify data.
                if (!ModelState.IsValid) // Invalid HTML form.
                {
                    return(View(createSubmission));
                }
                if (createSubmission.DatabasePassword != createSubmission.DatabasePasswordVerify) // Passwords don't match.
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "Passwords do not match.";
                    return(View(createSubmission));
                }
                Match PasswordVerification = Regex.Match(createSubmission.DatabasePassword, @"(?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*", RegexOptions.ECMAScript);
                if (!PasswordVerification.Success) // Password requirements.
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "Password does not meet minimal password requirments.";
                    return(View(createSubmission));
                }
                Match DatabaseNameVerification = Regex.Match(createSubmission.DatabaseName, @"^[0-9A-Za-z_]+$");
                if (!DatabaseNameVerification.Success) // Invalid database name.
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "Database name contains invalid characters.";
                    return(View(createSubmission));
                }
                Match DatabaseUserVerification = Regex.Match(createSubmission.DatabaseUser, @"^[0-9A-Za-z_]+$");
                if (!DatabaseUserVerification.Success) // Invalid database username.
                {
                    System.Web.HttpContext.Current.Session["StatusMessage"] = "Administrator username contains invalid characters.";
                    return(View(createSubmission));
                }
                List <DatabaseInfo> databases = MgmtMdl.GetDatabases("Databases.ServerID", createSubmission.Host.ServerID);
                for (int i = 0; i < databases.Count; i++)
                {
                    if (databases[i].Name == createSubmission.DatabaseName) // Database already exists.
                    {
                        System.Web.HttpContext.Current.Session["StatusMessage"] = @"The database <strong>" + createSubmission.DatabaseName + @"</strong> already exists on this server.";
                        return(View(createSubmission));
                    }
                    if (databases[i].Username == createSubmission.DatabaseUser) // Username already exists.
                    {
                        System.Web.HttpContext.Current.Session["StatusMessage"] = @"The username <strong>" + createSubmission.DatabaseUser + @"/<strong> already exists on this server.";
                        return(View(createSubmission));
                    }
                }

                // Add the database info to the management database.
                if (createSubmission.DoNotSave)
                {
                    createSubmission.DatabasePassword = "";
                }
                string databaseID = MgmtMdl.AddDatabase(createSubmission.DatabaseName, createSubmission.Host.ServerID, User.Identity.GetADUsername(), createSubmission.DatabaseUser, createSubmission.DatabasePassword);

                // Attempt to create the database.
                try
                { IntfcMdl.Create(createSubmission); }
                catch (Exception e) // Self-clean.
                {
                    MgmtMdl.RemoveDatabase(databaseID);
                    throw e;
                }

                // Redirect and display success message.
                System.Web.HttpContext.Current.Session["StatusMessage"] = @"The database <strong>" + createSubmission.DatabaseName + @"</strong> was created on <strong>" + createSubmission.Host.Hostname + @"</strong>.";
                System.Web.HttpContext.Current.Session["StatusStyle"]   = "success";
                return(RedirectToAction("Database", "View", new { id = databaseID }));
            }
            catch (Exception e)
            {
                System.Web.HttpContext.Current.Session["ErrorInfo"] = e.ToString();
                return(RedirectToAction("Error", "View"));
            }
        }