commit 43f4d7516427d0d581686f2ee84b451e3197e09d Author: max/sooulix Date: Mon Feb 10 21:24:31 2025 +0100 initial commit diff --git a/src/add_share.php b/src/add_share.php new file mode 100644 index 0000000..9695188 --- /dev/null +++ b/src/add_share.php @@ -0,0 +1,50 @@ +add(new DateInterval("P" . $offset)); + return $date->format(DateTimeInterface::ISO8601); +} + +function write_line($dirname, $name, $description, $creation, $expiration, $expires) +{ + file_put_contents( + tsv_path($dirname), + implode("\t", [ + $name, + $description, + $creation, + $expiration, + $expires . "\n" + ]), + FILE_APPEND + ); +} + +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); +} +?> diff --git a/src/common.php b/src/common.php new file mode 100644 index 0000000..0750f17 --- /dev/null +++ b/src/common.php @@ -0,0 +1,181 @@ + $dir, + "name" => $split[0], + "description" => $split[1], + "creation" => $split[2], + "expiration" => $split[3], + "expires" => $split[4] + ]; + } + return $shares; +} + +function share_list($dir) +{ + return array_reduce( + dir_list($dir), + function($carry, $child) + { + $tsv = tsv_path($child); + if (is_file($tsv)) + { + return array_merge($carry, read_tsv($child, $tsv)); + } + return $carry; + }, + [] + ); +} + +function zip_dir($dir) +{ + $filename = tempnam('./tmp', ''); + $zip = new ZipArchive(); + $zip->open($filename, ZipArchive::CREATE); + + function inner($stack, $result) + { + + $path = implode('/', $stack); + if (is_file($path)) + { + array_push($result, $path); + } + else + { + foreach (scandir($path) as $elt) + { + if ($elt[0] == '.') + { + continue; + } + else if (is_dir($path)) + { + array_push($stack, $elt); + $result = inner($stack, $result); + array_pop($stack); + } + } + } + + return $result; + } + + $result = inner([$GLOBALS['SANDDIR_ROOT_DIR'] . '/' . $dir], []); + sort($result); + + $dirs = []; + $files = []; + foreach ($result as $path) + { + $path_without_root_dir = array_slice( + explode('/', $path), 2 + ); + $files[] = [ + $path, + implode('/', $path_without_root_dir) + ]; + $dirs[] = array_slice($path_without_root_dir, 0, count($path_without_root_dir) -1); + } + + sort($dirs); + + $dirs = array_unique( + array_map( + function($item) + { + return implode('/', $item); + }, + $dirs + ) + ); + + foreach ($dirs as $dir) + { + $zip->addEmptyDir($dir); + } + foreach ($files as $file) + { + $zip->addFile($file[0], $file[1]); + } + + $zip->close(); + + return $filename; +} + +function zip_response($share) +{ + $filename = zip_dir($share); + $size = filesize($filename); + header('Content-Type: application/zip'); + header('Content-Disposition: attachment; filename=' . $share . '.zip'); + header('Content-Length: ' . $size); + ob_end_clean(); + flush(); + readfile($filename); + exit; +} + +function _($var) +{ + print($var); +} + +?> diff --git a/src/config_sanddir.php b/src/config_sanddir.php new file mode 100644 index 0000000..82c1b62 --- /dev/null +++ b/src/config_sanddir.php @@ -0,0 +1,4 @@ + diff --git a/src/dir_list_template.php b/src/dir_list_template.php new file mode 100644 index 0000000..67e82ea --- /dev/null +++ b/src/dir_list_template.php @@ -0,0 +1,12 @@ + diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..7a2d218 --- /dev/null +++ b/src/index.php @@ -0,0 +1,24 @@ + + + diff --git a/src/new_share_template.php b/src/new_share_template.php new file mode 100644 index 0000000..a98bb93 --- /dev/null +++ b/src/new_share_template.php @@ -0,0 +1,5 @@ +Share " with following link : "> + + diff --git a/src/read.php b/src/read.php new file mode 100644 index 0000000..b7ea4c3 --- /dev/null +++ b/src/read.php @@ -0,0 +1,16 @@ + diff --git a/src/sanddir.php b/src/sanddir.php new file mode 100644 index 0000000..cd57370 --- /dev/null +++ b/src/sanddir.php @@ -0,0 +1,8 @@ + diff --git a/src/sanddir_template.php b/src/sanddir_template.php new file mode 100644 index 0000000..5be713d --- /dev/null +++ b/src/sanddir_template.php @@ -0,0 +1,48 @@ +

Sanddir

+ +Add a share + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + +

Existing links

+ +