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>Filename</th>
<th>Size</th> <th>Size</th>
<th>Retention</th> <th>Retention</th>
<th>Uploaded</th> <th>Timestamp</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
{% for file in files %} {% for file in files %}
<tr> <tr>
<td><a href="https://xygt.cc/{{ file['id'] }}">{{ file['id'] }}</a></td> <td><a href="https://xygt.cc/{{ file['id'] }}">{{ file['id'] }}</a></td>
<td>{{ file["filename"] }}</td> <td>{{ file["filename"] }}</td>
<td>{{ file["size"] }}</td> <td>{{ file["filesize"] }}mb</td>
<td>{{ file["retention"] }}</td> <td>{{ file["retention"] }}</td>
<td>{{ file["uploaded"] }}</td> <td>{{ file["date"] }}</td>
<td><a href="/{{ file.id }}/delete">Delete</a></td> <td><a href="/{{ file.id }}/delete">Delete</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -57,7 +57,7 @@
<br> <br>
<h3>Forgot your UserID?</h3> <h3>Forgot your UserID?</h3>
<p>Click below to view it.</p> <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;"> <div id="userid" style="display: none;">
<p>Your UserID is: {{ current_user.userid }}</p> <p>Your UserID is: {{ current_user.userid }}</p>
</div> </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: with open(f"{os.path.abspath(Config.fileDir)}/{filename}", "wb") as f:
f.write(file.read()) 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 # Create the dictionary that we'll insert into the db
data = { data = {
@ -55,8 +56,8 @@ def uploadFile(file, ip, userid, filename, id, retention):
'retention': retention, 'retention': retention,
'userid': userid, 'userid': userid,
'ip': ip, 'ip': ip,
'date': date, 'date': timestamp,
'expiry': date + retention 'expiry': timestamp + retention
} }
# Add the data and verify its there. # Add the data and verify its there.
@ -88,12 +89,17 @@ def shortenURL(url, ip, userid, id, retention):
elif retention > 31540000: elif retention > 31540000:
retention = 31540000 retention = 31540000
timestamp = datetime.datetime.now()
timestamp = timestamp.timestamp()
data = { data = {
"id": id, 'id': id,
"url": url, 'url': url,
"userid": userid, 'retention': retention,
"retention": retention, 'userid': userid,
"ip": ip 'ip': ip,
'date': timestamp,
'expiry': timestamp + retention
} }
Config.url.insert_one(data) 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 import os
from pymongo import MongoClient from pymongo import MongoClient
from config import Config from config import Config
import time
class Config: class Config:
# MongoDB init stuff # MongoDB init stuff
@ -21,6 +22,7 @@ class Config:
fileDir = "./data" fileDir = "./data"
def main(): def main():
while True:
print("Starting cleanup script...") print("Starting cleanup script...")
# Get current time in unix timestamp # Get current time in unix timestamp
@ -43,6 +45,8 @@ def main():
Config.url.delete_one({"id": url["id"]}) Config.url.delete_one({"id": url["id"]})
print("Cleanup complete.") print("Cleanup complete.")
time.sleep(60)
if __name__ == "__main__": if __name__ == "__main__":
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)
########################################