- Created yaml-validator.js with pure validation functions - Removed redundant checkYAMLFormatting function (rely on js-yaml) - Fixed function shadowing issues by using window._validateYAMLPure - Updated nginx config to serve JS files with correct MIME type - Improved error reporting with line/column numbers from js-yaml
1134 lines
44 KiB
HTML
1134 lines
44 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Stronghold - Minecraft Server Generator</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
|
|
<script src="yaml-validator.js"></script>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
padding: 40px;
|
|
}
|
|
|
|
h1 {
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
font-size: 2.5em;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #666;
|
|
margin-bottom: 30px;
|
|
font-size: 1.1em;
|
|
}
|
|
|
|
.tabs {
|
|
display: flex;
|
|
border-bottom: 2px solid #e0e0e0;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.tab {
|
|
padding: 12px 24px;
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-size: 1em;
|
|
font-weight: 500;
|
|
color: #666;
|
|
border-bottom: 3px solid transparent;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.tab:hover {
|
|
color: #667eea;
|
|
}
|
|
|
|
.tab.active {
|
|
color: #667eea;
|
|
border-bottom-color: #667eea;
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
|
|
.form-section {
|
|
margin-bottom: 25px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #333;
|
|
font-weight: 500;
|
|
font-size: 0.95em;
|
|
}
|
|
|
|
input, select, textarea {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
transition: border-color 0.3s;
|
|
font-family: inherit;
|
|
}
|
|
|
|
input:focus, select:focus, textarea:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
textarea {
|
|
resize: vertical;
|
|
min-height: 80px;
|
|
}
|
|
|
|
.form-row {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 15px;
|
|
}
|
|
|
|
.form-row-3 {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
gap: 15px;
|
|
}
|
|
|
|
input[type="checkbox"] {
|
|
width: auto;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.checkbox-label {
|
|
display: flex;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.generate-btn {
|
|
width: 100%;
|
|
padding: 15px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1.1em;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.generate-btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.generate-btn:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.preview {
|
|
margin-top: 30px;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 6px;
|
|
border: 2px solid #e0e0e0;
|
|
}
|
|
|
|
.preview h3 {
|
|
margin-bottom: 15px;
|
|
color: #333;
|
|
}
|
|
|
|
pre {
|
|
background: #2d2d2d;
|
|
color: #f8f8f2;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
overflow-x: auto;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.85em;
|
|
line-height: 1.5;
|
|
max-height: 500px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.download-btn {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background: #28a745;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
margin-top: 15px;
|
|
transition: background 0.3s;
|
|
}
|
|
|
|
.download-btn:hover {
|
|
background: #218838;
|
|
}
|
|
|
|
.download-btn:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.info-text {
|
|
font-size: 0.85em;
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 1.2em;
|
|
font-weight: 600;
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
margin-top: 20px;
|
|
padding-bottom: 8px;
|
|
border-bottom: 2px solid #e0e0e0;
|
|
}
|
|
|
|
.modpack-type-section {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.modpack-input {
|
|
display: none;
|
|
}
|
|
|
|
.modpack-input.active {
|
|
display: block;
|
|
}
|
|
|
|
.yaml-editor {
|
|
width: 100%;
|
|
min-height: 300px;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 6px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.9em;
|
|
line-height: 1.5;
|
|
resize: vertical;
|
|
}
|
|
|
|
.yaml-editor:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.yaml-editor.error {
|
|
border-color: #dc3545;
|
|
background-color: #fff5f5;
|
|
}
|
|
|
|
.yaml-editor.valid {
|
|
border-color: #28a745;
|
|
}
|
|
|
|
.yaml-error {
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
background-color: #f8d7da;
|
|
border: 1px solid #f5c6cb;
|
|
border-radius: 6px;
|
|
color: #721c24;
|
|
font-size: 0.9em;
|
|
display: none;
|
|
}
|
|
|
|
.yaml-error.show {
|
|
display: block;
|
|
}
|
|
|
|
.yaml-success {
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
background-color: #d4edda;
|
|
border: 1px solid #c3e6cb;
|
|
border-radius: 6px;
|
|
color: #155724;
|
|
font-size: 0.9em;
|
|
display: none;
|
|
}
|
|
|
|
.yaml-success.show {
|
|
display: block;
|
|
}
|
|
|
|
.yaml-actions {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.yaml-tab {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e0e0e0;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.yaml-tab-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.yaml-status {
|
|
font-size: 0.85em;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.yaml-status.valid {
|
|
color: #28a745;
|
|
}
|
|
|
|
.yaml-status.invalid {
|
|
color: #dc3545;
|
|
}
|
|
|
|
.btn-sm {
|
|
padding: 8px 16px;
|
|
font-size: 0.9em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🛡️ Stronghold</h1>
|
|
<p class="subtitle">Minecraft Server Docker Compose Generator</p>
|
|
|
|
<div class="tabs">
|
|
<button class="tab active" data-tab="basic">Basic Configuration</button>
|
|
<button class="tab" data-tab="modpack">Modpack</button>
|
|
<button class="tab" data-tab="advanced">Advanced</button>
|
|
</div>
|
|
|
|
<form id="serverForm">
|
|
<!-- Basic Configuration Tab -->
|
|
<div class="tab-content active" id="basic-tab">
|
|
<div class="form-section">
|
|
<label for="serverName">Server Name</label>
|
|
<input type="text" id="serverName" placeholder="my-minecraft-server" value="minecraft">
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="serverType">Server Type</label>
|
|
<select id="serverType">
|
|
<option value="VANILLA">Vanilla</option>
|
|
<option value="PAPER" selected>Paper (Recommended)</option>
|
|
<option value="FORGE">Forge (Modded)</option>
|
|
<option value="FABRIC">Fabric (Modded)</option>
|
|
<option value="SPIGOT">Spigot</option>
|
|
<option value="BUKKIT">Bukkit</option>
|
|
<option value="MAGMA">Magma (Mods + Plugins)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="version">Minecraft Version</label>
|
|
<input type="text" id="version" placeholder="LATEST or 1.20.1" value="LATEST">
|
|
<span class="info-text">Use LATEST for newest version, or specify version like 1.20.1</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="memory">Memory Allocation</label>
|
|
<select id="memory">
|
|
<option value="1G">1GB (Small)</option>
|
|
<option value="2G" selected>2GB (Recommended for most)</option>
|
|
<option value="4G">4GB (Medium)</option>
|
|
<option value="8G">8GB (Large/Modded)</option>
|
|
<option value="16G">16GB (Very Large)</option>
|
|
<option value="custom">Custom</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-section" id="customMemorySection" style="display: none;">
|
|
<label for="customMemory">Custom Memory</label>
|
|
<input type="text" id="customMemory" placeholder="32G">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="port">Server Port</label>
|
|
<input type="number" id="port" value="25565" min="1024" max="65535">
|
|
<span class="info-text">Default Minecraft port is 25565</span>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="difficulty">Difficulty</label>
|
|
<select id="difficulty">
|
|
<option value="">Default</option>
|
|
<option value="peaceful">Peaceful</option>
|
|
<option value="easy" selected>Easy</option>
|
|
<option value="normal">Normal</option>
|
|
<option value="hard">Hard</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="gamemode">Default Game Mode</label>
|
|
<select id="gamemode">
|
|
<option value="">Default</option>
|
|
<option value="survival" selected>Survival</option>
|
|
<option value="creative">Creative</option>
|
|
<option value="adventure">Adventure</option>
|
|
<option value="spectator">Spectator</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="levelType">World Type</label>
|
|
<select id="levelType">
|
|
<option value="">Default</option>
|
|
<option value="DEFAULT">Default</option>
|
|
<option value="FLAT">Flat</option>
|
|
<option value="LARGEBIOMES">Large Biomes</option>
|
|
<option value="AMPLIFIED">Amplified</option>
|
|
<option value="CUSTOMIZED">Customized</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="motd">Server MOTD (Message of the Day)</label>
|
|
<input type="text" id="motd" placeholder="A Minecraft Server" maxlength="59">
|
|
<span class="info-text">Message shown in server list (max 59 characters)</span>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="maxPlayers">Max Players</label>
|
|
<input type="number" id="maxPlayers" value="20" min="1" max="999">
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="viewDistance">View Distance (chunks)</label>
|
|
<input type="number" id="viewDistance" value="10" min="3" max="32">
|
|
<span class="info-text">Higher = better visibility but more CPU usage</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="acceptEULA" checked>
|
|
Accept Minecraft EULA
|
|
</label>
|
|
<span class="info-text">Required to run a Minecraft server</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modpack Tab -->
|
|
<div class="tab-content" id="modpack-tab">
|
|
<div class="section-title">Modpack Installation</div>
|
|
|
|
<div class="form-section">
|
|
<label for="modpackType">Modpack Source</label>
|
|
<select id="modpackType">
|
|
<option value="none">No Modpack (Vanilla/Plugins only)</option>
|
|
<option value="curseforge">CurseForge Modpack</option>
|
|
<option value="modrinth">Modrinth Modpack</option>
|
|
<option value="url">Download from URL</option>
|
|
<option value="local">Local File Path</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="modpack-input" id="curseforge-input">
|
|
<div class="form-section">
|
|
<label for="curseforgeFile">CurseForge Server Pack Path</label>
|
|
<input type="text" id="curseforgeFile" placeholder="/modpacks/modpack-server.zip">
|
|
<span class="info-text">Path to CurseForge server pack zip file inside container</span>
|
|
</div>
|
|
<div class="form-section">
|
|
<label for="useCurseforgeType">Use CurseForge TYPE</label>
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="useCurseforgeType" checked>
|
|
Automatically set TYPE to CURSEFORGE
|
|
</label>
|
|
<span class="info-text">Uncheck if you want to manually set server type</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modpack-input" id="modrinth-input">
|
|
<div class="form-section">
|
|
<label for="modrinthProject">Modrinth Project ID or Slug</label>
|
|
<input type="text" id="modrinthProject" placeholder="allthemods">
|
|
<span class="info-text">Modrinth project identifier</span>
|
|
</div>
|
|
<div class="form-section">
|
|
<label for="modrinthVersion">Version ID (optional)</label>
|
|
<input type="text" id="modrinthVersion" placeholder="Leave empty for latest">
|
|
<span class="info-text">Specific version ID, or leave empty for latest</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modpack-input" id="url-input">
|
|
<div class="form-section">
|
|
<label for="modpackUrl">Modpack URL</label>
|
|
<input type="url" id="modpackUrl" placeholder="https://example.com/modpack.zip">
|
|
<span class="info-text">Direct download URL for modpack zip file</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modpack-input" id="local-input">
|
|
<div class="form-section">
|
|
<label for="modpackPath">Local Modpack Path</label>
|
|
<input type="text" id="modpackPath" placeholder="/modpacks/my-modpack.zip">
|
|
<span class="info-text">Path to modpack file inside container (use volume mount)</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="removeOldMods">
|
|
Remove Old Mods/Plugins Before Installing
|
|
</label>
|
|
<span class="info-text">Deletes existing mods/plugins before installing modpack</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Advanced Tab -->
|
|
<div class="tab-content" id="advanced-tab">
|
|
<div class="section-title">RCON Configuration</div>
|
|
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="enableRCON">
|
|
Enable RCON (Remote Console)
|
|
</label>
|
|
</div>
|
|
|
|
<div id="rconConfig" style="display: none;">
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="rconPort">RCON Port</label>
|
|
<input type="number" id="rconPort" value="25575" min="1024" max="65535">
|
|
</div>
|
|
<div class="form-section">
|
|
<label for="rconPassword">RCON Password</label>
|
|
<input type="password" id="rconPassword" placeholder="changeit">
|
|
<span class="info-text">Choose a strong password</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-title">Server Properties</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="pvpEnabled" checked>
|
|
Enable PVP
|
|
</label>
|
|
</div>
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="allowFlight">
|
|
Allow Flight
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="maxTickTime">Max Tick Time (ms)</label>
|
|
<input type="number" id="maxTickTime" placeholder="-1 (no limit)" value="-1">
|
|
<span class="info-text">Maximum time a single tick can take (-1 = no limit)</span>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label for="ops">Server Operators (comma-separated Minecraft usernames)</label>
|
|
<input type="text" id="ops" placeholder="Player1,Player2">
|
|
<span class="info-text">Players who will have operator permissions</span>
|
|
</div>
|
|
|
|
<div class="section-title">Container Options</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-section">
|
|
<label for="restartPolicy">Restart Policy</label>
|
|
<select id="restartPolicy">
|
|
<option value="no">No</option>
|
|
<option value="always">Always</option>
|
|
<option value="on-failure">On Failure</option>
|
|
<option value="unless-stopped" selected>Unless Stopped</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-section">
|
|
<label for="timezone">Timezone</label>
|
|
<input type="text" id="timezone" placeholder="America/New_York" value="UTC">
|
|
<span class="info-text">Server timezone (e.g., America/New_York, Europe/London)</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="rollingLogs">
|
|
Enable Rolling Logs
|
|
</label>
|
|
<span class="info-text">Automatically delete old log files</span>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="overrideServerProperties">
|
|
Override Server Properties
|
|
</label>
|
|
<span class="info-text">Allow environment variables to override server.properties</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="generate-btn" id="submitBtn">Create Server</button>
|
|
<button type="button" class="generate-btn" id="generateYamlBtn" style="margin-top: 10px; background: #6c757d;">Generate YAML Only</button>
|
|
</form>
|
|
|
|
<div id="preview" class="preview" style="display: none;">
|
|
<h3>Generated docker-compose.yml</h3>
|
|
<div class="yaml-tab">
|
|
<div class="yaml-tab-header">
|
|
<span class="yaml-status" id="yamlStatus">Valid YAML</span>
|
|
</div>
|
|
<textarea id="yamlEditor" class="yaml-editor" placeholder="YAML will appear here..."></textarea>
|
|
<div id="yamlError" class="yaml-error"></div>
|
|
<div id="yamlSuccess" class="yaml-success">✓ Valid YAML</div>
|
|
<div class="yaml-actions">
|
|
<button class="btn btn-primary btn-sm" id="validateYamlBtn">Validate YAML</button>
|
|
<button class="btn btn-success btn-sm" id="downloadYamlBtn">Download YAML</button>
|
|
<button class="btn btn-primary btn-sm" id="createFromYamlBtn">Create Server from YAML</button>
|
|
</div>
|
|
</div>
|
|
<pre id="yamlPreview" style="display: none;"></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Tab switching
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.addEventListener('click', () => {
|
|
const targetTab = tab.dataset.tab;
|
|
|
|
// Update tabs
|
|
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
|
tab.classList.add('active');
|
|
|
|
// Update tab content
|
|
document.querySelectorAll('.tab-content').forEach(content => {
|
|
content.classList.remove('active');
|
|
});
|
|
document.getElementById(`${targetTab}-tab`).classList.add('active');
|
|
});
|
|
});
|
|
|
|
// Modpack type switching
|
|
const modpackType = document.getElementById('modpackType');
|
|
modpackType.addEventListener('change', () => {
|
|
document.querySelectorAll('.modpack-input').forEach(input => {
|
|
input.classList.remove('active');
|
|
});
|
|
if (modpackType.value !== 'none') {
|
|
const activeInput = document.getElementById(`${modpackType.value}-input`);
|
|
if (activeInput) {
|
|
activeInput.classList.add('active');
|
|
}
|
|
}
|
|
});
|
|
|
|
// RCON config toggle
|
|
document.getElementById('enableRCON').addEventListener('change', (e) => {
|
|
document.getElementById('rconConfig').style.display = e.target.checked ? 'block' : 'none';
|
|
});
|
|
|
|
// Custom memory toggle
|
|
const memorySelect = document.getElementById('memory');
|
|
const customMemorySection = document.getElementById('customMemorySection');
|
|
memorySelect.addEventListener('change', () => {
|
|
customMemorySection.style.display = memorySelect.value === 'custom' ? 'block' : 'none';
|
|
});
|
|
|
|
// Form submission
|
|
const form = document.getElementById('serverForm');
|
|
const preview = document.getElementById('preview');
|
|
const yamlPreview = document.getElementById('yamlPreview');
|
|
const downloadBtn = document.getElementById('downloadBtn');
|
|
|
|
const API_BASE = window.location.origin;
|
|
|
|
const yamlEditor = document.getElementById('yamlEditor');
|
|
const yamlError = document.getElementById('yamlError');
|
|
const yamlSuccess = document.getElementById('yamlSuccess');
|
|
const yamlStatus = document.getElementById('yamlStatus');
|
|
let currentYaml = '';
|
|
|
|
// YAML validation function (wrapper that handles DOM updates)
|
|
function validateYAML(yamlText) {
|
|
const errorElement = document.getElementById('yamlError');
|
|
const successElement = document.getElementById('yamlSuccess');
|
|
|
|
errorElement.classList.remove('show');
|
|
successElement.classList.remove('show');
|
|
yamlEditor.classList.remove('error', 'valid');
|
|
yamlStatus.textContent = '';
|
|
yamlStatus.classList.remove('valid', 'invalid');
|
|
|
|
// Get the pure validation function from yaml-validator.js
|
|
// yaml-validator.js exposes it as window._validateYAMLPure to avoid shadowing
|
|
const pureValidateFn = (typeof window !== 'undefined' && window._validateYAMLPure)
|
|
? window._validateYAMLPure
|
|
: null;
|
|
|
|
if (!pureValidateFn) {
|
|
errorElement.textContent = 'Error: YAML validator library not loaded. Please refresh the page.';
|
|
errorElement.classList.add('show');
|
|
yamlStatus.textContent = '✗ Validation Error';
|
|
yamlStatus.classList.add('invalid');
|
|
console.error('Cannot access _validateYAMLPure from yaml-validator.js');
|
|
return { valid: false, error: 'YAML validator not loaded', config: null };
|
|
}
|
|
|
|
// Call the pure function from yaml-validator.js
|
|
const result = pureValidateFn(yamlText);
|
|
|
|
if (!result.valid) {
|
|
// Show error
|
|
errorElement.textContent = result.error;
|
|
errorElement.classList.add('show');
|
|
successElement.classList.remove('show');
|
|
yamlEditor.classList.add('error');
|
|
yamlEditor.classList.remove('valid');
|
|
|
|
// Determine status text based on error type
|
|
if (result.error.includes('Syntax Error')) {
|
|
yamlStatus.textContent = '✗ Invalid YAML Syntax';
|
|
} else if (result.error.includes('Docker Compose')) {
|
|
yamlStatus.textContent = '✗ Docker Compose Validation Failed';
|
|
} else {
|
|
yamlStatus.textContent = '✗ Validation Error';
|
|
}
|
|
yamlStatus.classList.add('invalid');
|
|
} else {
|
|
// All valid!
|
|
yamlEditor.classList.add('valid');
|
|
yamlEditor.classList.remove('error');
|
|
errorElement.classList.remove('show');
|
|
successElement.classList.add('show');
|
|
yamlStatus.textContent = '✓ Valid Docker Compose YAML';
|
|
yamlStatus.classList.add('valid');
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// Check if js-yaml is loaded
|
|
if (typeof jsyaml === 'undefined') {
|
|
console.error('js-yaml library not loaded!');
|
|
yamlStatus.textContent = 'Error: YAML library not loaded';
|
|
yamlStatus.classList.add('invalid');
|
|
}
|
|
|
|
// Real-time YAML linting with debounce
|
|
let lintTimeout;
|
|
yamlEditor.addEventListener('input', () => {
|
|
if (typeof jsyaml === 'undefined') {
|
|
return; // Don't validate if library isn't loaded
|
|
}
|
|
clearTimeout(lintTimeout);
|
|
lintTimeout = setTimeout(() => {
|
|
validateYAML(yamlEditor.value);
|
|
}, 500); // Wait 500ms after user stops typing
|
|
});
|
|
|
|
// Manual validate button
|
|
document.getElementById('validateYamlBtn').addEventListener('click', () => {
|
|
validateYAML(yamlEditor.value);
|
|
});
|
|
|
|
// Download YAML button
|
|
document.getElementById('downloadYamlBtn').addEventListener('click', () => {
|
|
const yaml = yamlEditor.value;
|
|
const blob = new Blob([yaml], { type: 'text/yaml' });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = 'docker-compose.yml';
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
});
|
|
|
|
// Create server from YAML button
|
|
document.getElementById('createFromYamlBtn').addEventListener('click', async () => {
|
|
const yaml = yamlEditor.value;
|
|
const validation = validateYAML(yaml);
|
|
|
|
if (!validation.valid) {
|
|
alert('Please fix YAML errors before creating server.');
|
|
return;
|
|
}
|
|
|
|
// Parse YAML to extract server name and config
|
|
try {
|
|
const config = jsyaml.load(yaml);
|
|
const serviceName = Object.keys(config.services || {})[0];
|
|
const service = config.services[serviceName];
|
|
|
|
if (!serviceName || !service) {
|
|
throw new Error('No service found in YAML');
|
|
}
|
|
|
|
// Convert docker-compose YAML to our config format
|
|
const serverConfig = {
|
|
serverName: serviceName,
|
|
serverType: service.environment?.TYPE || 'PAPER',
|
|
version: service.environment?.VERSION || 'LATEST',
|
|
memory: service.environment?.MEMORY || '2G',
|
|
port: Object.keys(service.ports || {})[0]?.split(':')[0] || '25565',
|
|
difficulty: service.environment?.DIFFICULTY || '',
|
|
gamemode: service.environment?.MODE || '',
|
|
levelType: service.environment?.LEVEL_TYPE || '',
|
|
motd: service.environment?.MOTD || '',
|
|
maxPlayers: parseInt(service.environment?.MAX_PLAYERS) || 20,
|
|
viewDistance: parseInt(service.environment?.VIEW_DISTANCE) || 10,
|
|
acceptEULA: service.environment?.EULA === 'TRUE',
|
|
enableRCON: service.environment?.ENABLE_RCON === 'true',
|
|
rconPort: service.environment?.RCON_PORT || '25575',
|
|
rconPassword: service.environment?.RCON_PASSWORD || '',
|
|
pvpEnabled: service.environment?.PVP !== 'false',
|
|
allowFlight: service.environment?.ALLOW_FLIGHT === 'true',
|
|
restartPolicy: service.restart || 'unless-stopped'
|
|
};
|
|
|
|
// Submit to API
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = 'Creating Server...';
|
|
|
|
const response = await fetch(`${API_BASE}/api/containers`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(serverConfig),
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
preview.innerHTML = `
|
|
<h3 style="color: #28a745;">✓ Server Created Successfully!</h3>
|
|
<p><strong>Name:</strong> ${result.name}</p>
|
|
<p><strong>Status:</strong> ${result.status}</p>
|
|
<br>
|
|
<a href="manage.html" class="btn btn-primary" style="text-decoration: none; display: inline-block; padding: 10px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 6px;">Go to Manage Page</a>
|
|
`;
|
|
} else {
|
|
throw new Error(result.detail || 'Failed to create server');
|
|
}
|
|
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = 'Create Server';
|
|
} catch (error) {
|
|
alert('Error creating server: ' + error.message);
|
|
}
|
|
});
|
|
|
|
// Generate YAML only (existing functionality)
|
|
document.getElementById('generateYamlBtn').addEventListener('click', () => {
|
|
const config = gatherFormData();
|
|
const yaml = generateDockerCompose(config);
|
|
|
|
currentYaml = yaml;
|
|
yamlEditor.value = yaml;
|
|
preview.style.display = 'block';
|
|
|
|
// Hide old preview, show editor
|
|
yamlPreview.style.display = 'none';
|
|
|
|
// Validate the generated YAML
|
|
validateYAML(yaml);
|
|
});
|
|
|
|
// Create server (new functionality)
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = 'Creating Server...';
|
|
|
|
try {
|
|
const config = gatherFormData();
|
|
|
|
// Submit to API
|
|
const response = await fetch(`${API_BASE}/api/containers`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(config),
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
// Show success message and redirect
|
|
preview.style.display = 'block';
|
|
preview.innerHTML = `
|
|
<h3 style="color: #28a745;">✓ Server Created Successfully!</h3>
|
|
<p><strong>Name:</strong> ${result.name}</p>
|
|
<p><strong>Status:</strong> ${result.status}</p>
|
|
<br>
|
|
<a href="manage.html" class="btn btn-primary" style="text-decoration: none; display: inline-block; padding: 10px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 6px;">Go to Manage Page</a>
|
|
`;
|
|
} else {
|
|
throw new Error(result.detail || 'Failed to create server');
|
|
}
|
|
} catch (error) {
|
|
preview.style.display = 'block';
|
|
preview.innerHTML = `
|
|
<h3 style="color: #dc3545;">Error Creating Server</h3>
|
|
<p>${error.message}</p>
|
|
`;
|
|
} finally {
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = 'Create Server';
|
|
}
|
|
});
|
|
|
|
function gatherFormData() {
|
|
return {
|
|
serverName: document.getElementById('serverName').value || 'minecraft',
|
|
serverType: document.getElementById('serverType').value,
|
|
version: document.getElementById('version').value || 'LATEST',
|
|
memory: memorySelect.value === 'custom'
|
|
? document.getElementById('customMemory').value || '2G'
|
|
: memorySelect.value,
|
|
port: document.getElementById('port').value || '25565',
|
|
difficulty: document.getElementById('difficulty').value,
|
|
gamemode: document.getElementById('gamemode').value,
|
|
levelType: document.getElementById('levelType').value,
|
|
motd: document.getElementById('motd').value,
|
|
maxPlayers: document.getElementById('maxPlayers').value,
|
|
viewDistance: document.getElementById('viewDistance').value,
|
|
acceptEULA: document.getElementById('acceptEULA').checked,
|
|
|
|
// Modpack
|
|
modpackType: document.getElementById('modpackType').value,
|
|
curseforgeFile: document.getElementById('curseforgeFile').value,
|
|
useCurseforgeType: document.getElementById('useCurseforgeType').checked,
|
|
modrinthProject: document.getElementById('modrinthProject').value,
|
|
modrinthVersion: document.getElementById('modrinthVersion').value,
|
|
modpackUrl: document.getElementById('modpackUrl').value,
|
|
modpackPath: document.getElementById('modpackPath').value,
|
|
removeOldMods: document.getElementById('removeOldMods').checked,
|
|
|
|
// RCON
|
|
enableRCON: document.getElementById('enableRCON').checked,
|
|
rconPort: document.getElementById('rconPort').value,
|
|
rconPassword: document.getElementById('rconPassword').value,
|
|
|
|
// Advanced
|
|
pvpEnabled: document.getElementById('pvpEnabled').checked,
|
|
allowFlight: document.getElementById('allowFlight').checked,
|
|
maxTickTime: document.getElementById('maxTickTime').value,
|
|
ops: document.getElementById('ops').value,
|
|
restartPolicy: document.getElementById('restartPolicy').value,
|
|
timezone: document.getElementById('timezone').value,
|
|
rollingLogs: document.getElementById('rollingLogs').checked,
|
|
overrideServerProperties: document.getElementById('overrideServerProperties').checked
|
|
};
|
|
}
|
|
|
|
function generateDockerCompose(config) {
|
|
let yaml = `services:
|
|
${config.serverName}:
|
|
image: itzg/minecraft-server
|
|
container_name: ${config.serverName}
|
|
ports:
|
|
- "${config.port}:25565"`;
|
|
|
|
// RCON port if enabled
|
|
if (config.enableRCON) {
|
|
yaml += `\n - "${config.rconPort}:25575"`;
|
|
}
|
|
|
|
yaml += `\n volumes:
|
|
- ${config.serverName}_data:/data`;
|
|
|
|
// Modpack volume mount if using local file
|
|
if (config.modpackType === 'curseforge' && config.curseforgeFile) {
|
|
yaml += `\n - ./modpacks:/modpacks:ro`;
|
|
} else if (config.modpackType === 'local' && config.modpackPath) {
|
|
const modpackDir = config.modpackPath.substring(0, config.modpackPath.lastIndexOf('/'));
|
|
if (modpackDir) {
|
|
yaml += `\n - ./modpacks:${modpackDir}:ro`;
|
|
}
|
|
}
|
|
|
|
yaml += `\n environment:`;
|
|
|
|
// EULA
|
|
if (config.acceptEULA) {
|
|
yaml += `\n EULA: "TRUE"`;
|
|
}
|
|
|
|
// Server Type
|
|
let serverType = config.serverType;
|
|
if (config.modpackType === 'curseforge' && config.useCurseforgeType) {
|
|
serverType = 'CURSEFORGE';
|
|
} else if (config.modpackType === 'modrinth') {
|
|
serverType = config.serverType; // Keep original or could be auto-detected
|
|
}
|
|
yaml += `\n TYPE: ${serverType}`;
|
|
|
|
// Version
|
|
if (config.version && config.version !== 'LATEST') {
|
|
yaml += `\n VERSION: ${config.version}`;
|
|
}
|
|
|
|
// Memory
|
|
if (config.memory) {
|
|
yaml += `\n MEMORY: ${config.memory}`;
|
|
}
|
|
|
|
// Modpack configuration
|
|
if (config.modpackType === 'curseforge' && config.curseforgeFile) {
|
|
yaml += `\n CF_SERVER_MOD: ${config.curseforgeFile}`;
|
|
} else if (config.modpackType === 'modrinth' && config.modrinthProject) {
|
|
yaml += `\n MODPACK: modrinth:${config.modrinthProject}`;
|
|
if (config.modrinthVersion) {
|
|
yaml += `:${config.modrinthVersion}`;
|
|
}
|
|
} else if (config.modpackType === 'url' && config.modpackUrl) {
|
|
yaml += `\n MODPACK: ${config.modpackUrl}`;
|
|
} else if (config.modpackType === 'local' && config.modpackPath) {
|
|
yaml += `\n MODPACK: ${config.modpackPath}`;
|
|
}
|
|
|
|
if (config.removeOldMods) {
|
|
yaml += `\n REMOVE_OLD_MODS: "TRUE"`;
|
|
}
|
|
|
|
// RCON
|
|
if (config.enableRCON) {
|
|
yaml += `\n ENABLE_RCON: "true"`;
|
|
if (config.rconPassword) {
|
|
yaml += `\n RCON_PASSWORD: ${config.rconPassword}`;
|
|
}
|
|
}
|
|
|
|
// Difficulty
|
|
if (config.difficulty) {
|
|
yaml += `\n DIFFICULTY: ${config.difficulty}`;
|
|
}
|
|
|
|
// Game Mode
|
|
if (config.gamemode) {
|
|
yaml += `\n MODE: ${config.gamemode}`;
|
|
}
|
|
|
|
// Level Type
|
|
if (config.levelType) {
|
|
yaml += `\n LEVEL_TYPE: ${config.levelType}`;
|
|
}
|
|
|
|
// MOTD
|
|
if (config.motd) {
|
|
yaml += `\n MOTD: "${config.motd}"`;
|
|
}
|
|
|
|
// Max Players
|
|
if (config.maxPlayers) {
|
|
yaml += `\n MAX_PLAYERS: ${config.maxPlayers}`;
|
|
}
|
|
|
|
// View Distance
|
|
if (config.viewDistance) {
|
|
yaml += `\n VIEW_DISTANCE: ${config.viewDistance}`;
|
|
}
|
|
|
|
// PVP
|
|
if (!config.pvpEnabled) {
|
|
yaml += `\n PVP: "false"`;
|
|
}
|
|
|
|
// Allow Flight
|
|
if (config.allowFlight) {
|
|
yaml += `\n ALLOW_FLIGHT: "true"`;
|
|
}
|
|
|
|
// Max Tick Time
|
|
if (config.maxTickTime && config.maxTickTime !== '-1') {
|
|
yaml += `\n MAX_TICK_TIME: ${config.maxTickTime}`;
|
|
}
|
|
|
|
// Ops
|
|
if (config.ops) {
|
|
yaml += `\n OPS: "${config.ops}"`;
|
|
}
|
|
|
|
// Timezone
|
|
if (config.timezone && config.timezone !== 'UTC') {
|
|
yaml += `\n TZ: ${config.timezone}`;
|
|
}
|
|
|
|
// Rolling Logs
|
|
if (config.rollingLogs) {
|
|
yaml += `\n ENABLE_ROLLING_LOGS: "true"`;
|
|
}
|
|
|
|
// Override Server Properties
|
|
if (config.overrideServerProperties) {
|
|
yaml += `\n OVERRIDE_SERVER_PROPERTIES: "true"`;
|
|
}
|
|
|
|
// Restart Policy
|
|
yaml += `\n restart: ${config.restartPolicy}`;
|
|
|
|
yaml += `\n\nvolumes:
|
|
${config.serverName}_data:`;
|
|
|
|
return yaml;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|