possibilité de révoquer un partage
This commit is contained in:
parent
c49abfb35b
commit
acd0796f5f
@ -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);
|
||||
?>
|
||||
|
@ -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);
|
||||
|
@ -1,3 +1,11 @@
|
||||
<?php
|
||||
if (!$selected_dir)
|
||||
{
|
||||
?>
|
||||
Select a directory to share
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<ul>
|
||||
<?php
|
||||
foreach (dir_list($GLOBALS['SANDDIR_ROOT_DIR']) as $share_dir)
|
||||
|
@ -1,22 +1,35 @@
|
||||
<html>
|
||||
<?php
|
||||
$new_share = NULL;
|
||||
$selected_dir = NULL;
|
||||
|
||||
require_once('./common.php');
|
||||
|
||||
require_once('./config_sanddir.php');
|
||||
|
||||
include('./add_share.php');
|
||||
|
||||
include('./dir_list_template.php');
|
||||
if (isset($_GET['dir']))
|
||||
{
|
||||
$selected_dir = $_GET['dir'];
|
||||
}
|
||||
else
|
||||
{
|
||||
include('./dir_list_template.php');
|
||||
}
|
||||
|
||||
if (isset($_POST) && isset($_GET['action']) && $_GET['action'] == 'add')
|
||||
{
|
||||
include('./add_share.php');
|
||||
}
|
||||
if ($new_share)
|
||||
{
|
||||
include('new_share_template.php');
|
||||
}
|
||||
else if (isset($_GET['dir']))
|
||||
else if ($selected_dir)
|
||||
{
|
||||
$selected_dir = $_GET['dir'];
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'remove')
|
||||
{
|
||||
include('./rm_share.php');
|
||||
}
|
||||
include('./sanddir_template.php');
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
Share "<?php _($new_share["dir"]) ?> with following link : <a href="<?php _($new_share["link"]) ?>"><?php _($new_share["link"]) ?></a>
|
||||
|
||||
<?php
|
||||
print_r($new_share);
|
||||
?>
|
||||
</br>
|
||||
|
||||
<a href="?dir=<?php _($new_share["dir"]) ?>">Return to home</a>
|
||||
|
36
src/rm_share.php
Normal file
36
src/rm_share.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
function remove_share($dir, $creation)
|
||||
{
|
||||
$identifier = gen_identifier([
|
||||
'dir' => $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']);
|
||||
|
||||
?>
|
@ -30,47 +30,61 @@ if (isset($_GET['action']) && $_GET['action'] == 'share')
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
$shares = read_tsv($selected_dir, tsv_path($selected_dir));
|
||||
|
||||
<h2>Existing shares for <?php _($selected_dir) ?></h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Creation</th>
|
||||
<th>Expiration</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach (read_tsv($selected_dir, tsv_path($selected_dir)) as $share)
|
||||
if (count($shares))
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _($share['name']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php _($share['description']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
_(
|
||||
explode('T', $share['creation'])[0]
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
_(
|
||||
$share['expires']
|
||||
? explode('T', $share['expires'])[0]
|
||||
: 'never'
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<h2>Existing shares for <?php _($selected_dir) ?></h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Creation</th>
|
||||
<th>Expiration</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($shares as $share)
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php _($share['name']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php _($share['description']) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
_(
|
||||
explode('T', $share['creation'])[0]
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
_(
|
||||
$share['expires']
|
||||
? explode('T', $share['expires'])[0]
|
||||
: 'never'
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="?dir=<?php _($selected_dir) ?>&action=remove&creation=<?php _($share['creation']) ?>">
|
||||
Delete
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user