Extend Devilbox web ui with vhost configs

This commit is contained in:
cytopia 2018-12-19 14:16:04 +01:00
parent fb5bbcd1e1
commit e8c38550c9
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
4 changed files with 104 additions and 2 deletions

View File

@ -0,0 +1,66 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
if (!isset($_GET['name'])) {
loadClass('Helper')->redirect('/vhosts.php');
}
if (!strlen($_GET['name'])) {
loadClass('Helper')->redirect('/vhosts.php');
}
$vhost = $_GET['name'];
$found = false;
$vhosts = loadClass('Httpd')->getVirtualHosts();
foreach ($vhosts as $v) {
if ($vhost == $v['name']) {
$found = true;
break;
}
}
// Be safe before using outputs
$vhost = htmlentities($vhost);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo loadClass('Html')->getHead(true); ?>
</head>
<body>
<?php echo loadClass('Html')->getNavbar(); ?>
<div class="container">
<h1>vhost-gen: <?php echo $vhost;?></h1>
<br/>
<br/>
<div class="row">
<div class="col-md-12">
<?php if (!$found): ?>
<p>The Virtual Host "<?php echo $vhost; ?>" does not exist.</p>
<?php else: ?>
<?php $tpl = loadClass('Httpd')->getVhostgenTemplatePath($vhost); ?>
<?php if (!$tpl): ?>
<p>No custom vhost-gen configuration found for "<?php echo $vhost; ?>".</p>
<?php else: ?>
<p>Note: If the resulting virtual host config does not reflect the vhost-gen template changes, you will need to restart the Devilbox.</p>
<a href="/vhosts.php"><i class="fa fa-chevron-left" aria-hidden="true"></i> Overview</a><br/>
<br/><h3>virtual host config</h3><br/>
<a title="Virtual host: <?php echo $vHost['name'];?>.conf" target="_blank" href="/vhost.d/<?php echo $vhost;?>.conf">
<i class="fa fa-external-link" aria-hidden="true"></i> <?php echo $vhost;?>.conf
</a>
<br/><br/><h3>vhost-gen config</h3><br/>
<code><?php echo $tpl; ?></code><br/><br/>
<?php $lines = file($tpl); ?>
<pre style="border: 1px solid black; padding:5px;"><code><?php foreach ($lines as $line): ?><?php echo $line; ?><?php endforeach; ?></code></pre>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div><!-- /.container -->
<?php echo loadClass('Html')->getFooter(); ?>
</body>
</html>

View File

@ -3,7 +3,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo loadClass('Html')->getHead(); ?>
<?php echo loadClass('Html')->getHead(true); ?>
</head>
<body>
@ -24,6 +24,7 @@
<tr>
<th>Project</th>
<th>DocumentRoot</th>
<th>Config</th>
<th>Valid</th>
<th>URL</th>
</tr>
@ -40,6 +41,12 @@
<tr>
<td><?php echo $vHost['name'];?></td>
<td><?php echo loadClass('Helper')->getEnv('HOST_PATH_HTTPD_DATADIR');?>/<?php echo $vHost['name'];?>/<?php echo loadClass('Helper')->getEnv('HTTPD_DOCROOT_DIR');?></td>
<td>
<a title="Virtual host: <?php echo $vHost['name'];?>.conf" target="_blank" href="/vhost.d/<?php echo $vHost['name'];?>.conf"><i class="fa fa-cog" aria-hidden="true"></i></a>
<?php if (($vhostGen = loadClass('Httpd')->getVhostgenTemplatePath($vHost['name'])) !== false): ?>
<a title="vhost-gen: <?php echo basename($vhostGen);?> for <?php echo $vHost['name'];?>" href="/info_vhostgen.php?name=<?php echo $vHost['name'];?>"><i class="fa fa-filter" aria-hidden="true"></i></a>
<?php endif; ?>
</td>
<td class="text-xs-center text-xs-small" id="valid-<?php echo $vHost['name'];?>">&nbsp;&nbsp;&nbsp;</td>
<td id="href-<?php echo $vHost['name'];?>"><?php echo $filler;?></td>
</tr>

View File

@ -165,6 +165,35 @@ class Httpd extends BaseClass implements BaseInterface
return $version;
}
public function getVhostgenTemplateName()
{
$httpd = strtolower($this->getName());
if ($httpd == 'nginx') {
return 'nginx.yml';
}
$version = $this->getVersion();
if (preg_match('/^2\.2.*/', $version)) {
return 'apache22.yml';
} elseif (preg_match('/^2\.4.*/', $version)) {
return 'apache24.yml';
} else {
return false;
}
}
public function getVhostgenTemplatePath($vhost)
{
if (!($name = $this->getVhostgenTemplateName())) {
return false;
}
$dir = loadClass('Helper')->getEnv('HTTPD_TEMPLATE_DIR');
if (is_file('/shared/httpd/'.$vhost.'/'.$dir.'/'.$name)) {
return '/shared/httpd/'.$vhost.'/'.$dir.'/'.$name;
}
return false;
}
/*********************************************************************************

View File

@ -206,7 +206,7 @@ services:
# Web Server
# ------------------------------------------------------------
httpd:
image: devilbox/${HTTPD_SERVER:-nginx-stable}:0.23
image: devilbox/${HTTPD_SERVER:-nginx-stable}:0.24
environment: