REL-0.9 Properly check client-side DNS via ajax CSR calls

This commit is contained in:
cytopia 2017-05-12 18:54:42 +02:00
parent d6fd9d1cda
commit 83ab3d8758
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
6 changed files with 47 additions and 26 deletions

View File

@ -26,6 +26,9 @@
VirtualDocumentRoot /shared/httpd/%-2+/htdocs/
php_admin_value auto_prepend_file /opt/bin/fix-virtual-docroot.php
# Devilbox API endpoint
Alias "/devilbox-api" "/var/www/default/api/devilbox-api"
<Directory "/shared/httpd/*/htdocs/">
DirectoryIndex index.php index.html

View File

@ -26,6 +26,9 @@
VirtualDocumentRoot /shared/httpd/%-2+/htdocs/
php_admin_value auto_prepend_file /opt/bin/fix-virtual-docroot.php
# Devilbox API endpoint
Alias "/devilbox-api" "/var/www/default/api/devilbox-api"
<Directory "/shared/httpd/*/htdocs/">
DirectoryIndex index.php index.html

View File

@ -19,13 +19,20 @@ server {
try_files $uri $uri/ /index.php;
}
# PHP FPM
location ~ \.php?$ {
# Devilbox API endpoint
location ~ /devilbox-api/ {
root /var/www/default/api/;
index status.json;
# Required for DNS checking
# Allow cross-domain requests to this domain
# Used to validate if client DNS is setup correctly
if ( $http_origin ~* (https?://(localhost|127\.0\.0\.1|httpd)$) ) {
add_header "Access-Control-Allow-Origin" "$http_origin";
}
}
# PHP FPM
location ~ \.php?$ {
# PHP.INI:
# ---------------------------

View File

@ -19,13 +19,20 @@ server {
try_files $uri $uri/ /index.php;
}
# PHP FPM
location ~ \.php?$ {
# Devilbox API endpoint
location ~ /devilbox-api/ {
root /var/www/default/api/;
index status.json;
# Required for DNS checking
# Allow cross-domain requests to this domain
# Used to validate if client DNS is setup correctly
if ( $http_origin ~* (https?://(localhost|127\.0\.0\.1|httpd)$) ) {
add_header "Access-Control-Allow-Origin" "$http_origin";
}
}
# PHP FPM
location ~ \.php?$ {
# PHP.INI:
# ---------------------------

View File

@ -0,0 +1 @@
{"success":"true"}

View File

@ -98,48 +98,48 @@
*/
function checkDns(vhost) {
var xhttp = new XMLHttpRequest();
// Timeout after 1 seconds and mark it invalid DNS
xhttp.timeout = <?php echo loadClass('Docker')->getEnv('DNS_CHECK_TIMEOUT');?> * 100;
// Timeout after XXX seconds and mark it invalid DNS
xhttp.timeout = <?php echo loadClass('Docker')->getEnv('DNS_CHECK_TIMEOUT');?>000;
xhttp.onreadystatechange = function(e) {
var el_valid = document.getElementById('valid-' + vhost);
var el_href = document.getElementById('href-' + vhost);
var error = this.responseText;
xhttp.onreadystatechange = function(e) {
if (this.readyState == 4 && this.status == 200) {
clearTimeout(xmlHttpTimeout);
el_valid.className += ' bg-success';
el_valid.innerHTML = 'OK';
el_href.innerHTML = '<a target="_blank" href="http://'+vhost+'.<?php echo loadClass('Php')->getTldSuffix().$Docker->getPort();?>">'+vhost+'.<?php echo loadClass('Php')->getTldSuffix().$Docker->getPort();?></a>';
} else {
//console.log(vhost);
}
}
xhttp.ontimeout = function(e) {
xhttp.open('GET', 'http://'+vhost+'.<?php echo loadClass('Php')->getTldSuffix();?>/devilbox-api/status.json', true);
xhttp.send();
// Timeout to abort in 1 second
var xmlHttpTimeout=setTimeout(ajaxTimeout, <?php echo loadClass('Docker')->getEnv('DNS_CHECK_TIMEOUT');?>000);
function ajaxTimeout(e){
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 DNS record found: <code>127.0.0.1 '+vhost+'.<?php echo loadClass('Php')->getTldSuffix();?></code>';
}
//xhttp.abort = function(e) {
// el_valid.className += ' bg-danger';
// el_valid.innerHTML = 'ERR';
// el_href.innerHTML = 'No DNS record found: <code>127.0.0.1 '+vhost+'.<?php echo loadClass('Php')->getTldSuffix();?></code>';
//}
xhttp.open('GET', 'http://'+vhost+'.<?php echo loadClass('Php')->getTldSuffix();?>', true);
xhttp.send();
// Timeout to abort in 1 second
var xmlHttpTimeout=setTimeout(ajaxTimeout, <?php echo loadClass('Docker')->getEnv('DNS_CHECK_TIMEOUT');?>100);
function ajaxTimeout(){
xhttp.ontimeout();
}
}
}
var vhosts = document.getElementsByName('vhost[]');
for (i = 0; i < vhosts.length; i++) {
updateStatus(vhosts[i].value);
}
})();
</script>
</body>
</html>