log failed

This commit is contained in:
François 2022-10-28 15:32:46 +02:00
parent aa5ae1824d
commit 99e888f5d1
3 changed files with 106 additions and 61 deletions

View File

@ -25,6 +25,7 @@ require (JIRAFEAU_ROOT . 'lib/lang.php');
define ('VAR_TOKENS', $cfg ['var_root'].'tokens/');
define ('VAR_TRACKS', $cfg ['var_root'].'tracks/');
define ('VAR_LANG', $cfg ['var_root'].'lang/');
define ('VAR_PERIOD', $cfg ['var_root'].'period/');
define ('VAR_FAKE', $cfg ['var_root'].'fake/');
define ('VAR_ADMIN', $cfg ['var_root'].'admin/');
@ -38,6 +39,7 @@ define ('TOKEN_USE_LIMIT', "-2 hours");
define ('TOKEN_LOGIN_LIMIT', "-15 minutes");
define ('TOKEN_LOGOUT_LIMIT', "-8 hours");
define ('DEFAULT_PERIOD', "month");
define ('DEFAULT_LANG', "fr");
define ('E_BAD_ARCHIVE_NAME', 'Bad archive name format');
define ('E_CREATE_ZIP', "Impossible de créer l'archive.");
@ -72,7 +74,7 @@ define ('M_WELCOME', "<p>Informations concernant le compte : <b>___SENDER___</b>
define ('M_INCONSISTENT_DATES',
" (dates incoh&eacute;antes avec ___FILENAME___ : ___DIRTIME___ != ___FILETIME___)");
define ('A_ACTION', 'a'); // action : T_LOGIN, T_LOGOUT, A_RECORD+(on|off), A_PERIOD(minute|hour|day|week|month|quarter)
define ('A_ACTION', 'a'); // action : T_LOGIN, T_LOGOUT, A_RECORD+(on|off), A_LANG(fr|en|br), A_PERIOD(minute|hour|day|week|month|quarter)
define ('A_GET', 'g'); // get archive
define ('A_HASH', 'h'); // file to update or delete
define ('A_OPEN_TOKEN', 'o'); // ask token
@ -81,6 +83,7 @@ define ('A_TOKEN', 't'); // session token
define ('A_UPDATE', 'u'); // update perriod for file or archive
define ('A_RECORD', 'r'); // get track status
define ('A_PERIOD', 'p'); // get period status
define ('A_LANG', 'l'); // get lang status
define ('A_DELETE', 'd'); // delete file ou archive + (sender+token)
define ('T_BAD_PASW', 'bad_psw');
define ('T_CREATE', "create");
@ -107,6 +110,7 @@ define ('T_ARCHIVE_TITLE', "archive_content");
define ('T_ARCHIVE_MIME', "text/kaz_email_archive");
$langText = ['fr' => "Francais", 'br' => "Breton", 'en' => "english"];
$periodText = ['minute' => "minute", 'hour' => "heure", 'day' => "jour", 'week' => "semaine", 'month' => "mois"];
// XXX , 'quarter' => "trimestre"];
$periodButton = ['hour' => ["&#128341;", ">1 heure"],
@ -193,6 +197,29 @@ function isSenderTrack ($sender) {
return $sender && file_exists (VAR_TRACKS.$sender);
}
// ========================================
function setSenderLang ($sender, $lang) {
if (!$sender)
return;
if (!file_exists (VAR_LANG))
mkdir (VAR_LANG, 0755);
if (empty ($lang) || DEFAULT_LANG == $lang) {
rmSenderLang ($sender);
} else
file_put_contents (VAR_LANG.$sender, $lang.NL);
}
function rmSenderLang ($sender) {
if (!$sender)
return;
if (file_exists (VAR_LANG.$sender))
unlink (VAR_LANG.$sender);
}
function getSenderLang ($sender) {
if ($sender && file_exists (VAR_LANG.$sender))
return trim (file (VAR_LANG.$sender)[0]);
return DEFAULT_LANG;
}
// ========================================
function setSenderPeriod ($sender, $period) {
if (!$sender)
@ -934,6 +961,10 @@ if (isset ($_REQUEST [A_ACTION])) {
rmSenderTrack ($sender);
$message .= "Votre suivi &agrave; &eacute;t&eacute; mise &agrave; jour.";
break;
case preg_match ("/^".A_LANG."(".implode ("|", array_keys ($langText)).")$/i", $_REQUEST [A_ACTION], $matches):
setSenderLang ($sender, $matches [1]);
$message .= "Votre lang &agrave; &eacute;t&eacute; mise &agrave; jour.";
break;
case preg_match ("/^".A_PERIOD."(".implode ("|", array_keys ($periodText)).")$/i", $_REQUEST [A_ACTION], $matches):
setSenderPeriod ($sender, $matches [1]);
$message .= "Votre p&eacute;riode &agrave; &eacute;t&eacute; mise &agrave; jour.";

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,27 +86,28 @@ 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;
}
@ -115,9 +116,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;
}
@ -125,7 +126,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;
}
@ -139,16 +140,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">' .
@ -163,13 +164,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;
@ -181,7 +182,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;
}
@ -191,38 +192,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');
@ -288,3 +289,4 @@ if ($link['onetime'] == 'O') {
exit;
?>

View File

@ -48,7 +48,8 @@ EX_TEMPFAIL=75
EX_UNAVAILABLE=69
EX_TOO_LARGE=552
INSPECT_DIR=/var/spool/filter
FIC_LOG=/var/log/mail/filter.log
DIR_LOG=/var/log/mail
FIC_LOG=${DIR_LOG}/filter.log
SENDMAIL="/usr/sbin/sendmail -G -i"
MAILS=/tmp/FILTER
MAX_KEEP_IN_MAIL=5ki
@ -60,10 +61,12 @@ JIRAFEAU_LOCAL=http://depot
JIRAFEAU_TIME=month
MD5_CMD=/usr/bin/md5sum
DISCLAMER_CMD=altermime
MAX_FINAL_SIZE=204800 # 200ki
MAX_FINAL_SIZE=307200 # 300ki
ARCHIVE_TITLE="archive_content"
ARCHIVE_MIME="text/kaz_email_archive"
KEEP_FAILED=true
#################### FONCTIONS ############################################
BOLD=''
RED=''
@ -75,8 +78,9 @@ CYAN=''
NC='' # No Color
NL='
'
#--------------------- Fichier de LOG -------------------
LOG_FIC() {
LOG_FIC () {
echo "${BLUE}$(date +%d-%m-%Y-%H-%M-%S)${NC} : $*" >> "${FIC_LOG}"
}
@ -85,6 +89,12 @@ quitFilter () {
exit $1
}
keepFailed () {
[ -z "${KEEP_FAILED}" ] && return
mkdir -p "${DIR_LOG}/pb/"
cp "$1" "${DIR_LOG}/pb/"
}
#################### MAIN #################################################
echo "${NL}" >> "${FIC_LOG}"
LOG_FIC "${GREEN}######################################## filter start${NC}"
@ -186,7 +196,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${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}"
echo "new:"
cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak"
keepFailed "${INSPECT_DIR}/in.$$"
echo "UPLOAD_FAIL" >> "${JIRAFEAU_ERROR}"
;;
* )
@ -216,7 +226,7 @@ LOG_FIC "${CYAN}${SHRINK_CMD} -s ${MAX_KEEP_IN_MAIL} -d ${REP_PIECE_JOINTE} ${IN
"" | no | *Error* | \<* )
LOG_FIC " - ${RED}can't upload archive (${JIR_TOKEN}) <in.$$.bak>, substitution couldn't be done${NC}"
echo "arch: bad"
cp "${INSPECT_DIR}/in.$$" "${INSPECT_DIR}/in.$$.bak"
keepFailed "${INSPECT_DIR}/in.$$"
echo "ARCHIVE_FAIL" >> "${JIRAFEAU_ERROR}"
;;
* )
@ -247,6 +257,7 @@ if [ "$(wc -l < "${ARCHIVE_CONTENT}")" -ge 3 ]; then
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}"
fi
LOG_FIC " - ${GREEN}send with : ${SENDMAIL} $@ ${INSPECT_DIR}/in.$$.altered ${NC}"
@ -256,6 +267,7 @@ else
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}"
fi
LOG_FIC " - ${GREEN}send without attach file${NC}"