Compare commits

..

No commits in common. "99e888f5d115512cb8c1ecde09a2b6718f74ba86" and "1d19e111c3b73679cdd9dc4baf93e471c6b1c0a1" have entirely different histories.

6 changed files with 299 additions and 1230 deletions

View File

@ -58,12 +58,12 @@ JIR_OUT = $(patsubst %, $(OUT_DIR)/%, $(JIR_PRG))
## FLAGS ###############################
#DFLAGS = -O2 -DDISABLE_LOG
DFLAGS = -g -Wall
DFLAGS = -O2 -DDISABLE_LOG
#DFLAGS = -g -Wall
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR) -std=c++11
LFLAGS = -L$(LIB_DIR) -lboost_system -lboost_program_options -lboost_filesystem -lcurl -lcrypto -lstdc++
LFLAGS = -L$(LIB_DIR) -Bstatic -lstdc++ -lcurl -lcrypto -lboost_system -lboost_program_options -lboost_filesystem
CC = g++
## RULES ###############################

File diff suppressed because it is too large Load Diff

View File

@ -46,7 +46,7 @@ $link = jirafeau_get_link($link_name);
if (count($link) == 0) {
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>' . t('FILE_404') .
'</p></div>';
'</p></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
@ -76,7 +76,7 @@ if (!file_exists(VAR_FILES . $p . $link['hash'])) {
jirafeau_delete_link($link_name);
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>'.t('FILE_NOT_AVAIL').
'</p></div>';
'</p></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
@ -86,28 +86,27 @@ if (!empty($delete_code) && $delete_code == $link['link_code']) {
if (isset($_POST['do_delete'])) {
jirafeau_delete_link($link_name);
echo '<div class="message"><p>'.t('FILE_DELETED').
'</p></div>';
'</p></div>';
} else { ?>
<div>
<form action="f.php" method="post" id="submit_delete_post" class="form login">
<input type="hidden" name="do_delete" value=1/>
<fieldset>
<legend> <?php echo t('CONFIRM_DEL') ?> </legend>
<table>
<tr><td>
<?php echo t('GONNA_DEL') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' ?>
</td></tr>
<tr><td>
<?php echo t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' ?>
</td></tr>
<tr><td>
<input type="submit" id="submit_delete" value="<?php echo t('DELETE'); ?>"
<?php $action_delete="'f.php?h=' . $link_name . '&amp;d=' . $delete_code'; document.getElementById('submit_delete').submit ();"; ?>
onclick="document.getElementById('submit_delete_post').action='<?php echo $action_delete; ?>" />
</td></tr>
</table>
</fieldset></form></div><?php
}
<form action="f.php" method="post" id="submit_delete_post" class="form login">
<input type="hidden" name="do_delete" value=1/>
<fieldset>
<legend> <?php echo t('CONFIRM_DEL') ?> </legend>
<table>
<tr><td>
<?php echo t('GONNA_DEL') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' ?>
</td></tr>
<tr><td>
<?php echo t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' ?>
</td></tr>
<tr><td>
<input type="submit" id="submit_delete" value="<?php echo t('DELETE'); ?>" <?php $action_delete="'f.php?h=' . $link_name . '&amp;d=' . $delete_code'; document.getElementById('submit_delete').submit ();"; ?>
onclick="document.getElementById('submit_delete_post').action='<?php echo $action_delete; ?>"/>
</td></tr>
</table>
</fieldset></form></div><?php
}
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
@ -116,9 +115,9 @@ if ($link['time'] != JIRAFEAU_INFINITY && time() > $link['time']) {
jirafeau_delete_link($link_name);
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>'.
t('FILE_EXPIRED') . ' ' .
t('FILE_DELETED') .
'</p></div>';
t('FILE_EXPIRED') . ' ' .
t('FILE_DELETED') .
'</p></div>';
require(JIRAFEAU_ROOT . 'lib/template/footer.php');
exit;
}
@ -126,7 +125,7 @@ if ($link['time'] != JIRAFEAU_INFINITY && time() > $link['time']) {
if (empty($crypt_key) && $link['crypted']) {
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>' . t('FILE_404') .
'</p></div>';
'</p></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
@ -140,16 +139,16 @@ if (!empty($link['key'])) {
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div>' .
'<form action="f.php" method="post" id="submit_post" class="form login">'; ?>
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
echo '<fieldset>' .
'<legend>' . t('PSW_PROTEC') .
'</legend><table><tr><td>' .
t('GIMME_PSW') . ' : ' .
'<input type = "password" name = "key" />' .
'</td></tr>' .
'<tr><td>' .
t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
'</td></tr>';
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
echo '<fieldset>' .
'<legend>' . t('PSW_PROTEC') .
'</legend><table><tr><td>' .
t('GIMME_PSW') . ' : ' .
'<input type = "password" name = "key" />' .
'</td></tr>' .
'<tr><td>' .
t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
'</td></tr>';
if ($link['onetime'] == 'O') {
echo '<tr><td id="self_destruct">' .
@ -164,13 +163,13 @@ if (!empty($link['key'])) {
document.getElementById('submit_download').submit ();"/><?php
if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
?><input type="submit" id = "submit_preview" value="<?php echo t('PREVIEW'); ?>"
onclick="document.getElementById('submit_post').action='<?php
onclick="document.getElementById('submit_post').action='<?php
echo 'f.php?h=' . $link_name . '&amp;p=1';
if (!empty($crypt_key)) {
echo '&amp;k=' . urlencode($crypt_key);
} ?>';
document.getElementById('submit_preview').submit ();"/><?php
}
}
echo '</td></tr></table></fieldset></form></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
@ -182,7 +181,7 @@ if (!empty($link['key'])) {
sleep(2);
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>' . t('ACCESS_KO') .
'</p></div>';
'</p></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
@ -192,38 +191,38 @@ if (!empty($link['key'])) {
if (!$password_challenged && !$do_download && !$do_preview) {
require(JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div>' .
'<form action="f.php" method="post" id="submit_post" class="form download">'; ?>
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
echo '<fieldset><legend>' . jirafeau_escape($link['file_name']) . '</legend><table>' .
'<tr><td>' .
t('NOW_DOWNLOADING') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' .
'</td></tr>' .
'<tr><td>' .
t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
'</td></tr>';
'<form action="f.php" method="post" id="submit_post" class="form download">'; ?>
<input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
echo '<fieldset><legend>' . jirafeau_escape($link['file_name']) . '</legend><table>' .
'<tr><td>' .
t('NOW_DOWNLOADING') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' .
'</td></tr>' .
'<tr><td>' .
t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
'</td></tr>';
if ($link['onetime'] == 'O') {
echo '<tr><td id="self_destruct">' .
t('AUTO_DESTRUCT') .
'</td></tr>';
t('AUTO_DESTRUCT') .
'</td></tr>';
} ?>
<tr><td><input type="submit" id = "submit_download" value="<?php echo t('DL'); ?>"
onclick="document.getElementById('submit_post').action='<?php
<tr><td><input type="submit" id = "submit_download" value="<?php echo t('DL'); ?>"
onclick="document.getElementById('submit_post').action='<?php
echo 'f.php?h=' . $link_name . '&amp;d=1';
if (!empty($crypt_key)) {
echo '&amp;k=' . urlencode($crypt_key);
} ?>';
document.getElementById('submit_post').submit ();"/><?php
if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
?><input type="submit" id = "submit_preview" value="<?php echo t('PREVIEW'); ?>"
onclick="document.getElementById('submit_post').action='<?php
if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
?><input type="submit" id = "submit_preview" value="<?php echo t('PREVIEW'); ?>"
onclick="document.getElementById('submit_post').action='<?php
echo 'f.php?h=' . $link_name . '&amp;p=1';
if (!empty($crypt_key)) {
echo '&amp;k=' . urlencode($crypt_key);
} ?>';
document.getElementById('submit_post').submit ();"/><?php
}
}
echo '</td></tr>';
echo '</table></fieldset></form></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
@ -289,4 +288,3 @@ if ($link['onetime'] == 'O') {
exit;
?>

View File

@ -48,12 +48,11 @@ EX_TEMPFAIL=75
EX_UNAVAILABLE=69
EX_TOO_LARGE=552
INSPECT_DIR=/var/spool/filter
DIR_LOG=/var/log/mail
FIC_LOG=${DIR_LOG}/filter.log
FIC_LOG=/var/log/mail/filter.log
SENDMAIL="/usr/sbin/sendmail -G -i"
MAILS=/tmp/FILTER
MAX_KEEP_IN_MAIL=5ki
MAX_UPLOAD_SIZE=1Gi
MAX_KEEP_IN_MAIL=24ki
MAX_UPLOAD_SIZE=100Mi
SHRINK_CMD=/home/filter/eMailShrinker
JIRAFEAU_CMD=/home/filter/jirafeauAPI
JIRAFEAU_URL=https://depot.${DOMAINNAME:-"kaz.bzh"}
@ -61,68 +60,23 @@ JIRAFEAU_LOCAL=http://depot
JIRAFEAU_TIME=month
MD5_CMD=/usr/bin/md5sum
DISCLAMER_CMD=altermime
MAX_FINAL_SIZE=307200 # 300ki
ARCHIVE_TITLE="archive_content"
ARCHIVE_MIME="text/kaz_email_archive"
KEEP_FAILED=true
MAX_FINAL_SIZE=204800 # 200ki
#################### FONCTIONS ############################################
BOLD=''
RED=''
GREEN=''
YELLOW=''
BLUE=''
MAGENTA=''
CYAN=''
NC='' # No Color
NL='
'
#--------------------- Fichier de LOG -------------------
LOG_FIC () {
echo "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${FIC_LOG}"
}
quitFilter () {
LOG_FIC "${GREEN}######################################## filter stop${NC}"
exit $1
}
keepFailed () {
[ -z "${KEEP_FAILED}" ] && return
mkdir -p "${DIR_LOG}/pb/"
cp "$1" "${DIR_LOG}/pb/"
LOG_FIC() {
echo "$(date +%d-%m-%Y-%H-%M-%S) : $*" >> "${FIC_LOG}"
}
#################### MAIN #################################################
echo "${NL}" >> "${FIC_LOG}"
LOG_FIC "${GREEN}######################################## filter start${NC}"
LOG_FIC "------------------------------------------------------"
LOG_FIC "--------------- debut de programme -------------------"
if ! mkdir -p "${MAILS}"; then
LOG_FIC "${RED}Can't mkdir ${MAILS} ${NC}"
quitFilter "${EX_UNAVAILABLE}"
fi
mkdir -p "${MAILS}" || { LOG_FIC "impossible de creer ce dossier"; 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}_$$"
TRACK=$(curl "${JIRAFEAU_LOCAL}/a.php?r=${MAIL_SOURCE}" 2>/dev/null)
PERIOD=$(curl "${JIRAFEAU_LOCAL}/a.php?p=${MAIL_SOURCE}" 2>/dev/null)
if [ -n "$(echo "${PERIOD}" | grep -e minute -e hour -e day -e week -e month -e quarter 2>/dev/null)" ]; then
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}"
if ! cd "${INSPECT_DIR}"; then
echo "${INSPECT_DIR} does not exist"
quitFilter "${EX_TEMPFAIL}"
fi
REP_PIECE_JOINTE=$(echo "${MAILS}/${DATE_TEMPS}_${MAIL_SOURCE}_$$")
cd "${INSPECT_DIR}" || { echo "${INSPECT_DIR} does not exist"; exit "${EX_TEMPFAIL}"; }
# lien renvoyé par le téléverssement
ONE_LINK="${REP_PIECE_JOINTE}/one.txt"
@ -130,18 +84,11 @@ ONE_LINK="${REP_PIECE_JOINTE}/one.txt"
OLD_LINKS="${REP_PIECE_JOINTE}/url-to-refresh.txt"
# contenu de l'archive
ARCHIVE_CONTENT="${REP_PIECE_JOINTE}/archive-content.txt"
# create if error
JIRAFEAU_ERROR="${REP_PIECE_JOINTE}/jirafeau-error.txt"
# Clean up when done or when aborting.
trap "rm -rf in.$$ in.$$.altered ${REP_PIECE_JOINTE}" 0 1 2 3 15
if ! cat > "in.$$"; then
LOG_FIC "${RED}Cannot save mail to file${NC}"
quitFilter "${EX_TEMPFAIL}"
fi
LOG_FIC "\n" \
" size: ${YELLOW}$(wc -c < "${INSPECT_DIR}/in.$$")${NC}"
cat > "in.$$" || { LOG_FIC "Cannot save mail to file"; exit "${EX_TEMPFAIL}"; }
# XXX trace
# cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak"
@ -150,10 +97,11 @@ mkdir -p "${REP_PIECE_JOINTE}/"
>"${ARCHIVE_CONTENT}"
# Etape de rafraichissement des anciens fichiers inclus
echo "time: ${DATE_TEMPS}\nid: $(date +%s)" > "${ARCHIVE_CONTENT}"
[ -n "${TRACK}" ] && echo "sender: ${MAIL_SOURCE}" >> "${ARCHIVE_CONTENT}"
LOG_FIC "${CYAN}${SHRINK_CMD} -u \"${INSPECT_DIR}/in.$$\" 2>> \"${FIC_LOG}\" > \"${OLD_LINKS}\"${NC}"
cat > "${ARCHIVE_CONTENT}" <<EOF
src: ${MAIL_SOURCE}
time: ${DATE_TEMPS}
EOF
LOG_FIC "${SHRINK_CMD} -u \"${INSPECT_DIR}/in.$$\" 2>> \"${FIC_LOG}\" > \"${OLD_LINKS}\""
"${SHRINK_CMD}" -u "${INSPECT_DIR}/in.$$" 2>> "${FIC_LOG}" > "${OLD_LINKS}"
cat "${OLD_LINKS}" | grep "${JIRAFEAU_URL}" | while read REMOTE_LINK
@ -162,14 +110,14 @@ do
[ -z "${REMOTE_REF}" ] && continue
REMOTE_KEY=$(echo "${REMOTE_LINK}" | grep "k=" | sed 's%.*k=\([^&]*\).*%\1%')
# update periode for download
LOG_FIC " - ${CYAN}\"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" update \"${REMOTE_REF}\" 2>&1 >> \"${FIC_LOG}\"${NC}"
LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -t \"${JIRAFEAU_TIME}\" update \"${REMOTE_REF}\" 2>&1 >> \"${FIC_LOG}\""
"${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: ${NL}${YELLOW}$(cat ${ARCHIVE_CONTENT})${NC}"
LOG_FIC " - archive starts with: $(cat ${ARCHIVE_CONTENT})"
# Etape extraction des pieces jointes
LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_DIR}/in.$$ ${NC}"
LOG_FIC "${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${INSPECT_DIR}/in.$$"
"${SHRINK_CMD}" -s "${MAX_KEEP_IN_MAIL}" -d "${REP_PIECE_JOINTE}" "${INSPECT_DIR}/in.$$" 2>> "${FIC_LOG}" | {
while read ATTACH_TMP_NAME
do
@ -179,101 +127,86 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
ATTACH_NAME=$(grep "^Name: " "${ATTACH_TMP_NAME}/meta" | cut -c 7- )
ATTACH_CONTENT_TYPE=$(grep "^Content-Type: " "${ATTACH_TMP_NAME}/meta" | cut -c 15- )
else
LOG_FIC " - ${RED}no ATTACH_TMP_NAME (${ATTACH_TMP_NAME}) ${NC}"
# XXX error
continue
fi
# 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 " - ${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}"
LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"${ATTACH_CONTENT_TYPE}\" -n \"${ATTACH_NAME}\" send \"${ATTACH_MEDIA}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\""
"${JIRAFEAU_CMD}" -f "${JIRAFEAU_LOCAL}" -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 " - return code ${YELLOW}${JIR_TOKEN}${NC} / ${YELLOW}${JIR_CODE}${NC}"
LOG_FIC " - Jirafeau retourne ${JIR_TOKEN} et ${JIR_CODE}"
case "${JIR_TOKEN}" in
"" | no | *Error* | \<* )
LOG_FIC " - ${RED}Can't upload <${ATTACH_NAME}> <${ATTACH_CONTENT_TYPE}> <$(wc -c < "${ATTACH_MEDIA}")> (${JIR_TOKEN}) <in.$$.bak>. It will be not change in e-mail.${NC}"
"" | no | *Error* | \<* )
LOG_FIC " - impossible de televerser ${ATTACH_TMP_FILE} (${JIR_TOKEN}), il ne sera pas remplace dans le message"
echo "new:"
keepFailed "${INSPECT_DIR}/in.$$"
echo "UPLOAD_FAIL" >> "${JIRAFEAU_ERROR}"
;;
* )
LOG_FIC " - change by link ${YELLOW}${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}${NC}"
LOG_FIC " - substitution par ${JIRAFEAU_URL}/f.php?d=1&h=${JIR_TOKEN}&k=${PASSWORD_MD5}"
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}"
rm -f "${ATTACH_TMP_FILE}"
done
# Création de l'archive
NB_ATTACH=$(grep -e "^old: " -e "^new: " "${ARCHIVE_CONTENT}" | wc -l)
if [ \( -n "${TRACK}" -a "${NB_ATTACH}" -gt 0 \) -o "${NB_ATTACH}" -gt 1 ]; then
if [ "$(wc -l < "${ARCHIVE_CONTENT}")" -ge 4 ]; then
PASSWORD=$(apg -n 1 -m 12)
PASSWORD_MD5=$(echo -n ${PASSWORD} | ${MD5_CMD} | cut -d \ -f 1)
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
LOG_FIC " - \"${JIRAFEAU_CMD}\" -f \"${JIRAFEAU_LOCAL}\" -s \"${MAX_UPLOAD_SIZE}\" -c \"text/plain\" -n \"archive_content\" send \"${ARCHIVE_CONTENT}\" \"${PASSWORD}\" 2>> \"${FIC_LOG}\" > \"${ONE_LINK}\""
"${JIRAFEAU_CMD}" -f "${JIRAFEAU_LOCAL}" -s "${MAX_UPLOAD_SIZE}" -c "text/plain" -n "archive_content" send "${ARCHIVE_CONTENT}" "${PASSWORD}" 2>> "${FIC_LOG}" > "${ONE_LINK}"
cat "${ONE_LINK}" | {
read JIR_TOKEN
read JIR_CODE
LOG_FIC " - return code ${YELLOW}${JIR_TOKEN}${NC} / ${YELLOW}${JIR_CODE}${NC}"
LOG_FIC " - Jirafeau retourne ${JIR_TOKEN} et ${JIR_CODE}"
case "${JIR_TOKEN}" in
"" | no | *Error* | \<* )
LOG_FIC " - ${RED}can't upload archive (${JIR_TOKEN}) <in.$$.bak>, substitution couldn't be done${NC}"
LOG_FIC " - impossible de televerser l'archive (${JIR_TOKEN}), il ne sera pas remplace dans le message"
echo "arch: bad"
keepFailed "${INSPECT_DIR}/in.$$"
echo "ARCHIVE_FAIL" >> "${JIRAFEAU_ERROR}"
;;
* )
LOG_FIC " - add archive ${YELLOW}${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}${NC}"
LOG_FIC " - ajoute de l'archive ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}"
echo "arch: ${JIRAFEAU_URL}/a.php?g=${JIR_TOKEN}~${PASSWORD_MD5}"
;;
esac
}
else
LOG_FIC " - no archive (less than 2 attach file)"
LOG_FIC " - pas d'archive (moins de 2 PJ)"
echo "arch: none"
fi
# Etape de substitution
LOG_FIC "${CYAN}${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" \"${INSPECT_DIR}/in.$$\" \"${INSPECT_DIR}/in.$$.altered\" 2>> \"${FIC_LOG}\"${NC}"
LOG_FIC "${SHRINK_CMD} -s \"${MAX_KEEP_IN_MAIL}\" \"${INSPECT_DIR}/in.$$\" \"${INSPECT_DIR}/in.$$.altered\" 2>> \"${FIC_LOG}\""
} | "${SHRINK_CMD}" -s "${MAX_KEEP_IN_MAIL}" "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.altered" 2>> "${FIC_LOG}"
# XXX trace
# cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.altered" /var/mail/tmp/
if [ -s "${JIRAFEAU_ERROR}" ]; then
LOG_FIC " - ${RED}upload fail${NC}"
quitFilter "${EX_TEMPFAIL}"
fi
# Etape choix de modification du message d'origine
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 " - ${RED}too big even after diet ${INSPECT_DIR}/in.$$.altered (${actualSize})${NC}"
keepFailed "${INSPECT_DIR}/in.$$"
quitFilter "${EX_TOO_LARGE}"
LOG_FIC " - message trop gros apres regime ${INSPECT_DIR}/in.$$.altered (${actualSize})"
exit "${EX_TOO_LARGE}";
fi
LOG_FIC " - ${GREEN}send with : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered ${NC}"
LOG_FIC " - envoi de la commande : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered"
${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 " - ${RED}too big without diet ${INSPECT_DIR}/in.$$ (${actualSize}) ${NC}"
keepFailed "${INSPECT_DIR}/in.$$"
quitFilter "${EX_TOO_LARGE}"
LOG_FIC " - message trop gros sans regime ${INSPECT_DIR}/in.$$ (${actualSize})"
exit "${EX_TOO_LARGE}";
fi
LOG_FIC " - ${GREEN}send without attach file${NC}"
LOG_FIC " - pas de piece jointe"
${SENDMAIL} "$@" < "in.$$"
fi
quitFilter 0
exit 0
##########################################################################

View File

@ -163,7 +163,7 @@ void
MainAttachment::addLink (string &plain, string &html, const string &url, const string &name) const {
string plainNewOneLink (templatePlainAddLink);
replaceAll (plainNewOneLink, TMPL_DOWNLOAD, url);
replaceAll (plainNewOneLink, TMPL_FILENAME, "\""+name+"\"");
replaceAll (plainNewOneLink, TMPL_FILENAME, name);
plain += plainNewOneLink;
string htmlNewOneLink (templateHtmlAddLink);
string codedUrl (url);
@ -211,7 +211,7 @@ MainAttachment::getDisclaim (string &plain, string &html) const {
plain = "\r\n"+KAZ_PLAIN_START+"\r\n"+KAZ_PLAIN_HR+"\r\n"+KAZ_PLAIN_DONT_TOUCH+"\r\n\r\n"+KAZ_PLAIN_WARNING+"\r\n\r\n"+KAZ_PLAIN_DOWLOAD_ONE+"\r\n"+plainNewLinks;
html = templateHtmlHeader+htmlNewLinks;
if (previousLinks.size ()) {
plain += "\r\n"+KAZ_PLAIN_DOWLOAD_OTHER+"\r\n"+plainOldLinks;
plain += KAZ_PLAIN_DOWLOAD_OTHER+"\r\n"+plainOldLinks;
html += templateHtmlOtherLink+htmlOldLinks;
}
if (linkCount > 1 && archiveDownloadURL.length ()) {
@ -239,7 +239,7 @@ MainAttachment::addPrevious (const string &href, const string &name, const bool
if (oldVal.length () && name.length () && !trust)
return;
previousLinks.erase (href);
previousLinks [href] = regex_replace (name, regex (R"([\t\r\n\"]+|(\\\")|(>\s*))"), "");
previousLinks [href] = name;
LOG ("inserted: " << href << ": " << previousLinks[href]);
}
@ -255,7 +255,7 @@ MainAttachment::extractLinks (const string &extractedPlainKAZ) {
const string href (extractedPlainKAZ.substr (startPos, stopPos-startPos));
LOG ("plain href: " << href);
if (extractedPlainKAZ [stopPos])
if (extractedPlainKAZ [stopPos] && extractedPlainKAZ [stopPos] != '\n')
++stopPos;
startPos = stopPos;
// get all href but KAZ_WEB_SITE
@ -266,11 +266,11 @@ MainAttachment::extractLinks (const string &extractedPlainKAZ) {
string::size_type nextPos = extractedPlainKAZ.find ("http", startPos);
string name (extractedPlainKAZ, startPos, (nextPos == string::npos ? extractedPlainKAZ.length () : nextPos) - startPos);
// skip [> \r\n\t]
nextPos = name.find_first_not_of ("[> \t\r\n\"]");
nextPos = name.find_first_not_of ("[> \t\r\n]");
if (nextPos != string::npos)
name.erase (0, nextPos);
// stop before [>\r\n\t]
nextPos = name.find_first_of ("[\"]");
nextPos = name.find_first_of ("[>\t\r\n]");
if (nextPos != string::npos)
name.erase (nextPos);
LOG ("plain name: " << name);
@ -354,8 +354,7 @@ void
MainAttachment::removePreviousArchive () {
vector<string> toRemove;
for (map <string, string>::const_iterator it = previousLinks.begin (); it != previousLinks.end (); ++it)
if (it->first.find ("&g=") != string::npos ||
it->first.find ("&l=/") != string::npos) // v1 compatibility
if (it->first.find ("&l=/") != string::npos)
toRemove.push_back (it->first);
for (string old : toRemove)
previousLinks.erase (old);

View File

@ -122,8 +122,8 @@ main (int argc, char** argv) {
contentType,
attachName,
urlBase ("http://file.kaz.bzh"),
uploadPage ("/a.php"),
updatePage ("/a.php"),
apiPage ("/script.php"),
downloadPage ("/f.php"),
minimumAvailability ("month"),
proxy;
@ -144,8 +144,8 @@ main (int argc, char** argv) {
("useTheForceLuke", bool_switch (&useTheForceLuke), "display hidded options")
("debug,g", bool_switch (&debugFlag), "debug mode")
("proxy,p", value<string> (&proxy)->default_value (proxy), "set proxy (proxy-host.org:8080)")
("uploadPage,u", value<string> (&uploadPage)->default_value (uploadPage), "upload page")
("updatePage,v", value<string> (&updatePage)->default_value (updatePage), "update page")
("uploadPage,u", value<string> (&apiPage)->default_value (apiPage), "upload page")
("downloadPage,d", value<string> (&downloadPage)->default_value (downloadPage), "download page")
;
options_description cmd ("All options");
@ -220,8 +220,8 @@ main (int argc, char** argv) {
switch (jirCmd) {
case SEND: {
LOG ("SEND: " << (urlBase+uploadPage));
curl_easy_setopt (easyhandle, CURLOPT_URL, (urlBase+uploadPage).c_str ());
LOG ("SEND: " << (urlBase+apiPage));
curl_easy_setopt (easyhandle, CURLOPT_URL, (urlBase+apiPage).c_str ());
LOG ("maxUploadSize: " << maxUploadSize);
long uploadsize = (size_t) maxUploadSize;
@ -264,8 +264,8 @@ main (int argc, char** argv) {
break;
case UPDATE: {
LOG ("UPDATE: " << (urlBase+updatePage));
curl_easy_setopt (easyhandle, CURLOPT_URL, (urlBase+updatePage).c_str ());
LOG ("UPDATE: " << (urlBase+downloadPage));
curl_easy_setopt (easyhandle, CURLOPT_URL, (urlBase+downloadPage).c_str ());
LOG ("h: " << inputFileName);
part = curl_mime_addpart (multipart);