Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/catalog/config/constants.go
2851 views
1
package config
2
3
import (
4
"strings"
5
6
"github.com/Masterminds/semver/v3"
7
)
8
9
type AppMode string
10
11
const (
12
AppModeLibrary AppMode = "library"
13
AppModeCLI AppMode = "cli"
14
)
15
16
var (
17
// Global Var to control behaviours specific to cli or library
18
// maybe this should be moved to utils ??
19
// this is overwritten in cmd/nuclei/main.go
20
CurrentAppMode = AppModeLibrary
21
)
22
23
const (
24
TemplateConfigFileName = ".templates-config.json"
25
NucleiTemplatesDirName = "nuclei-templates"
26
OfficialNucleiTemplatesRepoName = "nuclei-templates"
27
NucleiIgnoreFileName = ".nuclei-ignore"
28
NucleiTemplatesIndexFileName = ".templates-index" // contains index of official nuclei templates
29
NucleiTemplatesCheckSumFileName = ".checksum"
30
NewTemplateAdditionsFileName = ".new-additions"
31
CLIConfigFileName = "config.yaml"
32
ReportingConfigFilename = "reporting-config.yaml"
33
// Version is the current version of nuclei
34
Version = `v3.7.0`
35
// Directory Names of custom templates
36
CustomS3TemplatesDirName = "s3"
37
CustomGitHubTemplatesDirName = "github"
38
CustomAzureTemplatesDirName = "azure"
39
CustomGitLabTemplatesDirName = "gitlab"
40
BinaryName = "nuclei"
41
FallbackConfigFolderName = ".nuclei-config"
42
NucleiConfigDirEnv = "NUCLEI_CONFIG_DIR"
43
NucleiTemplatesDirEnv = "NUCLEI_TEMPLATES_DIR"
44
)
45
46
// IsOutdatedVersion compares two versions and returns true
47
// if the current version is outdated
48
func IsOutdatedVersion(current, latest string) bool {
49
if latest == "" {
50
// NOTE(dwisiswant0): if PDTM API call failed or returned empty, we
51
// cannot determine if templates are outdated w/o additional checks
52
// return false to avoid unnecessary updates.
53
return false
54
}
55
56
current = trimDevIfExists(current)
57
currentVer, _ := semver.NewVersion(current)
58
newVer, _ := semver.NewVersion(latest)
59
60
if currentVer == nil || newVer == nil {
61
// fallback to naive comparison - return true only if they are different
62
return current != latest
63
}
64
65
return newVer.GreaterThan(currentVer)
66
}
67
68
// trimDevIfExists trims `-dev` suffix from version string if it exists
69
func trimDevIfExists(version string) string {
70
if strings.HasSuffix(version, "-dev") {
71
return strings.TrimSuffix(version, "-dev")
72
}
73
return version
74
}
75
76
// similar to go pattern of enabling debug related features
77
// we add custom/extra switches for debugging purposes
78
const (
79
// DebugArgHostErrorStats is used to print host error stats
80
// when it is closed
81
DebugArgHostErrorStats = "host-error-stats"
82
// DebugExportReqURLPattern is used to export request URL pattern
83
DebugExportURLPattern = "req-url-pattern"
84
)
85
86