| 1 | package capletsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 5 | "io/ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/" |
| 6 | "osscip-go gomod github.com/golang/go/src go1.16 os/" |
| 7 | "path/filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/" |
| 8 | "sortscip-go gomod github.com/golang/go/src go1.16 sort/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 10 | "syncscip-go gomod github.com/golang/go/src go1.16 sync/" |
| 11 | |
| 12 | "github.com/evilsocket/islazy/fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/" |
| 13 | ) |
| 14 | |
| 15 | var ( |
| 16 | cachescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cache. = make(map[string]*Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#) |
| 17 | cacheLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cacheLock. = syncscip-go gomod github.com/golang/go/src go1.16 sync/.Mutexscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#{} |
| 18 | ) |
| 19 | |
| 20 | func Listscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/List().() []*Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet# { |
| 21 | caplets := make([]*Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#, 0) |
| 22 | for _, searchPath := range LoadPathsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/LoadPaths. { |
| 23 | files, _ := filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Globscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Glob().(searchPath + "/*" + Suffixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Suffix.) |
| 24 | files2, _ := filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Globscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Glob().(searchPath + "/*/*" + Suffixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Suffix.) |
| 25 | |
| 26 | for _, fileName := range append(files, files2...) { |
| 27 | if _, err := osscip-go gomod github.com/golang/go/src go1.16 os/.Statscip-go gomod github.com/golang/go/src go1.16 os/Stat().(fileName); err == nil { |
| 28 | base := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(fileName, searchPath+string(osscip-go gomod github.com/golang/go/src go1.16 os/.PathSeparatorscip-go gomod github.com/golang/go/src go1.16 os/PathSeparator.), "", -1) |
| 29 | base = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(base, Suffixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Suffix., "", -1) |
| 30 | |
| 31 | if caplet, err := Loadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Load().(base); err != nil { |
| 32 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.16 os/.Stderrscip-go gomod github.com/golang/go/src go1.16 os/Stderr., "wtf: %v\n", err) |
| 33 | } else { |
| 34 | caplets = append(caplets, caplet) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | sortscip-go gomod github.com/golang/go/src go1.16 sort/.Slicescip-go gomod github.com/golang/go/src go1.16 sort/Slice().(caplets, func(i, j int) bool { |
| 41 | return stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Comparescip-go gomod github.com/golang/go/src go1.16 strings/Compare().(caplets[i].Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Name., caplets[j].Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Name.) == -1 |
| 42 | }) |
| 43 | |
| 44 | return caplets |
| 45 | } |
| 46 | |
| 47 | func Loadscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Load().(name string) (*Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#, error) { |
| 48 | cacheLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cacheLock..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 49 | defer cacheLockscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cacheLock..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 50 | |
| 51 | if caplet, found := cachescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cache.[name]; found { |
| 52 | return caplet, nil |
| 53 | } |
| 54 | |
| 55 | baseName := name |
| 56 | names := []string{} |
| 57 | if !stringsscip-go gomod github.com/golang/go/src go1.16 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.16 strings/HasSuffix().(name, Suffixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Suffix.) { |
| 58 | name += Suffixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Suffix. |
| 59 | } |
| 60 | |
| 61 | if !filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/IsAbs().(name) { |
| 62 | for _, path := range LoadPathsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/LoadPaths. { |
| 63 | names = append(names, filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Join().(path, name)) |
| 64 | } |
| 65 | } else { |
| 66 | names = append(names, name) |
| 67 | } |
| 68 | |
| 69 | for _, fileName := range names { |
| 70 | if stats, err := osscip-go gomod github.com/golang/go/src go1.16 os/.Statscip-go gomod github.com/golang/go/src go1.16 os/Stat().(fileName); err == nil { |
| 71 | cap := &Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#{ |
| 72 | Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Script.: newScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/newScript().(fileName, stats.Sizescip-go gomod github.com/golang/go/src go1.16 `io/fs`/FileInfo#Size().()), |
| 73 | Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Name.: baseName, |
| 74 | Scriptsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Scripts.: make([]Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#, 0), |
| 75 | } |
| 76 | cachescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/cache.[name] = cap |
| 77 | |
| 78 | if reader, err := fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/.LineReaderscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/LineReader().(fileName); err != nil { |
| 79 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("error reading caplet %s: %v", fileName, err) |
| 80 | } else { |
| 81 | for line := range reader { |
| 82 | cap.Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code. = append(cap.Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code., line) |
| 83 | } |
| 84 | |
| 85 | // the caplet has a dedicated folder |
| 86 | if stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Containsscip-go gomod github.com/golang/go/src go1.16 strings/Contains().(baseName, "/") || stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Containsscip-go gomod github.com/golang/go/src go1.16 strings/Contains().(baseName, "\\") { |
| 87 | dir := filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Dir().(fileName) |
| 88 | // get all secondary .cap and .js files |
| 89 | if files, err := ioutilscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/.ReadDirscip-go gomod github.com/golang/go/src go1.16 `io/ioutil`/ReadDir().(dir); err == nil && len(files) > 0 { |
| 90 | for _, f := range files { |
| 91 | subFileName := filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Join().(dir, f.Namescip-go gomod github.com/golang/go/src go1.16 `io/fs`/FileInfo#Name().()) |
| 92 | if subFileName != fileName && (stringsscip-go gomod github.com/golang/go/src go1.16 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.16 strings/HasSuffix().(subFileName, ".cap") || stringsscip-go gomod github.com/golang/go/src go1.16 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.16 strings/HasSuffix().(subFileName, ".js")) { |
| 93 | if reader, err := fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/.LineReaderscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/LineReader().(subFileName); err == nil { |
| 94 | script := newScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/newScript().(subFileName, f.Sizescip-go gomod github.com/golang/go/src go1.16 `io/fs`/FileInfo#Size().()) |
| 95 | for line := range reader { |
| 96 | script.Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code. = append(script.Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code., line) |
| 97 | } |
| 98 | cap.Scriptsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Scripts. = append(cap.Scriptsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Scripts., script) |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return cap, nil |
| 107 | } |
| 108 | } |
| 109 | return nil, fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("caplet %s not found", name) |
| 110 | } |