9 Commits

Author SHA1 Message Date
Tyler 61193320d4 Actually working swipe controls for pacman game 2025-05-01 21:49:06 -10:00
Tyler 1c1fed1dd5 reverting swipe controls 2025-05-01 21:23:13 -10:00
Tyler 1edd1c858c Delete static/js/script.js 2025-05-01 21:20:15 -10:00
Tyler 1d55d4f4ce Swipe controls? 2025-05-01 21:14:34 -10:00
Tyler 7aefd5aff8 small fixes 2025-05-01 20:59:46 -10:00
Tyler 271b4cdc91 Delete restart.bat 2025-05-01 20:59:16 -10:00
Tyler 90dcb7ecb8 small things i forgot on my last push 2025-05-01 19:01:13 -10:00
Tyler 7ec213fad0 V .4.1 2025-05-01 18:46:29 -10:00
Tyler 766386501b Small fixes 2025-04-29 17:43:11 -10:00
20 changed files with 2336 additions and 1913 deletions
+177 -177
View File
@@ -1,177 +1,177 @@
# PacCrypt WebApp # PacCrypt WebApp
**PacCrypt** is a secure, feature-rich web app for encrypting and decrypting text and files — built with Flask, JavaScript, and AES-GCM encryption. **PacCrypt** is a secure, feature-rich web app for encrypting and decrypting text and files — built with Flask, JavaScript, and AES-GCM encryption.
Now with an admin control panel, GitHub updater, and a built-in Pac-Man easter egg! 🕹️ Now with an admin control panel, GitHub updater, and a built-in Pac-Man easter egg! 🕹️
Live demo: [paccrypt.unnaturalll.dev](http://paccrypt.unnaturalll.dev) Live demo: [paccrypt.unnaturalll.dev](http://paccrypt.unnaturalll.dev)
--- ---
## ✨ Features ## ✨ Features
- 🔒 Basic and Advanced Encryption for Text & Files - 🔒 Basic and Advanced Encryption for Text & Files
- 📁 Secure File Uploads with Pickup Passwords - 📁 Secure File Uploads with Pickup Passwords
- 🔑 Random Password Generator - 🔑 Random Password Generator
- 🎮 Hidden Pac-Man Game — type `pacman` to play - 🎮 Hidden Pac-Man Game — type `pacman` to play
- 🧠 Smart UI: Auto-switches input sections, toggles encryption labels - 🧠 Smart UI: Auto-switches input sections, toggles encryption labels
- 📋 Clipboard Copy Feedback with styled status boxes - 📋 Clipboard Copy Feedback with styled status boxes
- 🧾 Admin Panel: - 🧾 Admin Panel:
- Site map with live route list - Site map with live route list
- Server restart & GitHub update button - Server restart & GitHub update button
- Secure admin credential management - Secure admin credential management
- Server logs & upload cleanup - Server logs & upload cleanup
- 🧩 System Settings Page for upload config - 🧩 System Settings Page for upload config
- 📜 Custom 403, 404, and 500 Error Pages - 📜 Custom 403, 404, and 500 Error Pages
- 🤖 robots.txt and /sitemap for crawlers - 🤖 robots.txt and /sitemap for crawlers
- 📱 Mobile-Responsive UI - 📱 Mobile-Responsive UI
--- ---
## 👨‍💻 Installation ## 👨‍💻 Installation
### 📋 Prerequisites ### 📋 Prerequisites
- Python 3.7+ - Python 3.7+
- Flask 3+ - Flask 3+
- Cryptography 42+ - Cryptography 42+
- Waitress 2.1+ - Waitress 2.1+
- Git (for update feature) - Git (for update feature)
- Nginx (recommended) - Nginx (recommended)
--- ---
### ⚡ Quick Setup ### ⚡ Quick Setup
```bash ```bash
git clone https://github.com/TySP-Dev/PacCrypt.git git clone https://github.com/TySP-Dev/PacCrypt.git
cd paccrypt-webapp-final cd paccrypt-webapp-final
python -m venv venv python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt pip install -r requirements.txt
``` ```
Then run: Then run:
- Development Mode: - Development Mode:
```bash ```bash
./start_dev.sh # or start_dev.bat ./start_dev.sh # or start_dev.bat
``` ```
- Production Mode: - Production Mode:
```bash ```bash
./start_prod.sh # or start_prod.bat ./start_prod.sh # or start_prod.bat
``` ```
Visit [http://127.0.0.1:5000](http://127.0.0.1:5000) Visit [http://127.0.0.1:5000](http://127.0.0.1:5000)
--- ---
## 🧭 Navigation & Usage ## 🧭 Navigation & Usage
### 🔐 Encrypt & Decrypt ### 🔐 Encrypt & Decrypt
- Choose between Basic Cipher or Advanced AES - Choose between Basic Cipher or Advanced AES
- Type your message or upload a file - Type your message or upload a file
- Enter password (if AES) - Enter password (if AES)
- Select mode using toggle (Encrypt/Decrypt) - Select mode using toggle (Encrypt/Decrypt)
- Hit Execute - Hit Execute
### 📤 Share Files ### 📤 Share Files
- Upload a file with two passwords: - Upload a file with two passwords:
- Encryption password - Encryption password
- Pickup password - Pickup password
- Get a shareable URL and click 📋 Copy Link - Get a shareable URL and click 📋 Copy Link
### 🔑 Generate Passwords ### 🔑 Generate Passwords
- Click Generate - Click Generate
- Then hit 📋 Copy - Then hit 📋 Copy
### 🎮 Pac-Man Game ### 🎮 Pac-Man Game
- Type `pacman` in the input box - Type `pacman` in the input box
- Game appears with Restart/Exit controls - Game appears with Restart/Exit controls
- Classic arrow key controls 🕹️ - Classic arrow key controls 🕹️
--- ---
## 🛠️ Admin Panel ## 🛠️ Admin Panel
Visit `/adminpage` after setting up credentials at `/admin-setup`. Visit `/adminpage` after setting up credentials at `/admin-setup`.
Features: Features:
- 🔄 Restart server - 🔄 Restart server
- 🔃 Update from GitHub (git pull) - 🔃 Update from GitHub (git pull)
- 🧽 Clear uploads - 🧽 Clear uploads
- 🔐 Change admin password - 🔐 Change admin password
- 📝 View logs - 📝 View logs
- ⚙️ Adjust upload settings - ⚙️ Adjust upload settings
--- ---
## 🛡️ Deployment Tips ## 🛡️ Deployment Tips
Minimal Nginx config: Minimal Nginx config:
```nginx ```nginx
server { server {
listen 80; listen 80;
server_name yourdomain.com; server_name yourdomain.com;
location / { location / {
proxy_pass http://127.0.0.1:5000; proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} }
} }
``` ```
Use Let's Encrypt to add SSL/TLS support. Use Let's Encrypt to add SSL/TLS support.
--- ---
## 🗂️ Project Structure ## 🗂️ Project Structure
``` ```
paccrypt-webapp-final/ paccrypt-webapp-final/
├── app.py ├── app.py
├── requirements.txt ├── requirements.txt
├── README.md ├── README.md
├── templates/ ├── templates/
│ ├── index.html │ ├── index.html
│ ├── 404.html │ ├── 404.html
│ └── 403.html │ └── 403.html
│ └── 500.html │ └── 500.html
│ └── admin.html │ └── admin.html
│ └── admin_login.html │ └── admin_login.html
│ └── admin_settings.html │ └── admin_settings.html
│ └── admin_setup.html │ └── admin_setup.html
│ └── pickup.html │ └── pickup.html
├── static/ ├── static/
│ ├── css/ │ ├── css/
│ │ └── styles.css │ │ └── styles.css
│ ├── js/ │ ├── js/
│ │ └── ui.js │ │ └── ui.js
│ │ └── pacman.js │ │ └── pacman.js
│ │ └── main.js │ │ └── main.js
│ │ └── fileops.js │ │ └── fileops.js
│ │ └── encryption.js │ │ └── encryption.js
│ ├── img/ │ ├── img/
│ │ └── PacCrypt.png │ │ └── PacCrypt.png
│ │ └── Github_logo.png │ │ └── Github_logo.png
│ │ └── sitemap.png │ │ └── sitemap.png
│ └── audio/ │ └── audio/
│ └── chomp.mp3 │ └── chomp.mp3
├── start_dev.bat ├── start_dev.bat
├── start_prod.bat ├── start_prod.bat
├── start_dev.sh ├── start_dev.sh
├── start_prod.sh ├── start_prod.sh
``` ```
--- ---
## 📄 License ## 📄 License
MIT © [TySP-Dev](https://github.com/TySP-Dev) MIT © [TySP-Dev](https://github.com/TySP-Dev)
+719 -528
View File
File diff suppressed because it is too large Load Diff
+8 -7
View File
@@ -1,8 +1,9 @@
### **requirements.txt** ### **requirements.txt**
flask==3.0.3 flask==3.0.3
cryptography==42.0.5 cryptography==42.0.5
waitress==2.1.2 waitress==2.1.2
werkzeug==3.0.1
# nginx - Only needed for Nginx integration, not installed via pip
# nginx - Only needed for Nginx integration, not installed via pip
# Run pip install -r requirements.txt # Run pip install -r requirements.txt
+291 -76
View File
@@ -1,7 +1,7 @@
/* ===== Global Reset ===== */ /* ===== Global Reset ===== */
* { * {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 3px;
padding: 0; padding: 0;
} }
@@ -27,7 +27,7 @@ header {
box-shadow: 0 0 15px rgba(0, 255, 153, 0.4); box-shadow: 0 0 15px rgba(0, 255, 153, 0.4);
width: 100%; width: 100%;
max-width: 800px; max-width: 800px;
margin-bottom: 30px; margin-bottom: 40px !important;
} }
header h1 { header h1 {
@@ -48,8 +48,8 @@ main {
align-items: center; align-items: center;
width: 100%; width: 100%;
max-width: 800px; max-width: 800px;
padding: 20px; padding: 0;
gap: 30px; gap: 0;
} }
/* ===== Card Styling ===== */ /* ===== Card Styling ===== */
@@ -68,6 +68,7 @@ main {
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 0px; gap: 0px;
max-width: 725px;
width: 100%; width: 100%;
} }
@@ -79,14 +80,17 @@ input[type="file"] {
width: 80%; width: 80%;
max-width: 500px; max-width: 500px;
padding: 12px 20px; padding: 12px 20px;
border: 2px solid #00ff99; border: 1px solid #00ff99;
border-radius: 8px; border-radius: 8px;
background-color: #2c2f33; background-color: #2c2f33;
color: #00ff99; color: #00ff99;
font-size: 1em; font-size: 1em;
text-align: center; text-align: left;
transition: 0.3s; transition: 0.3s;
margin:10px auto; }
select {
text-align: center;
} }
textarea { textarea {
@@ -122,7 +126,7 @@ input:focus,
textarea:focus, textarea:focus,
select:focus { select:focus {
outline: none; outline: none;
box-shadow: 0 0 8px rgba(0, 255, 153, 0.8); box-shadow: 0 0 10px rgba(0, 255, 153, 0.8);
} }
/* ===== Textareas Specific Widths ===== */ /* ===== Textareas Specific Widths ===== */
@@ -136,10 +140,9 @@ select:focus {
/* ===== Button Group Styling ===== */ /* ===== Button Group Styling ===== */
.button-group { .button-group {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: nowrap;
justify-content: center; justify-content: center;
gap: 15px; gap: 15px;
margin: 10px auto;
width: 100%; width: 100%;
} }
@@ -152,23 +155,34 @@ button {
font-size: 1em; font-size: 1em;
cursor: pointer; cursor: pointer;
transition: 0.3s; transition: 0.3s;
width: 100%; width: auto;
max-width: 200px; min-width: 225px;
/* margin: 10px auto; */ max-width: 300px;
} }
button:hover { button:hover {
background-color: #00ff99; background-color: #00ff99;
color: #121212; color: #121212;
box-shadow: 0 0 10px rgba(0, 255, 153, 0.4);
} }
.danger-button {
background-color: #5f3131;
box-shadow: 0 0 20px rgba(185, 0, 0, 0.4);
}
.danger-button:hover {
background-color: #ff0000;
color: #121212;
box-shadow: 0 0 40px rgb(255, 0, 0);
}
/* ===== Toggle Switch Styling ===== */ /* ===== Toggle Switch Styling ===== */
.toggle-container { .toggle-container {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 12px; gap: 12px;
margin-top: 10px;
width: 100%; width: 100%;
} }
@@ -207,15 +221,15 @@ button {
/* The circle knob */ /* The circle knob */
.slider::before { .slider::before {
content: ""; content: "";
height: 26px; height: 22px;
width: 26px; width: 22px;
background-color: #00ff99; background-color: #00ff99;
border-radius: 50%; border-radius: 50%;
transition: .4s; transition: .4s;
transform: translateX(4px); transform: translateX(2px);
position: absolute; position: absolute;
left: 0px; left: auto;
bottom: 2.5px; bottom: auto;
} }
input:checked + .slider::before { input:checked + .slider::before {
@@ -295,9 +309,9 @@ footer {
color: #00ff99; color: #00ff99;
border-radius: 12px; border-radius: 12px;
box-shadow: 0 0 15px rgba(0, 255, 153, 0.4); box-shadow: 0 0 15px rgba(0, 255, 153, 0.4);
margin-top: 30px;
width: 100%; width: 100%;
max-width: 800px; max-width: 800px;
margin-top: 40px;
} }
footer a { footer a {
@@ -309,39 +323,70 @@ footer {
color: #ff0066; color: #ff0066;
} }
/* ===== Responsive Tweaks ===== */ /* ===== Responsive Design ===== */
@media (max-width: 600px) { @media (max-width: 600px) {
input, textarea, select, #input-text, #output-text { input,
textarea,
select,
#input-text,
#output-text {
width: 100%; width: 100%;
max-width: 90%; max-width: 90%;
} }
} }
/* ===== Copy Feedback Message ===== */ /* ===== Copy Feedback Message ===== */
.copy-feedback { .copy-feedback, #shared-link-feedback {
background-color: #2a2a2a; background-color: #2c2f33;
border: 1px solid #00ff99;
padding: 6px 12px; padding: 6px 12px;
margin-top: 6px; margin-top: 6px;
border-radius: 6px; border-radius: 6px;
color: #00ff99; color: #00ff99;
font-size: 0.9em; font-size: 0.9em;
display: none;
opacity: 0; opacity: 0;
transition: opacity 0.3s ease;
text-align: center; text-align: center;
max-width: 300px; max-width: 500px;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
transition: opacity 0.3s ease;
} }
.copy-feedback.show { .copy-feedback.show, #shared-link-feedback.show {
opacity: 1; display: block;
} opacity: 1;
.hidden {
display: none !important;
} }
.share-link-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
margin-top: 12px;
margin-bottom: 12px;
}
#share-link {
display: block;
background-color: #2c2f33;
padding: 8px 16px;
border-radius: 6px;
color: #00ff99;
font-size: 0.9em;
text-align: center;
max-width: 720px;
width: 100%;
word-break: break-all;
text-decoration: none;
transition: all 0.3s ease;
}
#share-link:hover {
color: #00cc77;
background-color: #36393f;
}
/* ===== Form Styling ===== */
form { form {
width: 100%; width: 100%;
display: flex; display: flex;
@@ -349,65 +394,39 @@ form {
align-items: center; align-items: center;
} }
form input, form input {
form button { width: 80%;
width: 80%; max-width: 500px;
max-width: 500px; text-align: left;
margin-bottom: 12px; }
text-align: center;
}
/* ===== Section Card Styling ===== */
section.card { section.card {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.copy-feedback.show { /* ===== Pacman Game Styling ===== */
display: block;
width: fit-content;
margin-top: 10px;
padding: 6px 12px;
background-color: #2a2a2a;
color: #00ff99;
border: 1px solid #00ff99;
border-radius: 6px;
}
#logContainer {
white-space: pre-wrap; /* Wrap long lines */
word-wrap: break-word; /* Break long words if needed */
overflow-wrap: anywhere; /* Ensures long strings don't overflow */
background: black;
color: lime;
padding: 10px;
border-radius: 8px;
max-height: 400px;
overflow-y: auto;
width: 100%;
box-sizing: border-box;
}
#pacmanCanvas { #pacmanCanvas {
background-color: black; background-color: black;
display: block; display: block;
margin: auto;
border: 2px solid #00ff99; border: 2px solid #00ff99;
border-radius: 12px; border-radius: 12px;
align-items: center; max-width: 700px;
justify-content: center; width: 100%;
aspect-ratio: 4/3;
object-fit: contain;
} }
#pacman-section { #pacman-section {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center;
gap: 20px; gap: 20px;
padding: 20px; margin-bottom: 25px;
display: block; max-width: 725px;
margin: auto; width: 100%;
border: 2px solid #00ff99;
border-radius: 12px;
} }
.pacman-wrapper { .pacman-wrapper {
@@ -415,10 +434,206 @@ section.card {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 100%; width: 100%;
padding: 0;
margin: 0;
} }
/* ===== Utility Classes ===== */
/* ===== Utility: Hidden Class ===== */
.hidden { .hidden {
display: none !important; display: none !important;
} }
/* ===== Section Spacing ===== */
#password-generator-section {
margin-bottom: 25px;
}
#encoding-section {
margin-bottom: 25px;
}
/* Pickup page sections */
#pickup-section {
margin-bottom: 25px;
}
#security-notice-section {
margin-bottom: 25px;
}
/* ===== File Input Section ===== */
#encoding-section #file-section {
display: none;
}
#encoding-section #file-section:not(.hidden) {
display: flex;
}
/* Ensure PacCrypt sharing file uploader is always visible */
#sharing-section #file-section {
display: flex;
}
/* Mobile-friendly download button */
.download-btn {
width: 100%;
padding: 12px;
font-size: 16px;
cursor: pointer;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 4px;
transition: background-color 0.3s;
}
.download-btn:hover {
background-color: var(--primary-hover);
}
/* Mobile form adjustments */
.pickup-form {
max-width: 100%;
margin: 0 auto;
}
.pickup-form input[type="password"] {
width: 100%;
padding: 12px;
margin-bottom: 10px;
font-size: 16px;
border: 1px solid var(--border-color);
border-radius: 4px;
background-color: var(--input-bg);
color: var(--text-color);
}
/* Mobile-specific styles */
@media (max-width: 768px) {
.download-btn {
padding: 15px;
font-size: 18px;
}
.pickup-form input[type="password"] {
padding: 15px;
font-size: 18px;
}
}
/* ===== Admin Section Styling ===== */
#sitemap-section,
#password-change-section,
#server-update-section,
#server-status-section,
#server-logs-section,
#system-settings-section {
margin-bottom: 25px;
padding: 25px;
background-color: #1e1e1e;
border-radius: 12px;
box-shadow: 0 0 15px rgba(0, 255, 153, 0.4);
}
.sitemap-header {
display: flex;
justify-content: space-between;
align-items: center;
margin: 15px 0;
}
.sitemap-header h3 {
color: #00ff99;
margin: 0;
}
.collapse-btn {
background: none;
border: none;
color: #00ff99;
font-size: 1.2em;
cursor: pointer;
padding: 5px 10px;
transition: transform 0.3s ease;
}
.collapse-btn:hover {
transform: scale(1.1);
}
.sitemap-content {
transition: all 0.3s ease;
margin-bottom: 15px;
}
#sitemap-section ul,
#server-status-section ul {
list-style: none;
padding-left: 0;
margin-top: 15px;
}
#sitemap-section li,
#server-status-section li {
margin-bottom: 10px;
padding: 8px;
background-color: #2c2f33;
border-radius: 6px;
color: #00ff99;
}
#server-logs-section button {
margin-bottom: 15px;
width: 100%;
max-width: 300px;
}
#logLoader {
color: #00ff99;
text-align: center;
padding: 10px;
}
#logContainer {
background-color: #2c2f33;
color: #00ff99;
padding: 15px;
border-radius: 8px;
max-height: 400px;
overflow-y: auto;
font-family: monospace;
white-space: pre-wrap;
}
#system-settings-section {
margin-bottom: unset !important;
padding: 25px;
background-color: #1e1e1e;
border-radius: 12px;
box-shadow: 0 0 15px rgba(0, 255, 153, 0.4);
}
/* ===== Mobile Responsive Adjustments ===== */
@media (max-width: 768px) {
#sitemap-section,
#password-change-section,
#server-update-section,
#server-status-section,
#server-logs-section,
#system-settings-section {
padding: 20px;
margin-bottom: 20px;
}
#sitemap-section li,
#server-status-section li {
font-size: 0.9em;
padding: 6px;
}
#logContainer {
font-size: 0.9em;
padding: 10px;
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1006 KiB

After

Width:  |  Height:  |  Size: 78 KiB

+104 -86
View File
@@ -1,86 +1,104 @@
// encryption.js /**
* Encryption module.
/** * Handles cryptographic operations using Web Crypto API.
* Derives an AES-GCM key from a password using PBKDF2. * Implements AES-GCM encryption with PBKDF2 key derivation.
* @param {string} password - User-supplied password. */
* @param {Uint8Array} salt - Randomly generated salt.
* @returns {Promise<CryptoKey>} // ===== Constants =====
*/ const SALT_LENGTH = 16;
export async function deriveKey(password, salt) { const IV_LENGTH = 12;
const encoder = new TextEncoder(); const PBKDF2_ITERATIONS = 200_000;
const keyMaterial = await crypto.subtle.importKey( const KEY_LENGTH = 256;
'raw',
encoder.encode(password), // ===== Key Derivation =====
{ name: 'PBKDF2' }, /**
false, * Derives an AES-GCM key from a password using PBKDF2.
['deriveKey'] * @param {string} password - User-supplied password.
); * @param {Uint8Array} salt - Randomly generated salt.
* @returns {Promise<CryptoKey>} - Derived cryptographic key.
return crypto.subtle.deriveKey( */
{ export async function deriveKey(password, salt) {
name: 'PBKDF2', const encoder = new TextEncoder();
salt, const keyMaterial = await crypto.subtle.importKey(
iterations: 200_000, 'raw',
hash: 'SHA-256' encoder.encode(password),
}, { name: 'PBKDF2' },
keyMaterial, false,
{ name: 'AES-GCM', length: 256 }, ['deriveKey']
false, );
['encrypt', 'decrypt']
); return crypto.subtle.deriveKey(
} {
name: 'PBKDF2',
/** salt,
* Encrypts a message using AES-GCM with a derived key. iterations: PBKDF2_ITERATIONS,
* @param {string} message - Plaintext message to encrypt. hash: 'SHA-256'
* @param {string} password - User password for key derivation. },
* @returns {Promise<string>} - Base64-encoded encrypted string. keyMaterial,
*/ { name: 'AES-GCM', length: KEY_LENGTH },
export async function encryptAdvanced(message, password) { false,
const encoder = new TextEncoder(); ['encrypt', 'decrypt']
const salt = crypto.getRandomValues(new Uint8Array(16)); );
const iv = crypto.getRandomValues(new Uint8Array(12)); }
const key = await deriveKey(password, salt);
const encoded = encoder.encode(message); // ===== Encryption =====
/**
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoded); * Encrypts a message using AES-GCM with a derived key.
* @param {string} message - Plaintext message to encrypt.
const output = new Uint8Array(salt.length + iv.length + ciphertext.byteLength); * @param {string} password - User password for key derivation.
output.set(salt); * @returns {Promise<string>} - Base64-encoded encrypted string.
output.set(iv, salt.length); */
output.set(new Uint8Array(ciphertext), salt.length + iv.length); export async function encryptAdvanced(message, password) {
const encoder = new TextEncoder();
return btoa(String.fromCharCode(...output)); const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
} const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
const key = await deriveKey(password, salt);
/** const encoded = encoder.encode(message);
* Decrypts an AES-GCM encrypted string.
* @param {string} encryptedData - Base64-encoded ciphertext. const ciphertext = await crypto.subtle.encrypt(
* @param {string} password - Password used to derive the decryption key. { name: 'AES-GCM', iv },
* @returns {Promise<string>} - Decrypted plaintext. key,
*/ encoded
export async function decryptAdvanced(encryptedData, password) { );
const encrypted = new Uint8Array(
atob(encryptedData).split('').map(c => c.charCodeAt(0)) const output = new Uint8Array(salt.length + iv.length + ciphertext.byteLength);
); output.set(salt);
output.set(iv, salt.length);
const salt = encrypted.slice(0, 16); output.set(new Uint8Array(ciphertext), salt.length + iv.length);
const iv = encrypted.slice(16, 28);
const ciphertext = encrypted.slice(28); return btoa(String.fromCharCode(...output));
const key = await deriveKey(password, salt); }
const decrypted = await crypto.subtle.decrypt( // ===== Decryption =====
{ name: 'AES-GCM', iv }, /**
key, * Decrypts an AES-GCM encrypted string.
ciphertext * @param {string} encryptedData - Base64-encoded ciphertext.
); * @param {string} password - Password used to derive the decryption key.
* @returns {Promise<string>} - Decrypted plaintext.
return new TextDecoder().decode(decrypted); */
} export async function decryptAdvanced(encryptedData, password) {
const encrypted = new Uint8Array(
/** atob(encryptedData).split('').map(c => c.charCodeAt(0))
* Optional init logging for module diagnostics. );
*/
export function setupEncryption() { const salt = encrypted.slice(0, SALT_LENGTH);
console.log('[Encryption] Module loaded'); const iv = encrypted.slice(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
} const ciphertext = encrypted.slice(SALT_LENGTH + IV_LENGTH);
const key = await deriveKey(password, salt);
const decrypted = await crypto.subtle.decrypt(
{ name: 'AES-GCM', iv },
key,
ciphertext
);
return new TextDecoder().decode(decrypted);
}
// ===== Module Initialization =====
/**
* Initializes the encryption module and logs its status.
*/
export function setupEncryption() {
console.log('[Encryption] Module loaded');
}
+119 -92
View File
@@ -1,92 +1,119 @@
// fileops.js /**
* File operations module.
import { encryptAdvanced, decryptAdvanced } from './encryption.js'; * Handles file encryption and decryption operations.
*/
/**
* Encrypts the selected file and triggers download of the encrypted version. // ===== Constants =====
* @param {HTMLInputElement} fileInput - The input element of type 'file'. const CHUNK_SIZE = 1024 * 1024; // 1MB chunks
* @param {string} password - Password for encryption.
*/ // ===== Public Interface =====
export function encryptFile(fileInput, password) { export async function encryptFile(fileInput, password) {
if (!fileInput.files.length) { const file = fileInput.files[0];
alert("Please select a file!"); if (!file) return;
return;
} try {
const encryptedChunks = await processFile(file, password, true);
const file = fileInput.files[0]; downloadEncryptedFile(encryptedChunks, file.name);
const reader = new FileReader(); } catch (error) {
alert("Error encrypting file: " + error.message);
reader.onload = async (e) => { }
const rawBytes = new Uint8Array(e.target.result); }
const base64 = btoa(String.fromCharCode(...rawBytes));
const encrypted = await encryptAdvanced(base64, password); export async function decryptFile(fileInput, password) {
downloadFile(encrypted, file.name + ".enc"); const file = fileInput.files[0];
}; if (!file) return;
reader.readAsArrayBuffer(file); try {
} const decryptedChunks = await processFile(file, password, false);
downloadDecryptedFile(decryptedChunks, file.name);
/** } catch (error) {
* Decrypts the selected encrypted file and triggers download of the original. alert("Error decrypting file: " + error.message);
* @param {HTMLInputElement} fileInput - The input element of type 'file'. }
* @param {string} password - Password for decryption. }
*/
export function decryptFile(fileInput, password) { // ===== File Processing =====
if (!fileInput.files.length) { async function processFile(file, password, isEncrypt) {
alert("Please select a file!"); const chunks = [];
return; const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
} let processedChunks = 0;
const file = fileInput.files[0]; for (let start = 0; start < file.size; start += CHUNK_SIZE) {
const reader = new FileReader(); const chunk = file.slice(start, start + CHUNK_SIZE);
const arrayBuffer = await chunk.arrayBuffer();
reader.onload = async (e) => { const uint8Array = new Uint8Array(arrayBuffer);
try {
const encryptedText = e.target.result; const processedChunk = await processChunk(uint8Array, password, isEncrypt);
const base64Decrypted = await decryptAdvanced(encryptedText, password); chunks.push(processedChunk);
const byteArray = new Uint8Array(
[...atob(base64Decrypted)].map(c => c.charCodeAt(0)) processedChunks++;
); updateProgress(processedChunks, totalChunks);
downloadFileBinary(byteArray, file.name.replace(/\.enc$/, '')); }
} catch (err) {
console.error("[Decryption Error]", err); return chunks;
alert("Decryption failed: wrong password or corrupted file."); }
}
}; async function processChunk(data, password, isEncrypt) {
const payload = {
reader.readAsText(file); "encryption-type": "advanced",
} operation: isEncrypt ? "encrypt" : "decrypt",
message: Array.from(data).join(','),
/** password: password
* Downloads a text-based file (encrypted string). };
* @param {string} content - The file content to download.
* @param {string} filename - Desired name for the downloaded file. const response = await fetch("/", {
*/ method: "POST",
function downloadFile(content, filename) { headers: { "Content-Type": "application/json" },
const blob = new Blob([content], { type: "application/octet-stream" }); body: JSON.stringify(payload)
const url = URL.createObjectURL(blob); });
const a = document.createElement("a"); if (!response.ok) {
a.href = url; throw new Error(`HTTP error! status: ${response.status}`);
a.download = filename; }
a.click();
const result = await response.json();
URL.revokeObjectURL(url); return new Uint8Array(result.result.split(',').map(Number));
} }
/** // ===== File Download =====
* Downloads a binary file (Uint8Array). function downloadEncryptedFile(chunks, originalName) {
* @param {Uint8Array} byteArray - The binary content. const blob = new Blob(chunks, { type: 'application/octet-stream' });
* @param {string} filename - Desired name for the downloaded file. const url = URL.createObjectURL(blob);
*/ const a = document.createElement('a');
function downloadFileBinary(byteArray, filename) { a.href = url;
const blob = new Blob([byteArray], { type: "application/octet-stream" }); a.download = originalName + '.encrypted';
const url = URL.createObjectURL(blob); document.body.appendChild(a);
a.click();
const a = document.createElement("a"); document.body.removeChild(a);
a.href = url; URL.revokeObjectURL(url);
a.download = filename; }
a.click();
function downloadDecryptedFile(chunks, originalName) {
URL.revokeObjectURL(url); const blob = new Blob(chunks, { type: 'application/octet-stream' });
} const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = originalName.replace('.encrypted', '');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// ===== Progress Tracking =====
function updateProgress(processed, total) {
const progressBar = document.getElementById("file-progress");
const progressText = document.getElementById("file-progress-text");
if (progressBar && progressText) {
const percent = Math.round((processed / total) * 100);
progressBar.style.width = percent + "%";
progressText.textContent = `Processing: ${percent}%`;
if (processed === total) {
setTimeout(() => {
progressBar.style.width = "0%";
progressText.textContent = "";
}, 1000);
}
}
}
+5 -4
View File
@@ -1,11 +1,12 @@
// main.js /**
* Main application entry point.
* Initializes UI and game components when the DOM is loaded.
*/
import { setupUI } from './ui.js'; import { setupUI } from './ui.js';
import { setupGame } from './pacman.js'; import { setupGame } from './pacman.js';
/** // Initialize application when DOM is fully loaded
* Initialize UI and game once the DOM is fully loaded.
*/
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
setupUI(); setupUI();
setupGame(); setupGame();
+169 -55
View File
@@ -1,52 +1,45 @@
// pacman.js /**
* Pacman game module.
* Handles game logic, rendering, and user interaction.
*/
// ===== Game Constants =====
const PACMAN_SPEED = 40;
const ENEMY_SPEED = 20;
const CELL_SIZE = 40;
const DOT_SIZE = 5;
// ===== Game State =====
let canvas, ctx, pacman, enemy, walls, dots, score;
let cols, rows, randSeed, gameInterval;
// ===== Public Interface =====
export function setupGame() { export function setupGame() {
console.log('[PacMan] Game module loaded.'); console.log('[PacMan] Game module loaded.');
window.startPacman = startPacman; window.startPacman = startPacman;
window.exitGame = exitGame; window.exitGame = exitGame;
} }
// ====== Game Constants & State ======
let canvas, ctx, pacman, enemy, walls, dots, score;
let pacmanSpeed = 40,
enemySpeed = 20,
cellSize = 40,
dotSize = 5,
cols, rows, randSeed, gameInterval;
// ====== Game Initialization ======
export function startPacman() { export function startPacman() {
canvas = document.getElementById("pacmanCanvas"); // Scroll to the Pacman section
ctx = canvas.getContext("2d"); const pacmanSection = document.getElementById("pacman-section");
if (pacmanSection) {
pacmanSection.scrollIntoView({ behavior: 'smooth' });
}
cols = Math.floor(canvas.width / cellSize); // Initialize game state
rows = Math.floor(canvas.height / cellSize); initializeGame();
walls = []; setupGameLoop();
dots = [];
score = 0;
clearInterval(gameInterval);
const seedSource = document.getElementById("password")?.value || "pacman";
randSeed = [...seedSource].reduce((s, c) => s + c.charCodeAt(0), 0);
generateWalls();
generateDots();
pacman = spawn();
do { enemy = spawn(); } while (enemy.x === pacman.x && enemy.y === pacman.y);
pacman.dx = pacman.dy = 0;
document.addEventListener("keydown", movePacman);
gameInterval = setInterval(gameLoop, 150);
} }
export function stopPacman() { export function stopPacman() {
clearInterval(gameInterval); clearInterval(gameInterval);
if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height); if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height);
// Restore scrolling
document.body.style.overflow = '';
document.removeEventListener('wheel', preventScroll);
document.removeEventListener('touchmove', preventScroll);
} }
export function resetGame() { export function resetGame() {
@@ -61,8 +54,88 @@ export function exitGame() {
document.getElementById("encoding-section").style.display = "block"; document.getElementById("encoding-section").style.display = "block";
} }
// ====== Game Setup Helpers ====== // ===== Game Initialization =====
function initializeGame() {
canvas = document.getElementById("pacmanCanvas");
ctx = canvas.getContext("2d");
cols = Math.floor(canvas.width / CELL_SIZE);
rows = Math.floor(canvas.height / CELL_SIZE);
walls = [];
dots = [];
score = 0;
clearInterval(gameInterval);
// Get seed from generated password or use default
const passwordField = document.getElementById("generated-password");
const seedSource = passwordField?.value || "pacman";
randSeed = [...seedSource].reduce((s, c) => s + c.charCodeAt(0), 0);
generateWalls();
generateDots();
pacman = spawn();
do { enemy = spawn(); } while (enemy.x === pacman.x && enemy.y === pacman.y);
pacman.dx = pacman.dy = 0;
document.addEventListener("keydown", movePacman);
// Prevent scrolling
document.body.style.overflow = 'hidden';
document.addEventListener('wheel', preventScroll, { passive: false });
document.addEventListener('touchmove', preventScroll, { passive: false });
// Add touch controls
let touchStartX = 0;
let touchStartY = 0;
canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
}, { passive: false });
canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
}, { passive: false });
canvas.addEventListener('touchend', (e) => {
e.preventDefault();
const touchEndX = e.changedTouches[0].clientX;
const touchEndY = e.changedTouches[0].clientY;
const dx = touchEndX - touchStartX;
const dy = touchEndY - touchStartY;
// Determine swipe direction based on the larger movement
if (Math.abs(dx) > Math.abs(dy)) {
// Horizontal swipe
if (dx > 0) {
pacman.dx = PACMAN_SPEED;
pacman.dy = 0;
} else {
pacman.dx = -PACMAN_SPEED;
pacman.dy = 0;
}
} else {
// Vertical swipe
if (dy > 0) {
pacman.dx = 0;
pacman.dy = PACMAN_SPEED;
} else {
pacman.dx = 0;
pacman.dy = -PACMAN_SPEED;
}
}
}, { passive: false });
}
function setupGameLoop() {
gameInterval = setInterval(gameLoop, 150);
}
// ===== Game Setup Helpers =====
function spawn() { function spawn() {
const options = []; const options = [];
for (let c = 1; c < cols - 1; c++) { for (let c = 1; c < cols - 1; c++) {
@@ -80,9 +153,9 @@ function spawn() {
} }
const s = options[Math.floor(rand() * options.length)]; const s = options[Math.floor(rand() * options.length)];
return { return {
x: s.c * cellSize + cellSize / 2, x: s.c * CELL_SIZE + CELL_SIZE / 2,
y: s.r * cellSize + cellSize / 2, y: s.r * CELL_SIZE + CELL_SIZE / 2,
size: cellSize / 2 - 5, size: CELL_SIZE / 2 - 5,
dx: 0, dx: 0,
dy: 0 dy: 0
}; };
@@ -94,6 +167,7 @@ function rand() {
} }
function generateWalls() { function generateWalls() {
// First pass: generate initial walls
for (let c = 0; c < cols; c++) { for (let c = 0; c < cols; c++) {
for (let r = 0; r < rows; r++) { for (let r = 0; r < rows; r++) {
if (c === 0 || r === 0 || c === cols - 1 || r === rows - 1 || rand() < 0.2) { if (c === 0 || r === 0 || c === cols - 1 || r === rows - 1 || rand() < 0.2) {
@@ -101,6 +175,25 @@ function generateWalls() {
} }
} }
} }
// Second pass: check for enclosed spaces
for (let c = 1; c < cols - 1; c++) {
for (let r = 1; r < rows - 1; r++) {
// Skip if already a wall
if (walls.some(w => w.c === c && w.r === r)) continue;
// Check all four sides
const hasWallAbove = walls.some(w => w.c === c && w.r === r - 1);
const hasWallBelow = walls.some(w => w.c === c && w.r === r + 1);
const hasWallLeft = walls.some(w => w.c === c - 1 && w.r === r);
const hasWallRight = walls.some(w => w.c === c + 1 && w.r === r);
// If all sides are walls, make this spot a wall too
if (hasWallAbove && hasWallBelow && hasWallLeft && hasWallRight) {
walls.push({ c, r });
}
}
}
} }
function generateDots() { function generateDots() {
@@ -120,8 +213,7 @@ function generateDots() {
} }
} }
// ====== Game Loop & Drawing ====== // ===== Game Loop & Rendering =====
function gameLoop() { function gameLoop() {
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
drawWalls(); drawWalls();
@@ -137,7 +229,7 @@ function gameLoop() {
function drawWalls() { function drawWalls() {
ctx.fillStyle = "blue"; ctx.fillStyle = "blue";
walls.forEach(w => { walls.forEach(w => {
ctx.fillRect(w.c * cellSize, w.r * cellSize, cellSize, cellSize); ctx.fillRect(w.c * CELL_SIZE, w.r * CELL_SIZE, CELL_SIZE, CELL_SIZE);
}); });
} }
@@ -151,7 +243,10 @@ function drawChar(ch, color) {
function drawScore() { function drawScore() {
ctx.fillStyle = "white"; ctx.fillStyle = "white";
ctx.font = "20px Poppins"; ctx.font = "20px Poppins";
ctx.fillText("Score: " + score, 10, 25); ctx.textAlign = "left";
// Add padding to prevent clipping
const padding = 10;
ctx.fillText("Score: " + score, padding, 25);
} }
function checkGameOver() { function checkGameOver() {
@@ -167,17 +262,16 @@ function checkGameOver() {
} }
} }
// ====== Movement Logic ====== // ===== Movement Logic =====
function movePacman(e) { function movePacman(e) {
const k = e.key; const k = e.key;
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(k)) return; if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(k)) return;
e.preventDefault(); e.preventDefault();
if (k === "ArrowUp") { pacman.dx = 0; pacman.dy = -pacmanSpeed; } if (k === "ArrowUp") { pacman.dx = 0; pacman.dy = -PACMAN_SPEED; }
if (k === "ArrowDown") { pacman.dx = 0; pacman.dy = pacmanSpeed; } if (k === "ArrowDown") { pacman.dx = 0; pacman.dy = PACMAN_SPEED; }
if (k === "ArrowLeft") { pacman.dx = -pacmanSpeed; pacman.dy = 0; } if (k === "ArrowLeft") { pacman.dx = -PACMAN_SPEED; pacman.dy = 0; }
if (k === "ArrowRight") { pacman.dx = pacmanSpeed; pacman.dy = 0; } if (k === "ArrowRight") { pacman.dx = PACMAN_SPEED; pacman.dy = 0; }
} }
function moveChar(ch) { function moveChar(ch) {
@@ -191,7 +285,7 @@ function moveChar(ch) {
function moveEnemy() { function moveEnemy() {
const options = []; const options = [];
const moves = [[enemySpeed, 0], [-enemySpeed, 0], [0, enemySpeed], [0, -enemySpeed]]; const moves = [[ENEMY_SPEED, 0], [-ENEMY_SPEED, 0], [0, ENEMY_SPEED], [0, -ENEMY_SPEED]];
moves.forEach(([dx, dy]) => { moves.forEach(([dx, dy]) => {
const nx = enemy.x + dx; const nx = enemy.x + dx;
@@ -225,8 +319,8 @@ function willCollide(x, y, size) {
const top = y - size, bottom = y + size; const top = y - size, bottom = y + size;
return walls.some(w => { return walls.some(w => {
const wx1 = w.c * cellSize, wy1 = w.r * cellSize; const wx1 = w.c * CELL_SIZE, wy1 = w.r * CELL_SIZE;
const wx2 = wx1 + cellSize, wy2 = wy1 + cellSize; const wx2 = wx1 + CELL_SIZE, wy2 = wy1 + CELL_SIZE;
return right > wx1 && left < wx2 && bottom > wy1 && top < wy2; return right > wx1 && left < wx2 && bottom > wy1 && top < wy2;
}); });
} }
@@ -235,8 +329,8 @@ function eatDots() {
const chompSound = document.getElementById("chomp-sound"); const chompSound = document.getElementById("chomp-sound");
dots = dots.filter(d => { dots = dots.filter(d => {
const dx = d.c * cellSize + cellSize / 2; const dx = d.c * CELL_SIZE + CELL_SIZE / 2;
const dy = d.r * cellSize + cellSize / 2; const dy = d.r * CELL_SIZE + CELL_SIZE / 2;
if (Math.abs(pacman.x - dx) < pacman.size && Math.abs(pacman.y - dy) < pacman.size) { if (Math.abs(pacman.x - dx) < pacman.size && Math.abs(pacman.y - dy) < pacman.size) {
score++; score++;
@@ -250,13 +344,33 @@ function eatDots() {
return true; return true;
}); });
// Check if all dots are eaten
if (dots.length === 0) {
// Trigger password generator for new random map
const generateBtn = document.getElementById("generate-btn");
if (generateBtn) {
generateBtn.click();
}
// Auto-restart the game after a short delay
setTimeout(() => {
resetGame();
}, 1000);
}
ctx.fillStyle = "white"; ctx.fillStyle = "white";
dots.forEach(d => { dots.forEach(d => {
ctx.beginPath(); ctx.beginPath();
ctx.arc(d.c * cellSize + cellSize / 2, d.r * cellSize + cellSize / 2, dotSize, 0, Math.PI * 2); ctx.arc(d.c * CELL_SIZE + CELL_SIZE / 2, d.r * CELL_SIZE + CELL_SIZE / 2, DOT_SIZE, 0, Math.PI * 2);
ctx.fill(); ctx.fill();
}); });
} }
// ===== Global Functions =====
window.resetGame = resetGame; window.resetGame = resetGame;
window.exitGame = exitGame; window.exitGame = exitGame;
// Add scroll prevention function
function preventScroll(e) {
e.preventDefault();
}
-475
View File
@@ -1,475 +0,0 @@
// ===== AES Advanced Encryption =====
async function encryptAdvanced(message, password) {
const salt = crypto.getRandomValues(new Uint8Array(16));
const key = await deriveKey(password, salt);
const iv = crypto.getRandomValues(new Uint8Array(12));
const encoder = new TextEncoder();
const encodedMessage = encoder.encode(message);
const encryptedMessage = await crypto.subtle.encrypt(
{ name: 'AES-GCM', iv: iv },
key,
encodedMessage
);
const encryptedArray = new Uint8Array(salt.length + iv.length + encryptedMessage.byteLength);
encryptedArray.set(salt);
encryptedArray.set(iv, salt.length);
encryptedArray.set(new Uint8Array(encryptedMessage), salt.length + iv.length);
return btoa(String.fromCharCode(...encryptedArray));
}
async function deriveKey(password, salt) {
const encoder = new TextEncoder();
const passwordBuffer = encoder.encode(password);
const keyMaterial = await crypto.subtle.importKey(
'raw',
passwordBuffer,
{ name: 'PBKDF2' },
false,
['deriveKey']
);
return crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: salt,
iterations: 200000,
hash: 'SHA-256',
},
keyMaterial,
{ name: 'AES-GCM', length: 256 },
false,
['encrypt', 'decrypt']
);
}
async function decryptAdvanced(encryptedData, password) {
const encryptedArray = new Uint8Array(atob(encryptedData).split("").map(c => c.charCodeAt(0)));
const salt = encryptedArray.slice(0, 16);
const iv = encryptedArray.slice(16, 28);
const encryptedMessage = encryptedArray.slice(28);
const key = await deriveKey(password, salt);
const decryptedMessage = await crypto.subtle.decrypt(
{ name: 'AES-GCM', iv: iv },
key,
encryptedMessage
);
const decoder = new TextDecoder();
return decoder.decode(decryptedMessage);
}
// ===== UI Toggles =====
function toggleEncryptionOptions() {
const type = document.getElementById("encryption-type").value;
document.getElementById("password-input").style.display = (type === 'advanced') ? 'flex' : 'none';
if (type === 'basic') removeFile();
toggleInputMode();
document.getElementById("encrypt-label").textContent = (type === 'basic') ? "Encode" : "Encrypt";
document.getElementById("decrypt-label").textContent = (type === 'basic') ? "Decode" : "Decrypt";
}
function removeFile() {
document.getElementById("file-input").value = "";
document.getElementById("remove-file-btn").style.display = 'none';
toggleInputMode();
}
function toggleInputMode() {
const textValue = document.getElementById("input-text").value.trim();
const fileSelected = document.getElementById("file-input").files.length > 0;
const isAdvanced = document.getElementById("encryption-type").value === 'advanced';
document.getElementById("text-section").style.display = fileSelected ? 'none' : 'flex';
document.getElementById("file-section").style.display = (isAdvanced && !textValue) ? 'flex' : 'none';
document.getElementById("remove-file-btn").style.display = fileSelected ? 'inline-block' : 'none';
if (isAdvanced) {
document.getElementById("password-input").style.display = 'flex';
}
}
// ===== Form Submission =====
async function handleSubmit(event) {
event.preventDefault();
const password = document.getElementById("password").value;
const encryptionType = document.getElementById("encryption-type").value;
if (encryptionType === 'advanced' && !password) {
alert("Password is required for advanced encryption.");
return;
}
const payload = {
"encryption-type": encryptionType,
operation: document.querySelector('input[name="operation"]:checked').value,
message: document.getElementById("input-text").value,
password: password
};
const fileInput = document.getElementById("file-input");
if (fileInput.files.length > 0) {
const op = document.querySelector('input[name="operation"]:checked').value;
if (op === 'encrypt') encryptFile();
else decryptFile();
return;
}
try {
const resp = await fetch("/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await resp.json();
document.getElementById("output-text").value = data.result;
} catch (err) {
alert("Error processing request: " + err);
}
}
// ===== File Encryption / Decryption =====
function encryptFile() {
const f = document.getElementById("file-input");
const pwd = document.getElementById("password").value;
if (!pwd) return alert("Please enter a password!");
if (!f.files.length) return alert("Please select a file!");
const reader = new FileReader();
reader.onload = async (e) => {
const raw = new Uint8Array(e.target.result);
const base64Raw = btoa(String.fromCharCode(...raw));
const encrypted = await encryptAdvanced(base64Raw, pwd);
downloadFile(encrypted, f.files[0].name + ".enc");
};
reader.readAsArrayBuffer(f.files[0]);
}
function decryptFile() {
const f = document.getElementById("file-input");
const pwd = document.getElementById("password").value;
if (!pwd) return alert("Please enter a password!");
if (!f.files.length) return alert("Please select a file!");
const reader = new FileReader();
reader.onload = async (e) => {
try {
const encryptedText = e.target.result;
const decryptedBase64 = await decryptAdvanced(encryptedText, pwd);
const byteString = atob(decryptedBase64);
const byteArray = new Uint8Array([...byteString].map(c => c.charCodeAt(0)));
downloadFileBinary(byteArray, f.files[0].name.replace(/\.enc$/, ''));
} catch (err) {
alert("Decryption failed: wrong password or corrupted file.");
}
};
reader.readAsText(f.files[0]);
}
function downloadFile(content, filename) {
const blob = new Blob([content], { type: "application/octet-stream" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
function downloadFileBinary(byteArray, filename) {
const blob = new Blob([byteArray], { type: "application/octet-stream" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
// ===== Password Generator =====
function generateRandomPassword() {
const length = 30;
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?/~";
let password = "";
for (let i = 0; i < length; i++) {
password += charset.charAt(Math.floor(Math.random() * charset.length));
}
document.getElementById("password-field").value = password;
}
// ===== Copy to Clipboard =====
function copyToClipboard(elementId, toastId) {
const copyText = document.getElementById(elementId);
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
const toast = document.getElementById(toastId);
toast.classList.add("show");
setTimeout(() => toast.classList.remove("show"), 2000);
}
// ===== Pacman Easter Egg =====
function checkForPacman() {
const val = document.getElementById("input-text").value.trim().toLowerCase();
const pacSection = document.getElementById("pacman-section");
const encSection = document.getElementById("encoding-section");
if (val.includes('pacman') && pacSection.style.display !== 'block') {
pacSection.style.display = 'block';
encSection.style.display = 'none';
startPacman();
} else if (pacSection.style.display === 'block' && !val.includes('pacman')) {
exitGame();
}
}
// ===== Game Exit & Restart =====
function exitGame() {
stopPacman();
document.getElementById("input-text").value = "";
document.getElementById("pacman-section").style.display = 'none';
document.getElementById("encoding-section").style.display = 'block';
}
function resetGame() {
stopPacman();
startPacman();
}
// ===== Clear All =====
function clearAll() {
document.getElementById("input-text").value = "";
document.getElementById("output-text").value = "";
document.getElementById("file-input").value = "";
document.getElementById("password").value = "";
document.getElementById("pacman-section").style.display = "none";
document.getElementById("encoding-section").style.display = "block";
removeFile();
toggleInputMode();
}
// ===== Initialize =====
document.addEventListener("DOMContentLoaded", () => {
toggleEncryptionOptions();
toggleInputMode();
document.getElementById("input-text").addEventListener("input", checkForPacman);
});
// ===== Pacman Game Variables & Logic =====
let canvas, ctx, pacman, enemy, walls, dots, score;
let pacmanSpeed = 40, enemySpeed = 20, cellSize = 40, dotSize = 5;
let cols, rows, randSeed, gameInterval;
function startPacman() {
canvas = document.getElementById("pacmanCanvas");
ctx = canvas.getContext("2d");
cols = Math.floor(canvas.width / cellSize);
rows = Math.floor(canvas.height / cellSize);
walls = []; dots = []; score = 0;
clearInterval(gameInterval);
randSeed = Array.from(
document.getElementById("password-field").value
).reduce((s, c) => s + c.charCodeAt(0), 0);
generateWalls();
generateDots();
pacman = spawn();
do {
enemy = spawn();
} while (enemy.x === pacman.x && enemy.y === pacman.y);
pacman.dx = pacman.dy = 0;
document.addEventListener("keydown", movePacman);
gameInterval = setInterval(gameLoop, 150);
}
function stopPacman() {
clearInterval(gameInterval);
if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function spawn() {
const opts = [];
for (let c = 1; c < cols - 1; c++) {
for (let r = 1; r < rows - 1; r++) {
if (!walls.some(w => w.c === c && w.r === r)) {
const neighbors = [
{ c: c+1, r }, { c: c-1, r },
{ c, r: r+1 }, { c, r: r-1 }
];
if (neighbors.some(n =>
!walls.some(w => w.c===n.c && w.r===n.r)
)) {
opts.push({ c, r });
}
}
}
}
const s = opts[Math.floor(rand() * opts.length)];
return {
x: s.c * cellSize + cellSize/2,
y: s.r * cellSize + cellSize/2,
size: cellSize/2 - 5,
dx: 0,
dy: 0
};
}
function rand() {
const x = Math.sin(randSeed++) * 10000;
return x - Math.floor(x);
}
function generateWalls() {
for (let c = 0; c < cols; c++) {
for (let r = 0; r < rows; r++) {
if (c===0||r===0||c===cols-1||r===rows-1||rand()<0.2) {
walls.push({ c, r });
}
}
}
}
function generateDots() {
dots = [];
for (let c = 1; c < cols - 1; c++) {
for (let r = 1; r < rows - 1; r++) {
if (walls.some(w => w.c===c && w.r===r)) continue;
const isEnclosed =
walls.some(w => w.c===c+1 && w.r===r) &&
walls.some(w => w.c===c-1 && w.r===r) &&
walls.some(w => w.c===c && w.r===r+1) &&
walls.some(w => w.c===c && w.r===r-1);
if (!isEnclosed) dots.push({ c, r });
}
}
}
function movePacman(e) {
if (!["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key)) return;
e.preventDefault();
if (e.key==="ArrowUp") { pacman.dx=0; pacman.dy=-pacmanSpeed; }
if (e.key==="ArrowDown") { pacman.dx=0; pacman.dy=pacmanSpeed; }
if (e.key==="ArrowLeft") { pacman.dx=-pacmanSpeed; pacman.dy=0; }
if (e.key==="ArrowRight") { pacman.dx=pacmanSpeed; pacman.dy=0; }
}
// ===== Collision Helper =====
function willCollide(x, y, size) {
const left = x - size, right = x + size;
const top = y - size, bottom = y + size;
for (let w of walls) {
const wx1 = w.c * cellSize, wy1 = w.r * cellSize;
const wx2 = wx1 + cellSize, wy2 = wy1 + cellSize;
if (right > wx1 && left < wx2 && bottom > wy1 && top < wy2) {
return true;
}
}
return false;
}
function moveChar(ch) {
const nx = ch.x + ch.dx, ny = ch.y + ch.dy;
if (!willCollide(nx, ny, ch.size)) {
ch.x = nx; ch.y = ny;
}
}
function moveEnemy() {
const options = [];
[[enemySpeed,0],[-enemySpeed,0],[0,enemySpeed],[0,-enemySpeed]].forEach(
([dx,dy]) => {
const nx = enemy.x + dx, ny = enemy.y + dy;
if (!willCollide(nx, ny, enemy.size)) options.push({dx,dy});
}
);
if (!options.length) return;
let best = options[0];
let bestD = Math.abs(enemy.x+best.dx-pacman.x)+Math.abs(enemy.y+best.dy-pacman.y);
for (let opt of options) {
const d = Math.abs(enemy.x+opt.dx-pacman.x)+Math.abs(enemy.y+opt.dy-pacman.y);
if (d < bestD) { best=opt; bestD=d; }
}
enemy.x += best.dx; enemy.y += best.dy;
}
function gameLoop() {
ctx.clearRect(0,0,canvas.width,canvas.height);
drawWalls();
moveChar(pacman);
moveEnemy();
drawChar(pacman,"yellow");
drawChar(enemy,"red");
eatDots();
drawScore();
checkGameOver();
}
function drawWalls() {
ctx.fillStyle="blue";
walls.forEach(w=>ctx.fillRect(w.c*cellSize,w.r*cellSize,cellSize,cellSize));
}
function drawChar(ch,color) {
ctx.beginPath();
ctx.arc(ch.x,ch.y,ch.size,0,Math.PI*2);
ctx.fillStyle=color; ctx.fill();
}
function eatDots() {
const chompSound = document.getElementById("chomp-sound");
dots = dots.filter(d => {
const dx = d.c * cellSize + cellSize / 2;
const dy = d.r * cellSize + cellSize / 2;
if (Math.abs(pacman.x - dx) < pacman.size && Math.abs(pacman.y - dy) < pacman.size) {
score++;
if (chompSound) {
chompSound.currentTime = 0; // Reset sound
chompSound.volume = 0.4;
chompSound.play();
}
return false; // Remove dot
}
return true;
});
ctx.fillStyle = "white";
dots.forEach(d => {
ctx.beginPath();
ctx.arc(d.c * cellSize + cellSize / 2, d.r * cellSize + cellSize / 2, dotSize, 0, Math.PI * 2);
ctx.fill();
});
}
function drawScore() {
ctx.fillStyle="white";
ctx.font="20px Poppins";
ctx.fillText("Score: "+score,10,25);
}
function checkGameOver() {
if (Math.abs(pacman.x-enemy.x)<pacman.size && Math.abs(pacman.y-enemy.y)<pacman.size) {
ctx.fillStyle="#00ff99";
ctx.font="40px Poppins";
ctx.textAlign="center";
ctx.fillText("Game Over!", canvas.width/2, canvas.height/2);
clearInterval(gameInterval);
}
}
+301 -215
View File
@@ -1,215 +1,301 @@
// ui.js /**
import { encryptFile, decryptFile } from './fileops.js'; * UI management module.
* Handles user interface interactions and form handling.
/** */
* Initialize all UI functionality after DOM is loaded
*/ import { encryptFile, decryptFile } from './fileops.js';
export function setupUI() {
toggleEncryptionOptions(); // ===== UI Initialization =====
toggleInputMode(); export function setupUI() {
// Set initial state of remove button to hidden
const encryptionTypeEl = document.getElementById("encryption-type"); const removeBtn = document.getElementById("remove-file-btn");
const inputTextEl = document.getElementById("input-text"); if (removeBtn) {
const formEl = document.getElementById("crypto-form"); removeBtn.style.display = "none";
const removeFileBtn = document.getElementById("remove-file-btn"); }
const clearAllBtn = document.getElementById("clear-all-btn");
const generateBtn = document.getElementById("generate-btn"); initializeEventListeners();
const copyPasswordBtn = document.getElementById("copy-btn"); }
const copyOutputBtn = document.getElementById("copy-output-btn");
const toggleSwitch = document.getElementById("operation-toggle"); // ===== Event Listeners =====
const copyShareBtn = document.getElementById("copy-share-btn"); function initializeEventListeners() {
const shareLink = document.getElementById("share-link"); const elements = {
encryptionType: document.getElementById("encryption-type"),
if ( inputText: document.getElementById("input-text"),
encryptionTypeEl && inputTextEl && formEl && removeFileBtn && form: document.getElementById("crypto-form"),
clearAllBtn && generateBtn && copyPasswordBtn && toggleSwitch removeFileBtn: document.getElementById("remove-file-btn"),
) { clearAllBtn: document.getElementById("clear-all-btn"),
encryptionTypeEl.addEventListener("change", toggleEncryptionOptions); generateBtn: document.getElementById("generate-btn"),
inputTextEl.addEventListener("input", () => { copyPasswordBtn: document.getElementById("copy-btn"),
toggleInputMode(); copyOutputBtn: document.getElementById("copy-output-btn"),
checkForPacman(); toggleSwitch: document.getElementById("operation-toggle"),
}); copyShareBtn: document.getElementById("copy-share-btn"),
formEl.addEventListener("submit", handleSubmit); shareLink: document.getElementById("share-link")
removeFileBtn.addEventListener("click", removeFile); };
clearAllBtn.addEventListener("click", clearAll);
generateBtn.addEventListener("click", generateRandomPassword); if (validateElements(elements)) {
copyPasswordBtn.addEventListener("click", () => copyToClipboard("generated-password", "password-copy-feedback")); setupElementListeners(elements);
copyOutputBtn?.addEventListener("click", () => copyToClipboard("output-text", "output-copy-feedback")); }
toggleSwitch.addEventListener("change", updateToggleLabels); }
const copySharedLinkBtn = document.getElementById("copy-shared-link"); function validateElements(elements) {
const sharedLinkEl = document.getElementById("shared-link"); return elements.encryptionType && elements.inputText && elements.form &&
elements.removeFileBtn && elements.clearAllBtn && elements.generateBtn &&
if (copySharedLinkBtn && sharedLinkEl) { elements.copyPasswordBtn && elements.toggleSwitch;
copySharedLinkBtn.addEventListener("click", () => { }
navigator.clipboard.writeText(sharedLinkEl.textContent.trim()).then(() => {
const feedback = document.getElementById("shared-link-feedback"); function setupElementListeners(elements) {
if (feedback) { elements.encryptionType.addEventListener("change", toggleEncryptionOptions);
feedback.classList.remove("hidden"); elements.inputText.addEventListener("input", handleInputChange);
feedback.classList.add("show"); elements.form.addEventListener("submit", handleSubmit);
elements.removeFileBtn.addEventListener("click", removeFile);
setTimeout(() => { elements.clearAllBtn.addEventListener("click", clearAll);
feedback.classList.remove("show"); elements.generateBtn.addEventListener("click", generateRandomPassword);
feedback.classList.add("hidden"); elements.copyPasswordBtn.addEventListener("click", () => copyToClipboard("generated-password", "password-copy-feedback"));
}, 3000); elements.copyOutputBtn?.addEventListener("click", () => copyToClipboard("output-text", "output-copy-feedback"));
} elements.toggleSwitch.addEventListener("change", updateToggleLabels);
});
}); // Add file input change listener
const fileInput = document.getElementById("file-input");
sharedLinkEl.scrollIntoView({ behavior: "smooth" }); if (fileInput) {
} fileInput.addEventListener("change", () => {
} const removeBtn = document.getElementById("remove-file-btn");
} if (removeBtn) {
removeBtn.style.display = fileInput.files.length > 0 ? "inline-block" : "none";
}
});
}
function toggleEncryptionOptions() {
const type = document.getElementById("encryption-type").value.trim().toLowerCase(); setupShareLinkListeners(elements);
const passwordInputWrapper = document.getElementById("password-input"); }
const isAdvanced = type.includes("advanced");
function setupShareLinkListeners(elements) {
if (passwordInputWrapper) { if (elements.copyShareBtn && elements.shareLink) {
if (isAdvanced) { elements.copyShareBtn.addEventListener("click", () => {
passwordInputWrapper.classList.remove("hidden"); const linkText = elements.shareLink.textContent.trim();
} else { navigator.clipboard.writeText(linkText).then(() => {
passwordInputWrapper.classList.add("hidden"); const feedback = document.getElementById("shared-link-feedback");
} if (feedback) {
} feedback.style.display = "block";
feedback.classList.add("show");
updateToggleLabels(); setTimeout(() => {
toggleInputMode(); feedback.classList.remove("show");
} setTimeout(() => {
feedback.style.display = "none";
}, 300);
function updateToggleLabels() { }, 3000);
const type = document.getElementById("encryption-type")?.value; }
const leftLabel = document.getElementById("toggle-left-label"); });
const rightLabel = document.getElementById("toggle-right-label"); });
}
if (!type || !leftLabel || !rightLabel) return; }
const isAdvanced = type.toLowerCase().includes("advanced"); // ===== UI State Management =====
leftLabel.textContent = isAdvanced ? "Encrypt" : "Encode"; function toggleEncryptionOptions() {
rightLabel.textContent = isAdvanced ? "Decrypt" : "Decode"; const type = document.getElementById("encryption-type").value.trim().toLowerCase();
} const passwordInputWrapper = document.getElementById("password-input");
const fileSection = document.querySelector("#encoding-section #file-section");
function toggleInputMode() { const isAdvanced = type.includes("advanced");
const fileInput = document.getElementById("file-input");
const textValue = document.getElementById("input-text")?.value.trim(); if (passwordInputWrapper) {
const isAdvanced = document.getElementById("encryption-type")?.value === "advanced"; if (isAdvanced) {
passwordInputWrapper.classList.remove("hidden");
const textSection = document.getElementById("text-section"); } else {
const fileSection = document.getElementById("file-section"); passwordInputWrapper.classList.add("hidden");
const removeBtn = document.getElementById("remove-file-btn"); }
}
if (!fileInput || !textSection || !fileSection || !removeBtn) return;
if (fileSection) {
const fileSelected = fileInput.files.length > 0; if (isAdvanced) {
fileSection.classList.remove("hidden");
textSection.style.display = fileSelected ? "none" : "flex"; } else {
fileSection.style.display = (isAdvanced && !textValue) ? "flex" : "none"; fileSection.classList.add("hidden");
removeBtn.style.display = fileSelected ? "inline-block" : "none"; }
} }
async function handleSubmit(event) { updateToggleLabels();
event.preventDefault(); toggleInputMode();
}
const encryptionType = document.getElementById("encryption-type")?.value;
const password = document.getElementById("password")?.value; function updateToggleLabels() {
const fileInput = document.getElementById("file-input"); const type = document.getElementById("encryption-type")?.value;
const isDecrypt = document.getElementById("operation-toggle").checked; const leftLabel = document.getElementById("toggle-left-label");
const operation = isDecrypt ? "decrypt" : "encrypt"; const rightLabel = document.getElementById("toggle-right-label");
if (!encryptionType || !fileInput) return; if (!type || !leftLabel || !rightLabel) return;
if (encryptionType === "advanced" && !password) { const isAdvanced = type.toLowerCase().includes("advanced");
return alert("Password is required for advanced encryption."); leftLabel.textContent = isAdvanced ? "Encrypt" : "Encode";
} rightLabel.textContent = isAdvanced ? "Decrypt" : "Decode";
}
if (fileInput.files.length > 0) {
return (operation === "encrypt") function toggleInputMode() {
? encryptFile(fileInput, password) const fileInput = document.getElementById("file-input");
: decryptFile(fileInput, password); const textValue = document.getElementById("input-text")?.value.trim();
} const isAdvanced = document.getElementById("encryption-type")?.value === "advanced";
const payload = { const textSection = document.getElementById("text-section");
"encryption-type": encryptionType, const fileSection = document.getElementById("file-section");
operation: operation, const removeBtn = document.getElementById("remove-file-btn");
message: document.getElementById("input-text")?.value,
password: password if (!fileInput || !textSection || !fileSection || !removeBtn) return;
};
const fileSelected = fileInput.files.length > 0;
try {
const response = await fetch("/", { textSection.style.display = fileSelected ? "none" : "flex";
method: "POST", fileSection.style.display = (isAdvanced && !textValue) ? "flex" : "none";
headers: { "Content-Type": "application/json" }, removeBtn.style.display = fileSelected ? "inline-block" : "none";
body: JSON.stringify(payload) }
});
const data = await response.json(); // ===== Form Handling =====
document.getElementById("output-text").value = data.result; async function handleSubmit(event) {
} catch (err) { event.preventDefault();
alert("Error processing request: " + err.message);
} const encryptionType = document.getElementById("encryption-type")?.value;
} const password = document.getElementById("password")?.value;
const fileInput = document.getElementById("file-input");
function removeFile() { const isDecrypt = document.getElementById("operation-toggle").checked;
const fileInput = document.getElementById("file-input"); const operation = isDecrypt ? "decrypt" : "encrypt";
if (fileInput) fileInput.value = "";
const removeBtn = document.getElementById("remove-file-btn"); if (!encryptionType || !fileInput) return;
if (removeBtn) removeBtn.style.display = 'none';
toggleInputMode(); if (encryptionType === "advanced" && !password) {
} return alert("Password is required for advanced encryption.");
}
function generateRandomPassword() {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?/~"; if (fileInput.files.length > 0) {
const length = 30; return (operation === "encrypt")
const password = Array.from({ length }, () => ? encryptFile(fileInput, password)
charset.charAt(Math.floor(Math.random() * charset.length)) : decryptFile(fileInput, password);
).join(""); }
const passwordField = document.getElementById("generated-password");
if (passwordField) passwordField.value = password; await handleTextOperation(encryptionType, operation, password);
} }
function copyToClipboard(elementId, feedbackId) { async function handleTextOperation(encryptionType, operation, password) {
const el = document.getElementById(elementId); const payload = {
const feedback = document.getElementById(feedbackId); "encryption-type": encryptionType,
if (!el || !feedback) return; operation: operation,
message: document.getElementById("input-text")?.value,
navigator.clipboard.writeText(el.textContent || el.value || "").then(() => { password: password
feedback.classList.add("show"); };
setTimeout(() => {
feedback.classList.remove("show"); try {
}, 3000); const response = await fetch("/", {
}); method: "POST",
} headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
function clearAll() { });
const fields = ["input-text", "output-text", "file-input", "password"]; const data = await response.json();
fields.forEach(id => { document.getElementById("output-text").value = data.result;
const el = document.getElementById(id); } catch (err) {
if (el) el.value = ""; alert("Error processing request: " + err.message);
}); }
removeFile(); }
toggleInputMode();
document.getElementById("pacman-section")?.style.setProperty("display", "none"); // ===== Utility Functions =====
document.getElementById("encoding-section")?.style.setProperty("display", "block"); function removeFile() {
} const fileInput = document.getElementById("file-input");
if (fileInput) fileInput.value = "";
function checkForPacman() { const removeBtn = document.getElementById("remove-file-btn");
const val = document.getElementById("input-text").value.trim().toLowerCase(); if (removeBtn) removeBtn.style.display = 'none';
const pacSection = document.getElementById("pacman-section"); toggleInputMode();
const encSection = document.getElementById("encoding-section"); }
if (val.includes("pacman") && pacSection.style.display !== "block") { function generateRandomPassword() {
pacSection.style.display = "block"; const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?/~";
encSection.style.display = "none"; const length = 30;
window.startPacman(); const password = Array.from({ length }, () =>
} else if (pacSection.style.display === "block" && !val.includes("pacman")) { charset.charAt(Math.floor(Math.random() * charset.length))
window.exitGame(); ).join("");
} const passwordField = document.getElementById("generated-password");
} if (passwordField) {
passwordField.value = password;
// Check if we should start Pacman
function startPacman() { } checkForPacman();
function exitGame() { } }
}
function copyToClipboard(elementId, feedbackId) {
const el = document.getElementById(elementId);
const feedback = document.getElementById(feedbackId);
if (!el || !el.value) return;
// Create a temporary textarea element
const textarea = document.createElement('textarea');
textarea.value = el.value;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
// Select and copy the text
textarea.select();
textarea.setSelectionRange(0, 99999); // For mobile devices
try {
// Try using the modern clipboard API first
navigator.clipboard.writeText(el.value).then(() => {
showFeedback(feedback);
}).catch(() => {
// Fallback to execCommand for older browsers
document.execCommand('copy');
showFeedback(feedback);
});
} catch (err) {
// Final fallback
document.execCommand('copy');
showFeedback(feedback);
}
// Clean up
document.body.removeChild(textarea);
}
function showFeedback(feedback) {
if (feedback) {
feedback.style.display = "block";
feedback.classList.add("show");
setTimeout(() => {
feedback.classList.remove("show");
setTimeout(() => {
feedback.style.display = "none";
}, 300);
}, 3000);
}
}
function clearAll() {
const fields = ["input-text", "output-text", "file-input", "password"];
fields.forEach(id => {
const el = document.getElementById(id);
if (el) el.value = "";
});
removeFile();
toggleInputMode();
document.getElementById("pacman-section")?.style.setProperty("display", "none");
document.getElementById("encoding-section")?.style.setProperty("display", "block");
}
function handleInputChange() {
toggleInputMode();
checkForPacman();
}
function checkForPacman() {
const val = document.getElementById("input-text").value.trim().toLowerCase();
const pacSection = document.getElementById("pacman-section");
const encSection = document.getElementById("encoding-section");
if (val.includes("pacman") && pacSection.style.display !== "block") {
pacSection.style.display = "block";
encSection.style.display = "none";
window.startPacman();
} else if (pacSection.style.display === "block" && !val.includes("pacman")) {
window.exitGame();
}
}
function startPacman() { }
function exitGame() { }
+13 -7
View File
@@ -3,20 +3,27 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>403 - PacCrypt</title> <meta name="description" content="PacCrypt - 403 Forbidden Access" />
<title>403 Forbidden - PacCrypt</title>
<!-- Favicon -->
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" /> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt</h1> <h1>PacCrypt</h1>
<p>Secure Encoding, Encryption and Password Generation</p> <p>Encrypt and share your text or files securely</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<section class="card form-group" style="padding: 50px 30px;"> <section class="card form-group" style="padding: 50px 30px;">
<h2 style="color: #00ff99; font-size: 2.5em;">🚫 403 - Forbidden</h2> <h2 style="color: #00ff99; font-size: 2.5em;">🚫 403 - Forbidden</h2>
@@ -24,6 +31,7 @@
Looks like this area is locked behind a secret ghost door! 🛡️👻 Looks like this area is locked behind a secret ghost door! 🛡️👻
</p> </p>
<!-- Navigation -->
<div class="button-group mt-4"> <div class="button-group mt-4">
<a href="{{ url_for('index') }}"> <a href="{{ url_for('index') }}">
<button type="button">⬅️ Return Home</button> <button type="button">⬅️ Return Home</button>
@@ -36,10 +44,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+14 -8
View File
@@ -3,27 +3,35 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>404 - PacCrypt</title> <meta name="description" content="PacCrypt - 404 Page Not Found" />
<title>404 Not Found - PacCrypt</title>
<!-- Favicon -->
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" /> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt</h1> <h1>PacCrypt</h1>
<p>Secure Encoding, Encryption and Password Generation</p> <p>Encrypt and share your text or files securely</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<section class="card form-group" style="padding: 50px 30px;"> <section class="card form-group" style="padding: 50px 30px;">
<h2 style="color: #ff0066; font-size: 2.5em;">❓ 404 - Not Found</h2> <h2 style="color: #ff0066; font-size: 2.5em;">❓ 404 - Not Found</h2>
<p class="mt-4" style="font-size: 1.2em; color: #cccccc;"> <p class="mt-4" style="font-size: 1.2em; color: #cccccc;">
Whoops! That page doesnt seem to exist. Maybe it got encrypted? 🧩🔐 Whoops! That page doesn't seem to exist. Maybe it got encrypted? 🧩🔐
</p> </p>
<!-- Navigation -->
<div class="button-group mt-4"> <div class="button-group mt-4">
<a href="{{ url_for('index') }}"> <a href="{{ url_for('index') }}">
<button type="button">⬅️ Return Home</button> <button type="button">⬅️ Return Home</button>
@@ -36,10 +44,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+14 -8
View File
@@ -3,28 +3,36 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>500 - PacCrypt</title> <meta name="description" content="PacCrypt - 500 Internal Server Error" />
<title>500 Server Error - PacCrypt</title>
<!-- Favicon -->
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" /> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt</h1> <h1>PacCrypt</h1>
<p>Secure Encoding, Encryption and Password Generation</p> <p>Encrypt and share your text or files securely</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<section class="card form-group" style="padding: 50px 30px;"> <section class="card form-group" style="padding: 50px 30px;">
<h2 style="color: #ff3300; font-size: 2.5em;">💥 500 - Server Error</h2> <h2 style="color: #ff3300; font-size: 2.5em;">💥 500 - Server Error</h2>
<p class="mt-4" style="font-size: 1.2em; color: #cccccc;"> <p class="mt-4" style="font-size: 1.2em; color: #cccccc;">
Uh oh! The ghosts chomped the server wires. 🧟‍♂️👾 Uh oh! The ghosts chomped the server wires. 🧟‍♂️👾
Were working on patching it up. We're working on patching it up.
</p> </p>
<!-- Navigation -->
<div class="button-group mt-4"> <div class="button-group mt-4">
<a href="{{ url_for('index') }}"> <a href="{{ url_for('index') }}">
<button type="button">⬅️ Return Home</button> <button type="button">⬅️ Return Home</button>
@@ -37,10 +45,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+179 -77
View File
@@ -1,97 +1,93 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="PacCrypt - Admin Panel" />
<title>Admin Panel - PacCrypt</title> <title>Admin Panel - PacCrypt</title>
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <!-- Favicon -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt Admin Panel</h1> <h1>PacCrypt Admin Panel</h1>
<p>Site Overview & Controls</p> <p>Site Overview & Controls</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<!-- Site Map Section -->
<section id="sitemap-section" class="card form-group">
<h2>💾 Server Management</h2>
<div class="sitemap-header">
<button onclick="toggleSitemap()" style="margin-bottom: 10px;">Show Site Map</button>
</div>
<div id="sitemap-list" class="sitemap-content" style="display: none;">
<ul style="list-style: none; padding-left: 0;">
{% for route in routes %}
<li style="margin-bottom: 5px;">🔗 <code>{{ route }}</code></li>
{% endfor %}
</ul>
</div>
<!-- Site Map --> <!-- Action Buttons -->
<section class="card form-group"> <div class="button-group">
<h2>🔍 Site Map</h2> <button onclick="restartServer()">🔁 Restart Server</button>
<ul style="list-style: none; padding-left: 0;">
{% for route in routes %}
<li style="margin-bottom: 5px;">🔗 <code>{{ route }}</code></li>
{% endfor %}
</ul>
<div class="button-group mt-4">
<a href="{{ url_for('restart_server') }}">
<button type="button">🔁 Restart Server</button>
</a>
<a href="{{ url_for('admin_logout') }}"> <a href="{{ url_for('admin_logout') }}">
<button type="button">🚪 Log Out</button> <button type="button">🚪 Log Out</button>
</a> </a>
</div> </div>
<form action="{{ url_for('admin_reset') }}" method="POST" onsubmit="return confirm('Are you sure you want to reset admin credentials?');"> <!-- Update and Settings Buttons -->
<button type="submit" class="mt-4" style="background-color: #b90000;">⚠️ Reset Admin</button> <div class="button-group">
</form> <button onclick="updateServer()">🔁 Pull Latest Changes</button>
<a href="{{ url_for('admin_settings') }}">
<button type="button">🛠️ Manage Upload Settings</button>
</a>
</div>
<form action="{{ url_for('admin_clear_uploads') }}" method="POST" <!-- Admin Reset and Clear Uploads Buttons -->
onsubmit="return confirm('Are you sure you want to delete ALL uploaded files?');"> <div class="button-group">
<button type="submit">🗑 Clear All Uploaded Files</button> <button onclick="resetAdmin()" class="danger-button">⚠️ Reset Admin</button>
</form> <button onclick="clearUploads()" class="danger-button">🗑 Clear Uploaded Files</button>
</div>
{% with messages = get_flashed_messages(with_categories=true, category_filter=['clear-feedback']) %}
{% for category, message in messages %}
<div class="copy-feedback show">{{ message }}</div>
{% endfor %}
{% endwith %}
<!-- Flash Messages -->
<div id="admin-feedback" class="copy-feedback" style="display: none;"></div>
</section> </section>
<!-- Change Admin Password --> <!-- Password Change Section -->
<section class="card form-group mt-5"> <section id="password-change-section" class="card form-group">
<h2>🔑 Change Admin Password</h2> <h2>🔑 Change Admin Password</h2>
<!-- Password Feedback -->
{% with messages = get_flashed_messages(with_categories=true, category_filter=['password-feedback']) %} {% with messages = get_flashed_messages(with_categories=true, category_filter=['password-feedback']) %}
{% for category, message in messages %} {% for category, message in messages %}
<div class="copy-feedback show">{{ message }}</div> <div class="copy-feedback show">{{ message }}</div>
{% endfor %} {% endfor %}
{% endwith %} {% endwith %}
<!-- Password Change Form -->
<form method="POST" action="{{ url_for('admin_change_password') }}"> <form method="POST" action="{{ url_for('admin_change_password') }}">
<input type="password" name="current_password" placeholder="Current Password" required> <input type="password" name="current_password" placeholder="Current Password" required />
<input type="password" name="new_password" placeholder="New Password" required> <input type="password" name="new_password" placeholder="New Password" required />
<button type="submit">Update Password</button> <button type="submit">Update Password</button>
</form> </form>
</section> </section>
<!-- Update Server --> <!-- Server Status Section -->
<section class="card form-group mt-5"> <section id="server-status-section" class="card form-group">
<h2>📦 Update Server from GitHub</h2>
<form method="POST" action="{{ url_for('admin_update_server') }}">
<button type="submit" onclick="return confirm('Are you sure you want to pull the latest changes from GitHub?')">
🔁 Pull Latest Changes
</button>
</form>
{% with update_msgs = get_flashed_messages(category_filter=["update"]) %}
{% if update_msgs %}
<div class="copy-feedback show" style="margin-top: 12px;">
{{ update_msgs[0] | safe }}
</div>
{% endif %}
{% endwith %}
</section>
<!-- Server Status -->
<section class="card form-group mt-5">
<h2>📊 Server Status</h2> <h2>📊 Server Status</h2>
<ul style="list-style: none; padding-left: 0;"> <ul style="list-style: none; padding-left: 0;">
<li>🕒 Uptime: <code>{{ server_info.uptime }}</code></li> <li>🕒 Uptime: <code>{{ server_info.uptime }}</code></li>
@@ -101,35 +97,22 @@
</ul> </ul>
</section> </section>
<!-- Server Logs --> <!-- Server Logs Section -->
<section class="card form-group mt-5"> <section id="server-logs-section" class="card form-group">
<h2>📜 Server Logs</h2> <h2>📜 Server Logs</h2>
<button onclick="toggleLogs()" style="margin-bottom: 10px;">🔽 Show/Hide Logs</button> <button onclick="toggleLogs()" style="margin-bottom: 10px;">🔽 Show/Hide Logs</button>
<div id="logLoader" style="display: none; margin-bottom: 10px;">Loading logs...</div> <div id="logLoader" style="display: none; margin-bottom: 10px;">Loading logs...</div>
<pre id="logContainer" style="display: none; max-height: 400px; overflow-y: auto; background: black; color: lime; padding: 10px; border-radius: 8px;"></pre> <pre id="logContainer" style="display: none;"></pre>
</section> </section>
<!-- System Settings -->
<section class="card form-group mt-5">
<h2>🧩 System Configuration</h2>
<p>You can manage upload storage, limits, and expiration policies here:</p>
<a href="{{ url_for('admin_settings') }}">
<button type="button">🛠️ Manage Upload Settings</button>
</a>
</section>
</main>
<!-- Footer --> <!-- Footer -->
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
<a href="{{ url_for('sitemap') }}"> <a href="{{ url_for('sitemap') }}">
<img src="\static\img\sitemap.png" <img src="\static\img\sitemap.png" alt="Sitemap Png" width="55" />
alt="Sitemap Png" width="55" />
</a> </a>
</footer> </footer>
@@ -151,5 +134,124 @@
} }
</script> </script>
<script>
function toggleSitemap() {
const list = document.getElementById('sitemap-list');
const button = document.querySelector('.sitemap-header button');
if (list.style.display === 'none') {
list.style.display = 'block';
button.textContent = 'Hide Site Map';
} else {
list.style.display = 'none';
button.textContent = 'Show Site Map';
}
}
async function restartServer() {
if (!confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) return;
try {
const response = await fetch('{{ url_for("restart_server") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
showFeedback(data.message);
// Add a small delay before redirecting to allow the server to restart
setTimeout(() => {
window.location.reload();
}, 2000);
} else {
showFeedback(data.error || 'Failed to restart server.');
}
} catch (error) {
showFeedback('Failed to restart server.');
}
}
async function updateServer() {
if (!confirm('Are you sure you want to pull the latest changes from GitHub?')) return;
try {
const response = await fetch('{{ url_for("admin_update_server") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
showFeedback(data.message);
} else {
showFeedback(data.error || 'Failed to update server from GitHub.');
}
} catch (error) {
showFeedback('Failed to update server from GitHub.');
}
}
async function resetAdmin() {
if (!confirm('Are you sure you want to reset admin credentials?')) return;
try {
const response = await fetch('{{ url_for("admin_reset") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
showFeedback('Admin credentials reset. Please create new credentials.');
setTimeout(() => {
window.location.href = '{{ url_for("admin_setup") }}';
}, 2000);
}
} catch (error) {
showFeedback('Failed to reset admin credentials.');
}
}
async function clearUploads() {
if (!confirm('Are you sure you want to delete ALL uploaded files?')) return;
try {
const response = await fetch('{{ url_for("admin_clear_uploads") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
showFeedback('All uploaded files have been cleared.');
}
} catch (error) {
showFeedback('Failed to clear uploaded files.');
}
}
function showFeedback(message) {
const feedback = document.getElementById('admin-feedback');
feedback.textContent = message;
feedback.style.display = 'block';
feedback.classList.add('show');
setTimeout(() => {
feedback.classList.remove('show');
setTimeout(() => {
feedback.style.display = 'none';
}, 300);
}, 3000);
}
</script>
</body> </body>
</html> </html>
+24 -14
View File
@@ -1,34 +1,45 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Admin Login - PacCrypt</title> <meta name="description" content="PacCrypt - Admin Login" />
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}"> <title>Admin Login - PacCrypt</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"> <!-- Favicon -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt Admin</h1> <h1>PacCrypt Admin</h1>
<p>Administrator Login</p> <p>Administrator Login</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<!-- Login Form Section -->
<section class="card form-group"> <section class="card form-group">
<h2>🔑 Admin Login</h2> <h2>🔑 Admin Login</h2>
<!-- Flash Messages -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<p style="color: red;">{{ messages[0] }}</p> <p style="color: red;">{{ messages[0] }}</p>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<!-- Login Form -->
<form method="POST"> <form method="POST">
<input type="text" name="username" placeholder="Username" required> <input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required> <input type="password" name="password" placeholder="Password" required />
<div class="button-group mt-3"> <div class="button-group mt-3">
<button type="submit">🚪 Log In</button> <button type="submit">🚪 Log In</button>
</div> </div>
@@ -36,13 +47,12 @@
</section> </section>
</main> </main>
<!-- Footer -->
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+22 -14
View File
@@ -1,24 +1,32 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="PacCrypt - Admin Settings" />
<title>Admin Settings - PacCrypt</title> <title>Admin Settings - PacCrypt</title>
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <!-- Favicon -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt Admin Settings</h1> <h1>PacCrypt Admin Settings</h1>
<p>Manage upload configuration securely</p> <p>Manage upload configuration</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<!-- Settings Form Section -->
<section class="card form-group"> <section class="card form-group">
<h2>⚙️ Upload Settings</h2> <h2>⚙️ Upload Settings</h2>
<!-- Flash Messages -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<ul style="color: lime;"> <ul style="color: lime;">
@@ -29,16 +37,18 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<!-- Settings Form -->
<form method="POST"> <form method="POST">
<label for="upload_folder">Upload Folder Path:</label> <label for="upload_folder">Upload Folder Path:</label>
<input type="text" name="upload_folder" id="upload_folder" value="{{ settings.upload_folder }}" required> <input type="text" name="upload_folder" id="upload_folder" value="{{ settings.upload_folder }}" required />
<label for="max_file_age_days">Max File Age (Days):</label> <label for="max_file_age_days">Max File Age (Days):</label>
<input type="number" name="max_file_age_days" id="max_file_age_days" value="{{ settings.max_file_age_days }}" min="1" required> <input type="number" name="max_file_age_days" id="max_file_age_days" value="{{ settings.max_file_age_days }}" min="1" required />
<label for="max_file_size_gb">Max File Size (GB):</label> <label for="max_file_size_gb">Max File Size (GB):</label>
<input type="number" name="max_file_size_gb" id="max_file_size_gb" value="{{ settings.max_file_size_bytes // (1024 * 1024 * 1024) }}" step="0.1" min="0.1" required> <input type="number" name="max_file_size_gb" id="max_file_size_gb" value="{{ settings.max_file_size_bytes // (1024 * 1024 * 1024) }}" step="0.1" min="0.1" required />
<!-- Action Buttons -->
<div class="button-group mt-4"> <div class="button-group mt-4">
<button type="submit">💾 Save Settings</button> <button type="submit">💾 Save Settings</button>
<a href="{{ url_for('admin_page') }}"> <a href="{{ url_for('admin_page') }}">
@@ -53,10 +63,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+22 -13
View File
@@ -1,34 +1,45 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="PacCrypt - Admin Setup" />
<title>Admin Setup - PacCrypt</title> <title>Admin Setup - PacCrypt</title>
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <!-- Favicon -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"> <link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}" />
<!-- Stylesheets -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}"></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt Admin</h1> <h1>PacCrypt Admin</h1>
<p>Secure Admin Setup</p> <p>Admin Setup</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<!-- Setup Form Section -->
<section class="card form-group"> <section class="card form-group">
<h2>🛡️ Create Admin Account</h2> <h2>🛡️ Create Admin Account</h2>
<!-- Flash Messages -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<p style="color: red;">{{ messages[0] }}</p> <p style="color: red;">{{ messages[0] }}</p>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<!-- Setup Form -->
<form method="POST"> <form method="POST">
<input type="text" name="username" placeholder="Username" required> <input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required> <input type="password" name="password" placeholder="Password" required />
<div class="button-group mt-3"> <div class="button-group mt-3">
<button type="submit">📝 Set Credentials</button> <button type="submit">📝 Set Credentials</button>
</div> </div>
@@ -40,10 +51,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+95 -35
View File
@@ -3,31 +3,38 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PacCrypt</title> <meta name="description" content="PacCrypt - Secure text and file encryption with password generation" />
<title>PacCrypt - Encrypt and share your text or files securely</title>
<!-- Favicon -->
<link rel="icon" href="{{ url_for('static', filename='img/PacCrypt.png') }}" type="image/png" /> <link rel="icon" href="{{ url_for('static', filename='img/PacCrypt.png') }}" type="image/png" />
<!-- Stylesheets -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<!-- Scripts -->
<script type="module" src="{{ url_for('static', filename='js/main.js') }}" defer></script> <script type="module" src="{{ url_for('static', filename='js/main.js') }}" defer></script>
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt</h1> <h1>PacCrypt</h1>
<p>Encrypt and share your text or files securely</p> <p>Encrypt and share your text or files securely</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<!-- Password Generator Section -->
<!-- Password Generator --> <section id="password-generator-section" class="card form-group">
<section class="card form-group mt-5">
<h2>🔑 Password Generator</h2> <h2>🔑 Password Generator</h2>
<div class="form-group"> <div class="form-group">
<input type="text" id="generated-password" readonly /> <input type="text" id="generated-password" readonly />
<div class="button-group"> <div class="button-group">
<button type="button" id="generate-btn">🎲 Generate</button> <button type="button" id="generate-btn">🎲 Generate</button>
<button type="button" id="copy-btn">📋 Copy</button> <button type="button" id="copy-btn">📋 Copy Password</button>
</div> </div>
<div id="password-copy-feedback" class="copy-feedback">Copied to clipboard!</div> <div id="password-copy-feedback" class="copy-feedback">Password copied to clipboard!</div>
</div> </div>
</section> </section>
@@ -43,12 +50,11 @@
</div> </div>
</section> </section>
<!-- Encryption/Decryption Section -->
<!-- Encrypt & Decrypt Section --> <section id="encoding-section" class="card form-group">
<section class="card form-group" id="encoding-section">
<h2>🔐 Encrypt & Decrypt</h2> <h2>🔐 Encrypt & Decrypt</h2>
<form id="crypto-form" class="form-group"> <form id="crypto-form" class="form-group">
<!-- Encryption Type Selection -->
<div class="form-group"> <div class="form-group">
<label for="encryption-type">Encryption Type:</label> <label for="encryption-type">Encryption Type:</label>
<select id="encryption-type"> <select id="encryption-type">
@@ -57,6 +63,7 @@
</select> </select>
</div> </div>
<!-- Operation Toggle -->
<div class="toggle-container"> <div class="toggle-container">
<span id="toggle-left-label">Encrypt</span> <span id="toggle-left-label">Encrypt</span>
<label class="switch"> <label class="switch">
@@ -66,37 +73,44 @@
<span id="toggle-right-label">Decrypt</span> <span id="toggle-right-label">Decrypt</span>
</div> </div>
<!-- Text Input Section -->
<div id="text-section" class="form-group"> <div id="text-section" class="form-group">
<textarea id="input-text" placeholder="Enter your message..."></textarea> <textarea id="input-text" placeholder="Enter your message..."></textarea>
</div> </div>
<!-- Password Input -->
<div id="password-input" class="form-group"> <div id="password-input" class="form-group">
<input type="password" id="password" placeholder="Password (AES only)" /> <input type="password" id="password" placeholder="Encryption/Decryption Password" />
</div> </div>
<!-- File Input Section -->
<div id="file-section" class="form-group" style="display: none;"> <div id="file-section" class="form-group" style="display: none;">
<input type="file" id="file-input" /> <input type="file" id="file-input" />
<button type="button" id="remove-file-btn">🗑 Remove File</button> <button type="button" id="remove-file-btn">🗑 Remove File</button>
</div> </div>
<div class="button-group mt-3"> <!-- Action Buttons -->
<button type="submit">⚡ Execute</button>
<button type="button" id="clear-all-btn">🧹 Clear All</button>
</div>
<textarea id="output-text" readonly placeholder="Result will appear here..."></textarea>
<div class="button-group"> <div class="button-group">
<button type="submit">⚡ Execute</button>
<button type="button" id="copy-output-btn">📋 Copy Output</button> <button type="button" id="copy-output-btn">📋 Copy Output</button>
</div> </div>
<div id="output-copy-feedback" class="copy-feedback">Copied to clipboard!</div>
<!-- Output Section -->
<textarea id="output-text" readonly placeholder="Encrypted/Decrypted text will appear here..."></textarea>
<div class="button-group">
<button type="button" id="clear-all-btn" class="danger-button">🧹 Clear All</button>
</div>
<div id="output-copy-feedback" class="copy-feedback">Text copied to clipboard!</div>
</form> </form>
</section> </section>
<!-- PacCrypt Sharing --> <!-- File Sharing Section -->
<section class="card form-group mt-5"> <section id="sharing-section" class="card form-group">
<h2>📤 PacCrypt Sharing</h2> <h2>📤 PacCrypt Share</h2>
<p>Securely share a file with encryption and a pickup password.</p> <h3>Securely share encrypted files.</h3>
<p>Do not lose your passwords, data will be lost forever!</p>
<!-- Flash Messages -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<ul style="color: lime; list-style: none; padding-left: 0;"> <ul style="color: lime; list-style: none; padding-left: 0;">
@@ -104,10 +118,12 @@
<li> <li>
{{ message | safe }} {{ message | safe }}
{% if "pickup" in message %} {% if "pickup" in message %}
<br /> <div class="share-link-container">
<span id="shared-link">{{ message.split(" at ")[1] }}</span> <a id="share-link" href="{{ message.split(' at ')[1] }}" target="_blank">{{ message.split(" at ")[1] }}</a>
<button type="button" id="copy-shared-link">📋 Copy Link</button> <!--- <span id="share-link">{{ message.split(" at ")[1] }}</span> --->
<div id="shared-link-feedback" class="copy-feedback">Copied to clipboard!</div> <button type="button" id="copy-share-btn">📋 Copy Link</button>
<div id="shared-link-feedback" class="copy-feedback">Link copied to clipboard!</div>
</div>
{% endif %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}
@@ -116,31 +132,75 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<form method="POST" enctype="multipart/form-data" class="form-group"> <!-- File Upload Form -->
<!-- Share Link Container (initially hidden) -->
<div class="share-link-container" id="share-link-container" style="display: none;">
<a id="share-link" href="#" target="_blank"></a>
<button type="button" id="copy-share-btn">📋 Copy Link</button>
<div id="shared-link-feedback" class="copy-feedback">Link copied to clipboard!</div>
</div>
<form method="POST" enctype="multipart/form-data" class="form-group" id="upload-form">
<input type="file" name="file" id="upload-file" required /> <input type="file" name="file" id="upload-file" required />
<input type="password" name="enc_password" placeholder="Encryption Password" required /> <input type="password" name="enc_password" placeholder="Encryption/Decryption Password" required />
<input type="password" name="pickup_password" placeholder="Pickup Password" required /> <input type="password" name="pickup_password" placeholder="Pickup Password" required />
<div class="button-group mt-3"> <div class="button-group">
<button type="submit">🔒 Upload and Generate Link</button> <button type="submit">🔒 Upload and Generate Link</button>
</div> </div>
</form> </form>
<script>
document.getElementById('upload-form').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
try {
const response = await fetch('/', {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.error) {
alert(data.error);
return;
}
if (data.success && data.pickup_url) {
const shareLink = document.getElementById('share-link');
const shareLinkContainer = document.getElementById('share-link-container');
shareLink.href = data.pickup_url;
shareLink.textContent = data.pickup_url;
shareLinkContainer.style.display = 'flex';
// Clear form fields
document.getElementById('upload-file').value = '';
document.getElementsByName('enc_password')[0].value = '';
document.getElementsByName('pickup_password')[0].value = '';
// Scroll to the share link
shareLinkContainer.scrollIntoView({ behavior: 'smooth' });
}
} catch (error) {
alert('Error uploading file: ' + error.message);
}
});
</script>
<!-- File Limits Information -->
<p class="text-muted mt-3" style="font-size: 0.85em;"> <p class="text-muted mt-3" style="font-size: 0.85em;">
Files expire after {{ settings.max_file_age_days }} days.<br /> Files expire after {{ settings.max_file_age_days }} days.<br />
Max file size: {{ settings.max_file_size_bytes // (1024 * 1024 * 1024) }} GB. Max file size: {{ settings.max_file_size_bytes // (1024 * 1024 * 1024) }} GB.
</p> </p>
</section> </section>
</main> </main>
<!-- Footer --> <!-- Footer -->
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>
+60 -22
View File
@@ -1,27 +1,35 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pickup File - PacCrypt</title> <meta name="description" content="PacCrypt - Secure file pickup and decryption" />
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/PacCrypt.png') }}"> <title>PacCrypt - Secure File Pickup</title>
<!-- Favicon -->
<link rel="icon" href="{{ url_for('static', filename='img/PacCrypt.png') }}" type="image/png" />
<!-- Stylesheets -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head> </head>
<body class="dark"> <body class="dark">
<!-- Header -->
<header class="card mb-5"> <header class="card">
<h1>PacCrypt Pickup</h1> <h1>PacCrypt</h1>
<p>Enter passwords to retrieve your file securely</p> <p>Secure File Pickup and Decryption</p>
</header> </header>
<!-- Main Content -->
<main> <main>
<section class="card form-group"> <!-- File Pickup Section -->
<h2>🔐 Decrypt and Download</h2> <section id="pickup-section" class="card form-group">
<h2>🔐 File Pickup</h2>
<!-- Flash Messages -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<ul style="color: red;"> <ul style="color: lime; list-style: none; padding-left: 0;">
{% for message in messages %} {% for message in messages %}
<li>{{ message }}</li> <li>{{ message }}</li>
{% endfor %} {% endfor %}
@@ -29,17 +37,49 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<form method="POST"> <!-- File Info -->
<input type="password" name="pickup_password" placeholder="Pickup Password" required> <div class="form-group">
<input type="password" name="enc_password" placeholder="Encryption Password" required> <p style="color: #00ff99; margin-bottom: 15px;">File ID: <code>{{ file_id }}</code></p>
<div class="button-group mt-3"> </div>
<!-- Pickup Form -->
<form method="POST" class="form-group">
<div class="form-group">
<input type="password"
name="pickup_password"
placeholder="Pickup Password"
required
autocomplete="off" />
</div>
<div class="form-group">
<input type="password"
name="enc_password"
placeholder="Encryption Password"
required
autocomplete="off" />
</div>
<div class="button-group">
<button type="submit">📥 Decrypt and Download</button> <button type="submit">📥 Decrypt and Download</button>
</div> </div>
</form> </form>
</section> </section>
<section class="card form-group mt-5"> <!-- Security Notice Section -->
<p style="font-size: 0.9em; color: gray;">Link ID: <code>{{ file_id }}</code></p> <section id="security-notice-section" class="card form-group">
<h2>🛡️ Security Notice</h2>
<p style="color: #00ff99; text-align: center;">
Make sure you're on the correct domain before entering any passwords.<br>
Your file will be permanently deleted after download.
</p>
</section>
<!-- Link ID Section -->
<section id="link-id-section" class="card form-group">
<p style="color: #00ff99; text-align: center; font-family: monospace; font-size: 1.1em;">
Link ID: <code>{{ file_id }}</code>
</p>
</section> </section>
</main> </main>
@@ -47,10 +87,8 @@
<footer> <footer>
<p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p> <p>&copy; 2025 UnNaturalll-Dev. All rights reserved.</p>
<a href="https://github.com/TySP-Dev" target="_blank" id="github-link"> <a href="https://github.com/TySP-Dev" target="_blank" id="github-link">
<img src="\static\img\Github_logo.png" <img src="\static\img\Github_logo.png" alt="GitHub Logo" width="100" />
alt="GitHub Logo" width="100" />
</a> </a>
</footer> </footer>
</body> </body>
</html> </html>