diff options
author | clsr <clsr@clsr.net> | 2022-06-13 21:25:33 +0000 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2022-06-13 21:25:33 +0000 |
commit | 1f995de12914d4ebb97ff2d1322b901183fa24ae (patch) | |
tree | 3c305499b33fa72bd94335c0df12bbbeeda1fabf /ircbot.bash | |
parent | 349b61f34c83740f8266ef07620158cdf939bb46 (diff) | |
download | mbibot-1f995de12914d4ebb97ff2d1322b901183fa24ae.tar.gz mbibot-1f995de12914d4ebb97ff2d1322b901183fa24ae.zip |
Add TLS supporttls
Diffstat (limited to 'ircbot.bash')
-rwxr-xr-x | ircbot.bash | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ircbot.bash b/ircbot.bash index 646c4da..e3fc56a 100755 --- a/ircbot.bash +++ b/ircbot.bash @@ -66,6 +66,8 @@ IRCBOT_MODULE=ircbot _events=(connect disconnect readmsg sendmsg privmsg dm ctcp self_join self_kick self_part self_invite) +_ircbot_cleanup=() + verbose() { if [ -n "$IRCBOT_VERBOSE" ] && [ "$IRCBOT_VERBOSE" -ne 0 ]; then printf "[%s] $1\n" "$IRCBOT_MODULE" "${@:2}" >&2 @@ -73,8 +75,17 @@ verbose() { } connect() { - if ! exec {_ircbot_fd}<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then - return $? + if [[ "$IRCBOT_TLS" -ne 0 ]]; then + local fifo + fifo="$(mktemp -u --tmpdir "ircbot.XXXXXX.fifo")" || return $? + mkfifo "$fifo" || return $? + _ircbot_cleanup+=("$fifo") + openssl s_client -quiet -connect "$IRCBOT_HOST:$IRCBOT_PORT" <"$fifo" >"$fifo" & + exec {_ircbot_fd}<>"$fifo" + else + if ! exec {_ircbot_fd}<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then + return $? + fi fi if [[ -n "$IRCBOT_PASS" ]]; then @@ -410,6 +421,14 @@ _main() { # args: $1 - config file verbose 'reconnecting in %d seconds...' "${IRCBOT_SLEEP_RECONNECT:-10}" sleep "${IRCBOT_SLEEP_RECONNECT:-10}" done + _cleanup +} + +_cleanup() { + local f + for f in "${_ircbot_cleanup[@]}"; do + rm -f "$f" + done } _main "$@" |