Skip to content

Commit

Permalink
Introduce easytls-conn-trac.lib
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Aug 12, 2021
1 parent 70f3a04 commit a05e4f1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions easytls-conn-trac.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

# Connection tacking - Connect
conn_trac_connect ()
{
[ $ENABLE_CONN_TRAC ] || return 0
[ -n "${1}" ] || return 1
[ -f "${EASYTLS_CONN_TRAC}" ] && \
conn_trac_data="$("${EASYTLS_CAT}" "${EASYTLS_CONN_TRAC}")"
if [ -f "${EASYTLS_CONN_TRAC}" ] && \
"${EASYTLS_GREP}" -q "^${1}\$" "${EASYTLS_CONN_TRAC}"
then
# Already connected don't add another
update_status \
"conn-trac: already registered ${1}"
else
{ # Add tlskey_serial to Easy-TLS Conn-Trac file
"${EASYTLS_PRINTF}" "%s\n" "${1}"
[ -z "${conn_trac_data}" ] || \
"${EASYTLS_PRINTF}" "%s" "${conn_trac_data}"
} > "${EASYTLS_CONN_TRAC}"
update_status "conn-trac: registered ${1}"
fi
unset conn_trac_data
} # => conn_trac_connect ()

# Update connection tacking - disconnect
conn_trac_disconnect ()
{
[ $ENABLE_CONN_TRAC ] || return 0
[ -n "${1}" ] || return 1
[ -f "${EASYTLS_CONN_TRAC}" ] && {
"${EASYTLS_SED}" -i -e "/^${1}\$/d" -e "/^\$/d" "${EASYTLS_CONN_TRAC}"
update_status "conn-trac: unregistered ${1}"
[ -s "${EASYTLS_CONN_TRAC}" ] || "${EASYTLS_RM}" -f "${EASYTLS_CONN_TRAC}"
}
} # => conn_trac_disconnect ()

1 comment on commit a05e4f1

@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.