2016-10-09 16:47:49 +00:00
< ? php require '../config.php' ; ?>
<! DOCTYPE html >
< html lang = " en " >
< head >
2017-05-15 06:56:17 +00:00
< ? php echo loadClass ( 'Html' ) -> getHead (); ?>
2016-10-09 16:47:49 +00:00
</ head >
< body >
2017-05-15 06:56:17 +00:00
< ? php echo loadClass ( 'Html' ) -> getNavbar (); ?>
2016-10-09 16:47:49 +00:00
< div class = " container " >
< h1 > Virtual Hosts </ h1 >
2016-10-22 17:07:09 +00:00
< br />
< br />
2016-10-09 16:47:49 +00:00
< div class = " row " >
< div class = " col-md-12 " >
2017-05-15 06:56:17 +00:00
< ? php $vHosts = loadClass ( 'Httpd' ) -> getVirtualHosts (); ?>
2016-10-09 16:47:49 +00:00
< ? php if ( $vHosts ) : ?>
2016-10-22 15:38:21 +00:00
< table class = " table table-striped " >
2016-10-22 14:39:08 +00:00
< thead class = " thead-inverse " >
2016-10-09 16:47:49 +00:00
< tr >
< th > Project </ th >
< th > DocumentRoot </ th >
< th > Valid </ th >
< th > URL </ th >
</ th >
</ thead >
< tbody >
2016-10-11 13:45:21 +00:00
< ? php
$totals = 70 ;
$filler = ' ' ;
for ( $i = 0 ; $i < $totals ; $i ++ ) {
$filler = $filler . ' ' ;
}
?>
2016-10-09 16:47:49 +00:00
< ? php foreach ( $vHosts as $vHost ) : ?>
< tr >
< td >< ? php echo $vHost [ 'name' ]; ?> </td>
2017-05-15 06:56:17 +00:00
< td >< ? php echo loadClass ( 'Helper' ) -> getEnv ( 'HOST_PATH_HTTPD_DATADIR' ); ?> /<?php echo $vHost['name'];?>/htdocs</td>
2016-10-22 14:39:08 +00:00
< td class = " text-xs-center text-xs-small " id = " valid-<?php echo $vHost['name'] ;?> " >& nbsp ; & nbsp ; & nbsp ; </ td >
2016-10-11 13:45:21 +00:00
< td id = " href-<?php echo $vHost['name'] ;?> " >< ? php echo $filler ; ?> </td>
2016-10-09 16:47:49 +00:00
</ tr >
2016-10-11 13:45:21 +00:00
< input type = " hidden " name = " vhost[] " class = " vhost " value = " <?php echo $vHost['name'] ;?> " />
2016-10-09 16:47:49 +00:00
< ? php endforeach ; ?>
</ tbody >
</ table >
< ? php else : ?>
< h4 > No projects here .</ h4 >
2017-05-15 06:56:17 +00:00
< p > Simply create a directory in < strong >< ? php echo loadClass ( 'Helper' ) -> getEnv ( 'HOST_PATH_HTTPD_DATADIR' ); ?> </strong> on your host computer (or in <strong>/shared/httpd</strong> inside the php container).</p>
< p >< strong > Example :</ strong >< br />< ? php echo loadClass ( 'Helper' ) -> getEnv ( 'HOST_PATH_HTTPD_DATADIR' ); ?> /my_project</p>
< p > It will then be available via < strong > http :// my_project .< ? php echo loadClass ( 'Httpd' ) -> getTldSuffix (); ?> </strong></p>
2016-10-09 16:47:49 +00:00
< ? php endif ; ?>
</ div >
</ div >
</ div ><!-- /. container -->
2017-05-15 06:56:17 +00:00
< ? php echo loadClass ( 'Html' ) -> getFooter (); ?>
2016-10-11 13:45:21 +00:00
< script >
// self executing function here
( function () {
// your page initialization code here
// the DOM will be available here
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 ) {
el_valid = document . getElementById ( 'valid-' + vhost );
el_href = document . getElementById ( 'href-' + vhost );
error = this . responseText ;
2017-05-15 07:32:29 +00:00
if ( error . length && error . match ( /^ error / )) {
console . log ( error );
2016-10-22 14:39:08 +00:00
el_valid . className += ' bg-danger' ;
2016-10-11 13:45:21 +00:00
el_valid . innerHTML = 'ERR' ;
el_href . innerHTML = error ;
2017-05-15 07:32:29 +00:00
} else if ( error . length && error . match ( /^ warning / )) {
console . log ( error );
el_valid . className += ' bg-warning' ;
el_valid . innerHTML = 'WARN' ;
el_href . innerHTML = error . replace ( 'warning' , '' );
checkDns ( vhost );
2016-10-11 13:45:21 +00:00
} else {
2017-05-07 13:51:12 +00:00
checkDns ( vhost );
2016-10-11 13:45:21 +00:00
}
}
};
2016-11-15 18:39:11 +00:00
xhttp . open ( 'GET' , '_ajax_callback.php?vhost=' + vhost , true );
2016-10-11 13:45:21 +00:00
xhttp . send ();
}
2017-05-07 13:51:12 +00:00
/**
* Check if DNS record is set in / etc / hosts ( or via attached DNS server )
* for TLD_SUFFIX
*/
function checkDns ( vhost ) {
var xhttp = new XMLHttpRequest ();
2017-05-12 16:54:42 +00:00
// Timeout after XXX seconds and mark it invalid DNS
2017-05-15 06:56:17 +00:00
xhttp . timeout = < ? php echo loadClass ( 'Helper' ) -> getEnv ( 'DNS_CHECK_TIMEOUT' ); ?> 000;
2017-05-07 13:51:12 +00:00
xhttp . onreadystatechange = function ( e ) {
2017-05-12 16:54:42 +00:00
var el_valid = document . getElementById ( 'valid-' + vhost );
var el_href = document . getElementById ( 'href-' + vhost );
var error = this . responseText ;
2017-05-07 13:51:12 +00:00
if ( this . readyState == 4 && this . status == 200 ) {
2017-05-12 07:25:38 +00:00
clearTimeout ( xmlHttpTimeout );
2017-05-07 13:51:12 +00:00
el_valid . className += ' bg-success' ;
2017-05-15 07:32:29 +00:00
if ( el_valid . innerHTML != 'WARN' ) {
el_valid . innerHTML = 'OK' ;
}
el_href . innerHTML = '<a target="_blank" href="http://' + vhost + '.<?php echo loadClass(' Httpd ')->getTldSuffix().loadClass(' Httpd ')->getPort();?>">' + vhost + '.<?php echo loadClass(' Httpd ')->getTldSuffix().loadClass(' Httpd ')->getPort();?></a>' + el_href . innerHTML ;
2017-05-12 16:54:42 +00:00
} else {
//console.log(vhost);
2017-05-07 13:51:12 +00:00
}
}
2017-05-15 06:56:17 +00:00
xhttp . open ( 'GET' , 'http://' + vhost + '.<?php echo loadClass(' Httpd ')->getTldSuffix();?>/devilbox-api/status.json' , true );
2017-05-12 16:54:42 +00:00
xhttp . send ();
2017-05-15 06:56:17 +00:00
2017-05-12 16:54:42 +00:00
// Timeout to abort in 1 second
2017-05-15 06:56:17 +00:00
var xmlHttpTimeout = setTimeout ( ajaxTimeout , < ? php echo loadClass ( 'Helper' ) -> getEnv ( 'DNS_CHECK_TIMEOUT' ); ?> 000);
function ajaxTimeout ( e ) {
2017-05-12 16:54:42 +00:00
var el_valid = document . getElementById ( 'valid-' + vhost );
var el_href = document . getElementById ( 'href-' + vhost );
var error = this . responseText ;
2017-05-07 13:51:12 +00:00
el_valid . className += ' bg-danger' ;
el_valid . innerHTML = 'ERR' ;
2017-05-15 07:32:29 +00:00
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>' ;
2017-05-07 13:51:12 +00:00
}
2017-05-12 16:54:42 +00:00
}
2016-10-11 13:45:21 +00:00
var vhosts = document . getElementsByName ( 'vhost[]' );
for ( i = 0 ; i < vhosts . length ; i ++ ) {
updateStatus ( vhosts [ i ] . value );
}
})();
2017-05-12 16:54:42 +00:00
2016-10-11 13:45:21 +00:00
</ script >
2016-10-09 16:47:49 +00:00
</ body >
</ html >