Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import (
"fmt"
"io/ioutil"
"io"
"os"
"reflect"
"sync"
Expand All @@ -29,7 +29,7 @@ func LoadConfiguration(path string) (*Configuration, error) {
return configuration, fmt.Errorf("loading configuration: file opening: %s", err)
}

bytes, _ := ioutil.ReadAll(file)
bytes, _ := io.ReadAll(file)

var cc map[interface{}]interface{}

Expand Down
7 changes: 4 additions & 3 deletions core/rule_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package core

import (
"fmt"
"github.com/evilsocket/islazy/log"
"io/ioutil"
"os"
"path/filepath"
"regexp"

"github.com/evilsocket/islazy/log"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
)
Expand Down Expand Up @@ -126,7 +127,7 @@ func (p *Parser) parseFile(filename string, deps []string) (*AST, error) {

ast := &AST{}
log.Debug("parsing %s", filename)
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("parsing '%s': %s", filename, err)
}
Expand Down
3 changes: 1 addition & 2 deletions feeders/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -136,7 +135,7 @@ func (f *Web) prepareRequest() (*http.Request, error) {
}

func (f *Web) getBodyAsString(r *http.Response) string {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return ""
}
Expand Down
5 changes: 2 additions & 3 deletions filters/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package filters

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestBase_Log(t *testing.T) {
expected := fmt.Sprintf("[%s::%s] this is %s\n", b.rule, b.name, b.name)

b.Log(msg)
dat, _ := ioutil.ReadFile(logfile)
dat, _ := os.ReadFile(logfile)
if string(dat) != expected {
t.Errorf("wrong error: expected=%#v had=%#v", expected, string(dat))
}
Expand Down Expand Up @@ -155,7 +154,7 @@ func TestBase_Pipe(t *testing.T) {
cbFilter: v.Callback,
}
b.Pipe(v.ExpectedMessage)
dat, _ := ioutil.ReadFile(logfile)
dat, _ := os.ReadFile(logfile)
if string(dat) != v.ExpectedLog {
t.Errorf("%s : wrong error: expected=%#v had=%#v", v.Name, v.ExpectedLog, string(dat))
}
Expand Down
3 changes: 1 addition & 2 deletions filters/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package filters

import (
"io/ioutil"
"os"

"github.com/Matrix86/driplane/data"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (f *File) DoFilter(msg *data.Message) (bool, error) {
// if the path exists and it's a file
if stat, err := os.Stat(path); err == nil && !stat.IsDir() {
log.Debug("path='%s' size=%d extra=%v", path, stat.Size(), msg.GetExtra())
readData, err := ioutil.ReadFile(path)
readData, err := os.ReadFile(path)
if err != nil {
return true, err
}
Expand Down
4 changes: 2 additions & 2 deletions filters/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package filters
import (
"fmt"
html "html/template"
"io/ioutil"
"os"
"path/filepath"
text "text/template"

Expand Down Expand Up @@ -66,7 +66,7 @@ func NewFormatFilter(p map[string]string) (Filter, error) {
} else {
fpath = filepath.Join(v, fpath)
}
content, err := ioutil.ReadFile(fpath)
content, err := os.ReadFile(fpath)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions filters/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

//"net/http/httputil"
"net/url"
"strconv"
Expand Down Expand Up @@ -222,15 +222,15 @@ func (f *HTTP) DoFilter(msg *data.Message) (bool, error) {
}

func (f *HTTP) readBody(r *http.Response) interface{} {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return ""
}
return body
}

// OnEvent is called when an event occurs
func (f *HTTP) OnEvent(event *data.Event){}
func (f *HTTP) OnEvent(event *data.Event) {}

// Set the name of the filter
func init() {
Expand Down
5 changes: 2 additions & 3 deletions plugins/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugins
import (
"fmt"
"io"
"io/ioutil"
"os"
)

Expand All @@ -26,7 +25,7 @@ type FileResponse struct {
func (c *FilePackage) Read(fileName string) FileResponse {
resp := FileResponse{}

resp.Binary, resp.Error = ioutil.ReadFile(fileName)
resp.Binary, resp.Error = os.ReadFile(fileName)
resp.Status = resp.Error == nil
resp.String = string(resp.Binary)

Expand All @@ -36,7 +35,7 @@ func (c *FilePackage) Read(fileName string) FileResponse {
func (c *FilePackage) Write(fileName string, data []byte) FileResponse {
resp := FileResponse{}

resp.Error = ioutil.WriteFile(fileName, data, os.ModePerm)
resp.Error = os.WriteFile(fileName, data, os.ModePerm)
resp.Status = resp.Error == nil

return resp
Expand Down
3 changes: 1 addition & 2 deletions plugins/file_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package plugins

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -274,7 +273,7 @@ func TestFilePackage_AppendString(t *testing.T) {
t.Errorf("%s: wrong result: expected=%#v had=%#v", v.Name, v.ExpectedError, had.Error.Error())
}
if v.ExpectedStatus {
content, err := ioutil.ReadFile(v.Filename)
content, err := os.ReadFile(v.Filename)
if err != nil {
t.Errorf("%s: cannot read the file '%s'", v.Name, v.Filename)
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -88,7 +87,7 @@ func (c *HTTPPackage) Request(method string, uri string, headers interface{}, da
}
defer resp.Body.Close()

raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
return HTTPResponse{Error: err, Status: false}
}
Expand Down Expand Up @@ -202,7 +201,7 @@ func (c *HTTPPackage) UploadFile(filename string, fieldname string, method strin
}
defer resp.Body.Close()

raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
return HTTPResponse{Error: err, Status: false}
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -124,7 +123,7 @@ func TestHTTPPackage_DownloadFile(t *testing.T) {
t.Errorf("%s: wrong error: expected=%#v had=%#v", v.Name, res.Error, v.ExpectedResponse.Error)
}
if v.ExpectedResponse.Status {
dat, _ := ioutil.ReadFile(v.Filepath)
dat, _ := os.ReadFile(v.Filepath)
if string(dat) != msg {
t.Errorf("%s : wrong file content: expected=%#v had=%#v", v.Name, msg, string(dat))
}
Expand Down Expand Up @@ -184,7 +183,7 @@ func TestHTTPPackage_UploadFile(t *testing.T) {
t.Errorf("%s: wrong error: expected=%#v had=%#v", v.Name, v.ExpectedResponse.Error, res.Error)
}
if v.ExpectedResponse.Status {
dat, _ := ioutil.ReadFile(v.Filepath)
dat, _ := os.ReadFile(v.Filepath)
if string(dat) != msg {
t.Errorf("%s : wrong file content: expected=%#v had=%#v", v.Name, msg, string(dat))
}
Expand Down
10 changes: 4 additions & 6 deletions plugins/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package plugins

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -25,7 +24,7 @@ func TestLogPackage_Debug(t *testing.T) {
expected := fmt.Sprintf("%s\n", message)
l.Debug("%s", message)

dat, _ := ioutil.ReadFile(logfile)
dat, _ := os.ReadFile(logfile)
if string(dat) != expected {
t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat))
}
Expand All @@ -45,13 +44,12 @@ func TestLogPackage_Info(t *testing.T) {
expected := fmt.Sprintf("%s\n", message)
l.Info("%s", message)

dat, _ := ioutil.ReadFile(logfile)
dat, _ := os.ReadFile(logfile)
if string(dat) != expected {
t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat))
}
}


func TestLogPackage_Error(t *testing.T) {
l := GetLog()

Expand All @@ -67,8 +65,8 @@ func TestLogPackage_Error(t *testing.T) {
expected := fmt.Sprintf("%s\n", message)
l.Error("%s", message)

dat, _ := ioutil.ReadFile(logfile)
dat, _ := os.ReadFile(logfile)
if string(dat) != expected {
t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat))
}
}
}
20 changes: 10 additions & 10 deletions utils/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -33,7 +33,7 @@ func ParseCookieFile(filename string) ([]*http.Cookie, error) {
}
defer jsonFile.Close()

byteValue, _ := ioutil.ReadAll(jsonFile)
byteValue, _ := io.ReadAll(jsonFile)
err = json.Unmarshal(byteValue, &cookies)
if err != nil {
return nil, err
Expand All @@ -45,15 +45,15 @@ func ParseCookieFile(filename string) ([]*http.Cookie, error) {
nsecs := int64((c.ExpirationDate - float64(secs)) * 1e9)

httpCookies[i] = &http.Cookie{
Name: c.Name,
Value: c.Value,
Path: c.Path,
Domain: c.Domain,
Expires: time.Unix(secs, nsecs),
Secure: c.Secure,
HttpOnly: c.HTTPOnly,
Name: c.Name,
Value: c.Value,
Path: c.Path,
Domain: c.Domain,
Expires: time.Unix(secs, nsecs),
Secure: c.Secure,
HttpOnly: c.HTTPOnly,
}
}

return httpCookies, nil
}
}
3 changes: 1 addition & 2 deletions utils/misc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -18,7 +17,7 @@ func TestIsFlagPassed(t *testing.T) {
}

func TestFileExists(t *testing.T) {
file, err := ioutil.TempFile(os.TempDir(), "prefix")
file, err := os.CreateTemp(os.TempDir(), "prefix")
if err != nil {
t.Errorf("cannot create a temporary file")
}
Expand Down
Loading