boot-editor.ejs
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="id">
<head><%- include('partials/head') %></head>
<body class="app-page">
<%- include('partials/nav') %>
<main class="main-content">
<div class="page-header">
<div>
<h1 class="page-title">BOOT EDITOR</h1>
<p class="page-sub">Edit konfigurasi boot.ipxe — <code class="path-inline"><%= bootFile %></code></p>
</div>
<div class="editor-badges">
<% if (fileExists) { %>
<span class="badge badge-ok">FILE DITEMUKAN</span>
<% } else { %>
<span class="badge badge-warn">FILE BARU</span>
<% } %>
</div>
</div>
<%- include('partials/flash') %>
<form action="/files/boot-editor/save" method="POST" id="editor-form">
<div class="editor-toolbar">
<div class="toolbar-left">
<span class="toolbar-label">boot.ipxe</span>
<span class="char-count" id="char-count">0 karakter</span>
</div>
<div class="toolbar-right">
<button type="button" class="btn-tool" onclick="insertTemplate()">
⊞ Template Dasar
</button>
<button type="button" class="btn-tool" onclick="formatEditor()">
✦ Format
</button>
<button type="submit" class="btn-save">
💾 SIMPAN FILE
</button>
</div>
</div>
<div class="editor-wrapper">
<div class="line-numbers" id="line-numbers"></div>
<textarea
name="content"
id="editor"
class="code-editor"
spellcheck="false"
autocomplete="off"
autocorrect="off"
><%= content %></textarea>
</div>
</form>
<div class="editor-info">
<div class="info-item">
<span class="info-label">FORMAT:</span>
<span class="info-val">GRUB UEFI Config</span>
</div>
<div class="info-item">
<span class="info-label">ENCODING:</span>
<span class="info-val">UTF-8</span>
</div>
<div class="info-item">
<span class="info-label">BACKUP:</span>
<span class="info-val">Otomatis (boot.ipxe.bak)</span>
</div>
</div>
</main>
<%- include('partials/footer') %>
<script>
const editor = document.getElementById('editor');
const lineNumbers = document.getElementById('line-numbers');
const charCount = document.getElementById('char-count');
function updateLineNumbers() {
const lines = editor.value.split('\n').length;
lineNumbers.innerHTML = Array.from({length: lines}, (_, i) =>
`<span>${i + 1}</span>`).join('');
charCount.textContent = editor.value.length + ' karakter';
}
editor.addEventListener('input', updateLineNumbers);
editor.addEventListener('scroll', () => {
lineNumbers.scrollTop = editor.scrollTop;
});
// Tab support
editor.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
e.preventDefault();
const start = editor.selectionStart;
const end = editor.selectionEnd;
editor.value = editor.value.substring(0, start) + ' ' + editor.value.substring(end);
editor.selectionStart = editor.selectionEnd = start + 2;
updateLineNumbers();
}
// Ctrl+S save
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
document.getElementById('editor-form').submit();
}
});
function insertTemplate() {
if (editor.value.trim() && !confirm('Timpa konten dengan template dasar?')) return;
editor.value = `# GRUB UEFI Boot Configuration
# PXE Server - Lab Komputer
set default=0
set timeout=10
set timeout_style=menu
# Debian 12 Live
menuentry "Debian 12 Live (PXE)" {
linuxefi /debian12/live/vmlinuz boot=live netboot=nfs nfsroot=SERVER_IP:/var/www/html/debian12 ip=dhcp quiet splash
initrdefi /debian12/live/initrd.img
}
menuentry "Debian 12 Live (Debug Mode)" {
linuxefi /debian12/live/vmlinuz boot=live netboot=nfs nfsroot=SERVER_IP:/var/www/html/debian12 ip=dhcp
initrdefi /debian12/live/initrd.img
}
menuentry "Reboot" {
reboot
}
menuentry "Shutdown" {
halt
}`;
updateLineNumbers();
}
function formatEditor() {
// Hapus trailing whitespace & normalize newlines
editor.value = editor.value
.split('\n')
.map(l => l.trimEnd())
.join('\n')
.replace(/\n{3,}/g, '\n\n');
updateLineNumbers();
}
updateLineNumbers();
</script>
</body>
</html>