public ActionResult AddDomain(FormCollection _POST)
        {
            try
            {
                CustomDomain AddDomain = new CustomDomain()
                {
                    Organization = _POST["organization"],
                    Domain       = _POST["domain"],
                    AddasEmail   = _POST["addasemail"] == "on" ? true : false
                };

                model.Domain = AddDomain;

                CommonCAS.Log(string.Format("has run Organization/AddDomain() for organization {0} to add domain {1}", AddDomain.Organization, AddDomain.Domain));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.AddDomain(AddDomain.Organization, AddDomain.Domain, AddDomain.AddasEmail);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("'{0}' added for organization '{1}'.", model.Domain.Domain, model.Domain.Organization));
                    }
                    else
                    {
                        model.OKMessage.Add(string.Format("Domain {0} has been added with following info:", AddDomain.Domain));

                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                            CommonCAS.Log(string.Format("Domain {0} info: {1}", AddDomain.Domain, message.ToString()));
                        }
                    }
                }

                CommonCAS.Stats("Organization/AddDomain");

                return(View("AddDomain", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult Enable(FormCollection _POST)
        {
            try
            {
                // property is disable but means enable
                model.EnableUser.Organization      = _POST["organization"];
                model.EnableUser.UserPrincipalName = _POST["userprincipalname"];
                model.EnableUser.Confirm           = _POST["confirm"] == "on" ? true : false;

                if (!model.EnableUser.Confirm)
                {
                    throw new Exception("You must confirm the action.");
                }

                CommonCAS.Log(string.Format("has run User/Enable(Confirmed: {0}) on user {1}", model.EnableUser.Confirm, model.EnableUser.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.EnableUser(model.EnableUser).Invoke();
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add("User successfully enabled.");
                    }
                    else
                    {
                        model.OKMessage.Add("User enabled with following info:");

                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                        }
                    }
                }

                CommonCAS.Stats("User/EnableUser");

                return(View("Enable", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("Enable", model));
            }
        }
        public ActionResult VerifyDomain(FormCollection _POST)
        {
            try
            {
                model.VerifyDomain = new CustomVerifyDomain()
                {
                    Organization = _POST["organization"],
                    Domain       = _POST["domainname"]
                };

                CommonCAS.Log(string.Format("has run Office365/VerifyDomain() to verify '{0}' for '{1}'", model.VerifyDomain.Domain, model.VerifyDomain.Organization));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.VerifyDomain(model.VerifyDomain.Organization, model.VerifyDomain.Domain);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("Domain {0} has been added.", model.VerifyDomain.Domain));
                    }
                    else
                    {
                        foreach (PSObject message in result)
                        {
                            CommonCAS.Log(string.Format("Domain {0} info: {1}", model.VerifyDomain.Domain, message.ToString()));
                            throw new Exception(string.Format(message.ToString()));
                        }
                    }
                }

                model.OKMessage.Add(string.Format("Domain '{0}' added for organization '{1}'.", model.VerifyDomain.Domain, model.VerifyDomain.Organization));

                CommonCAS.Stats("Office365/VerifyDomain");

                return(View("VerifyDomain", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult AddMailboxPermission(FormCollection _POST)
        {
            try
            {
                CustomMailboxPermission addMailboxPermission = new CustomMailboxPermission()
                {
                    Organization      = _POST["organization"],
                    UserPrincipalName = _POST["userprincipalname"],
                    FullAccess        = _POST["fullaccess"] == "on" ? true : false,
                    SendAs            = _POST["sendas"] == "on" ? true : false
                };

                model.MailboxPermission = addMailboxPermission;

                CommonCAS.Log(string.Format("has run Mail/AddMailboxPermission() on user {0}", addMailboxPermission.UserPrincipalName));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.AddMailboxPermission(addMailboxPermission);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("Mail/AddMailboxPermission");

                if (model.MailboxPermission.FullAccess)
                {
                    model.OKMessage.Add(string.Format("Successfully created FullAccess group for {0}.", model.MailboxPermission.UserPrincipalName));
                }

                if (model.MailboxPermission.SendAs)
                {
                    model.OKMessage.Add(string.Format("Successfully created SendAs group for {0}.", model.MailboxPermission.UserPrincipalName));
                }

                return(View("AddMailboxPermission", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult StartDirSync(FormCollection _POST)
        {
            try
            {
                model.StartDirSync = new CustomStartDirSync()
                {
                    Organization = _POST["organization"],
                    Policy       = _POST["policy"],
                    Force        = _POST["force"] == "on" ? true : false
                };

                CommonCAS.Log(string.Format("has run Office365/StartDirSync() with policy '{0}' for '{1}'", model.StartDirSync.Policy, model.StartDirSync.Organization));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.StartDirSync(model.StartDirSync.Organization, model.StartDirSync.Policy, model.StartDirSync.Force);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("Dirsync {0} has been started for {1}.", model.StartDirSync.Policy, model.StartDirSync.Organization));
                    }
                    else
                    {
                        foreach (PSObject message in result)
                        {
                            CommonCAS.Log(string.Format("Dirsync {0} info: {1}", model.StartDirSync.Policy, message.ToString()));
                            throw new Exception(string.Format(message.ToString()));
                        }
                    }
                }

                CommonCAS.Stats("Office365/StartDirSync");

                return(View("StartDirSync", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult ResetPWD(FormCollection _POST)
        {
            try
            {
                model.ResetPWD.Organization         = _POST["organization"];
                model.ResetPWD.UserPrincipalName    = _POST["userprincipalname"];
                model.ResetPWD.Password             = _POST["password"];
                model.ResetPWD.PasswordNeverExpires = _POST["passwordneverexpires"] == "on" ? true : false;

                CommonCAS.Log(string.Format("has run User/ResetPWD() for {0}, to reset password for user {1}", model.ResetPWD.Organization, model.ResetPWD.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.SetPassword(model.ResetPWD.Organization, model.ResetPWD.UserPrincipalName, model.ResetPWD.Password, model.ResetPWD.PasswordNeverExpires);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("Reset password success for '{1}', from Organization : '{0}' ", model.ResetPWD.Organization, model.ResetPWD.UserPrincipalName));
                    }
                    else
                    {
                        model.OKMessage.Add(string.Format("Reset password success for '{1}', from Organization : '{0}' ", model.ResetPWD.Organization, model.ResetPWD.UserPrincipalName));

                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                        }
                    }
                }

                CommonCAS.Stats("User/ResetPWD");

                return(View("ResetPWD", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("ResetPWD", model));
            }
        }
        public ActionResult SetMailboxAutoResize(FormCollection _POST)
        {
            try
            {
                CustomMailboxAutoResize mailboxAutoResize = new CustomMailboxAutoResize()
                {
                    Organization          = _POST["organization"],
                    ExcludeFromAutoResize = _POST["exclude"] == "true" ? true : false
                };

                model.MailboxAutoResize = mailboxAutoResize;

                CommonCAS.Log(string.Format("has run Mail/SetMailboxAutoResize() for organization {0} to set exclude to {1}", mailboxAutoResize.Organization, mailboxAutoResize.ExcludeFromAutoResize));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.SetMailboxAutoResize(mailboxAutoResize);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("Mail/SetMailboxAutoResize");

                if (mailboxAutoResize.ExcludeFromAutoResize)
                {
                    model.OKMessage.Add(string.Format("Excluded {0} from mailbox auto resizing", mailboxAutoResize.Organization));
                }
                else
                {
                    model.OKMessage.Add(string.Format("Enabled mailbox auto resizing for {0}", mailboxAutoResize.Organization));
                }

                return(View("SetMailboxAutoResize", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult GetDeviceReport(FormCollection _POST)
        {
            try
            {
                model.DeviceReport.Organization      = _POST["organization"];
                model.DeviceReport.UserPrincipalName = _POST["userprincipalname"];

                CommonCAS.Log(string.Format("has run Mail/GetDeviceReport for user {0}", model.DeviceReport.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.GetDeviceReport(model.DeviceReport);
                    var result = ps.Invoke();

                    if (result.Count() > 2)
                    {
                        foreach (var item in result)
                        {
                            model.DeviceReport.ReportHtml += item.ToString();
                        }
                    }
                    else
                    {
                        throw new Exception(model.DeviceReport.UserPrincipalName + " does not have any mobile devices connected.");
                    }
                }

                CommonCAS.Stats("Mail/GetDeviceReport");

                return(View("GetDeviceReportSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult CreateAllAdmins(FormCollection _POST)
        {
            try
            {
                model.CreateALLAdmins.Organization = _POST["organization"];

                CommonCAS.Log(string.Format("has run Organization/CreateALLAdmins() for customer {0}", model.CreateALLAdmins.Organization));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateALLAdmins(model.CreateALLAdmins.Organization);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add("Admins successfully created.");
                    }
                    else
                    {
                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                        }
                    }
                }

                CommonCAS.Stats("Organization/CreateALLAdmins");

                return(View("CreateALLAdmins", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #10
0
        public ActionResult GetItemsReport(FormCollection _POST)
        {
            try
            {
                CustomItemsReport GetItemsReport = new CustomItemsReport()
                {
                    Organization = _POST["organization"],
                    Mail         = _POST["mail"],
                    GetALL       = _POST["getall"] == "on" ? true : false
                };

                model.ItemsReport = GetItemsReport;

                CommonCAS.Log(string.Format("has run Mail/GetItemsReport() for organization {0} and sent the report to {1}", GetItemsReport.Organization, GetItemsReport.Mail));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.GetItemsReport(GetItemsReport.Organization, GetItemsReport.Mail, GetItemsReport.GetALL);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("Mail/GetItemsReport");

                model.OKMessage.Add(string.Format("'{0}' has been sent the report!...", model.ItemsReport.Mail));

                return(View("GetItemsReport", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult CustomerReport(FormCollection _POST)
        {
            try
            {
                model.CustomerReport = new CustomCustomerReport();
                model.CustomerReport.Organization = _POST["organization"];

                CommonCAS.Log(string.Format("has run Service/CustomerReport/{0}", model.CustomerReport.Organization));

                CustomerReportGenerateSQL();
                //CustomerReportGenerate();

                CommonCAS.Stats("Service/CustomerReport/" + model.CustomerReport.Organization);

                return(View("CustomerReportSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult ExpandCPURAM(FormCollection _POST)
        {
            try
            {
                // Expand CPU and create View.
                CustomExpandCPURAM ExpandCPURAM = new CustomExpandCPURAM()

                {
                    TaskID               = _POST["ExpandCPURAM.TaskID"],
                    VMID                 = _POST["vmid"].ToUpper(),
                    DateTime             = _POST["datetime"].ToString(),
                    CPU                  = _POST["ExpandCPURAM.CPU"].ToString(),
                    RAM                  = _POST["ExpandCPURAM.RAM"].ToString(),
                    Email                = _POST["ExpandCPURAM.Email"],
                    DynamicMemoryEnabled = _POST[""]
                };

                var CPU = Convert.ToInt32(ExpandCPURAM.CPU);
                var RAM = Convert.ToInt32(ExpandCPURAM.RAM);

                if (CPU > 4)
                {
                    throw new ArgumentException("For core numbers over 4, please contact Drift..");
                }

                if (RAM > 24)
                {
                    throw new ArgumentException("For RAM configurations over 24, please contact Drift..");
                }

                if (ExpandCPURAM.TaskID.Length == 0)
                {
                    throw new ArgumentException("Please enter a task id");
                }

                if (ExpandCPURAM.TaskID.Length < 6 || ExpandCPURAM.TaskID.Length > 6)
                {
                    throw new ArgumentException("The taskid must be 6 characters long.");
                }


                CommonCAS.Log(string.Format("has run Service/ExpandCPURAM() to Expand CPU/RAM on server {0}, at date {1}, with TaskID {2}", ExpandCPURAM.VMID, ExpandCPURAM.DateTime, ExpandCPURAM.TaskID));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.ExpandCPURAM(ExpandCPURAM.VMID, ExpandCPURAM.DateTime, ExpandCPURAM.CPU, ExpandCPURAM.RAM, ExpandCPURAM.Email, ExpandCPURAM.DynamicMemoryEnabled, ExpandCPURAM.TaskID);
                    var result = ps.Invoke();
                }

                model.OKMessage.Add(string.Format("The VM has been scheduled for expansion on {0}. CPU/RAM will be set to: {1} Cores, and {2} GB RAM.", ExpandCPURAM.DateTime, ExpandCPURAM.CPU, ExpandCPURAM.RAM));

                CommonCAS.Stats("Service/ExpandCPURAM");

                return(View("ExpandCPURAM", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult ExpandVHD(FormCollection _POST)
        {
            try
            {
                // Expand VHD and create View.
                CustomExpandVHD ExpandVHD = new CustomExpandVHD()
                {
                    TaskID   = _POST["ExpandVHD.TaskID"],
                    VMID     = _POST["vmid"].ToUpper(),
                    VHDID    = _POST["vhdid"],
                    DateTime = _POST["datetime"].ToString(),
                    GB       = _POST["ExpandVHD.GB"],
                    Email    = _POST["ExpandVHD.Email"]
                };

                var GB = Convert.ToInt32(ExpandVHD.GB);

                if (GB > 50)
                {
                    throw new ArgumentException("For more than 50 GB, please contact Drift..");
                }

                if (ExpandVHD.TaskID.Length == 0)
                {
                    throw new ArgumentException("Please enter a task id");
                }

                if (ExpandVHD.TaskID.Length < 6 || ExpandVHD.TaskID.Length > 6)
                {
                    throw new ArgumentException("The taskid must be 6 characters long.");
                }

                CommonCAS.Log(string.Format("has run Service/ExpandVHD() to Expand VHD on {0} at date {1}, with TaskID {2}. The VHD has been scheduled for {3} GB more..", ExpandVHD.VMID, ExpandVHD.DateTime, ExpandVHD.TaskID, ExpandVHD.GB));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.ExpandVHD(ExpandVHD.VMID, ExpandVHD.VHDID, ExpandVHD.DateTime, ExpandVHD.GB, ExpandVHD.Email, ExpandVHD.TaskID);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("The VM has been scheduled for expansion on {0}, with {1} GB", ExpandVHD.DateTime, ExpandVHD.GB));
                    }
                    else
                    {
                        model.OKMessage.Add(string.Format("VM has been expanded with following info:"));

                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                            CommonCAS.Log(string.Format("ExpandVHD() extra info: {0}", message.ToString()));
                        }
                    }
                }

                CommonCAS.Stats("Service/ExpandVHD");

                return(View("ExpandVHD", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult Create(FormCollection _POST)
        {
            try
            {
                CustomOrganization organization = new CustomOrganization()
                {
                    Platform            = _POST["platform"],
                    Name                = _POST["Organization.Name"],
                    initials            = _POST["Organization.initials"].ToUpper(),
                    EmailDomainName     = _POST["Organization.EmailDomainName"].ToLower(),
                    Subnet              = _POST["Organization.Subnet"],
                    Vlan                = _POST["Organization.Vlan"],
                    Gateway             = _POST["Organization.Gateway"],
                    IPAddressRangeStart = _POST["Organization.IPAddressRangeStart"],
                    IPAddressRangeEnd   = _POST["Organization.IPAddressRangeEnd"],
                    CreateVMM           = _POST["createvmm"] == "on" ? true : false,
                    createcrayon        = _POST["createcrayon"] == "on" ? true : false,
                };

                CustomCrayonTenantInfoDetailed crayontenantinfodetailed = new CustomCrayonTenantInfoDetailed()
                {
                    InvoiceProfile    = _POST["InvoiceProfile"].ToString(),
                    DomainPrefix      = _POST["CrayonDomainPrefix"],
                    FirstName         = _POST["CrayonFirstName"],
                    LastName          = _POST["CrayonLastName"],
                    Email             = _POST["CrayonTenantInfoDetailed.CrayonEmail"],
                    PhoneNumber       = _POST["CrayonPhoneNumber"],
                    CustomerFirstName = _POST["CrayonCustomerFirstName"],
                    CustomerLastName  = _POST["CrayonCustomerLastName"],
                    AddressLine1      = _POST["CrayonAddressLine1"],
                    City       = _POST["CrayonCity"],
                    Region     = _POST["CrayonRegion"],
                    PostalCode = _POST["CrayonPostalCode"]
                };

                model.Organization = organization;

                if (model.Organizations.Contains(organization.initials))
                {
                    throw new ArgumentException(string.Format("The organizaton '{0}' already exists.", organization.initials));
                }

                if (organization.initials.Length < 2 || organization.initials.Length > 5)
                {
                    throw new ArgumentException("The organizaton name must be between 2 and 5 characters.");
                }

                if (!organization.EmailDomainName.Contains(".") || organization.EmailDomainName.Contains("@"))
                {
                    throw new ArgumentException(string.Format("'{0}' is not a valid email domain name.", organization.EmailDomainName));
                }

                CommonCAS.Log(string.Format("has run Organization/Create() to create {0}", organization.initials));



                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateOrganization(organization, crayontenantinfodetailed);
                    var result = ps.Invoke();

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("Organization '{0}' created.", organization.initials));
                        CommonCAS.Log(string.Format("has run Organization/Create() to create {0}", organization.initials));
                    }
                    else
                    {
                        CommonCAS.Log(string.Format("has run Organization/Create() to create {0}", organization.initials));
                        model.OKMessage.Add(string.Format("Organization '{0}' created with following info:", organization.initials));

                        if (organization.createcrayon)
                        {
                            foreach (PSObject item in result)
                            {
                                model.CrayonTenantDetailed.ExternalPublisherCustomerId = item.Members["ExternalPublisherCustomerId"].Value.ToString();
                                model.CrayonTenantDetailed.AdminUser = item.Members["AdminUser"].Value.ToString();
                                model.CrayonTenantDetailed.AdminPass = item.Members["AdminPass"].Value.ToString();
                            }
                        }
                    }
                }

                CommonCAS.Stats("Organization/Create");
                return(View("CreateSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }