fix: Cron Validation (#4842)

* Add Cron Next Time Validation

The cron job can't be created if the year is more than 100 years in the future.
Getting the next valid time will return null if this is the case.

* add next cron validation to api
* add next cron validation to job settings page

* Add Missing Import
pull/4919/head
Alexander Russell 1 year ago committed by GitHub
parent ca947bd302
commit 97cc42ffa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,6 @@
using Ombi.Helpers;
using Quartz;
using System;
namespace Ombi.Settings.Settings.Models
{
@ -104,7 +105,9 @@ namespace Ombi.Settings.Settings.Models
private static string ValidateCron(string cron)
{
if (CronExpression.IsValidExpression(cron))
CronExpression expression = new CronExpression(cron);
DateTimeOffset? nextFireUTCTime = expression.GetNextValidTimeAfter(DateTime.Now);
if (CronExpression.IsValidExpression(cron) && nextFireUTCTime != null)
{
return cron;
}

@ -652,7 +652,9 @@ namespace Ombi.Controllers.V1
try
{
var isValid = CronExpression.IsValidExpression(expression);
if (!isValid)
CronExpression cron = new CronExpression(expression);
DateTimeOffset? nextFireUTCTime = cron.GetNextValidTimeAfter(DateTime.Now);
if (!isValid || nextFireUTCTime == null)
{
return new JobSettingsViewModel
{

Loading…
Cancel
Save