2021-07-12 17:20:01 +03:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
2021-07-19 21:04:08 +03:00
|
|
|
"strings"
|
|
|
|
|
|
2021-07-16 17:28:13 +03:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/internal/severity"
|
2021-07-12 17:20:01 +03:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Info struct {
|
2021-07-13 11:12:03 +03:00
|
|
|
Name string
|
|
|
|
|
Authors StringSlice `yaml:"author"`
|
|
|
|
|
Tags StringSlice `yaml:"tags"`
|
|
|
|
|
Description string
|
2021-07-16 17:28:13 +03:00
|
|
|
Reference StringSlice `yaml:"reference"`
|
|
|
|
|
SeverityHolder severity.SeverityHolder `yaml:"severity"`
|
2021-07-12 17:20:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type StringSlice struct {
|
|
|
|
|
Value interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stringSlice *StringSlice) IsEmpty() bool {
|
|
|
|
|
return utils.IsEmpty(stringSlice.Value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stringSlice StringSlice) ToSlice() []string {
|
|
|
|
|
switch value := stringSlice.Value.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
return []string{value}
|
|
|
|
|
case []string:
|
|
|
|
|
return value
|
2021-07-15 13:41:41 +03:00
|
|
|
case nil:
|
|
|
|
|
return []string{}
|
2021-07-12 17:20:01 +03:00
|
|
|
}
|
|
|
|
|
panic("Illegal State: StringSlice holds non-string value(s)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stringSlice *StringSlice) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
2021-07-15 13:41:41 +03:00
|
|
|
marshalledSlice, err := marshalStringToSlice(unmarshal)
|
2021-07-12 17:20:01 +03:00
|
|
|
if err != nil {
|
2021-07-15 13:41:41 +03:00
|
|
|
return err
|
2021-07-12 17:20:01 +03:00
|
|
|
}
|
|
|
|
|
|
2021-07-15 13:41:41 +03:00
|
|
|
result := make([]string, len(marshalledSlice))
|
|
|
|
|
for _, value := range marshalledSlice {
|
2021-07-12 17:20:01 +03:00
|
|
|
result = append(result, strings.ToLower(strings.TrimSpace(value)))
|
|
|
|
|
}
|
|
|
|
|
stringSlice.Value = result
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 13:41:41 +03:00
|
|
|
func marshalStringToSlice(unmarshal func(interface{}) error) ([]string, error) {
|
|
|
|
|
var marshalledValueAsString string
|
|
|
|
|
var marshalledValuesAsSlice []string
|
|
|
|
|
|
|
|
|
|
sliceMarshalError := unmarshal(&marshalledValuesAsSlice)
|
|
|
|
|
if sliceMarshalError != nil {
|
|
|
|
|
stringMarshalError := unmarshal(&marshalledValueAsString)
|
|
|
|
|
if stringMarshalError != nil {
|
|
|
|
|
return nil, stringMarshalError
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result []string
|
|
|
|
|
if len(marshalledValuesAsSlice) > 0 {
|
|
|
|
|
result = marshalledValuesAsSlice
|
|
|
|
|
} else if utils.IsNotEmpty(marshalledValueAsString) {
|
|
|
|
|
result = strings.Split(marshalledValueAsString, ",")
|
|
|
|
|
} else {
|
|
|
|
|
result = []string{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 17:20:01 +03:00
|
|
|
func (stringSlice StringSlice) MarshalYAML() (interface{}, error) {
|
|
|
|
|
switch value := stringSlice.Value.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
return value, nil
|
|
|
|
|
case []string:
|
|
|
|
|
return strings.Join(value, ", "), nil
|
|
|
|
|
default:
|
|
|
|
|
panic("Unsupported type")
|
|
|
|
|
}
|
|
|
|
|
}
|