forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template_path.go
43 lines (35 loc) · 1.13 KB
/
template_path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package utils
import (
"path/filepath"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
)
const (
// TemplatesRepoURL is the URL for files in nuclei-templates repository
TemplatesRepoURL = "https://github.com/projectdiscovery/nuclei-templates/blob/master/"
)
var configData *config.Config
func init() {
configData, _ = config.ReadConfiguration()
}
// TemplatePathURL returns the Path and URL for the provided template
func TemplatePathURL(fullPath string) (string, string) {
var templateDirectory string
if configData != nil && configData.TemplatesDirectory != "" && strings.HasPrefix(fullPath, configData.TemplatesDirectory) {
templateDirectory = configData.TemplatesDirectory
} else {
return "", ""
}
finalPath := strings.TrimPrefix(strings.TrimPrefix(fullPath, templateDirectory), "/")
templateURL := TemplatesRepoURL + finalPath
return finalPath, templateURL
}
// GetDefaultTemplatePath on default settings
func GetDefaultTemplatePath() (string, error) {
home, err := homedir.Dir()
if err != nil {
return "", err
}
return filepath.Join(home, "nuclei-templates"), nil
}