#!/usr/bin/bash if [ $(/usr/bin/id -u) != 0 ]; then echo "only root can do that"; exit 2; fi #*************************************************************************** # This file is part of the CRYPTO BONE # File : cron.fetchmail # Version : 1.5 (external cryptobone) # License : BSD # Date : Wednesday, 1 March 2023 # Contact : Please send enquiries and bug-reports to innovation@senderek.ie # # # Copyright (c) 2015-2023 # Ralf Senderek, Ireland. All rights reserved. (https://senderek.ie) # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Ralf Senderek. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #**************************************************************************** CONFIG=/usr/lib/cryptobone/ext/.exfetchmailrc RAM=/dev/shm/EXRAM if [ -s $RAM/GUI ] then # check if GUI is still active NOW=$(date +%s) LAST=$(cat $RAM/GUI 2> /dev/null) delta=$(( $NOW - $LAST )) echo $delta > $RAM/delta if [ $delta -gt 600 ] then date +%s > $RAM/exit # grace time is over /bin/rm -f $RAM/GUI $RAM/delta fi fi if [ -L /usr/lib/cryptobone/ext/masterkey ] && [ -d /dev/shm/EXRAM ] && [ -s $RAM/GUI ] ; then # only run fetchmail if GUI is active # make sure the .fetchmail file exists if [ ! -r $CONFIG ] then /usr/lib/cryptobone/ext/bin/createfetchmailrc 2> /dev/null fi FETCH=/tmp/exfetch touch $FETCH ERROR=/dev/shm/EXRAM/exfetchmail.error OUT=/dev/shm/EXRAM/exfetchmail.output /usr/bin/fetchmail -f $CONFIG -p AUTO -t 45 --nosslcertck --all --bsmtp $FETCH 2> $ERROR > $OUT /bin/chmod 600 $OUT $ERROR if [[ -r $FETCH ]]; then /bin/chmod 600 $FETCH fi /bin/mkdir /dev/shm/EXRAM/IN 2> /dev/null /bin/mkdir /dev/shm/EXRAM/FORENSIC 2> /dev/null /bin/mkdir /dev/shm/EXRAM/MESSAGES 2> /dev/null /bin/chmod 700 /dev/shm/EXRAM/MESSAGES /dev/shm/EXRAM/IN /dev/shm/EXRAM/FORENSIC 2> /dev/null if [ -r $FETCH ] ; then /bin/mv $FETCH /dev/shm/EXRAM # split the file into messages and analyse them all /usr/lib/cryptobone/ext/bin/analysebatchfile 2> /dev/null MAILFILE="/dev/shm/EXRAM/exfetch-`date +%y.%m.%d-%H.%M`" /bin/mv /dev/shm/EXRAM/exfetch $MAILFILE /bin/chmod 400 $MAILFILE # remove if size is 0 if [ ! -s $MAILFILE ] then /bin/rm -f $MAILFILE fi fi fi