Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .devilbox/www/htdocs/_ajax_callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
// ?vhost=
//
else if (isset($_GET['vhost'])) {
echo loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
$vhostResult = loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
if (strlen($vhostResult) === 0) {
echo json_encode(array('status' => 'ok', 'message' => ''));
} else if (strpos($vhostResult, 'error') === 0) {
echo json_encode(array('status' => 'error', 'message' => substr($vhostResult, 10)));
} else {
echo json_encode(array('status' => 'warning', 'message' => substr($vhostResult, 12)));
}
}


Expand Down
57 changes: 27 additions & 30 deletions .devilbox/www/htdocs/vhosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</button>
</div>
<div class="modal-body">
<?php $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]"; ?>
<?php $url = 'http://httpd'; ?>
<?php $src = file_get_contents($url.'/vhost.d/' . $vHost['name'] . '.conf'); ?>
<?php //$src = htmlentities($src); ?>
<?php $src = str_replace('<', '&lt;', $src); ?>
Expand Down Expand Up @@ -170,7 +170,7 @@
<td><?php echo $daemon['tool']; ?></td>
<td><?php echo $daemon['addr']; ?></td>
<td><?php echo $daemon['port']; ?></td>
<td>php (172.16.238.10)</td>
<td><?php echo gethostname(); ?> (<?php echo isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : 'unknown'; ?>)</td>
</tr>
<?php endforeach; ?>
</tbody>
Expand All @@ -195,26 +195,32 @@ function updateStatus(vhost) {
var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
var error = '';
var el_valid;
var el_href;

if (this.readyState == 4 && this.status == 200 || this.status == 426) {
if (this.readyState == 4 && (this.status == 200 || this.status == 426)) {
el_valid = document.getElementById('valid-' + vhost);
el_href = document.getElementById('href-' + vhost);
error = this.responseText;

if (error.length && error.match(/^error/)) {
try {
var data = JSON.parse(this.responseText);

if (data.status === 'error') {
el_valid.className += ' bg-danger';
el_valid.innerHTML = 'ERR';
el_href.innerHTML = data.message;
} else if (data.status === 'warning') {
el_valid.className += ' bg-warning';
el_valid.innerHTML = 'WARN';
el_href.innerHTML = data.message;
checkDns(vhost);
} else {
checkDns(vhost);
}
} catch (e) {
el_valid.className += ' bg-danger';
el_valid.innerHTML = 'ERR';
el_href.innerHTML = error;
} else if (error.length && error.match(/^warning/)) {
el_valid.className += ' bg-warning';
el_valid.innerHTML = 'WARN';
el_href.innerHTML = error.replace('warning', '');
checkDns(vhost);
} else {
checkDns(vhost);
el_href.innerHTML = 'Invalid response';
}
}
};
Expand All @@ -240,43 +246,34 @@ function checkDns(vhost) {
// Timeout after XXX seconds and mark it invalid DNS
xhttp.timeout = <?php echo loadClass('Helper')->getEnv('DNS_CHECK_TIMEOUT');?>000;

xhttp.onreadystatechange = function(e) {
xhttp.onreadystatechange = function() {
var el_valid = document.getElementById('valid-' + vhost);
var el_href = document.getElementById('href-' + vhost);
var error = this.responseText;

if (this.readyState == 4 && (this.status == 200 || this.status == 426)) {
clearTimeout(xmlHttpTimeout);
el_valid.className += ' bg-success';
if (el_valid.innerHTML != 'WARN') {
el_valid.innerHTML = 'OK';
}
//el_href.innerHTML = '(<a target="_blank" href="'+proto+'//localhost/devilbox-project/'+name+'">ext</a>) <a target="_blank" href="'+proto+'//'+name+port+'">'+name+port+'</a>' + el_href.innerHTML;
el_href.innerHTML = '<a target="_blank" href="'+proto+'//'+name+port+'">'+name+port+'</a>';
} else {
//console.log(vhost);
}
}
xhttp.open('POST', proto+'//'+name+port+'/devilbox-api/status.json', true);
xhttp.send();

// Timeout to abort in 1 second
var xmlHttpTimeout = setTimeout(ajaxTimeout, <?php echo loadClass('Helper')->getEnv('DNS_CHECK_TIMEOUT');?>000);
function ajaxTimeout(e) {
};
xhttp.ontimeout = function() {
var el_valid = document.getElementById('valid-' + vhost);
var el_href = document.getElementById('href-' + vhost);
var error = this.responseText;

el_valid.className += ' bg-danger';
el_valid.innerHTML = 'ERR';
el_href.innerHTML = 'No Host DNS record found. Add the following to <code>/etc/hosts</code>:<br/><code>127.0.0.1 '+vhost+'.<?php echo loadClass('Httpd')->getTldSuffix();?></code>';
}
};
xhttp.open('GET', proto+'//'+name+port+'/devilbox-api/status.json', true);
xhttp.send();

}

var vhosts = document.getElementsByName('vhost[]');

for (i = 0; i < vhosts.length; i++) {
for (var i = 0; i < vhosts.length; i++) {
updateStatus(vhosts[i].value);
}
})();
Expand Down
17 changes: 11 additions & 6 deletions .devilbox/www/include/lib/container/Httpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ public function canConnect(&$err, $hostname, $data = array())
}

// Silence errors and try to connect
$url = 'http://'.$hostname.'/'.$GLOBALS['DEVILBOX_API_PAGE'];
$url = 'http://'.$hostname.$this->getPort().'/'.$GLOBALS['DEVILBOX_API_PAGE'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Expand Down Expand Up @@ -212,6 +214,10 @@ public function getVhostBackend($vhost)
}

$fp = fopen($file, 'r');
if ($fp === false) {
loadClass('Logger')->error('Could not open backend config: ' . $file);
return 'default';
}
$cont = stream_get_contents($fp);
fclose($fp);

Expand All @@ -223,13 +229,12 @@ public function getVhostBackend($vhost)
// conf:<type>:<proto>:<server>:<port>
$arr = explode(':', $cont);

// conf:<type>:<proto>:<addr>:<port>
// Note: <addr> may contain ':' for IPv6 addresses (e.g., [::1])
$port = array_pop($arr);
$type = $arr[1];
$prot = $arr[2];
$addr = ''; // this may contain ':' itself due to IPv6 addresses
for ($i=3; $i<(count($arr)-1); $i++) {
$addr .= $arr[$i];
}
$port = $arr[count($arr) - 1];
$addr = implode(':', array_slice($arr, 3));

return $prot.'://'.$addr.':'.$port;
}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Ignore variable data
/.env
/backups/*
*-bak*

# Ignore Data dirs
/data/www/*
Expand Down Expand Up @@ -136,6 +137,9 @@
/cfg/php-startup-8.2/*.sh
/cfg/php-startup-8.3/*.sh
/cfg/php-startup-8.4/*.sh
# Ignore my local scripts...
/*php*.sh
/star*.sh

# Ignore custom Varnish configs
/cfg/varnish-4/*.vcl
Expand Down