diff --git a/src/Jirafeau/a.php b/src/Jirafeau/a.php index d46ffa6..a6d701f 100644 --- a/src/Jirafeau/a.php +++ b/src/Jirafeau/a.php @@ -124,8 +124,9 @@ $message = ''; // ======================================== if (isset ($_REQUEST [A_RECORD]) && !empty ($_REQUEST [A_RECORD])) { if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_RECORD])) - returnError (M_BAD_SENDER_NAME); - $content = getSenderTrack ($_REQUEST [A_RECORD]).NL; + $content = false.NL; + else + $content = getSenderTrack ($_REQUEST [A_RECORD]).NL; header ('HTTP/1.0 200 OK'); header ('Content-Length: ' . strlen ($content)); header ('Content-Type: text/plain'); @@ -136,8 +137,9 @@ if (isset ($_REQUEST [A_RECORD]) && !empty ($_REQUEST [A_RECORD])) { // ======================================== if (isset ($_REQUEST [A_PERIOD]) && !empty ($_REQUEST [A_PERIOD])) { if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_PERIOD])) - returnError (M_BAD_SENDER_NAME); - $content = getSenderPeriod ($_REQUEST [A_PERIOD]).NL; + $content = DEFAULT_PERIOD.NL; + else + $content = getSenderPeriod ($_REQUEST [A_PERIOD]).NL; header ('HTTP/1.0 200 OK'); header ('Content-Length: ' . strlen ($content)); header ('Content-Type: text/plain'); @@ -308,13 +310,16 @@ function readArchiveFromLines ($lines) { case preg_match ("/^\s*time:\s*(\d{4}([:-]\d{2}){5})\s*$/i", $line, $matches): $archive [T_TIME] = $matches [1]; break; - case preg_match ("/^\s*sender:\s*(([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})\s*$/i", $line, $matches): + // XXX + //case preg_match ("/^\s*sender:\s*(([a-z0-9_+-]+)(\.[a-z0-9_+-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})\s*$/i", $line, $matches): + case preg_match ("/^\s*sender:\s*(([a-z0-9_=+-]+)(\.[a-z0-9_=+-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})\s*$/i", $line, $matches): $archive [T_SENDER] = $matches [1]; break; - case preg_match ("/^\s*new:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches): + // XXX issue ")" + case preg_match ("/^\s*new:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\)?\s*$/", $line, $matches): $archive [T_NEW][] = [$matches [1], $matches [2]]; break; - case preg_match ("/^\s*old:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches): + case preg_match ("/^\s*old:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\)?\s*$/", $line, $matches): $archive [T_OLD][] = [$matches [1], $matches [2]]; break; case preg_match ("/^\s*sign:\s*([0-9a-zA-Z_-]+)\s*$/", $line, $matches): @@ -495,9 +500,10 @@ if ($doUpload) { // ======================================== if ($doUpdate) { $maxTime = time ()+period2seconds ($_REQUEST [A_UPDATE]); - $linkName = $_REQUEST [A_HASH]; - if (!preg_match ('/[0-9a-zA-Z_-]+$/', $linkName)) + // XXX issue ")" + if (!preg_match ('/([0-9a-zA-Z_-]+)\)?$/', $_REQUEST [A_HASH], $matches)) returnError (t ('FILE_404')); + $linkName = $matches [1]; $link = jirafeau_get_link ($linkName); if (count ($link) == 0) returnError (t ('FILE_404')); @@ -523,6 +529,8 @@ if ($doUpdate) { $sender = ''; $senderError = false; if (isset ($_REQUEST [A_SENDER]) && !empty ($_REQUEST [A_SENDER])) { + // XXX + //if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_SENDER])) if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_SENDER])) $senderError=true; else { diff --git a/src/bash/filter.sh b/src/bash/filter.sh index eb0a403..4e986bd 100644 --- a/src/bash/filter.sh +++ b/src/bash/filter.sh @@ -65,16 +65,26 @@ ARCHIVE_TITLE="archive_content" ARCHIVE_MIME="text/kaz_email_archive" #################### FONCTIONS ############################################ +BOLD='' +RED='' +GREEN='' +YELLOW='' +BLUE='' +MAGENTA='' +CYAN='' +NC='' # No Color +NL=' +' #--------------------- Fichier de LOG ------------------- LOG_FIC() { - echo -e "$(date +%d-%m-%Y-%H-%M-%S) : $*" >> "${FIC_LOG}" + echo "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${FIC_LOG}" } #################### MAIN ################################################# -LOG_FIC "------------------------------------------------------" -LOG_FIC "--------------- debut de programme -------------------" +echo "${NL}" >> "${FIC_LOG}" +LOG_FIC "${GREEN}######################################## filter start${NC}" -mkdir -p "${MAILS}" || { LOG_FIC "impossible de creer ce dossier"; exit "${EX_UNAVAILABLE}"; } +mkdir -p "${MAILS}" || { LOG_FIC "${RED}impossible de creer ce dossier${NC}"; exit "${EX_UNAVAILABLE}"; } MAIL_SOURCE=$(echo $@ | awk 'BEGIN{FS=" "} {print $2}') DATE_TEMPS=$(date "+%Y-%m-%d-%H:%M:%S") REP_PIECE_JOINTE="${MAILS}/${DATE_TEMPS}_${MAIL_SOURCE}_$$" @@ -84,6 +94,13 @@ if [ -n "$(echo "${PERIOD}" | grep -e minute -e hour -e day -e week -e month -e JIRAFEAU_TIME="${PERIOD}" fi +LOG_FIC "\n" \ + " MAIL_SOURCE : ${YELLOW}${MAIL_SOURCE}${NC}\n" \ + " DATE_TEMPS : ${YELLOW}${DATE_TEMPS=}${NC}\n" \ + " TRACK : ${YELLOW}${TRACK}${NC}\n" \ + " PERIOD : ${YELLOW}${PERIOD}${NC}\n" \ + " JIRAFEAU_TIME: ${YELLOW}${JIRAFEAU_TIME}${NC}" + cd "${INSPECT_DIR}" || { echo "${INSPECT_DIR} does not exist"; exit "${EX_TEMPFAIL}"; } # lien renvoyé par le téléverssement @@ -96,7 +113,7 @@ ARCHIVE_CONTENT="${REP_PIECE_JOINTE}/archive-content.txt" # Clean up when done or when aborting. trap "rm -rf in.$$ in.$$.altered ${REP_PIECE_JOINTE}" 0 1 2 3 15 -cat > "in.$$" || { LOG_FIC "Cannot save mail to file"; exit "${EX_TEMPFAIL}"; } +cat > "in.$$" || { LOG_FIC "${RED}Cannot save mail to file${NC}"; exit "${EX_TEMPFAIL}"; } # XXX trace # cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak" @@ -108,7 +125,7 @@ mkdir -p "${REP_PIECE_JOINTE}/" echo "time: ${DATE_TEMPS}\nid: $(date +%s)" > "${ARCHIVE_CONTENT}" [ -n "${TRACK}" ] && echo "sender: ${MAIL_SOURCE}" >> "${ARCHIVE_CONTENT}" -LOG_FIC "${SHRINK_CMD} -u \"${INSPECT_DIR}/in.$$\" 2>> \"${FIC_LOG}\" > \"${OLD_LINKS}\"" +LOG_FIC "${CYAN}${SHRINK_CMD} -u \"${INSPECT_DIR}/in.$$\" 2>> \"${FIC_LOG}\" > \"${OLD_LINKS}\"${NC}" "${SHRINK_CMD}" -u "${INSPECT_DIR}/in.$$" 2>> "${FIC_LOG}" > "${OLD_LINKS}" cat "${OLD_LINKS}" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK @@ -117,14 +134,14 @@ do [ -z "${REMOTE_REF}" ] && continue REMOTE_KEY=$(echo "${REMOTE_LINK}" | grep "k=" | sed 's%.*k=\([^&]*\).*%\1%') # update periode for download - LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" update \"${REMOTE_REF}\" 2>&1 >> \"${FIC_LOG}\"" + LOG_FIC " - ${CYAN}\"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" update \"${REMOTE_REF}\" 2>&1 >> \"${FIC_LOG}\"${NC}" "${JIRAFEAU_CMD}" -f "${JIRAFEAU_LOCAL}" -t "${JIRAFEAU_TIME}" update "${REMOTE_REF}" 2>&1 >> "${FIC_LOG}" echo "old: ${REMOTE_REF} ${REMOTE_KEY}" >> "${ARCHIVE_CONTENT}" done -LOG_FIC " - archive starts with: $(cat ${ARCHIVE_CONTENT})" +LOG_FIC " - archive starts with: ${NL}${YELLOW}$(cat ${ARCHIVE_CONTENT})${NC}" # Etape extraction des pieces jointes -LOG_FIC "${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_DIR}/in.$$" +LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_DIR}/in.$$ ${NC}" "${SHRINK_CMD}" -s "${MAX_KEEP_IN_MAIL}" -d "${REP_PIECE_JOINTE}" "${INSPECT_DIR}/in.$$" 2>> "${FIC_LOG}" | { while read ATTACH_TMP_NAME do @@ -140,25 +157,25 @@ LOG_FIC "${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_D # Etape de televersement des pieces jointes PASSWORD=$(apg -n 1 -m 12) PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1) - LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"${ATTACH_CONTENT_TYPE}\" -n \"${ATTACH_NAME}\" send \"${ATTACH_MEDIA}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\"" + LOG_FIC " - ${CYAN}\"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"${ATTACH_CONTENT_TYPE}\" -n \"${ATTACH_NAME}\" send \"${ATTACH_MEDIA}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\"${NC}" "${JIRAFEAU_CMD}" -f "${JIRAFEAU_LOCAL}" -t "${JIRAFEAU_TIME}" -s "${MAX_UPLOAD_SIZE}" -c "${ATTACH_CONTENT_TYPE}" -n "${ATTACH_NAME}" send "${ATTACH_MEDIA}" "${PASSWORD}" 2>> "${FIC_LOG}" > "${ONE_LINK}" cat "${ONE_LINK}" | { read JIR_TOKEN read JIR_CODE - LOG_FIC " - Jirafeau retourne ${JIR_TOKEN} et ${JIR_CODE}" + LOG_FIC " - return code ${YELLOW}${JIR_TOKEN}${NC} / ${YELLOW}${JIR_CODE}${NC}" case "${JIR_TOKEN}" in "" | no | *Error* | \<* ) - LOG_FIC " - impossible de televerser ${ATTACH_TMP_FILE} (${JIR_TOKEN}), il ne sera pas remplace dans le message" + LOG_FIC " - ${RED}impossible de televerser ${ATTACH_TMP_FILE} (${JIR_TOKEN}), il ne sera pas remplace dans le message${NC}" echo "new:" ;; * ) - LOG_FIC " - substitution par ${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}" + LOG_FIC " - change by link ${YELLOW}${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}${NC}" echo "url: ${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}" echo "new: ${JIR_TOKEN} ${PASSWORD_MD5}" >> "${ARCHIVE_CONTENT}" ;; esac } - LOG_FIC " - supprimer l'extraction ${ATTACH_TMP_FILE}" + LOG_FIC " - remove extraction file ${ATTACH_TMP_FILE}" rm -f "${ATTACH_TMP_FILE}" done # Création de l'archive @@ -166,31 +183,33 @@ LOG_FIC "${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_D if [ \( -n "${TRACK}" -a "${NB_ATTACH}" -gt 0 \) -o "${NB_ATTACH}" -gt 1 ]; then PASSWORD=$(apg -n 1 -m 12) PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1) - LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"${ARCHIVE_MIME}\" -n \"${ARCHIVE_TITLE}\" send \"${ARCHIVE_CONTENT}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\"" + LOG_FIC " - ${MAGENTA}upload archive${NC}" + LOG_FIC " - ${CYAN}\"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"${ARCHIVE_MIME}\" -n \"${ARCHIVE_TITLE}\" send \"${ARCHIVE_CONTENT}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\"${NC}" "${JIRAFEAU_CMD}" -f "${JIRAFEAU_LOCAL}" -t "${JIRAFEAU_TIME}" -s "${MAX_UPLOAD_SIZE}" -c "${ARCHIVE_MIME}" -n "${ARCHIVE_TITLE}" send "${ARCHIVE_CONTENT}" "${PASSWORD}" 2>> "${FIC_LOG}" > "${ONE_LINK}" fi + LOG_FIC " - final archive content: ${NL}${YELLOW}$(cat ${ARCHIVE_CONTENT})${NC}" if [ "${NB_ATTACH}" -gt 1 ]; then cat "${ONE_LINK}" | { read JIR_TOKEN read JIR_CODE - LOG_FIC " - Jirafeau retourne ${JIR_TOKEN} et ${JIR_CODE}" + LOG_FIC " - return code ${YELLOW}${JIR_TOKEN}${NC} / ${YELLOW}${JIR_CODE}${NC}" case "${JIR_TOKEN}" in "" | no | *Error* | \<* ) - LOG_FIC " - impossible de televerser l'archive (${JIR_TOKEN}), il ne sera pas remplace dans le message" + LOG_FIC " - ${RED}can't upload archive (${JIR_TOKEN}), substitution couldn't be done${NC}" echo "arch: bad" ;; * ) - LOG_FIC " - ajoute de l'archive ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}" + LOG_FIC " - add archive ${YELLOW}${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}${NC}" echo "arch: ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}" ;; esac } else - LOG_FIC " - pas d'archive (moins de 2 PJ)" + LOG_FIC " - no archive (less than 2 attach file)" echo "arch: none" fi # Etape de substitution - LOG_FIC "${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" \"${INSPECT_DIR}/in.$$\" \"${INSPECT_DIR}/in.$$.altered\" 2>> \"${FIC_LOG}\"" + LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" \"${INSPECT_DIR}/in.$$\" \"${INSPECT_DIR}/in.$$.altered\" 2>> \"${FIC_LOG}\"${NC}" } | "${SHRINK_CMD}" -s "${MAX_KEEP_IN_MAIL}" "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.altered" 2>> "${FIC_LOG}" # XXX trace @@ -201,22 +220,23 @@ if [ "$(wc -l < "${ARCHIVE_CONTENT}")" -ge 3 ]; then # verification de taille finale actualSize=$(wc -c < "${INSPECT_DIR}/in.$$.altered") if [ ${actualSize} -ge $MAX_FINAL_SIZE ]; then - LOG_FIC " - message trop gros apres regime ${INSPECT_DIR}/in.$$.altered (${actualSize})" + LOG_FIC " - ${RED}too big even after diet ${INSPECT_DIR}/in.$$.altered (${actualSize})${NC}" exit "${EX_TOO_LARGE}"; fi - LOG_FIC " - envoi de la commande : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered" + LOG_FIC " - ${GREEN}send with : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered ${NC}" ${SENDMAIL} "$@" < "${INSPECT_DIR}/in.$$.altered" else # verification de taille finale actualSize=$(wc -c < "${INSPECT_DIR}/in.$$") if [ ${actualSize} -ge $MAX_FINAL_SIZE ]; then - LOG_FIC " - message trop gros sans regime ${INSPECT_DIR}/in.$$ (${actualSize})" + LOG_FIC " - ${RED}too big without diet ${INSPECT_DIR}/in.$$ (${actualSize}) ${NC}" exit "${EX_TOO_LARGE}"; fi - LOG_FIC " - pas de piece jointe" + LOG_FIC " - ${GREEN}send without attach file${NC}" ${SENDMAIL} "$@" < "in.$$" fi +LOG_FIC "${GREEN}######################################## filter stop${NC}" exit 0 ##########################################################################