depollueur/src/Jirafeau/a.php

687 lines
25 KiB
PHP
Raw Normal View History

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
a.php?u=month&h=HHHHHHHH => deadline
a.php?g=l~k => zip
a.php?s=mel@domain.org => send status e-mail
*/
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-12 22:50:10 +01:00
define ('VAR_TOKENS', $cfg['var_root'] . 'tokens/');
define ('VAR_TRACKS', $cfg['var_root'] . 'tracks/');
define ('TOKEN_USE_LIMIT', "-2 hours");
define ('TOKEN_LOGIN_LIMIT', "-15 minutes");
define ('TOKEN_LOGOUT_LIMIT', "-8 hours");
define ('E_BAD_ARCHIVE_NAME', 'Bad archive name format');
2022-02-11 01:01:24 +01:00
define ('E_CREATE_ZIP', "Impossible de cr&eacute;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&egrave;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&eacute;pass&eacute;.");
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&egrave;ces jointes.<br/><br/>!!! Si vous n'&ecirc;tes pas &agrave; 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&egrave;s de Kaz en faisant suivre ce message qui contient les traces de son &eacute;metteur (___IP___, ___DATE___).<br/><br/>Bonne navigation.<br/>.");
define ('M_DOWNLOAD', "T&eacute;l&eacute;charger");
define ('M_UPDATE', "Prolonger");
define ('M_EMAIL_SUBJECT', "Lien de consultation des envoies de pi&egrave;ces jointes.");
2022-02-11 01:01:24 +01:00
define ('M_FILE', " fichier.");
define ('M_FILES', " fichiers.");
define ('M_FILES_NOT_FOUND', " fichiers sont expir&eacute;s.");
define ('M_FILES_RENAMED', " fichiers renomm&eacute;s.");
define ('M_FILE_NOT_FOUND', " fichier est expir&eacute;.");
define ('M_FILE_RENAMED', " fichier renomm&eacute;.");
2022-02-12 22:50:10 +01:00
define ('M_INTRO_FORM', "Quelles sont les informations me concernant ?");
define ('M_MEL', "votre m&egrave;l");
2022-02-11 01:01:24 +01:00
define ('M_NO_FILENAME', 'SansNom');
define ('M_NO_SENDER', 'kaz');
define ('M_OLD_ATTACHEMENT_DIRNAME', "RappelHistorique");
2022-02-12 22:50:10 +01:00
define ('M_SEND', "Connexion");
define ('M_LOGOUT', 'D&eacute;connexion');
define ('M_LOGOUT_TOKEN', "Vous n'&ecirc;tes plus connect&eacute;.");
2022-02-11 01:01:24 +01:00
define ('M_SEND_TOKEN', "Vous allez recevoir un lien d'acc&egrave;s temporaire &agrave; vos donn&eacute;es.");
2022-02-12 22:50:10 +01:00
define ('A_ACTION', 'a');
define ('A_GET', 'g');
define ('A_HASH', 'h');
define ('A_OPEN_TOKEN', 'o'); // ask send token
define ('A_SENDER', 's');
define ('A_TOKEN', 't');
define ('A_UPDATE', 'u');
define ('A_RECORD', 'r');
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');
define ('T_NOT_FOUND', 'not_found');
define ('T_OLD', 'old');
define ('T_RENAME', 'rename');
2022-02-12 22:50:10 +01:00
define ('T_SEND', 'send');
define ('T_LOGOUT', 'lougout');
2022-02-11 01:01:24 +01:00
define ('T_SENDER', 'sender');
define ('T_TIMESTAMP', 'timestamp');
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-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);
$do_update = false;
2022-02-11 01:01:24 +01:00
if (isset ($_REQUEST[A_UPDATE]) && !empty ($_REQUEST[A_UPDATE])) {
2022-02-10 01:37:43 +01:00
$do_update = true;
}
$do_download = false;
2022-02-11 01:01:24 +01:00
if (isset ($_REQUEST[A_GET]) && !empty ($_REQUEST[A_GET])) {
2022-02-10 01:37:43 +01:00
$do_download = true;
}
// ========================================
function return_error ($msg) {
require (JIRAFEAU_ROOT.'lib/template/header.php');
echo '<div class="error"><p>' . $msg . '</p></div>';
require (JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
// ========================================
/** Update link
* @param $link the link's name (hash)
* @param $update_period the periode (i.e in : "month")
*/
2022-02-12 22:50:10 +01:00
function update_link ($link_name, $link, $update_period) {
2022-02-10 01:37:43 +01:00
$time_max = $link ['time'];
$time_up = time () + $update_period;
$time_more = $time_up + JIRAFEAU_HOUR;
if ($time_max < 0 || $time_up < $time_max)
return $time_max;
$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;
}
// ========================================
function read_archive_info ($link) {
$p = s2p ($link ['hash']);
// read archive info
$result=[];
2022-02-11 01:01:24 +01:00
foreach (file (VAR_FILES . $p . $link ['hash']) as $line) {
2022-02-10 01:37:43 +01:00
switch (true) {
case preg_match ("/^\s*src:\s*(([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})\s*$/i", $line, $matches):
2022-02-11 01:01:24 +01:00
$result[T_SENDER] = $matches[1];
2022-02-10 01:37:43 +01:00
break;
case preg_match ("/^\s*time:\s*(\d{4}([:-]\d{2}){5})\s*$/i", $line, $matches):
2022-02-11 01:01:24 +01:00
$result[T_TIMESTAMP] = $matches[1];
2022-02-10 01:37:43 +01:00
break;
case preg_match ("/^\s*old:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
2022-02-11 01:01:24 +01:00
$result[T_OLD][] = [$matches[1], $matches[2]];
2022-02-10 01:37:43 +01:00
break;
case preg_match ("/^\s*new:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
2022-02-11 01:01:24 +01:00
$result[T_NEW][] = [$matches[1], $matches[2]];
2022-02-10 01:37:43 +01:00
break;
default:
break;
}
}
return $result;
}
2022-02-11 01:01:24 +01:00
// ========================================
function send_email($receiver, $receiver_name, $subject, $body_string){
// SERVER SETTINGS
$mail = new PHPMailer (true);
$mail->isSMTP ();
2022-02-12 22:50:10 +01:00
$mail->Host = 'smtp';
$mail->SMTPAuth = false;
2022-02-11 01:01:24 +01:00
$mail->SMTPAutoTLS = false;
2022-02-12 22:50:10 +01:00
$mail->SMTPSecure = "none";
$mail->Port = 25;
$mail->charSet = "UTF-8";
$mail->ContentType = 'text/html';
2022-02-11 01:01:24 +01:00
//Recipients (change this for every project)
$mail->setFrom ('no-reply@kaz.local', '');
$mail->addAddress ($receiver, $receiver_name);
//Content
2022-02-12 22:50:10 +01:00
$mail->isHTML (true);
2022-02-11 01:01:24 +01:00
$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;
}
}
2022-02-10 01:37:43 +01:00
2022-02-12 22:50:10 +01:00
// ========================================
function setTrack ($sender) {
if (!$sender)
return;
if (!file_exists (VAR_TRACKS))
mkdir (VAR_TRACKS, 0755);
touch (VAR_TRACKS.$sender);
}
function rmTrack ($sender) {
if (!$sender)
return;
if (file_exists (VAR_TRACKS.$sender))
unlink (VAR_TRACKS.$sender);
}
function getTrack ($sender) {
if (!$sender)
return;
return file_exists (VAR_TRACKS.$sender);
}
// ========================================
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))
return $matches[1];
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
// ========================================
if ($do_update) {
$update_period = JIRAFEAU_MONTH;
2022-02-11 01:01:24 +01:00
switch ($_REQUEST[A_UPDATE]) {
2022-02-10 01:37:43 +01:00
case 'minute':
$update_period = JIRAFEAU_MINUTE;
break;
case 'hour':
$update_period = JIRAFEAU_HOUR;
break;
case 'day':
$update_period = JIRAFEAU_DAY;
break;
case 'week':
$update_period = JIRAFEAU_WEEK;
break;
case 'month':
$update_period = JIRAFEAU_MONTH;
break;
case 'quarter':
$update_period = JIRAFEAU_QUARTER;
break;
case 'year':
$update_period = JIRAFEAU_YEAR;
break;
default:
2022-02-11 01:01:24 +01:00
return_error (t ('ERR_OCC') . ' (update_period)');
2022-02-10 01:37:43 +01:00
}
2022-02-11 01:01:24 +01:00
$link_name = $_REQUEST[A_HASH];
if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
return_error (t ('FILE_404'));
$link = jirafeau_get_link ($link_name);
if (count ($link) == 0)
return_error (t ('FILE_404'));
2022-02-12 22:50:10 +01:00
$time = update_link ($link_name, $link, $update_period);
2022-02-10 01:37:43 +01:00
$content = '' . $time . NL;
2022-02-12 22:50:10 +01:00
if (@preg_match ("/archive_content/", jirafeau_escape ($link ['file_name'])) &&
jirafeau_escape ($link ['mime_type']) != "text/plain") {
$archive_info = read_archive_info ($l);
if (count ($archive_info)) {
foreach ([T_OLD, T_NEW] as $cat)
if (isset ($archive_info[$cat]))
foreach ($archive_info[$cat] as [$link_name, $crypt_key])
update_link ($link_name, jirafeau_get_link ($link_name), $update_period);
}
}
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])) {
if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_SENDER])) {
$senderError=true;
return;
}
cleanToken ();
$sender = $_REQUEST [A_SENDER];
}
2022-02-10 01:37:43 +01:00
// ========================================
if ($do_download) {
// check archive exist
2022-02-11 01:01:24 +01:00
$couple = explode ("~", $_REQUEST[A_GET], 2);
2022-02-10 01:37:43 +01:00
if (count ($couple) == 0)
2022-02-12 22:50:10 +01:00
return_error (E_BAD_ARCHIVE_NAME);
2022-02-10 01:37:43 +01:00
$link_name = $couple [0];
if (!$link_name || !preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
2022-02-12 22:50:10 +01:00
return_error (E_BAD_ARCHIVE_NAME);
2022-02-10 01:37:43 +01:00
$crypt_key = count ($couple) == 2 ? $couple [1] : "";
$link = jirafeau_get_link ($link_name);
if (count ($link) == 0)
return_error (t ('FILE_404'));
2022-02-11 01:01:24 +01:00
$key = $link ['key'];
2022-02-10 01:37:43 +01:00
if ($key && (empty ($crypt_key) || $key != $crypt_key))
return_error (t ('BAD_PSW'));
$archive_info = read_archive_info ($link);
// check entries
$archive_content = [];
$modif = false;
2022-02-11 01:01:24 +01:00
$single_name = [];
foreach ([T_OLD, T_NEW] as $cat)
2022-02-10 01:37:43 +01:00
if (isset ($archive_info[$cat]))
foreach ($archive_info[$cat] as [$link_name, $crypt_key]) {
$link = jirafeau_get_link ($link_name);
if (count ($link) == 0) {
2022-02-11 01:01:24 +01:00
if (isset ($archive_content[T_NOT_FOUND]))
++$archive_content[T_NOT_FOUND];
else
$archive_content[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-10 01:37:43 +01:00
if ($key && (empty ($crypt_key) || $key != $crypt_key)) {
2022-02-11 01:01:24 +01:00
if (isset ($archive_content[T_BAD_PASW]))
++$archive_content[T_BAD_PASW];
else
$archive_content[T_BAD_PASW] = 1;
2022-02-10 01:37:43 +01:00
$modif = true;
continue;
}
2022-02-11 01:01:24 +01:00
$src_name = $dst_name = ($link ['file_name'] ? $link ['file_name'] : M_NO_FILENAME);
2022-02-10 01:37:43 +01:00
if (in_array ($src_name, $single_name))
for ($i = 0; $i < 10000; ++$i) {
$dst_name = sprintf ("%s-%2d", $src_name, $i);
if (!in_array ($dst_name, $single_name)) {
2022-02-11 01:01:24 +01:00
if (isset ($archive_content[T_RENAME]))
++$archive_content[T_RENAME];
else
$archive_content[T_RENAME] = 1;
2022-02-10 01:37:43 +01:00
$modif = true;
break;
}
}
$single_name [] = $dst_name;
2022-02-11 01:01:24 +01:00
$archive_content[$cat][T_ENTRIES][] = [T_HASH => $link ['hash'], T_FILENAME => $dst_name, T_CRYPT_KEY => $crypt_key, T_CRYPTED => $link['crypted']];
2022-02-10 01:37:43 +01:00
}
// build zip
2022-02-11 01:01:24 +01:00
$dirname = (isset ($archive_info[T_SENDER]) && !empty ($archive_info[T_SENDER]))
2022-02-12 22:50:10 +01:00
? $archive_info[T_SENDER] : ($sender ? $sender : M_NO_SENDER);
2022-02-11 01:01:24 +01:00
$dirname .= "-" . (isset ($archive_info[T_TIMESTAMP]) && !empty ($archive_info[T_TIMESTAMP]))
? $archive_info[T_TIMESTAMP] : date ("Ymd-His");
2022-02-10 01:37:43 +01:00
$tmpFileName = tempnam (sys_get_temp_dir (), $dirname."-");
$zip = new ZipArchive;
if (!$zip)
2022-02-11 01:01:24 +01:00
return_error (E_CREATE_ZIP);
if ($zip->open ($tmpFileName.T_ZIP_EXT, ZipArchive::CREATE) !== TRUE)
return_error (E_OPEN_ZIP);
2022-02-10 01:37:43 +01:00
// create info XXX
if ($modif) {
$info = '';
2022-02-11 01:01:24 +01:00
if (isset ($archive_info[T_NOT_FOUND]))
$info .= $archive_info[T_NOT_FOUND]. ($archive_info[T_NOT_FOUND] ? M_FILE_NOT_FOUND : M_FILES_NOT_FOUND).NL;
if (isset ($archive_info[T_BAD_PASW]))
$info .= M_BAD_KEY. $archive_info[T_BAD_PASW]. ($archive_info[T_BAD_PASW] ? M_FILE : M_FILES).NL;
if (isset ($archive_info[$cat][T_RENAME]))
$info .= $archive_info[$cat][T_RENAME]. ($archive_info[$cat][T_RENAME] ? M_FILE_RENAMED : M_FILES_RENAMED).NL;
$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-10 01:37:43 +01:00
if (isset ($archive_info [$cat])) {
2022-02-11 01:01:24 +01:00
$subdir = $dirname . ($cat == T_NEW ? "" : "/".M_OLD_ATTACHEMENT_DIRNAME);
foreach ($archive_content [$cat][T_ENTRIES] as $entry) {
$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-10 01:37:43 +01:00
$iv = jirafeau_crypt_create_iv ($md5_key, mcrypt_enc_get_iv_size ($m));
mcrypt_generic_init ($m, $md5_key, $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 ();
2022-02-11 01:01:24 +01:00
if (!is_file ($tmpFileName.T_ZIP_EXT,))
return_error (E_OPEN_ZIP);
2022-02-10 01:37:43 +01:00
if (false) {
// log
$content = print_r ($archive_info, 1);
$content .= print_r ($archive_content, 1);
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;
}
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
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]))
return_error (M_BAD_SENDER_NAME);
$content = getTrack ($_REQUEST [A_RECORD]).NL;
header ('HTTP/1.0 200 OK');
header ('Content-Length: ' . strlen ($content));
header ('Content-Type: text/plain');
echo $content;
exit;
}
2022-02-10 01:37:43 +01:00
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);
$url_base = $_SERVER['HTTP_X_FORWARDED_PROTO']."://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?";
if (isset ($_REQUEST [A_ACTION]) && $_REQUEST [A_ACTION] == T_SEND && $sender) {
$token = setToken ($sender);
// XXX test token
$url = $url_base.A_SENDER."=".$sender."&".A_TOKEN."=".$token;
$result = send_email ($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));
require (JIRAFEAU_ROOT . 'lib/template/header.php');
echo M_SEND_TOKEN;
require (JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
2022-02-10 01:37:43 +01:00
}
2022-02-12 22:50:10 +01:00
if (!($sender && $token && $token == $refToken &&
(getLoggedToken ($sender) || (getTimeToken ($sender) >= strtotime (TOKEN_LOGIN_LIMIT))) &&
(getCreateToken ($sender) >= strtotime (TOKEN_LOGOUT_LIMIT)))) {
// 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">
<input type="hidden" name="<?php echo A_ACTION; ?>" value="<?php echo T_SEND; ?>" />
<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-12 22:50:10 +01:00
// ========================================
if (isset ($_REQUEST [A_ACTION]) && $_REQUEST [A_ACTION] == T_LOGOUT) {
rmToken ($sender);
2022-02-11 01:01:24 +01:00
require (JIRAFEAU_ROOT . 'lib/template/header.php');
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])) {
if ($_REQUEST [A_ACTION] == A_RECORD."on")
setTrack ($sender);
else if ($_REQUEST [A_ACTION] == A_RECORD."off")
rmTrack ($sender);
}
// list
$archives = [];
2022-02-11 01:01:24 +01:00
$stack = array (VAR_LINKS);
while ( ($d = array_shift ($stack)) && $d != null) {
$dir = scandir ($d);
foreach ($dir as $node) {
if (strcmp ($node, '.') == 0 || strcmp ($node, '..') == 0 ||
preg_match ('/\.tmp/i', "$node")) {
continue;
}
if (is_dir ($d . $node)) {
/* Push new found directory. */
$stack[] = $d . $node . '/';
} elseif (is_file ($d . $node)) {
/* Read link informations. */
$l = jirafeau_get_link ($node);
if (!count ($l)) {
continue;
}
if (!@preg_match ("/archive_content/", jirafeau_escape ($l ['file_name'])) || jirafeau_escape ($l ['mime_type']) != "text/plain") {
continue;
}
$archive_info = read_archive_info ($l);
if ($sender != $archive_info [T_SENDER])
continue;
2022-02-12 22:50:10 +01:00
$archive_info ['link'] = $node;
$archive_info ['time'] = $l ['time'];
$archive_info ['key'] = $l ['key'];
$archives [] = $archive_info;
2022-02-11 01:01:24 +01:00
}
}
}
2022-02-12 22:50:10 +01:00
require (JIRAFEAU_ROOT . 'lib/template/header.php');
?>
<script type="text/javascript">
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) {
alert ("refarchez la page"); // XXX updage page
}
}
xhr.send ("<?php echo A_UPDATE; ?>="+period+"&<php ecgo A_HASH; ?>="+hash);
}
</script>
<?php
if (getTrack ($sender))
$onChecked=' checked="checked"';
else
$offChecked=' checked="checked"';
echo
'<form method="post">'.
'<input type="hidden" name="'.A_SENDER.'" value="'.$sender.'"/>'.
'<input type="hidden" name="'.A_TOKEN.'" value="'.$token.'"/>'.
'<input type="radio" name="'.A_ACTION.'" value="'.A_RECORD.'on" '.$onChecked.'>oui'.
'<input type="radio" name="'.A_ACTION.'" value="'.A_RECORD.'off" '.$offChecked.'>non'.
'<input type="submit" value="'."valider".'" />'.
'</form>'.
'<form method="post">'.
'<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.'"/>'.
'<input type="submit" value="'.M_LOGOUT.'" />'.
'</form>';
if ($archives) {
echo
// '<fieldset><legend>archives</legend>'.
'<table width="100%" ><tr><th></th><th>'.t('ACTION').'</th></tr>';
foreach ($archives as $archive_info) {
echo '<tr><td><strong>'.$archive_info [T_TIMESTAMP].'</strong>';
echo '<br/>=> '. ($archive_info ['time'] == -1 ? '∞' : jirafeau_get_datetimefield ($archive_info ['time'])).'<ul>';
foreach ([T_NEW, T_OLD] as $cat) {
$li_style = $cat == T_NEW ? "font-weight: bold;" : "font-style: italic;";
if (isset ($archive_info [$cat]))
foreach ($archive_info [$cat] as [$link_name, $crypt_key]) {
$link = jirafeau_get_link ($link_name);
if (count ($link) == 0)
continue;
echo
'<li style="'.$li_style.'">'.jirafeau_escape ($link ['file_name']).
' ('.jirafeau_escape ($link ['mime_type']).
' '.jirafeau_human_size($l['file_size']).
')</li>';
}
}
$dl_val = $archive_info ['link']."~".$archive_info ['key'];
echo
'</ul></td><td style="text-align:center;">'.
'<form method="post">'.
'<input type="hidden" name="'.A_GET.'" value="'.$dl_val.'"/>' .
'<input type="submit" value="'.M_DOWNLOAD.'" />' .
'</form>' .
'<form method="post" onSubmit="return false;">' .
'<input type="submit" value="'.M_UPDATE.'" onClick="ajaxUpdate (\'month\', \''.$archive_info ['link'].'\');"/>' .
'</form>'.
'</td></tr>';
}
echo '</table>';//</fieldset>';
} else
echo "Il n'y a aucune information vous concernant.";
require (JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
2022-02-10 01:37:43 +01:00
?>