Skip to content

Commit a3372ed

Browse files
authored
Merge pull request #2907 from testssl/fix_file_naming_3.2
Fix file time stamp issue
2 parents 6b7aa7a + ceb2474 commit a3372ed

1 file changed

Lines changed: 32 additions & 26 deletions

File tree

testssl.sh

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ fileout() {
14431443

14441444

14451445
json_header() {
1446+
local fname_date="$1"
14461447
local fname_prefix
14471448
local filename_provided=false
14481449

@@ -1471,9 +1472,9 @@ json_header() {
14711472
fname_prefix="${FNAME_PREFIX}${NODE}_p${PORT}"
14721473
fi
14731474
if [[ -z "$JSONFILE" ]]; then
1474-
JSONFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".json)"
1475+
JSONFILE="$fname_prefix-${fname_date}.json"
14751476
elif [[ -d "$JSONFILE" ]]; then
1476-
JSONFILE="$JSONFILE/${fname_prefix}-$(date +"%Y%m%d-%H%M".json)"
1477+
JSONFILE="$JSONFILE/${fname_prefix}-${fname_date}.json"
14771478
fi
14781479
# Silently reset APPEND var if the file doesn't exist as otherwise it won't be created
14791480
if "$APPEND" && [[ ! -s "$JSONFILE" ]]; then
@@ -1494,6 +1495,7 @@ json_header() {
14941495

14951496

14961497
csv_header() {
1498+
local fname_date="$1"
14971499
local fname_prefix
14981500
local filename_provided=false
14991501

@@ -1519,9 +1521,9 @@ csv_header() {
15191521
fname_prefix="${FNAME_PREFIX}${NODE}_p${PORT}"
15201522
fi
15211523
if [[ -z "$CSVFILE" ]]; then
1522-
CSVFILE="${fname_prefix}-$(date +"%Y%m%d-%H%M".csv)"
1524+
CSVFILE="${fname_prefix}-${fname_date}.csv"
15231525
elif [[ -d "$CSVFILE" ]]; then
1524-
CSVFILE="$CSVFILE/${fname_prefix}-$(date +"%Y%m%d-%H%M".csv)"
1526+
CSVFILE="$CSVFILE/${fname_prefix}-${fname_date}.csv"
15251527
fi
15261528
# Silently reset APPEND var if the file doesn't exist as otherwise it won't be created
15271529
if "$APPEND" && [[ ! -s "$CSVFILE" ]]; then
@@ -1548,6 +1550,7 @@ csv_header() {
15481550
################# END JSON file functions. START HTML functions ####################
15491551

15501552
html_header() {
1553+
local fname_date="$1"
15511554
local fname_prefix
15521555
local filename_provided=false
15531556

@@ -1576,9 +1579,9 @@ html_header() {
15761579
fname_prefix="${FNAME_PREFIX}${NODE}_p${PORT}"
15771580
fi
15781581
if [[ -z "$HTMLFILE" ]]; then
1579-
HTMLFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".html)"
1582+
HTMLFILE="$fname_prefix-${fname_date}.html"
15801583
elif [[ -d "$HTMLFILE" ]]; then
1581-
HTMLFILE="$HTMLFILE/$fname_prefix-$(date +"%Y%m%d-%H%M".html)"
1584+
HTMLFILE="$HTMLFILE/$fname_prefix-${fname_date}.html"
15821585
fi
15831586
# Silently reset APPEND var if the file doesn't exist as otherwise it won't be created
15841587
if "$APPEND" && [[ ! -s "$HTMLFILE" ]]; then
@@ -1626,8 +1629,9 @@ html_footer() {
16261629
################# END HTML file functions ####################
16271630

16281631
prepare_logging() {
1629-
# arg1: for testing mx records name we put a name of logfile in here, otherwise we get strange file names
1630-
local fname_prefix="$1"
1632+
local fname_date="$1"
1633+
# arg2: for testing mx records name we put a name of logfile in here, otherwise we get strange file names
1634+
local fname_prefix="$2"
16311635
local filename_provided=false
16321636

16331637
if [[ -n "$PARENT_LOGFILE" ]]; then
@@ -1644,10 +1648,10 @@ prepare_logging() {
16441648
[[ -z "$fname_prefix" ]] && fname_prefix="${FNAME_PREFIX}${NODE}_p${PORT}"
16451649

16461650
if [[ -z "$LOGFILE" ]]; then
1647-
LOGFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".log)"
1651+
LOGFILE="$fname_prefix-${fname_date}.log"
16481652
elif [[ -d "$LOGFILE" ]]; then
16491653
# actually we were instructed to place all files in a DIR instead of the current working dir
1650-
LOGFILE="$LOGFILE/$fname_prefix-$(date +"%Y%m%d-%H%M".log)"
1654+
LOGFILE="$LOGFILE/$fname_prefix-${fname_date}.log"
16511655
else
16521656
: # just for clarity: a log file was specified, no need to do anything else
16531657
fi
@@ -23119,25 +23123,26 @@ draw_line() {
2311923123

2312023124

2312123125
run_mx_all_ips() {
23126+
local fname_date="$1"
2312223127
local mxs mx
2312323128
local mxport
2312423129
local -i ret=0
2312523130
local word=""
2312623131

2312723132
STARTTLS_PROTOCOL="smtp"
2312823133
# test first higher priority servers
23129-
mxs=$(get_mx_record "$1" | sort -n | sed -e 's/^.* //' -e 's/\.$//' | tr '\n' ' ')
23134+
mxs=$(get_mx_record "$2" | sort -n | sed -e 's/^.* //' -e 's/\.$//' | tr '\n' ' ')
2313023135
if [[ $CMDLINE_IP == one ]]; then
2313123136
word="as instructed one" # with highest priority
2313223137
mxs=${mxs%% *}
2313323138
else
2313423139
word="the only"
2313523140
fi
23136-
mxport=${2:-25}
23141+
mxport=${3:-25}
2313723142
if [[ -n "$LOGFILE" ]] || [[ -n "$PARENT_LOGFILE" ]]; then
23138-
prepare_logging
23143+
prepare_logging "${fname_date}"
2313923144
else
23140-
prepare_logging "${FNAME_PREFIX}mx-$1"
23145+
prepare_logging "${fname_date}" "${FNAME_PREFIX}mx-$1"
2314123146
fi
2314223147
if [[ -n "$mxs" ]] && [[ "$mxs" != ' ' ]]; then
2314323148
[[ $(count_words "$mxs") -gt 1 ]] && MULTIPLE_CHECKS=true
@@ -25009,22 +25014,23 @@ lets_roll() {
2500925014
################# main #################
2501025015

2501125016

25012-
RET=0 # this is a global as we can have a function main(), see #705. Should we toss then all local $ret?
25013-
ip=""
25017+
RET=0 # this is a global as a function main() is problematic, see #705. Should we toss then all local $ret?
2501425018
stopwatch start
25019+
FNAME_DATE="$(date +"%Y%m%d-%H%M")" # a global var, and a definition via local doesn't work here. Omitting definition above
25020+
IP="" # see previous line, global used only here
2501525021

2501625022
lets_roll init
2501725023
initialize_globals
25018-
check_base_requirements # needs to come after $do_html is defined
25024+
check_base_requirements # needs to come after $do_html is defined
2501925025
parse_cmd_line "$@"
2502025026
# CMDLINE_PARSED has been set now. Don't put a function immediately after this which calls fatal().
2502125027
# Rather put it after csv_header below.
2502225028
# html_header() needs to be called early! Otherwise if html_out() is called before html_header() and the
2502325029
# command line contains --htmlfile <htmlfile> or --html, it'll make problems with html output, see #692.
2502425030
# json_header and csv_header could be called later but for context reasons we'll leave it here
25025-
html_header
25026-
json_header
25027-
csv_header
25031+
html_header "${FNAME_DATE}"
25032+
json_header "${FNAME_DATE}"
25033+
csv_header "${FNAME_DATE}"
2502825034
get_install_dir
2502925035
# see #705, we need to source TLS_DATA_FILE here instead of in get_install_dir(), see #705
2503025036
[[ -r "$TLS_DATA_FILE" ]] && . "$TLS_DATA_FILE"
@@ -25049,7 +25055,7 @@ lets_roll() {
2504925055
fileout_banner
2505025056

2505125057
if "$do_mass_testing"; then
25052-
prepare_logging
25058+
prepare_logging "${FNAME_DATE}"
2505325059
if [[ "$MASS_TESTING_MODE" == parallel ]]; then
2505425060
run_mass_testing_parallel
2505525061
else
@@ -25062,13 +25068,13 @@ lets_roll() {
2506225068
#TODO: there shouldn't be the need for a special case for --mx, only the ip addresses we would need upfront and the do-parser
2506325069
if "$do_mx_all_ips"; then
2506425070
#FIXME: do we need this really here?
25065-
count_do_variables # if we have just 1x "do_*" --> we do a standard run -- otherwise just the one specified
25071+
count_do_variables # if we have just 1x "do_*" --> we do a standard run -- otherwise just the one specified
2506625072
[[ $? -eq 1 ]] && set_scanning_defaults
25067-
run_mx_all_ips "${URI}" $PORT # we should reduce run_mx_all_ips to what's necessary as below we have similar code
25073+
run_mx_all_ips "${FNAME_DATE}" "${URI}" $PORT # we should reduce run_mx_all_ips to what's necessary as below we have similar code
2506825074
exit $?
2506925075
fi
2507025076

25071-
[[ -z "$NODE" ]] && parse_hn_port "${URI}" # NODE, URL_PATH, PORT, IPADDRs and IP46ADDR is set now
25077+
[[ -z "$NODE" ]] && parse_hn_port "${URI}" # NODE, URL_PATH, PORT, IPADDRs and IP46ADDR is set now
2507225078
prepare_logging
2507325079

2507425080
if [[ -n "$PROXY" ]] && $DNS_VIA_PROXY; then
@@ -25085,10 +25091,10 @@ lets_roll() {
2508525091
pr_bold "Testing all IPv4 addresses (port $PORT): "
2508625092
fi
2508725093
outln "$IPADDRs"
25088-
for ip in $IPADDRs; do
25094+
for IP in $IPADDRs; do
2508925095
draw_line "-" $((TERM_WIDTH * 2 / 3))
2509025096
outln
25091-
NODEIP="$ip"
25097+
NODEIP="$IP"
2509225098
lets_roll "${STARTTLS_PROTOCOL}"
2509325099
RET=$((RET + $?)) # RET value per IP address
2509425100
done

0 commit comments

Comments
 (0)