Skip to content

Commit

Permalink
Auto template download/update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Jul 3, 2021
1 parent c731e7f commit 57f29c8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions v2/internal/runner/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ func (r *Runner) updateTemplates() error {

ctx := context.Background()
if r.templatesConfig.CurrentVersion == "" || (r.options.TemplatesDirectory != "" && r.templatesConfig.TemplatesDirectory != r.options.TemplatesDirectory) {
if !r.options.UpdateTemplates {
gologger.Warning().Msgf("nuclei-templates are not installed (or indexed), use update-templates flag.\n")
return nil
}
gologger.Info().Msgf("nuclei-templates are not installed, installing...\n")

// Use custom location if user has given a template directory
r.templatesConfig = &config.Config{
Expand Down Expand Up @@ -155,7 +152,7 @@ func (r *Runner) updateTemplates() error {
return nil
}

// Check if last checked is more than 24 hours.
// Check if last checked is more than 24 hours and we don't have updateTemplates flag.
// If not, return since we don't want to do anything now.
if time.Since(r.templatesConfig.LastChecked) < 24*time.Hour && !r.options.UpdateTemplates {
return nil
Expand Down Expand Up @@ -187,10 +184,8 @@ func (r *Runner) updateTemplates() error {
}

if version.GT(oldVersion) {
if !r.options.UpdateTemplates {
gologger.Warning().Msgf("Your current nuclei-templates v%s are outdated. Latest is v%s\n", oldVersion, version.String())
return config.WriteConfiguration(r.templatesConfig, false, checkedIgnore)
}
gologger.Info().Msgf("Your current nuclei-templates v%s are outdated. Latest is v%s\n", oldVersion, version.String())
gologger.Info().Msgf("Downloading latest release...")

if r.options.TemplatesDirectory != "" {
r.templatesConfig.TemplatesDirectory = r.options.TemplatesDirectory
Expand Down Expand Up @@ -464,7 +459,7 @@ func writeTemplatesChecksum(file string, checksum map[string]string) error {
}

func (r *Runner) printUpdateChangelog(results *templateUpdateResults, version string) {
if len(results.additions) > 0 {
if len(results.additions) > 0 && r.options.Verbose {
gologger.Print().Msgf("\nNewly added templates: \n\n")

for _, addition := range results.additions {
Expand Down

0 comments on commit 57f29c8

Please sign in to comment.