Release v4.6.3

This commit is contained in:
j3ssie
2023-12-04 21:23:54 +07:00
parent 8daa48e19b
commit 0feb6b842e
3 changed files with 64 additions and 20 deletions
+1
View File
@@ -16,6 +16,7 @@ const (
CleanFFUFJson = "CleanFFUFJson"
GenNucleiReport = "GenNucleiReport"
PrintCSV = "PrintCSV"
BeautifyCSV = "BeautifyCSV"
)
const (
+9
View File
@@ -137,6 +137,15 @@ func (r *Runner) LoadScripts() string {
return result
})
vm.Set(BeautifyCSV, func(call otto.FunctionCall) otto.Value {
filename := call.Argument(0).String()
dest := call.Argument(1).String()
utils.InforF("Writing beautify CSV content to: %v", color.HiCyanString(dest))
execution.BeautifyCSV(filename, dest)
result, _ := vm.ToValue(true)
return result
})
// ExecCmdB execute in the background
vm.Set(ExecCmdB, func(call otto.FunctionCall) otto.Value {
cmd := call.Argument(0).String()
+54 -20
View File
@@ -1,7 +1,9 @@
package execution
import (
"bytes"
"encoding/csv"
"fmt"
"os"
"github.com/j3ssie/osmedeus/utils"
@@ -9,27 +11,8 @@ import (
)
func PrintCSV(filename string) {
filename = utils.NormalizePath(filename)
if !utils.FileExists(filename) {
utils.ErrorF("File %v not found", filename)
return
}
// Open the CSV file
file, err := os.Open(filename)
records, err := readCSV(filename)
if err != nil {
utils.ErrorF("%v", err)
return
}
defer file.Close()
// Create a new CSV reader
reader := csv.NewReader(file)
reader.LazyQuotes = true
// Read all CSV records
records, err := reader.ReadAll()
if err != nil {
utils.ErrorF("%v", err)
return
}
@@ -45,3 +28,54 @@ func PrintCSV(filename string) {
table.SetAutoWrapText(true)
table.Render()
}
func BeautifyCSV(filename string, dest string) {
records, err := readCSV(filename)
if err != nil {
return
}
// Create a new table
var buf bytes.Buffer
table := tablewriter.NewWriter(&buf)
for _, record := range records {
table.Append(record)
}
table.SetRowLine(false)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetColWidth(100)
table.SetHeaderLine(true)
table.SetAutoWrapText(true)
table.Render()
tableOutput := buf.String()
// write to file
utils.WriteToFile(dest, tableOutput)
}
func readCSV(filename string) ([][]string, error) {
filename = utils.NormalizePath(filename)
if !utils.FileExists(filename) {
utils.ErrorF("File %v not found", filename)
return nil, fmt.Errorf("File %v not found", filename)
}
// Open the CSV file
file, err := os.Open(filename)
if err != nil {
utils.ErrorF("%v", err)
return nil, err
}
defer file.Close()
// Create a new CSV reader
reader := csv.NewReader(file)
reader.LazyQuotes = true
// Read all CSV records
records, err := reader.ReadAll()
if err != nil {
utils.ErrorF("%v", err)
return nil, err
}
return records, nil
}