mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
finger update use exe path
This commit is contained in:
parent
7af848a6fd
commit
2b7be8d449
@ -11,7 +11,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -30,11 +30,11 @@ var (
|
||||
)
|
||||
|
||||
type FingerOptions struct {
|
||||
Finger bool `long:"finger" description:"Bool, enable active finger detect" config:"finger"`
|
||||
FingerUpdate bool `long:"update" description:"Bool, update finger database" config:"update"`
|
||||
FingerPath string `long:"finger-path" default:"fingers" description:"String, 3rd finger config path" config:"finger-path"`
|
||||
FingersTemplatesPath string `long:"finger-template" default:"fingers/templates" description:"Bool, use finger templates path" config:"finger-template"`
|
||||
FingerEngines string `long:"finger-engine" default:"all" description:"String, custom finger engine, e.g. --finger-engine ehole,goby" config:"finger-engine"`
|
||||
Finger bool `long:"finger" description:"Bool, enable active finger detect" config:"finger"`
|
||||
FingerUpdate bool `long:"update" description:"Bool, update finger database" config:"update"`
|
||||
FingerPath string `long:"finger-path" default:"fingers" description:"String, 3rd finger config path" config:"finger-path"`
|
||||
//FingersTemplatesPath string `long:"finger-template" default:"fingers/templates" description:"Bool, use finger templates path" config:"finger-template"`
|
||||
FingerEngines string `long:"finger-engine" default:"all" description:"String, custom finger engine, e.g. --finger-engine ehole,goby" config:"finger-engine"`
|
||||
}
|
||||
|
||||
func (opt *FingerOptions) Validate() error {
|
||||
@ -52,18 +52,17 @@ func (opt *FingerOptions) Validate() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opt.FingersTemplatesPath != DefaultFingerTemplate && !files.IsExist(opt.FingersTemplatesPath) {
|
||||
err = os.MkdirAll(opt.FingersTemplatesPath, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if !files.IsExist(DefaultFingerTemplate) {
|
||||
err = os.MkdirAll(DefaultFingerTemplate, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//if opt.FingersTemplatesPath != DefaultFingerTemplate && !files.IsExist(opt.FingersTemplatesPath) {
|
||||
// err = os.MkdirAll(opt.FingersTemplatesPath, 0755)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//} else if !files.IsExist(DefaultFingerTemplate) {
|
||||
// err = os.MkdirAll(DefaultFingerTemplate, 0755)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
if opt.FingerEngines != "all" {
|
||||
@ -121,11 +120,11 @@ func (opt *FingerOptions) UpdateFinger() error {
|
||||
}
|
||||
|
||||
func (opt *FingerOptions) downloadConfig(name string) (bool, error) {
|
||||
fingerPath, ok := FingerConfigs[name]
|
||||
fingerFile, ok := FingerConfigs[name]
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unknown engine name")
|
||||
}
|
||||
url := baseURL + fingerPath
|
||||
url := baseURL + fingerFile
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -137,14 +136,14 @@ func (opt *FingerOptions) downloadConfig(name string) (bool, error) {
|
||||
}
|
||||
|
||||
content, err := io.ReadAll(resp.Body)
|
||||
filePath := path.Join(opt.FingerPath, fingerPath)
|
||||
filePath := filepath.Join(files.GetExcPath(), opt.FingerPath, fingerFile)
|
||||
if files.IsExist(filePath) {
|
||||
origin, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if resources.CheckSum[name] != encode.Md5Hash(origin) {
|
||||
logs.Log.Importantf("update %s config from %s save to %s", name, url, fingerPath)
|
||||
logs.Log.Importantf("update %s config from %s save to %s", name, url, fingerFile)
|
||||
err = os.WriteFile(filePath, content, 0644)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -157,7 +156,7 @@ func (opt *FingerOptions) downloadConfig(name string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
defer out.Close()
|
||||
logs.Log.Importantf("download %s config from %s save to %s", name, url, fingerPath)
|
||||
logs.Log.Importantf("download %s config from %s save to %s", name, url, fingerFile)
|
||||
err = os.WriteFile(filePath, content, 0644)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -169,7 +168,7 @@ func (opt *FingerOptions) downloadConfig(name string) (bool, error) {
|
||||
|
||||
if origin, err := os.ReadFile(filePath); err == nil {
|
||||
if encode.Md5Hash(content) != encode.Md5Hash(origin) {
|
||||
logs.Log.Infof("download %s config from %s save to %s", name, url, fingerPath)
|
||||
logs.Log.Infof("download %s config from %s save to %s", name, url, fingerFile)
|
||||
err = os.WriteFile(filePath, content, 0644)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user