mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
new: caplets will now include the list of sub scripts and files in api.rest
This commit is contained in:
parent
fe568c8188
commit
bf8a7659b5
2 changed files with 41 additions and 9 deletions
|
@ -8,22 +8,34 @@ import (
|
||||||
"github.com/evilsocket/islazy/fs"
|
"github.com/evilsocket/islazy/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Caplet struct {
|
type Script struct {
|
||||||
Name string `json:"name"`
|
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Code []string `json:"code"`
|
Code []string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCaplet(name string, path string, size int64) Caplet {
|
func newScript(path string, size int64) Script {
|
||||||
return Caplet{
|
return Script{
|
||||||
Name: name,
|
|
||||||
Path: path,
|
Path: path,
|
||||||
Size: size,
|
Size: size,
|
||||||
Code: make([]string, 0),
|
Code: make([]string, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Caplet struct {
|
||||||
|
Script
|
||||||
|
Name string `json:"name"`
|
||||||
|
Scripts []Script `json:"scripts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCaplet(name string, path string, size int64) Caplet {
|
||||||
|
return Caplet{
|
||||||
|
Script: newScript(path, size),
|
||||||
|
Name: name,
|
||||||
|
Scripts: make([]Script, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (cap *Caplet) Eval(argv []string, lineCb func(line string) error) error {
|
func (cap *Caplet) Eval(argv []string, lineCb func(line string) error) error {
|
||||||
if argv == nil {
|
if argv == nil {
|
||||||
argv = []string{}
|
argv = []string{}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package caplets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -68,10 +69,9 @@ func Load(name string) (error, *Caplet) {
|
||||||
for _, fileName := range names {
|
for _, fileName := range names {
|
||||||
if stats, err := os.Stat(fileName); err == nil {
|
if stats, err := os.Stat(fileName); err == nil {
|
||||||
cap := &Caplet{
|
cap := &Caplet{
|
||||||
Name: baseName,
|
Script: newScript(fileName, stats.Size()),
|
||||||
Path: fileName,
|
Name: baseName,
|
||||||
Code: make([]string, 0),
|
Scripts: make([]Script, 0),
|
||||||
Size: stats.Size(),
|
|
||||||
}
|
}
|
||||||
cache[name] = cap
|
cache[name] = cap
|
||||||
|
|
||||||
|
@ -84,6 +84,26 @@ func Load(name string) (error, *Caplet) {
|
||||||
}
|
}
|
||||||
cap.Code = append(cap.Code, line)
|
cap.Code = append(cap.Code, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the caplet has a dedicated folder
|
||||||
|
if strings.Contains(baseName, "/") || strings.Contains(baseName, "\\") {
|
||||||
|
dir := filepath.Dir(fileName)
|
||||||
|
// get all secondary .cap and .js files
|
||||||
|
if files, err := ioutil.ReadDir(dir); err == nil && len(files) > 0 {
|
||||||
|
for _, f := range files {
|
||||||
|
subFileName := filepath.Join(dir, f.Name())
|
||||||
|
if subFileName != fileName && (strings.HasSuffix(subFileName, ".cap") || strings.HasSuffix(subFileName, ".js")) {
|
||||||
|
if reader, err := fs.LineReader(subFileName); err == nil {
|
||||||
|
script := newScript(subFileName, f.Size())
|
||||||
|
for line := range reader {
|
||||||
|
script.Code = append(script.Code, line)
|
||||||
|
}
|
||||||
|
cap.Scripts = append(cap.Scripts, script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, cap
|
return nil, cap
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue