public ActionResult CreateExtUser(FormCollection _POST)
        {
            try
            {
                model.CreateExtUser.Organization = _POST["organization"];
                model.CreateExtUser.UserName     = _POST["username"];
                model.CreateExtUser.Description  = _POST["description"];
                model.CreateExtUser.DisplayName  = _POST["displayname"];
                model.CreateExtUser.DomainName   = _POST["domainname"];

                model.CreateExtUser.Password       = CommonCAS.GeneratePassword();
                model.CreateExtUser.ExpirationDate = _POST["datetime"];

                CommonCAS.Log(string.Format("has run User/CreateExtUser() to create ext user {0}_ext_{1}", model.CreateExtUser.Organization, model.CreateExtUser.UserName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateExtUser(model.CreateExtUser).Invoke();
                }

                CommonCAS.Stats("User/CreateExtUser");

                return(View("CreateExtUserSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("CreateExtUser", model));
            }
        }
        public ActionResult DeleteDistributionGroup(FormCollection _POST)
        {
            try
            {
                model.DistributionGroup.Organization = _POST["organization"];
                model.DistributionGroup.DomainName   = _POST["domainname"];

                CommonCAS.Log(string.Format("has run Mail/DeleteDistributionGroup for contact {0}\\{1}", model.DistributionGroup.Organization, model.DistributionGroup.DomainName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.DeleteDistributionGroup(model.DistributionGroup).Invoke();
                }

                CommonCAS.Stats("Mail/DeleteDistributionGroup");

                return(View("DeleteDistributionGroupSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult AddDistributionGroupManager(FormCollection _POST)
        {
            try
            {
                model.DistributionGroup.Organization = _POST["organization"];
                model.DistributionGroup.DomainName   = _POST["domainname"];
                model.DistributionGroup.ManagedBy    = _POST["upnselector"];

                CommonCAS.Log(string.Format("has run Mail/AddDistributionGroupManager for group {0}\\{1}", model.DistributionGroup.Organization, model.DistributionGroup.DomainName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.AddDistributionGroupManager(model.DistributionGroup).Invoke();
                }

                CommonCAS.Stats("Mail/AddDistributionGroupManager");

                return(View("AddDistributionGroupManagerSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult SetCalendarPermissions(FormCollection _POST)
        {
            try
            {
                model.CalendarPermissions.Organization      = _POST["organization"];
                model.CalendarPermissions.UserPrincipalName = _POST["userprincipalname"];
                model.CalendarPermissions.User         = _POST.GetValues("user[]");
                model.CalendarPermissions.AccessRights = _POST.GetValues("accessrights[]");

                CommonCAS.Log(string.Format("has run Mail/SetCalendarPermissions for user {0}\\{1}", model.CalendarPermissions.Organization, model.CalendarPermissions.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.SetCalendarPermissions(model.CalendarPermissions).Invoke();
                }

                CommonCAS.Stats("Mail/SetCalendarPermissions");

                model.OKMessage.Add(string.Format("Success, updated calendar permissions for '{0}' ", model.CalendarPermissions.UserPrincipalName));

                return(View("GetCalendarPermissions", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("GetCalendarPermissions", model));
            }
        }
        public ActionResult RemoveOOFMessage(FormCollection _POST)
        {
            try
            {
                CustomOOF OOF = new CustomOOF()
                {
                    Organization      = _POST["organization"].ToString(),
                    UserPrincipalName = _POST["userprincipalname"].ToString()
                };

                CommonCAS.Log(string.Format("has run Mail/RemoveOOFMessage() for organization {0} and mailbox {1}", OOF.Organization, OOF.UserPrincipalName));

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

                CommonCAS.Stats("Mail/RemoveOOFMessage");

                model.OKMessage.Add(string.Format("'{0}' OOF has been removed...", OOF.UserPrincipalName));

                return(View("RemoveOOFMessage", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult DeleteMailContact(FormCollection _POST)
        {
            try {
                model.MailContact.Organization       = _POST["organization"];
                model.MailContact.PrimarySmtpAddress = _POST["primarysmtpaddress"];

                CommonCAS.Log(string.Format("has run Mail/DeleteMailContact for contact {0}\\{1}", model.MailContact.Organization, model.MailContact.PrimarySmtpAddress));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.DeleteMailContact(model.MailContact).Invoke();
                }

                CommonCAS.Stats("Mail/DeleteMailContact");

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

                CommonCAS.Log(string.Format("has run Mail/AddMailboxPermissionFullAccess on {0}\\{1}", model.MailboxPermissionFullAccess.Organization, model.MailboxPermissionFullAccess.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.AddMailboxPermissionFullAccess(model.MailboxPermissionFullAccess).Invoke();
                }

                CommonCAS.Stats("Mail/AddMailboxPermissionFullAccess");

                model.OKMessage.Add("Success");

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

                CommonCAS.Log(string.Format("has run Mail/SetMailboxPlan (user: {0}, plan: {1})", model.MailboxPlan.UserPrincipalName, model.MailboxPlan.MailboxPlan));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.SetMailboxPlan(model.MailboxPlan);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("Mail/SetMailboxPlan");

                model.OKMessage.Add("MailboxPlan successfully set.");

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

                CommonCAS.Log(string.Format("has run Mail/RemoveMailbox for {0}\\{1}", model.Mailbox.Organization, model.Mailbox.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.RemoveMailbox(model.Mailbox).Invoke();
                }

                CommonCAS.Stats("Mail/RemoveMailbox");

                model.OKMessage.Add(string.Format("{0}\\{1} was deleted successfully. It can take up to 30 seconds for the mailbox to disappear from SelfService.", model.Mailbox.Organization, model.Mailbox.UserPrincipalName));

                return(View("RemoveMailbox", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("RemoveMailbox", model));
            }
        }
예제 #10
0
        public ActionResult CreateServiceUser(FormCollection _POST)
        {
            try
            {
                model.ServiceUser.Organization = _POST["organization"];
                model.ServiceUser.Service      = _POST["service"];
                model.ServiceUser.Description  = _POST["description"];
                model.ServiceUser.Password     = CommonCAS.GeneratePassword();
                model.ServiceUser.Management   = _POST["management"] == "on" ? true : false;

                CommonCAS.Log(string.Format("has run User/CreateServiceUser() to create service user {0}_svc_{1}", model.ServiceUser.Organization, model.ServiceUser.Service));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateServiceUser(model.ServiceUser);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("User/CreateServiceUser");

                return(View("CreateServiceUserSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("CreateServiceUser", model));
            }
        }
예제 #11
0
        public ActionResult CreateDistributionGroup(FormCollection _POST)
        {
            try
            {
                model.DistributionGroup.Name         = _POST["name"];
                model.DistributionGroup.UserName     = _POST["username"];
                model.DistributionGroup.DomainName   = _POST["domainname"];
                model.DistributionGroup.ManagedBy    = _POST["userprincipalname"];
                model.DistributionGroup.Organization = _POST["organization"];
                model.DistributionGroup.RequireSenderAuthentication = _POST["allowexternalemails"] == "on" ? false : true;


                CommonCAS.Log(string.Format("has run Mail/CreateDistributionGroup() on user {0}", model.DistributionGroup.UserName));

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

                model.OKMessage.Add("Succesfully created distribution group " + model.DistributionGroup.Name + " (" + model.DistributionGroup.UserName + ")");

                CommonCAS.Stats("Mail/CreateDistributionGroup");

                return(View("CreateDistributionGroup", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #12
0
        public ActionResult GetUserMemberOf(FormCollection _POST)
        {
            try
            {
                model.MemberOf.Organization      = _POST["organization"];
                model.MemberOf.UserPrincipalName = _POST["userprincipalname"];

                CommonCAS.Log(string.Format("has run User/GetUserMemberOf() on user {0}\\{1}", model.MemberOf.Organization, model.MemberOf.UserPrincipalName));

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

                    foreach (var item in result)
                    {
                        model.MemberOf.Groups.Add(item.ToString());
                    }
                }

                CommonCAS.Stats("User/GetUserMemberOf");

                return(View("GetUserMemberOfSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult CreateCrayonTenant(FormCollection _POST)
        {
            try
            {
                CustomCrayonTenant CrayonTenant = new CustomCrayonTenant()
                {
                    Name              = _POST["Name"],
                    Reference         = _POST["Reference"],
                    InvoiceProfile    = _POST["InvoiceProfile"],
                    DomainPrefix      = _POST["DomainPrefix"],
                    FirstName         = _POST["FirstName"],
                    LastName          = _POST["LastName"],
                    Email             = _POST["Email"],
                    PhoneNumber       = _POST["PhoneNumber"],
                    CustomerFirstName = _POST["CustomerFirstName"],
                    CustomerLastName  = _POST["CustomerLastName"],
                    AddressLine1      = _POST["AddressLine1"],
                    City              = _POST["City"],
                    Region            = _POST["Region"],
                    PostalCode        = _POST["PostalCode"],
                };

                model.CrayonTenant = CrayonTenant;

                CommonCAS.Log(string.Format("has run Crayon/CreateTenant() to create {0}", CrayonTenant.Name));

                // execute powershell script and dispose powershell object
                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateCrayonTenant(CrayonTenant);
                    var result = ps.Invoke().Single();

                    model.CrayonTenantDetailed.Name                        = result.Members["Name"].Value.ToString();
                    model.CrayonTenantDetailed.DomainPrefix                = result.Members["DomainPrefix"].Value.ToString();
                    model.CrayonTenantDetailed.PublisherCustomerId         = result.Members["PublisherCustomerId"].Value.ToString();
                    model.CrayonTenantDetailed.ExternalPublisherCustomerId = result.Members["ExternalPublisherCustomerId"].Value.ToString();
                    model.CrayonTenantDetailed.Reference                   = result.Members["Reference"].Value.ToString();
                    model.CrayonTenantDetailed.AdminUser                   = result.Members["AdminUser"].Value.ToString();
                    model.CrayonTenantDetailed.AdminPass                   = result.Members["AdminPass"].Value.ToString();
                }

                CommonCAS.Log(string.Format("Crayon Tenant {0} created with: {1}, {2}", CrayonTenant.Reference, model.CrayonTenantDetailed.AdminUser, model.CrayonTenantDetailed.AdminPass));

                model.OKMessage.Add(string.Format("Crayon Tenant '{0}' created.", CrayonTenant.Name));

                CommonCAS.Stats("Crayon/CreateCrayonTenant");

                return(View("CreateCrayonTenantSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult ScheduleReboot(FormCollection _POST)
        {
            try
            {
                // Schedule Reboot and create View.
                CustomScheduleReboot ScheduleReboot = new CustomScheduleReboot()
                {
                    TaskID   = _POST["ScheduleReboot.TaskID"].ToString(),
                    VMID     = _POST["vmid"].ToUpper(),
                    DateTime = _POST["datetime"].ToString(),
                    Email    = _POST["ScheduleReboot.Email"]
                };

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

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

                CommonCAS.Log(string.Format("has run Service/ScheduleReboot() to Reboot {0} at date {1}, with TaskID {2}.", ScheduleReboot.VMID, ScheduleReboot.DateTime, ScheduleReboot.TaskID));

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

                    if (result.Count() == 0)
                    {
                        model.OKMessage.Add(string.Format("The VM has been scheduled for reboot on {0}", ScheduleReboot.DateTime));
                    }
                    else
                    {
                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                            CommonCAS.Log(string.Format("Has run Service/ScheduleReboot() with info: {1}", ScheduleReboot.TaskID, message.ToString()));
                        }
                    }
                }

                CommonCAS.Stats("Service/ScheduleReboot");

                return(View("ScheduleReboot", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #15
0
        public ActionResult Remove(FormCollection _POST)
        {
            try
            {
                CustomUser removeUser = new CustomUser()
                {
                    UserPrincipalName = _POST["userprincipalname"],
                    Organization      = _POST["organization"],
                    DelData           = _POST["deldata"] == "on" ? true : false,
                    Confirm           = _POST["confirm"] == "on" ? true : false
                };

                model.RemoveUser = removeUser;

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

                CommonCAS.Log(string.Format("has run User/Remove for user {0}", removeUser.UserPrincipalName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.RemoveUser(removeUser);
                    var result = ps.Invoke();

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

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

                CommonCAS.Stats("User/Remove");

                return(View("Remove", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #16
0
        public ActionResult SetMailforward(FormCollection _POST)
        {
            try
            {
                model.Mailforward.UserPrincipalName          = _POST["userprincipalname"];
                model.Mailforward.Organization               = _POST["organization"];
                model.Mailforward.ForwardingSmtpAddress      = _POST["forwardingaddress"];
                model.Mailforward.ForwardingType             = _POST["forwardingtype"];
                model.Mailforward.DeliverToMailboxAndForward = _POST["delivertomailboxandforward"] == "on" ? true : false;

                if (model.Mailforward.ForwardingSmtpAddress == string.Empty)
                {
                    model.Mailforward.ForwardingSmtpAddress = "clear";
                }

                CommonCAS.Log(string.Format("has run Mail/SetMailforward(address: {1}) on user {0}", model.Mailforward.UserPrincipalName, model.Mailforward.ForwardingSmtpAddress));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.SetMailforward(model.Mailforward);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("Mail/SetMailforward");

                switch (model.Mailforward.ForwardingType.ToUpper())
                {
                case "INTERNAL":
                    model.OKMessage.Add(string.Format("Successfully set mailforward for {0} to {1}.", model.Mailforward.UserPrincipalName, model.Mailforward.ForwardingSmtpAddress));
                    break;

                case "EXTERNAL":
                    model.OKMessage.Add(string.Format("Successfully set mailforward for {0} to {1}.", model.Mailforward.UserPrincipalName, model.Mailforward.ForwardingSmtpAddress));
                    break;

                case "CLEAR":
                    model.OKMessage.Add(string.Format("Successfully removed mailforward for {0}.", model.Mailforward.UserPrincipalName));
                    break;
                }

                return(View("SetMailforward", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #17
0
        public ActionResult AddAlias(FormCollection _POST)
        {
            try
            {
                CustomAlias addAlias = new CustomAlias()
                {
                    Organization      = _POST["organization"],
                    UserPrincipalName = _POST["userprincipalname"],
                    EmailAddresses    = _POST["emailaddresses"].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>(),
                    SetFirstAsPrimary = _POST["setfirstasprimary"] == "on" ? true : false
                };
                for (int i = 0; i < addAlias.EmailAddresses.Count; i++)
                {
                    addAlias.EmailAddresses[i] = addAlias.EmailAddresses[i].Trim();
                }

                if (addAlias.EmailAddresses.Count == 0)
                {
                    throw new Exception("No aliases specified");
                }

                model.Alias = addAlias;

                CommonCAS.Log(string.Format("has run Mail/AddAlias() for user {0} to add alias {1}", addAlias.UserPrincipalName, string.Join(",", addAlias.EmailAddresses)));

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

                CommonCAS.Stats("Mail/AddAlias");

                model.OKMessage.Add("Successfully added alias for " + addAlias.UserPrincipalName + ":");
                foreach (string alias in addAlias.EmailAddresses)
                {
                    model.OKMessage.Add(alias);
                }

                return(View("AddAlias", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #18
0
        public ActionResult CreateMailbox(FormCollection _POST)
        {
            try
            {
                var NewPassword = CommonCAS.GeneratePassword();

                CustomMailbox newMailbox = new CustomMailbox()
                {
                    UserName     = _POST["username"].Trim(),
                    DomainName   = _POST["domainname"],
                    DisplayName  = _POST["displayname"].TrimEnd(),
                    Organization = _POST["organization"],
                    Password     = CommonCAS.GeneratePassword(),
                    Type         = _POST["type"],
                };

                if (_POST["emailaddresses"] != null)
                {
                    newMailbox.EmailAddresses = _POST["emailaddresses"].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();
                }
                else
                {
                    newMailbox.EmailAddresses = new List <string>();
                }

                model.Mailbox = newMailbox;

                CommonCAS.Log(string.Format("has run Mail/CreateMailbox() to create {0} for {1}.", newMailbox.DisplayName, model.Mailbox.Organization));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateMailbox(newMailbox);
                    var result = ps.Invoke();
                }

                model.OKMessage.Add("Successfully created mailbox " + newMailbox.DisplayName + "for" + newMailbox.Organization);

                CommonCAS.Stats("Mail/CreateMailbox");

                return(View("CreateMailboxSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #19
0
        public ActionResult Create(FormCollection _POST)
        {
            try
            {
                // set up a user account for display in view
                CustomUser newUser = new CustomUser()
                {
                    CopyFrom             = _POST["userprincipalname"],
                    FirstName            = _POST["firstname"],
                    LastName             = _POST["lastname"],
                    Organization         = _POST["organization"],
                    Password             = _POST["password"],
                    UserName             = _POST["username"],
                    DomainName           = _POST["domainname"],
                    TestUser             = _POST["testuser"] == "on" ? true : false,
                    PasswordNeverExpires = _POST["passwordneverexpires"] == "on" ? true : false,
                };

                model.UserList.Add(newUser);

                CommonCAS.Log(string.Format("has run User/CreateUser() to create {0}", newUser.UserName));

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

                    if (result.Count() > 0)
                    {
                        foreach (PSObject message in result)
                        {
                            model.OKMessage.Add(message.ToString());
                        }
                    }
                }

                CommonCAS.Stats("User/Create");

                return(View("CreateSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
        public ActionResult RemoveDomain(FormCollection _POST)
        {
            try
            {
                CustomDomain RemoveDomain = new CustomDomain()
                {
                    Organization  = _POST["organization"],
                    Domain        = _POST["domainname"],
                    RemoveasEmail = _POST["removeasemail"] == "on" ? true : false
                };

                model.Domain = RemoveDomain;

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

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

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

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

                CommonCAS.Stats("Organization/RemoveDomain");

                return(View("RemoveDomain", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }
예제 #21
0
        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));
            }
        }
예제 #23
0
        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));
            }
        }
예제 #25
0
        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));
            }
        }
예제 #26
0
        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));
            }
        }
예제 #27
0
        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));
            }
        }
예제 #29
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));
            }
        }