fix BITH
This commit is contained in:
78
src/bash/checkAltered.sh
Executable file
78
src/bash/checkAltered.sh
Executable file
@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
##########################################################################
|
||||
# Copyright KAZ 2021 #
|
||||
# #
|
||||
# contact (at) kaz.bzh #
|
||||
# #
|
||||
# This software is a filter to shrink email by attachment extraction. #
|
||||
# #
|
||||
# This software is governed by the CeCILL-B license under French law and #
|
||||
# abiding by the rules of distribution of free software. You can use, #
|
||||
# modify and/or redistribute the software under the terms of the #
|
||||
# CeCILL-B license as circulated by CEA, CNRS and INRIA at the following #
|
||||
# URL "http://www.cecill.info". #
|
||||
# #
|
||||
# As a counterpart to the access to the source code and rights to copy, #
|
||||
# modify and redistribute granted by the license, users are provided #
|
||||
# only with a limited warranty and the software's author, the holder of #
|
||||
# the economic rights, and the successive licensors have only limited #
|
||||
# liability. #
|
||||
# #
|
||||
# In this respect, the user's attention is drawn to the risks associated #
|
||||
# with loading, using, modifying and/or developing or reproducing the #
|
||||
# software by the user in light of its specific status of free software, #
|
||||
# that may mean that it is complicated to manipulate, and that also #
|
||||
# therefore means that it is reserved for developers and experienced #
|
||||
# professionals having in-depth computer knowledge. Users are therefore #
|
||||
# encouraged to load and test the software's suitability as regards #
|
||||
# their requirements in conditions enabling the security of their #
|
||||
# systems and/or data to be ensured and, more generally, to use and #
|
||||
# operate it in the same conditions as regards security. #
|
||||
# #
|
||||
# The fact that you are presently reading this means that you have had #
|
||||
# knowledge of the CeCILL-B license and that you accept its terms. #
|
||||
##########################################################################
|
||||
|
||||
PRG=$(basename $0)
|
||||
|
||||
usage () {
|
||||
echo "Usage: ${PRG} logDir"
|
||||
exit 1
|
||||
}
|
||||
|
||||
BOLD='\e[1m'
|
||||
RED='\e[0;31m'
|
||||
GREEN='\e[0;32m'
|
||||
YELLOW='\e[0;33m'
|
||||
BLUE='\e[0;34m'
|
||||
MAGENTA='\e[0;35m'
|
||||
CYAN='\e[0;36m'
|
||||
NC='\e[0m' # No Color
|
||||
NL='
|
||||
'
|
||||
[ "$#" -eq 1 ] || usage
|
||||
logDir=$(realpath "$1")
|
||||
|
||||
########################################
|
||||
# recherche des binaires
|
||||
cd $(dirname $0)
|
||||
eMailShrinker="$(realpath "./eMailShrinker")"
|
||||
[ -x "${eMailShrinker}" ] || eMailShrinker="$(realpath "../../build/out/eMailShrinker")"
|
||||
[ -x "${eMailShrinker}" ] || ( echo "${RED}eMailShrinker not found${NC}" ; exit)
|
||||
|
||||
|
||||
cd "${logDir}"
|
||||
for i in in.*.orig;
|
||||
do
|
||||
clear
|
||||
echo -e " ${GREEN}${BOLD}${i//.orig}${NC}\n"
|
||||
"${eMailShrinker}" -l ${i}
|
||||
echo -e "\n ####################\n"
|
||||
"${eMailShrinker}" -l ${i//.orig}.altered
|
||||
echo -en "\n(q = quit / y = rm / default = continue)? "
|
||||
read rep
|
||||
case "${rep}" in
|
||||
"q" ) break;;
|
||||
"y") rm ${i} ${i//.orig}.altered
|
||||
esac
|
||||
done
|
77
src/bash/checkShrinker.sh
Executable file
77
src/bash/checkShrinker.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
##########################################################################
|
||||
# Copyright KAZ 2021 #
|
||||
# #
|
||||
# contact (at) kaz.bzh #
|
||||
# #
|
||||
# This software is a filter to shrink email by attachment extraction. #
|
||||
# #
|
||||
# This software is governed by the CeCILL-B license under French law and #
|
||||
# abiding by the rules of distribution of free software. You can use, #
|
||||
# modify and/or redistribute the software under the terms of the #
|
||||
# CeCILL-B license as circulated by CEA, CNRS and INRIA at the following #
|
||||
# URL "http://www.cecill.info". #
|
||||
# #
|
||||
# As a counterpart to the access to the source code and rights to copy, #
|
||||
# modify and redistribute granted by the license, users are provided #
|
||||
# only with a limited warranty and the software's author, the holder of #
|
||||
# the economic rights, and the successive licensors have only limited #
|
||||
# liability. #
|
||||
# #
|
||||
# In this respect, the user's attention is drawn to the risks associated #
|
||||
# with loading, using, modifying and/or developing or reproducing the #
|
||||
# software by the user in light of its specific status of free software, #
|
||||
# that may mean that it is complicated to manipulate, and that also #
|
||||
# therefore means that it is reserved for developers and experienced #
|
||||
# professionals having in-depth computer knowledge. Users are therefore #
|
||||
# encouraged to load and test the software's suitability as regards #
|
||||
# their requirements in conditions enabling the security of their #
|
||||
# systems and/or data to be ensured and, more generally, to use and #
|
||||
# operate it in the same conditions as regards security. #
|
||||
# #
|
||||
# The fact that you are presently reading this means that you have had #
|
||||
# knowledge of the CeCILL-B license and that you accept its terms. #
|
||||
##########################################################################
|
||||
|
||||
PRG=$(basename $0)
|
||||
FILTER_TEST="$(realpath "$(dirname $0)/filterTest.sh")"
|
||||
|
||||
ATTACH_MODE="FOOTER"
|
||||
|
||||
usage () {
|
||||
echo "Usage: ${PRG} {NONE|FOOTER|ATTACHMENT|BOTH} mbox..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
########################################
|
||||
BOLD='\e[1m'
|
||||
RED='\e[0;31m'
|
||||
GREEN='\e[0;32m'
|
||||
YELLOW='\e[0;33m'
|
||||
BLUE='\e[0;34m'
|
||||
MAGENTA='\e[0;35m'
|
||||
CYAN='\e[0;36m'
|
||||
NC='\e[0m' # No Color
|
||||
NL='
|
||||
'
|
||||
|
||||
########################################
|
||||
[ "$#" -lt 2 ] && usage
|
||||
|
||||
ATTACH_MODE="$1"; shift
|
||||
|
||||
case "${ATTACH_MODE}" in
|
||||
""|NONE|FOOTER|ATTACHMENT|BOTH);;
|
||||
*) usage;;
|
||||
esac
|
||||
|
||||
for mbox in $*; do
|
||||
clear
|
||||
echo -e " ${GREEN}${BOLD}${mbox}${NC}\n"
|
||||
"${FILTER_TEST}" -s -m "${ATTACH_MODE}" "${mbox}"
|
||||
echo -en "\n(q = quit / default = continue)? "
|
||||
read rep
|
||||
case "${rep}" in
|
||||
"q" ) break;;
|
||||
esac
|
||||
done
|
@ -38,9 +38,8 @@
|
||||
# - installer l'utilitaire dos2unix
|
||||
# - le contenu de INSPECT_DIR doit être accessible en écriture pour le
|
||||
# proriétaire du script
|
||||
# - shrinkEMail et jirafeau.sh doivent être accessible en execution pour
|
||||
# le roriétaire du script
|
||||
# - il faut que root fasse avant :
|
||||
# - shrinkEMail doit être accessible en execution pour le proriétaire
|
||||
# - comme le programme n'a pas de privigèle, il faut que root fasse avant :
|
||||
# mkdir -p "${DIR_LOG}/pb/" ; chmod a+rwx "${DIR_LOG}/pb/"
|
||||
##########################################################################
|
||||
|
||||
@ -63,7 +62,6 @@ MAILS=/tmp/FILTER
|
||||
MAX_KEEP_IN_MAIL=5ki
|
||||
MAX_UPLOAD_SIZE=1Gi
|
||||
SHRINK_CMD=/home/filter/eMailShrinker
|
||||
JIRAFEAU_CMD=/home/filter/jirafeauAPI
|
||||
JIRAFEAU_URL=https://depot.${DOMAINNAME:-"kaz.bzh"}
|
||||
JIRAFEAU_LOCAL=http://depot
|
||||
MD5_CMD=/usr/bin/md5sum
|
||||
@ -80,20 +78,20 @@ KEEP_FAILED=true
|
||||
DEBUG=true
|
||||
|
||||
#################### FONCTIONS ############################################
|
||||
BOLD='[1m'
|
||||
RED='[0;31m'
|
||||
GREEN='[0;32m'
|
||||
YELLOW='[0;33m'
|
||||
BLUE='[0;34m'
|
||||
MAGENTA='[0;35m'
|
||||
CYAN='[0;36m'
|
||||
NC='[0m' # No Color
|
||||
BOLD='\e[1m'
|
||||
RED='\e[0;31m'
|
||||
GREEN='\e[0;32m'
|
||||
YELLOW='\e[0;33m'
|
||||
BLUE='\e[0;34m'
|
||||
MAGENTA='\e[0;35m'
|
||||
CYAN='\e[0;36m'
|
||||
NC='\e[0m' # No Color
|
||||
NL='
|
||||
'
|
||||
|
||||
#--------------------- Fichier de LOG -------------------
|
||||
LOG_FIC () {
|
||||
echo "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${TMP_LOG}"
|
||||
echo -e "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${TMP_LOG}"
|
||||
}
|
||||
|
||||
quitFilter () {
|
||||
@ -124,11 +122,11 @@ curlJirafeauSend () {
|
||||
# $4: name
|
||||
# $5: password
|
||||
|
||||
type=$3
|
||||
[ -z "${type}" ] && type="text/plain"
|
||||
LOG_FIC " - curl -X POST -F \"time=$1\" -F \"key=$5\" -F \"file=@$2;type=${type};filename=\\\"$4\\\"\" \"${JIRAFEAU_LOCAL}/a.php\""
|
||||
type="type=$3;"
|
||||
[ -z "$3" -o "$3" = "/" ] && type=""
|
||||
LOG_FIC " - curl -X POST -F \"time=$1\" -F \"key=$5\" -F \"file=@$2;${type}filename=\\\"$4\\\"\" \"${JIRAFEAU_LOCAL}/a.php\""
|
||||
for num in {1..2}; do
|
||||
OUTPUT=$(curl -X POST -F "time=$1" -F "key=$5" -F "file=@$2;type=${type};filename=\"$4\"" "${JIRAFEAU_LOCAL}/a.php")
|
||||
OUTPUT=$(curl -X POST -F "time=$1" -F "key=$5" -F "file=@$2;${type}filename=\"$4\"" "${JIRAFEAU_LOCAL}/a.php")
|
||||
read JIR_TOKEN <<< "${OUTPUT}"
|
||||
case "${JIR_TOKEN}" in
|
||||
"" | no | *Error* | \<* )
|
||||
@ -151,7 +149,7 @@ function check_skip_domains() {
|
||||
local domain="${email##*@}"
|
||||
|
||||
# Utiliser grep pour vérifier si le domaine est dans la liste des domaines à sauter
|
||||
if echo "$SKIP_DOMAINS" | grep -q -w "$domain"; then
|
||||
if echo "${SKIP_DOMAINS}" | grep -q -w "${domain}"; then
|
||||
echo "yes"
|
||||
return
|
||||
fi
|
||||
@ -162,7 +160,7 @@ function check_skip_domains() {
|
||||
}
|
||||
|
||||
#################### MAIN #################################################
|
||||
echo "${NL}${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : ${GREEN}######################################## filter start (log in ${TMP_LOG})${NC}" >> "${FIC_LOG}"
|
||||
echo -e "${NL}${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : ${GREEN}######################################## filter start (log in ${TMP_LOG})${NC}" >> "${FIC_LOG}"
|
||||
LOG_FIC "${GREEN}######################################## ${TMP_LOG} ${NC}"
|
||||
|
||||
if ! mkdir -p "${MAILS}"; then
|
||||
|
@ -36,22 +36,21 @@
|
||||
PRG=$(basename $0)
|
||||
|
||||
ATTACH_MODE="FOOTER"
|
||||
export SIMULATE=""
|
||||
|
||||
BOLD='[1m'
|
||||
RED='[0;31m'
|
||||
GREEN='[0;32m'
|
||||
YELLOW='[0;33m'
|
||||
BLUE='[0;34m'
|
||||
MAGENTA='[0;35m'
|
||||
CYAN='[0;36m'
|
||||
NC='[0m' # No Color
|
||||
BOLD='\e[1m'
|
||||
RED='\e[0;31m'
|
||||
GREEN='\e[0;32m'
|
||||
YELLOW='\e[0;33m'
|
||||
BLUE='\e[0;34m'
|
||||
MAGENTA='\e[0;35m'
|
||||
CYAN='\e[0;36m'
|
||||
NC='\e[0m' # No Color
|
||||
NL='
|
||||
'
|
||||
|
||||
TTY=$(tty)
|
||||
########################################
|
||||
LOG () {
|
||||
echo "$1" >> "${TTY}"
|
||||
echo -e "$1" 1>&2
|
||||
}
|
||||
|
||||
usage () {
|
||||
@ -64,6 +63,7 @@ while : ; do
|
||||
-h*) usage;;
|
||||
-v*) "${eMailShrinker}" -v; exit;;
|
||||
-g) DEBUG="-g"; shift;;
|
||||
-s) SIMULATE="echo"; shift;;
|
||||
-m) shift; ATTACH_MODE="$1"; shift;;
|
||||
*) break;;
|
||||
esac
|
||||
@ -83,11 +83,11 @@ mbox=$(realpath "$1")
|
||||
cd $(dirname $0)
|
||||
eMailShrinker="$(realpath "./eMailShrinker")"
|
||||
[ -x "${eMailShrinker}" ] || eMailShrinker="$(realpath "../../build/out/eMailShrinker")"
|
||||
[ -x "${eMailShrinker}" ] || ( echo "${RED}eMailShrinker not found${NC}" ; exit)
|
||||
[ -x "${eMailShrinker}" ] || ( echo -e "${RED}eMailShrinker not found${NC}" ; exit)
|
||||
|
||||
########################################
|
||||
dos2unix "${mbox}"
|
||||
DOMAINNAME="$(cat domainname)"
|
||||
[ -z "${SIMULATE}" ] && DOMAINNAME="$(cat domainname)"
|
||||
JIRAFEAU_URL="https://depot.${DOMAINNAME}"
|
||||
JIRAFEAU_LOCAL="${JIRAFEAU_URL}"
|
||||
|
||||
@ -99,8 +99,7 @@ curlJirafeauUpdate () {
|
||||
# $1: periode
|
||||
# $2: jirafeauItemRef
|
||||
|
||||
curl -X POST -d "u=$1" -d "h=$2" "${JIRAFEAU_LOCAL}/a.php"
|
||||
#"${jirafeauAPI}" -f "${JIRAFEAU_LOCAL}" -t "$1" update "$2"
|
||||
[ -z "${SIMULATE}" ] && curl -X POST -d "u=$1" -d "h=$2" "${JIRAFEAU_LOCAL}/a.php"
|
||||
}
|
||||
|
||||
curlJirafeauSend () {
|
||||
@ -110,11 +109,14 @@ curlJirafeauSend () {
|
||||
# $4: name
|
||||
# $5: password
|
||||
|
||||
type=$3
|
||||
[ -z "${type}" ] && type="text/plain"
|
||||
LOG "curl -X POST -F \"time=$1\" -F \"key=$5\" -F \"file=@$2;type=${type};filename=\\\"$4\\\"\" \"${JIRAFEAU_LOCAL}/a.php\""
|
||||
curl -X POST -F "time=$1" -F "key=$5" -F "file=@$2;type=${type};filename=\"$4\"" "${JIRAFEAU_LOCAL}/a.php" || exit 1
|
||||
#"${jirafeauAPI}" -f "${JIRAFEAU_LOCAL}" -t "$1" -s "1Gi" -c "${type}" -n "$4" send "$2" "$5"
|
||||
if [ -n "${SIMULATE}" ]; then
|
||||
echo -e "TokenXXX\nCodeX"
|
||||
return
|
||||
fi
|
||||
type="type=$3;"
|
||||
[ -z "$3" -o "$3" = "/" ] && type=""
|
||||
LOG "curl -X POST -F \"time=$1\" -F \"key=$5\" -F \"file=@$2;${type}filename=\\\"$4\\\"\" \"${JIRAFEAU_LOCAL}/a.php\""
|
||||
curl -X POST -F "time=$1" -F "key=$5" -F "file=@$2;${type}filename=\"$4\"" "${JIRAFEAU_LOCAL}/a.php" || exit 1
|
||||
}
|
||||
|
||||
########################################
|
||||
@ -126,19 +128,18 @@ echo -e "time: $(date "+%Y-%m-%d-%H:%M:%S")\nid: $(date +%s)" > "${TMP_DIR}/arch
|
||||
|
||||
########################################
|
||||
# affichage de la structure de départ
|
||||
LOG " - ${BLUE}mbox: ${mbox}${NC}"
|
||||
LOG " - ${BLUE}mbox: ${mbox}${NC}${YELLOW}"
|
||||
"${eMailShrinker}" -l "${mbox}"
|
||||
LOG
|
||||
LOG "${NC}"
|
||||
|
||||
########################################
|
||||
# recherche des prolongations des délais de grace
|
||||
"${eMailShrinker}" ${DEBUG} -u "${mbox}" > "${TMP_DIR}/url-to-refresh.txt" 2>> "${TTY}"
|
||||
"${eMailShrinker}" ${DEBUG} -u "${mbox}" > "${TMP_DIR}/url-to-refresh.txt"
|
||||
cat "${TMP_DIR}/url-to-refresh.txt" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK; do
|
||||
REMOTE_REF=$(echo "${REMOTE_LINK}" | sed -e 's/.*h=\([^&]*\).*/\1/' -e 's/.*http.*//')
|
||||
[ -z "${REMOTE_REF}" ] && continue
|
||||
LOG " - ${BLUE}update ${REMOTE_REF}${NC}"
|
||||
curlJirafeauUpdate "month" "${REMOTE_REF}" 2>> "${TTY}"
|
||||
LOG
|
||||
curlJirafeauUpdate "month" "${REMOTE_REF}"
|
||||
echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${TMP_DIR}/archive-content.txt"
|
||||
done
|
||||
|
||||
@ -167,7 +168,7 @@ cat "${TMP_DIR}/PJ-name.txt" | {
|
||||
LOG " - ${BLUE}find ${ATTACH_NAME} / (${ATTACH_CONTENT_TYPE}) / ${ATTACH_MEDIA} ${NC}"
|
||||
PASSWORD=$(apg -n 1 -m 12 -M cln)
|
||||
PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1)
|
||||
curlJirafeauSend "month" "${ATTACH_MEDIA}" "${ATTACH_CONTENT_TYPE}" "${ATTACH_NAME}" "${PASSWORD}" 2>> "${TTY}" > "${TMP_DIR}/one.txt"
|
||||
curlJirafeauSend "month" "${ATTACH_MEDIA}" "${ATTACH_CONTENT_TYPE}" "${ATTACH_NAME}" "${PASSWORD}" > "${TMP_DIR}/one.txt"
|
||||
|
||||
cat "${TMP_DIR}/one.txt" | {
|
||||
read JIR_TOKEN
|
||||
@ -175,7 +176,7 @@ cat "${TMP_DIR}/PJ-name.txt" | {
|
||||
case "${JIR_TOKEN}" in
|
||||
"" | no | *Error* | \<* )
|
||||
LOG " - ${RED}can't upload ${ATTACH_MEDIA} <${JIR_TOKEN}> <${JIR_CODE}>${NC}"
|
||||
cat "${TMP_DIR}/one.txt" >> "${TTY}"
|
||||
cat "${TMP_DIR}/one.txt" >&2
|
||||
echo "url:"
|
||||
exit 1
|
||||
;;
|
||||
@ -191,7 +192,7 @@ cat "${TMP_DIR}/PJ-name.txt" | {
|
||||
if [ "${NB_ATTACH}" -gt 1 ]; then
|
||||
PASSWORD=$(apg -n 1 -m 12 -M cln)
|
||||
PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1)
|
||||
curlJirafeauSend "month" "${TMP_DIR}/archive-content.txt" "text/kaz_email_archive" "archive_content" "${PASSWORD}" 2>> "${TTY}" > "${TMP_DIR}/one.txt" || exit 1
|
||||
curlJirafeauSend "month" "${TMP_DIR}/archive-content.txt" "text/kaz_email_archive" "archive_content" "${PASSWORD}" > "${TMP_DIR}/one.txt" || exit 1
|
||||
cat "${TMP_DIR}/one.txt" | {
|
||||
read JIR_TOKEN
|
||||
read JIR_CODE
|
||||
@ -221,12 +222,12 @@ LOG " - ${GREEN}ATTACH_MODE: ${ATTACH_MODE}${NC}"
|
||||
|
||||
########################################
|
||||
# substitution des pièces jointes par les codes fournis par jirafeau
|
||||
cat "${TMP_DIR}/PJ-Keys.txt" | "${eMailShrinker}" ${DEBUG} ${ATTACH_MODE} -s "5ki" "${mbox}" "${TMP_DIR}/new-mbox" 2>> "${TTY}" || exit 1
|
||||
cat "${TMP_DIR}/PJ-Keys.txt" | "${eMailShrinker}" ${DEBUG} ${ATTACH_MODE} -s "5ki" "${mbox}" "${TMP_DIR}/new-mbox" || exit 1
|
||||
|
||||
########################################
|
||||
# affichage de la structure à la fin
|
||||
LOG " - ${BLUE}new-mbox:${NC}"
|
||||
"${eMailShrinker}" -l "${TMP_DIR}/new-mbox" 2>> "${TTY}" || exit 1
|
||||
LOG " - ${BLUE}new-mbox:${NC}${YELLOW}"
|
||||
"${eMailShrinker}" -l "${TMP_DIR}/new-mbox" || ( LOG "${NC}" ; exit 1)
|
||||
|
||||
echo -e "\nresul in ${TMP_DIR}/new-mbox"
|
||||
echo -e "\n${NC}${GREEN}${BOLD}resul in ${TMP_DIR}/new-mbox${NC}"
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user