clean code
This commit is contained in:
parent
bf06a130f6
commit
d83b89b624
@ -22,7 +22,9 @@ define ('VAR_TOKENS', $cfg ['var_root'].'tokens/');
|
|||||||
define ('VAR_TRACKS', $cfg ['var_root'].'tracks/');
|
define ('VAR_TRACKS', $cfg ['var_root'].'tracks/');
|
||||||
define ('VAR_PERIOD', $cfg ['var_root'].'period/');
|
define ('VAR_PERIOD', $cfg ['var_root'].'period/');
|
||||||
define ('VAR_FAKE', $cfg ['var_root'].'fake/');
|
define ('VAR_FAKE', $cfg ['var_root'].'fake/');
|
||||||
|
define ('VAR_PRIVATE', $cfg ['var_root'].'private/');
|
||||||
|
|
||||||
|
define ('MAX_VALID_UPLOAD_TIME', 60);
|
||||||
define ('TOKEN_USE_LIMIT', "-2 hours");
|
define ('TOKEN_USE_LIMIT', "-2 hours");
|
||||||
define ('TOKEN_LOGIN_LIMIT', "-15 minutes");
|
define ('TOKEN_LOGIN_LIMIT', "-15 minutes");
|
||||||
define ('TOKEN_LOGOUT_LIMIT', "-8 hours");
|
define ('TOKEN_LOGOUT_LIMIT', "-8 hours");
|
||||||
@ -50,12 +52,16 @@ define ('M_INTRO_FORM', "Quelles sont les informations me concernant ?");
|
|||||||
define ('M_MEL', "votre mèl");
|
define ('M_MEL', "votre mèl");
|
||||||
define ('M_NO_FILENAME', 'SansNom');
|
define ('M_NO_FILENAME', 'SansNom');
|
||||||
define ('M_NO_SENDER', 'kaz-');
|
define ('M_NO_SENDER', 'kaz-');
|
||||||
define ('M_OLD_ATTACHEMENT_DIRNAME', "RappelHistorique");
|
define ('M_NEW_ATTACHEMENT_DIRNAME', "nouveau");
|
||||||
|
define ('M_OLD_ATTACHEMENT_DIRNAME', "ancien");
|
||||||
define ('M_SEND', "Connexion");
|
define ('M_SEND', "Connexion");
|
||||||
define ('M_LOGOUT', 'Deconnecter');
|
define ('M_LOGOUT', 'Deconnecter');
|
||||||
define ('M_REFRESH', 'Actualiser');
|
define ('M_REFRESH', 'Actualiser');
|
||||||
define ('M_LOGOUT_TOKEN', "Vous n'êtes plus connecté.");
|
define ('M_LOGOUT_TOKEN', "Vous n'êtes plus connecté.");
|
||||||
define ('M_SEND_TOKEN', "Vous allez recevoir un lien d'accès temporaire à vos données.");
|
define ('M_SEND_TOKEN', "Vous allez recevoir un lien d'accès temporaire à vos données.");
|
||||||
|
define ('M_INCONSISTENT_DATES',
|
||||||
|
" (dates incohéantes avec ___FILENAME___ : ".___DIRTIME___." != ".___FILETIME___." / ".
|
||||||
|
date ("Y-m-d H:i:s", ___DIRTIME___)." != ".date ("Y-m-d H:i:s", ___DIRTIME___).")");
|
||||||
|
|
||||||
define ('A_ACTION', 'a'); // action : T_SEND, T_LOGOUT, A_RECORD+(on|off), A_PERIOD(minute|hour|day|week|month|quarter)
|
define ('A_ACTION', 'a'); // action : T_SEND, T_LOGOUT, A_RECORD+(on|off), A_PERIOD(minute|hour|day|week|month|quarter)
|
||||||
define ('A_GET', 'g'); // get archive
|
define ('A_GET', 'g'); // get archive
|
||||||
@ -76,13 +82,15 @@ define ('T_FILENAME', 'file_name');
|
|||||||
define ('T_HASH', 'hash');
|
define ('T_HASH', 'hash');
|
||||||
define ('T_LOGGED', "logged");
|
define ('T_LOGGED', "logged");
|
||||||
define ('T_NEW', 'new');
|
define ('T_NEW', 'new');
|
||||||
|
define ('T_SIGN', 'sign');
|
||||||
define ('T_NOT_FOUND', 'not_found');
|
define ('T_NOT_FOUND', 'not_found');
|
||||||
define ('T_OLD', 'old');
|
define ('T_OLD', 'old');
|
||||||
define ('T_RENAME', 'rename');
|
define ('T_RENAME', 'rename');
|
||||||
define ('T_SEND', 'send');
|
define ('T_SEND', 'send');
|
||||||
define ('T_LOGOUT', 'lougout');
|
define ('T_LOGOUT', 'lougout');
|
||||||
define ('T_SENDER', 'sender');
|
define ('T_SENDER', 'sender');
|
||||||
define ('T_TIMESTAMP', 'timestamp');
|
define ('T_TIME', 'time');
|
||||||
|
define ('T_ID', 'id');
|
||||||
define ('T_TOKEN', "token");
|
define ('T_TOKEN', "token");
|
||||||
define ('T_WARNING_FILENAME', "-Avertissement.txt");
|
define ('T_WARNING_FILENAME', "-Avertissement.txt");
|
||||||
define ('T_ZIP_EXT', ".zip");
|
define ('T_ZIP_EXT', ".zip");
|
||||||
@ -106,18 +114,23 @@ $message = '';
|
|||||||
/* Remove errors. */
|
/* Remove errors. */
|
||||||
@error_reporting (0);
|
@error_reporting (0);
|
||||||
|
|
||||||
$do_update = false;
|
$doUpdate = false;
|
||||||
if (isset ($_REQUEST [A_UPDATE]) && !empty ($_REQUEST [A_UPDATE])) {
|
if (isset ($_REQUEST [A_UPDATE]) && !empty ($_REQUEST [A_UPDATE])) {
|
||||||
$do_update = true;
|
$doUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$do_download = false;
|
$doDownload = false;
|
||||||
if (isset ($_REQUEST [A_GET]) && !empty ($_REQUEST [A_GET])) {
|
if (isset ($_REQUEST [A_GET]) && !empty ($_REQUEST [A_GET])) {
|
||||||
$do_download = true;
|
$doDownload = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$doUpload = false;
|
||||||
|
if (isset ($_FILES ['file'])) {
|
||||||
|
$doUpload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
function return_error ($msg) {
|
function returnError ($msg) {
|
||||||
require (JIRAFEAU_ROOT.'lib/template/header.php');
|
require (JIRAFEAU_ROOT.'lib/template/header.php');
|
||||||
echo '<div class="error"><p>' . $msg . '</p></div>';
|
echo '<div class="error"><p>' . $msg . '</p></div>';
|
||||||
require (JIRAFEAU_ROOT.'lib/template/footer.php');
|
require (JIRAFEAU_ROOT.'lib/template/footer.php');
|
||||||
@ -125,52 +138,80 @@ function return_error ($msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
function setTrack ($sender) {
|
function setSenderTrack ($sender) {
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
if (!file_exists (VAR_TRACKS))
|
if (!file_exists (VAR_TRACKS))
|
||||||
mkdir (VAR_TRACKS, 0755);
|
mkdir (VAR_TRACKS, 0755);
|
||||||
touch (VAR_TRACKS.$sender);
|
touch (VAR_TRACKS.$sender);
|
||||||
}
|
}
|
||||||
function rmTrack ($sender) {
|
function rmSenderTrack ($sender) {
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
if (file_exists (VAR_TRACKS.$sender))
|
if (file_exists (VAR_TRACKS.$sender))
|
||||||
unlink (VAR_TRACKS.$sender);
|
unlink (VAR_TRACKS.$sender);
|
||||||
}
|
}
|
||||||
function getTrack ($sender) {
|
function getSenderTrack ($sender) {
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
return file_exists (VAR_TRACKS.$sender);
|
return file_exists (VAR_TRACKS.$sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
function setPeriod ($sender, $period) {
|
function setSenderPeriod ($sender, $period) {
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
if (!file_exists (VAR_PERIOD))
|
if (!file_exists (VAR_PERIOD))
|
||||||
mkdir (VAR_PERIOD, 0755);
|
mkdir (VAR_PERIOD, 0755);
|
||||||
if (empty ($period) || DEFAULT_PERIOD == $period) {
|
if (empty ($period) || DEFAULT_PERIOD == $period) {
|
||||||
if (file_exists (VAR_PERIOD.$sender))
|
rmSenderPeriod ($sender);
|
||||||
unlink (VAR_PERIOD.$sender);
|
|
||||||
} else
|
} else
|
||||||
file_put_contents (VAR_PERIOD.$sender, $period.NL);
|
file_put_contents (VAR_PERIOD.$sender, $period.NL);
|
||||||
}
|
}
|
||||||
function rmPeriod ($sender) {
|
function rmSenderPeriod ($sender) {
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
if (file_exists (VAR_PERIOD.$sender))
|
if (file_exists (VAR_PERIOD.$sender))
|
||||||
unlink (VAR_PERIOD.$sender);
|
unlink (VAR_PERIOD.$sender);
|
||||||
}
|
}
|
||||||
function getPeriod ($sender) {
|
function getSenderPeriod ($sender) {
|
||||||
if (!$sender || !file_exists (VAR_PERIOD.$sender))
|
if (!$sender || !file_exists (VAR_PERIOD.$sender))
|
||||||
return DEFAULT_PERIOD;
|
return DEFAULT_PERIOD;
|
||||||
return trim (file (VAR_PERIOD.$sender)[0]);
|
return trim (file (VAR_PERIOD.$sender)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
function setFake ($sender, $dir_link, $dirTime) {
|
function setSenderFake ($sender, $dirLink, $dirTime) {
|
||||||
return;
|
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
if (!file_exists (VAR_FAKE))
|
if (!file_exists (VAR_FAKE))
|
||||||
@ -178,8 +219,7 @@ function setFake ($sender, $dir_link, $dirTime) {
|
|||||||
file_put_contents (VAR_FAKE.$sender, "time: ".$dirTime.NL."sender: ".$sender.NL);
|
file_put_contents (VAR_FAKE.$sender, "time: ".$dirTime.NL."sender: ".$sender.NL);
|
||||||
rmToken ($sender);
|
rmToken ($sender);
|
||||||
}
|
}
|
||||||
|
function getSenderFake ($sender) {
|
||||||
function getFake ($sender) {
|
|
||||||
if (!$sender)
|
if (!$sender)
|
||||||
return;
|
return;
|
||||||
return file_exists (VAR_FAKE.$sender);
|
return file_exists (VAR_FAKE.$sender);
|
||||||
@ -191,33 +231,70 @@ function isKazArchive ($link) {
|
|||||||
@preg_match ("/".T_ARCHIVE_TITLE."/", jirafeau_escape ($link ['file_name'])) &&
|
@preg_match ("/".T_ARCHIVE_TITLE."/", jirafeau_escape ($link ['file_name'])) &&
|
||||||
jirafeau_escape ($link ['mime_type']) == T_ARCHIVE_MIME;
|
jirafeau_escape ($link ['mime_type']) == T_ARCHIVE_MIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
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];
|
||||||
|
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;
|
||||||
|
case preg_match ("/^\s*time:\s*(\d{4}([:-]\d{2}){5})\s*$/i", $line, $matches):
|
||||||
|
$archive [T_TIME] = $matches [1];
|
||||||
|
break;
|
||||||
|
case preg_match ("/^\s*new:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
|
||||||
|
$archive [T_NEW][] = [$matches [1], $matches [2]];
|
||||||
|
break;
|
||||||
|
case preg_match ("/^\s*old:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
function getFileName ($hash) {
|
function getFileName ($hash) {
|
||||||
$p = s2p ($hash);
|
$p = s2p ($hash);
|
||||||
return VAR_FILES.$p.$hash;
|
return VAR_FILES.$p.$hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimeFile ($hash) {
|
function getTimeFile ($hash) {
|
||||||
$f = getFileName ($hash);
|
$f = getFileName ($hash);
|
||||||
return file_exists ($f) ? filemtime ($f) : 0;
|
return file_exists ($f) ? filemtime ($f) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function valideTime ($t1, $t2) {
|
function valideTime ($t1, $t2) {
|
||||||
return true;
|
global $message;
|
||||||
return abs ($t1 - $t2) < 60; // XXX delay
|
return abs ($t1 - $t2) < MAX_VALID_UPLOAD_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
/** Update link
|
/** Update link
|
||||||
* @param $link the link's name (hash)
|
* @param $link the link's name (hash)
|
||||||
* @param $update_period the periode (i.e in : "month")
|
* @param $update_period the period (i.e in : "month")
|
||||||
*/
|
*/
|
||||||
function update_link ($link_name, $link, $update_period) {
|
function updateLink ($link_name, $link, $maxLimit) {
|
||||||
$time_max = $link ['time'];
|
$time_max = $link ['time'];
|
||||||
$time_up = time () + $update_period;
|
if ($time_max < 0 || $maxLimit < $time_max)
|
||||||
$time_more = $time_up + JIRAFEAU_HOUR;
|
|
||||||
if ($time_max < 0 || $time_up < $time_max)
|
|
||||||
return $time_max;
|
return $time_max;
|
||||||
|
$time_more = $maxLimit + JIRAFEAU_MINUTE;
|
||||||
$link ['time'] = $time_more;
|
$link ['time'] = $time_more;
|
||||||
$link_tmp_name = VAR_LINKS . $link ['hash'] . rand (0, 10000) . '.tmp';
|
$link_tmp_name = VAR_LINKS . $link ['hash'] . rand (0, 10000) . '.tmp';
|
||||||
$handle = fopen ($link_tmp_name, 'w');
|
$handle = fopen ($link_tmp_name, 'w');
|
||||||
@ -232,35 +309,7 @@ function update_link ($link_name, $link, $update_period) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
// read archive info
|
function sendEMail ($receiver, $receiver_name, $subject, $body_string){
|
||||||
function read_archive_info ($link) {
|
|
||||||
$p = s2p ($link ['hash']);
|
|
||||||
$result = [];
|
|
||||||
$error=false;
|
|
||||||
foreach (file (VAR_FILES . $p . $link ['hash']) as $line) {
|
|
||||||
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):
|
|
||||||
$result [T_SENDER] = $matches [1];
|
|
||||||
break;
|
|
||||||
case preg_match ("/^\s*time:\s*(\d{4}([:-]\d{2}){5})\s*$/i", $line, $matches):
|
|
||||||
$result [T_TIMESTAMP] = $matches [1];
|
|
||||||
break;
|
|
||||||
case preg_match ("/^\s*old:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
|
|
||||||
$result [T_OLD][] = [$matches [1], $matches [2]];
|
|
||||||
break;
|
|
||||||
case preg_match ("/^\s*new:\s*([0-9a-zA-Z_-]+)\s+([0-9a-zA-Z_-]+)\s*$/", $line, $matches):
|
|
||||||
$result [T_NEW][] = [$matches [1], $matches [2]];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$error = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $error ? [] : $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========================================
|
|
||||||
function send_email ($receiver, $receiver_name, $subject, $body_string){
|
|
||||||
try {
|
try {
|
||||||
// SERVER SETTINGS
|
// SERVER SETTINGS
|
||||||
$mail = new PHPMailer (true);
|
$mail = new PHPMailer (true);
|
||||||
@ -359,49 +408,50 @@ function getTimeToken ($sender) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
if ($do_update) {
|
if ($doUpload) {
|
||||||
$update_period = JIRAFEAU_MONTH;
|
$maxtime = time ()+period2seconds ($_REQUEST ['time']);
|
||||||
switch ($_REQUEST [A_UPDATE]) {
|
$key = isset ($_REQUEST ['key']) ? $_REQUEST ['key'] : '';
|
||||||
case 'minute':
|
$ip = $_SERVER ['HTTP_X_REAL_IP']; // XXX
|
||||||
$update_period = JIRAFEAU_MINUTE;
|
$res = jirafeau_upload (
|
||||||
break;
|
$_FILES['file'],
|
||||||
case 'hour':
|
isset ($_POST ['one_time_download']),
|
||||||
$update_period = JIRAFEAU_HOUR;
|
$key,
|
||||||
break;
|
$maxtime,
|
||||||
case 'day':
|
$ip,
|
||||||
$update_period = JIRAFEAU_DAY;
|
$cfg['enable_crypt'],
|
||||||
break;
|
$cfg['link_name_length'],
|
||||||
case 'week':
|
$cfg['file_hash']
|
||||||
$update_period = JIRAFEAU_WEEK;
|
);
|
||||||
break;
|
if (! count ($res ['error']) || $res['error']['has_error'])
|
||||||
case 'month':
|
$content = 'Error 6 ' . $res['error']['why'];
|
||||||
$update_period = JIRAFEAU_MONTH;
|
else
|
||||||
break;
|
$content = $res ['link'].NL.$res ['delete_link'].NL;
|
||||||
case 'quarter':
|
header ('HTTP/1.0 200 OK');
|
||||||
$update_period = JIRAFEAU_QUARTER;
|
header ('Content-Length: ' . strlen ($content));
|
||||||
break;
|
header ('Content-Type: text/plain');
|
||||||
case 'year':
|
echo $content;
|
||||||
$update_period = JIRAFEAU_YEAR;
|
exit;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return_error (t ('ERR_OCC') . ' (update_period)');
|
|
||||||
}
|
}
|
||||||
$link_name = $_REQUEST [A_HASH];
|
|
||||||
if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
|
// ========================================
|
||||||
return_error (t ('FILE_404'));
|
if ($doUpdate) {
|
||||||
$link = jirafeau_get_link ($link_name);
|
$maxTime = time ()+period2seconds ($_REQUEST [A_UPDATE]);
|
||||||
|
$linkName = $_REQUEST [A_HASH];
|
||||||
|
if (!preg_match ('/[0-9a-zA-Z_-]+$/', $linkName))
|
||||||
|
returnError (t ('FILE_404'));
|
||||||
|
$link = jirafeau_get_link ($linkName);
|
||||||
if (count ($link) == 0)
|
if (count ($link) == 0)
|
||||||
return_error (t ('FILE_404'));
|
returnError (t ('FILE_404'));
|
||||||
$time = update_link ($link_name, $link, $update_period);
|
$time = updateLink ($linkName, $link, $maxTime);
|
||||||
$content = '' . $time . NL;
|
$content = '' . $time . NL;
|
||||||
|
|
||||||
if (isKazArchive ($link)) {
|
if (isKazArchive ($link)) {
|
||||||
$archive_info = read_archive_info ($l);
|
$archiveInfo = readArchiveFromLink ($l);
|
||||||
if (count ($archive_info)) {
|
if (count ($archiveInfo)) {
|
||||||
foreach ([T_OLD, T_NEW] as $cat)
|
foreach ([T_OLD, T_NEW] as $cat)
|
||||||
if (isset ($archive_info [$cat]))
|
if (isset ($archiveInfo [$cat]))
|
||||||
foreach ($archive_info [$cat] as [$link_name, $crypt_key])
|
foreach ($archiveInfo [$cat] as [$linkName, $cryptKey])
|
||||||
update_link ($link_name, jirafeau_get_link ($link_name), $update_period);
|
updateLink ($linkName, jirafeau_get_link ($linkName), $maxTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
header ('HTTP/1.0 200 OK');
|
header ('HTTP/1.0 200 OK');
|
||||||
@ -423,98 +473,98 @@ if (isset ($_REQUEST [A_SENDER]) && !empty ($_REQUEST [A_SENDER])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
if ($do_download) {
|
if ($doDownload) {
|
||||||
// check archive exist
|
// check archive exist
|
||||||
$couple = explode ("~", $_REQUEST [A_GET], 2);
|
$couple = explode ("~", $_REQUEST [A_GET], 2);
|
||||||
if (count ($couple) == 0)
|
if (count ($couple) == 0)
|
||||||
return_error (E_BAD_ARCHIVE_NAME);
|
returnError (E_BAD_ARCHIVE_NAME);
|
||||||
$link_name = $couple [0];
|
$linkName = $couple [0];
|
||||||
if (!$link_name || !preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
|
if (!$linkName || !preg_match ('/[0-9a-zA-Z_-]+$/', $linkName))
|
||||||
return_error (E_BAD_ARCHIVE_NAME);
|
returnError (E_BAD_ARCHIVE_NAME);
|
||||||
$crypt_key = count ($couple) == 2 ? $couple [1] : "";
|
$cryptKey = count ($couple) == 2 ? $couple [1] : "";
|
||||||
$link = jirafeau_get_link ($link_name);
|
$link = jirafeau_get_link ($linkName);
|
||||||
if (count ($link) == 0)
|
if (count ($link) == 0)
|
||||||
return_error (t ('FILE_404'));
|
returnError (t ('FILE_404'));
|
||||||
$key = $link ['key'];
|
$key = $link ['key'];
|
||||||
if ($key && (empty ($crypt_key) || $key != $crypt_key))
|
if ($key && (empty ($cryptKey) || $key != $cryptKey))
|
||||||
return_error (t ('BAD_PSW'));
|
returnError (t ('BAD_PSW'));
|
||||||
|
|
||||||
$archive_info = read_archive_info ($link);
|
$archiveInfo = readArchiveFromLink ($link);
|
||||||
|
|
||||||
// check entries
|
// check entries
|
||||||
$archive_content = [];
|
$archiveContent = [];
|
||||||
$modif = false;
|
$modif = false;
|
||||||
$single_name = [];
|
$singleName = [];
|
||||||
foreach ([T_OLD, T_NEW] as $cat)
|
foreach ([T_OLD, T_NEW] as $cat)
|
||||||
if (isset ($archive_info [$cat]))
|
if (isset ($archiveInfo [$cat]))
|
||||||
foreach ($archive_info [$cat] as [$link_name, $crypt_key]) {
|
foreach ($archiveInfo [$cat] as [$linkName, $cryptKey]) {
|
||||||
$link = jirafeau_get_link ($link_name);
|
$link = jirafeau_get_link ($linkName);
|
||||||
if (count ($link) == 0) {
|
if (count ($link) == 0) {
|
||||||
if (isset ($archive_content [T_NOT_FOUND]))
|
if (isset ($archiveContent [T_NOT_FOUND]))
|
||||||
++$archive_content [T_NOT_FOUND];
|
++$archiveContent [T_NOT_FOUND];
|
||||||
else
|
else
|
||||||
$archive_content [T_NOT_FOUND] = 1;
|
$archiveContent [T_NOT_FOUND] = 1;
|
||||||
$modif = true;
|
$modif = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$key = $link ['key'];
|
$key = $link ['key'];
|
||||||
if ($key && (empty ($crypt_key) || $key != $crypt_key)) {
|
if ($key && (empty ($cryptKey) || $key != $cryptKey)) {
|
||||||
if (isset ($archive_content [T_BAD_PASW]))
|
if (isset ($archiveContent [T_BAD_PASW]))
|
||||||
++$archive_content [T_BAD_PASW];
|
++$archiveContent [T_BAD_PASW];
|
||||||
else
|
else
|
||||||
$archive_content [T_BAD_PASW] = 1;
|
$archiveContent [T_BAD_PASW] = 1;
|
||||||
$modif = true;
|
$modif = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$src_name = $dst_name = ($link ['file_name'] ? $link ['file_name'] : M_NO_FILENAME);
|
$srcName = $dstName = ($link ['file_name'] ? $link ['file_name'] : M_NO_FILENAME);
|
||||||
if (in_array ($src_name, $single_name))
|
if (in_array ($srcName, $singleName))
|
||||||
for ($i = 0; $i < 10000; ++$i) {
|
for ($i = 0; $i < 10000; ++$i) {
|
||||||
$dst_name = sprintf ("%s-%2d", $src_name, $i);
|
$dstName = sprintf ("%s-%2d", $srcName, $i);
|
||||||
if (!in_array ($dst_name, $single_name)) {
|
if (!in_array ($dstName, $singleName)) {
|
||||||
if (isset ($archive_content [T_RENAME]))
|
if (isset ($archiveContent [T_RENAME]))
|
||||||
++$archive_content [T_RENAME];
|
++$archiveContent [T_RENAME];
|
||||||
else
|
else
|
||||||
$archive_content [T_RENAME] = 1;
|
$archiveContent [T_RENAME] = 1;
|
||||||
$modif = true;
|
$modif = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$single_name [] = $dst_name;
|
$singleName [] = $dstName;
|
||||||
$archive_content [$cat][T_ENTRIES][] = [T_HASH => $link ['hash'], T_FILENAME => $dst_name, T_CRYPT_KEY => $crypt_key, T_CRYPTED => $link ['crypted']];
|
$archiveContent [$cat][T_ENTRIES][] = [T_HASH => $link ['hash'], T_FILENAME => $dstName, T_CRYPT_KEY => $cryptKey, T_CRYPTED => $link ['crypted']];
|
||||||
}
|
}
|
||||||
|
|
||||||
// build zip
|
// build zip
|
||||||
$dirname = M_NO_SENDER.(isset ($archive_info [T_TIMESTAMP]) && !empty ($archive_info [T_TIMESTAMP])) ?
|
$dirname = M_NO_SENDER.(isset ($archiveInfo [T_TIME]) && !empty ($archiveInfo [T_TIME])) ?
|
||||||
$archive_info [T_TIMESTAMP] : date ("Y-m-d-H:i:s");
|
$archiveInfo [T_TIME] : date ("Y-m-d-H:i:s");
|
||||||
$dirname = str_replace (":", "_", $dirname);
|
$dirname = str_replace (":", "_", $dirname);
|
||||||
$tmpFileName = tempnam (sys_get_temp_dir (), $dirname."-");
|
$tmpFileName = tempnam (sys_get_temp_dir (), $dirname."-");
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
if (!$zip)
|
if (!$zip)
|
||||||
return_error (E_CREATE_ZIP);
|
returnError (E_CREATE_ZIP);
|
||||||
if ($zip->open ($tmpFileName.T_ZIP_EXT, ZipArchive::CREATE) !== TRUE)
|
if ($zip->open ($tmpFileName.T_ZIP_EXT, ZipArchive::CREATE) !== TRUE)
|
||||||
return_error (E_OPEN_ZIP);
|
returnError (E_OPEN_ZIP);
|
||||||
|
|
||||||
// create info
|
// create info
|
||||||
if ($modif) {
|
if ($modif) {
|
||||||
$info = '';
|
$info = '';
|
||||||
if (isset ($archive_info [T_NOT_FOUND]))
|
if (isset ($archiveInfo [T_NOT_FOUND]))
|
||||||
$info .= $archive_info [T_NOT_FOUND]. ($archive_info [T_NOT_FOUND] ? M_FILE_NOT_FOUND : M_FILES_NOT_FOUND).NL;
|
$info .= $archiveInfo [T_NOT_FOUND]. ($archiveInfo [T_NOT_FOUND] ? M_FILE_NOT_FOUND : M_FILES_NOT_FOUND).NL;
|
||||||
if (isset ($archive_info [T_BAD_PASW]))
|
if (isset ($archiveInfo [T_BAD_PASW]))
|
||||||
$info .= M_BAD_KEY. $archive_info [T_BAD_PASW]. ($archive_info [T_BAD_PASW] ? M_FILE : M_FILES).NL;
|
$info .= M_BAD_KEY. $archiveInfo [T_BAD_PASW]. ($archiveInfo [T_BAD_PASW] ? M_FILE : M_FILES).NL;
|
||||||
if (isset ($archive_info[T_RENAME]))
|
if (isset ($archiveInfo[T_RENAME]))
|
||||||
$info .= $archive_info[T_RENAME]. ($archive_info[T_RENAME] ? M_FILE_RENAMED : M_FILES_RENAMED).NL;
|
$info .= $archiveInfo[T_RENAME]. ($archiveInfo[T_RENAME] ? M_FILE_RENAMED : M_FILES_RENAMED).NL;
|
||||||
$zip->addFromString ($dirname.T_WARNING_FILENAME, $info);
|
$zip->addFromString ($dirname.T_WARNING_FILENAME, $info);
|
||||||
}
|
}
|
||||||
foreach ([T_OLD, T_NEW] as $cat)
|
foreach ([T_OLD, T_NEW] as $cat)
|
||||||
if (isset ($archive_info [$cat])) {
|
if (isset ($archiveInfo [$cat])) {
|
||||||
$subdir = $dirname . ($cat == T_NEW ? "" : "/".M_OLD_ATTACHEMENT_DIRNAME);
|
$subdir = $dirname . "-".($cat == T_NEW ? M_NEW_ATTACHEMENT_DIRNAME : M_OLD_ATTACHEMENT_DIRNAME);
|
||||||
foreach ($archive_content [$cat][T_ENTRIES] as $entry) {
|
foreach ($archiveContent [$cat][T_ENTRIES] as $entry) {
|
||||||
$p = s2p ($entry [T_HASH]);
|
$p = s2p ($entry [T_HASH]);
|
||||||
if ($entry [T_CRYPTED]) {
|
if ($entry [T_CRYPTED]) {
|
||||||
$m = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
|
$m = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
|
||||||
$md5_key = md5 ($entry [T_CRYPT_KEY]);
|
$md5_key = md5 ($entry [T_CRYPT_KEY]);
|
||||||
$iv = jirafeau_crypt_create_iv ($md5_key, mcrypt_enc_get_iv_size ($m));
|
$iv = jirafeau_crypt_create_iv ($md5Key, mcrypt_enc_get_iv_size ($m));
|
||||||
mcrypt_generic_init ($m, $md5_key, $iv);
|
mcrypt_generic_init ($m, $md5Key, $iv);
|
||||||
$r = fopen (VAR_FILES . $p . $entry [T_HASH], 'r');
|
$r = fopen (VAR_FILES . $p . $entry [T_HASH], 'r');
|
||||||
$content = "";
|
$content = "";
|
||||||
while (!feof ($r)) {
|
while (!feof ($r)) {
|
||||||
@ -534,21 +584,21 @@ if ($do_download) {
|
|||||||
$zip->close ();
|
$zip->close ();
|
||||||
|
|
||||||
|
|
||||||
if (!is_file ($tmpFileName.T_ZIP_EXT,))
|
|
||||||
return_error (E_OPEN_ZIP);
|
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
// log
|
// log
|
||||||
$content = print_r ($archive_info, 1);
|
$message .= print_r ($archiveInfo, 1);
|
||||||
$content .= print_r ($archive_content, 1);
|
$message .= print_r ($archiveContent, 1);
|
||||||
|
|
||||||
header ('HTTP/1.0 200 OK');
|
header ('HTTP/1.0 200 OK');
|
||||||
header ('Content-Length: ' . strlen ($content));
|
header ('Content-Length: ' . strlen ($message));
|
||||||
header ('Content-Type: text/plain');
|
header ('Content-Type: text/plain');
|
||||||
echo $content;
|
echo $message;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_file ($tmpFileName.T_ZIP_EXT,))
|
||||||
|
returnError (E_OPEN_ZIP);
|
||||||
|
|
||||||
header ("Content-Type: application/zip");
|
header ("Content-Type: application/zip");
|
||||||
header ('Content-Disposition: filename="'.$dirname.'.zip"');
|
header ('Content-Disposition: filename="'.$dirname.'.zip"');
|
||||||
$r = fopen ($tmpFileName.".zip", 'r');
|
$r = fopen ($tmpFileName.".zip", 'r');
|
||||||
@ -566,8 +616,8 @@ if ($do_download) {
|
|||||||
// ========================================
|
// ========================================
|
||||||
if (isset ($_REQUEST [A_RECORD]) && !empty ($_REQUEST [A_RECORD])) {
|
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]))
|
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);
|
returnError (M_BAD_SENDER_NAME);
|
||||||
$content = getTrack ($_REQUEST [A_RECORD]).NL;
|
$content = getSenderTrack ($_REQUEST [A_RECORD]).NL;
|
||||||
header ('HTTP/1.0 200 OK');
|
header ('HTTP/1.0 200 OK');
|
||||||
header ('Content-Length: ' . strlen ($content));
|
header ('Content-Length: ' . strlen ($content));
|
||||||
header ('Content-Type: text/plain');
|
header ('Content-Type: text/plain');
|
||||||
@ -578,8 +628,8 @@ if (isset ($_REQUEST [A_RECORD]) && !empty ($_REQUEST [A_RECORD])) {
|
|||||||
// ========================================
|
// ========================================
|
||||||
if (isset ($_REQUEST [A_PERIOD]) && !empty ($_REQUEST [A_PERIOD])) {
|
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]))
|
if (!preg_match ("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i", $_REQUEST [A_PERIOD]))
|
||||||
return_error (M_BAD_SENDER_NAME);
|
returnError (M_BAD_SENDER_NAME);
|
||||||
$content = getPeriod ($_REQUEST [A_PERIOD]).NL;
|
$content = getSenderPeriod ($_REQUEST [A_PERIOD]).NL;
|
||||||
header ('HTTP/1.0 200 OK');
|
header ('HTTP/1.0 200 OK');
|
||||||
header ('Content-Length: ' . strlen ($content));
|
header ('Content-Length: ' . strlen ($content));
|
||||||
header ('Content-Type: text/plain');
|
header ('Content-Type: text/plain');
|
||||||
@ -597,16 +647,16 @@ if (isset ($_REQUEST [A_TOKEN]) && !empty ($_REQUEST [A_TOKEN])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$refToken = getToken ($sender);
|
$refToken = getToken ($sender);
|
||||||
$url_base = $_SERVER ['HTTP_X_FORWARDED_PROTO']."://".$_SERVER ['HTTP_HOST'];
|
$urlBase = $_SERVER ['HTTP_X_FORWARDED_PROTO']."://".$_SERVER ['HTTP_HOST'];
|
||||||
if (isset ($_REQUEST [A_ACTION]) && $_REQUEST [A_ACTION] == T_SEND && $sender) {
|
if (isset ($_REQUEST [A_ACTION]) && $_REQUEST [A_ACTION] == T_SEND && $sender) {
|
||||||
require (JIRAFEAU_ROOT . 'lib/template/header.php');
|
require (JIRAFEAU_ROOT . 'lib/template/header.php');
|
||||||
if (getFake ($sender))
|
if (getSenderFake ($sender))
|
||||||
echo "Ce compte ne peut plus se connecter. Veuillez contacter les administrateurs.";
|
echo "Ce compte ne peut plus se connecter. Veuillez contacter les administrateurs.";
|
||||||
else {
|
else {
|
||||||
$token = setToken ($sender);
|
$token = setToken ($sender);
|
||||||
// XXX test token
|
// XXX test token
|
||||||
$url = $url_base.$_SERVER ['SCRIPT_NAME']."?".A_SENDER."=".$sender."&".A_TOKEN."=".$token;
|
$url = $urlBase.$_SERVER ['SCRIPT_NAME']."?".A_SENDER."=".$sender."&".A_TOKEN."=".$token;
|
||||||
$result = send_email ($sender, "", M_EMAIL_SUBJECT,
|
$result = sendEMail ($sender, "", M_EMAIL_SUBJECT,
|
||||||
str_replace (["___LINK___", "___IP___", "___DATE___"],
|
str_replace (["___LINK___", "___IP___", "___DATE___"],
|
||||||
[$url, $_SERVER ['HTTP_X_REAL_IP'] , date ("Y-m-d H:i:s")], M_EMAIL_CONTENT));
|
[$url, $_SERVER ['HTTP_X_REAL_IP'] , date ("Y-m-d H:i:s")], M_EMAIL_CONTENT));
|
||||||
if ($result)
|
if ($result)
|
||||||
@ -665,115 +715,126 @@ if (!getLoggedToken ($sender))
|
|||||||
else
|
else
|
||||||
touch (VAR_TOKENS.$sender);
|
touch (VAR_TOKENS.$sender);
|
||||||
|
|
||||||
function deleteAction ($link_name) {
|
function deleteAction ($linkName) {
|
||||||
global $sender, $token, $message, $doLogout;
|
global $sender, $token, $message, $doLogout;
|
||||||
|
|
||||||
$link = jirafeau_get_link ($link_name);
|
$link = jirafeau_get_link ($linkName);
|
||||||
//$message .= "ln: ".$link_name." l: "."<pre>".print_r ($link, 1)."</pre> mt: ".getTimeFile ($link ['hash'])."</br>";
|
//$message .= "ln: ".$linkName." l: "."<pre>".print_r ($link, 1)."</pre> mt: ".getTimeFile ($link ['hash'])."</br>";
|
||||||
if (!count ($link))
|
if (!count ($link))
|
||||||
return;
|
return;
|
||||||
if (isKazArchive ($link)) {
|
if (isKazArchive ($link)) {
|
||||||
$dir_name = $link_name;
|
$dirName = $linkName;
|
||||||
$dir_link = $link;
|
$dirLink = $link;
|
||||||
$dirTime = getTimeFile ($dir_link ['hash']);
|
$dirTime = $dirLink ['upload_date'];
|
||||||
$archive_info = read_archive_info ($dir_link);
|
$archiveInfo = readArchiveFromLink ($dirLink);
|
||||||
if (! count ($archive_info))
|
if (! count ($archiveInfo))
|
||||||
return;
|
return;
|
||||||
if ($sender != $archive_info [T_SENDER]) {
|
if ($sender != $archiveInfo [T_SENDER]) {
|
||||||
setFake ($sender, $dir_link, $dirTime);
|
setSenderFake ($sender, $dirLink, $dirTime);
|
||||||
$message .= "Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire. (F1 ".$sender." != ".$archive_info [T_SENDER].")";
|
$message .= "Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire. (".$sender." != ".$archiveInfo [T_SENDER].")";
|
||||||
//XXX $doLogout = true;
|
$doLogout = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($archive_info [T_NEW])
|
$fileToDelete = false;
|
||||||
foreach ($archive_info [T_NEW] as [$file_name, $crypt_key]) {
|
if ($archiveInfo [T_NEW])
|
||||||
$file_link = jirafeau_get_link ($file_name);
|
foreach ($archiveInfo [T_NEW] as [$fileName, $cryptKey]) {
|
||||||
if (! count ($file_link))
|
$fileLink = jirafeau_get_link ($fileName);
|
||||||
|
if (! count ($fileLink))
|
||||||
continue;
|
continue;
|
||||||
$fileTime = getTimeFile ($file_link ['hash']);
|
$fileTime = $fileLink ['upload_date'];
|
||||||
if (! valideTime ($dirTime, $fileTime)) {
|
if (! valideTime ($dirTime, $fileTime)) {
|
||||||
setFake ($sender, $dir_link, $dirTime);
|
setSenderFake ($sender, $dirLink, $dirTime);
|
||||||
$message .= "Cet envoi a été forgée (dates incohéantes). (F2 ".
|
$message .= "Cet envoi a été forgée".
|
||||||
getFileName ($dir_link ['hash'])." =? ".getFileName ($file_link ['hash'])." ".
|
str_replace (["___FILENAME___", "___DIRTIME___", "___FILETIME___"],
|
||||||
date ("Y-m-d H:i:s", $dirTime)." != ".date ("Y-m-d H:i:s", $fileTime).")";
|
[$fileLink ['file_name'], $dirTime , $fileTime], M_INCONSISTENT_DATES);
|
||||||
// XXX $doLogout = true;
|
$doLogout = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$fileToDelete = true;
|
||||||
}
|
}
|
||||||
if ($archive_info [T_NEW])
|
$message .= "l'envoi ".$archiveInfo [T_TIME]." est supprimé";
|
||||||
foreach ($archive_info [T_NEW] as [$file_name, $crypt_key]) {
|
if ($fileToDelete)
|
||||||
$file_link = jirafeau_get_link ($file_name);
|
$message .= " avec<ul>";
|
||||||
if (! count ($file_link))
|
if ($archiveInfo [T_NEW])
|
||||||
|
foreach ($archiveInfo [T_NEW] as [$fileName, $cryptKey]) {
|
||||||
|
$fileLink = jirafeau_get_link ($fileName);
|
||||||
|
if (! count ($fileLink))
|
||||||
continue;
|
continue;
|
||||||
jirafeau_delete_link ($file_name);
|
$message .= "<li>".jirafeau_escape ($fileLink ['file_name'])."</li>";
|
||||||
|
jirafeau_delete_link ($fileName);
|
||||||
}
|
}
|
||||||
jirafeau_delete_link ($dir_name);
|
jirafeau_delete_link ($dirName);
|
||||||
|
$message .= $fileToDelete ? "</ul>" : ".";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$file_name = $link_name;
|
$fileName = $linkName;
|
||||||
$file_link = $link;
|
$fileLink = $link;
|
||||||
$fileTime = getTimeFile ($file_name);
|
$fileTime = $fileLink ['upload_date'];
|
||||||
$stack = array (VAR_LINKS);
|
$stack = array (VAR_LINKS);
|
||||||
while (($d = array_shift ($stack)) && $d != null) {
|
while (($d = array_shift ($stack)) && $d != null) {
|
||||||
if (!file_exists ($d))
|
if (!file_exists ($d))
|
||||||
continue;
|
continue;
|
||||||
$dir = scandir ($d);
|
$dir = scandir ($d);
|
||||||
foreach ($dir as $dir_name) {
|
foreach ($dir as $dirName) {
|
||||||
if (strcmp ($dir_name, '.') == 0 || strcmp ($dir_name, '..') == 0 ||
|
if (strcmp ($dirName, '.') == 0 || strcmp ($dirName, '..') == 0 ||
|
||||||
preg_match ('/\.tmp/i', "$dir_name")) {
|
preg_match ('/\.tmp/i', "$dirName")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_dir ($d . $dir_name)) {
|
if (is_dir ($d . $dirName)) {
|
||||||
/* Push new found directory. */
|
$stack [] = $d . $dirName . '/';
|
||||||
$stack [] = $d . $dir_name . '/';
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Read link informations. */
|
$dirLink = jirafeau_get_link ($dirName);
|
||||||
$dir_link = jirafeau_get_link ($dir_name);
|
//$dirTime = getTimeFile ($dirLink ['hash']);
|
||||||
$dirTime = getTimeFile ($dir_link ['hash']);
|
$dirTime = $dirLink ['upload_date'];
|
||||||
if (!count ($dir_link))
|
if (!count ($dirLink))
|
||||||
continue;
|
continue;
|
||||||
if (!isKazArchive ($dir_link))
|
if (!isKazArchive ($dirLink))
|
||||||
continue;
|
continue;
|
||||||
$archive_info = read_archive_info ($dir_link);
|
$archiveInfo = readArchiveFromLink ($dirLink);
|
||||||
if (! count ($archive_info))
|
if (! count ($archiveInfo))
|
||||||
return;
|
return;
|
||||||
if ($archive_info [T_NEW])
|
if ($archiveInfo [T_NEW])
|
||||||
foreach ($archive_info [T_NEW] as [$new_name, $crypt_key]) {
|
foreach ($archiveInfo [T_NEW] as [$newName, $cryptKey]) {
|
||||||
if ($file_name != $new_name)
|
if ($fileName != $newName)
|
||||||
continue;
|
continue;
|
||||||
if ($sender == $archive_info [T_SENDER]) {
|
if ($sender == $archiveInfo [T_SENDER]) {
|
||||||
if (valideTime ($dirTime, $fileTime)) {
|
if (valideTime ($dirTime, $fileTime)) {
|
||||||
jirafeau_delete_link ($file_name);
|
jirafeau_delete_link ($fileName);
|
||||||
$message .= jirafeau_escape ($file_link ['file_name'])." est supprim&eacte;.";
|
$message .= jirafeau_escape ($fileLink ['file_name'])." est supprimé";
|
||||||
// check empty dir
|
// check empty dir
|
||||||
$empty = true;
|
$empty = true;
|
||||||
foreach ([T_OLD, T_NEW] as $cat)
|
foreach ([T_OLD, T_NEW] as $cat)
|
||||||
if ($empty && isset ($archive_info [$cat]))
|
if ($empty && isset ($archiveInfo [$cat]))
|
||||||
foreach ($archive_info [$cat] as [$l, $c])
|
foreach ($archiveInfo [$cat] as [$l, $c])
|
||||||
if (count (jirafeau_get_link ($l))) {
|
if (count (jirafeau_get_link ($l))) {
|
||||||
$empty = false;
|
$empty = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($empty) {
|
if ($empty) {
|
||||||
$message .= jirafeau_escape ($file_link ['dir_name'])." vide est &eacte;galement supprim&eacte;.";
|
$message .= " ainsi que l'envoie ".$archiveInfo [T_TIME]." qui est vide.";
|
||||||
jirafeau_delete_link ($dir_name);
|
jirafeau_delete_link ($dirName);
|
||||||
}
|
} else
|
||||||
|
$message .= ".";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setFake ($sender, $dir_link, $dirTime);
|
setSenderFake ($sender, $dirLink, $dirTime);
|
||||||
$message .= "Cet envoi a été forgée. (F3 ".date ("Y-m-d H:i:s", $dirTime)." != ".date ("Y-m-d H:i:s", $fileTime).")";
|
$message .= "Cet envoi a été forgée. ".
|
||||||
// XXX $dologout = true;
|
str_replace (["___FILENAME___", "___DIRTIME___", "___FILETIME___"],
|
||||||
|
[$fileLink ['file_name'], $dirTime , $fileTime], M_INCONSISTENT_DATES);
|
||||||
|
$dologout = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (valideTime ($dirTime, $fileTime)) {
|
if (valideTime ($dirTime, $fileTime)) {
|
||||||
setFake ($sender, $dir_link, $dirTime);
|
setSenderFake ($sender, $dirLink, $dirTime);
|
||||||
$message .= "Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire. (F4 ".date ("Y-m-d H:i:s", $dirTime)." != ".date ("Y-m-d H:i:s", $fileTime).")";
|
$message .= "Tentative de supprimer un envoi dont vous n'êtes pas le propriétaire.".
|
||||||
// XXX $doLogout = true;
|
str_replace (["___FILENAME___", "___DIRTIME___", "___FILETIME___"],
|
||||||
|
[$fileLink ['file_name'], $dirTime , $fileTime], M_INCONSISTENT_DATES);
|
||||||
|
$doLogout = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setFake ($archive_info [T_SENDER], $dir_link, $dirTime);
|
setSenderFake ($archiveInfo [T_SENDER], $dirLink, $dirTime);
|
||||||
$message .= "Quelqu'un avétait revandiqué cet envoi. (F5 ".$sender." != ".$archive_info [T_SENDER].")";
|
$message .= "Quelqu'un avétait revandiqué cet envoi. (".$sender." != ".$archiveInfo [T_SENDER].")";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -787,7 +848,7 @@ function deleteAction ($link_name) {
|
|||||||
// delete
|
// delete
|
||||||
if (isset ($_REQUEST [A_DELETE])) {
|
if (isset ($_REQUEST [A_DELETE])) {
|
||||||
if (!preg_match ('/[0-9a-zA-Z_-]+$/', $_REQUEST [A_DELETE]))
|
if (!preg_match ('/[0-9a-zA-Z_-]+$/', $_REQUEST [A_DELETE]))
|
||||||
return_error (t ('FILE_404'));
|
returnError (t ('FILE_404'));
|
||||||
deleteAction ($_REQUEST [A_DELETE]);
|
deleteAction ($_REQUEST [A_DELETE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,13 +871,13 @@ if (isset ($_REQUEST [A_ACTION])) {
|
|||||||
switch (true) {
|
switch (true) {
|
||||||
case preg_match ("/^".A_RECORD."(on|off)$/i", $_REQUEST [A_ACTION], $matches):
|
case preg_match ("/^".A_RECORD."(on|off)$/i", $_REQUEST [A_ACTION], $matches):
|
||||||
if ($matches [1] == "on")
|
if ($matches [1] == "on")
|
||||||
setTrack ($sender);
|
setSenderTrack ($sender);
|
||||||
else
|
else
|
||||||
rmTrack ($sender);
|
rmSenderTrack ($sender);
|
||||||
$message .= "Votre suivi à été mise à jour.";
|
$message .= "Votre suivi à été mise à jour.";
|
||||||
break;
|
break;
|
||||||
case preg_match ("/^".A_PERIOD."(".implode ("|", array_keys ($periodText)).")$/i", $_REQUEST [A_ACTION], $matches):
|
case preg_match ("/^".A_PERIOD."(".implode ("|", array_keys ($periodText)).")$/i", $_REQUEST [A_ACTION], $matches):
|
||||||
setPeriod ($sender, $matches [1]);
|
setSenderPeriod ($sender, $matches [1]);
|
||||||
$message .= "Votre période à été mise à jour.";
|
$message .= "Votre période à été mise à jour.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -827,30 +888,30 @@ $archives = [];
|
|||||||
$stack = array (VAR_LINKS);
|
$stack = array (VAR_LINKS);
|
||||||
while ( ($d = array_shift ($stack)) && $d != null) {
|
while ( ($d = array_shift ($stack)) && $d != null) {
|
||||||
$dir = scandir ($d);
|
$dir = scandir ($d);
|
||||||
foreach ($dir as $dir_name) {
|
foreach ($dir as $dirName) {
|
||||||
if (strcmp ($dir_name, '.') == 0 || strcmp ($dir_name, '..') == 0 ||
|
if (strcmp ($dirName, '.') == 0 || strcmp ($dirName, '..') == 0 ||
|
||||||
preg_match ('/\.tmp/i', "$dir_name")) {
|
preg_match ('/\.tmp/i', "$dirName")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_dir ($d . $dir_name)) {
|
if (is_dir ($d . $dirName)) {
|
||||||
/* Push new found directory. */
|
/* Push new found directory. */
|
||||||
$stack [] = $d . $dir_name . '/';
|
$stack [] = $d . $dirName . '/';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Read link informations. */
|
/* Read link informations. */
|
||||||
$l = jirafeau_get_link ($dir_name);
|
$l = jirafeau_get_link ($dirName);
|
||||||
if (!count ($l))
|
if (!count ($l))
|
||||||
continue;
|
continue;
|
||||||
if (!isKazArchive ($l))
|
if (!isKazArchive ($l))
|
||||||
continue;
|
continue;
|
||||||
$archive_info = read_archive_info ($l);
|
$archiveInfo = readArchiveFromLink ($l);
|
||||||
if ($sender != $archive_info [T_SENDER])
|
if ($sender != $archiveInfo [T_SENDER])
|
||||||
continue;
|
continue;
|
||||||
$archive_info ['link'] = $dir_name;
|
$archiveInfo ['link'] = $dirName;
|
||||||
$archive_info ['key'] = $l ['key'];
|
$archiveInfo ['key'] = $l ['key'];
|
||||||
$archive_info ['time'] = $l ['time'];
|
$archiveInfo ['maxtime'] = $l ['time'];
|
||||||
$archive_info ['hash'] = $l ['hash'];
|
$archiveInfo ['hash'] = $l ['hash'];
|
||||||
$archives [] = $archive_info;
|
$archives [] = $archiveInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require (JIRAFEAU_ROOT . 'lib/template/header.php');
|
require (JIRAFEAU_ROOT . 'lib/template/header.php');
|
||||||
@ -864,7 +925,7 @@ echo '<script type="text/javascript">';
|
|||||||
function getURI (uri, params) {
|
function getURI (uri, params) {
|
||||||
var form = document.createElement ('form');
|
var form = document.createElement ('form');
|
||||||
form.setAttribute ('method', 'post');
|
form.setAttribute ('method', 'post');
|
||||||
form.setAttribute ('action', "<?php echo $url_base; ?>"+uri);
|
form.setAttribute ('action', "<?php echo $urlBase; ?>"+uri);
|
||||||
var hiddenField = document.createElement ('input');
|
var hiddenField = document.createElement ('input');
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
if (params.hasOwnProperty (key)) {
|
if (params.hasOwnProperty (key)) {
|
||||||
@ -882,10 +943,10 @@ function getKazArchive (l, k) {
|
|||||||
getURI ("<?php echo $_SERVER ['SCRIPT_NAME']; ?>", {<?php echo A_GET; ?>:l+'~'+k});
|
getURI ("<?php echo $_SERVER ['SCRIPT_NAME']; ?>", {<?php echo A_GET; ?>:l+'~'+k});
|
||||||
}
|
}
|
||||||
function getKazFile (l, k) {
|
function getKazFile (l, k) {
|
||||||
window.location.href = "<?php echo $url_base; ?>/f.php?h="+l+"&k="+k;
|
window.location.href = "<?php echo $urlBase; ?>/f.php?h="+l+"&k="+k;
|
||||||
}
|
}
|
||||||
function showLink (l, k) {
|
function showLink (l, k) {
|
||||||
alert ("<?php echo $url_base;?>/f.php?h="+l+"&k="+k);
|
alert ("<?php echo $urlBase;?>/f.php?h="+l+"&k="+k);
|
||||||
}
|
}
|
||||||
function ajaxUpdate (period, hash) {
|
function ajaxUpdate (period, hash) {
|
||||||
var xhr = new XMLHttpRequest ();
|
var xhr = new XMLHttpRequest ();
|
||||||
@ -913,8 +974,8 @@ div.frame {border: 1px; border-style: solid; padding: 1em; margin: 1em;}
|
|||||||
--></style>
|
--></style>
|
||||||
<?php
|
<?php
|
||||||
$defaultChecked = [];
|
$defaultChecked = [];
|
||||||
$defaultChecked [getTrack ($sender) ? "on" : "off"] = ' checked="checked"';
|
$defaultChecked [getSenderTrack ($sender) ? "on" : "off"] = ' checked="checked"';
|
||||||
$defaultChecked [getPeriod ($sender)] = ' selected="selected"';
|
$defaultChecked [getSenderPeriod ($sender)] = ' selected="selected"';
|
||||||
echo
|
echo
|
||||||
'<form method="post">'.
|
'<form method="post">'.
|
||||||
'Je veux que Kaz suive tous mes futurs envois: '.
|
'Je veux que Kaz suive tous mes futurs envois: '.
|
||||||
@ -944,22 +1005,22 @@ echo
|
|||||||
$userSise = 0;
|
$userSise = 0;
|
||||||
$userTab = [];
|
$userTab = [];
|
||||||
if ($archives) {
|
if ($archives) {
|
||||||
foreach ($archives as $archive_info) {
|
foreach ($archives as $archiveInfo) {
|
||||||
$contentSize = 0;
|
$contentSize = 0;
|
||||||
$archContent = '';
|
$archContent = '';
|
||||||
foreach ([T_NEW, T_OLD] as $cat) {
|
foreach ([T_NEW, T_OLD] as $cat) {
|
||||||
$li_style = $cat == T_NEW ? "font-weight: bold;" : "font-style: italic;";
|
$liStyle = $cat == T_NEW ? "font-weight: bold;" : "font-style: italic;";
|
||||||
if (isset ($archive_info [$cat]))
|
if (isset ($archiveInfo [$cat]))
|
||||||
foreach ($archive_info [$cat] as [$link_name, $crypt_key]) {
|
foreach ($archiveInfo [$cat] as [$linkName, $cryptKey]) {
|
||||||
$link = jirafeau_get_link ($link_name);
|
$link = jirafeau_get_link ($linkName);
|
||||||
if (count ($link) == 0)
|
if (count ($link) == 0)
|
||||||
continue;
|
continue;
|
||||||
if ($cat == T_NEW )
|
if ($cat == T_NEW )
|
||||||
$contentSize += $link ['file_size'];
|
$contentSize += $link ['file_size'];
|
||||||
$lf = $link_name;
|
$lf = $linkName;
|
||||||
$kf = $link ['key'];
|
$kf = $link ['key'];
|
||||||
$archContent .=
|
$archContent .=
|
||||||
'<li style="list-style:none; '.$li_style.'">'.
|
'<li style="list-style:none; '.$liStyle.'">'.
|
||||||
'<a data-tooltip="voir" href="javascript:getKazFile (\''.$lf.'\', \''.$kf.'\');"> 👁 </a>'.
|
'<a data-tooltip="voir" href="javascript:getKazFile (\''.$lf.'\', \''.$kf.'\');"> 👁 </a>'.
|
||||||
'<a data-tooltip="voir le lien" href="javascript:showLink (\''.$lf.'\', \''.$kf.'\');"> 🔗 </a>';
|
'<a data-tooltip="voir le lien" href="javascript:showLink (\''.$lf.'\', \''.$kf.'\');"> 🔗 </a>';
|
||||||
// foreach ($periodButton as $item => $bt)
|
// foreach ($periodButton as $item => $bt)
|
||||||
@ -977,8 +1038,8 @@ if ($archives) {
|
|||||||
}
|
}
|
||||||
$archEntry =
|
$archEntry =
|
||||||
'<div class="frame" width="100%" >';
|
'<div class="frame" width="100%" >';
|
||||||
$la = $archive_info ['link'];
|
$la = $archiveInfo ['link'];
|
||||||
$ka = $archive_info ['key'];
|
$ka = $archiveInfo ['key'];
|
||||||
$archEntry .=
|
$archEntry .=
|
||||||
'<a data-tooltip="voir" href="javascript:getKazArchive (\''.$la.'\', \''.$ka.'\');"> 👁 </a>'.
|
'<a data-tooltip="voir" href="javascript:getKazArchive (\''.$la.'\', \''.$ka.'\');"> 👁 </a>'.
|
||||||
'<a data-tooltip="voir le lien" href="javascript:showLink (\''.$la.'\', \''.$ka.'\');"> 🔗 </a>';
|
'<a data-tooltip="voir le lien" href="javascript:showLink (\''.$la.'\', \''.$ka.'\');"> 🔗 </a>';
|
||||||
@ -986,13 +1047,13 @@ if ($archives) {
|
|||||||
$archEntry .=
|
$archEntry .=
|
||||||
'<a data-tooltip="'.$bt[1].'" href="javascript:ajaxUpdate (\''.$la.'\', \''.$ka.'\');"> '.$bt[0].' </a>';
|
'<a data-tooltip="'.$bt[1].'" href="javascript:ajaxUpdate (\''.$la.'\', \''.$ka.'\');"> '.$bt[0].' </a>';
|
||||||
$archEntry .=
|
$archEntry .=
|
||||||
'<strong>'.$archive_info [T_TIMESTAMP].' ('.jirafeau_human_size ($contentSize).')</strong>'.
|
'<strong>'.$archiveInfo [T_TIME].' ('.jirafeau_human_size ($contentSize).')</strong>'.
|
||||||
'<a data-tooltip="supprimer tous" href="javascript:rmFile (\''.$la.'\');"> ♺ </a>'.
|
'<a data-tooltip="supprimer tous" href="javascript:rmFile (\''.$la.'\');"> ♺ </a>'.
|
||||||
'<br/>=> '. ($archive_info ['time'] == -1 ? '∞' : jirafeau_get_datetimefield ($archive_info ['time'])).'<ul>'.
|
'<br/>=> '. ($archiveInfo ['maxtime'] == -1 ? '∞' : jirafeau_get_datetimefield ($archiveInfo ['maxtime'])).'<ul>'.
|
||||||
$archContent.
|
$archContent.
|
||||||
'</div>';
|
'</div>';
|
||||||
$userSise += $contentSize;
|
$userSise += $contentSize;
|
||||||
$userTab [getTimeFile ($archive_info ['hash'])] = $archEntry;
|
$userTab [getTimeFile ($archiveInfo ['hash'])] = $archEntry;
|
||||||
}
|
}
|
||||||
ksort ($userTab);
|
ksort ($userTab);
|
||||||
}
|
}
|
||||||
@ -1015,4 +1076,74 @@ if (count ($userTab)) {
|
|||||||
|
|
||||||
require (JIRAFEAU_ROOT.'lib/template/footer.php');
|
require (JIRAFEAU_ROOT.'lib/template/footer.php');
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// // $count = count ($lines)-1;
|
||||||
|
// // $content = '';
|
||||||
|
// // for ($i = 0; $i < $count; $i++)
|
||||||
|
// // $content .= $lines [$i];
|
||||||
|
// // if (isset ($archive [T_SIGN]) && $archive [T_SIGN] == md5 ($content))
|
||||||
|
// // return $archive;
|
||||||
|
// // $message .= "bad signature <pre>".print_r ($lines, 1)."</pre>";
|
||||||
|
// // return [];
|
||||||
|
|
||||||
|
// function getSecret () {
|
||||||
|
// if (!file_exists (VAR_PRIVATE."secret")) {
|
||||||
|
// mkdir (VAR_PERIOD, 0700);
|
||||||
|
// for ($s = '', $i = 0, $z = strlen ($a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')-1;
|
||||||
|
// $i != 32;
|
||||||
|
// $x = rand (0, $z), $s .= $a{$x}, $i++);
|
||||||
|
// file_put_contents (VAR_PRIVATE."secret", $s.NL);
|
||||||
|
// }
|
||||||
|
// return trim (file (VAR_PERIOD."secret"));
|
||||||
|
// }
|
||||||
|
// function crea-teArchive ($archive, $key, $maxtime, $ip) {
|
||||||
|
// if (!count ($archive))
|
||||||
|
// return;
|
||||||
|
// $content = T_ID.': '.time ();
|
||||||
|
// if (isset ($archive [T_TIME]))
|
||||||
|
// $content .= "time: ".$archive [T_TIME].NL;
|
||||||
|
// if (isset ($archive [T_SENDER]))
|
||||||
|
// $content .= "src: ".$archive [T_SENDER].NL;
|
||||||
|
// foreach ([T_OLD, T_NEW] as $cat)
|
||||||
|
// if (isset ($archiveInfo [$cat]))
|
||||||
|
// foreach ($archiveInfo [$cat] as [$linkName, $cryptKey])
|
||||||
|
// $content .= $cat.": ".$linkName." ".$cryptKey;
|
||||||
|
// $content .= T_SIGN.": ".md5 ($content).NL;
|
||||||
|
// $tmpFileName = tempnam (sys_get_temp_dir (), date ("newArchive-Ymd-H:i:s")."-");
|
||||||
|
// file_put_contents ($tmpFileName, $content);
|
||||||
|
|
||||||
|
// $file ['name'] = $tmpFileName;
|
||||||
|
// $file ['tmp_name'] = T_ARCHIVE_TITLE;
|
||||||
|
// $file ['error'] = UPLOAD_ERR_OK;
|
||||||
|
// $file ['type'] = T_ARCHIVE_MIME;
|
||||||
|
// $file ['size'] = filesize ($file ['tmp_name']);
|
||||||
|
|
||||||
|
// $res = jirafeau_upload (
|
||||||
|
// $file,
|
||||||
|
// false,
|
||||||
|
// $key,
|
||||||
|
// $maxtime,
|
||||||
|
// $ip,
|
||||||
|
// $cfg ['enable_crypt'],
|
||||||
|
// $cfg ['link_name_length'],
|
||||||
|
// $cfg ['file_hash']
|
||||||
|
// );
|
||||||
|
// unlink ($tmpFileName);
|
||||||
|
// }
|
||||||
|
// function checkNewArchive ($archive) {
|
||||||
|
// if (isset ($archiveInfo [T_NEW]))
|
||||||
|
// foreach ($archiveInfo [T_NEW] as [$fileName, $cryptKey]) {
|
||||||
|
// $fileLink = jirafeau_get_link ($fileName);
|
||||||
|
// if (! count ($link))
|
||||||
|
// return false;
|
||||||
|
// //upload_date
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // all new never download
|
||||||
|
// // all new mtime < 60s
|
||||||
|
// }
|
||||||
|
// function checkReadArchive ($archive) {
|
||||||
|
// // md5
|
||||||
|
// }
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user