i think we're done for v1

This commit is contained in:
Jack Eilles 2024-01-05 14:18:55 +00:00
parent b26327627d
commit f037e8b62c
7 changed files with 111 additions and 30 deletions

View file

@ -20,16 +20,16 @@
<th>Filename</th>
<th>Size</th>
<th>Retention</th>
<th>Uploaded</th>
<th>Timestamp</th>
<th>Actions</th>
</tr>
{% for file in files %}
<tr>
<td><a href="https://xygt.cc/{{ file['id'] }}">{{ file['id'] }}</a></td>
<td>{{ file["filename"] }}</td>
<td>{{ file["size"] }}</td>
<td>{{ file["filesize"] }}mb</td>
<td>{{ file["retention"] }}</td>
<td>{{ file["uploaded"] }}</td>
<td>{{ file["date"] }}</td>
<td><a href="/{{ file.id }}/delete">Delete</a></td>
</tr>
{% endfor %}
@ -57,7 +57,7 @@
<br>
<h3>Forgot your UserID?</h3>
<p>Click below to view it.</p>
<button onclick="showUserIDandIDPass();">View UserID/IDPass</button>
<button onclick="showUserIDandIDPass();">View UserID</button>
<div id="userid" style="display: none;">
<p>Your UserID is: {{ current_user.userid }}</p>
</div>

View file

@ -44,7 +44,8 @@ def uploadFile(file, ip, userid, filename, id, retention):
with open(f"{os.path.abspath(Config.fileDir)}/{filename}", "wb") as f:
f.write(file.read())
date = time.mktime(datetime.datetime.now().timetuple())
timestamp = datetime.datetime.now()
timestamp = timestamp.timestamp()
# Create the dictionary that we'll insert into the db
data = {
@ -55,8 +56,8 @@ def uploadFile(file, ip, userid, filename, id, retention):
'retention': retention,
'userid': userid,
'ip': ip,
'date': date,
'expiry': date + retention
'date': timestamp,
'expiry': timestamp + retention
}
# Add the data and verify its there.
@ -87,13 +88,18 @@ def shortenURL(url, ip, userid, id, retention):
retention = 604800
elif retention > 31540000:
retention = 31540000
timestamp = datetime.datetime.now()
timestamp = timestamp.timestamp()
data = {
"id": id,
"url": url,
"userid": userid,
"retention": retention,
"ip": ip
'id': id,
'url': url,
'retention': retention,
'userid': userid,
'ip': ip,
'date': timestamp,
'expiry': timestamp + retention
}
Config.url.insert_one(data)

13
autoclean-xygt.service Normal file
View file

@ -0,0 +1,13 @@
[Unit]
Description=Runs every minute to autoclean xygt.
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/autoclean.py
[Install]
WantedBy=multi-user.target

View file

@ -10,6 +10,7 @@ import datetime
import os
from pymongo import MongoClient
from config import Config
import time
class Config:
# MongoDB init stuff
@ -21,28 +22,31 @@ class Config:
fileDir = "./data"
def main():
print("Starting cleanup script...")
while True:
print("Starting cleanup script...")
# Get current time in unix timestamp
now = datetime.datetime.now()
now = now.timestamp()
# Get current time in unix timestamp
now = datetime.datetime.now()
now = now.timestamp()
# Get all expired files
expiredFiles = Config.files.find({"expiry": {"$lt": now}})
expiredURLs = Config.url.find({"expiry": {"$lt": now}})
# Get all expired files
expiredFiles = Config.files.find({"expiry": {"$lt": now}})
expiredURLs = Config.url.find({"expiry": {"$lt": now}})
# Delete all expired files
for file in expiredFiles:
print(f"Deleting file {file['id']}")
Config.files.delete_one({"id": file["id"]})
os.remove(os.path.join(Config.fileDir, file["filename"]))
# Delete all expired files
for file in expiredFiles:
print(f"Deleting file {file['id']}")
Config.files.delete_one({"id": file["id"]})
os.remove(os.path.join(Config.fileDir, file["filename"]))
# Delete all expired URL's
for url in expiredURLs:
print(f"Deleting URL {url['id']}")
Config.url.delete_one({"id": url["id"]})
# Delete all expired URL's
for url in expiredURLs:
print(f"Deleting URL {url['id']}")
Config.url.delete_one({"id": url["id"]})
print("Cleanup complete.")
time.sleep(60)
print("Cleanup complete.")
if __name__ == "__main__":
main()

18
install.sh Executable file
View file

@ -0,0 +1,18 @@
# Might dockerise this stuff sooner or later, not now tho.
if [ $EUID -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
apt install mongodb-org python3-pip python3-venv
systemctl enable --now mongod
cp autoclean-xygt.service /lib/systemd/system/
cp autoclean.py /usr/bin/
cp config.py /usr/bin/
systemctl enable --now autoclean-xygt.service
echo "Installation complete, launch xygt with ./run.py (in the venv)"

31
moderation.py Normal file
View file

@ -0,0 +1,31 @@
from pymongo import MongoClient
import datetime
class Config:
# MongoDB init stuff
client = MongoClient("mongodb://localhost:27017/")
db = client["xygt"]
files = db["file"]
url = db["url"]
users = db["users"]
fileDir = "./data"
def main():
# Grab everything from the past day
now = datetime.datetime.now()
now = now.timestamp()
yesterday = now - 86400
files = Config.files.find({'date': {'$gt': yesterday}}).sort('date', -1)
urls = Config.url.find({'date': {'$gt': yesterday}}).sort('date', -1)
print("Files:")
for file in files:
print(f"File ID: {file['id']}, UserID: {file['userid']}, File Name: {file['filename']}, File Size: {file['filesize']}, File Type: {file['mimetype']}")
print("URLs:")
for url in urls:
print(f"URL ID: {url['id']}, UserID: {url['userid']}, URL: {url['url']}")
if __name__ == "__main__":
main()

9
run.py Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python3
# Run the app - MADE FOR SYSTEMD SERVICE
from app import app
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)
########################################