mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
fix: correct lookup of caplet files from multiple default paths
This commit is contained in:
parent
924387faf2
commit
da5cbea7b1
1 changed files with 28 additions and 8 deletions
|
@ -504,10 +504,33 @@ func (s *Session) ReadLine() (string, error) {
|
||||||
return s.Input.Readline()
|
return s.Input.Readline()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) RunCaplet(filename string) error {
|
func (s *Session) getCapletFilePath(caplet string) string {
|
||||||
s.Events.Log(core.INFO, "Reading from caplet %s ...", filename)
|
if core.Exists(caplet) {
|
||||||
|
return caplet
|
||||||
|
}
|
||||||
|
|
||||||
input, err := os.Open(filename)
|
for _, path := range CapPaths {
|
||||||
|
filename := filepath.Join(path, caplet)
|
||||||
|
if !strings.HasSuffix(filename, ".cap") {
|
||||||
|
filename += ".cap"
|
||||||
|
}
|
||||||
|
if core.Exists(filename) {
|
||||||
|
return filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Session) RunCaplet(filename string) error {
|
||||||
|
var caplet string
|
||||||
|
if caplet = s.getCapletFilePath(filename); caplet == "" {
|
||||||
|
return fmt.Errorf("could not load caplet from %s", filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Events.Log(core.INFO, "Reading from caplet %s ...", caplet)
|
||||||
|
|
||||||
|
input, err := os.Open(caplet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -543,11 +566,8 @@ func (s *Session) isCapletCommand(line string) (is bool, filename string, argv [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range CapPaths {
|
if filename := s.getCapletFilePath(file); filename != "" {
|
||||||
filename := filepath.Join(path, file) + ".cap"
|
return true, filename, argv
|
||||||
if core.Exists(filename) {
|
|
||||||
return true, filename, argv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, "", nil
|
return false, "", nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue