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
+
with following link : ">
-
+
+
+">Return to home
diff --git a/src/rm_share.php b/src/rm_share.php
new file mode 100644
index 0000000..86ac83b
--- /dev/null
+++ b/src/rm_share.php
@@ -0,0 +1,36 @@
+ $dir,
+ 'creation' => $creation
+ ]);
+
+
+ $tsv = tsv_path($dir);
+ $keep = [];
+
+ $lines = file_get_contents($tsv);
+
+ foreach (explode("\n", $lines) as $line)
+ {
+ if (!$line)
+ {
+ continue;
+ }
+
+ $share = get_struct($dir, $line);
+ if (!(gen_identifier($share) == $identifier))
+ {
+ $keep[] = $line;
+ }
+ }
+ file_put_contents($tsv, implode("\n", $keep));
+
+ header("Location: index.php?dir=" . $dir);
+
+}
+
+remove_share($selected_dir, $_GET['creation']);
+
+?>
diff --git a/src/sanddir_template.php b/src/sanddir_template.php
index ea0942d..d5d9b66 100644
--- a/src/sanddir_template.php
+++ b/src/sanddir_template.php
@@ -30,47 +30,61 @@ if (isset($_GET['action']) && $_GET['action'] == 'share')
+$shares = read_tsv($selected_dir, tsv_path($selected_dir));
-Existing shares for
-
-
-
- | Name |
- Description |
- Creation |
- Expiration |
-
-
-
- |
-
- |
-
-
- |
-
-
- |
-
-
- |
-
+
+ Existing shares for
+
+
+
+ | Name |
+ Description |
+ Creation |
+ Expiration |
+ Actions |
+
+
+
+ |
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+ Delete
+
+ |
+
+
+
-
+