73 lines
2.4 KiB
PHP
73 lines
2.4 KiB
PHP
<?php
|
|
$generated_vhost = "";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Collect and sanitize input
|
|
$domain = htmlspecialchars($_POST['domain'] ?: 'example.com');
|
|
$email = htmlspecialchars($_POST['email'] ?: 'webmaster@localhost');
|
|
$path = htmlspecialchars($_POST['path'] ?: '/var/www/html');
|
|
$port = htmlspecialchars($_POST['port'] ?: '80');
|
|
|
|
// Create the Virtual Host template
|
|
$vhost = "<VirtualHost *:$port>\n";
|
|
$vhost .= " ServerAdmin $email\n";
|
|
$vhost .= " ServerName $domain\n";
|
|
$vhost .= " ServerAlias www.$domain\n";
|
|
$vhost .= " DocumentRoot $path\n\n";
|
|
$vhost .= " <Directory $path>\n";
|
|
$vhost .= " Options Indexes FollowSymLinks\n";
|
|
$vhost .= " AllowOverride All\n";
|
|
$vhost .= " Require all granted\n";
|
|
$vhost .= " </Directory>\n\n";
|
|
$vhost .= " ErrorLog \${APACHE_LOG_DIR}/error.log\n";
|
|
$vhost .= " CustomLog \${APACHE_LOG_DIR}/access.log combined\n";
|
|
$vhost .= "</VirtualHost>";
|
|
|
|
$generated_vhost = $vhost;
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Apache VHost Generator</title>
|
|
<link rel="stylesheet" href="css/gen.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h5><a href="https://gen.mxdev.ovh">Back to Gen. List</a></h5>
|
|
<h1>Apache VHost Generator</h1>
|
|
<h2>Language: HTML / PHP</h2>
|
|
<h4>Developper: mikx</h4>
|
|
<h4>Sources: <a href="https://mxgit.ovh/mikx/MxGen/src/branch/main/apvh">MxGit</a></h4>
|
|
<h5>Version: 0.2.0</h5>
|
|
</div>
|
|
<br><br>
|
|
<div class="container">
|
|
<form method="post">
|
|
<label>Domain Name</label>
|
|
<input type="text" name="domain" placeholder="example.com" required>
|
|
|
|
<label>Document Root Path</label>
|
|
<input type="text" name="path" placeholder="/var/www/project" required>
|
|
|
|
<label>Admin Email</label>
|
|
<input type="email" name="email" placeholder="admin@example.com">
|
|
|
|
<label>Port</label>
|
|
<input type="number" name="port" value="80">
|
|
|
|
<button type="submit">Generate Configuration</button>
|
|
</form>
|
|
|
|
<?php if ($generated_vhost): ?>
|
|
<h3>Result:</h3>
|
|
<textarea readonly><?php echo $generated_vhost; ?></textarea>
|
|
<p style="font-size: 0.8em; color: #64748b;">Copy this into your /etc/apache2/sites-available/ folder.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|