示例#1
0
 public BSGSmsService(SmsServiceConfiguration configuration)
 {
     if (configuration.ServiceName != SmsServiceTypes.BSG)
     {
         throw new ArgumentException($"{nameof(SmsServiceConfiguration.ServiceName)} should be {SmsServiceTypes.BSG}.", nameof(configuration));
     }
     _configuration = (BSGServiceConfiguration)configuration;
 }
示例#2
0
 public SMSRUSmsService(SmsServiceConfiguration configuration)
 {
     if (configuration.ServiceName != SmsServiceTypes.SMSRU)
     {
         throw new ArgumentException($"{nameof(SmsServiceConfiguration.ServiceName)} should be {SmsServiceTypes.SMSRU}.", nameof(configuration));
     }
     _configuration = (SMSRUServiceConfiguration)configuration;
 }
 public GolosAlohaSmsService(SmsServiceConfiguration configuration)
 {
     if (configuration.ServiceName != SmsServiceTypes.GolosAloha)
     {
         throw new ArgumentException($"{nameof(SmsServiceConfiguration.ServiceName)} should be {SmsServiceTypes.GolosAloha}.", nameof(configuration));
     }
     _configuration = (VoiceServiceConfiguration)configuration;
 }
        public async Task <IActionResult> Update([FromForm] ConfigsModel configsModel)
        {
            ErrorModel errorModel            = new ErrorModel();
            bool       encryptionChangedFlag = false;

            try
            {
                if (!configsModel.SmtpClient.IsValid() && configsModel.Node.RegistrationMethod == RegistrationMethod.EmailRequired)
                {
                    errorModel.Errors.Add("RegistrationMethod", "Selected registration method requires specifying the correct SmtpClient settings.");
                }
                int settingsCount = 0;
                SmsServiceConfiguration smsConfiguration = NodeSettings.Configs.SmsServiceConfiguration;
                if (configsModel.BSGServiceConfiguration.IsValid() && NodeSettings.Configs.SmsServiceConfiguration.GetType() != typeof(BSGServiceConfiguration))
                {
                    settingsCount++;
                    smsConfiguration = configsModel.BSGServiceConfiguration;
                }
                if (configsModel.SMSIntelServiceConfiguration.IsValid() && NodeSettings.Configs.SmsServiceConfiguration.GetType() != typeof(SMSIntelServiceConfiguration))
                {
                    settingsCount++;
                    smsConfiguration = configsModel.SMSIntelServiceConfiguration;
                }
                if (configsModel.SMSRUServiceConfiguration.IsValid() && NodeSettings.Configs.SmsServiceConfiguration.GetType() != typeof(SMSRUServiceConfiguration))
                {
                    settingsCount++;
                    smsConfiguration = configsModel.SMSRUServiceConfiguration;
                }
                if (configsModel.GolosAlohaServiceConfiguration.IsValid() && NodeSettings.Configs.SmsServiceConfiguration.GetType() != typeof(VoiceServiceConfiguration))
                {
                    settingsCount++;
                    smsConfiguration = configsModel.GolosAlohaServiceConfiguration;
                }
                if (settingsCount > 1)
                {
                    errorModel.Errors.Add("SmsServiceConfiguration", "Found more than one SMS service configuration");
                }
                if (settingsCount == 0 && configsModel.Node.RegistrationMethod == RegistrationMethod.PhoneRequired && !smsConfiguration.IsValid())
                {
                    errorModel.Errors.Add("RegistrationMethod", "Selected registration method requires specifying the correct SmsService settings.");
                }
                if (errorModel.Errors.Any())
                {
                    configsModel.ErrorModel = errorModel;
                    return(Index(configsModel));
                }
                if (settingsCount == 0)
                {
                    if (configsModel.SMSIntelServiceConfiguration.IsValid())
                    {
                        smsConfiguration = configsModel.SMSIntelServiceConfiguration;
                    }
                    else if (configsModel.SMSRUServiceConfiguration.IsValid())
                    {
                        smsConfiguration = configsModel.SMSRUServiceConfiguration;
                    }
                    else if (configsModel.BSGServiceConfiguration.IsValid())
                    {
                        smsConfiguration = configsModel.BSGServiceConfiguration;
                    }
                    else if (configsModel.GolosAlohaServiceConfiguration.IsValid())
                    {
                        smsConfiguration = configsModel.GolosAlohaServiceConfiguration;
                    }
                }
                NodeSettings.Configs.AllowedRegistration      = configsModel.AllowedRegistration;
                NodeSettings.Configs.BlockchainDbConnection   = configsModel.BlockchainDbConnection;
                NodeSettings.Configs.CacheServerConnection    = configsModel.CacheServerConnection;
                NodeSettings.Configs.ConfirmUsers             = configsModel.ConfirmUsers;
                NodeSettings.Configs.LicensorUrl              = configsModel.LicensorUrl;
                NodeSettings.Configs.MaxDbBackups             = configsModel.MaxDbBackups;
                NodeSettings.Configs.MessengerDbConnection    = configsModel.MessengerDbConnection;
                NodeSettings.Configs.OpenStackOptions         = configsModel.OpenStackOptions;
                NodeSettings.Configs.S3FileStorageOptions     = configsModel.S3FileStorageOptions;
                NodeSettings.Configs.SmtpClient               = configsModel.SmtpClient;
                NodeSettings.Configs.RecoveryMode             = configsModel.RecoveryMode;
                NodeSettings.Configs.Node.ClientsPort         = configsModel.ClientsPort;
                NodeSettings.Configs.Node.NodesPort           = configsModel.NodesPort;
                NodeSettings.Configs.Node.SupportEmail        = configsModel.Node.SupportEmail;
                NodeSettings.Configs.Node.AdminEmail          = configsModel.Node.AdminEmail;
                NodeSettings.Configs.Node.PermanentlyDeleting = configsModel.Node.PermanentlyDeleting;
                NodeSettings.Configs.Node.RegistrationMethod  = configsModel.Node.RegistrationMethod;
                NodeSettings.Configs.Node.Country             = configsModel.Node.Country;
                NodeSettings.Configs.SmsServiceConfiguration  = smsConfiguration;
                if (configsModel.Node.EncryptionType != NodeSettings.Configs.Node.EncryptionType)
                {
                    NodeSettings.Configs.Node.EncryptionType = configsModel.Node.EncryptionType;
                    encryptionChangedFlag = true;
                }
                if (configsModel.RecoveryMode)
                {
                    _connectionsService.CloseAllClientConnections();
                }

                if (configsModel.Node != null)
                {
                    NodeSettings.Configs.Node.About   = configsModel.Node.About;
                    NodeSettings.Configs.Node.Name    = configsModel.Node.Name;
                    NodeSettings.Configs.Node.Storage = configsModel.Node.Storage;
                    NodeSettings.Configs.Node.Visible = configsModel.Node.Visible;
                    NodeSettings.Configs.Node.Routing = configsModel.Node.Routing;
                    NodeSettings.Configs.Node.UserRegistrationAllowed = configsModel.Node.UserRegistrationAllowed;
                    if (configsModel.NodeImage != null && configsModel.NodeImage.Length > 0)
                    {
                        string path = _fileStorage.StorageName == "Local"
                            ? Path.Combine(
                            NodeSettings.LOCAL_FILE_STORAGE_PATH,
                            $"[{RandomExtensions.NextString(10)}]{configsModel.NodeImage.FileName}")
                            : null;
                        using (SHA256 sha256 = SHA256.Create())
                        {
                            var fileHash = sha256.ComputeHash(configsModel.NodeImage.OpenReadStream());
                            var fileInfo = await _filesService.SaveFileAsync(
                                null,
                                configsModel.NodeImage.FileName,
                                path,
                                configsModel.NodeImage.Length,
                                fileHash,
                                _fileStorage.StorageName).ConfigureAwait(false);

                            await _fileStorage.UploadAsync(configsModel.NodeImage.OpenReadStream(), path ?? fileInfo.FileId).ConfigureAwait(false);

                            NodeSettings.Configs.Node.Photo = fileInfo.FileId;
                        }
                    }
                    if (LicensorClient.Instance.IsAuthentificated)
                    {
                        var editedNode = await LicensorClient.Instance.EditNodeAsync(NodeSettings.Configs.Node).ConfigureAwait(false);

                        _nodesService.CreateOrUpdateNodeInformationAsync(editedNode);
                    }
                }
                await NodeSettings.Configs.UpdateConfigurationFileAsync().ConfigureAwait(false);

                if (encryptionChangedFlag)
                {
                    _connectionsService.RestartNodeConnections();
                }
                NodeSettings.AppShutdownTokenSource.CancelAfter(TimeSpan.FromSeconds(3));
                return(Index(configsModel));
            }
            catch (Exception ex)
            {
                errorModel.Errors.Add("Internal server error", ex.Message);
                configsModel.ErrorModel = errorModel;
                return(Index(configsModel));
            }
        }