icingaweb2/library/Icinga/Application/webrouter.php

115 lines
2.7 KiB
PHP
Raw Normal View History

2014-03-04 12:13:43 +01:00
<?php
// {{{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);
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'];
$baseDir = dirname($_SERVER['SCRIPT_FILENAME']);
// Fix aliases
$remove = dirname($_SERVER['PHP_SELF']);
if (substr($ruri, 0, strlen($remove)) !== $remove) {
2014-04-17 18:47:01 +02:00
return false;
}
2014-03-27 21:00:43 +01:00
$ruri = ltrim(substr($ruri, strlen($remove)), '/');
if (strpos($ruri, '?') === false) {
$params = '';
2014-03-27 21:00:43 +01:00
$path = $ruri;
} else {
list($path, $params) = preg_split('/\?/', $ruri, 2);
}
2014-03-27 20:39:38 +01:00
$special = array(
'css/icinga.css',
'css/icinga.min.css',
'js/icinga.dev.js',
'js/icinga.ie8.js',
'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';
EmbeddedWeb::start();
2014-03-27 08:25:53 +01:00
switch($path) {
2014-03-27 08:25:53 +01:00
case 'css/icinga.css':
2014-03-27 08:25:53 +01:00
Stylesheet::send();
exit;
case 'css/icinga.min.css':
2014-03-27 08:25:53 +01:00
Stylesheet::sendMinified();
exit;
case 'js/icinga.dev.js':
2014-03-27 08:25:53 +01:00
JavaScript::send();
exit;
case 'js/icinga.min.js':
2014-03-27 08:25:53 +01:00
JavaScript::sendMinified();
break;
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';
EmbeddedWeb::start();
2014-03-27 08:25:53 +01:00
header('Content-Type: image/svg+xml');
$pie = new PieChart();
$pie->initFromRequest();
$pie->toSvg();
2014-03-04 12:13:43 +01: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();
} 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';
Web::start()->dispatch();
2014-03-04 12:13:43 +01:00
}