-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/save responses to output directory provided in new -srd flag and also print if in json if -json flag enabled fixes #128, #129, #130 #161
base: main
Are you sure you want to change the base?
Changes from 3 commits
7001edc
6a6bfb4
3ad8778
2bd3ae4
0bfbd90
34a15ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,9 @@ const ( | |
|
||
// CreateOutputFolder creates the output folder | ||
// If it fails exits with an error message. | ||
func CreateOutputFolder() { | ||
func CreateOutputFolder(outputDir string) { | ||
// Create a folder/directory at a full qualified path | ||
err := os.Mkdir("output-cariddi", Permission0755) | ||
err := os.MkdirAll(outputDir, Permission0755) | ||
if err != nil { | ||
fmt.Println("Can't create output folder.") | ||
os.Exit(1) | ||
|
@@ -56,9 +56,9 @@ func CreateOutputFolder() { | |
// CreateHostOutputFolder creates the host output folder | ||
// for the HTTP responses. | ||
// If it fails exits with an error message. | ||
func CreateHostOutputFolder(host string) { | ||
func CreateHostOutputFolder(host string, outputDir string) { | ||
// Create a folder/directory at a full qualified path | ||
err := os.MkdirAll(filepath.Join("output-cariddi", host), Permission0755) | ||
err := os.MkdirAll(filepath.Join(outputDir, host), Permission0755) | ||
if err != nil { | ||
fmt.Println("Can't create host output folder.") | ||
os.Exit(1) | ||
|
@@ -71,21 +71,21 @@ func CreateHostOutputFolder(host string) { | |
// already exists, if yes asks the user if cariddi has to overwrite it; | ||
// if no cariddi creates it. | ||
// Whenever an instruction fails, it exits with an error message. | ||
func CreateOutputFile(target string, subcommand string, format string) string { | ||
func CreateOutputFile(target string, subcommand string, format string, outputDir string) string { | ||
target = ReplaceBadCharacterOutput(target) | ||
|
||
var filename string | ||
if subcommand != "" { | ||
filename = filepath.Join("output-cariddi", target+"."+subcommand+"."+format) | ||
filename = filepath.Join(outputDir, target+"."+subcommand+"."+format) | ||
} else { | ||
filename = filepath.Join("output-cariddi", target+"."+format) | ||
filename = filepath.Join(outputDir, target+"."+format) | ||
} | ||
|
||
_, err := os.Stat(filename) | ||
|
||
if os.IsNotExist(err) { | ||
if _, err := os.Stat("output-cariddi/"); os.IsNotExist(err) { | ||
CreateOutputFolder() | ||
if _, err := os.Stat(outputDir + "/"); os.IsNotExist(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's better to use Sprintf |
||
CreateOutputFolder(outputDir) | ||
} | ||
// If the file doesn't exist, create it. | ||
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, Permission0644) | ||
|
@@ -119,15 +119,15 @@ func CreateOutputFile(target string, subcommand string, format string) string { | |
// It creates the output folder if needed, then checks if the index output file | ||
// already exists, if no cariddi creates it. | ||
// Whenever an instruction fails, it exits with an error message. | ||
func CreateIndexOutputFile(filename string) { | ||
func CreateIndexOutputFile(filename string, outputDir string) { | ||
_, err := os.Stat(filename) | ||
|
||
if os.IsNotExist(err) { | ||
if _, err := os.Stat("output-cariddi/"); os.IsNotExist(err) { | ||
CreateOutputFolder() | ||
if _, err := os.Stat(outputDir + "/"); os.IsNotExist(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sprintf |
||
CreateOutputFolder(outputDir) | ||
} | ||
// If the file doesn't exist, create it. | ||
filename = filepath.Join("output-cariddi", filename) | ||
filename = filepath.Join(outputDir, filename) | ||
|
||
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, Permission0644) | ||
if err != nil { | ||
|
@@ -161,6 +161,7 @@ func ReadFile(inputFile string) []string { | |
for scanner.Scan() { | ||
text = append(text, scanner.Text()) | ||
} | ||
|
||
file.Close() | ||
|
||
return text | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,8 @@ func GenerateRandomUserAgent() string { | |
source := rand.NewSource(time.Now().UnixNano()) | ||
rng := rand.New(source) | ||
|
||
decision := rng.Intn(100) | ||
const maxRandomValue = 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put all constants at the top of this file. Like const (
maxRandomValue = 100
) |
||
decision := rng.Intn(maxRandomValue) | ||
|
||
var ua string | ||
if decision%2 == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should perform some tests. What if config.StoreResp is not specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the two tags
-sr
and-srd
, there are four possible scenarios:Both
-sr
and-srd
are not set:OutputDir
will be set to its default value, and any other data that needs to be saved will be stored in this directory.Only
-sr
is set:OutputDir
, which will be the default directory.Only
-srd
is set:OutputDir
provided with the-srd
flag.Both
-sr
and-srd
are set:OutputDir
provided with the-srd
flag.In the config struct, I have used the
StoreResp
boolean as the key indicator of whether to store the response. Therefore, if the user provides only the-srd
flag, we will setStoreResp
totrue
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can understand point 3 and 4 are the same right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just in point 3 we will set the StoreResp value to true