#!/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.6 (ALL-IN-ONE) # License : BSD # Date : 1 May 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. #**************************************************************************** RAM=/dev/shm/RAM FETCH=${RAM}/fetch BATCH=${RAM}/batch SOCK=/usr/lib/cryptobone/secrets.sock /usr/bin/mkdir ${RAM}/IN 2> /dev/null /usr/bin/mkdir ${RAM}/FORENSIC 2> /dev/null /usr/bin/mkdir ${RAM}/MESSAGES 2> /dev/null /usr/bin/mkdir ${RAM}/FILES 2> /dev/null /usr/bin/chmod 700 ${RAM}/MESSAGES ${RAM}/IN ${RAM}/FORENSIC ${RAM}/FILES 2> /dev/null # only run fetchmail if GUI is active and $RAM/GUI exists 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 /usr/bin/rm -f $RAM/GUI $RAM/delta fi fi if [ -L /usr/lib/cryptobone/ALLINONE ] && [ -d ${RAM} ] && [ -s $RAM/GUI ] ; then # check the transport mechanism TRANS=$(echo "get-element transport" | socat -t15 - UNIX-connect:$SOCK 2> /dev/null) echo ${TRANS} > $RAM/transport if [ ${TRANS}x = "WEBDROPx" ]; then /usr/bin/touch $RAM/WEBDROP 2> /dev/null else # proceed with fetchmail /usr/bin/rm -f ${RAM}/WEBDROP 2> /dev/null fi # make sure the .fetchmail file exists if [ ! -r /usr/lib/cryptobone/.fetchmailrc ] then /usr/lib/cryptobone/bin/createfetchmailrc 2> /dev/null fi touch $FETCH CONFIG=/usr/lib/cryptobone/.fetchmailrc ERROR=${RAM}/fetchmail.error OUT=${RAM}/fetchmail.output if [ ${TRANS}x = "WEBDROPx" ]; then # run the safewebdrop code /usr/lib/cryptobone/safewebdrop/bin/safewebdroprequest # if safewebdrops are received they are stored in ${FETCH} else /usr/bin/fetchmail -f $CONFIG -p AUTO -t 45 --nosslcertck --all --bsmtp ${FETCH} 2> $ERROR > $OUT fi /usr/bin/chmod 600 $OUT $ERROR 2> /dev/null if [[ -r $FETCH ]]; then /usr/bin/chmod 600 $FETCH 2> /dev/null fi if [ -r $FETCH ] ; then /usr/bin/mv $FETCH ${RAM} 2> /dev/null if [ ${TRANS}x = "WEBDROPx" ]; then /usr/lib/cryptobone/safewebdrop/bin/analysebatchfile-safewebdrop 2> /dev/null else # split the file into messages and analyse them all /usr/lib/cryptobone/bin/analysebatchfile 2> /dev/null fi MAILFILE="${RAM}/fetch-$(/usr/bin/date +%y.%m.%d-%H.%M)" /usr/bin/mv ${RAM}/fetch $MAILFILE 2> /dev/null /usr/bin/chmod 400 $MAILFILE 2> /dev/null # remove if size is 0 if [ ! -s $MAILFILE ] then /usr/bin/rm -f $MAILFILE fi fi fi if [ -L /usr/lib/cryptobone/ext/masterkey ] && [ -d /dev/shm/EXRAM ] ; then # check for active GUI in ext /usr/lib/cryptobone/ext/cron.fetchmail fi