Merge pull request #487 from mitchellcash/port_validation

Fixed: Proper port validation for download clients and connections
pull/2/head
Devin Buhl 8 years ago committed by GitHub
commit f9844c284a

@ -76,14 +76,14 @@ namespace NzbDrone.Api.ClientSchema
if (propertyInfo.PropertyType == typeof(int)) if (propertyInfo.PropertyType == typeof(int))
{ {
var value = Convert.ToInt32(field.Value); var value = field.Value.ToString().ParseInt32();
propertyInfo.SetValue(target, value, null); propertyInfo.SetValue(target, value ?? 0, null);
} }
else if (propertyInfo.PropertyType == typeof(long)) else if (propertyInfo.PropertyType == typeof(long))
{ {
var value = Convert.ToInt64(field.Value); var value = field.Value.ToString().ParseInt64();
propertyInfo.SetValue(target, value, null); propertyInfo.SetValue(target, value ?? 0, null);
} }
else if (propertyInfo.PropertyType == typeof(int?)) else if (propertyInfo.PropertyType == typeof(int?))

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
public DelugeSettingsValidator() public DelugeSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.MovieCategory).Matches("^[-a-z]*$").WithMessage("Allowed characters a-z and -"); RuleFor(c => c.MovieCategory).Matches("^[-a-z]*$").WithMessage("Allowed characters a-z and -");
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
public HadoukenSettingsValidator() public HadoukenSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.Username).NotEmpty() RuleFor(c => c.Username).NotEmpty()
.WithMessage("Username must not be empty."); .WithMessage("Username must not be empty.");

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
public NzbVortexSettingsValidator() public NzbVortexSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.ApiKey).NotEmpty() RuleFor(c => c.ApiKey).NotEmpty()
.WithMessage("API Key is required"); .WithMessage("API Key is required");

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
public NzbgetSettingsValidator() public NzbgetSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.Username).NotEmpty().When(c => !string.IsNullOrWhiteSpace(c.Password)); RuleFor(c => c.Username).NotEmpty().When(c => !string.IsNullOrWhiteSpace(c.Password));
RuleFor(c => c.Password).NotEmpty().When(c => !string.IsNullOrWhiteSpace(c.Username)); RuleFor(c => c.Password).NotEmpty().When(c => !string.IsNullOrWhiteSpace(c.Username));

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
public QBittorrentSettingsValidator() public QBittorrentSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(0, 65535); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
} }
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
public SabnzbdSettingsValidator() public SabnzbdSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.ApiKey).NotEmpty() RuleFor(c => c.ApiKey).NotEmpty()
.WithMessage("API Key is required when username/password are not configured") .WithMessage("API Key is required when username/password are not configured")

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
public TransmissionSettingsValidator() public TransmissionSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.UrlBase).ValidUrlBase(); RuleFor(c => c.UrlBase).ValidUrlBase();

@ -10,10 +10,10 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
public RTorrentSettingsValidator() public RTorrentSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(0, 65535); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.MovieCategory).NotEmpty() RuleFor(c => c.MovieCategory).NotEmpty()
.WithMessage("A category is recommended") .WithMessage("A category is recommended")
.AsWarning(); .AsWarning();
} }
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
public UTorrentSettingsValidator() public UTorrentSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(0, 65535); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.TvCategory).NotEmpty(); RuleFor(c => c.TvCategory).NotEmpty();
} }
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Email
public EmailSettingsValidator() public EmailSettingsValidator()
{ {
RuleFor(c => c.Server).NotEmpty(); RuleFor(c => c.Server).NotEmpty();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.From).NotEmpty(); RuleFor(c => c.From).NotEmpty();
RuleFor(c => c.To).NotEmpty(); RuleFor(c => c.To).NotEmpty();
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Growl
public GrowlSettingsValidator() public GrowlSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
} }
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Plex
public PlexClientSettingsValidator() public PlexClientSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
} }
} }

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Notifications.Plex
public PlexServerSettingsValidator() public PlexServerSettingsValidator()
{ {
RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).GreaterThan(0); RuleFor(c => c.Port).InclusiveBetween(1, 65535);
} }
} }

Loading…
Cancel
Save