initial commit

This commit is contained in:
wt
2026-03-14 05:32:29 +07:00
commit d3e5b28e72
15 changed files with 34273 additions and 0 deletions
+309
View File
@@ -0,0 +1,309 @@
// Bootloader Update Manager - Frontend JavaScript
document.addEventListener("DOMContentLoaded", function () {
// Elements
const uploadForm = document.getElementById("upload-form");
const fileInput = document.getElementById("file-input");
const fileName = document.getElementById("file-name");
const uploadType = document.getElementById("upload-type");
const progressContainer = document.getElementById("progress-container");
const progressFill = document.getElementById("progress-fill");
const progressPercent = document.getElementById("progress-percent");
const progressStatus = document.getElementById("progress-status");
const progressBytes = document.getElementById("progress-bytes");
const resultMessage = document.getElementById("result-message");
const mountStatus = document.getElementById("mount-status");
const extlinuxEditor = document.getElementById("extlinux-editor");
const editorStatus = document.getElementById("editor-status");
// Tab buttons
const tabBtns = document.querySelectorAll(".tab-btn");
// Initialize
checkMountStatus();
setInterval(checkMountStatus, 10000); // Check every 10 seconds
// Tab switching
tabBtns.forEach((btn) => {
btn.addEventListener("click", function () {
tabBtns.forEach((b) => b.classList.remove("active"));
this.classList.add("active");
uploadType.value = this.dataset.type;
hideResult();
});
});
// File input change
fileInput.addEventListener("change", function () {
if (this.files && this.files[0]) {
fileName.textContent = this.files[0].name;
} else {
fileName.textContent = "";
}
});
// Drag and drop
const fileLabel = document.querySelector(".file-label");
["dragenter", "dragover", "dragleave", "drop"].forEach((eventName) => {
fileLabel.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
["dragenter", "dragover"].forEach((eventName) => {
fileLabel.addEventListener(eventName, () => {
fileLabel.style.borderColor = "#00d9ff";
fileLabel.style.background = "rgba(0,217,255,0.1)";
});
});
["dragleave", "drop"].forEach((eventName) => {
fileLabel.addEventListener(eventName, () => {
fileLabel.style.borderColor = "";
fileLabel.style.background = "";
});
});
fileLabel.addEventListener("drop", (e) => {
const dt = e.dataTransfer;
const files = dt.files;
if (files && files[0]) {
fileInput.files = files;
fileName.textContent = files[0].name;
}
});
// Form submission
uploadForm.addEventListener("submit", async function (e) {
e.preventDefault();
const formData = new FormData(this);
const file = fileInput.files[0];
if (!file) {
showResult("Please select a file", "error");
return;
}
// Check file size (200MB limit)
const MAX_SIZE = 200 * 1024 * 1024;
if (file.size > MAX_SIZE) {
showResult("File too large. Maximum size is 200MB", "error");
return;
}
// Reset progress
progressContainer.style.display = "block";
progressFill.style.width = "0%";
progressPercent.textContent = "0%";
progressStatus.textContent = "Uploading...";
progressBytes.textContent = "";
hideResult();
try {
const xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function (e) {
if (e.lengthComputable) {
const percent = Math.round((e.loaded / e.total) * 100);
progressFill.style.width = percent + "%";
progressPercent.textContent = percent + "%";
progressBytes.textContent =
formatBytes(e.loaded) + " / " + formatBytes(e.total);
}
});
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
progressStatus.textContent = "Complete!";
showResult(
`Successfully uploaded ${response.filename} (${formatBytes(response.size)})`,
"success",
);
} else {
let errorMsg = "Upload failed";
try {
const err = JSON.parse(xhr.responseText);
errorMsg = err.error || errorMsg;
} catch (e) {}
progressStatus.textContent = "Failed";
showResult(errorMsg, "error");
}
});
xhr.addEventListener("error", function () {
progressStatus.textContent = "Failed";
showResult("Network error", "error");
});
xhr.open("POST", "/api/upload");
xhr.send(formData);
} catch (error) {
progressStatus.textContent = "Failed";
showResult("Error: " + error.message, "error");
}
});
// extlinux.conf buttons
document
.getElementById("load-extlinux")
.addEventListener("click", loadExtlinux);
document
.getElementById("save-extlinux")
.addEventListener("click", saveExtlinux);
document
.getElementById("clear-extlinux")
.addEventListener("click", function () {
extlinuxEditor.value = "";
showEditorStatus("Editor cleared", "success");
});
// Check mount status
async function checkMountStatus() {
try {
const response = await fetch("/api/mount");
const data = await response.json();
const indicator = mountStatus.querySelector(".status-indicator");
const text = mountStatus.querySelector(".status-text");
if (data.mounted) {
indicator.className = "status-indicator mounted";
text.textContent = "Mounted";
} else {
indicator.className = "status-indicator not-mounted";
text.textContent = "Not Mounted";
}
} catch (error) {
const indicator = mountStatus.querySelector(".status-indicator");
const text = mountStatus.querySelector(".status-text");
indicator.className = "status-indicator";
text.textContent = "Error checking status";
}
}
// Load extlinux.conf
async function loadExtlinux() {
showEditorStatus("Loading...", "");
try {
const response = await fetch("/api/extlinux");
const data = await response.json();
if (data.status === "success") {
extlinuxEditor.value = data.content;
showEditorStatus(`Loaded ${data.size} bytes`, "success");
} else {
showEditorStatus(data.error || "Failed to load", "error");
}
} catch (error) {
showEditorStatus("Error: " + error.message, "error");
}
}
// Save extlinux.conf
async function saveExtlinux() {
const content = extlinuxEditor.value;
if (!content.trim()) {
showEditorStatus("Cannot save empty file", "error");
return;
}
showEditorStatus("Saving...", "");
try {
const response = await fetch("/api/extlinux", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: content }),
});
const data = await response.json();
if (data.status === "success") {
showEditorStatus("Successfully saved extlinux.conf", "success");
} else {
showEditorStatus(data.error || "Failed to save", "error");
}
} catch (error) {
showEditorStatus("Error: " + error.message, "error");
}
}
// Reboot button
const rebootBtn = document.getElementById("reboot-btn");
const rebootMessage = document.getElementById("reboot-message");
if (rebootBtn) {
rebootBtn.addEventListener("click", async function () {
// Confirm reboot
if (!confirm("Are you sure you want to reboot the system?")) {
return;
}
rebootBtn.disabled = true;
rebootMessage.className = "reboot-message";
rebootMessage.style.display = "none";
try {
const response = await fetch("/api/reboot", { method: "POST" });
const data = await response.json();
if (data.status === "success") {
rebootMessage.textContent =
"System rebooting... Connection will be lost.";
rebootMessage.className = "reboot-message success";
rebootMessage.style.display = "block";
// Wait a bit then show reconnection message
setTimeout(() => {
rebootMessage.textContent =
"Waiting for device to come back online...";
}, 5000);
} else {
rebootMessage.textContent = data.error || "Reboot failed";
rebootMessage.className = "reboot-message error";
rebootMessage.style.display = "block";
rebootBtn.disabled = false;
}
} catch (error) {
rebootMessage.textContent = "Error: " + error.message;
rebootMessage.className = "reboot-message error";
rebootMessage.style.display = "block";
rebootBtn.disabled = false;
}
});
}
// Helper functions
function showResult(message, type) {
resultMessage.textContent = message;
resultMessage.className = "result-message " + type;
}
function hideResult() {
resultMessage.className = "result-message";
resultMessage.style.display = "none";
}
function showEditorStatus(message, type) {
editorStatus.textContent = message;
editorStatus.className = "editor-status " + type;
}
function formatBytes(bytes) {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
}
});
+144
View File
@@ -0,0 +1,144 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bootloader Update Manager</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<header>
<h1>🚀 Bootloader Update Manager</h1>
<p>
Orange Pi Zero 2W - Kernel, Device-Tree & U-Boot Environment
</p>
</header>
<section class="status-section">
<h2>System Status</h2>
<div class="status-card">
<div class="status-item">
<span class="label">Mount Point:</span>
<span class="value">/media</span>
</div>
<div class="status-item">
<span class="label">Device:</span>
<span class="value">/dev/mmcblk1p1</span>
</div>
<div class="status-item">
<span class="label">Mount Status:</span>
<span class="value" id="mount-status">
<span class="status-indicator"></span>
<span class="status-text">Checking...</span>
</span>
</div>
</div>
</section>
<section class="upload-section">
<h2>File Upload</h2>
<div class="upload-tabs">
<button class="tab-btn active" data-type="kernel">
Kernel (Image.gz)
</button>
<button class="tab-btn" data-type="dtb">
Device-Tree (DTB)
</button>
<button class="tab-btn" data-type="uboot">
U-Boot Environment
</button>
</div>
<div class="upload-area">
<form id="upload-form" enctype="multipart/form-data">
<input
type="hidden"
name="type"
id="upload-type"
value="kernel"
/>
<div class="file-input-wrapper">
<input
type="file"
name="file"
id="file-input"
accept=".gz,.dtb,.env,.bin"
/>
<label for="file-input" class="file-label">
<span class="file-icon">📁</span>
<span class="file-text"
>Drop file here or click to browse</span
>
<span class="file-name" id="file-name"></span>
</label>
</div>
<button type="submit" class="upload-btn">Upload</button>
</form>
<div
class="progress-container"
id="progress-container"
style="display: none"
>
<div class="progress-header">
<span>Upload Progress</span>
<span id="progress-percent">0%</span>
</div>
<div class="progress-bar">
<div class="progress-fill" id="progress-fill"></div>
</div>
<div class="progress-info">
<span id="progress-status">Waiting...</span>
<span id="progress-bytes"></span>
</div>
</div>
<div class="result-message" id="result-message"></div>
</div>
</section>
<section class="extlinux-section">
<h2>extlinux.conf Editor</h2>
<div class="editor-container">
<div class="editor-toolbar">
<button id="load-extlinux" class="toolbar-btn">
📥 Load
</button>
<button id="save-extlinux" class="toolbar-btn">
💾 Save
</button>
<button id="clear-extlinux" class="toolbar-btn">
🗑️ Clear
</button>
</div>
<textarea
id="extlinux-editor"
placeholder="Load extlinux.conf to edit..."
spellcheck="false"
></textarea>
<div class="editor-status" id="editor-status"></div>
</div>
</section>
<section class="reboot-section">
<h2>System Control</h2>
<div class="reboot-container">
<p class="reboot-warning">
⚠️ Warning: This will reboot the device immediately
</p>
<button id="reboot-btn" class="reboot-btn">
🔄 Reboot System
</button>
<div class="reboot-message" id="reboot-message"></div>
</div>
</section>
<footer>
<p>Bootloader Update Manager &copy; 2026</p>
</footer>
</div>
<script src="app.js"></script>
</body>
</html>
+432
View File
@@ -0,0 +1,432 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
color: #e4e4e4;
}
.container {
max-width: 900px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
padding: 30px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
margin-bottom: 30px;
}
header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
background: linear-gradient(90deg, #00d9ff, #00ff88);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
header p {
color: #888;
font-size: 1.1rem;
}
section {
background: rgba(255, 255, 255, 0.05);
border-radius: 12px;
padding: 25px;
margin-bottom: 25px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
h2 {
font-size: 1.5rem;
margin-bottom: 20px;
color: #00d9ff;
}
/* Status Section */
.status-card {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
}
.status-item {
background: rgba(0, 0, 0, 0.2);
padding: 15px;
border-radius: 8px;
}
.status-item .label {
display: block;
color: #888;
font-size: 0.85rem;
margin-bottom: 5px;
}
.status-item .value {
font-size: 1.1rem;
font-weight: 600;
}
.status-indicator {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background: #888;
margin-right: 8px;
}
.status-indicator.mounted {
background: #00ff88;
box-shadow: 0 0 10px #00ff88;
}
.status-indicator.not-mounted {
background: #ff4757;
box-shadow: 0 0 10px #ff4757;
}
/* Upload Section */
.upload-tabs {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.tab-btn {
flex: 1;
padding: 12px 20px;
border: none;
background: rgba(255, 255, 255, 0.1);
color: #e4e4e4;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
transition: all 0.3s ease;
}
.tab-btn:hover {
background: rgba(255, 255, 255, 0.2);
}
.tab-btn.active {
background: linear-gradient(90deg, #00d9ff, #00ff88);
color: #1a1a2e;
font-weight: 600;
}
.upload-area {
text-align: center;
}
.file-input-wrapper {
margin-bottom: 20px;
}
#file-input {
display: none;
}
.file-label {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 50px;
border: 2px dashed rgba(255, 255, 255, 0.3);
border-radius: 12px;
cursor: pointer;
transition: all 0.3s ease;
}
.file-label:hover {
border-color: #00d9ff;
background: rgba(0, 217, 255, 0.05);
}
.file-icon {
font-size: 3rem;
margin-bottom: 10px;
}
.file-text {
color: #888;
margin-bottom: 10px;
}
.file-name {
color: #00ff88;
font-weight: 600;
}
.upload-btn {
padding: 15px 40px;
font-size: 1.1rem;
border: none;
border-radius: 8px;
background: linear-gradient(90deg, #00d9ff, #00ff88);
color: #1a1a2e;
font-weight: 600;
cursor: pointer;
transition:
transform 0.2s ease,
box-shadow 0.2s ease;
}
.upload-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(0, 217, 255, 0.4);
}
.upload-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* Progress Bar */
.progress-container {
margin-top: 20px;
padding: 20px;
background: rgba(0, 0, 0, 0.2);
border-radius: 8px;
}
.progress-header {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.progress-bar {
height: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
overflow: hidden;
}
.progress-fill {
height: 100%;
width: 0%;
background: linear-gradient(90deg, #00d9ff, #00ff88);
transition: width 0.3s ease;
border-radius: 10px;
}
.progress-info {
display: flex;
justify-content: space-between;
margin-top: 10px;
font-size: 0.9rem;
color: #888;
}
.result-message {
margin-top: 15px;
padding: 15px;
border-radius: 8px;
display: none;
}
.result-message.success {
display: block;
background: rgba(0, 255, 136, 0.2);
border: 1px solid #00ff88;
color: #00ff88;
}
.result-message.error {
display: block;
background: rgba(255, 71, 87, 0.2);
border: 1px solid #ff4757;
color: #ff4757;
}
/* Editor Section */
.editor-container {
display: flex;
flex-direction: column;
}
.editor-toolbar {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.toolbar-btn {
padding: 10px 20px;
border: none;
border-radius: 6px;
background: rgba(255, 255, 255, 0.1);
color: #e4e4e4;
cursor: pointer;
font-size: 0.95rem;
transition: all 0.2s ease;
}
.toolbar-btn:hover {
background: rgba(255, 255, 255, 0.2);
}
#save-extlinux:hover {
background: #00ff88;
color: #1a1a2e;
}
#clear-extlinux:hover {
background: #ff4757;
color: white;
}
#extlinux-editor {
width: 100%;
min-height: 300px;
padding: 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
background: rgba(0, 0, 0, 0.3);
color: #e4e4e4;
font-family: "Monaco", "Menlo", monospace;
font-size: 0.9rem;
line-height: 1.5;
resize: vertical;
}
#extlinux-editor:focus {
outline: none;
border-color: #00d9ff;
}
.editor-status {
margin-top: 10px;
padding: 10px;
border-radius: 6px;
font-size: 0.9rem;
}
.editor-status.success {
background: rgba(0, 255, 136, 0.2);
color: #00ff88;
}
.editor-status.error {
background: rgba(255, 71, 87, 0.2);
color: #ff4757;
}
/* Footer */
footer {
text-align: center;
padding: 20px;
color: #666;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
/* Reboot Section */
.reboot-section {
border: 1px solid rgba(255, 71, 87, 0.3);
}
.reboot-section h2 {
color: #ff4757;
}
.reboot-container {
text-align: center;
}
.reboot-warning {
color: #ff4757;
font-weight: 600;
margin-bottom: 20px;
padding: 15px;
background: rgba(255, 71, 87, 0.1);
border-radius: 8px;
}
.reboot-btn {
padding: 15px 40px;
font-size: 1.1rem;
border: none;
border-radius: 8px;
background: linear-gradient(90deg, #ff4757, #ff6b7a);
color: white;
font-weight: 600;
cursor: pointer;
transition:
transform 0.2s ease,
box-shadow 0.2s ease;
}
.reboot-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(255, 71, 87, 0.4);
}
.reboot-btn:active {
transform: translateY(0);
}
.reboot-message {
margin-top: 15px;
padding: 15px;
border-radius: 8px;
display: none;
}
.reboot-message.success {
display: block;
background: rgba(0, 255, 136, 0.2);
border: 1px solid #00ff88;
color: #00ff88;
}
.reboot-message.error {
display: block;
background: rgba(255, 71, 87, 0.2);
border: 1px solid #ff4757;
color: #ff4757;
}
/* Animations */
@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.loading {
animation: pulse 1.5s infinite;
}
/* Responsive */
@media (max-width: 600px) {
header h1 {
font-size: 1.8rem;
}
.upload-tabs {
flex-direction: column;
}
.status-card {
grid-template-columns: 1fr;
}
}