/** * Constructor. */ public function __construct() { $www = \LXC\Container\Variables::get('www_docroot'); // Initialize every directory in WWW as VirtualHost object. foreach (scandir($www) as $node) { if (in_array($node, array('.', '..', 'default'))) { continue; } if (!is_dir($www . '/' . $node)) { continue; } $this->data[] = new VirtualHost($www . '/' . $node); } }
$t = new \h2o(); # ROUTE /: index listing. $router->get('/', function () use($t) { $t->loadTemplate('templates/listing.html'); print $t->render(array('lxc' => \LXC\Container\Variables::get(), 'vhosts' => \LXC\VirtualHost\Listing::get(), 'hostsoutdated' => \LXC\VirtualHost\Listing::are_hosts_outdated(), 'logfiles' => \LXC\Logging\Files::get(), 'hostname' => gethostname())); }); # ROUTE /php: PHP information. $router->get('/php', function () { phpinfo(); }); # ROUTE /$LOGFILE: tail -f style log viewer. foreach (\LXC\Logging\Files::get() as $logfile) { $path = '/' . $logfile->name; $router->get($path, function () use($t, $logfile) { $t->loadTemplate('templates/logtail.html'); print $t->render(array('file' => $logfile, 'lxc' => \LXC\Container\Variables::get(), 'hostname' => gethostname())); }); $router->get($path . '/(\\d+)', function ($from_line) use($t, $logfile) { $logfile->sendPayload((int) $from_line); }); } /** * Redirect on unmatched routes. */ $router->set404(function () { header('HTTP/1.1 301 Moved Permanently'); header('Location: /'); echo '404, route not found!'; }); /** * Dispatch the request.