diff --git a/src/Jirafeau/a.php b/src/Jirafeau/a.php
index cf9af98..0ecfe19 100644
--- a/src/Jirafeau/a.php
+++ b/src/Jirafeau/a.php
@@ -1,16 +1,27 @@
track
- a.php?p=email => period
- a.php?u=month&h=HHHHHHHH => update deadline
- a.php?g=l~k => zip
- 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|semester]
+ a.php?time=[month|...]&key={password} + POST file => upload
+ a.php?g={linkHash}~{key} => zip
+ a.php?c=[minute|hour|day|week|month|quarter|semester] => update track cache => cron
+ a.php?u=[month|...]&h={linkHash} => update deadline
+ a.php?r={email} => track status
+ a.php?p={email} => period status
+ a.php?l={email} => lang status
+ a.php?s={mel@domain} => form
+ a.php?s={mel@domain}&t={token}&{action} => manage account
+
+ action:
+ | a=login => login
+ | a=logout => logout
+ | a=m[none|footer|attachment|both] => set mode
+ | a=c[minute|hour|day|week|month|quarter|semester] => update track cache
+ | a=r[on|off] => set followed email
+ | a=p[minute|hour|day|week|month|quarter|semester] => set perriod
+ | a=l[fr|en|br] => set lang
+ | d={linkHash} => delete link
*/
require_once (__DIR__ . "/lib/attach-setup.php");
@@ -18,12 +29,12 @@ require_once (__DIR__ . "/lib/attach-setup.php");
$modeText = ['none' => "sans", 'footer' => "pied de page", 'attachment' => "pièce jointe", 'both' => "les deux"];
$trackText = ['on' => "oui", 'off' => "non"];
$periodText = ['minute' => "minute", 'hour' => "heure", 'day' => "jour", 'week' => "semaine", 'month' => "mois", 'quarter' => "trimestre", "semester" => "semestre"];
-$periodButton = ['hour' => ["🕐", ">1 heure"], // 1F550
- 'day' => ["🕑", ">1 jour"], // 1F551
- 'week' => ["🕒", "> 1 semaine"], // 1F552
- 'month' => ["🕓", "> 1 mois"], // 1F553
- 'quarter' => ["🕔", "> 1 trimestre"], // 1F554
- 'semester' => ["🕕", "> 1 semestre"] // 1F555
+$periodButton = ['hour' => ["🕐", "garantir 1 heure"], // 1F550
+ 'day' => ["🕑", "garantir 1 jour"], // 1F551
+ 'week' => ["🕒", "garantir 1 semaine"], // 1F552
+ 'month' => ["🕓", "garantir 1 mois"], // 1F553
+ 'quarter' => ["🕔", "garantir 1 trimestre"], // 1F554
+ 'semester' => ["🕕", "garantir 1 semestre"] // 1F555
];
$langText = ['fr' => "Francais", 'br' => "Breton", 'en' => "english"];
$doLogout = '';
@@ -91,6 +102,11 @@ if (isset ($_REQUEST [A_GET]) && !empty ($_REQUEST [A_GET])) {
$doDownload = true;
}
+$doCache = false;
+if (isset ($_REQUEST [A_CACHE]) && !empty ($_REQUEST [A_CACHE])) {
+ $doCache = true;
+}
+
// ========================================
function returnError ($msg) {
displayHeadPage ("Gestion des pièces jointes");
@@ -243,58 +259,83 @@ function getArchiveCacheFromSender ($sender) {
$l = jirafeau_get_link ($hash);
if (empty ($l))
continue;
- $archives [] = readArchiveFromLink ($l);
-
- // $p = s2p ($hash);
- // $lines = file (VAR_FILES . $p . $hash);
- // if (!$lines)
- // continue;
- // $archives [] = readArchiveFromLines ($lines);
+ $archives [] = readArchiveFromLink ($l, $hash);
}
return $archives;
}
+function cleanArchiveCache () {
+ global $message, $admin;
+ if (!file_exists (VAR_CACHE))
+ return;
+ $listSender = scandir (VAR_CACHE);
+ foreach ($listSender as $cacheSender) {
+ if (strcmp ($cacheSender, '.') === 0 || strcmp ($cacheSender, '..') === 0 ||
+ preg_match ('/\.tmp/i', "$cacheSender")) {
+ continue;
+ }
+ if (! is_dir (VAR_CACHE.$cacheSender))
+ continue;
+ $listLink = scandir (VAR_CACHE.$cacheSender.'/');
+ foreach ($listLink as $cacheLink) {
+ if (strcmp ($cacheLink, '.') === 0 || strcmp ($cacheLink, '..') === 0 ||
+ preg_match ('/\.tmp/i', "$cacheLink")) {
+ continue;
+ }
+ $link = VAR_LINKS . s2p("$cacheLink") . $cacheLink;
+ if (!file_exists($link)) {
+ if ($admin)
+ $message .= "Remove ".$cacheSender."/".$cacheLink."
";
+ unlink (VAR_CACHE.$cacheSender."/".$cacheLink);
+ }
+ }
+ }
+}
+
function updateArchiveCacheUpTo ($period) {
+ global $message;
+ cleanArchiveCache ();
if (!file_exists (VAR_CACHE))
mkdir (VAR_CACHE, 0755);
$minTime = getArchiveCacheLastUpdate ();
$maxTime = time ()-period2seconds ($period);
$stack = array (VAR_LINKS);
- while ( ($d = array_shift ($stack)) && $d != null) {
- $dir = scandir ($d);
- foreach ($dir as $dirName) {
- if (strcmp ($dirName, '.') === 0 || strcmp ($dirName, '..') === 0 ||
- preg_match ('/\.tmp/i', "$dirName")) {
+ while ( ($dirName = array_shift ($stack)) && $dirName != null) {
+ $list = scandir ($dirName);
+ foreach ($list as $fileName) {
+ if (strcmp ($fileName, '.') === 0 || strcmp ($fileName, '..') === 0 ||
+ preg_match ('/\.tmp/i', "$fileName")) {
continue;
}
- if (is_dir ($d . $dirName)) {
+ if (is_dir ($dirName . $fileName)) {
// Push new found directory.
- $stack [] = $d . $dirName . '/';
+ $stack [] = $dirName . $fileName . '/';
continue;
}
- $time = filemtime ($d . $dirName);
+ $time = filemtime ($dirName . $fileName);
if ($time < $minTime || $time >= $maxTime)
continue;
// Read link informations.
- $l = jirafeau_get_link ($dirName);
+ $l = jirafeau_get_link ($fileName);
if (!count ($l))
continue;
if (!isKazArchive ($l))
continue;
- $archiveInfo = readArchiveFromLink ($l);
+ $archiveInfo = readArchiveFromLink ($l, $fileName);
if (!isset ($archiveInfo [T_SENDER]) || empty ($archiveInfo [T_SENDER]))
continue;
if (!file_exists (VAR_CACHE.$archiveInfo [T_SENDER]))
mkdir (VAR_CACHE.$archiveInfo [T_SENDER], 0755);
- touch (VAR_CACHE.$archiveInfo [T_SENDER]."/".$l ['hash']);
+ touch (VAR_CACHE.$archiveInfo [T_SENDER]."/".$fileName);
}
}
setArchiveCacheLastUpdate ($maxTime);
+ $message .= "Cache mise à jour ({$period}).";
}
// ========================================
-function readArchiveFromLink ($link) {
+function readArchiveFromLink ($link, $linkName) {
$p = s2p ($link ['hash']);
$lines = file (VAR_FILES . $p . $link ['hash']);
if (empty ($lines)) {
@@ -302,9 +343,6 @@ function readArchiveFromLink ($link) {
$message .= "can't read {$linkName}".NL;
return [];
}
-// return readArchiveFromLines ($lines);
-// }
-// function readArchiveFromLines ($lines) {
$archive = [];
$error = false;
foreach ($lines as $line) {
@@ -315,9 +353,7 @@ function readArchiveFromLink ($link) {
case preg_match ("/^\s*time:\s*(\d{4}([:-]\d{2}){5})\s*$/i", $line, $matches):
$archive [T_TIME] = $matches [1];
break;
- // 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):
+ case preg_match ("/^\s*sender:\s*(([a-z0-9_=+-]+)(\.[a-z0-9_=+-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6})\s*$/i", $line, $matches):
$archive [T_SENDER] = $matches [1];
break;
// XXX issue ")"
@@ -335,11 +371,13 @@ function readArchiveFromLink ($link) {
break;
}
}
- global $message, $admin;
- if ($error && $admin)
- $message .= "readArchiveFromLines
".print_r ($lines, true).""; - $archiveInfo ['maxtime'] = $link ['time']; - return $error ? [] : $archive; + if ($error) + return []; + $archive ['maxtime'] = $link ['time']; + $archive ['hash'] = $link ['hash']; + $archive ['key'] = $link ['key']; + $archive ['link'] = $linkName; + return $archive; } // ======================================== @@ -398,27 +436,41 @@ function isAdmin ($sender) { } // ======================================== +function deleteLinkAndCache ($linkName, $fileName) { + global $sender, $message; + jirafeau_delete_link ($linkName); + $cacheToDelete = VAR_CACHE.$sender."/".$linkName; + if (file_exists ($cacheToDelete)) { + if (!empty ($fileName)) + $message .= "
".print_r ($link, 1)."mt: ".getTimeFile ($link ['hash']).""; if (!count ($link)) return; if (isKazArchive ($link)) { + // Acrhive $dirName = $linkName; $dirLink = $link; $dirTime = $dirLink ['upload_date']; - $archiveInfo = readArchiveFromLink ($dirLink); - if (! count ($archiveInfo)) + $archiveInfo = readArchiveFromLink ($dirLink, $linkName); + if (! count ($archiveInfo)) { + $message .= "Archive introuvable ({$dirName})"; return; + } if ($sender != $archiveInfo [T_SENDER]) { setSenderFake ("rmdir: not owner", $sender, $archiveInfo [T_SENDER], $dirLink, null); $message .= "Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire"; return; } $fileToDelete = false; - if ($archiveInfo [T_NEWKAZ]) + if (isset ($archiveInfo [T_NEWKAZ]) && count ($archiveInfo [T_NEWKAZ])) foreach ($archiveInfo [T_NEWKAZ] as [$fileName, $cryptKey]) { $fileLink = jirafeau_get_link ($fileName); if (! count ($fileLink)) @@ -427,8 +479,8 @@ function deleteAction ($linkName) { if (! valideTime ($dirTime, $fileTime)) { setSenderFake ("rmdir: newfile not same time", $sender, null, $dirLink, $fileLink); $message .= "Cet envoi a été forgée". - str_replace (["___FILENAME___", "___DIRTIME___", "___FILETIME___"], - [$fileLink ['file_name'], $dirTime , $fileTime], M_INCONSISTENT_DATES); + str_replace (["___FILENAME___", "___DIRTIME___", "___FILETIME___"], + [$fileLink ['file_name'], $dirTime , $fileTime], M_INCONSISTENT_DATES); return; } $fileToDelete = true; @@ -436,90 +488,21 @@ function deleteAction ($linkName) { $message .= "l'envoi ".$archiveInfo [T_TIME]." est supprimé"; if ($fileToDelete) $message .= " avec