2014-03-04 12:13:43 +01:00
|
|
|
<?php
|
2014-07-15 13:39:22 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2014-03-04 12:13:43 +01:00
|
|
|
|
2014-03-27 08:25:53 +01:00
|
|
|
namespace Icinga\Application;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
if (isset($_SERVER['REQUEST_URI'])) {
|
|
|
|
$ruri = $_SERVER['REQUEST_URI'];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Workaround, PHPs internal Webserver seems to mess up SCRIPT_FILENAME
|
|
|
|
// as it prefixes it's absolute path with DOCUMENT_ROOT
|
|
|
|
if (preg_match('/^PHP .* Development Server/', $_SERVER['SERVER_SOFTWARE'])) {
|
|
|
|
$script = basename($_SERVER['SCRIPT_FILENAME']);
|
|
|
|
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] = '/' . $script;
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT']
|
|
|
|
. DIRECTORY_SEPARATOR
|
|
|
|
. $script;
|
|
|
|
}
|
|
|
|
|
2014-03-04 12:13:43 +01:00
|
|
|
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
2014-03-28 20:46:58 +01:00
|
|
|
$baseDir = dirname($_SERVER['SCRIPT_FILENAME']);
|
2014-03-27 09:33:45 +01:00
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
// Fix aliases
|
|
|
|
$remove = dirname($_SERVER['PHP_SELF']);
|
2014-03-27 09:33:45 +01:00
|
|
|
if (substr($ruri, 0, strlen($remove)) !== $remove) {
|
2014-04-17 18:47:01 +02:00
|
|
|
return false;
|
2014-03-27 09:33:45 +01:00
|
|
|
}
|
2014-03-27 21:00:43 +01:00
|
|
|
$ruri = ltrim(substr($ruri, strlen($remove)), '/');
|
2014-03-28 20:46:58 +01:00
|
|
|
|
2014-03-27 12:04:10 +01:00
|
|
|
if (strpos($ruri, '?') === false) {
|
|
|
|
$params = '';
|
2014-03-27 21:00:43 +01:00
|
|
|
$path = $ruri;
|
2014-03-27 12:04:10 +01:00
|
|
|
} else {
|
|
|
|
list($path, $params) = preg_split('/\?/', $ruri, 2);
|
|
|
|
}
|
2014-03-27 20:39:38 +01:00
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
$special = array(
|
|
|
|
'css/icinga.css',
|
|
|
|
'css/icinga.min.css',
|
|
|
|
'js/icinga.dev.js',
|
2014-06-12 19:33:28 +02:00
|
|
|
'js/icinga.ie8.js',
|
2014-03-28 20:46:58 +01:00
|
|
|
'js/icinga.min.js'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (in_array($path, $special)) {
|
2014-03-27 08:25:53 +01:00
|
|
|
|
2014-04-17 18:47:01 +02:00
|
|
|
include_once __DIR__ . '/EmbeddedWeb.php';
|
2014-04-17 18:59:10 +02:00
|
|
|
EmbeddedWeb::start();
|
2014-03-27 08:25:53 +01:00
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
switch($path) {
|
2014-03-27 08:25:53 +01:00
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
case 'css/icinga.css':
|
2014-03-27 08:25:53 +01:00
|
|
|
Stylesheet::send();
|
|
|
|
exit;
|
2014-03-28 20:46:58 +01:00
|
|
|
case 'css/icinga.min.css':
|
2014-03-27 08:25:53 +01:00
|
|
|
Stylesheet::sendMinified();
|
|
|
|
exit;
|
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
case 'js/icinga.dev.js':
|
2014-03-27 08:25:53 +01:00
|
|
|
JavaScript::send();
|
|
|
|
exit;
|
|
|
|
|
2014-03-28 20:46:58 +01:00
|
|
|
case 'js/icinga.min.js':
|
2014-03-27 08:25:53 +01:00
|
|
|
JavaScript::sendMinified();
|
|
|
|
break;
|
|
|
|
|
2014-06-12 19:33:28 +02:00
|
|
|
case 'js/icinga.ie8.js':
|
|
|
|
JavaScript::sendForIe8();
|
|
|
|
break;
|
|
|
|
|
2014-03-27 08:25:53 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-27 20:39:38 +01:00
|
|
|
} elseif ($path === 'svg/chart.php') {
|
2014-03-27 08:25:53 +01:00
|
|
|
if (!array_key_exists('data', $_GET)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-17 18:47:01 +02:00
|
|
|
include __DIR__ . '/EmbeddedWeb.php';
|
2014-04-17 18:59:10 +02:00
|
|
|
EmbeddedWeb::start();
|
2014-03-27 08:25:53 +01:00
|
|
|
header('Content-Type: image/svg+xml');
|
|
|
|
$pie = new PieChart();
|
|
|
|
$pie->initFromRequest();
|
2014-12-15 13:55:20 +01:00
|
|
|
$pie->toSvg();
|
2014-03-04 12:13:43 +01:00
|
|
|
|
2014-05-21 00:48:06 +02:00
|
|
|
} elseif ($path === 'png/chart.php') {
|
|
|
|
if (!array_key_exists('data', $_GET)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
include __DIR__ . '/EmbeddedWeb.php';
|
|
|
|
EmbeddedWeb::start();
|
|
|
|
header('Content-Type: image/png');
|
|
|
|
$pie = new PieChart();
|
|
|
|
$pie->initFromRequest();
|
|
|
|
$pie->toPng();
|
|
|
|
|
2014-04-17 22:58:34 +02:00
|
|
|
} elseif (file_exists($baseDir . '/' . $path) && is_file($baseDir . '/' . $path)) {
|
2014-03-04 12:13:43 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2014-04-17 18:47:01 +02:00
|
|
|
include __DIR__ . '/Web.php';
|
2014-04-17 18:59:10 +02:00
|
|
|
Web::start()->dispatch();
|
2014-03-04 12:13:43 +01:00
|
|
|
}
|
|
|
|
|