mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-21 23:25:26 +00:00
refactor(confif): update known misc dirs & improve IsTemplate func
Signed-off-by: Dwi Siswanto <git@dw1.io>
This commit is contained in:
parent
3ef581c5e8
commit
b529125031
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
knownConfigFiles = []string{"cves.json", "contributors.json", "TEMPLATES-STATS.json"}
|
knownConfigFiles = []string{"cves.json", "contributors.json", "TEMPLATES-STATS.json"}
|
||||||
knownMiscDirectories = []string{".git/", ".github/", "helpers/"}
|
knownMiscDirectories = []string{".git", ".github", "helpers"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// TemplateFormat
|
// TemplateFormat
|
||||||
@ -26,6 +26,20 @@ const (
|
|||||||
Unknown
|
Unknown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetKnownConfigFiles returns known config files
|
||||||
|
func GetKnownConfigFiles() []string {
|
||||||
|
return knownConfigFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetKnownMiscDirectories() []string {
|
||||||
|
trailedSlashDirs := make([]string, 0, len(knownMiscDirectories))
|
||||||
|
for _, dir := range knownMiscDirectories {
|
||||||
|
trailedSlashDirs = append(trailedSlashDirs, dir+string(os.PathSeparator))
|
||||||
|
}
|
||||||
|
|
||||||
|
return trailedSlashDirs
|
||||||
|
}
|
||||||
|
|
||||||
// GetTemplateFormatFromExt returns template format
|
// GetTemplateFormatFromExt returns template format
|
||||||
func GetTemplateFormatFromExt(filePath string) TemplateFormat {
|
func GetTemplateFormatFromExt(filePath string) TemplateFormat {
|
||||||
fileExt := strings.ToLower(filepath.Ext(filePath))
|
fileExt := strings.ToLower(filepath.Ext(filePath))
|
||||||
@ -44,18 +58,21 @@ func GetSupportTemplateFileExtensions() []string {
|
|||||||
return []string{extensions.YAML, extensions.JSON}
|
return []string{extensions.YAML, extensions.JSON}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTemplate is a callback function used by goflags to decide if given file should be read
|
// IsTemplate returns true if the file is a template based on its path.
|
||||||
// if it is not a nuclei-template file only then file is read
|
// It used by goflags and other places to filter out non-template files.
|
||||||
func IsTemplate(filename string) bool {
|
func IsTemplate(fpath string) bool {
|
||||||
if stringsutil.ContainsAny(filename, knownConfigFiles...) {
|
fname := filepath.Base(fpath)
|
||||||
|
fext := strings.ToLower(filepath.Ext(fpath))
|
||||||
|
|
||||||
|
if stringsutil.ContainsAny(fname, GetKnownConfigFiles()...) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if stringsutil.ContainsAny(filename, knownMiscDirectories...) {
|
if stringsutil.ContainsAny(fpath, GetKnownMiscDirectories()...) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringsutil.EqualFoldAny(filepath.Ext(filename), GetSupportTemplateFileExtensions()...)
|
return stringsutil.EqualFoldAny(fext, GetSupportTemplateFileExtensions()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type template struct {
|
type template struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user