Simplify pre-bootstrapping web routing

This commit is contained in:
Thomas Gelf 2014-03-27 07:25:53 +00:00
parent fdc39189aa
commit cb5d90ad41
9 changed files with 68 additions and 107 deletions

View File

@ -1,7 +1,5 @@
RewriteEngine on
RewriteBase /icingaweb
RewriteRule ^css/icinga.css css.php
RewriteRule ^js/icinga.min.js js.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

View File

@ -1,8 +0,0 @@
<?php
use Icinga\Application\EmbeddedWeb;
use Icinga\Web\StyleSheet;
require_once '/vagrant/library/Icinga/Application/EmbeddedWeb.php';
EmbeddedWeb::start('/etc/icingaweb');
Stylesheet::send();

View File

@ -1,8 +0,0 @@
<?php
use Icinga\Application\EmbeddedWeb;
use Icinga\Web\JavaScript;
require_once '/vagrant/library/Icinga/Application/EmbeddedWeb.php';
$app = EmbeddedWeb::start('/etc/icingaweb');
JavaScript::sendMinified();

View File

@ -611,15 +611,11 @@ file { '/var/www/html/icingaweb/index.php':
}
file { '/var/www/html/icingaweb/js.php':
source => 'puppet:////vagrant/.vagrant-puppet/files/var/www/html/icingaweb/js.php',
owner => 'apache',
group => 'apache',
ensure => absent,
}
file { '/var/www/html/icingaweb/css.php':
source => 'puppet:////vagrant/.vagrant-puppet/files/var/www/html/icingaweb/css.php',
owner => 'apache',
group => 'apache',
ensure => absent,
}
file { '/var/www/html/icingaweb/.htaccess':

View File

@ -1,14 +1,70 @@
<?php
$baseDir = $_SERVER['DOCUMENT_ROOT'];
namespace Icinga\Application;
if ($_SERVER['REQUEST_URI'] === '/css/icinga.css') {
include $baseDir . '/css.php';
} elseif ($_SERVER['REQUEST_URI'] === '/js/icinga.min.js') {
include $baseDir . '/js.php';
} elseif (file_exists($baseDir . $_SERVER['REQUEST_URI'])) {
return false;
use Icinga\Application\EmbeddedWeb;
use Icinga\Application\Web;
use Icinga\Web\StyleSheet;
use Icinga\Web\JavaScript;
use Icinga\Chart\Inline\PieChart;
error_reporting(E_ALL | E_STRICT);
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_ENV)) {
$configDir = $_ENV['ICINGAWEB_CONFIGDIR'];
} else {
include $baseDir . '/index.php';
$configDir = '/etc/icingaweb';
}
// TODO: Detect aliases!
$baseDir = $_SERVER['DOCUMENT_ROOT'];
$ruri = $_SERVER['REQUEST_URI'];
list($path, $params) = preg_split('/\?/', $ruri, 2);
$ruriParts = preg_split('~/~', ltrim($ruri, '/'));
if (count($ruriParts) === 2 &&
($ruriParts[0] === 'css' || $ruriParts[0] === 'js')
) {
require_once __DIR__ . '/EmbeddedWeb.php';
EmbeddedWeb::start($configDir);
switch($ruriParts[1]) {
case 'icinga.css':
Stylesheet::send();
exit;
case 'icinga.min.css':
Stylesheet::sendMinified();
exit;
case 'icinga.dev.js':
JavaScript::send();
exit;
case 'icinga.min.js':
JavaScript::sendMinified();
break;
default:
return false;
}
} elseif ($path === '/svg/chart.php') {
if (!array_key_exists('data', $_GET)) {
return false;
}
require_once __DIR__ . '/EmbeddedWeb.php';
EmbeddedWeb::start($configDir);
header('Content-Type: image/svg+xml');
$pie = new PieChart();
$pie->initFromRequest();
echo $pie->render();
} elseif (file_exists($baseDir . $ruri) && is_file($baseDir . $ruri)) {
return false;
} else {
require_once __DIR__ . '/Web.php';
Web::start($configDir)->dispatch();
}

View File

@ -1,8 +0,0 @@
<?php
use Icinga\Application\EmbeddedWeb;
use Icinga\Web\StyleSheet;
require_once dirname(__FILE__). '/../library/Icinga/Application/EmbeddedWeb.php';
EmbeddedWeb::start('@icingaweb_config_path@');
Stylesheet::send();

View File

@ -1,9 +1,4 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
require_once dirname(__FILE__). '/../library/Icinga/Application/Web.php';
use Icinga\Application\Web;
Web::start('@icingaweb_config_path@')->dispatch();
$_ENV['ICINGAWEB_CONFIGDIR'] = '@icingaweb_config_path@';
require_once dirname(__DIR__). '/library/Icinga/Application/webrouter.php';

View File

@ -1,8 +0,0 @@
<?php
use Icinga\Application\EmbeddedWeb;
use Icinga\Web\JavaScript;
require_once dirname(__FILE__). '/../library/Icinga/Application/EmbeddedWeb.php';
$app = EmbeddedWeb::start('@icingaweb_config_path@');
JavaScript::sendMinified();

View File

@ -1,52 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga Web 2.
*
* Icinga Web 2 - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
*/
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Chart\Inline\PieChart;
use Icinga\Application\Loader;
/*
* Use only autoloader and do not bootstrap EmbeddedWeb to improve performance
* of svg rendering
*/
require_once dirname(__FILE__) . '/../../library/Icinga/Application/Loader.php';
$loader = new Loader();
$loader->registerNamespace('Icinga', dirname(__FILE__) . '/../../library/Icinga');
$loader->register();
if (!array_key_exists('data', $_GET)) {
die;
}
header('Content-Type: image/svg+xml');
$pie = new PieChart();
$pie->initFromRequest();
echo $pie->render();