From 06a56540b041accaaff795ad57664e368cb07a10 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 12 Sep 2023 23:47:12 -0400 Subject: [PATCH] mainly new feature to intentionally delay sending email --- brc | 12 +++- brc2 | 65 +++++++++++++++++---- mail-setup | 157 +++++++++++++++++++++++++++++++++++++++++--------- pkgs | 1 + system-status | 32 ++++++++-- 5 files changed, 225 insertions(+), 42 deletions(-) diff --git a/brc b/brc index b78e08f..4e02122 100644 --- a/brc +++ b/brc @@ -712,7 +712,7 @@ for field in {1..20}; do done # h1 = head -n1 for num in {1..9}; do - eval h$num"() { head -n$num; }" + eval h$num"() { head -n$num || [[ \$? == 141 ]]; }" done @@ -1590,6 +1590,8 @@ pst() { pstree -apnA } +# journalctl with times in the format the --since= and --until= options accept +jrt() { journalctl -e -n100000 -o short-full "$@"; } jr() { journalctl -e -n100000 "$@" ; } jrf() { journalctl -n1000 -f "$@" ; } jru() { @@ -1754,6 +1756,14 @@ nags() { fi /usr/bin/nagstamon & } +prof() { + if ! pgrep -f /usr/lib/notification-daemon/notification-daemon >/dev/null; then + /usr/lib/notification-daemon/notification-daemon & + fi + profanity "$@" +} + + nmt() { # cant use s because sudo -i doesnt work for passwordless sudo command diff --git a/brc2 b/brc2 index 23cfd89..1974c58 100644 --- a/brc2 +++ b/brc2 @@ -289,14 +289,41 @@ tback() { # sshfs example: # s sshfs bu@$host:/bu/home/md /bu/mnt -o reconnect,ServerAliveInterval=20,ServerAliveCountMax=30 -o allow_other +edelayoff() { + echo all >/etc/exim4/no-delay-eximids +} +edelayon() { + echo >/etc/exim4/no-delay-eximids +} + eqgo() { - local -a array tmpstr + local -a array tmpstr delayon + delayon=true + if grep -qFx all /etc/exim4/no-delay-eximids; then + delayon=false + fi + if $delayon; then + echo all >/etc/exim4/no-delay-eximids + fi tmpstr=$(exiqgrep -i -r.\*) mapfile -t array <<<"$tmpstr" enn -M "${array[@]}" + if $delayon; then + echo >/etc/exim4/no-delay-eximids + fi } eqgo1() { - enn -M "$(exipick -i -r.\*|h1)" + local eid + eid="$(exipick -i -r.\*|h1)" + sed -n "/^all$/p;\$a $eid" /etc/exim4/no-delay-eximids + enn -M "$eid" +} +ennm() { + local eid + for eid; do + printf "%s\n" "$eid" >>/etc/exim4/no-delay-eximids + done + enn -M "$@" } @@ -2751,11 +2778,21 @@ myirc() { # use * instead of -r since that does sorted order ssh root@iankelling.org "for f in ${d[*]}; do cd \$f/#$1; grep '\/dev/null | grep -iP --color=auto "$*" ||: - rgv -m 5 "$*" $paths /a/t.org /p/w.org /a/work.org ||: + -o -name .undo-tree-history -prune \) 2>/dev/null | grep -iP --color=auto -- "$*" ||: + rgv -m 5 -- "$*" $paths /a/t.org /p/w.org /a/work.org ||: } # setup: @@ -3827,6 +3864,14 @@ amoffice() { amls() { amall silence query "$@" } +# amtool silence add +amsa() { + amall silence add "$@" +} +# amtool silence force +amsf() { + amall silence add x!="1" +} amrmall() { # note: not sure if quoting of this arg is correct amfsf silence expire "$(amfsf silence query -q)" @@ -3842,12 +3887,12 @@ youtube-dl-update() { # https://github.com/yt-dlp/yt-dlp/wiki/Installation yt-dlp-update() { sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp -sudo chmod a+rx /usr/local/bin/yt-dlp # Make executable - } + sudo chmod a+rx /usr/local/bin/yt-dlp # Make executable +} mpvyt() { mpv --ytdl ytdl_path=/usr/local/bin/yt-dlp "$@" - } +} # taken from default changes to bashrc and bash_profile path-add --end --ifexists $HOME/.rvm/bin diff --git a/mail-setup b/mail-setup index e753fbe..667f0ec 100755 --- a/mail-setup +++ b/mail-setup @@ -13,6 +13,8 @@ # which has log path # log_file_path = /var/log/exim4/my%s # +# On non bk|MAIL_HOST, the config and log file are all standard. +# # eximbackup folder is /bu/md # it is cleaned up by mail-backup-clean, which is run by btrbk-run @@ -24,6 +26,14 @@ # #&! testignore|jtuttle|eximbackup|/usr/sbin/exim4 -bpu +# todo: this message seems to get dropped on the floor, it was due to a missing 2nd colon in +# condition = ${if def:h_fdate:} +# Figure out how to avoid this message being discarded. + +# 2023-09-12 01:41:43 [722371] 1qfw9f-0031v9-0S <= ian@iankelling.org U=iank P=local S=483 id=87cyyogd7t.fsf@iankelling.org T="iank2" from for testignore@amnimal.ninja +# 2023-09-12 01:41:43 [722373] 1qfw9f-0031v9-0S H=nn.b8.nz [10.173.8.2]: SMTP error from remote mail server after pipelined end of data: 451 Temporary local problem - please try later +# 2023-09-12 01:41:43 [722372] 1qfw9f-0031v9-0S == testignore@amnimal.ninja R=smarthost T=remote_smtp_smarthost defer (-46) H=nn.b8.nz [10.173.8.2] DT=0s: SMTP error from remote mail server after pipelined end of data: 451 Temporary local problem - please try later + # todo: check new macro DKIM_TIMESTAMPS # todo: check if REMOTE_SMTP_INTERFACE or REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE can simplify my or fsfs config @@ -494,6 +504,9 @@ EOF # * clamav +# old file. remove when all hosts updated, 2023-09-11 +rm -fv /etc/exim4/conf.d/clamav_data_acl + m usermod -a -G Debian-exim clamav u /etc/systemd/system/clamav-daemon.service.d/fix.conf </etc/exim4/conf.d/main/30_local <>/etc/exim4/conf.d/main/000_local <> /etc/exim4/conf.d/data_local_acl <<'EOF' -deny - malware = */defer_ok - !condition = ${if match {$malware_name}{\N^Heuristic\N}} - message = This message was detected as possible malware ($malware_name). -EOF cat >/etc/exim4/conf.d/main/000_local-nn <>/etc/exim4/conf.d/main/000_local <> /etc/exim4/conf.d/data_local_acl <<'EOF' +deny + malware = */defer_ok + !condition = ${if match {$malware_name}{\N^Heuristic\N}} + message = This message was detected as possible malware ($malware_name). + +warn + !hosts = +iank_trusted + !authenticated = * + condition = ${if def:malware_name} + remove_header = Subject: + add_header = Subject: [Clamav warning: $malware_name] $h_subject + log_message = heuristic malware warning: $malware_name + +warn + # fdate = future date. # tdate = temporary date. + condition = ${if def:h_fdate} + remove_header = fdate: + add_header = tdate: + control = freeze +EOF + /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]] 10.173.8.2 nn.b8.nz @@ -3199,18 +3295,25 @@ EOF ;; # ** not MAIL_HOST|bk|je *) - # this one should be removed for all non mail hosts, but + echo|u /etc/exim4/conf.d/router/155_delay + # this one should be removed for all non mail_hosts. note # bk and je never become mail_host echo|u /etc/exim4/conf.d/router/195_dnslookup_vpn echo|u /etc/exim4/conf.d/router/160_backup_redir echo|u /etc/exim4/conf.d/router/161_backup_redir_nn echo|u /etc/exim4/conf.d/router/185_sentarchive echo|u /etc/exim4/conf.d/router/186_sentarchive_nn + # Note, in general we could submit to smarthosts on non MAIL_HOST. + # however, delayed mail makes this inconvenient, because I + # occasionally want to send an email from a non-MAIL_HOST and then + # turn off that computer or travel with it so it is disconnected. + # It is also probably easier to setup emacs to delay messages, but + # that would mean we need to keep emacs running, this is much + # nicer. echo|u /etc/exim4/conf.d/router/188_exim4-config_smarthost echo|u /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost echo|u /etc/exim4/conf.d/rcpt_local_acl echo|u /etc/exim4/conf.d/main/000_local-nn - echo|u /etc/exim4/conf.d/clamav_data_acl if $bhost_t; then @@ -3530,6 +3633,8 @@ case $HOSTNAME in else m systemctl --now enable $vpnser fi + ;;& + bk) if ! systemctl is-active clamav-daemon >/dev/null; then m systemctl --now enable clamav-daemon out=$(rsync -aiSAX --chown=root:root --chmod=g-s /a/bin/ds/filesystem/etc/systemd/system/epanicclean.service /etc/systemd/system) diff --git a/pkgs b/pkgs index 9c6f907..efa7945 100644 --- a/pkgs +++ b/pkgs @@ -223,6 +223,7 @@ p3=( pidgin pidgin-otr pixz + profanity pry pv python3-doc diff --git a/system-status b/system-status index 87d8cf9..fdf4758 100755 --- a/system-status +++ b/system-status @@ -263,13 +263,35 @@ write-status() { fi p $var_mail_msg | loday -1 var_mail - # early in install process, we dont have permission yet for exiqgrep. - # 1100 helps allow for system restarts - qlen=$(/usr/sbin/exiqgrep -o 1100 -c -b | awk '{print $1}') ||: + # Note, early in install process, we dont have permission yet for exiqgrep. + # + # todo: don't do this every 15 seconds, more like once every 2 minutes to + # save cpu cycles. + # + # 2400 = 40 mins. This should allow for system restarts, and + # 30 minute message delay plus 10 minute queu runs. + qlen=$(/usr/sbin/exiqgrep -o 2400 -c -b | awk '{print $1}') ||: qmsg= if ((qlen)); then - qmsg="queue length $qlen" - chars+=("q $qlen") + # Do sending of long delayed messages, and dont count them in our queue warnings. + for mid in $(exiqgrep -o 2400 -zi); do + if exim -Mvh $mid | awk 'tolower($2) == "fdate:"' | grep -q .; then + qlen=$(( qlen - 1 )) + if (( $(date -d "$(exim -Mset $mid -be <<<'$h_date:' | sed -n 's/^> *//;/./p')" +%s) < EPOCHSECONDS )); then + if ip a show veth0-mail &>/dev/null; then + pid=$(pgrep -f "/usr/sbin/exim4 -bd -q30m -C /etc/exim4/my.conf"|head -n1); + nsenter -t $pid -n -m /usr/sbin/exim4 -C /etc/exim4/my.conf -M $mid + else + /usr/sbin/exim4 -M $mid + fi + fi + fi + done + + if ((qlen)); then + qmsg="queue length $qlen" + chars+=("q $qlen") + fi fi case $HOSTNAME in # No point in emailing about the mailq on a host where we don't -- 2.30.2