Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/catalog/config/constants.go
2070 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.4.10`
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
)
44
45
// IsOutdatedVersion compares two versions and returns true
46
// if the current version is outdated
47
func IsOutdatedVersion(current, latest string) bool {
48
if latest == "" {
49
// NOTE(dwisiswant0): if PDTM API call failed or returned empty, we
50
// cannot determine if templates are outdated w/o additional checks
51
// return false to avoid unnecessary updates.
52
return false
53
}
54
55
current = trimDevIfExists(current)
56
currentVer, _ := semver.NewVersion(current)
57
newVer, _ := semver.NewVersion(latest)
58
59
if currentVer == nil || newVer == nil {
60
// fallback to naive comparison - return true only if they are different
61
return current != latest
62
}
63
64
return newVer.GreaterThan(currentVer)
65
}
66
67
// trimDevIfExists trims `-dev` suffix from version string if it exists
68
func trimDevIfExists(version string) string {
69
if strings.HasSuffix(version, "-dev") {
70
return strings.TrimSuffix(version, "-dev")
71
}
72
return version
73
}
74
75
// similar to go pattern of enabling debug related features
76
// we add custom/extra switches for debugging purposes
77
const (
78
// DebugArgHostErrorStats is used to print host error stats
79
// when it is closed
80
DebugArgHostErrorStats = "host-error-stats"
81
// DebugExportReqURLPattern is used to export request URL pattern
82
DebugExportURLPattern = "req-url-pattern"
83
)
84
85