forked from spitkov/sxbin
Merge branch 'main' of https://git.spitkov.hu/cgcristi/aCloud
This commit is contained in:
parent
e723fb45d8
commit
7c641df41e
210
app.py
210
app.py
@ -1,4 +1,4 @@
|
||||
from flask import Flask, request, jsonify, send_from_directory, render_template, url_for, redirect
|
||||
from flask import Flask, request, jsonify, send_from_directory, render_template, url_for, redirect, send_file
|
||||
from werkzeug.utils import secure_filename
|
||||
import shortuuid
|
||||
import os
|
||||
@ -14,8 +14,11 @@ from pygments.lexers import get_lexer_by_name, guess_lexer
|
||||
from pygments.formatters import HtmlFormatter
|
||||
from pygments.util import ClassNotFound
|
||||
import json
|
||||
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
|
||||
import hashlib
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your_secret_key_here' # Add this line
|
||||
UPLOAD_FOLDER = './uploads'
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||
DATABASE = 'data.db'
|
||||
@ -77,6 +80,39 @@ cleanup_thread = threading.Thread(target=delete_old_files)
|
||||
cleanup_thread.daemon = True
|
||||
cleanup_thread.start()
|
||||
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
login_manager.login_view = 'login'
|
||||
|
||||
class User(UserMixin):
|
||||
def __init__(self, id, username, password_hash):
|
||||
self.id = id
|
||||
self.username = username
|
||||
self.password_hash = password_hash
|
||||
|
||||
@staticmethod
|
||||
def hash_password(password):
|
||||
salt = os.urandom(32)
|
||||
key = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt, 100000)
|
||||
return salt + key
|
||||
|
||||
@staticmethod
|
||||
def verify_password(stored_password, provided_password):
|
||||
salt = stored_password[:32]
|
||||
stored_key = stored_password[32:]
|
||||
new_key = hashlib.pbkdf2_hmac('sha256', provided_password.encode('utf-8'), salt, 100000)
|
||||
return stored_key == new_key
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
|
||||
user = cursor.fetchone()
|
||||
if user:
|
||||
return User(user[0], user[1], user[2])
|
||||
return None
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
@ -338,5 +374,177 @@ def download_folder_file(vanity, file_name):
|
||||
return send_from_directory(folder_path, file_name, as_attachment=True)
|
||||
return 'Not Found', 404
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if request.method == 'POST':
|
||||
username = request.form['username']
|
||||
password = request.form['password']
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
|
||||
if cursor.fetchone():
|
||||
return "Username already exists"
|
||||
hashed_password = User.hash_password(password)
|
||||
cursor.execute("INSERT INTO users (username, password_hash) VALUES (?, ?)",
|
||||
(username, hashed_password))
|
||||
db.commit()
|
||||
return redirect(url_for('login'))
|
||||
return render_template('register.html')
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
username = request.form['username']
|
||||
password = request.form['password']
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
|
||||
user = cursor.fetchone()
|
||||
if user and User.verify_password(user[2], password):
|
||||
login_user(User(user[0], user[1], user[2]))
|
||||
return redirect(url_for('user_files', username=username))
|
||||
return "Invalid username or password"
|
||||
return render_template('login.html')
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/user/<username>')
|
||||
def user_files(username):
|
||||
if current_user.is_authenticated and current_user.username == username:
|
||||
user_folder = os.path.join(app.config['UPLOAD_FOLDER'], username)
|
||||
if not os.path.exists(user_folder):
|
||||
os.makedirs(user_folder)
|
||||
files = os.listdir(user_folder)
|
||||
return render_template('user_files.html', username=username, files=files)
|
||||
return "Unauthorized", 401
|
||||
|
||||
@app.route('/user/<username>/upload', methods=['POST'])
|
||||
@login_required
|
||||
def upload_user_file(username):
|
||||
if current_user.username != username:
|
||||
return "Unauthorized", 401
|
||||
if 'file' not in request.files:
|
||||
return 'No file part', 400
|
||||
file = request.files['file']
|
||||
if file.filename == '':
|
||||
return 'No selected file', 400
|
||||
if file:
|
||||
filename = secure_filename(file.filename)
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], username, filename)
|
||||
file.save(file_path)
|
||||
return redirect(url_for('user_files', username=username))
|
||||
|
||||
@app.route('/user/<username>/delete/<filename>', methods=['POST'])
|
||||
@login_required
|
||||
def delete_user_file(username, filename):
|
||||
if current_user.username != username:
|
||||
return "Unauthorized", 401
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], username, filename)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
return redirect(url_for('user_files', username=username))
|
||||
|
||||
@app.route('/user/<username>/rename', methods=['POST'])
|
||||
@login_required
|
||||
def rename_user_file(username):
|
||||
if current_user.username != username:
|
||||
return "Unauthorized", 401
|
||||
old_filename = request.form['old_filename']
|
||||
new_filename = secure_filename(request.form['new_filename'])
|
||||
old_path = os.path.join(app.config['UPLOAD_FOLDER'], username, old_filename)
|
||||
new_path = os.path.join(app.config['UPLOAD_FOLDER'], username, new_filename)
|
||||
if os.path.exists(old_path):
|
||||
os.rename(old_path, new_path)
|
||||
return redirect(url_for('user_files', username=username))
|
||||
|
||||
@app.route('/<username>')
|
||||
@app.route('/<username>/')
|
||||
@app.route('/<username>/<path:filename>')
|
||||
def serve_user_page(username, filename=None):
|
||||
print(f"Accessing user page: {username}, filename: {filename}") # Debug print
|
||||
|
||||
# Check if the username exists in the database
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
|
||||
user = cursor.fetchone()
|
||||
if not user:
|
||||
print(f"User {username} not found") # Debug print
|
||||
return "User not found", 404
|
||||
|
||||
user_folder = os.path.join(app.config['UPLOAD_FOLDER'], username)
|
||||
print(f"User folder path: {user_folder}") # Debug print
|
||||
|
||||
if not os.path.exists(user_folder):
|
||||
print(f"User folder does not exist for {username}") # Debug print
|
||||
os.makedirs(user_folder) # Create the folder if it doesn't exist
|
||||
|
||||
if filename is None or filename == '':
|
||||
# Try to serve index.html
|
||||
index_path = os.path.join(user_folder, 'index.html')
|
||||
print(f"Checking for index.html at: {index_path}") # Debug print
|
||||
if os.path.exists(index_path):
|
||||
print(f"Serving index.html for {username}") # Debug print
|
||||
return send_file(index_path)
|
||||
else:
|
||||
print(f"No index.html found, listing files for {username}") # Debug print
|
||||
# If no index.html, list all files
|
||||
files = os.listdir(user_folder)
|
||||
print(f"Files in {username}'s folder: {files}") # Debug print
|
||||
return render_template('user_files_public.html', username=username, files=files)
|
||||
else:
|
||||
# Serve the requested file
|
||||
file_path = os.path.join(user_folder, filename)
|
||||
print(f"Attempting to serve file: {file_path}") # Debug print
|
||||
if os.path.exists(file_path) and os.path.isfile(file_path):
|
||||
print(f"Serving file: {file_path}") # Debug print
|
||||
return send_file(file_path)
|
||||
else:
|
||||
print(f"File not found: {file_path}") # Debug print
|
||||
return "File not found", 404
|
||||
|
||||
@app.route('/debug/users')
|
||||
def debug_users():
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
cursor.execute("SELECT username FROM users")
|
||||
users = cursor.fetchall()
|
||||
|
||||
user_files = {}
|
||||
for user in users:
|
||||
username = user[0]
|
||||
user_folder = os.path.join(app.config['UPLOAD_FOLDER'], username)
|
||||
if os.path.exists(user_folder):
|
||||
user_files[username] = os.listdir(user_folder)
|
||||
else:
|
||||
user_files[username] = []
|
||||
|
||||
return jsonify(user_files)
|
||||
|
||||
@app.route('/user/<username>/edit/<path:filename>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_file(username, filename):
|
||||
if current_user.username != username:
|
||||
return "Unauthorized", 401
|
||||
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], username, filename)
|
||||
|
||||
if request.method == 'POST':
|
||||
content = request.form['content']
|
||||
with open(file_path, 'w') as file:
|
||||
file.write(content)
|
||||
return redirect(url_for('user_files', username=username))
|
||||
|
||||
if os.path.exists(file_path) and os.path.isfile(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
content = file.read()
|
||||
return render_template('edit_file.html', username=username, filename=filename, content=content)
|
||||
else:
|
||||
return "File not found", 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=7123)
|
||||
|
@ -3,4 +3,10 @@ CREATE TABLE IF NOT EXISTS content (
|
||||
type TEXT NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
password_hash TEXT NOT NULL
|
||||
);
|
39
templates/edit_file.html
Normal file
39
templates/edit_file.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Edit {{ filename }}</title>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.30.1/min/vs/loader.min.js"></script>
|
||||
<style>
|
||||
#editor {
|
||||
width: 100%;
|
||||
height: 600px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Editing {{ filename }}</h1>
|
||||
<div id="editor"></div>
|
||||
<form id="saveForm" method="POST">
|
||||
<input type="hidden" name="content" id="content">
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.30.1/min/vs' }});
|
||||
require(['vs/editor/editor.main'], function() {
|
||||
var editor = monaco.editor.create(document.getElementById('editor'), {
|
||||
value: {{ content|tojson }},
|
||||
language: 'plaintext',
|
||||
theme: 'vs-dark'
|
||||
});
|
||||
|
||||
document.getElementById('saveForm').onsubmit = function() {
|
||||
document.getElementById('content').value = editor.getValue();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -3,148 +3,128 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>aCloud</title>
|
||||
<title>aCloud - File Sharing Service</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #121212;
|
||||
color: #e0e0e0;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background-color: #1a1a1a;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.container {
|
||||
background: #1e1e1e;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
h1 {
|
||||
nav {
|
||||
margin-bottom: 20px;
|
||||
color: #f5f5f5;
|
||||
}
|
||||
nav a {
|
||||
color: #4CAF50;
|
||||
text-decoration: none;
|
||||
margin: 0 10px;
|
||||
}
|
||||
.upload-options {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.upload-options button {
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
background-color: #4CAF50;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
margin: 0 10px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
margin: 4px 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.upload-options button.active {
|
||||
background-color: #0056b3;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.upload-form {
|
||||
display: none;
|
||||
background-color: #2a2a2a;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
.upload-form.active {
|
||||
display: block;
|
||||
}
|
||||
textarea, input[type="file"], input[type="text"] {
|
||||
width: calc(100% - 20px);
|
||||
margin-top: 10px;
|
||||
.upload-form input[type="text"],
|
||||
.upload-form input[type="file"],
|
||||
.upload-form textarea {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #333;
|
||||
box-sizing: border-box;
|
||||
background-color: #2e2e2e;
|
||||
color: #e0e0e0;
|
||||
border: 1px solid #4CAF50;
|
||||
background-color: #333;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
button[type="button"] {
|
||||
background-color: #28a745;
|
||||
color: #fff;
|
||||
.upload-form button {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
padding: 10px 20px;
|
||||
margin-top: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
color: #f5f5f5;
|
||||
margin-top: 10px;
|
||||
color: #4CAF50;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #2c2f33;
|
||||
color: #99aab5;
|
||||
padding: 10px 0;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
background-color: #2a2a2a;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: #61afef;
|
||||
text-decoration: none;
|
||||
.typewriter-container {
|
||||
font-family: monospace;
|
||||
white-space: pre-wrap;
|
||||
overflow: hidden;
|
||||
font-size: 1.2em;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
text-decoration: underline;
|
||||
.cursor {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 20px;
|
||||
background-color: #4CAF50;
|
||||
animation: blink 0.7s infinite;
|
||||
}
|
||||
|
||||
.footer .container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 15px;
|
||||
@keyframes blink {
|
||||
0% { opacity: 0; }
|
||||
50% { opacity: 1; }
|
||||
100% { opacity: 0; }
|
||||
}
|
||||
|
||||
.typewriter-container {
|
||||
font-size: 23px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.typewriter-text {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cursor {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 1em;
|
||||
background-color: #ff69b4;
|
||||
animation: blink 0.7s step-end infinite;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
50% {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<nav>
|
||||
<a href="{{ url_for('login') }}">Login</a>
|
||||
<a href="{{ url_for('register') }}">Register</a>
|
||||
</nav>
|
||||
|
||||
<div class="typewriter-container">
|
||||
<span id="typewriter-text" class="typewriter-text"></span><span id="cursor" class="cursor"></span>
|
||||
<span id="typewriter-text"></span><span id="cursor" class="cursor"></span>
|
||||
</div>
|
||||
</br>
|
||||
</br>
|
||||
|
||||
<div class="upload-options">
|
||||
<button id="textUploadBtn" onclick="showForm('text')">Upload Text</button>
|
||||
<button id="fileUploadBtn" onclick="showForm('file')">Upload File</button>
|
||||
<button id="folderUploadBtn" onclick="showForm('folder')">Upload Folder</button>
|
||||
<button id="urlShortenerBtn" onclick="showForm('url')">Shorten URL</button>
|
||||
<button onclick="showForm('text')">Upload Text</button>
|
||||
<button onclick="showForm('file')">Upload File</button>
|
||||
<button onclick="showForm('folder')">Upload Folder</button>
|
||||
<button onclick="showForm('url')">Shorten URL</button>
|
||||
</div>
|
||||
<div id="uploadFormContainer">
|
||||
<div id="textForm" class="upload-form">
|
||||
@ -182,155 +162,151 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const message1 = "Welcome to aCloud.";
|
||||
const message2 = "\n A simple toolbox for file uploading,\n URL shortening and pastebin.";
|
||||
const typewriterTextElement = document.getElementById('typewriter-text');
|
||||
const cursorElement = document.getElementById('cursor');
|
||||
const typingSpeed = 70;
|
||||
|
||||
function typeMessage(message, callback) {
|
||||
let index = 0;
|
||||
|
||||
function typeCharacter() {
|
||||
if (index < message.length) {
|
||||
if (message[index] === '\n') {
|
||||
typewriterTextElement.innerHTML += '<br>';
|
||||
} else {
|
||||
typewriterTextElement.innerHTML += message[index];
|
||||
}
|
||||
index++;
|
||||
updateCursorPosition();
|
||||
setTimeout(typeCharacter, typingSpeed);
|
||||
} else if (callback) {
|
||||
setTimeout(callback, typingSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
typeCharacter();
|
||||
}
|
||||
|
||||
function updateCursorPosition() {
|
||||
|
||||
const textRect = typewriterTextElement.getBoundingClientRect();
|
||||
cursorElement.style.left = (textRect.width + textRect.left - cursorElement.offsetWidth) + 'px';
|
||||
}
|
||||
|
||||
typeMessage(message1, function() {
|
||||
typeMessage(message2);
|
||||
});
|
||||
});;
|
||||
|
||||
|
||||
document.getElementById('uploadForm').onsubmit = function(e) {
|
||||
e.preventDefault();
|
||||
var formData = new FormData(this);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload/file', true);
|
||||
|
||||
xhr.upload.onprogress = function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var percentComplete = (e.loaded / e.total) * 100;
|
||||
document.getElementById('progressBar').style.display = 'block';
|
||||
document.getElementById('progressBar').value = percentComplete;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
alert('Upload complete!');
|
||||
document.getElementById('progressBar').style.display = 'none';
|
||||
} else {
|
||||
alert('Upload failed.');
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
function showForm(type) {
|
||||
document.querySelectorAll('.upload-form').forEach(form => {
|
||||
form.classList.remove('active');
|
||||
});
|
||||
document.getElementById(type + 'Form').classList.add('active');
|
||||
}
|
||||
|
||||
function uploadText() {
|
||||
const content = document.querySelector('#textForm textarea').value;
|
||||
fetch('/upload/pastebin', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams({ content }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('textResult').innerHTML = `Text uploaded. Access it <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function uploadFile() {
|
||||
const formData = new FormData();
|
||||
formData.append('file', document.querySelector('#fileForm input[type="file"]').files[0]);
|
||||
fetch('/upload/file', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('fileResult').innerHTML = `File uploaded. Download it <a href="/download/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function uploadFolder() {
|
||||
const files = document.querySelector('#folderForm input[type="file"]').files;
|
||||
if (files.length === 0) {
|
||||
alert('Please select a folder.');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
for (const file of files) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
|
||||
fetch('/upload/folder', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('folderResult').innerHTML = `Folder uploaded. View its contents <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function shortenUrl() {
|
||||
const url = document.querySelector('#urlForm input[name="url"]').value;
|
||||
fetch('/shorten', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams({ url }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('urlResult').innerHTML = `URL shortened. Access it <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p class="footer-text">Source code available on:
|
||||
<footer class="footer">
|
||||
<p>Source code available on:
|
||||
<a href="https://github.com/realcgcristi/order" target="_blank">GitHub (not up-to-date)</a> |
|
||||
<a href="https://git.spitkov.hu/cgcristi/aCloud" target="_blank">Spitkov's Git (main)</a>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const message1 = "Welcome to aCloud.";
|
||||
const message2 = "\n A simple toolbox for file uploading,\n URL shortening and pastebin.";
|
||||
const typewriterTextElement = document.getElementById('typewriter-text');
|
||||
const cursorElement = document.getElementById('cursor');
|
||||
const typingSpeed = 70;
|
||||
|
||||
function typeMessage(message, callback) {
|
||||
let index = 0;
|
||||
|
||||
function typeCharacter() {
|
||||
if (index < message.length) {
|
||||
if (message[index] === '\n') {
|
||||
typewriterTextElement.innerHTML += '<br>';
|
||||
} else {
|
||||
typewriterTextElement.innerHTML += message[index];
|
||||
}
|
||||
index++;
|
||||
updateCursorPosition();
|
||||
setTimeout(typeCharacter, typingSpeed);
|
||||
} else if (callback) {
|
||||
setTimeout(callback, typingSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
typeCharacter();
|
||||
}
|
||||
|
||||
function updateCursorPosition() {
|
||||
|
||||
const textRect = typewriterTextElement.getBoundingClientRect();
|
||||
cursorElement.style.left = (textRect.width + textRect.left - cursorElement.offsetWidth) + 'px';
|
||||
}
|
||||
|
||||
typeMessage(message1, function() {
|
||||
typeMessage(message2);
|
||||
});
|
||||
});;
|
||||
|
||||
|
||||
document.getElementById('uploadForm').onsubmit = function(e) {
|
||||
e.preventDefault();
|
||||
var formData = new FormData(this);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload/file', true);
|
||||
|
||||
xhr.upload.onprogress = function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var percentComplete = (e.loaded / e.total) * 100;
|
||||
document.getElementById('progressBar').style.display = 'block';
|
||||
document.getElementById('progressBar').value = percentComplete;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
alert('Upload complete!');
|
||||
document.getElementById('progressBar').style.display = 'none';
|
||||
} else {
|
||||
alert('Upload failed.');
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
function showForm(type) {
|
||||
document.querySelectorAll('.upload-form').forEach(form => {
|
||||
form.classList.remove('active');
|
||||
});
|
||||
document.getElementById(type + 'Form').classList.add('active');
|
||||
}
|
||||
|
||||
function uploadText() {
|
||||
const content = document.querySelector('#textForm textarea').value;
|
||||
fetch('/upload/pastebin', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams({ content }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('textResult').innerHTML = `Text uploaded. Access it <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function uploadFile() {
|
||||
const formData = new FormData();
|
||||
formData.append('file', document.querySelector('#fileForm input[type="file"]').files[0]);
|
||||
fetch('/upload/file', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('fileResult').innerHTML = `File uploaded. Download it <a href="/download/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function uploadFolder() {
|
||||
const files = document.querySelector('#folderForm input[type="file"]').files;
|
||||
if (files.length === 0) {
|
||||
alert('Please select a folder.');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
for (const file of files) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
|
||||
fetch('/upload/folder', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('folderResult').innerHTML = `Folder uploaded. View its contents <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
|
||||
function shortenUrl() {
|
||||
const url = document.querySelector('#urlForm input[name="url"]').value;
|
||||
fetch('/shorten', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams({ url }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('urlResult').innerHTML = `URL shortened. Access it <a href="/${data.vanity}">here</a>.`;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
6
templates/login.html
Normal file
6
templates/login.html
Normal file
@ -0,0 +1,6 @@
|
||||
<h2>Login</h2>
|
||||
<form method="post">
|
||||
<input type="text" name="username" placeholder="Username" required>
|
||||
<input type="password" name="password" placeholder="Password" required>
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
6
templates/register.html
Normal file
6
templates/register.html
Normal file
@ -0,0 +1,6 @@
|
||||
<h2>Register</h2>
|
||||
<form method="post">
|
||||
<input type="text" name="username" placeholder="Username" required>
|
||||
<input type="password" name="password" placeholder="Password" required>
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
21
templates/user_files.html
Normal file
21
templates/user_files.html
Normal file
@ -0,0 +1,21 @@
|
||||
<h2>{{ username }}'s Files</h2>
|
||||
<form action="{{ url_for('upload_user_file', username=username) }}" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file" required>
|
||||
<input type="submit" value="Upload">
|
||||
</form>
|
||||
<ul>
|
||||
{% for file in files %}
|
||||
<li>
|
||||
{{ file }}
|
||||
<form action="{{ url_for('delete_user_file', username=username, filename=file) }}" method="post" style="display: inline;">
|
||||
<input type="submit" value="Delete">
|
||||
</form>
|
||||
<form action="{{ url_for('rename_user_file', username=username) }}" method="post" style="display: inline;">
|
||||
<input type="hidden" name="old_filename" value="{{ file }}">
|
||||
<input type="text" name="new_filename" placeholder="New filename" required>
|
||||
<input type="submit" value="Rename">
|
||||
</form>
|
||||
<a href="{{ url_for('edit_file', username=username, filename=file) }}">Edit</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
43
templates/user_files_public.html
Normal file
43
templates/user_files_public.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ username }}'s Files</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #1a1a1a;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
h2 {
|
||||
color: #4CAF50;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
a {
|
||||
color: #4CAF50;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>{{ username }}'s Files</h2>
|
||||
<ul>
|
||||
{% for file in files %}
|
||||
<li><a href="{{ url_for('download_folder_file', vanity=username, file_name=file) }}">{{ file }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
27
uploads/asdasd/index.html
Normal file
27
uploads/asdasd/index.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Python IDE</title><script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.0/brython.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.0/brython_stdlib.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/codemirror.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/mode/python/python.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/addon/hint/show-hint.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/addon/hint/python-hint.js"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/codemirror.min.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/theme/monokai.min.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.0/addon/hint/show-hint.css"><style>body{background-color:#1e1e1e;color:#d4d4d4;font-family:'Consolas','Courier New',monospace;margin:0;padding:20px}h1{color:#569cd6}#code{width:100%;height:300px}#output{width:100%;height:200px;background-color:#1e1e1e;border:1px solid #3c3c3c;padding:10px;margin-top:10px;overflow-y:auto;font-family:'Consolas','Courier New',monospace}#run-button,#save-button{background-color:#0e639c;color:white;border:none;padding:10px 20px;margin-top:10px;cursor:pointer}#run-button:hover,#save-button:hover{background-color:#1177bb}.toolbar{margin-bottom:10px}.toolbar button{background-color:#3c3c3c;color:#d4d4d4;border:none;padding:5px 10px;margin-right:5px;cursor:pointer}.toolbar button:hover{background-color:#4e4e4e}</style></head><body onload="brython()"><h1>Python IDE</h1><div class="toolbar"><button id="undo-button">Undo</button><button id="redo-button">Redo</button><button id="save-button">Save</button></div><textarea id="code" placeholder="Enter your Python code here"></textarea><br><button id="run-button">Run</button><div id="output"></div><script type="text/python">from browser import document,window
|
||||
import sys
|
||||
class _0x1234:
|
||||
def __init__(_0x5678):_0x5678._0x9abc=document["output"]
|
||||
def write(_0x5678,_0xdef0):_0x5678._0x9abc.innerHTML+=_0xdef0
|
||||
sys.stdout=_0x1234()
|
||||
sys.stderr=_0x1234()
|
||||
def _0x2345(_0x6789):
|
||||
document["output"].innerHTML=""
|
||||
_0xabcd=window.editor.getValue()
|
||||
try:exec(_0xabcd)
|
||||
except Exception as _0xef01:print(f"Error: {str(_0xef01)}")
|
||||
document["run-button"].bind("click",_0x2345)
|
||||
def _0x3456(_0x789a):window.editor.undo()
|
||||
def _0x4567(_0x89ab):window.editor.redo()
|
||||
document["undo-button"].bind("click",_0x3456)
|
||||
document["redo-button"].bind("click",_0x4567)
|
||||
def _0x5678(_0x9abc):
|
||||
_0xbcde=window.editor.getValue()
|
||||
_0xcdef=window.Blob.new([_0xbcde],{'type':'text/plain'})
|
||||
_0xdef0=window.URL.createObjectURL(_0xcdef)
|
||||
_0xef01=document.createElement('a')
|
||||
_0xef01.href=_0xdef0
|
||||
_0xef01.download='python_code.py'
|
||||
_0xef01.click()
|
||||
window.URL.revokeObjectURL(_0xdef0)
|
||||
document["save-button"].bind("click",_0x5678)</script><script>var _0x1234=CodeMirror.fromTextArea(document.getElementById("code"),{mode:"python",theme:"monokai",lineNumbers:!0,autoCloseBrackets:!0,matchBrackets:!0,indentUnit:4,tabSize:4,indentWithTabs:!1,extraKeys:{"Ctrl-Space":"autocomplete","Tab":function(_0x5678){_0x5678.somethingSelected()?_0x5678.indentSelection("add"):_0x5678.replaceSelection(_0x5678.getOption("indentWithTabs")?"\t":Array(_0x5678.getOption("indentUnit")+1).join(" "),"end","+input")}},hintOptions:{completeSingle:!1}});_0x1234.on("inputRead",function(_0x2345,_0x3456){if("+input"===_0x3456.origin){var _0x4567=_0x2345.getCursor(),_0x5678=_0x2345.getTokenAt(_0x4567);("variable"===_0x5678.type||"."===_0x5678.string)&&_0x2345.showHint({completeSingle:!1})}})</script></body></html>
|
Loading…
Reference in New Issue
Block a user