Skip to content

Commit d070445

Browse files
committed
refact: refactored to use islazy and updated deps
1 parent a2b3ee7 commit d070445

File tree

238 files changed

+12661
-1585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+12661
-1585
lines changed

Gopkg.lock

+46-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@
7777
name = "github.com/malfunkt/iprange"
7878
version = "0.9.0"
7979

80-
[[constraint]]
81-
name = "github.com/mattn/go-isatty"
82-
version = "0.0.3"
83-
8480
[[constraint]]
8581
branch = "master"
8682
name = "github.com/mdlayher/dhcp6"

caplets/env.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"path/filepath"
66

7-
"github.com/bettercap/bettercap/core"
7+
"github.com/evilsocket/islazy/str"
88
)
99

1010
const (
@@ -26,8 +26,8 @@ var (
2626
)
2727

2828
func init() {
29-
for _, path := range core.SepSplit(core.Trim(os.Getenv(EnvVarName)), ":") {
30-
if path = core.Trim(path); len(path) > 0 {
29+
for _, path := range str.SplitBy(str.Trim(os.Getenv(EnvVarName)), ":") {
30+
if path = str.Trim(path); len(path) > 0 {
3131
LoadPaths = append(LoadPaths, path)
3232
}
3333
}

caplets/manager.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"strings"
1010
"sync"
1111

12-
"github.com/bettercap/bettercap/core"
12+
"github.com/evilsocket/islazy/fs"
13+
"github.com/evilsocket/islazy/str"
1314
)
1415

1516
var (
@@ -62,7 +63,7 @@ func Load(name string) (error, *Caplet) {
6263
}
6364

6465
for _, filename := range names {
65-
if core.Exists(filename) {
66+
if fs.Exists(filename) {
6667
cap := &Caplet{
6768
Path: filename,
6869
Code: make([]string, 0),
@@ -77,7 +78,7 @@ func Load(name string) (error, *Caplet) {
7778
scanner := bufio.NewScanner(input)
7879
scanner.Split(bufio.ScanLines)
7980
for scanner.Scan() {
80-
line := core.Trim(scanner.Text())
81+
line := str.Trim(scanner.Text())
8182
if line == "" || line[0] == '#' {
8283
continue
8384
}

core/core.go

+2-103
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
package core
22

33
import (
4-
"archive/zip"
54
"fmt"
6-
"io"
7-
"os"
85
"os/exec"
9-
"os/user"
10-
"path/filepath"
116
"sort"
12-
"strings"
13-
)
147

15-
const (
16-
defaultTrimSet = "\r\n\t "
8+
"github.com/evilsocket/islazy/str"
179
)
1810

19-
func Trim(s string) string {
20-
return strings.Trim(s, defaultTrimSet)
21-
}
22-
23-
func TrimRight(s string) string {
24-
return strings.TrimRight(s, defaultTrimSet)
25-
}
26-
2711
func UniqueInts(a []int, sorted bool) []int {
2812
tmp := make(map[int]bool)
2913
uniq := make([]int, 0)
@@ -43,22 +27,6 @@ func UniqueInts(a []int, sorted bool) []int {
4327
return uniq
4428
}
4529

46-
func SepSplit(sv string, sep string) []string {
47-
filtered := make([]string, 0)
48-
for _, part := range strings.Split(sv, sep) {
49-
part = Trim(part)
50-
if part != "" {
51-
filtered = append(filtered, part)
52-
}
53-
}
54-
return filtered
55-
56-
}
57-
58-
func CommaSplit(csv string) []string {
59-
return SepSplit(csv, ",")
60-
}
61-
6230
func ExecSilent(executable string, args []string) (string, error) {
6331
path, err := exec.LookPath(executable)
6432
if err != nil {
@@ -69,7 +37,7 @@ func ExecSilent(executable string, args []string) (string, error) {
6937
if err != nil {
7038
return "", err
7139
} else {
72-
return Trim(string(raw)), nil
40+
return str.Trim(string(raw)), nil
7341
}
7442
}
7543

@@ -80,72 +48,3 @@ func Exec(executable string, args []string) (string, error) {
8048
}
8149
return out, err
8250
}
83-
84-
func Exists(path string) bool {
85-
if _, err := os.Stat(path); os.IsNotExist(err) {
86-
return false
87-
}
88-
return true
89-
}
90-
91-
func ExpandPath(path string) (string, error) {
92-
// Check if path is empty
93-
if path != "" {
94-
if strings.HasPrefix(path, "~") {
95-
usr, err := user.Current()
96-
if err != nil {
97-
return "", err
98-
} else {
99-
// Replace only the first occurrence of ~
100-
path = strings.Replace(path, "~", usr.HomeDir, 1)
101-
}
102-
}
103-
return filepath.Abs(path)
104-
}
105-
return "", nil
106-
}
107-
108-
// Unzip will decompress a zip archive, moving all files and folders
109-
// within the zip file (parameter 1) to an output directory (parameter 2).
110-
// Credits to https://golangcode.com/unzip-files-in-go/
111-
func Unzip(src string, dest string) ([]string, error) {
112-
var filenames []string
113-
114-
r, err := zip.OpenReader(src)
115-
if err != nil {
116-
return filenames, err
117-
}
118-
defer r.Close()
119-
120-
for _, f := range r.File {
121-
rc, err := f.Open()
122-
if err != nil {
123-
return filenames, err
124-
}
125-
defer rc.Close()
126-
127-
// Store filename/path for returning and using later on
128-
fpath := filepath.Join(dest, f.Name)
129-
130-
// Check for ZipSlip. More Info: https://snyk.io/research/zip-slip-vulnerability#go
131-
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
132-
return filenames, fmt.Errorf("%s: illegal file path", fpath)
133-
}
134-
135-
filenames = append(filenames, fpath)
136-
if f.FileInfo().IsDir() {
137-
os.MkdirAll(fpath, os.ModePerm)
138-
} else if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
139-
return filenames, err
140-
} else if outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()); err != nil {
141-
return filenames, err
142-
} else {
143-
defer outFile.Close()
144-
if _, err = io.Copy(outFile, rc); err != nil {
145-
return filenames, err
146-
}
147-
}
148-
}
149-
150-
return filenames, nil
151-
}

0 commit comments

Comments
 (0)