2023-04-19 21:58:48 +05:30
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-14 03:08:53 +05:30
|
|
|
type AppMode string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
AppModeLibrary AppMode = "library"
|
|
|
|
|
AppModeCLI AppMode = "cli"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
// Global Var to control behaviours specific to cli or library
|
|
|
|
|
// maybe this should be moved to utils ??
|
|
|
|
|
// this is overwritten in cmd/nuclei/main.go
|
|
|
|
|
CurrentAppMode = AppModeLibrary
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-19 21:58:48 +05:30
|
|
|
const (
|
2023-06-26 14:15:12 +02:00
|
|
|
TemplateConfigFileName = ".templates-config.json"
|
|
|
|
|
NucleiTemplatesDirName = "nuclei-templates"
|
2023-05-28 17:12:23 +05:30
|
|
|
OfficialNucleiTemplatesRepoName = "nuclei-templates"
|
2023-06-26 14:15:12 +02:00
|
|
|
NucleiIgnoreFileName = ".nuclei-ignore"
|
|
|
|
|
NucleiTemplatesIndexFileName = ".templates-index" // contains index of official nuclei templates
|
|
|
|
|
NucleiTemplatesCheckSumFileName = ".checksum"
|
|
|
|
|
NewTemplateAdditionsFileName = ".new-additions"
|
2023-07-17 15:23:10 -04:00
|
|
|
CLIConfigFileName = "config.yaml"
|
2023-06-26 14:15:12 +02:00
|
|
|
ReportingConfigFilename = "reporting-config.yaml"
|
2023-04-19 21:58:48 +05:30
|
|
|
// Version is the current version of nuclei
|
2024-05-11 00:47:35 +05:30
|
|
|
Version = `v3.2.7`
|
2023-04-19 17:42:52 -04:00
|
|
|
// Directory Names of custom templates
|
|
|
|
|
CustomS3TemplatesDirName = "s3"
|
2023-08-01 14:33:43 -04:00
|
|
|
CustomGitHubTemplatesDirName = "github"
|
2023-04-19 17:42:52 -04:00
|
|
|
CustomAzureTemplatesDirName = "azure"
|
|
|
|
|
CustomGitLabTemplatesDirName = "gitlab"
|
2023-10-13 11:55:09 +05:30
|
|
|
BinaryName = "nuclei"
|
|
|
|
|
FallbackConfigFolderName = ".nuclei-config"
|
|
|
|
|
NucleiConfigDirEnv = "NUCLEI_CONFIG_DIR"
|
2023-04-19 21:58:48 +05:30
|
|
|
)
|
|
|
|
|
|
2023-07-17 15:23:10 -04:00
|
|
|
// IsOutdatedVersion compares two versions and returns true
|
|
|
|
|
// if the current version is outdated
|
2023-04-19 21:58:48 +05:30
|
|
|
func IsOutdatedVersion(current, latest string) bool {
|
|
|
|
|
if latest == "" {
|
2023-07-17 15:23:10 -04:00
|
|
|
// if pdtm api call failed it's assumed that the current version is outdated
|
|
|
|
|
// and it will be confirmed while updating from GitHub
|
2023-04-19 21:58:48 +05:30
|
|
|
// this fixes `version string empty` errors
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
current = trimDevIfExists(current)
|
|
|
|
|
currentVer, _ := semver.NewVersion(current)
|
|
|
|
|
newVer, _ := semver.NewVersion(latest)
|
|
|
|
|
if currentVer == nil || newVer == nil {
|
|
|
|
|
// fallback to naive comparison
|
|
|
|
|
return current == latest
|
|
|
|
|
}
|
|
|
|
|
return newVer.GreaterThan(currentVer)
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 11:36:39 -04:00
|
|
|
// trimDevIfExists trims `-dev` suffix from version string if it exists
|
2023-04-19 21:58:48 +05:30
|
|
|
func trimDevIfExists(version string) string {
|
|
|
|
|
if strings.HasSuffix(version, "-dev") {
|
|
|
|
|
return strings.TrimSuffix(version, "-dev")
|
|
|
|
|
}
|
|
|
|
|
return version
|
|
|
|
|
}
|