From acd0796f5fd1651d27fa479e4f9f2d811eeeed1d Mon Sep 17 00:00:00 2001 From: max/sooulix Date: Tue, 11 Feb 2025 00:22:13 +0100 Subject: [PATCH] =?UTF-8?q?possibilit=C3=A9=20de=20r=C3=A9voquer=20un=20pa?= =?UTF-8?q?rtage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/add_share.php | 41 ++++++++---------- src/common.php | 59 +++++++++++++++++++------ src/dir_list_template.php | 8 ++++ src/index.php | 23 +++++++--- src/new_share_template.php | 6 +-- src/rm_share.php | 36 ++++++++++++++++ src/sanddir_template.php | 88 ++++++++++++++++++++++---------------- 7 files changed, 180 insertions(+), 81 deletions(-) create mode 100644 src/rm_share.php diff --git a/src/add_share.php b/src/add_share.php index 9695188..42f0bbf 100644 --- a/src/add_share.php +++ b/src/add_share.php @@ -25,26 +25,23 @@ function write_line($dirname, $name, $description, $creation, $expiration, $expi ); } -if (isset($_POST) && isset($_GET['action']) && $_GET['action'] == 'add') -{ - $creation = (new DateTime())->format(DateTimeInterface::ISO8601); - $expires = current_date_offset($_POST['expiration']); - write_line( - $_POST['dirname'], - $_POST['name'], - $_POST['description'], - $creation, - $_POST['expiration'], - $expires - ); - $new_share = [ - "dir" => $_POST['dirname'], - "name" => $_POST['name'], - "description" => $_POST['description'], - "creation" => $creation, - "expiration" => $_POST['expiration'], - "expires" => current_date_offset($_POST['expiration']) - ]; - $new_share["link"] = "./read.php?id=" . gen_identifier($new_share); -} +$creation = (new DateTime())->format(DateTimeInterface::ISO8601); +$expires = current_date_offset($_POST['expiration']); +write_line( + $_POST['dirname'], + $_POST['name'], + $_POST['description'], + $creation, + $_POST['expiration'], + $expires +); +$new_share = [ + "dir" => $_POST['dirname'], + "name" => $_POST['name'], + "description" => $_POST['description'], + "creation" => $creation, + "expiration" => $_POST['expiration'], + "expires" => current_date_offset($_POST['expiration']) +]; +$new_share["link"] = "./read.php?id=" . gen_identifier($new_share); ?> diff --git a/src/common.php b/src/common.php index 46a3ada..0bf8a7a 100644 --- a/src/common.php +++ b/src/common.php @@ -8,7 +8,7 @@ function gen_identifier($share) [ $GLOBALS['SANDDIR_SALT'], $share['dir'], - $share['creation'] + str_replace(' ', '+', $share['creation']) ] ) ); @@ -37,6 +37,27 @@ function tsv_path($dir) ]); } +function get_struct($dir, $line) +{ + if (!$line) + { + throw new Exception("Line is not compatible"); + } + $split = explode("\t", $line); + if (count($split) < 5) + { + throw new Exception("Error with line " . $line); + } + return [ + "dir" => $dir, + "name" => $split[0], + "description" => $split[1], + "creation" => $split[2], + "expiration" => $split[3], + "expires" => $split[4] + ]; +} + function read_tsv($dir, $path) { @@ -49,19 +70,8 @@ function read_tsv($dir, $path) { continue; } - $split = explode("\t", $line); - if (count($split) < 5) - { - throw new Exception("Error with line " . $line); - } - $shares[] = [ - "dir" => $dir, - "name" => $split[0], - "description" => $split[1], - "creation" => $split[2], - "expiration" => $split[3], - "expires" => $split[4] - ]; + + $shares[] = get_struct($dir, $line); } return $shares; } @@ -175,6 +185,27 @@ function zip_response($share) exit; } +function find_share($dir, $creation) +{ + $shares = read_tsv( + $dir, + tsv_path($dir) + ); + $identifier = gen_identifier([ + 'dir' => $dir, + 'creation' => $creation + ]); + + foreach ($shares as $share) + { + if (gen_identifier($share) == $identifier) + { + return $share; + } + } + return NULL; +} + function _($var) { print($var); diff --git a/src/dir_list_template.php b/src/dir_list_template.php index 67e82ea..f6b9727 100644 --- a/src/dir_list_template.php +++ b/src/dir_list_template.php @@ -1,3 +1,11 @@ + +Select a directory to share +