aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2024-08-16 15:23:07 +0800
committerHsiangNianian <i@jyunko.cn>2024-08-16 15:23:07 +0800
commitee281cb6ef11b8e115e02032a7c899927d2e92e5 (patch)
treeec83b3b57920b181c6c988bc6901a3730f725506
parent0817897398dd3ef7f0738838b20cc6c1e67db323 (diff)
downloadfiles-ee281cb6ef11b8e115e02032a7c899927d2e92e5.tar.gz
files-ee281cb6ef11b8e115e02032a7c899927d2e92e5.zip
chore: init project
-rw-r--r--Pipefile10
-rw-r--r--app.py127
-rw-r--r--files/109951167368046405.jpgbin0 -> 25916 bytes
-rw-r--r--files/3B42EE8DE456CDB990D27EAC440A150C.jpgbin0 -> 238970 bytes
-rw-r--r--files/GoodbyeDPI-master.zipbin0 -> 68677 bytes
-rw-r--r--files/security-key.txt1
-rw-r--r--requirements.txt1
-rw-r--r--static/style.css0
-rw-r--r--templates/file_info.html25
-rw-r--r--templates/files.html17
-rw-r--r--templates/index.html0
-rw-r--r--templates/login.html19
-rw-r--r--templates/upload.html16
13 files changed, 216 insertions, 0 deletions
diff --git a/Pipefile b/Pipefile
new file mode 100644
index 0000000..5ece07a
--- /dev/null
+++ b/Pipefile
@@ -0,0 +1,10 @@
+[[source]]
+url = "https://pypi.org/simple"
+verify_ssl = true
+name = "pypi"
+
+[packages]
+flask = "*"
+
+[requires]
+python_version = "3.9" \ No newline at end of file
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..7c3810e
--- /dev/null
+++ b/app.py
@@ -0,0 +1,127 @@
+from flask import Flask, render_template, request, redirect, send_file, url_for, send_from_directory, session, flash
+from werkzeug.utils import secure_filename
+import os
+import zipfile
+import io
+import urllib.parse
+
+
+app = Flask(__name__)
+app.secret_key = 'supersecretkey'
+app.config['UPLOAD_FOLDER'] = 'files'
+app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB
+
+ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'zip'}
+
+def allowed_file(filename):
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
+
+@app.route('/')
+def index():
+ if 'username' in session:
+ return redirect(url_for('upload_file'))
+ return redirect(url_for('login'))
+
+@app.route('/login', methods=['GET', 'POST'])
+def login():
+ if request.method == 'POST':
+ username = request.form['username']
+ password = request.form['password']
+ # 简单的用户名和密码验证
+ if username == 'admin' and password == 'password':
+ session['username'] = username
+ return redirect(url_for('upload_file'))
+ else:
+ flash('Invalid credentials')
+ return render_template('login.html')
+
+@app.route('/logout')
+def logout():
+ session.pop('username', None)
+ return redirect(url_for('login'))
+
+@app.route('/upload', methods=['GET', 'POST'])
+def upload_file():
+ if 'username' not in session:
+ return redirect(url_for('login'))
+ if request.method == 'POST':
+ if 'file' not in request.files:
+ flash('No file part')
+ return redirect(request.url)
+ file = request.files['file']
+ if file.filename == '':
+ flash('No selected file')
+ return redirect(request.url)
+ if file and allowed_file(file.filename):
+ filename = secure_filename(file.filename)
+ file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
+ flash('File successfully uploaded')
+ return redirect(url_for('uploaded_files'))
+ return render_template('upload.html')
+
+@app.route('/files')
+def uploaded_files():
+ if 'username' not in session:
+ return redirect(url_for('login'))
+ files = os.listdir(app.config['UPLOAD_FOLDER'])
+ return render_template('files.html', files=files)
+
+@app.route('/files/<filename>')
+def file_info(filename):
+ if 'username' not in session:
+ return redirect(url_for('login'))
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
+ if os.path.exists(file_path):
+ file_ext = filename.rsplit('.', 1)[1].lower()
+ if file_ext in {'png', 'jpg', 'jpeg', 'gif'}:
+ file_type = 'image'
+ elif file_ext in {'txt', 'pdf'}:
+ file_type = 'text'
+ elif file_ext == 'zip':
+ file_type = 'zip'
+ with zipfile.ZipFile(file_path, 'r') as zip_ref:
+ zip_contents = zip_ref.namelist()
+ return render_template('file_info.html', filename=filename, file_type=file_type, zip_contents=zip_contents)
+ else:
+ file_type = 'other'
+ return render_template('file_info.html', filename=filename, file_type=file_type)
+ else:
+ flash('File not found')
+ return redirect(url_for('uploaded_files'))
+
+@app.route('/files/<zip_filename>/<inner_filename>')
+def view_inner_file(zip_filename, inner_filename):
+ if 'username' not in session:
+ return redirect(url_for('login'))
+ zip_path = os.path.join(app.config['UPLOAD_FOLDER'], zip_filename)
+ if os.path.exists(zip_path):
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
+ if inner_filename in zip_ref.namelist():
+ file_ext = inner_filename.rsplit('.', 1)[1].lower()
+ if file_ext in {'png', 'jpg', 'jpeg', 'gif'}:
+ file_type = 'image'
+ file_data = zip_ref.read(inner_filename)
+ return send_file(io.BytesIO(file_data), mimetype=f'image/{file_ext}')
+ elif file_ext in {'txt', 'pdf'}:
+ file_type = 'text'
+ file_data = zip_ref.read(inner_filename)
+ return send_file(io.BytesIO(file_data), mimetype=f'application/{file_ext}')
+ else:
+ flash('Unsupported file type inside zip')
+ return redirect(url_for('file_info', filename=zip_filename))
+ else:
+ flash('File not found inside zip')
+ return redirect(url_for('file_info', filename=zip_filename))
+ else:
+ flash('Zip file not found')
+ return redirect(url_for('uploaded_files'))
+
+
+@app.route('/download/<filename>')
+def download_file(filename):
+ if 'username' not in session:
+ return redirect(url_for('login'))
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
+
+if __name__ == '__main__':
+ app.run(debug=True) \ No newline at end of file
diff --git a/files/109951167368046405.jpg b/files/109951167368046405.jpg
new file mode 100644
index 0000000..78c5593
--- /dev/null
+++ b/files/109951167368046405.jpg
Binary files differ
diff --git a/files/3B42EE8DE456CDB990D27EAC440A150C.jpg b/files/3B42EE8DE456CDB990D27EAC440A150C.jpg
new file mode 100644
index 0000000..9a57384
--- /dev/null
+++ b/files/3B42EE8DE456CDB990D27EAC440A150C.jpg
Binary files differ
diff --git a/files/GoodbyeDPI-master.zip b/files/GoodbyeDPI-master.zip
new file mode 100644
index 0000000..4462fb2
--- /dev/null
+++ b/files/GoodbyeDPI-master.zip
Binary files differ
diff --git a/files/security-key.txt b/files/security-key.txt
new file mode 100644
index 0000000..4fa34a5
--- /dev/null
+++ b/files/security-key.txt
@@ -0,0 +1 @@
+EsTw da7P ZCmG bw2F Mvhd BJHQ TMDf dVT3 vXBp 861C q6P4 PH9q \ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..2db5aea
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+Flask==2.0.2 \ No newline at end of file
diff --git a/static/style.css b/static/style.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/static/style.css
diff --git a/templates/file_info.html b/templates/file_info.html
new file mode 100644
index 0000000..9e88c64
--- /dev/null
+++ b/templates/file_info.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>File Info</title>
+</head>
+<body>
+ <h1>File Info: {{ filename }}</h1>
+ {% if file_type == 'image' %}
+ <img src="{{ url_for('download_file', filename=filename) }}" alt="{{ filename }}">
+ {% elif file_type == 'text' %}
+ <iframe src="{{ url_for('download_file', filename=filename) }}" width="100%" height="600px"></iframe>
+ {% elif file_type == 'zip' %}
+ <h2>Contents of {{ filename }}:</h2>
+ <ul>
+ {% for item in zip_contents %}
+ <li>{{ item }}</li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p>Cannot display this file type.</p>
+ {% endif %}
+ <a href="{{ url_for('uploaded_files') }}">Back to files</a>
+</body>
+</html> \ No newline at end of file
diff --git a/templates/files.html b/templates/files.html
new file mode 100644
index 0000000..5095242
--- /dev/null
+++ b/templates/files.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Uploaded Files</title>
+</head>
+<body>
+ <h1>Uploaded Files</h1>
+ <ul>
+ {% for file in files %}
+ <li><a href="{{ url_for('file_info', filename=file) }}">{{ file }}</a></li>
+ {% endfor %}
+ </ul>
+ <a href="{{ url_for('upload_file') }}">Upload More Files</a>
+ <a href="{{ url_for('logout') }}">Logout</a>
+</body>
+</html> \ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/templates/index.html
diff --git a/templates/login.html b/templates/login.html
new file mode 100644
index 0000000..e0c5d68
--- /dev/null
+++ b/templates/login.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Login</title>
+</head>
+<body>
+ <h1>Login</h1>
+ <form method="post">
+ <label for="username">Username:</label>
+ <input type="text" id="username" name="username" required>
+ <br>
+ <label for="password">Password:</label>
+ <input type="password" id="password" name="password" required>
+ <br>
+ <button type="submit">Login</button>
+ </form>
+</body>
+</html> \ No newline at end of file
diff --git a/templates/upload.html b/templates/upload.html
new file mode 100644
index 0000000..e024330
--- /dev/null
+++ b/templates/upload.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Upload File</title>
+</head>
+<body>
+ <h1>Upload File</h1>
+ <form method="post" enctype="multipart/form-data">
+ <input type="file" name="file" required>
+ <button type="submit">Upload</button>
+ </form>
+ <a href="{{ url_for('uploaded_files') }}">View Uploaded Files</a>
+ <a href="{{ url_for('logout') }}">Logout</a>
+</body>
+</html> \ No newline at end of file