<!DOCTYPE html> <html lang="id"> <head> <meta… · The Chat Archive
code Copy code
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-cloud"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-cloud"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
<script>
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', {
method: 'POST',
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', {
method: 'POST',
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
}
});
</script>
</form>
</div>
</div>
</div>
</div>
can you add server logs (show the cmd console.log to the dashboard)
Show full message · 168 lines Assistant2024-10-19 10:35 UTC Copy response
To display server logs (essentially the console output of a Node.js server, if that's what you're using) on the dashboard, you'll need to:
Capture the logs on the server.
Transmit those logs to the client (browser).
Display the logs on your webpage.
Here's a basic example of how you can achieve that:
Step 1: Capture Logs
To capture server-side logs, you can override the default console.log function to push log messages to an array, which can then be sent to clients:
javascript Copy code
let logMessages = [];
const originalLog = console.log;
console.log = (...args) => {
originalLog(...args);
logMessages.push(args.join(' '));
};
Step 2: Serve Logs via an Endpoint
Create an endpoint in your server code to serve the captured logs to the client. This could be a simple Express.js endpoint:
javascript Copy code
const express = require('express');
const app = express();
app.get('/logs', (req, res) => {
res.json({
logs: logMessages
});
});
// Other server code...
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Step 3: Display Logs on the Webpage
Add an HTML element to your existing page to display the logs, and use JavaScript to fetch and update the logs periodically:
HTML Section
Add this to your HTML where you want the logs to appear:
html Copy code
<div class="card mt-4">
<div class="card-header bg-secondary text-white">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body bg-dark text-white">
<pre id="serverLogs" class="bg-dark text-white"></pre>
</div>
</div>
JavaScript Section
Add this script after your existing JavaScript to periodically fetch and update logs:
html Copy code
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch
</script>
This setup will allow your web page to display server logs in real-time, updating every 5 seconds. Adjust the interval as needed. Please note that this example assumes you are using Express.js and Node.js for your server. If your server environment differs, you might need to adapt the approach accordingly.
Show full message · 193 lines Assistant2024-10-19 10:38 UTC Copy response
To display server logs on your HTML page, you must ensure that the server correctly captures and serves these logs, and that the client-side code can retrieve and display them. Let’s go through a detailed step-by-step guide to help you fix any issues:
Step 1: Ensure Server-Side Log Capture
Assuming you are using a Node.js server with Express, you need to capture and serve the logs. Here’s a simple example on how to achieve that:
Server-Side (Node.js with Express)
First, capture console logs and store them in an array to be served to the client:
javascript Copy code
const express = require('express');
const app = express();
const port = 3000;
let logMessages = [];
// Override console.log
const originalLog = console.log;
console.log = (...args) => {
originalLog(...args); // Keep logging to the console
logMessages.push(args.join(' ')); // Capture the log messages in an array
};
// Endpoint to serve logs to the frontend
app.get('/logs', (req, res) => {
res.json({
logs: logMessages // Return captured logs as JSON
});
});
// Example log
console.log("Server started on port", port);
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});
Step 2: Client-Side (HTML/JavaScript)
Ensure your HTML and JavaScript are set up to retrieve and display the captured logs on the webpage:
Client-Side
From your provided HTML, it looks mostly correct, but ensure you're correctly formatting and placing it:
give me the full code of config.ejs
Assistant2024-10-19 10:39 UTC Copy response
Certainly! Below is the full HTML code for config.ejs, which incorporates the logging functionality along with the form and buttons for server configuration. This assumes you are using Express.js with a Node.js backend and the server log capturing as previously described.
config.ejs
Show full message · 172 lines bisakah kamu buatkan responsive
Assistant2024-10-19 10:40 UTC Copy response
Tentu! Untuk membuat halaman lebih responsif, kita bisa memanfaatkan grid layout dan fitur responsif dari Bootstrap. Berikut adalah beberapa cara untuk membuat kode Anda lebih responsif:
Menggunakan Grid System: Bootstrap sudah menyediakan grid system yang memudahkan pembuatan layout responsif.
Media Queries: Meskipun Bootstrap sudah cukup untuk kebanyakan kebutuhan responsif, kita bisa menambahkan media queries untuk penyesuaian tambahan jika diperlukan.
Saya akan memastikan kode ini sudah siap digunakan dengan Bootstrap.
config.ejs
Berikut adalah versi yang lebih responsif dari file config.ejs:
Show full message · 190 lines maksud saya buatkan responsive ke semua resolusi, jadi saya bisa melihat server logs nya jika perlu percantik tampilan nya
Assistant2024-10-19 10:42 UTC Copy response
Untuk membuat halaman Anda lebih responsif di semua resolusi, kita perlu memastikan elemen-elemen grid, teks, dan lainnya beradaptasi dengan baik di berbagai ukuran layar. Kita juga bisa mempercantik tampilannya dengan menggunakan lebih banyak styling CSS bersama dengan komponen Bootstrap. Berikut ini adalah versi yang lebih responsif dan estetis dari config.ejs yang bisa Anda gunakan:
config.ejs
Show full message · 205 lines maksud saya adalah, tata letak nya server logs dan server configuration perbaiki, saya tidak bisa lihat server logs jika tidak saya minimize size resolusi nya
Assistant2024-10-19 10:44 UTC Copy response
To improve the layout so that you can view the server logs more easily without minimizing the resolution, we can adjust the grid structure and element sizes. We want to ensure that the Server Logs section is visible on different screen sizes without having to adjust the window size. Here's how you can do that:
Modified config.ejs
I will separate the configuration form and server logs visually and ensure they stack on smaller screens while allowing sufficient space for logs.
Show full message · 214 lines Ok good, it's almost done now fix for all resolution
Assistant2024-10-19 10:46 UTC Copy response
To ensure that your layout is optimal for all screen resolutions and devices, we can make the following adjustments:
Improve Flexibility: Ensure elements are using responsive Bootstrap grid classes correctly.
Ensure Readability: Maintain sufficient size and spacing for elements on all screen sizes, including small mobile devices.
Optimize Viewing Area: Maximize the visibility of content such as server logs, without sacrificing the usability of the form.
Here’s an adjusted version of config.ejs with these improvements:
Adjusted config.ejs
Show full message · 226 lines masih saja tidak rapih, sedikit lagi rapih buatlah tampilan server logs nya full (tidak perlu geser-geser) dan server configuration nya perbaiki untuk semua resolusi atau percantik sebagus mungkin agar enak di pandang!
Assistant2024-10-19 10:49 UTC Copy response
Certainly! To refine the layout and enhance aesthetics so that the server logs can fully fit within the visible area and ensure the server configuration is visually appealing and easily accessible on all devices, we'll make some strategic changes. Here’s a step-by-step approach:
Ensure Full Visibility of Logs: Simplify the size and structure to balance the space between the form and logs.
Optimize Form Layout: Use Bootstrap's responsive form styling to ensure better spacing and alignment.
Add Visual Enhancements: Use consistent and subtle design elements to make the interface pleasing to the eye.
Updated config.ejs
Show full message · 215 lines ok now fix the label color make it all readable bruh
Assistant2024-10-19 10:57 UTC Copy response
Certainly! To ensure readability, we'll adjust the label and form input text colors for better contrast against the dark background. We'll ensure the text is in a lighter color to stand out clearly. Let's update the CSS in your config.ejs.
Updated CSS and HTML
Show full message · 224 lines ok great, now for the server logs why there is 36m 36m weird text ? fix it
also make the button glow effects
Assistant2024-10-19 11:00 UTC Copy response
The “36m 36m” issue is likely due to ANSI escape codes being logged. These codes are used in terminal applications to style text with color and effects. When captured and displayed in plain HTML, they can appear as strange text like “36m”. To fix this, we need to strip these codes before displaying the logs in the HTML. Additionally, we'll add a glow effect to the buttons for a modern look.
Stripping ANSI Escape Codes
You can use a small utility function to remove these escape codes before displaying the logs. Here’s an updated version of the script that includes this functionality:
Updated config.ejs
Show full message · 227 lines Copy first response
Not yet included in a published release.
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-cloud"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-cloud"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
<div>
<div class="card mt-4">
<div class="card-header bg-secondary text-white">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body bg-dark text-white">
<pre id="serverLogs" class="bg-dark text-white"></pre>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch
code Copy code
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', {
method: 'POST',
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', {
method: 'POST',
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
}
});
</script>
</form>
</div>
</div>
</div>
</div>
I cant see the server logs, can u fix it for me
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#"><i class="fas fa-rocket"></i> Server Config</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<div class="container mt-5">
<!-- Existing form card -->
<!-- Server Logs section -->
<div class="card bg-dark text-white mt-4">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body bg-dark text-white">
<pre id="serverLogs" class="bg-dark text-white"></pre>
</div>
</div>
</div>
<script>
// Fetch logs every 5 seconds
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
setInterval(fetchLogs, 5000); // Set interval to fetch logs
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server?')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Final Checks
Server Logs : Verify that logs are being correctly captured on the server and updating logMessages.
Endpoints : Ensure the /logs endpoint is accessible and your server is running.
Network : If using a different environment than localhost, ensure your frontend can access the server.
Console Output : Check your browser's console for any errors related to fetching logs.
Following these steps should help you diagnose and fix problems so that server logs are correctly displayed on your HTML page.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<% if (typeof successMsg !== 'undefined' && successMsg.length > 0) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle"></i> <%= successMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
</form>
</div>
</div>
<!-- Server Logs section -->
<div class="card bg-dark text-white mt-4">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Key Points
Server Logs: Ensures a <pre> tag captures the logs and displays them, updating every 5 seconds via the fetchLogs function.
Form Styling: Uses Bootstrap for styling form elements and ensuring consistency.
Server Control Buttons: fetch API is used for restarting and shutting down the server with confirmation dialogs.
Script Placement: Ensure all scripts load correctly, external dependencies such as Bootstrap and Font Awesome are linked using CDN.
Replace your existing config.ejs content with this code after ensuring your server-side code correctly handles log capturing and endpoints. This will give you a framework to view and manage server configurations and logs effectively from a web dashboard.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<link rel="stylesheet" href="/styles.css">
<style>
/* Tambahan CSS untuk memastikan elemen responsif */
.card {
margin-top: 20px;
}
.navbar-brand {
font-size: 1.5rem;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<!-- Tambahkan elemen navbar di sini jika diperlukan -->
</div>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-10 col-lg-8"> <!-- Kolom responsif -->
<% if (typeof successMsg !== 'undefined' && successMsg.length > 0) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle"></i> <%= successMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
</form>
</div>
</div>
<!-- Server Logs section -->
<div class="card bg-dark text-white mt-4">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Catatan
Grid System: Saya menggunakan kelas Bootstrap seperti col-12, col-md-10, dan col-lg-8 untuk memastikan elemen-elemen beradaptasi dengan baik di berbagai ukuran layar.
Responsiveness: Untuk menambahkan lebih banyak penyesuaian dan responsivitas, Anda dapat selalu menambahkan media queries di dalam file CSS Anda sendiri. Namun, banyak dari ini sudah dikelola oleh Bootstrap.
Navbar Toggler: Navbar dirancang untuk beradaptasi dan menampilkan tombol toggler pada layar yang lebih kecil.
Dengan setup ini, tampilan akan lebih responsif di berbagai perangkat, mulai dari ponsel hingga layar desktop besar.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<link rel="stylesheet" href="/styles.css">
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
}
.starfield, .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.card {
margin-top: 20px;
}
.navbar-brand {
font-size: 1.5rem;
}
pre {
height: 300px;
overflow-y: auto;
background-color: #1c1c1c;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<!-- Additional navigation items can go here -->
</div>
</div>
</nav>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12 col-md-10 col-lg-8"> <!-- Responsive columns -->
<% if (typeof successMsg !== 'undefined' && successMsg.length > 0) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle"></i> <%= successMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
</form>
</div>
</div>
<!-- Server Logs section -->
<div class="card bg-dark text-white mt-4">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Penjelasan:
Background: Saya menambahkan styling dasar yang membuat halaman tampak lebih baik dengan latar belakang gelap untuk mendukung teks putih yang lebih jelas.
Responsiveness: Menggunakan Bootstrap grid system untuk memastikan layoutnya responsif, memanfaatkan utility classes seperti col-12, col-md-10, dan col-lg-8 untuk mengatur lebar berdasarkan ukuran layar.
Styling: Styling tambahan telah ditambahkan ke <pre> untuk tampilan log server yang lebih baik, termasuk scrollbar jika isinya panjang.
Interaksi: Penggunaan Bootstrap dan Font Awesome menambahkan sedikit gaya visual dan ikon yang membuat tampilannya lebih profesional.
Pastikan untuk menyajikan file statis yang diperlukan seperti CSS eksternal yang mungkin Anda gunakan (seperti styles.css di sini), dan bahwa endpoint server-side (misalnya, untuk /logs) sudah berjalan dan merespons dengan benar. Ini akan memastikan bahwa halaman ini tidak hanya terlihat baik tetapi juga berfungsi sebagaimana mestinya dalam berbagai layar dan resolusi.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<link rel="stylesheet" href="/styles.css">
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
}
.starfield, .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.card {
margin-top: 20px;
}
.navbar-brand {
font-size: 1.5rem;
}
pre {
max-height: 400px;
overflow-y: auto;
background-color: #1c1c1c;
padding: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<!-- Additional navigation items can go here -->
</div>
</div>
</nav>
<div class="container mt-5">
<!-- Use a responsive grid layout to separate the config form and logs -->
<div class="row">
<!-- Configuration Form -->
<div class="col-12 col-lg-6 mb-4"> <!-- Use mb-4 to add margin-bottom -->
<% if (typeof successMsg !== 'undefined' && successMsg.length > 0) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle"></i> <%= successMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-sync-alt"></i> Shutdown HTTP</button>
</form>
</div>
</div>
</div>
<!-- Server Logs Section -->
<div class="col-12 col-lg-6"> <!-- Stack below on smaller screens -->
<div class="card bg-dark text-white shadow">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Key Adjustments:
Grid Layout: The configuration form and server logs are placed in separate columns (col-lg-6) which will stack vertically on smaller screens (col-12), making better use of the available space.
Scrollable Logs: The <pre> element has a specified max height and is scrollable, allowing you to see more logs without taking up too much space vertically.
Consistent Design: Ensures consistency between both sections with Bootstrap's card design, while allowing them to adapt smoothly across devices—from mobile to desktop.
Responsiveness: Leverage Bootstrap’s responsive classes (col-12, col-lg-6) to ensure usability and visibility on varying resolutions. You should now be able to view the logs regardless of resolution by scrolling as needed.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<link rel="stylesheet" href="/styles.css">
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
}
.starfield, .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.card {
margin-top: 20px;
}
.navbar-brand {
font-size: 1.5rem;
}
pre {
max-height: 400px;
overflow-y: auto;
background-color: #1c1c1c;
color: #c7c7c7;
padding: 10px;
border-radius: 5px;
}
.form-label i,
.card-header i {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-transparent">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<!-- Additional navigation items can go here -->
</div>
</div>
</nav>
<div class="container mt-5">
<!-- Use a responsive grid layout to separate the config form and logs -->
<div class="row g-4"> <!-- Add gap between cards -->
<!-- Configuration Form -->
<div class="col-12 col-lg-6"> <!-- Take full width on small devices -->
<% if (typeof successMsg !== 'undefined' && successMsg.length > 0) { %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle"></i> <%= successMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<% if (typeof errorMsg !== 'undefined' && errorMsg.length > 0) { %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-triangle"></i> <%= errorMsg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% } %>
<div class="card bg-dark text-white shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control bg-dark text-white" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control bg-dark text-white" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control bg-dark text-white" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control bg-dark text-white" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control bg-dark text-white" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<div class="d-flex justify-content-between">
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<div>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-warning" id="shutdownButton"><i class="fas fa-power-off"></i> Shutdown HTTP</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Server Logs Section -->
<div class="col-12 col-lg-6">
<div class="card bg-dark text-white shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
// Fetch logs every 5 seconds
setInterval(fetchLogs, 5000);
fetchLogs(); // Initial fetch to display logs immediately
// Restart and Shutdown button click handlers
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Summary of Improvements:
Consistency and Flexibility: Used utility and grid classes such as col-12 and col-lg-6 for flexible spacing and layout, ensuring both form and logs are accessible at all screen widths.
Visibility and Usability: Adjusted log panel's height and scroll options to maintain a clean and usable interface across all devices.
Styling Enhancements: Included visual enhancements to ensure clear display of buttons and forms using consistent light-on-dark color schemes.
Performance and Readability: Added shadow-lg for cards for a more defined layout and better separation of content, enhancing readability on all resolutions.
With these changes, the page should be usable and visually appealing across all devices without any additional adjustment needed. Let me know if there’s anything else specific you’d like to enhance!
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<style>
body {
background-color: #212529;
color: #ffffff;
font-family: 'Roboto', sans-serif;
}
.starfield, .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.navbar-brand {
font-size: 1.75rem;
}
.card {
margin-top: 20px;
border: none;
border-radius: 8px;
}
.card-header {
background-color: #343a40;
}
.card-body {
background-color: #272b30;
}
pre {
background-color: #1c1e22;
color: #c7c7c7;
padding: 15px;
border-radius: 5px;
height: 450px;
overflow-y: auto;
}
.btn-primary, .btn-warning {
margin-right: 10px;
}
.form-label i {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<div class="container mt-3">
<div class="row g-4"> <!-- Add gap between cards -->
<!-- Configuration Form -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-danger" id="shutdownButton"><i class="fas fa-power-off"></i> Shutdown HTTP</button>
</div>
</form>
</div>
</div>
</div>
<!-- Server Logs Section -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
setInterval(fetchLogs, 5000);
fetchLogs();
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Explanation:
Layout Adjustments: Cards for the server configuration and logs are placed side by side on larger screens but stack on smaller screens.
Full Height Logs: The pre element for logs has a larger height to display logs without scrolling in most cases.
Responsive Design: Using Bootstrap's grid system ensures that both sections adapt to various screen sizes—stacking vertically on mobile devices.
Styling Enhancements: Both sections use shadow and consistent colors to create a unified and readable interface.
Visual Balance: Optimized button placement and form input spacing enhance usability and the overall visual appeal.
This layout should provide a balanced, pleasing, and functional interface across all resolutions. Let me know if there are more specific enhancements you need!
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<style>
body {
background-color: #212529;
color: #ffffff;
font-family: 'Roboto', sans-serif;
}
.starfield, .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.navbar-brand {
font-size: 1.75rem;
}
.card {
margin-top: 20px;
border: none;
border-radius: 8px;
}
.card-header {
background-color: #343a40;
}
.card-body {
background-color: #272b30;
}
pre {
background-color: #1c1e22;
color: #c7c7c7;
padding: 15px;
border-radius: 5px;
height: 450px;
overflow-y: auto;
}
.btn-primary, .btn-warning {
margin-right: 10px;
}
.form-label {
color: #b0b0b0; /* Light color for improved readability */
margin-bottom: 5px;
}
input.form-control {
color: #ffffff;
border-color: #6c757d;
}
input.form-control:focus {
color: #ffffff;
background-color: #343a40;
}
.form-label i {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="starfield"></div>
<div class="overlay"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<div class="container mt-3">
<div class="row g-4"> <!-- Add gap between cards -->
<!-- Configuration Form -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-danger" id="shutdownButton"><i class="fas fa-power-off"></i> Shutdown HTTP</button>
</div>
</form>
</div>
</div>
</div>
<!-- Server Logs Section -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
document.getElementById('serverLogs').textContent = data.logs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
setInterval(fetchLogs, 5000);
fetchLogs();
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Enhancements Made:
Improved Readability: The label and form input colors have been adjusted to a lighter color to ensure readability against the dark background.
Input Focus Styling: When an input field is focused, the background remains consistent with a clear focus on the content.
Overall Aesthetic: Subtle design adjustments, including button arrangement and shadow effects on cards, enhance the visual appeal while maintaining functionality.
These changes should ensure that all text and inputs are easily readable, providing users with a comfortable viewing and interaction experience. Adjust these settings as needed for further customization.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Konfigurasi Server</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous"/>
<style>
body {
background-color: #212529;
color: #ffffff;
font-family: 'Roboto', sans-serif;
}
.navbar-brand {
font-size: 1.75rem;
}
.card {
margin-top: 20px;
border: none;
border-radius: 8px;
}
.card-header {
background-color: #343a40;
}
.card-body {
background-color: #272b30;
}
pre {
background-color: #1c1e22;
color: #c7c7c7;
padding: 15px;
border-radius: 5px;
height: 450px;
overflow-y: auto;
}
.btn-primary, .btn-warning, .btn-danger {
margin-right: 10px;
transition: box-shadow 0.3s ease-in-out;
}
.btn-primary:hover, .btn-warning:hover, .btn-danger:hover {
box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}
.form-label {
color: #b0b0b0;
margin-bottom: 5px;
}
input.form-control {
color: #ffffff;
border-color: #6c757d;
}
input.form-control:focus {
color: #ffffff;
background-color: #343a40;
}
.form-label i {
margin-right: 5px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<i class="fas fa-rocket"></i> Server Config
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<div class="container mt-3">
<div class="row g-4">
<!-- Configuration Form -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-cogs"></i> Konfigurasi Server</h4>
</div>
<div class="card-body">
<form action="/config" method="POST" novalidate>
<div class="mb-3">
<label for="ip" class="form-label"><i class="fas fa-network-wired"></i> IP Server</label>
<input type="text" class="form-control" id="ip" name="ip" value="<%= config.ip %>" required>
<div class="invalid-feedback">
Silakan masukkan IP server.
</div>
</div>
<div class="mb-3">
<label for="port" class="form-label"><i class="fas fa-server"></i> Port</label>
<input type="number" class="form-control" id="port" name="port" value="<%= config.port %>" required>
<div class="invalid-feedback">
Silakan masukkan port.
</div>
</div>
<div class="mb-3">
<label for="loginurl" class="form-label"><i class="fas fa-sign-in-alt"></i> Login URL</label>
<input type="url" class="form-control" id="loginurl" name="loginurl" value="<%= config.loginurl %>" required>
<div class="invalid-feedback">
Silakan masukkan Login URL yang valid.
</div>
</div>
<div class="mb-3">
<label for="cdn" class="form-label"><i class="fas fa-cloud"></i> CDN Path</label>
<input type="text" class="form-control" id="cdn" name="cdn" value="<%= config.cdn %>" required>
<div class="invalid-feedback">
Silakan masukkan CDN Path.
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label"><i class="fas fa-user"></i> Username (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="username" name="username" value="<%= config.username %>" required>
<div class="invalid-feedback">
Silakan masukkan Username untuk mengganti username.
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label"><i class="fas fa-lock"></i> Password (ADMIN LOGIN)</label>
<input type="text" class="form-control" id="password" name="password" value="<%= config.password %>" required>
<div class="invalid-feedback">
Silakan masukkan Password untuk mengganti password.
</div>
</div>
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Simpan Konfigurasi</button>
<button type="button" class="btn btn-warning" id="restartButton"><i class="fas fa-sync-alt"></i> Restart HTTP</button>
<button type="button" class="btn btn-danger" id="shutdownButton"><i class="fas fa-power-off"></i> Shutdown HTTP</button>
</div>
</form>
</div>
</div>
</div>
<!-- Server Logs Section -->
<div class="col-12 col-lg-6">
<div class="card shadow-lg">
<div class="card-header bg-secondary">
<h4 class="mb-0"><i class="fas fa-terminal"></i> Server Logs</h4>
</div>
<div class="card-body">
<pre id="serverLogs"></pre>
</div>
</div>
</div>
</div>
</div>
<script>
function stripAnsiCodes(text) {
return text.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
}
function fetchLogs() {
fetch('/logs')
.then(response => response.json())
.then(data => {
const cleanLogs = data.logs.map(log => stripAnsiCodes(log));
document.getElementById('serverLogs').textContent = cleanLogs.join('\n');
})
.catch(error => console.error('Error while fetching logs:', error));
}
setInterval(fetchLogs, 5000);
fetchLogs();
document.getElementById('restartButton').addEventListener('click', function () {
if (confirm('Are you sure you want to restart the server? This will temporarily disconnect all users.')) {
fetch('/restart', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with restart request:', error));
}
});
document.getElementById('shutdownButton').addEventListener('click', function () {
if (confirm('Are you sure you want to shutdown the server?')) {
fetch('/shutdown', { method: 'POST' })
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error with shutdown request:', error));
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
</body>
</html>
Key Changes:
Strip ANSI Codes: A stripAnsiCodes function is added to remove any ANSI escape codes from the logged text before displaying it in the browser.
Glow Effect for Buttons: Added a CSS rule for a glow effect on button hover, making the interface more interactive and visually appealing.
These enhancements should help streamline the log display while adding a visually pleasing interaction for buttons. Adjust further as per your specific design needs!