Skip to content

Commit

Permalink
Standardise sourcing conntrac library and improve "Time" variables
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Feb 8, 2022
1 parent 1b77ed7 commit b7163f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
32 changes: 11 additions & 21 deletions easytls-client-connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ connection_allowed ()
# Update conntrac
update_conntrac ()
{
# Source tctip lib
# Source conntrac lib
lib_file="${EASYTLS_WORK_DIR}/easytls-conntrac.lib"
[ -f "${lib_file}" ] || \
lib_file="${EASYTLS_WORK_DIR}/dev/easytls-conntrac.lib"
Expand All @@ -451,24 +451,10 @@ update_conntrac ()
die "Missing file: ${lib_file}" 77
fi

prog_dir="${0%/*}"
lib_file="${prog_dir}/easytls-conntrac.lib"
[ -f "${lib_file}" ] || {
easytls_url="https://github.com/TinCanTech/easy-tls"
easytls_wiki="/wiki/download-and-install"
#easytls_rawurl="https://raw.githubusercontent.com/TinCanTech/easy-tls"
#easytls_file="/master/easytls-conntrac.lib"
help_note="See: ${easytls_url}${easytls_wiki}"
die "Missing ${lib_file}" 159
}
# shellcheck source=./easytls-conntrac.lib
. "${lib_file}"
unset -v prog_dir lib_file

# Absolute start time
easytls_start_d_file="${EASYTLS_CONN_TRAC}-start-d"
if [ ! -f "${easytls_start_d_file}" ]; then
# shellcheck disable=SC2154
# shellcheck disable=SC2154 # daemon_start_time
"${EASYTLS_PRINTF}" '%s' \
"${daemon_start_time}" > "${easytls_start_d_file}"
fi
Expand Down Expand Up @@ -506,7 +492,9 @@ update_conntrac ()
[ -z "${peer_id}" ] || conntrac_record="${conntrac_record}==${peer_id}"

# shellcheck disable=SC2154
conntrac_record="${conntrac_record}==${time_ascii}"
timestamp="${local_date_ascii}=${local_time_ascii}"

conntrac_record="${conntrac_record}==${timestamp}"
# shellcheck disable=SC2154
conntrac_record="${conntrac_record}++${untrusted_ip}:${untrusted_port}"

Expand Down Expand Up @@ -542,7 +530,7 @@ update_conntrac ()
{
[ -f "${EASYTLS_CONN_TRAC}.fail" ] && \
"${EASYTLS_CAT}" "${EASYTLS_CONN_TRAC}.fail"
"${EASYTLS_PRINTF}" '%s ' "$("${EASYTLS_DATE}" '+%x %X')"
"${EASYTLS_PRINTF}" '%s ' "${timestamp}"
[ $conntrac_fail ] && "${EASYTLS_PRINTF}" '%s ' "Pre-Reg"
[ $conntrac_error ] && "${EASYTLS_PRINTF}" '%s ' "ERROR"
[ $ip_pool_exhausted ] && "${EASYTLS_PRINTF}" '%s ' "IP-POOL"
Expand Down Expand Up @@ -887,9 +875,11 @@ deps ()
LOCK_TIMEOUT="${LOCK_TIMEOUT:-30}"

# Need the date/time ..
full_date="$("${EASYTLS_DATE}" '+%s %Y/%m/%d-%H:%M:%S')"
local_date_ascii="${full_date##* }"
#local_date_sec="${full_date%% *}"
#full_date="$("${EASYTLS_DATE}" '+%s %Y/%m/%d-%H:%M:%S')"
# shellcheck disable=SC2154
full_date="${time_ascii}"
local_date_ascii="${full_date% *}"
local_time_ascii="${full_date#* }"

# Windows log
EASYTLS_WLOG="${temp_stub}-client-connect.log"
Expand Down
39 changes: 19 additions & 20 deletions easytls-client-disconnect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,17 @@ disconnect_accepted ()
# Update conntrac
update_conntrac ()
{
# Source conn-trac lib
prog_dir="${0%/*}"
lib_file="${prog_dir}/easytls-conntrac.lib"
[ -f "${lib_file}" ] || {
easytls_url="https://github.com/TinCanTech/easy-tls"
easytls_wiki="/wiki/download-and-install"
#easytls_rawurl="https://raw.githubusercontent.com/TinCanTech/easy-tls"
#easytls_file="/master/easytls-conntrac.lib"
help_note="See: ${easytls_url}${easytls_wiki}"
die "Missing ${lib_file}" 159
}
# Source conntrac lib
lib_file="${EASYTLS_WORK_DIR}/easytls-conntrac.lib"
[ -f "${lib_file}" ] || \
lib_file="${EASYTLS_WORK_DIR}/dev/easytls-conntrac.lib"
# shellcheck source=./easytls-conntrac.lib
. "${lib_file}"
unset -v lib_file
if [ -f "${lib_file}" ]; then
. "${lib_file}" || die "Source failed: ${lib_file}" 77
unset lib_file
else
die "Missing file: ${lib_file}" 77
fi

# Update connection tracking
conntrac_record="${UV_TLSKEY_SERIAL:-TLSAC}"
Expand Down Expand Up @@ -231,10 +228,10 @@ update_conntrac ()
conntrac_alt2_rec="${conntrac_alt2_rec}==${peer_id}"
fi

# shellcheck disable=SC2154
conntrac_record="${conntrac_record}==${time_ascii}"
conntrac_alt_rec="${conntrac_alt_rec}==${time_ascii}"
conntrac_alt2_rec="${conntrac_alt2_rec}==${time_ascii}"
timestamp="${local_date_ascii}=${local_time_ascii}"
conntrac_record="${conntrac_record}==${timestamp}"
conntrac_alt_rec="${conntrac_alt_rec}==${timestamp}"
conntrac_alt2_rec="${conntrac_alt2_rec}==${timestamp}"

# shellcheck disable=SC2154
conntrac_record="${conntrac_record}++${untrusted_ip}:${untrusted_port}"
Expand Down Expand Up @@ -570,9 +567,11 @@ deps ()
LOCK_TIMEOUT="${LOCK_TIMEOUT:-30}"

# Need the date/time ..
full_date="$("${EASYTLS_DATE}" '+%s %Y/%m/%d-%H:%M:%S')"
local_date_ascii="${full_date##* }"
#local_date_sec="${full_date%% *}"
#full_date="$("${EASYTLS_DATE}" '+%s %Y/%m/%d-%H:%M:%S')"
# shellcheck disable=SC2154
full_date="${time_ascii}"
local_date_ascii="${full_date% *}"
local_time_ascii="${full_date#* }"

# Windows log
EASYTLS_WLOG="${temp_stub}-client-disconnect.log"
Expand Down

1 comment on commit b7163f3

@TinCanTech
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.