2022-02-10 01:37:43 +01:00
< ? php
/*
* Kaz addon ( see https :// git . kaz . bzh / KAZ / depollueur for information )
* create un archive for a set of file or update file deadline
2022-02-19 08:43:14 +01:00
a . php ? r = email => track
a . php ? p = email => period
a . php ? u = month & h = HHHHHHHH => update deadline
2022-02-10 01:37:43 +01:00
a . php ? g = l ~ k => zip
2022-02-19 08:43:14 +01:00
a . php ? time = month & key = password + POST file => upload
a . php ? s = mel @ domain . org => form
a . php ? s = mel @ domain . org & t = password + [ action ] => manage account
action : a = login a = logout a = r [ on | off ] a = p [ minute | hour | day | week | month | quarter ]
2022-02-10 01:37:43 +01:00
*/
2022-02-11 01:01:24 +01:00
use PHPMailer\PHPMailer\PHPMailer ;
use PHPMailer\PHPMailer\SMTP ;
use PHPMailer\PHPMailer\Exception ;
require 'vendor/autoload.php' ;
2022-02-10 01:37:43 +01:00
2022-02-11 01:01:24 +01:00
define ( 'JIRAFEAU_ROOT' , dirname ( __FILE__ ) . '/' );
2022-02-10 01:37:43 +01:00
2022-02-11 01:01:24 +01:00
require ( JIRAFEAU_ROOT . 'lib/settings.php' );
require ( JIRAFEAU_ROOT . 'lib/functions.php' );
require ( JIRAFEAU_ROOT . 'lib/lang.php' );
2022-02-14 17:07:18 +01:00
define ( 'VAR_TOKENS' , $cfg [ 'var_root' ] . 'tokens/' );
define ( 'VAR_TRACKS' , $cfg [ 'var_root' ] . 'tracks/' );
2022-02-15 13:30:19 +01:00
define ( 'VAR_PERIOD' , $cfg [ 'var_root' ] . 'period/' );
define ( 'VAR_FAKE' , $cfg [ 'var_root' ] . 'fake/' );
2022-02-17 18:13:09 +01:00
define ( 'VAR_PRIVATE' , $cfg [ 'var_root' ] . 'private/' );
2022-02-12 22:50:10 +01:00
2022-02-17 18:13:09 +01:00
define ( 'MAX_VALID_UPLOAD_TIME' , 60 );
2022-02-12 22:50:10 +01:00
define ( 'TOKEN_USE_LIMIT' , " -2 hours " );
define ( 'TOKEN_LOGIN_LIMIT' , " -15 minutes " );
define ( 'TOKEN_LOGOUT_LIMIT' , " -8 hours " );
2022-02-15 13:30:19 +01:00
define ( 'DEFAULT_PERIOD' , " month " );
2022-02-12 22:50:10 +01:00
define ( 'E_BAD_ARCHIVE_NAME' , 'Bad archive name format' );
2022-02-11 01:01:24 +01:00
define ( 'E_CREATE_ZIP' , " Impossible de créer l'archive. " );
define ( 'E_OPEN_ZIP' , " Impossible d'ouvrir l'archive. " );
define ( 'M_BAD_KEY' , " Mauvaise clef pour " );
2022-02-12 22:50:10 +01:00
define ( 'M_BAD_SENDER_NAME' , 'Votre mèl est incorrect' );
define ( 'M_BAD_TOKEN' , " Vous n'utilisez pas le bon jeton (consultez votre messagerie). " );
define ( 'M_TOO_LONG_BEFORE_LOGGED' , " Jeton de connexion trop ancien. " );
define ( 'M_TOO_LONG_LOGGED' , " Temps de connexion dépassé. " );
define ( 'M_EMAIL_CONTENT' , " Bonjour,<br/><br/>Ceci est un message automatique, car vous venez de cliquer sur une demande de consultation de vos pièces jointes.<br/><br/>!!! Si vous n'êtes pas à l'origine de cette demande, ne cliquez sur aucun lien de ce message. !!!<br/><br/>Le lien de connexion suivant est valable 15 minutes.<br/><a href= \" ___LINK___ \" >___LINK___</a><br/><br/>Vous pouvez signaler des abus auprès de Kaz en faisant suivre ce message qui contient les traces de son émetteur (___IP___, ___DATE___).<br/><br/>Bonne navigation.<br/>. " );
define ( 'M_DOWNLOAD' , " Télécharger " );
define ( 'M_UPDATE' , " Prolonger " );
2022-02-16 16:14:35 +01:00
define ( 'M_EMAIL_SUBJECT' , " Lien de consultation des envois de pièces jointes. " );
2022-02-11 01:01:24 +01:00
define ( 'M_FILE' , " fichier. " );
define ( 'M_FILES' , " fichiers. " );
2022-02-19 12:00:16 +01:00
define ( 'M_FILES_NOT_FOUND' , " fichiers sont expirés. " );
define ( 'M_FILES_RENAMED' , " fichiers renommés. " );
define ( 'M_FILE_NOT_FOUND' , " fichier est expiré. " );
define ( 'M_FILE_RENAMED' , " fichier renommé. " );
2022-02-12 22:50:10 +01:00
define ( 'M_INTRO_FORM' , " Quelles sont les informations me concernant ? " );
define ( 'M_MEL' , " votre mèl " );
2022-02-11 01:01:24 +01:00
define ( 'M_NO_FILENAME' , 'SansNom' );
2022-02-14 17:07:18 +01:00
define ( 'M_NO_SENDER' , 'kaz-' );
2022-02-17 18:13:09 +01:00
define ( 'M_NEW_ATTACHEMENT_DIRNAME' , " nouveau " );
define ( 'M_OLD_ATTACHEMENT_DIRNAME' , " ancien " );
2022-02-12 22:50:10 +01:00
define ( 'M_SEND' , " Connexion " );
2022-02-15 13:30:19 +01:00
define ( 'M_LOGOUT' , 'Deconnecter' );
define ( 'M_REFRESH' , 'Actualiser' );
2022-02-12 22:50:10 +01:00
define ( 'M_LOGOUT_TOKEN' , " Vous n'êtes plus connecté. " );
2022-02-19 12:00:16 +01:00
define ( 'M_SEND_TOKEN' , " <br/><p>Vous allez recevoir un <b>lien d'accès temporaire</b> à vos données.</p> " );
2022-02-20 19:00:13 +01:00
define ( 'M_WELCOME' , " <p>Informations concernant le compte : <b>___SENDER___</b><br/>(page actualisée à ___DATE___)</p> " );
2022-02-17 18:13:09 +01:00
define ( 'M_INCONSISTENT_DATES' ,
2022-02-17 18:31:38 +01:00
" (dates incohéantes avec ___FILENAME___ : ___DIRTIME___ != ___FILETIME___) " );
2022-02-12 22:50:10 +01:00
2022-02-19 08:43:14 +01:00
define ( 'A_ACTION' , 'a' ); // action : T_LOGIN, T_LOGOUT, A_RECORD+(on|off), A_PERIOD(minute|hour|day|week|month|quarter)
2022-02-14 17:07:18 +01:00
define ( 'A_GET' , 'g' ); // get archive
define ( 'A_HASH' , 'h' ); // file to update or delete
define ( 'A_OPEN_TOKEN' , 'o' ); // ask token
define ( 'A_SENDER' , 's' ); // session sender
define ( 'A_TOKEN' , 't' ); // session token
define ( 'A_UPDATE' , 'u' ); // update perriod for file or archive
define ( 'A_RECORD' , 'r' ); // get track status
2022-02-15 13:30:19 +01:00
define ( 'A_PERIOD' , 'p' ); // get period status
2022-02-14 17:07:18 +01:00
define ( 'A_DELETE' , 'd' ); // delete file ou archive + (sender+token)
2022-02-11 01:01:24 +01:00
define ( 'T_BAD_PASW' , 'bad_psw' );
2022-02-12 22:50:10 +01:00
define ( 'T_CREATE' , " create " );
2022-02-11 01:01:24 +01:00
define ( 'T_CRYPTED' , 'crypted' );
define ( 'T_CRYPT_KEY' , 'crypt_key' );
define ( 'T_ENTRIES' , 'entries' );
define ( 'T_FILENAME' , 'file_name' );
define ( 'T_HASH' , 'hash' );
2022-02-12 22:50:10 +01:00
define ( 'T_LOGGED' , " logged " );
2022-02-11 01:01:24 +01:00
define ( 'T_NEW' , 'new' );
2022-02-17 18:13:09 +01:00
define ( 'T_SIGN' , 'sign' );
2022-02-11 01:01:24 +01:00
define ( 'T_NOT_FOUND' , 'not_found' );
define ( 'T_OLD' , 'old' );
define ( 'T_RENAME' , 'rename' );
2022-02-19 08:43:14 +01:00
define ( 'T_LOGIN' , 'login' );
define ( 'T_LOGOUT' , 'logout' );
2022-02-11 01:01:24 +01:00
define ( 'T_SENDER' , 'sender' );
2022-02-17 18:13:09 +01:00
define ( 'T_TIME' , 'time' );
define ( 'T_ID' , 'id' );
2022-02-12 22:50:10 +01:00
define ( 'T_TOKEN' , " token " );
2022-02-11 01:01:24 +01:00
define ( 'T_WARNING_FILENAME' , " -Avertissement.txt " );
define ( 'T_ZIP_EXT' , " .zip " );
2022-02-14 17:07:18 +01:00
define ( 'T_ARCHIVE_TITLE' , " archive_content " );
define ( 'T_ARCHIVE_MIME' , " text/kaz_email_archive " );
2022-02-10 01:37:43 +01:00
2022-02-15 13:30:19 +01:00
2022-02-20 19:31:35 +01:00
$periodText = [ 'minute' => " minute " , 'hour' => " heure " , 'day' => " jour " , 'week' => " semaine " , 'month' => " mois " ];
// XXX , 'quarter' => "trimestre"];
$periodButton = [ 'hour' => [ " 🕕 " , " >1 heure " ],
'day' => [ " 🕜 " , " >1 jour " ],
2022-02-15 13:30:19 +01:00
'week' => [ " 🕝 " , " > 1 semaine " ],
2022-02-20 19:31:35 +01:00
'month' => [ " 🕞 " , " > 1 mois " ]];
// XXX 'quarter' => ["🕟", "> 1 trimestre"]];
2022-02-15 13:30:19 +01:00
$trackText = [ 'on' => " oui " , 'off' => " non " ];
$doLogout = '' ;
$message = '' ;
2022-02-10 01:37:43 +01:00
/* Operations may take a long time .
* Be sure PHP ' s safe mode is off .
*/
@ set_time_limit ( 0 );
/* Remove errors. */
@ error_reporting ( 0 );
2022-02-19 08:43:14 +01:00
// ========================================
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 ]))
2022-02-25 08:52:09 +01:00
$content = false . NL ;
else
$content = getSenderTrack ( $_REQUEST [ A_RECORD ]) . NL ;
2022-02-19 08:43:14 +01:00
header ( 'HTTP/1.0 200 OK' );
header ( 'Content-Length: ' . strlen ( $content ));
header ( 'Content-Type: text/plain' );
echo $content ;
exit ;
}
// ========================================
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 ]))
2022-02-25 08:52:09 +01:00
$content = DEFAULT_PERIOD . NL ;
else
$content = getSenderPeriod ( $_REQUEST [ A_PERIOD ]) . NL ;
2022-02-19 08:43:14 +01:00
header ( 'HTTP/1.0 200 OK' );
header ( 'Content-Length: ' . strlen ( $content ));
header ( 'Content-Type: text/plain' );
echo $content ;
exit ;
}
// ========================================
2022-02-17 18:13:09 +01:00
$doUpdate = false ;
2022-02-14 17:07:18 +01:00
if ( isset ( $_REQUEST [ A_UPDATE ]) && ! empty ( $_REQUEST [ A_UPDATE ])) {
2022-02-17 18:13:09 +01:00
$doUpdate = true ;
2022-02-10 01:37:43 +01:00
}
2022-02-17 18:13:09 +01:00
$doDownload = false ;
2022-02-14 17:07:18 +01:00
if ( isset ( $_REQUEST [ A_GET ]) && ! empty ( $_REQUEST [ A_GET ])) {
2022-02-17 18:13:09 +01:00
$doDownload = true ;
}
$doUpload = false ;
if ( isset ( $_FILES [ 'file' ])) {
$doUpload = true ;
2022-02-10 01:37:43 +01:00
}
// ========================================
2022-02-17 18:13:09 +01:00
function returnError ( $msg ) {
2022-02-10 01:37:43 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/header.php' );
echo '<div class="error"><p>' . $msg . '</p></div>' ;
require ( JIRAFEAU_ROOT . 'lib/template/footer.php' );
exit ;
}
2022-02-15 13:30:19 +01:00
// ========================================
2022-02-17 18:13:09 +01:00
function setSenderTrack ( $sender ) {
2022-02-15 13:30:19 +01:00
if ( ! $sender )
return ;
if ( ! file_exists ( VAR_TRACKS ))
mkdir ( VAR_TRACKS , 0755 );
touch ( VAR_TRACKS . $sender );
}
2022-02-17 18:13:09 +01:00
function rmSenderTrack ( $sender ) {
2022-02-15 13:30:19 +01:00
if ( ! $sender )
return ;
if ( file_exists ( VAR_TRACKS . $sender ))
unlink ( VAR_TRACKS . $sender );
}
2022-02-17 18:13:09 +01:00
function getSenderTrack ( $sender ) {
2022-02-19 09:49:41 +01:00
return $sender && file_exists ( VAR_TRACKS . $sender );
2022-02-15 13:30:19 +01:00
}
// ========================================
2022-02-17 18:13:09 +01:00
function setSenderPeriod ( $sender , $period ) {
2022-02-15 13:30:19 +01:00
if ( ! $sender )
return ;
if ( ! file_exists ( VAR_PERIOD ))
mkdir ( VAR_PERIOD , 0755 );
if ( empty ( $period ) || DEFAULT_PERIOD == $period ) {
2022-02-17 18:13:09 +01:00
rmSenderPeriod ( $sender );
2022-02-15 13:30:19 +01:00
} else
file_put_contents ( VAR_PERIOD . $sender , $period . NL );
}
2022-02-17 18:13:09 +01:00
function rmSenderPeriod ( $sender ) {
2022-02-15 13:30:19 +01:00
if ( ! $sender )
return ;
if ( file_exists ( VAR_PERIOD . $sender ))
unlink ( VAR_PERIOD . $sender );
}
2022-02-17 18:13:09 +01:00
function getSenderPeriod ( $sender ) {
2022-02-19 09:49:41 +01:00
if ( $sender && file_exists ( VAR_PERIOD . $sender ))
return trim ( file ( VAR_PERIOD . $sender )[ 0 ]);
return DEFAULT_PERIOD ;
2022-02-15 13:30:19 +01:00
}
2022-02-17 18:13:09 +01:00
function period2seconds ( $periodName ) {
if ( ! $periodName )
return JIRAFEAU_MONTH ;
switch ( $periodName ) {
case 'minute' :
return JIRAFEAU_MINUTE ;
break ;
case 'hour' :
return JIRAFEAU_HOUR ;
break ;
case 'day' :
return JIRAFEAU_DAY ;
break ;
case 'week' :
return JIRAFEAU_WEEK ;
break ;
case 'month' :
return JIRAFEAU_MONTH ;
break ;
case 'quarter' :
return JIRAFEAU_QUARTER ;
break ;
case 'year' :
return JIRAFEAU_YEAR ;
break ;
default :
returnError ( t ( 'ERR_OCC' ) . ' (periodName)' );
}
}
2022-02-15 13:30:19 +01:00
// ========================================
2022-02-19 08:43:14 +01:00
function setSenderFake ( $error , $sender , $owner , $dirLink , $fileLink ) {
global $doLogout ;
2022-02-15 13:30:19 +01:00
if ( ! file_exists ( VAR_FAKE ))
mkdir ( VAR_FAKE , 0755 );
2022-02-19 08:43:14 +01:00
$dirTime = $fileTime = $fileName = $fileType = $ip = '' ;
if ( count ( $dirLink ) != 0 ) {
$dirTime = $dirLink [ 'upload_date' ] . date ( " Y-m-d H:i:s " , $dirLink [ 'upload_date' ]);
$ip = $dirLink [ 'ip' ];
}
2022-02-15 13:30:19 +01:00
if ( ! $sender )
return ;
2022-02-19 08:43:14 +01:00
if ( count ( $fileLink ) != 0 ) {
$fileTime = $fileLink [ 'upload_date' ] . date ( " Y-m-d H:i:s " , $fileLink [ 'upload_date' ]);
$fileName = $link [ 'file_name' ];
$fileType = $link [ 'mime_type' ];
}
$content =
" time : " . time () . NL .
" date : " . date ( " Y-m-d H:i:s " ) . NL .
" error : " . $error . NL .
" sender : < " . $sender . " > " . NL .
" owner : < " . $owner . " > " . NL .
" dirLink : < " . $dirLink . " > " . NL .
" dirTime : " . $dirTime . NL .
" dirIp : " . $ip . NL .
" fileTime: " . $fileTime . NL .
" fileType: < " . $fileType . " > " . NL .
" fileName: < " . $fileName . " > " . NL ;
$log = $ip . $sender ;
if ( $log )
file_put_contents ( VAR_FAKE . $log , $content );
// $doLogout = true;
// rmToken ($sender);
}
function getSenderFake ( $sender ) {
return false ;
// return $sender && file_exists (VAR_FAKE.$sender);
2022-02-15 13:30:19 +01:00
}
2022-02-14 17:07:18 +01:00
// ========================================
function isKazArchive ( $link ) {
return
@ preg_match ( " / " . T_ARCHIVE_TITLE . " / " , jirafeau_escape ( $link [ 'file_name' ])) &&
jirafeau_escape ( $link [ 'mime_type' ]) == T_ARCHIVE_MIME ;
}
2022-02-17 18:13:09 +01:00
// ========================================
function readArchiveFromLink ( $link ) {
$p = s2p ( $link [ 'hash' ]);
$lines = file ( VAR_FILES . $p . $link [ 'hash' ]);
$archive = readArchiveFromLines ( $lines );
return $archive ;
}
function readArchiveFromLines ( $lines ) {
$archive = [];
$error = false ;
foreach ( $lines as $line ) {
switch ( true ) {
case preg_match ( " /^ \ s*id: \ s*( \ d++) \ s* $ / " , $line , $matches ) :
$archive [ T_ID ] = $matches [ 1 ];
2022-02-19 12:00:16 +01:00
break ;
2022-02-17 18:13:09 +01:00
case preg_match ( " /^ \ s*time: \ s*( \ d { 4}([:-] \ d { 2}) { 5}) \ s* $ /i " , $line , $matches ) :
$archive [ T_TIME ] = $matches [ 1 ];
break ;
2022-02-25 08:52:09 +01:00
// 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 ) :
2022-02-18 18:30:30 +01:00
$archive [ T_SENDER ] = $matches [ 1 ];
break ;
2022-02-25 08:52:09 +01:00
// XXX issue ")"
case preg_match ( " /^ \ s*new: \ s*([0-9a-zA-Z_-]+) \ s+([0-9a-zA-Z_-]+) \ )? \ s* $ / " , $line , $matches ) :
2022-02-17 18:13:09 +01:00
$archive [ T_NEW ][] = [ $matches [ 1 ], $matches [ 2 ]];
break ;
2022-02-25 08:52:09 +01:00
case preg_match ( " /^ \ s*old: \ s*([0-9a-zA-Z_-]+) \ s+([0-9a-zA-Z_-]+) \ )? \ s* $ / " , $line , $matches ) :
2022-02-17 18:13:09 +01:00
$archive [ T_OLD ][] = [ $matches [ 1 ], $matches [ 2 ]];
break ;
case preg_match ( " /^ \ s*sign: \ s*([0-9a-zA-Z_-]+) \ s* $ / " , $line , $matches ) :
$archive [ T_SIGN ] = $matches [ 1 ];
break ;
default :
global $message ;
$message .= " <p>error: " . $line . " </p> " ;
$error = true ;
break ;
}
}
return $error ? [] : $archive ;
}
2022-02-14 17:07:18 +01:00
// ========================================
2022-02-16 16:14:35 +01:00
function getFileName ( $hash ) {
$p = s2p ( $hash );
return VAR_FILES . $p . $hash ;
}
2022-02-15 13:30:19 +01:00
function getTimeFile ( $hash ) {
2022-02-16 16:14:35 +01:00
$f = getFileName ( $hash );
2022-02-15 13:30:19 +01:00
return file_exists ( $f ) ? filemtime ( $f ) : 0 ;
2022-02-14 17:07:18 +01:00
}
function valideTime ( $t1 , $t2 ) {
2022-02-17 18:13:09 +01:00
global $message ;
return abs ( $t1 - $t2 ) < MAX_VALID_UPLOAD_TIME ;
2022-02-14 17:07:18 +01:00
}
2022-02-10 01:37:43 +01:00
// ========================================
/** Update link
* @ param $link the link ' s name ( hash )
2022-02-17 18:13:09 +01:00
* @ param $update_period the period ( i . e in : " month " )
2022-02-10 01:37:43 +01:00
*/
2022-02-17 18:13:09 +01:00
function updateLink ( $link_name , $link , $maxLimit ) {
2022-02-10 01:37:43 +01:00
$time_max = $link [ 'time' ];
2022-02-17 18:13:09 +01:00
if ( $time_max < 0 || $maxLimit < $time_max )
2022-02-10 01:37:43 +01:00
return $time_max ;
2022-02-17 18:13:09 +01:00
$time_more = $maxLimit + JIRAFEAU_MINUTE ;
2022-02-10 01:37:43 +01:00
$link [ 'time' ] = $time_more ;
2022-02-11 01:01:24 +01:00
$link_tmp_name = VAR_LINKS . $link [ 'hash' ] . rand ( 0 , 10000 ) . '.tmp' ;
2022-02-10 01:37:43 +01:00
$handle = fopen ( $link_tmp_name , 'w' );
fwrite ( $handle ,
2022-02-11 01:01:24 +01:00
$link [ 'file_name' ] . NL . $link [ 'mime_type' ] . NL . $link [ 'file_size' ] . NL . $link [ 'key' ] . NL . $link [ 'time' ] . NL .
$link [ 'hash' ] . NL . $link [ 'onetime' ] . ' ' . JIRAFEAU_MONTH . ' ' . JIRAFEAU_DAY . NL . $link [ 'upload_date' ] . NL .
$link [ 'ip' ] . NL . $link [ 'link_code' ] . NL . $link [ 'crypted' ]);
2022-02-10 01:37:43 +01:00
fclose ( $handle );
2022-02-11 01:01:24 +01:00
$link_file = VAR_LINKS . s2p ( " $link_name " ) . $link_name ;
2022-02-10 01:37:43 +01:00
rename ( $link_tmp_name , $link_file );
return $time_more ;
}
// ========================================
2022-02-17 18:13:09 +01:00
function sendEMail ( $receiver , $receiver_name , $subject , $body_string ){
2022-02-16 16:14:35 +01:00
try {
// SERVER SETTINGS
$mail = new PHPMailer ( true );
$mail -> isSMTP ();
$mail -> Host = 'smtp' ;
$mail -> SMTPAuth = false ;
$mail -> SMTPAutoTLS = false ;
$mail -> SMTPSecure = " none " ;
$mail -> Port = 25 ;
$mail -> charSet = " UTF-8 " ;
$mail -> ContentType = 'text/html' ;
//Recipients (change this for every project)
$mail -> setFrom ( 'no-reply@kaz.local' , '' );
$mail -> addAddress ( $receiver , $receiver_name );
//Content
$mail -> isHTML ( true );
$mail -> Subject = $subject ;
$mail -> Body = $body_string ;
//send the message, check for errors
if ( ! $mail -> send ()) {
//echo 'Mailer Error: ' . $mail->ErrorInfo;
return 0 ;
} else {
//echo 'Message sent!';
return 1 ;
}
} catch ( Exception $e ) {
2022-02-11 01:01:24 +01:00
return 0 ;
}
}
2022-02-10 01:37:43 +01:00
2022-02-12 22:50:10 +01:00
// ========================================
function cleanToken () {
if ( ! file_exists ( VAR_TOKENS ))
mkdir ( VAR_TOKENS , 0755 );
$d = dir ( VAR_TOKENS );
$oldest = strtotime ( TOKEN_USE_LIMIT );
foreach ( glob ( VAR_TOKENS . " * " ) as $file ) {
if ( filemtime ( $file ) <= $oldest )
unlink ( $file );
}
}
function rmToken ( $sender ) {
if ( ! $sender )
return ;
if ( file_exists ( VAR_TOKENS . $sender ))
unlink ( VAR_TOKENS . $sender );
}
function setToken ( $sender ) {
if ( ! $sender )
return ;
$token = md5 ( rand ());
if ( file_put_contents ( VAR_TOKENS . $sender , T_CREATE . " : " . time () . NL . T_TOKEN . " : " . $token . NL ))
return $token ;
return false ;
}
function setLoggedToken ( $sender , $token ) {
if ( ! $sender || ! $token )
return ;
file_put_contents ( VAR_TOKENS . $sender , T_CREATE . " : " . time () . NL . T_TOKEN . " : " . $token . NL . T_LOGGED . " : ok " . NL );
}
function getTokenVar ( $sender , $varName ) {
if ( ! $sender )
return ;
if ( ! file_exists ( VAR_TOKENS . $sender ))
return false ;
$content = file_get_contents ( VAR_TOKENS . $sender );
if ( preg_match ( " / \ b " . $varName . " : \ s*([^ \ s]+) \n / " , $content , $matches ))
2022-02-14 17:07:18 +01:00
return $matches [ 1 ];
2022-02-12 22:50:10 +01:00
return false ;
}
function getToken ( $sender ) {
return getTokenVar ( $sender , T_TOKEN ,);
}
function getCreateToken ( $sender ) {
return getTokenVar ( $sender , T_CREATE );
}
function getLoggedToken ( $sender ) {
return getTokenVar ( $sender , T_LOGGED );
}
function getTimeToken ( $sender ) {
if ( ! $sender || ! file_exists ( VAR_TOKENS . $sender ))
return false ;
return filemtime ( VAR_TOKENS . $sender );
}
2022-02-10 01:37:43 +01:00
// ========================================
2022-02-17 18:13:09 +01:00
if ( $doUpload ) {
$maxtime = time () + period2seconds ( $_REQUEST [ 'time' ]);
$key = isset ( $_REQUEST [ 'key' ]) ? $_REQUEST [ 'key' ] : '' ;
$ip = $_SERVER [ 'HTTP_X_REAL_IP' ]; // XXX
$res = jirafeau_upload (
$_FILES [ 'file' ],
isset ( $_POST [ 'one_time_download' ]),
$key ,
$maxtime ,
$ip ,
$cfg [ 'enable_crypt' ],
$cfg [ 'link_name_length' ],
$cfg [ 'file_hash' ]
);
if ( ! count ( $res [ 'error' ]) || $res [ 'error' ][ 'has_error' ])
$content = 'Error 6 ' . $res [ 'error' ][ 'why' ];
else
$content = $res [ 'link' ] . NL . $res [ 'delete_link' ] . NL ;
header ( 'HTTP/1.0 200 OK' );
header ( 'Content-Length: ' . strlen ( $content ));
header ( 'Content-Type: text/plain' );
echo $content ;
exit ;
}
// ========================================
if ( $doUpdate ) {
$maxTime = time () + period2seconds ( $_REQUEST [ A_UPDATE ]);
2022-02-25 08:52:09 +01:00
// XXX issue ")"
if ( ! preg_match ( '/([0-9a-zA-Z_-]+)\)?$/' , $_REQUEST [ A_HASH ], $matches ))
2022-02-17 18:13:09 +01:00
returnError ( t ( 'FILE_404' ));
2022-02-25 08:52:09 +01:00
$linkName = $matches [ 1 ];
2022-02-17 18:13:09 +01:00
$link = jirafeau_get_link ( $linkName );
2022-02-11 01:01:24 +01:00
if ( count ( $link ) == 0 )
2022-02-17 18:13:09 +01:00
returnError ( t ( 'FILE_404' ));
$time = updateLink ( $linkName , $link , $maxTime );
2022-02-10 01:37:43 +01:00
$content = '' . $time . NL ;
2022-02-12 22:50:10 +01:00
2022-02-14 17:07:18 +01:00
if ( isKazArchive ( $link )) {
2022-02-17 18:13:09 +01:00
$archiveInfo = readArchiveFromLink ( $l );
if ( count ( $archiveInfo )) {
2022-02-12 22:50:10 +01:00
foreach ([ T_OLD , T_NEW ] as $cat )
2022-02-17 18:13:09 +01:00
if ( isset ( $archiveInfo [ $cat ]))
foreach ( $archiveInfo [ $cat ] as [ $linkName , $cryptKey ])
updateLink ( $linkName , jirafeau_get_link ( $linkName ), $maxTime );
2022-02-12 22:50:10 +01:00
}
}
2022-02-11 01:01:24 +01:00
header ( 'HTTP/1.0 200 OK' );
header ( 'Content-Length: ' . strlen ( $content ));
header ( 'Content-Type: text/plain' );
2022-02-10 01:37:43 +01:00
echo $content ;
exit ;
}
2022-02-12 22:50:10 +01:00
$sender = '' ;
$senderError = false ;
if ( isset ( $_REQUEST [ A_SENDER ]) && ! empty ( $_REQUEST [ A_SENDER ])) {
2022-02-25 08:52:09 +01:00
// XXX
//if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_SENDER]))
2022-02-15 13:30:19 +01:00
if ( ! preg_match ( " /^([a-z0-9 \ +_ \ -]+)( \ .[a-z0-9 \ +_ \ -]+)*@([a-z0-9 \ -]+ \ .)+[a-z] { 2,6} $ /i " , $_REQUEST [ A_SENDER ]))
2022-02-12 22:50:10 +01:00
$senderError = true ;
2022-02-15 13:30:19 +01:00
else {
cleanToken ();
$sender = $_REQUEST [ A_SENDER ];
2022-02-12 22:50:10 +01:00
}
}
2022-02-10 01:37:43 +01:00
// ========================================
2022-02-17 18:13:09 +01:00
if ( $doDownload ) {
2022-02-10 01:37:43 +01:00
// check archive exist
2022-02-14 17:07:18 +01:00
$couple = explode ( " ~ " , $_REQUEST [ A_GET ], 2 );
2022-02-10 01:37:43 +01:00
if ( count ( $couple ) == 0 )
2022-02-17 18:13:09 +01:00
returnError ( E_BAD_ARCHIVE_NAME );
$linkName = $couple [ 0 ];
if ( ! $linkName || ! preg_match ( '/[0-9a-zA-Z_-]+$/' , $linkName ))
returnError ( E_BAD_ARCHIVE_NAME );
$cryptKey = count ( $couple ) == 2 ? $couple [ 1 ] : " " ;
$link = jirafeau_get_link ( $linkName );
2022-02-10 01:37:43 +01:00
if ( count ( $link ) == 0 )
2022-02-17 18:13:09 +01:00
returnError ( t ( 'FILE_404' ));
2022-02-11 01:01:24 +01:00
$key = $link [ 'key' ];
2022-02-17 18:13:09 +01:00
if ( $key && ( empty ( $cryptKey ) || $key != $cryptKey ))
returnError ( t ( 'BAD_PSW' ));
2022-02-10 01:37:43 +01:00
2022-02-17 18:13:09 +01:00
$archiveInfo = readArchiveFromLink ( $link );
2022-02-10 01:37:43 +01:00
// check entries
2022-02-17 18:13:09 +01:00
$archiveContent = [];
2022-02-10 01:37:43 +01:00
$modif = false ;
2022-02-17 18:13:09 +01:00
$singleName = [];
2022-02-11 01:01:24 +01:00
foreach ([ T_OLD , T_NEW ] as $cat )
2022-02-17 18:13:09 +01:00
if ( isset ( $archiveInfo [ $cat ]))
foreach ( $archiveInfo [ $cat ] as [ $linkName , $cryptKey ]) {
$link = jirafeau_get_link ( $linkName );
2022-02-10 01:37:43 +01:00
if ( count ( $link ) == 0 ) {
2022-02-17 18:13:09 +01:00
if ( isset ( $archiveContent [ T_NOT_FOUND ]))
++ $archiveContent [ T_NOT_FOUND ];
2022-02-11 01:01:24 +01:00
else
2022-02-17 18:13:09 +01:00
$archiveContent [ T_NOT_FOUND ] = 1 ;
2022-02-10 01:37:43 +01:00
$modif = true ;
continue ;
}
2022-02-11 01:01:24 +01:00
$key = $link [ 'key' ];
2022-02-17 18:13:09 +01:00
if ( $key && ( empty ( $cryptKey ) || $key != $cryptKey )) {
if ( isset ( $archiveContent [ T_BAD_PASW ]))
++ $archiveContent [ T_BAD_PASW ];
2022-02-11 01:01:24 +01:00
else
2022-02-17 18:13:09 +01:00
$archiveContent [ T_BAD_PASW ] = 1 ;
2022-02-10 01:37:43 +01:00
$modif = true ;
continue ;
}
2022-02-17 18:13:09 +01:00
$srcName = $dstName = ( $link [ 'file_name' ] ? $link [ 'file_name' ] : M_NO_FILENAME );
if ( in_array ( $srcName , $singleName ))
2022-02-10 01:37:43 +01:00
for ( $i = 0 ; $i < 10000 ; ++ $i ) {
2022-02-17 18:13:09 +01:00
$dstName = sprintf ( " %s-%2d " , $srcName , $i );
if ( ! in_array ( $dstName , $singleName )) {
if ( isset ( $archiveContent [ T_RENAME ]))
++ $archiveContent [ T_RENAME ];
2022-02-11 01:01:24 +01:00
else
2022-02-17 18:13:09 +01:00
$archiveContent [ T_RENAME ] = 1 ;
2022-02-10 01:37:43 +01:00
$modif = true ;
break ;
}
}
2022-02-17 18:13:09 +01:00
$singleName [] = $dstName ;
$archiveContent [ $cat ][ T_ENTRIES ][] = [ T_HASH => $link [ 'hash' ], T_FILENAME => $dstName , T_CRYPT_KEY => $cryptKey , T_CRYPTED => $link [ 'crypted' ]];
2022-02-10 01:37:43 +01:00
}
// build zip
2022-02-17 18:13:09 +01:00
$dirname = M_NO_SENDER . ( isset ( $archiveInfo [ T_TIME ]) && ! empty ( $archiveInfo [ T_TIME ])) ?
$archiveInfo [ T_TIME ] : date ( " Y-m-d-H:i:s " );
2022-02-14 17:07:18 +01:00
$dirname = str_replace ( " : " , " _ " , $dirname );
2022-02-10 01:37:43 +01:00
$tmpFileName = tempnam ( sys_get_temp_dir (), $dirname . " - " );
$zip = new ZipArchive ;
if ( ! $zip )
2022-02-17 18:13:09 +01:00
returnError ( E_CREATE_ZIP );
2022-02-11 01:01:24 +01:00
if ( $zip -> open ( $tmpFileName . T_ZIP_EXT , ZipArchive :: CREATE ) !== TRUE )
2022-02-17 18:13:09 +01:00
returnError ( E_OPEN_ZIP );
2022-02-10 01:37:43 +01:00
2022-02-15 13:30:19 +01:00
// create info
2022-02-10 01:37:43 +01:00
if ( $modif ) {
$info = '' ;
2022-02-19 12:00:16 +01:00
if ( isset ( $archiveContent [ T_NOT_FOUND ]))
$info .= $archiveContent [ T_NOT_FOUND ] . ( $archiveContent [ T_NOT_FOUND ] ? M_FILE_NOT_FOUND : M_FILES_NOT_FOUND ) . NL ;
if ( isset ( $archiveContent [ T_BAD_PASW ]))
$info .= M_BAD_KEY . $archiveContent [ T_BAD_PASW ] . ( $archiveContent [ T_BAD_PASW ] ? M_FILE : M_FILES ) . NL ;
if ( isset ( $archiveContent [ T_RENAME ]))
$info .= $archiveContent [ T_RENAME ] . ( $archiveContent [ T_RENAME ] ? M_FILE_RENAMED : M_FILES_RENAMED ) . NL ;
2022-02-11 01:01:24 +01:00
$zip -> addFromString ( $dirname . T_WARNING_FILENAME , $info );
2022-02-10 01:37:43 +01:00
}
2022-02-11 01:01:24 +01:00
foreach ([ T_OLD , T_NEW ] as $cat )
2022-02-19 12:00:16 +01:00
if ( isset ( $archiveContent [ $cat ])) {
2022-02-17 18:13:09 +01:00
$subdir = $dirname . " - " . ( $cat == T_NEW ? M_NEW_ATTACHEMENT_DIRNAME : M_OLD_ATTACHEMENT_DIRNAME );
foreach ( $archiveContent [ $cat ][ T_ENTRIES ] as $entry ) {
2022-02-11 01:01:24 +01:00
$p = s2p ( $entry [ T_HASH ]);
if ( $entry [ T_CRYPTED ]) {
2022-02-10 01:37:43 +01:00
$m = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
2022-02-11 01:01:24 +01:00
$md5_key = md5 ( $entry [ T_CRYPT_KEY ]);
2022-02-17 18:13:09 +01:00
$iv = jirafeau_crypt_create_iv ( $md5Key , mcrypt_enc_get_iv_size ( $m ));
mcrypt_generic_init ( $m , $md5Key , $iv );
2022-02-11 01:01:24 +01:00
$r = fopen ( VAR_FILES . $p . $entry [ T_HASH ], 'r' );
2022-02-10 01:37:43 +01:00
$content = " " ;
while ( ! feof ( $r )) {
$dec = mdecrypt_generic ( $m , fread ( $r , 1024 ));
$content .= $dec ;
ob_flush ();
}
fclose ( $r );
2022-02-11 01:01:24 +01:00
$zip -> addFromString ( $subdir . " / " . $entry [ T_FILENAME ], $content );
2022-02-10 01:37:43 +01:00
mcrypt_generic_deinit ( $m );
mcrypt_module_close ( $m );
continue ;
}
2022-02-11 01:01:24 +01:00
$zip -> addFile ( VAR_FILES . $p . $entry [ T_HASH ], $subdir . " / " . $entry [ T_FILENAME ]);
2022-02-10 01:37:43 +01:00
}
}
$zip -> close ();
if ( false ) {
2022-02-19 09:09:45 +01:00
// log
2022-02-17 18:13:09 +01:00
$message .= print_r ( $archiveInfo , 1 );
$message .= print_r ( $archiveContent , 1 );
2022-02-10 01:37:43 +01:00
2022-02-11 01:01:24 +01:00
header ( 'HTTP/1.0 200 OK' );
2022-02-17 18:13:09 +01:00
header ( 'Content-Length: ' . strlen ( $message ));
2022-02-11 01:01:24 +01:00
header ( 'Content-Type: text/plain' );
2022-02-17 18:13:09 +01:00
echo $message ;
2022-02-10 01:37:43 +01:00
exit ;
}
2022-02-17 18:13:09 +01:00
if ( ! is_file ( $tmpFileName . T_ZIP_EXT ,))
returnError ( E_OPEN_ZIP );
2022-02-10 01:37:43 +01:00
header ( " Content-Type: application/zip " );
header ( 'Content-Disposition: filename="' . $dirname . '.zip"' );
2022-02-11 01:01:24 +01:00
$r = fopen ( $tmpFileName . " .zip " , 'r' );
2022-02-10 01:37:43 +01:00
while ( ! feof ( $r )) {
print fread ( $r , 1024 );
ob_flush ();
}
fclose ( $r );
unlink ( $tmpFileName . " .zip " );
unlink ( $tmpFileName );
exit ;
}
2022-02-12 22:50:10 +01:00
// ========================================
// form
$token = '' ;
if ( isset ( $_REQUEST [ A_TOKEN ]) && ! empty ( $_REQUEST [ A_TOKEN ])) {
if ( ! preg_match ( " /^([0-9a-zA-Z_-]+) $ / " , $_REQUEST [ A_TOKEN ]))
return false ;
$token = $_REQUEST [ A_TOKEN ];
}
$refToken = getToken ( $sender );
2022-02-17 18:13:09 +01:00
$urlBase = $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ] . " :// " . $_SERVER [ 'HTTP_HOST' ];
2022-02-19 08:43:14 +01:00
if ( isset ( $_REQUEST [ A_ACTION ]) && $_REQUEST [ A_ACTION ] == T_LOGIN && $sender ) {
2022-02-12 22:50:10 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/header.php' );
2022-02-17 18:13:09 +01:00
if ( getSenderFake ( $sender ))
2022-02-15 13:30:19 +01:00
echo " Ce compte ne peut plus se connecter. Veuillez contacter les administrateurs. " ;
else {
$token = setToken ( $sender );
// XXX test token
2022-02-17 18:13:09 +01:00
$url = $urlBase . $_SERVER [ 'SCRIPT_NAME' ] . " ? " . A_SENDER . " = " . $sender . " & " . A_TOKEN . " = " . $token ;
$result = sendEMail ( $sender , " " , M_EMAIL_SUBJECT ,
str_replace ([ " ___LINK___ " , " ___IP___ " , " ___DATE___ " ],
[ $url , $_SERVER [ 'HTTP_X_REAL_IP' ] , date ( " Y-m-d H:i:s " )], M_EMAIL_CONTENT ));
2022-02-16 16:14:35 +01:00
if ( $result )
echo M_SEND_TOKEN ;
else
echo
" Erreur dans l'envoi. Véritiez votre mèl. " ;
2022-02-15 13:30:19 +01:00
}
2022-02-19 12:00:16 +01:00
echo " <br/><br/><br/> " ;
2022-02-12 22:50:10 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/footer.php' );
exit ;
2022-02-10 01:37:43 +01:00
}
2022-02-14 17:07:18 +01:00
if ( ! ( $sender && $token && $token == $refToken &&
( getLoggedToken ( $sender ) || ( getTimeToken ( $sender ) >= strtotime ( TOKEN_LOGIN_LIMIT ))) &&
( getCreateToken ( $sender ) >= strtotime ( TOKEN_LOGOUT_LIMIT )))) {
2022-02-12 22:50:10 +01:00
// XXX temps de connexion
2022-02-11 01:01:24 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/header.php' );
echo M_INTRO_FORM ;
2022-02-12 22:50:10 +01:00
if ( $senderError )
echo " <p> " . M_BAD_SENDER_NAME . " </p> " ;
else if (( $token && ! $refToken ) || ! getLoggedToken ( $sender ))
echo " <p> " . M_TOO_LONG_BEFORE_LOGGED . " </p> " ;
else if ( $token && $token != $refToken )
echo " <p> " . M_BAD_TOKEN . " </p> " ;
else if ( getCreateToken ( $sender ) < strtotime ( TOKEN_LOGOUT_LIMIT ))
echo " <p> " . M_TOO_LONG_LOGGED . " </p> " ;
2022-02-11 01:01:24 +01:00
?>
< Form method = " post " class = " form login " >
2022-02-12 22:50:10 +01:00
< fieldset >
2022-02-11 01:01:24 +01:00
< table >
< tr >
2022-02-12 22:50:10 +01:00
< td class = " label " >< label for = " enter_password " >< ? php echo M_MEL . ' :' ; ?> </label>
2022-02-11 01:01:24 +01:00
</ td >
</ tr >
< tr >
2022-02-12 22:50:10 +01:00
< td class = " field " >< input type = " text " name = " <?php echo A_SENDER; ?> " size = " 40 " value = " <?php echo jirafeau_escape ( $_REQUEST [A_SENDER]);?> " />
2022-02-11 01:01:24 +01:00
</ td >
</ tr >
2022-02-12 22:50:10 +01:00
< tr class = " nav " >
< td class = " nav next " >
2022-02-19 08:43:14 +01:00
< input type = " hidden " name = " <?php echo A_ACTION; ?> " value = " <?php echo T_LOGIN; ?> " />
2022-02-12 22:50:10 +01:00
< input type = " submit " value = " <?php echo M_SEND; ?> " />
2022-02-11 01:01:24 +01:00
</ td >
</ tr >
</ table >
</ fieldset >
</ form >
< ? php
require ( JIRAFEAU_ROOT . 'lib/template/footer.php' );
exit ;
}
2022-02-12 22:50:10 +01:00
if ( ! getLoggedToken ( $sender ))
setLoggedToken ( $sender , $token );
else
touch ( VAR_TOKENS . $sender );
2022-02-11 01:01:24 +01:00
2022-02-17 18:13:09 +01:00
function deleteAction ( $linkName ) {
2022-02-14 17:07:18 +01:00
global $sender , $token , $message , $doLogout ;
2022-02-17 18:13:09 +01:00
$link = jirafeau_get_link ( $linkName );
//$message .= "ln: ".$linkName." l: "."<pre>".print_r ($link, 1)."</pre> mt: ".getTimeFile ($link ['hash'])."</br>";
2022-02-14 17:07:18 +01:00
if ( ! count ( $link ))
return ;
if ( isKazArchive ( $link )) {
2022-02-17 18:13:09 +01:00
$dirName = $linkName ;
$dirLink = $link ;
$dirTime = $dirLink [ 'upload_date' ];
$archiveInfo = readArchiveFromLink ( $dirLink );
if ( ! count ( $archiveInfo ))
2022-02-15 13:30:19 +01:00
return ;
2022-02-17 18:13:09 +01:00
if ( $sender != $archiveInfo [ T_SENDER ]) {
2022-02-19 08:43:14 +01:00
setSenderFake ( " rmdir: not owner " , $sender , $archiveInfo [ T_SENDER ], $dirLink , null );
2022-02-18 18:30:30 +01:00
$message .= " Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire " ;
2022-02-15 13:30:19 +01:00
return ;
}
2022-02-17 18:13:09 +01:00
$fileToDelete = false ;
if ( $archiveInfo [ T_NEW ])
foreach ( $archiveInfo [ T_NEW ] as [ $fileName , $cryptKey ]) {
$fileLink = jirafeau_get_link ( $fileName );
if ( ! count ( $fileLink ))
2022-02-14 17:07:18 +01:00
continue ;
2022-02-17 18:13:09 +01:00
$fileTime = $fileLink [ 'upload_date' ];
2022-02-15 13:30:19 +01:00
if ( ! valideTime ( $dirTime , $fileTime )) {
2022-02-19 08:43:14 +01:00
setSenderFake ( " rmdir: newfile not same time " , $sender , null , $dirLink , $fileLink );
2022-02-17 18:13:09 +01:00
$message .= " Cet envoi a été forgée " .
str_replace ([ " ___FILENAME___ " , " ___DIRTIME___ " , " ___FILETIME___ " ],
[ $fileLink [ 'file_name' ], $dirTime , $fileTime ], M_INCONSISTENT_DATES );
2022-02-14 17:07:18 +01:00
return ;
}
2022-02-17 18:13:09 +01:00
$fileToDelete = true ;
2022-02-14 17:07:18 +01:00
}
2022-02-17 18:13:09 +01:00
$message .= " l'envoi " . $archiveInfo [ T_TIME ] . " est supprimé " ;
if ( $fileToDelete )
$message .= " avec<ul> " ;
if ( $archiveInfo [ T_NEW ])
foreach ( $archiveInfo [ T_NEW ] as [ $fileName , $cryptKey ]) {
$fileLink = jirafeau_get_link ( $fileName );
if ( ! count ( $fileLink ))
2022-02-14 17:07:18 +01:00
continue ;
2022-02-17 18:13:09 +01:00
$message .= " <li> " . jirafeau_escape ( $fileLink [ 'file_name' ]) . " </li> " ;
jirafeau_delete_link ( $fileName );
2022-02-14 17:07:18 +01:00
}
2022-02-17 18:13:09 +01:00
jirafeau_delete_link ( $dirName );
$message .= $fileToDelete ? " </ul> " : " . " ;
2022-02-15 13:30:19 +01:00
return ;
}
2022-02-17 18:13:09 +01:00
$fileName = $linkName ;
$fileLink = $link ;
$fileTime = $fileLink [ 'upload_date' ];
2022-02-15 13:30:19 +01:00
$stack = array ( VAR_LINKS );
while (( $d = array_shift ( $stack )) && $d != null ) {
if ( ! file_exists ( $d ))
continue ;
$dir = scandir ( $d );
2022-02-17 18:13:09 +01:00
foreach ( $dir as $dirName ) {
if ( strcmp ( $dirName , '.' ) == 0 || strcmp ( $dirName , '..' ) == 0 ||
preg_match ( '/\.tmp/i' , " $dirName " )) {
2022-02-15 13:30:19 +01:00
continue ;
}
2022-02-17 18:13:09 +01:00
if ( is_dir ( $d . $dirName )) {
$stack [] = $d . $dirName . '/' ;
2022-02-15 13:30:19 +01:00
continue ;
}
2022-02-17 18:13:09 +01:00
$dirLink = jirafeau_get_link ( $dirName );
//$dirTime = getTimeFile ($dirLink ['hash']);
$dirTime = $dirLink [ 'upload_date' ];
if ( ! count ( $dirLink ))
2022-02-15 13:30:19 +01:00
continue ;
2022-02-17 18:13:09 +01:00
if ( ! isKazArchive ( $dirLink ))
2022-02-15 13:30:19 +01:00
continue ;
2022-02-17 18:13:09 +01:00
$archiveInfo = readArchiveFromLink ( $dirLink );
if ( ! count ( $archiveInfo ))
2022-02-15 13:30:19 +01:00
return ;
2022-02-17 18:13:09 +01:00
if ( $archiveInfo [ T_NEW ])
foreach ( $archiveInfo [ T_NEW ] as [ $newName , $cryptKey ]) {
if ( $fileName != $newName )
2022-02-15 13:30:19 +01:00
continue ;
2022-02-17 18:13:09 +01:00
if ( $sender == $archiveInfo [ T_SENDER ]) {
2022-02-15 13:30:19 +01:00
if ( valideTime ( $dirTime , $fileTime )) {
2022-02-17 18:13:09 +01:00
jirafeau_delete_link ( $fileName );
$message .= jirafeau_escape ( $fileLink [ 'file_name' ]) . " est supprimé " ;
2022-02-15 13:30:19 +01:00
// check empty dir
$empty = true ;
foreach ([ T_OLD , T_NEW ] as $cat )
2022-02-17 18:13:09 +01:00
if ( $empty && isset ( $archiveInfo [ $cat ]))
foreach ( $archiveInfo [ $cat ] as [ $l , $c ])
2022-02-15 13:30:19 +01:00
if ( count ( jirafeau_get_link ( $l ))) {
$empty = false ;
break ;
}
if ( $empty ) {
2022-02-17 18:13:09 +01:00
$message .= " ainsi que l'envoie " . $archiveInfo [ T_TIME ] . " qui est vide. " ;
jirafeau_delete_link ( $dirName );
} else
$message .= " . " ;
2022-02-14 17:07:18 +01:00
break ;
}
2022-02-19 08:43:14 +01:00
setSenderFake ( " rm: dir not same time " , $sender , null , $dirLink , $fileLink );
2022-02-17 18:13:09 +01:00
$message .= " Cet envoi a été forgée. " .
str_replace ([ " ___FILENAME___ " , " ___DIRTIME___ " , " ___FILETIME___ " ],
[ $fileLink [ 'file_name' ], $dirTime , $fileTime ], M_INCONSISTENT_DATES );
2022-02-15 13:30:19 +01:00
break ;
}
if ( valideTime ( $dirTime , $fileTime )) {
2022-02-19 08:43:14 +01:00
setSenderFake ( " rm: not owner " , $sender , $archiveInfo [ T_SENDER ], $dirLink , $fileLink );
2022-02-17 18:13:09 +01:00
$message .= " Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire. " .
str_replace ([ " ___FILENAME___ " , " ___DIRTIME___ " , " ___FILETIME___ " ],
[ $fileLink [ 'file_name' ], $dirTime , $fileTime ], M_INCONSISTENT_DATES );
2022-02-14 17:07:18 +01:00
break ;
}
2022-02-19 08:43:14 +01:00
setSenderFake ( " rm: find not owner " , $archiveInfo [ T_SENDER ], $sender , $dirLink , $fileLink );
2022-02-17 18:13:09 +01:00
$message .= " Quelqu'un avétait revandiqué cet envoi. ( " . $sender . " != " . $archiveInfo [ T_SENDER ] . " ) " ;
2022-02-15 13:30:19 +01:00
break ;
2022-02-14 17:07:18 +01:00
}
}
}
}
2022-02-12 22:50:10 +01:00
// ========================================
2022-02-14 17:07:18 +01:00
// sender OK, token OK
// ========================================
// delete
if ( isset ( $_REQUEST [ A_DELETE ])) {
if ( ! preg_match ( '/[0-9a-zA-Z_-]+$/' , $_REQUEST [ A_DELETE ]))
2022-02-17 18:13:09 +01:00
returnError ( t ( 'FILE_404' ));
2022-02-14 17:07:18 +01:00
deleteAction ( $_REQUEST [ A_DELETE ]);
}
// logout
if ( $doLogout || ( isset ( $_REQUEST [ A_ACTION ]) && $_REQUEST [ A_ACTION ] == T_LOGOUT )) {
2022-02-12 22:50:10 +01:00
rmToken ( $sender );
2022-02-11 01:01:24 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/header.php' );
2022-02-20 19:00:13 +01:00
echo str_replace ([ " ___SENDER___ " , " ___DATE___ " ], [ $sender , jirafeau_get_datetimefield ( time ())], M_WELCOME );
2022-02-14 17:07:18 +01:00
if ( $message )
2022-02-15 13:30:19 +01:00
echo " <p>Info : " . $message . " </p> " ;
2022-02-12 22:50:10 +01:00
echo M_LOGOUT ;
2022-02-11 01:01:24 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/footer.php' );
exit ;
}
2022-02-12 22:50:10 +01:00
if ( isset ( $_REQUEST [ A_ACTION ])) {
2022-02-15 13:30:19 +01:00
// change track
switch ( true ) {
case preg_match ( " /^ " . A_RECORD . " (on|off) $ /i " , $_REQUEST [ A_ACTION ], $matches ) :
if ( $matches [ 1 ] == " on " )
2022-02-17 18:13:09 +01:00
setSenderTrack ( $sender );
2022-02-15 13:30:19 +01:00
else
2022-02-17 18:13:09 +01:00
rmSenderTrack ( $sender );
2022-02-15 13:30:19 +01:00
$message .= " Votre suivi à été mise à jour. " ;
break ;
case preg_match ( " /^ " . A_PERIOD . " ( " . implode ( " | " , array_keys ( $periodText )) . " ) $ /i " , $_REQUEST [ A_ACTION ], $matches ) :
2022-02-17 18:13:09 +01:00
setSenderPeriod ( $sender , $matches [ 1 ]);
2022-02-15 13:30:19 +01:00
$message .= " Votre période à été mise à jour. " ;
break ;
}
2022-02-12 22:50:10 +01:00
}
// list
$archives = [];
2022-02-11 01:01:24 +01:00
$stack = array ( VAR_LINKS );
while ( ( $d = array_shift ( $stack )) && $d != null ) {
$dir = scandir ( $d );
2022-02-17 18:13:09 +01:00
foreach ( $dir as $dirName ) {
if ( strcmp ( $dirName , '.' ) == 0 || strcmp ( $dirName , '..' ) == 0 ||
preg_match ( '/\.tmp/i' , " $dirName " )) {
2022-02-11 01:01:24 +01:00
continue ;
}
2022-02-17 18:13:09 +01:00
if ( is_dir ( $d . $dirName )) {
2022-02-11 01:01:24 +01:00
/* Push new found directory. */
2022-02-17 18:13:09 +01:00
$stack [] = $d . $dirName . '/' ;
2022-02-14 17:07:18 +01:00
continue ;
2022-02-11 01:01:24 +01:00
}
2022-02-14 17:07:18 +01:00
/* Read link informations. */
2022-02-17 18:13:09 +01:00
$l = jirafeau_get_link ( $dirName );
2022-02-14 17:07:18 +01:00
if ( ! count ( $l ))
continue ;
if ( ! isKazArchive ( $l ))
continue ;
2022-02-17 18:13:09 +01:00
$archiveInfo = readArchiveFromLink ( $l );
if ( $sender != $archiveInfo [ T_SENDER ])
2022-02-14 17:07:18 +01:00
continue ;
2022-02-17 18:13:09 +01:00
$archiveInfo [ 'link' ] = $dirName ;
$archiveInfo [ 'key' ] = $l [ 'key' ];
$archiveInfo [ 'maxtime' ] = $l [ 'time' ];
$archiveInfo [ 'hash' ] = $l [ 'hash' ];
$archives [] = $archiveInfo ;
2022-02-11 01:01:24 +01:00
}
}
2022-02-12 22:50:10 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/header.php' );
2022-02-20 19:00:13 +01:00
echo str_replace ([ " ___SENDER___ " , " ___DATE___ " ], [ $sender , jirafeau_get_datetimefield ( time ())], M_WELCOME );
2022-02-14 17:07:18 +01:00
if ( $message )
2022-02-15 13:30:19 +01:00
echo " <p>Info : " . $message . " </p> " ;
2022-02-14 17:07:18 +01:00
echo '<script type="text/javascript">' ;
2022-02-12 22:50:10 +01:00
?>
2022-02-14 17:07:18 +01:00
function getURI ( uri , params ) {
var form = document . createElement ( 'form' );
form . setAttribute ( 'method' , 'post' );
2022-02-17 18:13:09 +01:00
form . setAttribute ( 'action' , " <?php echo $urlBase ; ?> " + uri );
2022-02-14 17:07:18 +01:00
var hiddenField = document . createElement ( 'input' );
for ( var key in params ) {
if ( params . hasOwnProperty ( key )) {
var hiddenField = document . createElement ( 'input' );
hiddenField . setAttribute ( 'type' , 'hidden' );
hiddenField . setAttribute ( 'name' , key );
hiddenField . setAttribute ( 'value' , params [ key ]);
form . appendChild ( hiddenField );
}
document . body . appendChild ( form );
form . submit ();
}
}
function getKazArchive ( l , k ) {
getURI ( " <?php echo $_SERVER ['SCRIPT_NAME']; ?> " , { < ? php echo A_GET ; ?> :l+'~'+k});
}
function getKazFile ( l , k ) {
2022-02-17 18:13:09 +01:00
window . location . href = " <?php echo $urlBase ; ?>/f.php?h= " + l + " &k= " + k ;
2022-02-14 17:07:18 +01:00
}
function showLink ( l , k ) {
2022-02-17 18:13:09 +01:00
alert ( " <?php echo $urlBase ;?>/f.php?h= " + l + " &k= " + k );
2022-02-14 17:07:18 +01:00
}
function ajaxUpdate ( period , hash ) {
var xhr = new XMLHttpRequest ();
xhr . open ( " POST " , " <?php echo $_SERVER ['SCRIPT_NAME']; ?> " , true );
xhr . setRequestHeader ( " Content-Type " , " application/x-www-form-urlencoded " );
xhr . onreadystatechange = function () {
if ( this . readyState === XMLHttpRequest . DONE && this . status === 200 ) {
2022-02-15 13:30:19 +01:00
getURI ( " <?php echo $_SERVER ['SCRIPT_NAME']; ?> " , { < ? php echo A_SENDER . " : ' " . $sender . " ', " . A_TOKEN . " : ' " . $token . " ' " ; ?> });
2022-02-14 17:07:18 +01:00
}
}
2022-02-20 19:31:35 +01:00
xhr . send ( " <?php echo A_UPDATE; ?>= " + period + " &<?php echo A_HASH; ?>= " + hash );
2022-02-14 17:07:18 +01:00
}
2022-02-15 13:30:19 +01:00
function rmFile ( f ) {
2022-02-14 17:07:18 +01:00
if ( ! confirm ( " Les suppressions sont definitives. Voulez-vous continuer ? " ))
return ;
getURI ( " <?php echo $_SERVER ['SCRIPT_NAME']; ?> " , { < ? php echo A_DELETE ; ?> : f, <?php echo A_SENDER.": '".$sender."', ".A_TOKEN.": '".$token."'"; ?>});
}
2022-02-12 22:50:10 +01:00
</ script >
2022-02-14 17:07:18 +01:00
< style type = " text/css " ><!-- a { text - decoration : none ;}
2022-02-15 13:30:19 +01:00
div . frame { border : 1 px ; border - style : solid ; padding : 1 em ; margin : 1 em ;}
2022-02-14 17:07:18 +01:00
[ data - tooltip ] : before { position : absolute ; content : attr ( data - tooltip ); opacity : 0 ; background : yellow ; padding : 10 px ; marging : 1 em ; transform : translate ( 10 px , 10 px );}
[ data - tooltip ] : hover : before { opacity : 1 ;}
[ data - tooltip ] : not ([ data - tooltip - persistent ]) : before { pointer - events : none ;}
--></ style >
2022-02-12 22:50:10 +01:00
< ? php
2022-02-15 13:30:19 +01:00
$defaultChecked = [];
2022-02-17 18:13:09 +01:00
$defaultChecked [ getSenderTrack ( $sender ) ? " on " : " off " ] = ' checked="checked"' ;
$defaultChecked [ getSenderPeriod ( $sender )] = ' selected="selected"' ;
2022-02-12 22:50:10 +01:00
echo
'<form method="post">' .
2022-02-16 16:14:35 +01:00
'Je veux que Kaz suive tous mes futurs envois: ' .
2022-02-12 22:50:10 +01:00
'<input type="hidden" name="' . A_SENDER . '" value="' . $sender . '"/>' .
2022-02-15 13:30:19 +01:00
'<input type="hidden" name="' . A_TOKEN . '" value="' . $token . '"/>' ;
foreach ( $trackText as $item => $text )
echo '<input type="radio" name="' . A_ACTION . '" value="' . A_RECORD . $item . '"' . $defaultChecked [ $item ] . '>' . $text . ' ' ;
echo
2022-02-14 17:07:18 +01:00
'<button type="submit">' . " valider " . '</button>' .
2022-02-12 22:50:10 +01:00
'</form>' .
'<form method="post">' .
2022-02-15 13:30:19 +01:00
'Je veux que mes futurs envois soient accessibles pendant au moins un·e ' .
'<select name="' . A_ACTION . '" style="width: auto !important;">' ;
foreach ( $periodText as $item => $text )
echo ' <option value="' . A_PERIOD . $item . '"' . $defaultChecked [ $item ] . '>' . $text . '</option>' ;
echo
'</select> ' .
'<button type="submit">' . " valider " . '</button>' .
'</form>' .
'<form method="post">' .
'Je veux ' .
'<input type="hidden" name="' . A_SENDER . '" value="' . $sender . '"/>' .
'<input type="hidden" name="' . A_TOKEN . '" value="' . $token . '"/>' .
'<button type="submit">' . M_REFRESH . '</button>' .
2022-02-16 16:14:35 +01:00
' la page.</form>' ;
2022-02-12 22:50:10 +01:00
2022-02-16 16:14:35 +01:00
$userSise = 0 ;
$userTab = [];
2022-02-12 22:50:10 +01:00
if ( $archives ) {
2022-02-17 18:13:09 +01:00
foreach ( $archives as $archiveInfo ) {
2022-02-16 16:14:35 +01:00
$contentSize = 0 ;
$archContent = '' ;
2022-02-12 22:50:10 +01:00
foreach ([ T_NEW , T_OLD ] as $cat ) {
2022-02-17 18:13:09 +01:00
$liStyle = $cat == T_NEW ? " font-weight: bold; " : " font-style: italic; " ;
if ( isset ( $archiveInfo [ $cat ]))
foreach ( $archiveInfo [ $cat ] as [ $linkName , $cryptKey ]) {
$link = jirafeau_get_link ( $linkName );
2022-02-12 22:50:10 +01:00
if ( count ( $link ) == 0 )
continue ;
2022-02-16 16:14:35 +01:00
if ( $cat == T_NEW )
$contentSize += $link [ 'file_size' ];
2022-02-17 18:13:09 +01:00
$lf = $linkName ;
2022-02-14 17:07:18 +01:00
$kf = $link [ 'key' ];
2022-02-16 16:14:35 +01:00
$archContent .=
2022-02-17 18:13:09 +01:00
'<li style="list-style:none; ' . $liStyle . '">' .
2022-02-16 16:14:35 +01:00
'<a data-tooltip="voir" href="javascript:getKazFile (\'' . $lf . '\', \'' . $kf . '\');"> 👁 </a>' .
'<a data-tooltip="voir le lien" href="javascript:showLink (\'' . $lf . '\', \'' . $kf . '\');"> 🔗 </a>' ;
// foreach ($periodButton as $item => $bt)
// echo '<a data-tooltip="'.$bt[1].'" href="javascript:ajaxUpdate (\''.$lf.'\', \''.$kf.'\');"> '.$bt[0].' </a>';
$archContent .=
jirafeau_escape ( $link [ 'file_name' ]) .
' (' . jirafeau_escape ( $link [ 'mime_type' ]) .
' ' . jirafeau_human_size ( $link [ 'file_size' ]) . ')' ;
2022-02-14 17:07:18 +01:00
if ( $cat == T_NEW )
2022-02-16 16:14:35 +01:00
$archContent .=
'<a data-tooltip="supprimer" href="javascript:rmFile (\'' . $lf . '\');"> ♺ </a>' ;
$archContent .=
'</li>' ;
2022-02-12 22:50:10 +01:00
}
}
2022-02-16 16:14:35 +01:00
$archEntry =
'<div class="frame" width="100%" >' ;
2022-02-17 18:13:09 +01:00
$la = $archiveInfo [ 'link' ];
$ka = $archiveInfo [ 'key' ];
2022-02-16 16:14:35 +01:00
$archEntry .=
'<a data-tooltip="voir" href="javascript:getKazArchive (\'' . $la . '\', \'' . $ka . '\');"> 👁 </a>' .
'<a data-tooltip="voir le lien" href="javascript:showLink (\'' . $la . '\', \'' . $ka . '\');"> 🔗 </a>' ;
foreach ( $periodButton as $item => $bt )
$archEntry .=
2022-02-20 19:00:13 +01:00
'<a data-tooltip="' . $bt [ 1 ] . '" href="javascript:ajaxUpdate (\'' . $item . '\', \'' . $la . '\');"> ' . $bt [ 0 ] . ' </a>' ;
2022-02-16 16:14:35 +01:00
$archEntry .=
2022-02-17 18:13:09 +01:00
'<strong>' . $archiveInfo [ T_TIME ] . ' (' . jirafeau_human_size ( $contentSize ) . ')</strong>' .
2022-02-16 16:14:35 +01:00
'<a data-tooltip="supprimer tous" href="javascript:rmFile (\'' . $la . '\');"> ♺ </a>' .
2022-02-17 18:13:09 +01:00
'<br/>=> ' . ( $archiveInfo [ 'maxtime' ] == - 1 ? '∞' : jirafeau_get_datetimefield ( $archiveInfo [ 'maxtime' ])) . '<ul>' .
2022-02-16 16:14:35 +01:00
$archContent .
'</div>' ;
$userSise += $contentSize ;
2022-02-17 18:13:09 +01:00
$userTab [ getTimeFile ( $archiveInfo [ 'hash' ])] = $archEntry ;
2022-02-12 22:50:10 +01:00
}
2022-02-16 16:14:35 +01:00
ksort ( $userTab );
}
echo
2022-02-20 19:00:13 +01:00
'<p>Votre compte occupe <b>' . jirafeau_human_size ( $userSise ) . '</b>.</p>' .
2022-02-16 16:14:35 +01:00
'<form method="post">' .
'Je veux me ' .
'<input type="hidden" name="' . A_ACTION . '" value="' . T_LOGOUT . '" />' .
'<input type="hidden" name="' . A_SENDER . '" value="' . $sender . '"/>' .
'<input type="hidden" name="' . A_TOKEN . '" value="' . $token . '"/>' .
'<button type="submit">' . M_LOGOUT . '</button>' .
'.</form>' ;
if ( count ( $userTab )) {
foreach ( $userTab as $time => $entry )
echo $entry ;
2022-02-12 22:50:10 +01:00
} else
2022-02-16 16:14:35 +01:00
echo
" <p>Il n'y a aucune information vous concernant.</p> " ;
2022-02-12 22:50:10 +01:00
require ( JIRAFEAU_ROOT . 'lib/template/footer.php' );
exit ;
2022-02-17 18:13:09 +01:00
// ========================================