public static void Clean(SIPAccount sipAccount) { sipAccount.Owner = sipAccount.Owner.Trim(); sipAccount.SIPUsername = sipAccount.SIPUsername.Trim(); sipAccount.SIPPassword = (sipAccount.SIPPassword == null) ? null : sipAccount.SIPPassword.Trim(); sipAccount.SIPDomain = sipAccount.SIPDomain.Trim(); }
public static string Validate(SIPAccount sipAccount) { TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(SIPAccount), typeof(SIPAccountMetadata)), typeof(SIPAccount)); var validationContext = new ValidationContext(sipAccount, null, null); var validationResults = new List<ValidationResult>(); Validator.TryValidateObject(sipAccount, validationContext, validationResults); if (validationResults.Count > 0) { return validationResults.First().ErrorMessage; } else { Guid testGuid = Guid.Empty; if(!Guid.TryParse(sipAccount.ID, out testGuid)) { return "The ID was not a valid GUID."; } else if (String.Compare(sipAccount.SIPUsername, BANNED_SIPACCOUNT_NAME, true) == 0) { return "The username you have requested is not permitted."; } else if (sipAccount.SIPUsername.Contains(".") && (sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim().Length >= SIPAccount.USERNAME_MIN_LENGTH && sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim() != sipAccount.Owner)) { return "You are not permitted to create this username. Only user " + sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim() + " can create SIP accounts ending in " + sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".")).Trim() + "."; } } return null; }
public static string Validate(SIPAccount sipAccount) { TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(SIPAccount), typeof(SIPAccountMetadata)), typeof(SIPAccount)); var validationContext = new ValidationContext(sipAccount, null, null); var validationResults = new List <ValidationResult>(); Validator.TryValidateObject(sipAccount, validationContext, validationResults); if (validationResults.Count > 0) { return(validationResults.First().ErrorMessage); } else { Guid testGuid = Guid.Empty; if (!Guid.TryParse(sipAccount.ID, out testGuid)) { return("The ID was not a valid GUID."); } else if (String.Compare(sipAccount.SIPUsername, BANNED_SIPACCOUNT_NAME, true) == 0) { return("The username you have requested is not permitted."); } else if (sipAccount.SIPUsername.Contains(".") && (sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim().Length >= SIPAccount.USERNAME_MIN_LENGTH && sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim() != sipAccount.Owner)) { return("You are not permitted to create this username. Only user " + sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".") + 1).Trim() + " can create SIP accounts ending in " + sipAccount.SIPUsername.Substring(sipAccount.SIPUsername.LastIndexOf(".")).Trim() + "."); } } return(null); }
public SIPAccount ToSIPAccount() { var entitySIPAccount = new SIPAccount() { Owner = String.Empty, AvatarURL = AvatarURL, DontMangleEnabled = DontMangleEnabled, ID = ID, InDialPlanName = InDialPlanName, IPAddressACL = IPAddressACL, IsIncomingOnly = IsIncomingOnly, IsSwitchboardEnabled = IsSwitchboardEnabled, IsUserDisabled = IsUserDisabled, NetworkID = NetworkID, OutDialPlanName = OutDialPlanName, SendNATKeepAlives = SendNATKeepAlives, SIPPassword = SIPPassword, SIPUsername = SIPUsername, AccountCode = AccountCode, Description = Description }; if (!SIPDomain.IsNullOrBlank()) { entitySIPAccount.SIPDomain = SIPDomain; } return(entitySIPAccount); }
public SIPAccountDetailsControl( DetailsControlModesEnum mode, SIPAccount sipAccount, string owner, SIPAccountUpdateDelegate add, SIPAccountUpdateDelegate update, ControlClosedDelegate closed, SIPEntitiesDomainContext riaContext //GetDialPlanNamesDelegate getDialPlanNames, //GetSIPDomainsDelegate getSIPDomains ) { InitializeComponent(); m_detailsMode = mode; m_owner = owner; m_sipAccount = sipAccount; AddSIPAccount_External = add; UpdateSIPAccount_External = update; Closed_External = closed; m_riaContext = riaContext; //GetDialPlanNames_External = getDialPlanNames; //GetSIPDomains_External = getSIPDomains; if (m_detailsMode == DetailsControlModesEnum.Edit) { PopulateDataFields(m_sipAccount); } else { m_sipAccountUpdateButton.Content = "Add"; m_sipAccountIdCanvas.Visibility = Visibility.Collapsed; m_statusDisabledRadio.Visibility = Visibility.Collapsed; m_statusAdminDisabledRadio.Visibility = Visibility.Collapsed; UIHelper.SetText(m_sipAccountOwner, m_owner); SetDomainNames(null); SetDialPlanNames(null); } }
private void DetailsControlClosed() { m_selectedSIPAccount = null; m_sipAccountsPanel.CloseDetailsPane(); }
public SIPAccount ToSIPAccount() { var entitySIPAccount = new SIPAccount() { Owner = String.Empty, AvatarURL = AvatarURL, DontMangleEnabled = DontMangleEnabled, ID = ID, InDialPlanName = InDialPlanName, IPAddressACL = IPAddressACL, IsIncomingOnly = IsIncomingOnly, IsSwitchboardEnabled = IsSwitchboardEnabled, IsUserDisabled = IsUserDisabled, NetworkID = NetworkID, OutDialPlanName = OutDialPlanName, SendNATKeepAlives = SendNATKeepAlives, SIPPassword = SIPPassword, SIPUsername = SIPUsername }; if (!SIPDomain.IsNullOrBlank()) { entitySIPAccount.SIPDomain = SIPDomain; } return entitySIPAccount; }
private void SIPAccountUpdate(SIPAccount sipAccount) { //LogActivityMessage_External(MessageLevelsEnum.Info, "Attempting to update " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + "."); m_riaContext.SubmitChanges(UpdateSIPAccountComplete, sipAccount); }
private void SIPAccountsDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { try { if (m_riaContext.SIPAccounts.Count() > 0) { DataGrid dataGrid = (DataGrid)sender; if (dataGrid.SelectedItem != null && dataGrid.CurrentColumn.Header as string != "Delete") { SIPAccount sipAccount = (SIPAccount)m_sipAccountsDataGrid.SelectedItem; if (m_selectedSIPAccount == null || m_selectedSIPAccount != sipAccount) { m_selectedSIPAccount = sipAccount; m_editControl = new SIPAccountDetailsControl(DetailsControlModesEnum.Edit, sipAccount, m_owner, null, SIPAccountUpdate, DetailsControlClosed, m_riaContext); m_sipAccountsPanel.SetDetailsElement(m_editControl); } } } } catch (Exception excp) { LogActivityMessage_External(MessageLevelsEnum.Error, "Exception showing SIP account details. " + excp.Message); m_selectedSIPAccount = null; } }
private void SIPAccountsAssetViewer_Add() { if (m_riaContext.SIPDomains.Count() == 0) { LogActivityMessage_External(MessageLevelsEnum.Error, "A SIP account cannot be added as there are no available SIP domains loaded."); } else { m_selectedSIPAccount = null; m_addControl = new SIPAccountDetailsControl(DetailsControlModesEnum.Add, null, m_owner, SIPAccountAdd, null, DetailsControlClosed, m_riaContext); m_sipAccountsPanel.SetDetailsElement(m_addControl); } }
private void SIPAccountAdd(SIPAccount sipAccount) { m_riaContext.SIPAccounts.Add(sipAccount); m_riaContext.SubmitChanges(SIPAccountAddComplete, sipAccount); }
public void UpdateSIPAccount(string authUser, SIPAccount sipAccount) { if (authUser.IsNullOrBlank()) { throw new ArgumentException("An authenticated user is required for UpdateSIPAccount."); } using (var sipSorceryEntities = new SIPSorceryEntities()) { SIPAccount existingAccount = (from sa in sipSorceryEntities.SIPAccounts where sa.ID == sipAccount.ID && sa.Owner == authUser.ToLower() select sa).FirstOrDefault(); if (existingAccount == null) { throw new ApplicationException("The SIP account to update could not be found."); } else if (existingAccount.Owner != authUser.ToLower()) { logger.Warn("User " + authUser + " was not authorised to update SIP account " + existingAccount.SIPUsername + " belonging to " + existingAccount.Owner + "."); throw new ApplicationException("Not authorised to update the SIP Account."); } // Check for a duplicate in case the SIP username has been changed. if (sipSorceryEntities.SIPAccounts.Where(x => x.SIPUsername.ToLower() == sipAccount.SIPUsername.ToLower() && x.SIPDomain.ToLower() == sipAccount.SIPDomain.ToLower() && x.ID != existingAccount.ID).Count() > 0) { throw new ApplicationException("Sorry the requested username and domain combination is already in use."); } existingAccount.SIPUsername = sipAccount.SIPUsername; existingAccount.SIPDomain = sipAccount.SIPDomain; existingAccount.DontMangleEnabled = sipAccount.DontMangleEnabled; existingAccount.InDialPlanName = sipAccount.InDialPlanName; existingAccount.IPAddressACL = sipAccount.IPAddressACL; existingAccount.IsIncomingOnly = sipAccount.IsIncomingOnly; existingAccount.IsSwitchboardEnabled = sipAccount.IsSwitchboardEnabled; existingAccount.IsUserDisabled = sipAccount.IsUserDisabled; existingAccount.NetworkID = sipAccount.NetworkID; existingAccount.OutDialPlanName = sipAccount.OutDialPlanName; existingAccount.SendNATKeepAlives = sipAccount.SendNATKeepAlives; existingAccount.SIPPassword = sipAccount.SIPPassword; existingAccount.AccountCode = sipAccount.AccountCode; existingAccount.Description = sipAccount.Description; string validationError = SIPAccount.Validate(existingAccount); if (validationError != null) { throw new ApplicationException(validationError); } sipSorceryEntities.SaveChanges(); } }
/// <summary> /// Create a new SIPAccount object. /// </summary> /// <param name="dontMangleEnabled">Initial value of the DontMangleEnabled property.</param> /// <param name="id">Initial value of the ID property.</param> /// <param name="inserted">Initial value of the Inserted property.</param> /// <param name="isAdminDisabled">Initial value of the IsAdminDisabled property.</param> /// <param name="isIncomingOnly">Initial value of the IsIncomingOnly property.</param> /// <param name="isSwitchboardEnabled">Initial value of the IsSwitchboardEnabled property.</param> /// <param name="isUserDisabled">Initial value of the IsUserDisabled property.</param> /// <param name="owner">Initial value of the Owner property.</param> /// <param name="sendNATKeepAlives">Initial value of the SendNATKeepAlives property.</param> /// <param name="sIPDomain">Initial value of the SIPDomain property.</param> /// <param name="sIPPassword">Initial value of the SIPPassword property.</param> /// <param name="sIPUsername">Initial value of the SIPUsername property.</param> public static SIPAccount CreateSIPAccount(global::System.Boolean dontMangleEnabled, global::System.String id, global::System.String inserted, global::System.Boolean isAdminDisabled, global::System.Boolean isIncomingOnly, global::System.Boolean isSwitchboardEnabled, global::System.Boolean isUserDisabled, global::System.String owner, global::System.Boolean sendNATKeepAlives, global::System.String sIPDomain, global::System.String sIPPassword, global::System.String sIPUsername) { SIPAccount sIPAccount = new SIPAccount(); sIPAccount.DontMangleEnabled = dontMangleEnabled; sIPAccount.ID = id; sIPAccount.Inserted = inserted; sIPAccount.IsAdminDisabled = isAdminDisabled; sIPAccount.IsIncomingOnly = isIncomingOnly; sIPAccount.IsSwitchboardEnabled = isSwitchboardEnabled; sIPAccount.IsUserDisabled = isUserDisabled; sIPAccount.Owner = owner; sIPAccount.SendNATKeepAlives = sendNATKeepAlives; sIPAccount.SIPDomain = sIPDomain; sIPAccount.SIPPassword = sIPPassword; sIPAccount.SIPUsername = sIPUsername; return sIPAccount; }
private void PopulateDataFields(SIPAccount sipAccount) { m_outDialPlan.Visibility = Visibility.Collapsed; m_inDialPlan.Visibility = Visibility.Collapsed; m_domainNames.Visibility = Visibility.Collapsed; m_sipAccountUsername.Visibility = Visibility.Collapsed; if (sipAccount.IsAdminDisabled) { WriteStatusMessage(MessageLevelsEnum.Warn, "SIP Account has been disabled by administrator. " + sipAccount.AdminDisabledReason); m_sipAccountPassword.IsEnabled = false; m_keepAlivesCheckBox.IsEnabled = false; m_statusAdminDisabledRadio.IsEnabled = true; m_statusAdminDisabledRadio.IsChecked = true; m_statusAdminDisabledRadio.IsEnabled = false; m_statusStandardRadio.IsEnabled = false; m_statusIncomingOnlyRadio.IsEnabled = false; m_statusDisabledRadio.IsEnabled = false; m_outDialPlan.IsEnabled = false; m_inDialPlan.IsEnabled = false; m_sipAccountUpdateButton.IsEnabled = false; m_sipAccountOutDialPlanStatus.Text = (m_sipAccount.OutDialPlanName != null) ? m_sipAccount.OutDialPlanName : "-"; m_sipAccountInDialPlanStatus.Text = (m_sipAccount.InDialPlanName != null) ? m_sipAccount.InDialPlanName : "-"; m_sipAccountNetworkId.IsEnabled = false; m_sipAccountIPAddressACL.IsEnabled = false; m_isSwitchboardEnabledCheckBox.IsEnabled = false; } else { if (sipAccount.Owner == m_owner) { //ThreadPool.QueueUserWorkItem(new WaitCallback(SetDialPlanNames), null); SetDialPlanNames(null); } else { // Don't have a list of dial plan names for non-owned SIP accounts so just display the dial plan names. m_sipAccountOutDialPlanStatus.Text = (m_sipAccount.OutDialPlanName != null) ? m_sipAccount.OutDialPlanName : "-"; m_sipAccountInDialPlanStatus.Text = (m_sipAccount.InDialPlanName != null) ? m_sipAccount.InDialPlanName : "-"; } if (sipAccount.IsDisabled) { m_statusDisabledRadio.IsChecked = true; } else if (sipAccount.IsIncomingOnly) { m_statusIncomingOnlyRadio.IsChecked = true; } } m_sipAccountId.Text = sipAccount.ID; m_sipAccountOwner.Text = sipAccount.Owner; m_sipAccountUsernameText.Text = sipAccount.SIPUsername; m_sipAccountPassword.Text = sipAccount.SIPPassword; m_sipAccountDomain.Text = sipAccount.SIPDomain; m_keepAlivesCheckBox.IsChecked = sipAccount.SendNATKeepAlives; m_sipAccountNetworkId.Text = (sipAccount.NetworkID != null) ? sipAccount.NetworkID : String.Empty; m_sipAccountIPAddressACL.Text = (sipAccount.IPAddressACL != null) ? sipAccount.IPAddressACL : String.Empty; m_isSwitchboardEnabledCheckBox.IsChecked = sipAccount.IsSwitchboardEnabled; }
private void Add() { try { string username = m_sipAccountUsername.Text.Trim(); string password = m_sipAccountPassword.Text.Trim(); string domain = m_domainNames.SelectedItem as string; string outDialPlan = m_outDialPlan.SelectedItem as string; string inDialPlan = (m_inDialPlan.SelectedIndex != -1) ? m_inDialPlan.SelectedItem as string : null; string networkId = m_sipAccountNetworkId.Text.Trim(); string ipAddressACL = m_sipAccountIPAddressACL.Text.Trim(); bool sendKeepAlives = m_keepAlivesCheckBox.IsChecked.Value; bool isIncomingOnly = m_statusIncomingOnlyRadio.IsChecked.Value; bool isSwitchboardEnabled = m_isSwitchboardEnabledCheckBox.IsChecked.Value; SIPAccount sipAccount = new SIPAccount(); sipAccount.ID = Guid.Empty.ToString(); // Will be set server side. sipAccount.Owner = m_owner; // Will be set server side. sipAccount.SIPDomain = domain; sipAccount.SIPUsername = username; sipAccount.SIPPassword = password; sipAccount.OutDialPlanName = outDialPlan; sipAccount.InDialPlanName = inDialPlan; sipAccount.SendNATKeepAlives = sendKeepAlives; sipAccount.IsIncomingOnly = isIncomingOnly; sipAccount.NetworkID = networkId; sipAccount.IPAddressACL = ipAddressACL; sipAccount.IsSwitchboardEnabled = isSwitchboardEnabled; sipAccount.Inserted = DateTime.UtcNow.ToString("o"); // Will be set server side. if (sipAccount.HasValidationErrors) { WriteStatusMessage(MessageLevelsEnum.Warn, sipAccount.ValidationErrors.First().ErrorMessage); } else { SIPAccount.Clean(sipAccount); WriteStatusMessage(MessageLevelsEnum.Info, "Adding SIP Account please wait..."); AddSIPAccount_External(sipAccount); } } catch (Exception excp) { WriteStatusMessage(MessageLevelsEnum.Error, "Add SIPAccount Exception. " + excp.Message); } }
public void DeleteSIPAccount(string authUser, SIPAccount sipAccount) { using (var sipSorceryEntities = new SIPSorceryEntities()) { SIPAccount existingAccount = (from sa in sipSorceryEntities.SIPAccounts where sa.ID == sipAccount.ID && sa.Owner.ToLower() == authUser.ToLower() select sa).FirstOrDefault(); if (existingAccount == null) { throw new ApplicationException("The SIP account to delete could not be found."); } else if (existingAccount.Owner.ToLower() != authUser.ToLower()) { throw new ApplicationException("Not authorised to delete the SIP Account."); } sipSorceryEntities.SIPAccounts.DeleteObject(existingAccount); sipSorceryEntities.SaveChanges(); } }
/// <summary> /// Deprecated Method for adding a new object to the SIPAccounts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSIPAccounts(SIPAccount sIPAccount) { base.AddObject("SIPAccounts", sIPAccount); }
public string InsertSIPAccount(string authUser, SIPAccount sipAccount) { if (authUser.IsNullOrBlank()) { throw new ArgumentException("An authenticated user is required for InsertSIPAccount."); } sipAccount.ID = Guid.NewGuid().ToString(); sipAccount.Owner = authUser.ToLower(); sipAccount.Inserted = DateTimeOffset.UtcNow.ToString("o"); sipAccount.IsAdminDisabled = false; sipAccount.AdminDisabledReason = null; using (var sipSorceryEntities = new SIPSorceryEntities()) { if (sipAccount.SIPDomain.IsNullOrBlank()) { // Get default domain name. string defaultDomain = sipSorceryEntities.SIPDomains.Where(x => x.AliasList.Contains("local")).Select(y => y.Domain).First(); sipAccount.SIPDomain = defaultDomain; } string validationError = SIPAccount.Validate(sipAccount); if (validationError != null) { throw new ApplicationException(validationError); } // Check for a duplicate. if (sipSorceryEntities.SIPAccounts.Where(x => x.SIPUsername.ToLower() == sipAccount.SIPUsername.ToLower() && x.SIPDomain.ToLower() == sipAccount.SIPDomain.ToLower()).Count() > 0) { throw new ApplicationException("Sorry the requested username and domain combination is already in use."); } sipSorceryEntities.SIPAccounts.AddObject(sipAccount); sipSorceryEntities.SaveChanges(); return sipAccount.ID; } }