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 +