#!/bin/bash # UPDATE alias update-bashscripts='curl -o /root/.bashscripts "https://raw.githubusercontent.com/feanorknd/bashscripts/main/bashscripts" && chmod 0600 /root/.bashscripts' # COMMON ALIASES alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias cpd='cp -Rfv' alias du+='du max-depth\=1 -x -h' alias llg='ls -lah | grep' alias lll='ls -laFtu | less' alias mesgrep='cat /var/log/syslog | grep' alias ls='ls --color=auto' alias mata='kill -9' alias p='ps axf -o pid,user,cmd' alias paquete='dpkg -l | grep -i' alias psgg='ps -fC' alias psl='ps aux | less' alias rmd='rm -Rfv' alias setgpg='gpg --armor --export | sudo apt-key add -' alias t='tail' alias tf='tail -f' alias tn='tail -n' alias tree='find -type d' alias disco='iostat -xm 1' alias mystop='watch -n 1 mysqladmin process' alias mempro='ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS' alias socketing='cat /proc/net/sockstat' alias mysqlcon='for i in `seq 1 10000`;do echo "Conexiones a Mysql: `mysqladmin process | grep "|" | wc -l`";sleep 2; done' alias chequeaconntrack='sysctl -a | grep -i conntr | grep -E "(k_count |k_max )"' alias apti='aptitude install' alias aptp='aptitude purge' alias aptr='aptitude remove' alias apts='aptitude search' alias aptu='aptitude update' alias aptup='aptitude upgrade' alias reloadcsf="systemctl stop csf;systemctl stop lfd;sleep 5;systemctl start csf;sleep 10;systemctl start lfd" alias resetcsf="csf -x; sleep 1; csf -e" alias godomlogs="cd /var/log/ispconfig/httpd" alias bind9querylog="rndc querylog" alias clearcachesswap="sync && echo 3 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" alias modsecanalysis="source /root/scripts/split-modsec-file.sh;/root/scripts/clean-modsec-files.sh;ll" alias testipv6ping="ping -c 2 -6 www.cyberciti.biz" alias salirssh='unset HISTFILE && exit' alias restartnginx='if [ -d /var/modsecurity ]; then rm -f /var/modsecurity/*; systemctl restart nginx; else systemctl restart nginx; fi' alias modsec-counters="/etc/modsecurity/scripts/06-read_shared_collections.sh" alias compressed-mail-read="zstdcat" alias mless="zstdless" alias mcat="zstdcat" alias mgrep="zstdgrep" alias ports="netstat -tnlp" alias ports2="lsof -i -P -sTCP:LISTEN" alias rbls="/root/scripts/rbl/check_bl.sh" alias rbls-modsecurity="/root/scripts/rbl/check_bl.sh -l /etc/modsecurity/rules-available/rbls.lists -v" alias pagecache-writeback="while true; do sleep 1; clear; cat /proc/vmstat | egrep 'dirty|writeback'; done" alias flushea="truncate -s 0" alias vacia="truncate -s 0" alias cola="postqueue -p" alias cola-borrar-todo="postsuper -d ALL" alias cola-enviar-todo="postqueue -f" alias cola-check-mail-by-id="postcat -q " alias cola-remove-mail-by-id="postsuper -d " alias cola-eliminar-mails-devueltos="postsuper -d ALL deferred" alias cola-pfqueue="pfqueue" compare_dirs() { local SOURCE="" local NEW="" while [[ $# -gt 0 ]]; do case "$1" in --source) SOURCE="${2:-}" shift 2 ;; --new) NEW="${2:-}" shift 2 ;; *) echo "Uso: compare_dirs --source /ruta/source --new /ruta/new" return 1 ;; esac done [[ -z "$SOURCE" || -z "$NEW" ]] && { echo "Uso: compare_dirs --source /ruta/source --new /ruta/new" return 1 } [[ ! -d "$SOURCE" ]] && { echo "ERROR: source no existe o no es directorio: $SOURCE" return 1 } [[ ! -d "$NEW" ]] && { echo "ERROR: new no existe o no es directorio: $NEW" return 1 } local tmp_source tmp_new tmp_source=$(mktemp) tmp_new=$(mktemp) trap 'rm -f "$tmp_source" "$tmp_new"' RETURN ( cd "$SOURCE" || return 1 find . -type f | sort ) > "$tmp_source" ( cd "$NEW" || return 1 find . -type f | sort ) > "$tmp_new" echo "Archivos solo en SOURCE:" comm -23 "$tmp_source" "$tmp_new" echo echo "Archivos solo en NEW:" comm -13 "$tmp_source" "$tmp_new" echo echo "Archivos en ambos pero distintos:" comm -12 "$tmp_source" "$tmp_new" | while read -r file; do local source_file="$SOURCE/${file#./}" local new_file="$NEW/${file#./}" local source_md5 new_md5 source_md5=$(md5sum "$source_file" | awk '{print $1}') new_md5=$(md5sum "$new_file" | awk '{print $1}') if [[ "$source_md5" != "$new_md5" ]]; then echo "$file" echo " SOURCE md5: $source_md5" echo " NEW md5: $new_md5" fi done } rastrea() { local archivo="$1" shift if [ -z "$archivo" ]; then echo "Uso: rastrea [texto1] [texto2] [...]"; return 1; fi if [ ! -f "$archivo" ]; then echo "Error: el archivo no existe: $archivo"; return 1; fi local pipeline pipeline="tail -f \"\$archivo\"" for filtro in "$@"; do pipeline+=" | grep -i --line-buffered -- \"\$filtro\""; done tail -f "$archivo" | while IFS= read -r linea; do local coincide=1 for filtro in "$@"; do if ! grep -qi -- "$filtro" <<< "$linea"; then coincide=0; break; fi done if [ "$coincide" -eq 1 ]; then printf '%s\n' "$linea"; fi done } # RAM CONSUMING PER PROCESS % ram() { string="$1" # Es más seguro usar comillas al comprobar la variable [ -z "$string" ] && string="(.*)" # Aquí está el cambio clave: \$3 en lugar de $3 echo "'${string}' takes: $(ps -eo pid,comm,%mem | sort -rk3 | grep -P "${string}" | awk '{sum += \$3} END {print sum}')% of RAM memory" } ramlist() { awk ' # Para cada archivo /proc/[pid]/status # Capturamos el nombre del proceso y reiniciamos los valores de memoria temporal FNR==1 && /Name:/ { current_name = $2; current_rss = 0; current_swap = 0; } # Buscamos y guardamos el valor de VmRSS (RAM) /VmRSS:/ { current_rss = $2; } # Buscamos y guardamos el valor de VmSwap (Swap) /VmSwap:/ { current_swap = $2; } # Al final de cada archivo (ENDFILE se soporta en gawk), agregamos los valores ENDFILE { # Si el proceso no usa memoria, lo ignoramos if (current_rss + current_swap > 0) { rss[current_name] += current_rss; swap[current_name] += current_swap; count[current_name]++; } } END { # Imprimimos la cabecera printf "%-25s %12s %12s %12s %8s\n", "NOMBRE", "RAM (RSS)", "SWAP", "TOTAL", "PROCESOS"; printf "%-25s %12s %12s %12s %8s\n", "-------------------------", "------------", "------------", "------------", "--------"; # Creamos un array para poder ordenar por el total de memoria usada i = 0; for (name in rss) { total_mem = rss[name] + swap[name]; # Guardamos la línea de salida precedida por la memoria total para usarla como clave de ordenación sort_array[i++] = sprintf("%020d\t%-25s\t%10.1f MB\t%10.1f MB\t%10.1f MB\t%8d", total_mem, name, rss[name]/1024, swap[name]/1024, total_mem/1024, count[name]); } # Ordenamos el array numéricamente en orden descendente n = asort(sort_array); for (i = n; i >= 1; i--) { # Extraemos la parte imprimible del string (ignoramos la clave de ordenación) sub(/^[0-9]+\t/, "", sort_array[i]); print sort_array[i]; if (n-i+1 >= 30) break; # Limitar a los 30 primeros } } ' /proc/[0-9]*/status } swaplist() { awk ' # Para cada archivo /proc/[pid]/status # Capturamos el nombre del proceso y reiniciamos los valores de memoria temporal FNR==1 && /Name:/ { current_name = $2; current_rss = 0; current_swap = 0; } # Buscamos y guardamos el valor de VmRSS (RAM) /VmRSS:/ { current_rss = $2; } # Buscamos y guardamos el valor de VmSwap (Swap) /VmSwap:/ { current_swap = $2; } # Al final de cada archivo (ENDFILE se soporta en gawk), agregamos los valores ENDFILE { # Si el proceso no usa memoria, lo ignoramos if (current_rss + current_swap > 0) { rss[current_name] += current_rss; swap[current_name] += current_swap; count[current_name]++; } } END { # Imprimimos la cabecera printf "%-25s %12s %12s %12s %8s\n", "NOMBRE", "SWAP", "RAM (RSS)", "TOTAL", "PROCESOS"; printf "%-25s %12s %12s %12s %8s\n", "-------------------------", "------------", "------------", "------------", "--------"; # Creamos un array para poder ordenar por el total de memoria usada i = 0; for (name in swap) { # Ignoramos los procesos que no usan swap para esta lista if (swap[name] > 0) { swap_mem = swap[name]; total_mem = rss[name] + swap_mem; sort_array[i++] = sprintf("%020d\t%-25s\t%10.1f MB\t%10.1f MB\t%10.1f MB\t%8d", swap_mem, name, swap_mem/1024, rss[name]/1024, total_mem/1024, count[name]); } } # Ordenamos el array numéricamente en orden descendente n = asort(sort_array); for (i = n; i >= 1; i--) { # Extraemos la parte imprimible del string (ignoramos la clave de ordenación) sub(/^[0-9]+\t/, "", sort_array[i]); print sort_array[i]; if (n-i+1 >= 30) break; # Limitar a los 30 primeros } } ' /proc/[0-9]*/status } # MAIL FILTERING alias mailtail="tail -f /var/log/mail.log | grep -i -a postfix" alias dovetail="tail -f /var/log/mail.log | grep -i -a dovecot" alias mailtailgrep="tail -f /var/log/mail.log | grep -i" mailgrep(){ string="$1" [ -z $2 ] && time=3 || time=$2 while read logfile do FILE_TYPE=$(file --mime-type -b "${logfile}") if [[ "${FILE_TYPE}" == "application/gzip" ]]; then zcat "${logfile}" | grep -a " postfix" | grep -a "${string}" else cat "${logfile}" | grep -a " postfix" | grep -a "${string}" fi done < <(find /var/log/ -name "mail.log*" -mtime -${time} -printf "%T+ %p\n" | sort | awk '{print $2}') } dovegrep(){ string="$1" [ -z $2 ] && time=3 || time=$2 while read logfile do FILE_TYPE=$(file --mime-type -b "${logfile}") if [[ "${FILE_TYPE}" == "application/gzip" ]]; then zcat "${logfile}" | grep -a " dovecot:" | grep -a "${string}" else cat "${logfile}" | grep -a " dovecot:" | grep -a "${string}" fi done < <(find /var/log/ -name "mail.log*" -mtime -${time} -printf "%T+ %p\n" | sort | awk '{print $2}') } # COMMON FUNCTIONS psg(){ ps aux | grep "$1" | grep -v grep } urldecodemodsec(){ file="$1" string="$(grep -A 1 "\---C--" $file | tail -n 1)" echo "$string" | python3 -c "import sys, urllib.parse as ul; [print(ul.unquote_plus(l), end='') for l in sys.stdin]" | tr '&' '\n' } showline(){ file="$1"; line="$2"; if [ -z $3 ] then after=${line} else after=$((${line} + ${3})) fi awk "NR >= ${line} && NR <= ${after}" ${file}; } geolocate(){ curl "https://gino.es/geo/$1"; } ispcron(){ /usr/local/ispconfig/server/server.sh 2>&1 | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done; } dudir(){ find $1 -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; ; } dudirg(){ find $1 -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; | grep -E "^[0-9\.\,]+G" | sort ; } dudirm(){ find $1 -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; | grep -E "^[0-9\.\,]+M" | sort ; } dufiles(){ find $1 -maxdepth 1 -mindepth 1 -type f -exec du -hs {} \; ; } dufilesg(){ find $1 -maxdepth 1 -mindepth 1 -type f -exec du -hs {} \; | grep -E "^[0-9\.\,]+G" | sort ; } dufilesm(){ find $1 -maxdepth 1 -mindepth 1 -type f -exec du -hs {} \; | grep -E "^[0-9\.\,]+M" | sort ; } duall(){ find $1 -maxdepth 1 -mindepth 1 -exec du -hs {} \; ; } duallg(){ find $1 -maxdepth 1 -mindepth 1 -exec du -hs {} \; | grep -E "^[0-9\.\,]+G" | sort ; } duallsm(){ find $1 -maxdepth 1 -mindepth 1 -exec du -hs {} \; | grep -E "^[0-9\.\,]+M" | sort ; } dufilesbetween(){ midir="$1";min="$2";max="$3" if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then echo "dufilesbetween "; echo "for example: dufilesbetween /var/vmail/ 3K 5M"; return; fi totalfiles=$(find $midir -maxdepth 1 -mindepth 1 -size +${min} -size -${max} | wc -l) echo "(find $midir -maxdepth 1 -mindepth 1 -size +${min} -size -${max})" echo "" echo "files" echo "------------------------------------------------------------------------------------------------------------------" find $midir -maxdepth 1 -mindepth 1 -size +${min} -size -${max} -exec stat --format="%Y %n %s" {} \; | sort -n | awk '{printf "%s\t\t\t%s\t\t\t%s\n", $2, $3, strftime("%Y-%m-%d %H:%M:%S", $1)}' | numfmt --to=iec --field=2 echo "------------------------------------------------------------------------------------------------------------------" find $midir -maxdepth 1 -mindepth 1 -size +${min} -size -${max} -printf "%s\n" | awk '{s=s+$1} END {print s}' | awk '{ byte =$1/1024/1024; print byte }' | awk '{printf("%.2f\n", $1)}' | xargs -I{} echo "Total size: {}M ($totalfiles files)"; echo "" } dufilesextension(){ midir="$1" ext="$2" if [ -z $1 ] || [ -z $2 ]; then echo "dufilesextension []"; echo "for example: dufilesextension /var/vmail/ jpg recursive"; return; fi totalfiles=$(find $midir -iname "*.${ext}" | wc -l) echo "" echo "${ext} files" echo "------------------------------------------------------------------------------------------------------------------" if [ -z $3 ]; then find $midir -maxdepth 1 -mindepth 1 -iname "*.${ext}" -printf "%s\n" | awk '{s=s+$1} END {print s}' | awk '{ byte =$1/1024/1024; print byte }' | awk '{printf("%.2f\n", $1)}' | xargs -I{} echo "Total size: {}M ($totalfiles files)"; else find $midir -iname "*.${ext}" -printf "%s\n" | awk '{s=s+$1} END {print s}' | awk '{ byte =$1/1024/1024; print byte }' | awk '{printf("%.2f\n", $1)}' | xargs -I{} echo "Total size: {}M ($totalfiles files)"; fi echo "" } dur(){ find $1 -type f -links 1 -printf "%s\n" | awk '{s=s+$1} END {print s}' | awk '{ byte =$1/1024/1024/1024; print byte }' | awk '{printf("%.2f\n", $1)}' | xargs -I{} echo "{}G"; } duh(){ find $1 -type f -links +1 -printf "%s\n" | awk '{s=s+$1} END {print s}' | awk '{ byte =$1/1024/1024/1024; print byte }' | awk '{printf("%.2f\n", $1)}' | xargs -I{} echo "{}G"; } durf(){ find $1 -type f -links 1; } duhf(){ find $1 -type f -links +1; } limpia(){ rm -vf ./*${1}* | wc -l; } limpiafind(){ find ./ -maxdepth 1 -mindepth 1 -type f -exec grep -l "${1}" {} \; | xargs rm -vf | wc -l ; } limpiaipmatching(){ find ./ -maxdepth 1 -mindepth 1 -type f -name "*${1}*" | grep -o -P "_[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+_" | grep -o -P "[0-9\.]+" | sort -u | while read IP; do rm -vf ./*${IP}* ; done | wc -l ; } limpiaipmatchingfind(){ find ./ -maxdepth 1 -mindepth 1 -type f -exec grep -l "${1}" {} \; | grep -o -P "_[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+_" | grep -o -P "[0-9\.]+" | sort -u | while read IP; do rm -vf ./*${IP}* ; done | wc -l ; } chequeacon(){ netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c; } quienphp(){ psg php | awk '{print $1}' | sort | uniq -c | sort -n; } reloadphps(){ for php in $(find /usr/bin/ -maxdepth 1 -mindepth 1 -type f -regextype sed -regex ".*/php[0-9]\.[0-9]" | awk -F"php" '{print $2}' | sort) do echo "Reloading php${php}-fpm.service" systemctl reload php${php}-fpm.service sleep 5 done echo "Showing current php processes executing:" ps aux | grep "php-fpm: master process" } restartphps(){ for php in $(find /usr/bin/ -maxdepth 1 -mindepth 1 -type f -regextype sed -regex ".*/php[0-9]\.[0-9]" | awk -F"php" '{print $2}' | sort) do echo "Restarting php${php}-fpm.service" systemctl restart php${php}-fpm.service sleep 5 done echo "Showing current php processes executing:" ps aux | grep "php-fpm: master process" } checkcertfile(){ [[ -z $1 ]] && echo "checkcert " file="$1" [[ ! -z $1 ]] && cat ${file} | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' } checkcerttls(){ [[ -z $1 ]] && echo "checkcert " server="$1" port="$2" sni="$3" [[ ! -z $1 ]] && openssl s_client -connect ${server}:${port} -servername ${sni} -tls1_2 /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' } checkcerttls13(){ [[ -z $1 ]] && echo "checkcert " server="$1" port="$2" sni="$3" [[ ! -z $1 ]] && openssl s_client -connect ${server}:${port} -servername ${sni} -tls1_3 /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' } checkcertstarttls(){ [[ -z $1 ]] && echo "checkcert " server="$1" port="$2" sni="$3" [[ ! -z $1 ]] && openssl s_client -connect ${server}:${port} -servername ${sni} -starttls smtp /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' } checkcert(){ [[ -z $1 ]] && echo "checkcert " server="$1" port="$2" sni="$3" [[ ! -z $1 ]] && openssl s_client -connect ${server}:${port} -servername ${sni} /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' } checkcertmails(){ [[ -z $1 ]] && echo "checkcert " [[ -z $1 ]] && return 1 server="$1" sni="$2" echo "" echo "Checking certificates for $sni in server $server ..." echo "" echo "------------------------------------------------------------------------------------------------------------------------------------------" echo "Checking SMTP 25 (TLS):" openssl s_client -connect ${server}:25 -servername ${sni} -starttls smtp /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' echo "" echo "------------------------------------------------------------------------------------------------------------------------------------------" echo "Checking SMTP 465 (SSL):" openssl s_client -connect ${server}:465 -servername ${sni} /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' echo "" echo "------------------------------------------------------------------------------------------------------------------------------------------" echo "Checking SMTP 587 (TLS):" openssl s_client -connect ${server}:587 -servername ${sni} -starttls smtp /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' echo "" echo "------------------------------------------------------------------------------------------------------------------------------------------" echo "Checking IMAP 993 (SSL):" openssl s_client -connect ${server}:993 -servername ${sni} /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' echo "" echo "------------------------------------------------------------------------------------------------------------------------------------------" echo "Checking POP3 995 (SSL):" openssl s_client -connect ${server}:995 -servername ${sni} /dev/null | openssl x509 -noout -text | grep -P "(Issuer:|Not Before|Not After|Subject:|DNS:)" | sed 's/^[[:space:]]*//g' echo "" } swap(){ #smem --sort=swap --reverse --percent smem --sort=swap --reverse | head -n 20 } memory(){ ps aux --sort -rss | head -n 20 } learnspam(){ for file in $(find -maxdepth 1 -mindepth 1 -type f ! -name "dovecot*" ! -name "subscriptions"); do echo "" echo "-------------------------------------------------------------------" echo "Processing:" echo "$(realpath "$file")"; echo "" if [ $(file --mime-type $file | grep "application/zstd" | wc -l) -eq 1 ] then MYCAT="/usr/bin/zstdcat" else MYCAT="/usr/bin/cat" fi ${MYCAT} $file | rspamc learn_spam done } learnspamfuzzy(){ for file in $(find -maxdepth 1 -mindepth 1 -type f ! -name "dovecot*" ! -name "subscriptions"); do echo "" echo "-------------------------------------------------------------------" echo "Processing:" echo "$(realpath "$file")"; echo "" if [ $(file --mime-type $file | grep "application/zstd" | wc -l) -eq 1 ] then MYCAT="/usr/bin/zstdcat" else MYCAT="/usr/bin/cat" fi ${MYCAT} $file | rspamc -S LOCAL_FUZZY_WHITE fuzzy_del ${MYCAT} $file | rspamc -S LOCAL_FUZZY_DENIED -w 10 fuzzy_add ${MYCAT} $file | rspamc learn_spam done } learnham(){ for file in $(find -maxdepth 1 -mindepth 1 -type f ! -name "dovecot*" ! -name "subscriptions"); do echo "" echo "-------------------------------------------------------------------" echo "Processing:" echo "$(realpath "$file")"; echo "" if [ $(file --mime-type $file | grep "application/zstd" | wc -l) -eq 1 ] then MYCAT="/usr/bin/zstdcat" else MYCAT="/usr/bin/cat" fi ${MYCAT} $file | rspamc learn_ham done } learnhamfuzzy(){ for file in $(find -maxdepth 1 -mindepth 1 -type f ! -name "dovecot*" ! -name "subscriptions"); do echo "" echo "-------------------------------------------------------------------" echo "Processing:" echo "$(realpath "$file")"; echo "" if [ $(file --mime-type $file | grep "application/zstd" | wc -l) -eq 1 ] then MYCAT="/usr/bin/zstdcat" else MYCAT="/usr/bin/cat" fi ${MYCAT} $file | rspamc -S LOCAL_FUZZY_DENIED fuzzy_del ${MYCAT} $file | rspamc -S LOCAL_FUZZY_WHITE -w 10 fuzzy_add ${MYCAT} $file | rspamc learn_ham done } gomail(){ mail="$(echo $1 | awk -F"@" '{print $1}')" domain="$(echo $1 | awk -F"@" '{print $2}')" cd /var/vmail/$domain/$mail/Maildir/ } findmailgrep(){ if [ -z "$1" ] || [ -z "$2" ] then echo "findmail " else mail="$(echo "$1" | awk -F"@" '{print $1}')" domain="$(echo "$1" | awk -F"@" '{print $2}')" text="$2" daysold="$3" if [ -z $daysold ] then daysold=7 fi find /var/vmail/$domain/$mail/Maildir/ -type f -regextype posix-extended -regex ".*\/[0-9]+[^\/]*" -mtime -${daysold} -exec grep -l "${text}" {} \; fi } findmailzstdgrep(){ if [ -z "$1" ] || [ -z "$2" ] then echo "findmail " else mail="$(echo "$1" | awk -F"@" '{print $1}')" domain="$(echo "$1" | awk -F"@" '{print $2}')" text="$2" daysold="$3" if [ -z $daysold ] then daysold=7 fi find /var/vmail/$domain/$mail/Maildir/ -type f -regextype posix-extended -regex ".*\/[0-9]+[^\/]*" -mtime -${daysold} -exec zstdgrep -l "${text}" {} \; fi } imunifyrestart(){ for service in imunify-antivirus-sensor.socket imunify-antivirus.service imunify-antivirus.socket imunify-antivirus-user.socket imunify-notifier.service imunify-notifier.socket do systemctl stop $service systemctl stop $service sleep 10 systemctl start $service done } checkmailautos(){ [[ -z $1 ]] && echo "checkmailautos " mail="$1" domain="$(echo $mail | awk -F'@' '{print $2}')" clear echo "" echo "Testing autoconfig:" echo "-------------------------------------------------------------------------------------------------------------------------------------------------" echo "curl \"https://$domain/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress=$mail\"" echo "" echo "Result:" curl "https://$domain/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress=$mail" echo "" echo "" echo "" echo "Testing autodiscover:" echo "-------------------------------------------------------------------------------------------------------------------------------------------------" echo "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a$mail" >> /tmp/testautodiscover.xml echo "XML to send:" cat /tmp/testautodiscover.xml echo "" echo "curl -X POST -d @/tmp/testautodiscover.xml \"https://$domain/autodiscover/autodiscover.xml\"" echo "" echo "Result:" curl -X POST -d @/tmp/testautodiscover.xml "https://$domain/autodiscover/autodiscover.xml" echo "" rm -f /tmp/testautodiscover.xml }