public string GetSendAsGroups(string organization) { try { List <AjaxSendAsGroups> groups = new List <AjaxSendAsGroups>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetSendAsGroups(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject Group in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(Group); groups.Add(new AjaxSendAsGroups() { Name = properties["Name"].ToString(), DistinguishedName = properties["DistinguishedName"].ToString(), Description = properties["Description"].ToString(), }); } } return(new JavaScriptSerializer().Serialize(groups)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetADUsersProxy(string organization, string userprincipalname) { try { List <AjaxADUser> users = new List <AjaxADUser>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetADUsers(organization, userprincipalname); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject User in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(User); users.Add(new AjaxADUser() { proxyAddresses = properties["proxyAddresses"].ToString().Split(','), }); } } return(new JavaScriptSerializer().Serialize(users)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetO365Domain(string organization) { try { string initials = organization.Split(' ')[0]; List <AjaxDomain> domains = new List <AjaxDomain>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetO365Domain(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject domain in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(domain); domains.Add(new AjaxDomain() { DomainName = properties["DomainName"].ToString(), Status = properties["Status"].ToString(), IsDefault = properties["IsDefault"].ToString(), }); } } return(new JavaScriptSerializer().Serialize(domains)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetMailContacts(string organization) { try { List <AjaxMailContact> mailContacts = new List <AjaxMailContact>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetMailContacts(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject contact in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(contact); mailContacts.Add(new AjaxMailContact() { Name = properties["DisplayName"].ToString(), PrimarySmtpAddress = properties["PrimarySmtpAddress"].ToString() }); } } return(new JavaScriptSerializer().Serialize(mailContacts)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetCALMailbox(string organization, string name) { try { List <AjaxMailbox> calmailboxes = new List <AjaxMailbox>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetMailbox(organization, name); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject mailbox in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(mailbox); calmailboxes.Add(new AjaxMailbox() { Name = properties["Name"].ToString(), UserPrincipalName = properties["UserPrincipalName"].ToString(), RecipientTypeDetails = properties["RecipientTypeDetails"].ToString(), EmailAddresses = properties["EmailAddresses"].ToString().Split(' ') }); } } return(new JavaScriptSerializer().Serialize(calmailboxes)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetCalendarPermissions(string organization, string userprincipalname) { try { List <AjaxMailboxFolderPermission> folderPermissions = new List <AjaxMailboxFolderPermission>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetCalendarPermissions(organization, userprincipalname); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject folderPermission in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(folderPermission); folderPermissions.Add(new AjaxMailboxFolderPermission() { User = properties["User"].ToString(), AccessRights = properties["AccessRights"].ToString() }); } } return(new JavaScriptSerializer().Serialize(folderPermissions)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string CPOGetDistributionGroups(string organization) { try { List <AjaxDistributionGroup> distributionGroups = new List <AjaxDistributionGroup>(); using (CPOMyPowerShell ps = new CPOMyPowerShell()) { ps.GetDistributionGroups(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject group in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(group); distributionGroups.Add(new AjaxDistributionGroup() { Name = properties["DisplayName"].ToString(), PrimarySmtpAddress = properties["PrimarySmtpAddress"].ToString() }); } } return(new JavaScriptSerializer().Serialize(distributionGroups)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
public string GetVMVHDs(string vmid) { try { List <AjaxVMVHDs> vhds = new List <AjaxVMVHDs>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetVMVHDs(vmid); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject VHD in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(VHD); vhds.Add(new AjaxVMVHDs() { Name = properties["Name"].ToString(), VHDID = properties["VHDID"].ToString(), Size = properties["Size"].ToString(), }); } } return(new JavaScriptSerializer().Serialize(vhds)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
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 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 string GetCrayonInvoiceProfiles() { try { List <CustomCrayonInvoiceProfile> CrayonInvoiceProfiles = new List <CustomCrayonInvoiceProfile>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetCrayonInvoiceProfiles(); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject profiles in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(profiles); CrayonInvoiceProfiles.Add(new CustomCrayonInvoiceProfile() { Name = properties["Name"].ToString(), Id = properties["Id"].ToString() }); } } return(new JavaScriptSerializer().Serialize(CrayonInvoiceProfiles)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
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)); } }
public string CPOGetAcceptedDomain(string organization) { try { List <CPOAjaxAcceptedDomain> domains = new List <CPOAjaxAcceptedDomain>(); using (CPOMyPowerShell ps = new CPOMyPowerShell()) { ps.GetAcceptedDomain(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject domain in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(domain); domains.Add(new CPOAjaxAcceptedDomain() { Name = properties["Name"].ToString(), DomainName = properties["DomainName"].ToString(), }); } } return(new JavaScriptSerializer().Serialize(domains)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
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 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 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 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)); } }
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 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 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)); } }
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 string CPOGetCTXGoldenServers(string solution, bool mcsenabled) { try { List <AjaxCTXGoldenServers> servers = new List <AjaxCTXGoldenServers>(); using (CPOMyPowerShell ps = new CPOMyPowerShell()) { ps.GetCTXGoldenServers(solution, mcsenabled); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject Server in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(Server); servers.Add(new AjaxCTXGoldenServers() { Name = properties["Name"].ToString(), }); } } return(new JavaScriptSerializer().Serialize(servers)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
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 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)); } }
public ActionResult AzureLog() { model.AzureLog = CommonCAS.GetAzureLog(); if (model.AzureLog.Count == 0) { model.AzureLog.Add("AzureLog is empty..."); } return(View(model)); }
public ActionResult CPOLog() { model.CPOLog = CommonCAS.GetCPOLog(); if (model.CPOLog.Count == 0) { model.CPOLog.Add("Capto Log is empty..."); } return(View(model)); }
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)); } }
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)); } }
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)); } }