boot-editor.ejs 4.39 KB
<!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>