Skip to content

Commit

Permalink
fixed syntax based on shellcheck
Browse files Browse the repository at this point in the history
Fixed issues reported by shellcheck
(https://github.com/koalaman/shellcheck/wiki) to improve security and
POSIX shell interoperability.

(part of #27)

Signed-off-by: Andreas Ulm <[email protected]>
  • Loading branch information
root360-AndreasUlm committed Nov 25, 2019
1 parent 20e3b59 commit 4a40270
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh

current_time=$(date "+%Y.%m.%d-%H.%M")
if [[ -z $upload ]]
upload="${upload:-}"
current_time="$(date "+%Y.%m.%d-%H.%M")"
if [ -z "$upload" ]
then
root_dir=/shared/
else
Expand All @@ -10,38 +11,42 @@ else
mkdir /reports
fi

xml_dir=xml_files/$current_time
report_file=reports/report_$current_time.tex
xml_dir="xml_files/$current_time"
report_file="reports/report_$current_time.tex"
report_file_path="${root_dir}${report_file}"

function upload {
if [[ -z $upload ]]
upload() {
if [ -z "$upload" ]
then
return
elif [ $upload = "aws" ]
fi
if [ "$upload" = "aws" ]
then
python /aws_push.py $1
elif [ $upload = "gcp" ]
python /aws_push.py "$1"
elif [ "$upload" = "gcp" ]
then
python /gcp_push.py $1
python /gcp_push.py "$1"
fi
}

function get_filename(){
echo $1 | tr / -
get_filename() {
echo "$1" | tr / -
}

mkdir $root_dir$xml_dir
mkdir -p "$root_dir$xml_dir"
while IFS= read -r line
do
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
filename=$(get_filename $line)".xml"
nmap -sV -oX $root_dir$xml_dir/$filename -oN - -v1 $@ --script=vulners/vulners.nse $line
upload $xml_dir/$filename
current_time="$(date "+%Y.%m.%d-%H.%M.%S")"
filename="$(get_filename "$line").xml"
# $@ without quotes required to expand additional options
# shellcheck disable=SC2068
nmap -sV -oX "$root_dir$xml_dir/$filename" -oN - -v1 $@ --script=vulners/vulners.nse "$line"
upload "$xml_dir/$filename"
done < /shared/ips.txt

python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt
sed -i 's/_/\\_/g' $root_dir$report_file
sed -i 's/\$/\\\$/g' $root_dir$report_file
sed -i 's/#/\\#/g' $root_dir$report_file
sed -i 's/%/\\%/g' $root_dir$report_file
upload $report_file
python /output_report.py "$root_dir$xml_dir" "$report_file_path" /shared/ips.txt
sed -i 's/_/\\_/g' "$report_file_path"
sed -i 's/\$/\\\$/g' "$report_file_path"
sed -i 's/#/\\#/g' "$report_file_path"
sed -i 's/%/\\%/g' "$report_file_path"
upload "$report_file"

0 comments on commit 4a40270

Please sign in to comment.