public void UpdateCustomer(Customer updatedCustomer) { Customer customer = AuthoriseRequest(); if (customer.CustomerUsername == updatedCustomer.CustomerUsername) { logger.Debug("Updating customer details for " + customer.CustomerUsername); customer.FirstName = updatedCustomer.FirstName; customer.LastName = updatedCustomer.LastName; customer.EmailAddress = updatedCustomer.EmailAddress; customer.SecurityQuestion = updatedCustomer.SecurityQuestion; customer.SecurityAnswer = updatedCustomer.SecurityAnswer; customer.City = updatedCustomer.City; customer.Country = updatedCustomer.Country; customer.WebSite = updatedCustomer.WebSite; customer.TimeZone = updatedCustomer.TimeZone; string validationError = Customer.ValidateAndClean(customer); if (validationError != null) { throw new ApplicationException(validationError); } CRMCustomerPersistor.Update(customer); } else { throw new ApplicationException("You are not authorised to update customer for username " + updatedCustomer.CustomerUsername + "."); } }
public CustomerSession Authenticate(string sessionId) { try { CustomerSession customerSession = m_customerSessionPersistor.Get(s => s.SessionID == sessionId && !s.Expired); //CustomerSession customerSession = m_customerSessionPersistor.Get(s => s.Id == sessionId); if (customerSession != null) { int sessionLengthMinutes = (int)DateTimeOffset.UtcNow.Subtract(customerSession.Inserted).TotalMinutes; //logger.Debug("CustomerSession Inserted=" + customerSession.Inserted.ToString("o") + ", session length=" + sessionLengthMinutes + "mins."); if (sessionLengthMinutes > customerSession.TimeLimitMinutes || sessionLengthMinutes > CustomerSession.MAX_SESSION_LIFETIME_MINUTES) { customerSession.Expired = true; m_customerSessionPersistor.Update(customerSession); return(null); } else { //logger.Debug("Authentication token valid for " + sessionId + "."); return(customerSession); } } else { logger.Warn("Authentication token invalid for " + sessionId + "."); return(null); } } catch (Exception excp) { logger.Error("Exception Authenticate CustomerSessionManager. " + excp.Message); throw; } }
protected void Page_Load(object sender, EventArgs e) { try { logger.Debug("CustomerEmailConfirmation request from " + this.Context.Request.UserHostAddress + " for " + this.Request.QueryString["id"] + "."); string id = this.Request.QueryString["id"]; if (!id.IsNullOrBlank()) { Guid customerId = new Guid(id); m_crmPersistor = SIPAssetPersistorFactory <Customer> .CreateSIPAssetPersistor(m_crmStorageType, m_crmStorageConnStr, null); Customer customer = m_crmPersistor.Get(customerId); if (customer != null) { if (!customer.EmailAddressConfirmed) { customer.CreatedFromIPAddress = this.Context.Request.UserHostAddress; customer.EmailAddressConfirmed = true; if (IsValidCustomer(m_validationRules, customer)) { m_crmPersistor.Update(customer); m_confirmed = true; m_confirmMessage.Text = "Thank you, your account has now been activated."; } else { customer.Suspended = true; m_crmPersistor.Update(customer); m_confirmed = false; m_confirmMessage.Text = "Your account has been confirmed but not approved. You will receive an email within 48 hours if it is approved."; } } else { m_confirmed = false; m_confirmMessage.Text = "Your account has already been confirmed."; } } else { m_confirmMessage.Text = "No matching customer record could be found. Please check that you entered the confirmation URL correctly."; } } else { m_confirmMessage.Text = "Your account could not be confirmed. Please check that you entered the confirmation URL correctly."; } } catch (Exception excp) { logger.Error("Exception CustomerEmailConfirmation. " + excp.Message); m_confirmMessage.Text = "There was an error confirming your account. Please check that you entered the confirmation URL correctly."; } }
public SIPProvider UpdateSIPProvider(SIPProvider sipProvider) { Customer customer = AuthoriseRequest(); if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername) { throw new ApplicationException("You are not authorised to update the SIP Provider."); } string validationError = SIPProvider.ValidateAndClean(sipProvider); if (validationError != null) { logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError); throw new ApplicationException(validationError); } else { if (m_providerRegDisabled && sipProvider.RegisterEnabled) { logger.Warn("A SIP provider for customer " + customer.CustomerUsername + " had registrations enabled on a disabled registrations service."); throw new ApplicationException("SIP provider registrations are disabled on this system."); } else { return(SIPProviderPersistor.Update(sipProvider)); } } }
public void SIPProviderUpdated(SIPProvider sipProvider) { try { Logger.Logger.Debug("SIPProviderBindingSynchroniser SIPProviderUpdated for " + sipProvider.Owner + " and " + sipProvider.ProviderName + "."); SIPProviderBinding existingBinding = m_bindingPersistor.Get(b => b.ProviderId == sipProvider.Id); if (sipProvider.RegisterEnabled) { if (existingBinding == null) { SIPProviderBinding newBinding = new SIPProviderBinding(sipProvider); m_bindingPersistor.Add(newBinding); } else { existingBinding.SetProviderFields(sipProvider); existingBinding.NextRegistrationTime = DateTime.UtcNow; m_bindingPersistor.Update(existingBinding); } } else { if (existingBinding != null) { if (existingBinding.IsRegistered) { // Let the registration agent know the existing binding should be expired. existingBinding.BindingExpiry = 0; existingBinding.NextRegistrationTime = DateTime.UtcNow; m_bindingPersistor.Update(existingBinding); } else { m_bindingPersistor.Delete(existingBinding); } } } } catch (Exception excp) { Logger.Logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderUpdated. ->" + excp.Message); } }
protected void Page_Load(object sender, EventArgs e) { try { logger.Debug("CustomerEmailConfirmation request from " + this.Context.Request.UserHostAddress + " for " + this.Request.QueryString["id"] + "."); string id = this.Request.QueryString["id"]; if (!id.IsNullOrBlank()) { Guid customerId = new Guid(id); m_crmPersistor = SIPAssetPersistorFactory<Customer>.CreateSIPAssetPersistor(m_crmStorageType, m_crmStorageConnStr, null); Customer customer = m_crmPersistor.Get(customerId); if (customer != null) { if (!customer.EmailAddressConfirmed) { customer.CreatedFromIPAddress = this.Context.Request.UserHostAddress; customer.EmailAddressConfirmed = true; if (IsValidCustomer(m_validationRules, customer)) { m_crmPersistor.Update(customer); m_confirmed = true; m_confirmMessage.Text = "Thank you, your account has now been activated."; } else { customer.Suspended = true; m_crmPersistor.Update(customer); m_confirmed = false; m_confirmMessage.Text = "Your account has been confirmed but not approved. You will receive an email within 48 hours if it is approved."; } } else { m_confirmed = false; m_confirmMessage.Text = "Your account has already been confirmed."; } } else { m_confirmMessage.Text = "No matching customer record could be found. Please check that you entered the confirmation URL correctly."; } } else { m_confirmMessage.Text = "Your account could not be confirmed. Please check that you entered the confirmation URL correctly."; } } catch (Exception excp) { logger.Error("Exception CustomerEmailConfirmation. " + excp.Message); m_confirmMessage.Text = "There was an error confirming your account. Please check that you entered the confirmation URL correctly."; } }
public SIPDialPlan UpdateDialPlan(SIPDialPlan dialPlan) { Customer customer = AuthoriseRequest(); if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && dialPlan.Owner != customer.CustomerUsername) { throw new ApplicationException("You are not authorised to update the Dial Plan."); } return(DialPlanPersistor.Update(dialPlan)); }
public SIPProvider UpdateSIPProvider(SIPProvider sipProvider) { Customer customer = AuthoriseRequest(); if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername) { throw new ApplicationException("You are not authorised to update the SIP Provider."); } string validationError = SIPProvider.ValidateAndClean(sipProvider); if (validationError != null) { logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError); throw new ApplicationException(validationError); } else { return(SIPProviderPersistor.Update(sipProvider)); } }
public SIPAccount UpdateSIPAccount(SIPAccount sipAccount) { Customer customer = AuthoriseRequest(); if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipAccount.Owner != customer.CustomerUsername) { logger.Debug("Unauthorised attempt to update SIP account by user="******", on account owned by=" + sipAccount.Owner + "."); throw new ApplicationException("You are not authorised to update the SIP Account."); } string validationError = SIPAccount.ValidateAndClean(sipAccount); if (validationError != null) { logger.Warn("Validation error in UpdateSIPAccount for customer " + customer.CustomerUsername + ". " + validationError); throw new ApplicationException(validationError); } else { return(SIPAccountPersistor.Update(sipAccount)); } }
/// <summary> /// Updates the bindings list for a registrar's address-of-records. /// </summary> /// <param name="proxyEndPoint">If the request arrived at this registrar via a proxy then this will contain the end point of the proxy.</param> /// <param name="uacRecvdEndPoint">The public end point the UAC REGISTER request was deemded to have originated from.</param> /// <param name="registrarEndPoint">The registrar end point the registration request was received on.</param> /// <param name="maxAllowedExpiry">The maximum allowed expiry that can be granted to this binding request.</param> /// <returns>If the binding update was successful the expiry time for it is returned otherwise 0.</returns> public List <SIPRegistrarBinding> UpdateBindings( SIPAccount sipAccount, SIPEndPoint proxySIPEndPoint, SIPEndPoint remoteSIPEndPoint, SIPEndPoint registrarSIPEndPoint, List <SIPContactHeader> contactHeaders, string callId, int cseq, //int contactHeaderExpiresValue, int expiresHeaderValue, string userAgent, out SIPResponseStatusCodesEnum responseStatus, out string responseMessage) { //logger.Debug("UpdateBinding " + bindingURI.ToString() + "."); int maxAllowedExpiry = (m_userAgentConfigs != null) ? m_userAgentConfigs.GetMaxAllowedExpiry(userAgent) : SIPUserAgentConfiguration.DEFAULT_MAX_EXPIRY_SECONDS; responseMessage = null; string sipAccountAOR = sipAccount.SIPUsername + "@" + sipAccount.SIPDomain; responseStatus = SIPResponseStatusCodesEnum.Ok; try { userAgent = (userAgent != null && userAgent.Length > MAX_USERAGENT_LENGTH) ? userAgent.Substring(0, MAX_USERAGENT_LENGTH) : userAgent; List <SIPRegistrarBinding> bindings = m_bindingsPersistor.Get(b => b.SIPAccountId == sipAccount.Id, null, 0, Int32.MaxValue); foreach (SIPContactHeader contactHeader in contactHeaders) { SIPURI bindingURI = contactHeader.ContactURI.CopyOf(); int contactHeaderExpiresValue = contactHeader.Expires; int bindingExpiry = 0; if (bindingURI.Host == m_sipRegisterRemoveAll) { if (contactHeaders.Count > 1) { // If a register request specifies remove all it cannot contain any other binding requests. FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingRemoval, "Remove all bindings requested for " + sipAccountAOR + " but mutliple bindings specified, rejecting as a bad request.", sipAccount.SIPUsername)); responseStatus = SIPResponseStatusCodesEnum.BadRequest; break; } #region Process remove all bindings. if (expiresHeaderValue == 0) { // Removing all bindings for user. FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingRemoval, "Remove all bindings requested for " + sipAccountAOR + ".", sipAccount.SIPUsername)); // Mark all the current bindings as expired. if (bindings != null && bindings.Count > 0) { for (int index = 0; index < bindings.Count; index++) { bindings[index].RemovalReason = SIPBindingRemovalReason.ClientExpiredAll; bindings[index].Expiry = 0; m_bindingsPersistor.Update(bindings[index]); // Remove the NAT keep-alive job if present. if (m_natKeepAliveJobs.ContainsKey(bindings[index].RemoteSIPSocket)) { m_natKeepAliveJobs[bindings[index].RemoteSIPSocket].CancelJob(); } } } FireSIPMonitorLogEvent(new SIPMonitorMachineEvent(SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingRemoval, sipAccount.Owner, sipAccount.Id.ToString(), SIPURI.ParseSIPURIRelaxed(sipAccountAOR))); responseStatus = SIPResponseStatusCodesEnum.Ok; } else { // Remove all header cannot be present with other headers and must have an Expiry equal to 0. responseStatus = SIPResponseStatusCodesEnum.BadRequest; } #endregion } else { int requestedExpiry = (contactHeaderExpiresValue != -1) ? contactHeaderExpiresValue : expiresHeaderValue; requestedExpiry = (requestedExpiry == -1) ? maxAllowedExpiry : requestedExpiry; // This will happen if the Expires header and the Expiry on the Contact are both missing. bindingExpiry = (requestedExpiry > maxAllowedExpiry) ? maxAllowedExpiry : requestedExpiry; bindingExpiry = (bindingExpiry < MINIMUM_EXPIRY_SECONDS) ? MINIMUM_EXPIRY_SECONDS : bindingExpiry; bindingURI.Parameters.Remove(m_sipExpiresParameterKey); SIPRegistrarBinding binding = GetBindingForContactURI(bindings, bindingURI.ToString()); if (binding != null) { if (requestedExpiry <= 0) { FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingExpired, "Binding expired by client for " + sipAccountAOR + " from " + remoteSIPEndPoint.ToString() + ".", sipAccount.SIPUsername)); bindings.Remove(binding); m_bindingsPersistor.Delete(binding); bindingExpiry = 0; FireSIPMonitorLogEvent(new SIPMonitorMachineEvent(SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingRemoval, sipAccount.Owner, sipAccount.Id.ToString(), SIPURI.ParseSIPURIRelaxed(sipAccountAOR))); // Remove the NAT keep-alive job if present. if (m_natKeepAliveJobs.ContainsKey(binding.RemoteSIPSocket)) { m_natKeepAliveJobs[binding.RemoteSIPSocket].CancelJob(); } } else { FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.Registrar, "Binding update request for " + sipAccountAOR + " from " + remoteSIPEndPoint.ToString() + ", expiry requested " + requestedExpiry + "s granted " + bindingExpiry + "s.", sipAccount.Owner)); binding.RefreshBinding(bindingExpiry, remoteSIPEndPoint, proxySIPEndPoint, registrarSIPEndPoint, sipAccount.DontMangleEnabled); DateTime startTime = DateTime.Now; m_bindingsPersistor.Update(binding); TimeSpan duration = DateTime.Now.Subtract(startTime); //FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.RegistrarTiming, "Binding database update time for " + sipAccountAOR + " took " + duration.TotalMilliseconds + "ms.", null)); FireSIPMonitorLogEvent(new SIPMonitorMachineEvent(SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingUpdate, sipAccount.Owner, sipAccount.Id.ToString(), SIPURI.ParseSIPURIRelaxed(sipAccountAOR))); // Add a NAT keep-alive job if required. if (sipAccount.SendNATKeepAlives && proxySIPEndPoint != null) { AddNATKeepAliveJob(sipAccount, remoteSIPEndPoint, proxySIPEndPoint, binding, bindingExpiry); } } } else { if (requestedExpiry > 0) { FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingInProgress, "New binding request for " + sipAccountAOR + " from " + remoteSIPEndPoint.ToString() + ", expiry requested " + requestedExpiry + "s granted " + bindingExpiry + "s.", sipAccount.Owner)); if (bindings.Count >= m_maxBindingsPerAccount) { // Need to remove the oldest binding to stay within limit. //SIPRegistrarBinding oldestBinding = m_bindingsPersistor.Get(b => b.SIPAccountId == sipAccount.Id, null, 0, Int32.MaxValue).OrderBy(x => x.LastUpdateUTC).Last(); SIPRegistrarBinding oldestBinding = bindings.OrderBy(x => x.LastUpdate).Last(); FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingInProgress, "Binding limit exceeded for " + sipAccountAOR + " from " + remoteSIPEndPoint.ToString() + " removing oldest binding to stay within limit of " + m_maxBindingsPerAccount + ".", sipAccount.Owner)); m_bindingsPersistor.Delete(oldestBinding); if (m_natKeepAliveJobs.ContainsKey(binding.RemoteSIPSocket)) { m_natKeepAliveJobs[binding.RemoteSIPSocket].CancelJob(); } } SIPRegistrarBinding newBinding = new SIPRegistrarBinding(sipAccount, bindingURI, callId, cseq, userAgent, remoteSIPEndPoint, proxySIPEndPoint, registrarSIPEndPoint, bindingExpiry); DateTime startTime = DateTime.Now; bindings.Add(newBinding); m_bindingsPersistor.Add(newBinding); TimeSpan duration = DateTime.Now.Subtract(startTime); //FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.RegistrarTiming, "Binding database add time for " + sipAccountAOR + " took " + duration.TotalMilliseconds + "ms.", null)); // Add a NAT keep-alive job if required. if (sipAccount.SendNATKeepAlives && proxySIPEndPoint != null) { AddNATKeepAliveJob(sipAccount, remoteSIPEndPoint, proxySIPEndPoint, newBinding, bindingExpiry); } FireSIPMonitorLogEvent(new SIPMonitorMachineEvent(SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingUpdate, sipAccount.Owner, sipAccount.Id.ToString(), SIPURI.ParseSIPURIRelaxed(sipAccountAOR))); } else { FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.BindingFailed, "New binding received for " + sipAccountAOR + " with expired contact," + bindingURI.ToString() + " no update.", sipAccount.Owner)); bindingExpiry = 0; } } responseStatus = SIPResponseStatusCodesEnum.Ok; } } return(bindings); } catch (Exception excp) { logger.Error("Exception UpdateBinding. " + excp.Message); FireSIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Registrar, SIPMonitorEventTypesEnum.Error, "Registrar error updating binding: " + excp.Message + " Binding not updated.", sipAccount.SIPUsername)); responseStatus = SIPResponseStatusCodesEnum.InternalServerError; return(null); } }