Files
3x-ui/internal/util/cronspec/cronspec.go
T
MHSanaei b124af2a1b fix(settings): accept five-field crontab for report and LDAP schedules
The panel scheduler runs WithSeconds(), whose parser rejects a standard
five-field crontab such as "30 8 * * *". An admin who typed one into the
Telegram/Discord notify time or the LDAP sync schedule saved it without
error, AddJob then failed at startup, and the job silently never ran.

Admin-typed schedules now go through internal/util/cronspec, which takes
an optional seconds column plus the @descriptors and hands the scheduler
a parsed cron.Schedule. CheckValid rejects an unparseable schedule on
save, and a stored legacy value falls back to the job's default instead
of dropping the job.
2026-10-11 20:37:04 +02:00

25 lines
724 B
Go

// Package cronspec parses the cron schedules an admin types into the settings.
package cronspec
import (
"strings"
"github.com/robfig/cron/v3"
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
)
// The panel scheduler runs WithSeconds(), whose parser rejects five-field crontab,
// so admin schedules are parsed here with the seconds column optional.
var parser = cron.NewParser(
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
)
func Parse(spec string) (cron.Schedule, error) {
schedule, err := parser.Parse(strings.TrimSpace(spec))
if err != nil {
return nil, common.NewErrorf("cron schedule <%v> is not valid: %v", spec, err)
}
return schedule, nil
}