mirror of
https://github.com/jackeilles/xygt.git
synced 2024-11-27 01:02:40 +01:00
i think we're done for v1
This commit is contained in:
parent
b26327627d
commit
f037e8b62c
7 changed files with 111 additions and 30 deletions
|
@ -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>
|
||||||
|
|
|
@ -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
13
autoclean-xygt.service
Normal 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
|
38
autoclean.py
38
autoclean.py
|
@ -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,28 +22,31 @@ class Config:
|
||||||
fileDir = "./data"
|
fileDir = "./data"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Starting cleanup script...")
|
while True:
|
||||||
|
print("Starting cleanup script...")
|
||||||
|
|
||||||
# Get current time in unix timestamp
|
# Get current time in unix timestamp
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
now = now.timestamp()
|
now = now.timestamp()
|
||||||
|
|
||||||
# Get all expired files
|
# Get all expired files
|
||||||
expiredFiles = Config.files.find({"expiry": {"$lt": now}})
|
expiredFiles = Config.files.find({"expiry": {"$lt": now}})
|
||||||
expiredURLs = Config.url.find({"expiry": {"$lt": now}})
|
expiredURLs = Config.url.find({"expiry": {"$lt": now}})
|
||||||
|
|
||||||
# Delete all expired files
|
# Delete all expired files
|
||||||
for file in expiredFiles:
|
for file in expiredFiles:
|
||||||
print(f"Deleting file {file['id']}")
|
print(f"Deleting file {file['id']}")
|
||||||
Config.files.delete_one({"id": file["id"]})
|
Config.files.delete_one({"id": file["id"]})
|
||||||
os.remove(os.path.join(Config.fileDir, file["filename"]))
|
os.remove(os.path.join(Config.fileDir, file["filename"]))
|
||||||
|
|
||||||
# Delete all expired URL's
|
# Delete all expired URL's
|
||||||
for url in expiredURLs:
|
for url in expiredURLs:
|
||||||
print(f"Deleting URL {url['id']}")
|
print(f"Deleting URL {url['id']}")
|
||||||
Config.url.delete_one({"id": url["id"]})
|
Config.url.delete_one({"id": url["id"]})
|
||||||
|
|
||||||
|
print("Cleanup complete.")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
print("Cleanup complete.")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
18
install.sh
Executable file
18
install.sh
Executable 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
31
moderation.py
Normal 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
9
run.py
Executable 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)
|
||||||
|
|
||||||
|
########################################
|
Loading…
Reference in a new issue