render nuclei-templates release (#4082)

This commit is contained in:
Tarun Koyalwar 2023-08-23 18:22:53 +05:30 committed by GitHub
parent fd2ae8de00
commit e146c89930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels" "github.com/projectdiscovery/gologger/levels"
"github.com/projectdiscovery/interactsh/pkg/client" "github.com/projectdiscovery/interactsh/pkg/client"
"github.com/projectdiscovery/nuclei/v2/internal/installer"
"github.com/projectdiscovery/nuclei/v2/internal/runner" "github.com/projectdiscovery/nuclei/v2/internal/runner"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity" "github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
@ -340,6 +341,11 @@ on extensive configurability, massive extensibility and ease of use.`)
gologger.DefaultLogger.SetTimestamp(options.Timestamp, levels.LevelDebug) gologger.DefaultLogger.SetTimestamp(options.Timestamp, levels.LevelDebug)
if options.Silent {
// hide release notes if silent mode is enabled
installer.HideReleaseNotes = true
}
if options.LeaveDefaultPorts { if options.LeaveDefaultPorts {
http.LeaveDefaultPorts = true http.LeaveDefaultPorts = true
} }

View File

@ -12,6 +12,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/charmbracelet/glamour"
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
@ -29,6 +30,7 @@ const (
var ( var (
HideProgressBar = true HideProgressBar = true
HideUpdateChangesTable = false HideUpdateChangesTable = false
HideReleaseNotes = false
) )
// TemplateUpdateResults contains the results of template update // TemplateUpdateResults contains the results of template update
@ -105,6 +107,7 @@ func (t *TemplateManager) installTemplatesAt(dir string) error {
if err != nil { if err != nil {
return errorutil.NewWithErr(err).Msgf("failed to install templates at %s", dir) return errorutil.NewWithErr(err).Msgf("failed to install templates at %s", dir)
} }
// write templates to disk // write templates to disk
if err := t.writeTemplatesToDisk(ghrd, dir); err != nil { if err := t.writeTemplatesToDisk(ghrd, dir); err != nil {
return errorutil.NewWithErr(err).Msgf("failed to write templates to disk at %s", dir) return errorutil.NewWithErr(err).Msgf("failed to write templates to disk at %s", dir)
@ -313,6 +316,21 @@ func (t *TemplateManager) writeTemplatesToDisk(ghrd *updateutils.GHReleaseDownlo
return errorutil.NewWithErr(err).Msgf("failed to write nuclei templates index") return errorutil.NewWithErr(err).Msgf("failed to write nuclei templates index")
} }
if !HideReleaseNotes {
output := ghrd.Latest.GetBody()
// adjust colors for both dark / light terminal themes
r, err := glamour.NewTermRenderer(glamour.WithAutoStyle())
if err != nil {
gologger.Error().Msgf("markdown rendering not supported: %v", err)
}
if rendered, err := r.Render(output); err == nil {
output = rendered
} else {
gologger.Error().Msg(err.Error())
}
gologger.Print().Msgf("\n%v\n\n", output)
}
// after installation, create and write checksums to .checksum file // after installation, create and write checksums to .checksum file
return t.writeChecksumFileInDir(dir) return t.writeChecksumFileInDir(dir)
} }