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 string GetMailboxes(string organization, string selectname = "upnselector", string inputname = "userprincipalname") { string returnstr = "<select name=\"" + selectname + "\"><option selected=\"selected\" value=\"\">... select a person</option>"; using (MyPowerShell ps = new MyPowerShell()) { ps.GetMailboxes(organization); var result = ps.Invoke(); foreach (var item in result) { string upn = item.ToString().Split(';')[0]; string name = item.ToString().Split(';')[1]; string disabled = item.ToString().Split(';')[2]; string hidden = item.ToString().Split(';')[3]; returnstr += string.Format("<option value=\"{0}\">{1}{2}{3}</option>", upn, //0 name, //1 disabled == "True" ? "(disabled)" : "", //2 hidden == "True" ? "(hidden)" : "" //3 ); } } returnstr += "</select>"; returnstr += "<script>$(\"select[name=" + selectname + "]\").change(function () { var upn = $(\"select[name=" + selectname + "]\").val(); $(\"input[name=" + inputname + "]\").val(upn); GetExistingAliases(); }); </script>"; return(returnstr); }
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 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 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 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 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 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 string GetCurrentOOF(string organization, string userprincipalname) { try { using (MyPowerShell ps = new MyPowerShell()) { ps.GetOOFMessage(organization, userprincipalname); PSObject result = ps.Invoke().Single(); return(new JavaScriptSerializer().Serialize(new AjaxGetCurrentOOF() { StartTime = result.Members["StartTime"].Value.ToString(), EndTime = result.Members["EndTime"].Value.ToString(), AutoReplyState = result.Members["AutoReplyState"].Value.ToString(), InternalMessage = result.Members["InternalMessage"].Value.ToString(), ExternalMessage = result.Members["ExternalMessage"].Value.ToString(), ExternalAudience = result.Members["ExternalAudience"].Value.ToString() })); } } catch (Exception exc) { return(new JsonException(exc).ToString()); } }
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 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 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 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 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 string GetScheduledJobs(string job) { string returnstr = "<table>"; using (MyPowerShell ps = new MyPowerShell()) { ps.GetScheduledJobs(job); var result = ps.Invoke(); if (result.Count() == 0) { returnstr += "<tr><td><b>No current schedules!..</b></td></tr>"; } else { // Returns string with properties.. foreach (var item in result) { { returnstr += "<center><table class='SQLlight'><tr><td style='width: 150px; text-align: left;'><b>VM Name</b></td><td style='text-align: left;'>" + item.Members["VMName"].Value.ToString() + "</td>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Parameters</b></td><td style='text-align: left'>" + item.Members["Parameters"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Opgave nr.</b></td><td style='text-align: left'>" + item.Members["TaskID"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Email Status To</b></td><td style='text-align: left; color: #e60000; font-weight:bold'>" + item.Members["EmailStatusTo"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Scheduled Time</b></td><td style='text-align: left'>" + item.Members["ScheduledTime"].Value.ToString() + "</td></tr></table></center></br>"; } } } } returnstr += "</table>"; return(returnstr); }
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 string GetLatestAlerts(string alert) { string returnstr = "<table>"; using (MyPowerShell ps = new MyPowerShell()) { ps.GetLatestAlerts(alert); var result = ps.Invoke(); if (result.Count() == 0) { returnstr += "<tr><td><b>No alerts! Be happy..</b></td></tr>"; } else { // Returns string with properties.. foreach (var item in result) { var severity = item.Members["Severity"].Value.ToString(); var name = item.Members["Name"].Value.ToString(); if (name == "Pending Reboot") { returnstr += "<center><table class='SQLlight'><tr><td style='display: block; width: 450px; text-align: left;'>" + item.Members["PrincipalName"].Value.ToString() + "</td>"; returnstr += "<td style='width: 200px; text-align: left;'>" + item.Members["Name"].Value.ToString() + "</td>"; returnstr += "<td style='width: 250px; text-align: left;'>" + item.Members["TimeRaised"].Value.ToString() + "</td></tr><br/></table>"; } else { if (severity == "Error") { returnstr += "<center><table class='SQLlight'><tr><td style='width: 150px; text-align: left;'><b>ServerName</b></td><td style='width: 150px; text-align: left;'>" + item.Members["PrincipalName"].Value.ToString() + "</td>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Name</b></td><td style='width: 260px; text-align: left;'>" + item.Members["Name"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Severity</b></td><td style='width: 100px; text-align: left; color: #e60000; font-weight:bold;'>" + item.Members["Severity"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>TimeRaised</b></td><td style='width: 180px; text-align: left;'>" + item.Members["TimeRaised"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Description</b></td><td style='display:block; width: 850px; word-break: break-all; text-align: left;'>" + item.Members["Description"].Value.ToString() + "</td></tr></tr></table></center></br>"; } if (severity == "Warning") { returnstr += "<center><table class='SQLlight'><tr><td style='width: 150px; text-align: left;'><b>ServerName</b></td><td style='width: 150px; text-align: left;'>" + item.Members["PrincipalName"].Value.ToString() + "</td>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Name</b></td><td style='width: 260px; text-align: left;'>" + item.Members["Name"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Severity</b></td><td style='width: 100px; text-align: left; color: #cccc00; font-weight:bold;'>" + item.Members["Severity"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>TimeRaised</b></td><td style='width: 180px; text-align: left;'>" + item.Members["TimeRaised"].Value.ToString() + "</td></tr>"; returnstr += "<tr><td style='width: 150px; text-align: left;'><b>Description</b></td><td style='display:block; width: 850px; word-break: break-all; text-align: left;'>" + item.Members["Description"].Value.ToString() + "</td></tr></tr></table></center></br>"; } } } } } returnstr += "</table>"; return(returnstr); }
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)); } }
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)); } }
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)); } }
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 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)); } }
// Ajax function - returns currently active mailbox plan set on a mailbox public string GetMailboxPlan(string organization, string userprincipalname) { string ret = ""; using (MyPowerShell ps = new MyPowerShell()) { ps.GetMailboxPlan(organization, userprincipalname); var result = ps.Invoke(); foreach (var item in result) { ret += item.ToString(); } } return(ret); }
public static string GetDefaultAcceptedDomain(string organization) { using (MyPowerShell ps = new MyPowerShell()) { ps.GetDefaultAcceptedDomain(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject item in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(item); return(properties["DomainName"].ToString()); } throw new Exception("Unable to find default accepted domain"); } }
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)); } }