From fda0ca04aab0a84f8d2c6e699162014071b66451 Mon Sep 17 00:00:00 2001
From: SanJacobs
Date: Sun, 9 Oct 2022 05:27:31 +0200
Subject: It works!!!
---
README.md | 15 ++++++++++-----
send-refresh.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 0aff7e1..4b04988 100644
--- a/README.md
+++ b/README.md
@@ -14,17 +14,22 @@ This is not finished software, don't use it.
## Planning
+### The main problem
+
+Not generating the page for every file every time the script runs.
+Somehow, the script needs to know if a file has already had it's page set up.
+Ok, just md5 the file, and see if the directory exists.
+Do the same for when the file is beyond 14 days old, and delete said directory, and then the file.
+
+### The easy part
+
I need a dir where I put a bunch of zip files.
Probably the home directory of a new user named "send"
Each filename will get md5sum'ed, and that will become the link.
send.sparkburst.net/f38eba6dbbe1965bc4869621d5a6fed3/test.zip
-Is this amazing for security? No, you could brute force this to find the files, but honestly, who cares?
-Any production important for security and leaks to be a concern will have a dedicated DIT, and this won't be needed.
-Maybe I could salt it... Hmmm... A thought for later.
-
-To generate the webpage, all I need is three pices of HTML to cat together.
+To generate the webpage, all I need is a few pieces of HTML to concatenate
1. Header and down to an opening `
`
2. Title of File
diff --git a/send-refresh.sh b/send-refresh.sh
index 388571c..422f787 100755
--- a/send-refresh.sh
+++ b/send-refresh.sh
@@ -4,29 +4,54 @@
#find /path/to/base/dir/ -mindepth 1 -maxdepth 1 -type d -ctime +14 -exec rm -rf {} \;
-# Recursively discover files in the user's home directory, older than 14 days, and delete them
+# Discover files in the user's home directory, older than 14 days, and delete them
#find /path/to/home/dir/ -mindepth 1 -maxdepth 1 -type f -ctime +14 -exec rm -rf {} \;
-# Recursively discover files in the user's home directory, younger than 14 days
+# Discover files in the user's home directory, younger than 14 days
#find /path/to/home/dir/ -mindepth 1 -maxdepth 1 -type f -ctime -14
# command for getting the filename out of a full path
#basename /path/to/file.zip
-# Creating an array of homedirectory files younger than 14 days:
+# Creating an arrays of home directory files:
-webdir="/path/to/public/webdir/"
+webdir="testdir/website/"
+homedir="testdir/home/"
young_files=()
-
while IFS= read -r -d $'\0'; do
young_files+=("$REPLY")
-done < <(find /home/san/ -mindepth 1 -maxdepth 1 -type f -ctime -14 -name "*.zip" -print0)
+done < <(find $homedir -mindepth 1 -maxdepth 1 -type f -ctime -14 -name "*.zip" -print0)
+
+old_files=()
+while IFS= read -r -d $'\0'; do
+ old_files+=("$REPLY")
+done < <(find $webdir* -mindepth 1 -maxdepth 1 -type f -ctime +14 -name "*.zip" -print0)
+# +14 this should say
# Looping over said array:
+echo " --- Young files ---"
for file in "${young_files[@]}"; do
filename=$(basename "$file")
checksum=$(md5sum "$file" | awk '{print $1;}')
+ filesite=$webdir$checksum
+
+ if mkdir "$filesite" ; then
+ echo "Made directory, and it worked!"
+
+ webpage=$filesite/index.html
+ cat html/1.part >> $webpage
+ echo \ >> $webpage
+ cat html/2.part >> $webpage
+ stat $file >> $webpage
+ zipinfo -1 $file | tree --fromfile . >> $webpage
+ cat html/3.part >> $webpage
+
+ mv "$file" "$filesite/$filename"
+
+ else
+ echo "Already done."
+ fi
echo "file: $file"
echo "filename: $filename"
@@ -34,3 +59,16 @@ for file in "${young_files[@]}"; do
done
+
+echo " --- Old files ---"
+for file in "${old_files[@]}"; do
+ filename=$(basename "$file")
+ checksum=$(md5sum "$file" | awk '{print $1;}')
+
+ echo "file: $file"
+ echo "filename: $filename"
+ echo "checksum: $checksum"
+
+ rm -rf $(dirname "$file")
+
+done
--
cgit v1.2.1