Update k8s/games/minecraft/deployments.yaml
All checks were successful
Check with kubeconform / lint (push) Successful in 12s
All checks were successful
Check with kubeconform / lint (push) Successful in 12s
This commit is contained in:
@@ -22,33 +22,147 @@ data:
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
|
||||||
|
# Custom 502 error page with auto-refresh
|
||||||
error_page 502 /502.html;
|
error_page 502 /502.html;
|
||||||
location = /502.html {
|
location = /502.html {
|
||||||
internal;
|
internal;
|
||||||
return 200 '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Server Loading</title><style>body{font-family:Arial,sans-serif;text-align:center;margin-top:100px;background:#f0f0f0}h1{color:#333}p{color:#666;font-size:18px}</style></head><body><h1>Server is loading probably...</h1><p>Please wait a moment and try refreshing the page.</p><script>setTimeout(function(){window.location.reload();}, 10000);</script></body></html>';
|
return 200 '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Server Loading</title><style>body{font-family:Arial,sans-serif;text-align:center;margin-top:100px;background:#f0f0f0}h1{color:#333}p{color:#666;font-size:18px}</style></head><body><h1>Server is loading probably...</h1><p>Please wait a moment and try refreshing the page.</p><script>setTimeout(function(){window.location.reload();}, 10000);</script></body></html>';
|
||||||
add_header Content-Type text/html;
|
add_header Content-Type text/html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Main location - proxy to Minecraft Dynmap
|
||||||
location / {
|
location / {
|
||||||
|
# Proxy configuration for Dynmap server
|
||||||
proxy_pass http://localhost:8123;
|
proxy_pass http://localhost:8123;
|
||||||
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;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
|
# Inject user authentication meta tag into HTML head
|
||||||
sub_filter '<head>' '<head><meta name="remote-user" content="$http_x_authentik_username">';
|
sub_filter '<head>' '<head><meta name="remote-user" content="$http_x_authentik_username">';
|
||||||
|
|
||||||
|
# Replace default Dynmap title with custom server name
|
||||||
sub_filter 'Minecraft Dynamic Map' "Hexor's MC server";
|
sub_filter 'Minecraft Dynamic Map' "Hexor's MC server";
|
||||||
sub_filter "</body>" '<script>function getUsername(){var headers=document.querySelectorAll("meta");for(var i=0;i<headers.length;i++){if(headers[i].getAttribute("name")==="remote-user"){return headers[i].getAttribute("content");}}var jwt=document.cookie.split("; ").find(row=>row.startsWith("authentik_session="));if(jwt){try{var token=jwt.split("=")[1];var payload=JSON.parse(atob(token.split(".")[1]));return payload.sub||payload.username||"web-user";}catch(e){}}return "web-user";}var username=getUsername();console.log("Username found:", username);if(username && username!=="web-user" && window.location.search.indexOf("playername=")===-1){var currentUrl=new URL(window.location.href);currentUrl.searchParams.set("playername",username);console.log("Redirecting to:", currentUrl.href);window.location.href=currentUrl.href;}document.addEventListener("DOMContentLoaded",function(){var userBlock=document.createElement("div");userBlock.style.cssText="background-color: #CEC6CB; color: black; padding: 8px; text-align: center; font-size: medium; border-radius: 4px; position: absolute; top: 10px; right: 10px; max-width: 200px;";userBlock.innerHTML="Logged in as: <b>"+username+"</b>";document.body.appendChild(userBlock);});</script><p style="background-color: #CEC6CB; color: black; padding: 10px 10px; text-align: center; font-size: large; text-decoration: none; display: inline-block; border-radius: 4px; position: absolute; top: 10px; left: 150px;">Get <a href="https://github.com/PrismLauncher/PrismLauncher/releases/tag/8.4" >Prism Launcher</a> and <a href="/clients/1.12.2.zip" >client.zip</a> for this server. Server address <b>minecraft.hexor.cy:30565</b><br><br><a href="#" onclick="showInstallModal(); return false;" style="color: black; text-decoration: underline;">Windows Install Script</a></p><div id="installModal" style="display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5);"><div style="background-color: #CEC6CB; margin: 15% auto; padding: 10px; border-radius: 4px; width: 70%; max-width: 500px; text-align: center; color: black; font-size: large;"><h3 style="margin-top: 0; color: black;">Windows Installation</h3><p style="color: black;">Copy and paste this command into PowerShell (run as Administrator):</p><textarea id="scriptCommand" readonly style="width: 90%; height: 60px; font-family: monospace; padding: 8px; border: 1px solid #888; border-radius: 4px; resize: none; background-color: white; color: black;">iwr -useb https://minecraft.hexor.cy/clients/win-install.ps1 | iex</textarea><br><br><button id="copyButton" onclick="copyToClipboard()" style="background-color: #CEC6CB; color: black; padding: 10px 15px; border: 1px solid #888; border-radius: 4px; cursor: pointer; margin-right: 10px; font-size: large; text-decoration: none;">Copy</button><button onclick="closeInstallModal()" style="background-color: #CEC6CB; color: black; padding: 10px 15px; border: 1px solid #888; border-radius: 4px; cursor: pointer; font-size: large; text-decoration: none;">Close</button></div></div><script>function showInstallModal() { document.getElementById("installModal").style.display = "block"; } function closeInstallModal() { document.getElementById("installModal").style.display = "none"; } function copyToClipboard() { var textarea = document.getElementById("scriptCommand"); textarea.select(); textarea.setSelectionRange(0, 99999); if (document.execCommand("copy")) { var button = document.getElementById("copyButton"); button.style.borderColor = "#4CAF50"; setTimeout(function() { button.style.borderColor = "#888"; }, 2000); } } window.onclick = function(event) { var modal = document.getElementById("installModal"); if (event.target == modal) { closeInstallModal(); } }</script></body>';
|
|
||||||
|
# Inject custom JavaScript and UI elements before closing body tag
|
||||||
|
sub_filter "</body>" '
|
||||||
|
<script>
|
||||||
|
// Function to extract username from various sources
|
||||||
|
function getUsername() {
|
||||||
|
// First try to get from meta tag (set by Authentik)
|
||||||
|
var headers = document.querySelectorAll("meta");
|
||||||
|
for (var i = 0; i < headers.length; i++) {
|
||||||
|
if (headers[i].getAttribute("name") === "remote-user") {
|
||||||
|
return headers[i].getAttribute("content");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: try to decode JWT from cookie
|
||||||
|
var jwt = document.cookie.split("; ").find(row => row.startsWith("authentik_session="));
|
||||||
|
if (jwt) {
|
||||||
|
try {
|
||||||
|
var token = jwt.split("=")[1];
|
||||||
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
||||||
|
return payload.sub || payload.username || "web-user";
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default fallback username
|
||||||
|
return "web-user";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get username and add to URL parameters if not already present
|
||||||
|
var username = getUsername();
|
||||||
|
console.log("Username found:", username);
|
||||||
|
|
||||||
|
// Auto-redirect to add playername parameter for authenticated users
|
||||||
|
if (username && username !== "web-user" && window.location.search.indexOf("playername=") === -1) {
|
||||||
|
var currentUrl = new URL(window.location.href);
|
||||||
|
currentUrl.searchParams.set("playername", username);
|
||||||
|
console.log("Redirecting to:", currentUrl.href);
|
||||||
|
window.location.href = currentUrl.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add user info block to page after DOM loads
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
var userBlock = document.createElement("div");
|
||||||
|
userBlock.style.cssText = "background-color: #CEC6CB; color: black; padding: 8px; text-align: center; font-size: medium; border-radius: 4px; position: absolute; top: 10px; right: 10px; max-width: 200px;";
|
||||||
|
userBlock.innerHTML = "Logged in as: <b>" + username + "</b>";
|
||||||
|
document.body.appendChild(userBlock);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Server information and download links panel -->
|
||||||
|
<p style="background-color: #CEC6CB; color: black; padding: 10px 10px; text-align: center; font-size: large; text-decoration: none; display: inline-block; border-radius: 4px; position: absolute; top: 10px; left: 150px;">
|
||||||
|
Get <a href="https://github.com/PrismLauncher/PrismLauncher/releases/tag/8.4">Prism Launcher</a>
|
||||||
|
and <a href="/clients/1.12.2.zip">client.zip</a> for this server.
|
||||||
|
Server address <b>minecraft.hexor.cy:30565</b>
|
||||||
|
<br><br>
|
||||||
|
<a href="#" onclick="showInstallModal(); return false;" style="color: black; text-decoration: underline;">
|
||||||
|
Windows Install Script
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Modal for Windows installation instructions -->
|
||||||
|
<div id="installModal" style="display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5);">
|
||||||
|
<div style="background-color: #CEC6CB; margin: 15% auto; padding: 10px; border-radius: 4px; width: 70%; max-width: 500px; text-align: center; color: black; font-size: large;">
|
||||||
|
<h3 style="margin-top: 0; color: black;">Windows Installation</h3>
|
||||||
|
<p style="color: black;">Copy and paste this command into PowerShell (run as Administrator):</p>
|
||||||
|
<textarea id="scriptCommand" readonly style="width: 90%; height: 60px; font-family: monospace; padding: 8px; border: 1px solid #888; border-radius: 4px; resize: none; background-color: white; color: black;">iwr -useb https://minecraft.hexor.cy/clients/win-install.ps1 | iex</textarea>
|
||||||
|
<br><br>
|
||||||
|
<button id="copyButton" onclick="copyToClipboard()" style="background-color: #CEC6CB; color: black; padding: 10px 15px; border: 1px solid #888; border-radius: 4px; cursor: pointer; margin-right: 10px; font-size: large; text-decoration: none;">Copy</button>
|
||||||
|
<button onclick="closeInstallModal()" style="background-color: #CEC6CB; color: black; padding: 10px 15px; border: 1px solid #888; border-radius: 4px; cursor: pointer; font-size: large; text-decoration: none;">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Modal control functions
|
||||||
|
function showInstallModal() {
|
||||||
|
document.getElementById("installModal").style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeInstallModal() {
|
||||||
|
document.getElementById("installModal").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy PowerShell command to clipboard
|
||||||
|
function copyToClipboard() {
|
||||||
|
var textarea = document.getElementById("scriptCommand");
|
||||||
|
textarea.select();
|
||||||
|
textarea.setSelectionRange(0, 99999);
|
||||||
|
|
||||||
|
if (document.execCommand("copy")) {
|
||||||
|
var button = document.getElementById("copyButton");
|
||||||
|
button.style.borderColor = "#4CAF50";
|
||||||
|
setTimeout(function() {
|
||||||
|
button.style.borderColor = "#888";
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close modal when clicking outside of it
|
||||||
|
window.onclick = function(event) {
|
||||||
|
var modal = document.getElementById("installModal");
|
||||||
|
if (event.target == modal) {
|
||||||
|
closeInstallModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>';
|
||||||
|
|
||||||
|
# Apply sub_filter replacements globally (not just once)
|
||||||
sub_filter_once off;
|
sub_filter_once off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Static file serving for client downloads
|
||||||
location /clients/ {
|
location /clients/ {
|
||||||
alias /mc/clients/;
|
alias /mc/clients/;
|
||||||
sendfile on;
|
sendfile on; # Enable efficient file serving
|
||||||
add_header Content-Disposition "attachment";
|
add_header Content-Disposition "attachment"; # Force download
|
||||||
autoindex on;
|
autoindex on; # Enable directory listing
|
||||||
gzip off;
|
gzip off; # Disable compression for downloads
|
||||||
chunked_transfer_encoding off;
|
chunked_transfer_encoding off; # Disable chunked encoding
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user