Imported Upstream version 0.6.24+dfsg1
This commit is contained in:
148
share/pnp/application/controllers/ajax.php
Normal file
148
share/pnp/application/controllers/ajax.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Ajax controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Ajax_Controller extends System_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
url::redirect("start", 302);
|
||||
}
|
||||
|
||||
public function search() {
|
||||
$query = pnp::clean($this->input->get('term'));
|
||||
$result = array();
|
||||
if(strlen($query)>=1) {
|
||||
$hosts = $this->data->getHosts();
|
||||
foreach($hosts as $host){
|
||||
if(preg_match("/$query/i",$host['name'])){
|
||||
array_push($result,$host['name']);
|
||||
}
|
||||
}
|
||||
echo json_encode($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($what){
|
||||
if($what == 'timerange'){
|
||||
$this->session->delete('start');
|
||||
$this->session->delete('end');
|
||||
$this->session->set('timerange-reset', 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function filter($what){
|
||||
if($what == 'set-sfilter'){
|
||||
$this->session->set('sfilter', $_POST['sfilter']);
|
||||
}elseif($what == 'set-spfilter'){
|
||||
$this->session->set('spfilter', $_POST['spfilter']);
|
||||
}elseif($what == 'set-pfilter'){
|
||||
$this->session->set('pfilter', $_POST['pfilter']);
|
||||
}
|
||||
}
|
||||
|
||||
public function basket($action=FALSE){
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
$host = false;
|
||||
$service = false;
|
||||
$basket = array();
|
||||
|
||||
if($action == "list"){
|
||||
$basket = $this->session->get("basket");
|
||||
if(is_array($basket) && sizeof($basket) > 0){
|
||||
foreach($basket as $item){
|
||||
printf("<li class=\"ui-state-default %s\" id=\"%s\"><a title=\"%s\" id=\"%s\"><img width=12px height=12px src=\"%smedia/images/remove.png\"></a>%s</li>\n",
|
||||
"basket_action_remove",
|
||||
$item,
|
||||
$item,
|
||||
Kohana::lang('common.basket-remove', $item),
|
||||
url::base(),
|
||||
pnp::shorten($item)
|
||||
);
|
||||
}
|
||||
}
|
||||
}elseif($action == "add"){
|
||||
$item = $_POST['item'];
|
||||
$basket = $this->session->get("basket");
|
||||
if(!is_array($basket)){
|
||||
$basket[] = "$item";
|
||||
}else{
|
||||
if(!in_array($item,$basket)){
|
||||
$basket[] = $item;
|
||||
}
|
||||
}
|
||||
$this->session->set("basket", $basket);
|
||||
foreach($basket as $item){
|
||||
printf("<li class=\"ui-state-default %s\" id=\"%s\"><a title=\"%s\" id=\"%s\"><img width=12px height=12px src=\"%smedia/images/remove.png\"></a>%s</li>\n",
|
||||
"basket_action_remove",
|
||||
$item,
|
||||
$item,
|
||||
Kohana::lang('common.basket-remove', $item),
|
||||
url::base(),
|
||||
pnp::shorten($item)
|
||||
);
|
||||
}
|
||||
}elseif($action == "sort"){
|
||||
$items = $_POST['items'];
|
||||
$basket = explode(',', $items);
|
||||
array_pop($basket);
|
||||
$this->session->set("basket", $basket);
|
||||
foreach($basket as $item){
|
||||
printf("<li class=\"ui-state-default %s\" id=\"%s\"><a title=\"%s\" id=\"%s\"><img width=12px height=12px src=\"%smedia/images/remove.png\"></a>%s</li>\n",
|
||||
"basket_action_remove",
|
||||
$item,
|
||||
$item,
|
||||
Kohana::lang('common.basket-remove', $item),
|
||||
url::base(),
|
||||
pnp::shorten($item)
|
||||
);
|
||||
}
|
||||
}elseif($action == "remove"){
|
||||
$basket = $this->session->get("basket");
|
||||
$item_to_remove = $_POST['item'];
|
||||
$new_basket = array();
|
||||
foreach($basket as $item){
|
||||
if($item == $item_to_remove){
|
||||
continue;
|
||||
}
|
||||
$new_basket[] = $item;
|
||||
}
|
||||
$basket = $new_basket;
|
||||
$this->session->set("basket", $basket);
|
||||
foreach($basket as $item){
|
||||
printf("<li class=\"ui-state-default %s\" id=\"%s\"><a title=\"%s\" id=\"%s\"><img width=12px height=12px src=\"%smedia/images/remove.png\"></a>%s</li>\n",
|
||||
"basket_action_remove",
|
||||
$item,
|
||||
$item,
|
||||
Kohana::lang('common.basket-remove', $item),
|
||||
url::base(),
|
||||
pnp::shorten($item)
|
||||
);
|
||||
}
|
||||
}elseif($action == "clear"){
|
||||
$this->session->delete("basket");
|
||||
}else{
|
||||
echo "Action $action not known";
|
||||
}
|
||||
$basket = $this->session->get("basket");
|
||||
if(is_array($basket) && sizeof($basket) == 0){
|
||||
echo Kohana::lang('common.basket-empty');
|
||||
}else{
|
||||
echo "<div align=\"center\" class=\"p2\">\n";
|
||||
echo "<button id=\"show\">".Kohana::lang('common.basket-show')."</button>\n";
|
||||
echo "<button id=\"clear\">".Kohana::lang('common.basket-clear')."</button>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
share/pnp/application/controllers/color.php
Normal file
26
share/pnp/application/controllers/color.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Debug controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Color_Controller extends System_Controller {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
$this->template->color = $this->add_view('color');
|
||||
$this->template->color->color_box = $this->add_view('color_box');
|
||||
$this->template->color->logo_box = $this->add_view('logo_box');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->scheme = $this->config->scheme;
|
||||
|
||||
}
|
||||
}
|
||||
66
share/pnp/application/controllers/debug.php
Normal file
66
share/pnp/application/controllers/debug.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Debug controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Debug_Controller extends System_Controller {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
$this->template->debug = $this->add_view('debug');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
if(isset($this->host) && isset($this->service)){
|
||||
$this->url = "?host=".$this->host."&srv=".$this->service;
|
||||
if($this->start){
|
||||
$this->url .= "&start=".$this->start;
|
||||
$this->session->set("start", $this->start);
|
||||
}
|
||||
if($this->end){
|
||||
$this->url .= "&end=".$this->end;
|
||||
$this->session->set("end", $this->end);
|
||||
}
|
||||
$services = $this->data->getServices($this->host);
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view);
|
||||
$this->is_authorized = $this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']);
|
||||
$this->title = "Service Details ". $this->host ." -> " . $this->data->MACRO['DISP_SERVICEDESC'];
|
||||
}elseif(isset($this->host)){
|
||||
$this->is_authorized = $this->auth->is_authorized($this->host);
|
||||
if($this->view == ""){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
if($this->start){
|
||||
$this->url .= "&start=".$this->start;
|
||||
$this->session->set("start", $this->start);
|
||||
}
|
||||
if($this->end){
|
||||
$this->url .= "&end=".$this->end;
|
||||
$this->session->set("end", $this->end);
|
||||
}
|
||||
$this->title = "Start $this->host";
|
||||
$services = $this->data->getServices($this->host);
|
||||
$this->title = "Service Overview for $this->host";
|
||||
foreach($services as $service){
|
||||
if($service['state'] == 'active')
|
||||
$this->data->buildDataStruct($this->host,$service['name'],$this->view);
|
||||
}
|
||||
}else{
|
||||
if(isset($this->host)){
|
||||
url::redirect("/graph");
|
||||
}else{
|
||||
throw new Kohana_Exception('error.get-first-host');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
80
share/pnp/application/controllers/docs.php
Normal file
80
share/pnp/application/controllers/docs.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Docs controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Docs_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
$this->template->docs = $this->add_view('docs');
|
||||
$this->template->docs->search_box = $this->add_view('search_box');
|
||||
$this->template->docs->docs_box = $this->add_view('docs_box');
|
||||
$this->template->docs->logo_box = $this->add_view('logo_box');
|
||||
$this->doc_language = $this->config->conf['doc_language'];
|
||||
}
|
||||
|
||||
public function index(){
|
||||
url::redirect("docs/view/");
|
||||
}
|
||||
|
||||
public function view($lang=FALSE, $page=FALSE){
|
||||
if($lang == FALSE){
|
||||
if(!in_array($this->config->conf['lang'],$this->doc_language) ){
|
||||
$this->lang = $this->doc_language[0];
|
||||
}else{
|
||||
$this->lang = $this->config->conf['lang'] ;
|
||||
}
|
||||
}else{
|
||||
if(in_array($lang,$this->doc_language) ){
|
||||
$this->lang = $lang;
|
||||
}else{
|
||||
$this->lang = $this->doc_language[0];
|
||||
url::redirect("docs/view/");
|
||||
}
|
||||
}
|
||||
|
||||
if($page == FALSE){
|
||||
url::redirect("docs/view/".$this->lang."/start");
|
||||
}
|
||||
|
||||
$this->page = $page;
|
||||
$file = sprintf("documents/%s/%s.html", $this->lang, $this->page);
|
||||
$file_toc = sprintf("documents/%s/start.html", $this->lang);
|
||||
if(!file_exists($file)){
|
||||
url::redirect("docs/view/start");
|
||||
}
|
||||
$this->content = file_get_contents($file);
|
||||
$toc = file( $file_toc );
|
||||
$this->toc = "";
|
||||
$in = FALSE;
|
||||
foreach($toc as $t){
|
||||
if(preg_match("/SECTION/", $t) ){
|
||||
$in = ! $in;
|
||||
continue;
|
||||
}
|
||||
if($in == TRUE){
|
||||
$this->toc .= $t;
|
||||
}
|
||||
}
|
||||
#
|
||||
# some string replacements
|
||||
#
|
||||
$this->toc = str_replace("/de/pnp-0.6/", "", $this->toc);
|
||||
$this->toc = str_replace("/pnp-0.6/", "", $this->toc);
|
||||
$this->toc = preg_replace("/<h2>.*<\/h2>/", "" , $this->toc);
|
||||
$this->content = str_replace("/templates/", "http://docs.pnp4nagios.org/templates/", $this->content);
|
||||
$this->content = str_replace("/de/pnp-0.6/", "", $this->content);
|
||||
$this->content = str_replace("/pnp-0.6/", "", $this->content);
|
||||
$this->content = str_replace("/_media", url::base()."documents/_media", $this->content);
|
||||
$this->content = str_replace("gallery", "", $this->content);
|
||||
$this->content = str_replace("/_detail", url::base()."documents/_media", $this->content);
|
||||
$this->content = str_replace("/lib/images", url::base()."documents/images", $this->content);
|
||||
$this->graph_width = ($this->config->conf['graph_width'] + 140);
|
||||
}
|
||||
}
|
||||
129
share/pnp/application/controllers/graph.php
Normal file
129
share/pnp/application/controllers/graph.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Graph controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Graph_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
if (isset($this->version) && $this->version == "tiny" )
|
||||
$this->template->graph = $this->add_view('graph_tiny');
|
||||
else
|
||||
$this->template->graph = $this->add_view('graph');
|
||||
$this->template->zoom_header = $this->add_view('zoom_header');
|
||||
$this->template->zoom_header->graph_width = ($this->config->conf['zgraph_width'] + 140);
|
||||
$this->template->zoom_header->graph_height = ($this->config->conf['zgraph_height'] + 230);
|
||||
$this->template->graph->icon_box = $this->add_view('icon_box');
|
||||
$this->template->graph->icon_box->position = "graph";
|
||||
$this->template->graph->icon_box->xml_icon = TRUE;
|
||||
$this->template->graph->icon_box->pdf_icon = TRUE;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->template->graph->graph_content = $this->add_view('graph_content');
|
||||
$this->template->graph->graph_content->graph_width = ($this->config->conf['graph_width'] + 85);
|
||||
$this->template->graph->graph_content->timerange_select = $this->add_view('timerange_select');
|
||||
$this->template->graph->header = $this->add_view('header');
|
||||
$this->template->graph->search_box = $this->add_view('search_box');
|
||||
$this->template->graph->service_box = $this->add_view('service_box');
|
||||
$this->template->graph->basket_box = $this->add_view('basket_box');
|
||||
$this->template->graph->widget_menu = $this->add_view('widget_menu');
|
||||
$this->template->graph->graph_content->widget_graph = $this->add_view('widget_graph');
|
||||
// Change the status box while multisite theme is in use
|
||||
if($this->theme == "multisite"){
|
||||
$this->template->graph->status_box = $this->add_view('multisite_box');
|
||||
$this->template->graph->status_box->base_url = $this->config->conf['multisite_base_url'];
|
||||
$this->template->graph->status_box->site = $this->config->conf['multisite_site'];
|
||||
}else{
|
||||
$this->template->graph->status_box = $this->add_view('status_box');
|
||||
}
|
||||
// Service Details
|
||||
if($this->host != "" && $this->service != ""){
|
||||
$this->service = pnp::clean($this->service);
|
||||
$this->host = pnp::clean($this->host);
|
||||
$this->url = "?host=".$this->host."&srv=".$this->service;
|
||||
$services = $this->data->getServices($this->host);
|
||||
#Landingpage for mobile devices
|
||||
if($this->isMobileDevice()){
|
||||
url::redirect( "mobile/host/".urlencode($this->host)."/".urlencode($this->service) );
|
||||
}
|
||||
#print Kohana::debug($services);
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view);
|
||||
$this->is_authorized = $this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']);
|
||||
|
||||
$this->title = Kohana::lang('common.service-details') . " ". $this->host ." -> " . $this->data->MACRO['DISP_SERVICEDESC'];
|
||||
$this->template->graph->graph_content->graph_width = ($this->data->STRUCT[0]['GRAPH_WIDTH'] + 85);
|
||||
// Status Box Vars
|
||||
$this->template->graph->status_box->host = $this->data->MACRO['DISP_HOSTNAME'];
|
||||
$this->template->graph->status_box->lhost = $this->data->MACRO['HOSTNAME'];
|
||||
$this->template->graph->status_box->service = $this->data->MACRO['DISP_SERVICEDESC'];
|
||||
$this->template->graph->status_box->lservice = $this->data->MACRO['SERVICEDESC'];
|
||||
$this->template->graph->status_box->timet = date($this->config->conf['date_fmt'],intval($this->data->MACRO['TIMET']));
|
||||
// Service Box Vars
|
||||
$this->template->graph->service_box->services = $services;
|
||||
$this->template->graph->service_box->host = $this->host;
|
||||
// Timerange Box Vars
|
||||
$this->template->graph->timerange_box = $this->add_view('timerange_box');
|
||||
$this->template->graph->timerange_box->timeranges = $this->data->TIMERANGE;
|
||||
//
|
||||
// Host Overview
|
||||
}elseif($this->host != ""){
|
||||
$this->is_authorized = $this->auth->is_authorized($this->host);
|
||||
$this->host = pnp::clean($this->host);
|
||||
#Landingpage for mobile devices
|
||||
if($this->isMobileDevice()){
|
||||
url::redirect( "mobile/host/".urlencode($this->host) );
|
||||
}
|
||||
if($this->view == ""){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
$this->url = "?host=".$this->host;
|
||||
$this->title = Kohana::lang('common.start'). " ". $this->host;
|
||||
$services = $this->data->getServices($this->host);
|
||||
// Status Box Vars
|
||||
$this->template->graph->status_box->host = $this->data->MACRO['DISP_HOSTNAME'];
|
||||
$this->template->graph->status_box->lhost = $this->data->MACRO['HOSTNAME'];
|
||||
$this->template->graph->status_box->shost = pnp::shorten($this->data->MACRO['DISP_HOSTNAME']);
|
||||
$this->template->graph->status_box->timet = date($this->config->conf['date_fmt'],intval($this->data->MACRO['TIMET']));
|
||||
// Service Box Vars
|
||||
$this->template->graph->service_box->services = $services;
|
||||
$this->template->graph->service_box->host = $this->host;
|
||||
// Timerange Box Vars
|
||||
$this->template->graph->timerange_box = $this->add_view('timerange_box');
|
||||
$this->template->graph->timerange_box->timeranges = $this->data->TIMERANGE;
|
||||
|
||||
$this->template->graph->icon_box->xml_icon = FALSE;
|
||||
|
||||
$this->title = Kohana::lang('common.service-overview', $this->host);
|
||||
foreach($services as $service){
|
||||
if($service['state'] == 'active')
|
||||
$this->data->buildDataStruct($this->host,$service['name'],$this->view);
|
||||
}
|
||||
}else{
|
||||
#Landingpage for mobile devices
|
||||
if($this->isMobileDevice()){
|
||||
url::redirect("mobile");
|
||||
return;
|
||||
}
|
||||
if($this->isAuthorizedFor('host_overview' ) ){
|
||||
$this->host = $this->data->getFirstHost();
|
||||
if(isset($this->host)){
|
||||
url::redirect("graph?host=".$this->host);
|
||||
}else{
|
||||
throw new Kohana_Exception('error.get-first-host');
|
||||
}
|
||||
}else{
|
||||
throw new Kohana_Exception('error.not_authorized_for_host_overview');
|
||||
}
|
||||
}
|
||||
$this->template->graph->logo_box = $this->add_view('logo_box');
|
||||
$this->template->graph->header->title = $this->title;
|
||||
}
|
||||
}
|
||||
56
share/pnp/application/controllers/image.php
Normal file
56
share/pnp/application/controllers/image.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Image controller.
|
||||
*
|
||||
* @package pnp4nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Image_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
if($this->input->get('w') != "" )
|
||||
$this->rrdtool->config->conf['graph_width'] = intval($this->input->get('w'));
|
||||
if($this->input->get('graph_width') != "" )
|
||||
$this->rrdtool->config->conf['graph_width'] = intval($this->input->get('graph_width'));
|
||||
|
||||
if($this->input->get('h') != "" )
|
||||
$this->rrdtool->config->conf['graph_height'] = intval($this->input->get('h'));
|
||||
if($this->input->get('graph_height') != "" )
|
||||
$this->rrdtool->config->conf['graph_height'] = intval($this->input->get('graph_height'));
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
if($this->tpl != ""){
|
||||
$this->data->buildDataStruct('__special',$this->tpl,$this->view,$this->source);
|
||||
#print Kohana::debug($this->data->STRUCT);
|
||||
$image = $this->rrdtool->doImage($this->data->STRUCT[0]['RRD_CALL']);
|
||||
$this->rrdtool->streamImage($image);
|
||||
}elseif(isset($this->host) && isset($this->service)){
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view,$this->source);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE)
|
||||
$this->rrdtool->streamImage("ERROR: NOT_AUTHORIZED");
|
||||
|
||||
#print Kohana::debug($this->data->STRUCT);
|
||||
if(sizeof($this->data->STRUCT) > 0){
|
||||
$image = $this->rrdtool->doImage($this->data->STRUCT[0]['RRD_CALL']);
|
||||
}else{
|
||||
$image = FALSE;
|
||||
}
|
||||
$this->rrdtool->streamImage($image);
|
||||
}else{
|
||||
url::redirect("start", 302);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
75
share/pnp/application/controllers/json.php
Normal file
75
share/pnp/application/controllers/json.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Json controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Json_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(){
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
// Service Details
|
||||
if($this->host != "" && $this->service != ""){
|
||||
$services = $this->data->getServices($this->host);
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){
|
||||
print json_encode("not authorized");
|
||||
exit;
|
||||
}
|
||||
$i = 0;
|
||||
$json = array();
|
||||
foreach($this->data->STRUCT as $struct){
|
||||
$json[$i]['image_url'] = "host=".$struct['MACRO']['HOSTNAME']."&srv=".$struct['MACRO']['SERVICEDESC']."&source=".$struct['SOURCE']."&view=".$struct['VIEW'];
|
||||
$json[$i]['ds_name'] = $struct['ds_name'];
|
||||
$json[$i]['start'] = $struct['TIMERANGE']['start'];
|
||||
$json[$i]['end'] = $struct['TIMERANGE']['end'];
|
||||
$json[$i]['title'] = $struct['TIMERANGE']['title'];
|
||||
$i++;
|
||||
}
|
||||
print json_encode($json);
|
||||
// Host Overview
|
||||
}elseif($this->host != ""){
|
||||
if($this->auth->is_authorized($this->host) === FALSE){
|
||||
print json_encode("not authorized");
|
||||
exit;
|
||||
}
|
||||
$services = $this->data->getServices($this->host);
|
||||
foreach($services as $service){
|
||||
if($service['state'] == 'active'){
|
||||
$this->data->buildDataStruct($this->host,$service['name'],$this->view);
|
||||
}
|
||||
}
|
||||
$i = 0;
|
||||
$json = array();
|
||||
foreach($this->data->STRUCT as $struct){
|
||||
$json[$i]['image_url'] = "host=".$struct['MACRO']['HOSTNAME']."&srv=".$struct['MACRO']['SERVICEDESC']."&source=".$struct['SOURCE']."&view=".$struct['VIEW'];
|
||||
$json[$i]['servicedesc'] = $struct['MACRO']['SERVICEDESC'];
|
||||
$json[$i]['ds_name'] = $struct['ds_name'];
|
||||
$json[$i]['start'] = $struct['TIMERANGE']['start'];
|
||||
$json[$i]['end'] = $struct['TIMERANGE']['end'];
|
||||
$json[$i]['title'] = $struct['TIMERANGE']['title'];
|
||||
$i++;
|
||||
}
|
||||
print json_encode($json);
|
||||
}else{
|
||||
$this->hosts = $this->data->getHosts();
|
||||
$i = 0;
|
||||
$json = array();
|
||||
foreach($this->hosts as $host){
|
||||
if($host['state'] == "active"){
|
||||
$json[$i]['hostname'] = $host['name'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print json_encode($json);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
share/pnp/application/controllers/mobile.php
Normal file
93
share/pnp/application/controllers/mobile.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Mobile controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Mobile_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->session->set('classic-ui',0);
|
||||
$this->template = $this->add_view('mobile');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->template->home = $this->add_view('mobile_home');
|
||||
}
|
||||
public function about()
|
||||
{
|
||||
$this->template->about = $this->add_view('mobile_about');
|
||||
}
|
||||
public function overview()
|
||||
{
|
||||
$this->template->overview = $this->add_view('mobile_overview');
|
||||
$this->template->overview->hosts = $this->data->getHosts();
|
||||
}
|
||||
public function host($host=NULL)
|
||||
{
|
||||
$this->template->host = $this->add_view('mobile_host');
|
||||
$this->is_authorized = $this->auth->is_authorized($host);
|
||||
$this->template->host->hostname = $host;
|
||||
$this->template->host->services = $this->data->getServices($host);
|
||||
}
|
||||
public function graph($host=NULL, $service=NULL)
|
||||
{
|
||||
$this->template->graph = $this->add_view('mobile_graph');
|
||||
$this->data->buildDataStruct($host,$service,$this->view);
|
||||
$this->is_authorized = $this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']);
|
||||
}
|
||||
public function search()
|
||||
{
|
||||
$this->template->query = $this->add_view('mobile_search');
|
||||
$query = pnp::clean($this->input->post('term'));
|
||||
$result = array();
|
||||
if(strlen($query)>=1) {
|
||||
$hosts = $this->data->getHosts();
|
||||
foreach($hosts as $host){
|
||||
if(preg_match("/$query/i",$host['name'])){
|
||||
array_push($result,$host['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->result = $result;
|
||||
}
|
||||
public function pages($page=NULL)
|
||||
{
|
||||
$this->is_authorized=TRUE;
|
||||
if($this->view == ""){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
|
||||
$this->page = $page;
|
||||
if(is_null($this->page) ){
|
||||
$this->template->pages = $this->add_view('mobile_pages');
|
||||
$this->template->pages->pages = $this->data->getPages();
|
||||
return;
|
||||
}
|
||||
$this->data->buildPageStruct($this->page,$this->view);
|
||||
$this->template->pages = $this->add_view('mobile_graph');
|
||||
}
|
||||
public function special($tpl=NULL)
|
||||
{
|
||||
$this->tpl = $tpl;
|
||||
if(is_null($this->tpl) ){
|
||||
$this->template->special = $this->add_view('mobile_special');
|
||||
$this->template->special->templates = $this->data->getSpecialTemplates();
|
||||
return;
|
||||
}
|
||||
$this->data->buildDataStruct('__special',$this->tpl,$this->view);
|
||||
$this->template->special = $this->add_view('mobile_graph_special');
|
||||
}
|
||||
public function go($goto=FALSE)
|
||||
{
|
||||
if($goto == 'classic'){
|
||||
$this->session->set('classic-ui',1);
|
||||
url::redirect("graph");
|
||||
}
|
||||
}
|
||||
}
|
||||
80
share/pnp/application/controllers/page.php
Normal file
80
share/pnp/application/controllers/page.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Graph controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Page_Controller extends System_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
$this->template->page = $this->add_view('page');
|
||||
$this->template->zoom_header = $this->add_view('zoom_header');
|
||||
$this->template->zoom_header->graph_width = ($this->config->conf['graph_width'] + 140);
|
||||
$this->template->zoom_header->graph_height = ($this->config->conf['graph_height'] + 230);
|
||||
$this->template->page->graph_content = $this->add_view('graph_content');
|
||||
$this->template->page->graph_content->graph_width = ($this->config->conf['graph_width'] + 85);
|
||||
$this->template->page->graph_content->timerange_select = $this->add_view('timerange_select');
|
||||
$this->template->page->header = $this->add_view('header');
|
||||
$this->template->page->search_box = $this->add_view('search_box');
|
||||
$this->template->page->logo_box = $this->add_view('logo_box');
|
||||
$this->is_authorized=TRUE;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
if( !$this->isAuthorizedFor('pages') ){
|
||||
throw new Kohana_Exception('error.auth-pages');
|
||||
}
|
||||
$this->page = pnp::clean($this->input->get('page'));
|
||||
if($this->page == ""){
|
||||
$this->page = $this->data->getFirstPage();
|
||||
}
|
||||
if($this->page == ""){
|
||||
throw new Kohana_Exception('error.page-config-dir', $this->config->conf['page_dir']);
|
||||
}
|
||||
if($this->view == ""){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
$this->data->buildPageStruct($this->page,$this->view);
|
||||
$this->template->page->header->title = Kohana::lang('common.page',$this->data->PAGE_DEF['page_name']);
|
||||
$this->url = "?page&page=$this->page";
|
||||
// Timerange Box Vars
|
||||
$this->template->page->timerange_box = $this->add_view('timerange_box');
|
||||
$this->template->page->timerange_box->timeranges = $this->data->TIMERANGE;
|
||||
// Pages Box
|
||||
$this->pages = $this->data->getPages();
|
||||
$this->template->page->pages_box = $this->add_view('pages_box');
|
||||
$this->template->page->pages_box->pages = $this->pages;
|
||||
// Basket Box
|
||||
$this->template->page->basket_box = $this->add_view('basket_box');
|
||||
// Icon Box
|
||||
$this->template->page->icon_box = $this->add_view('icon_box');
|
||||
$this->template->page->icon_box->position = "page";
|
||||
|
||||
}
|
||||
|
||||
public function basket(){
|
||||
$basket = $this->session->get("basket");
|
||||
if(is_array($basket) && sizeof($basket) > 0){
|
||||
$this->data->buildBasketStruct($basket,$this->view);
|
||||
$this->template->page->basket_box = $this->add_view('basket_box');
|
||||
$this->template->page->header->title = Kohana::lang('common.page-basket');
|
||||
$this->url = "basket?";
|
||||
// Timerange Box Vars
|
||||
$this->template->page->timerange_box = $this->add_view('timerange_box');
|
||||
$this->template->page->timerange_box->timeranges = $this->data->TIMERANGE;
|
||||
// Pages Box
|
||||
$this->pages = $this->data->getPages();
|
||||
$this->template->page->pages_box = $this->add_view('pages_box');
|
||||
$this->template->page->pages_box->pages = $this->pages;
|
||||
// Icon Box
|
||||
$this->template->page->icon_box = $this->add_view('icon_box');
|
||||
$this->template->page->icon_box->position = "basket";
|
||||
}else{
|
||||
url::redirect("start", 302);
|
||||
}
|
||||
}
|
||||
}
|
||||
280
share/pnp/application/controllers/pdf.php
Normal file
280
share/pnp/application/controllers/pdf.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* PDF controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Pdf_Controller extends System_Controller {
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
|
||||
$this->use_bg = 0;
|
||||
$this->bg = $this->config->conf['background_pdf'];
|
||||
$this->pdf_page_size = $this->config->conf['pdf_page_size'];
|
||||
$this->pdf_margin_left = $this->config->conf['pdf_margin_left'];
|
||||
$this->pdf_margin_top = $this->config->conf['pdf_margin_top'];
|
||||
$this->pdf_margin_right = $this->config->conf['pdf_margin_right'];
|
||||
|
||||
// Define PDF background per url option
|
||||
if(isset($this->bg) && $this->bg != ""){
|
||||
if( is_readable( Kohana::config( 'core.pnp_etc_path')."/".$this->bg ) ){
|
||||
$this->bg = Kohana::config('core.pnp_etc_path')."/".$this->bg;
|
||||
}else{
|
||||
$this->bg = $this->config->conf['background_pdf'];
|
||||
}
|
||||
}
|
||||
// Use PDF background if readable
|
||||
if(is_readable($this->bg)){
|
||||
$this->use_bg = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->tpl = pnp::clean($this->input->get('tpl'));
|
||||
$this->type = "normal";
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
// Service Details
|
||||
if($this->host != "" && $this->service != ""){
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view);
|
||||
// Host Overview
|
||||
}elseif($this->host != ""){
|
||||
if($this->view == ""){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
$services = $this->data->getServices($this->host);
|
||||
foreach($services as $service){
|
||||
if($service['state'] == 'active')
|
||||
$this->data->buildDataStruct($this->host,$service['name'],$this->view);
|
||||
}
|
||||
// Special Templates
|
||||
}elseif($this->tpl != ""){
|
||||
$this->data->buildDataStruct('__special',$this->tpl,$this->view);
|
||||
$this->type = 'special';
|
||||
}else{
|
||||
$this->host = $this->data->getFirstHost();
|
||||
if(isset($this->host)){
|
||||
url::redirect("/graph?host=$this->host");
|
||||
}else{
|
||||
throw new Kohana_User_Exception('Hostname not set ;-)', "RTFM my Friend, RTFM!");
|
||||
}
|
||||
}
|
||||
#throw new Kohana_Exception(print_r($this->data->STRUCT,TRUE));
|
||||
/*
|
||||
* PDF Output
|
||||
*/
|
||||
$pdf = new PDF("P", "mm", $this->pdf_page_size);
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->SetAutoPageBreak('off');
|
||||
$pdf->SetMargins($this->pdf_margin_left,$this->pdf_margin_top,$this->pdf_margin_right);
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){
|
||||
$pdf->setSourceFile($this->bg);
|
||||
$tplIdx = $pdf->importPage(1,'/MediaBox');
|
||||
$pdf->useTemplate($tplIdx);
|
||||
}
|
||||
$pdf->SetCreator('Created with PNP');
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
// Title
|
||||
$header = TRUE;
|
||||
foreach($this->data->STRUCT as $key=>$data){
|
||||
if($key != 0){
|
||||
$header = FALSE;
|
||||
}
|
||||
if ($pdf->GetY() > 200) {
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){$pdf->useTemplate($tplIdx);}
|
||||
}
|
||||
if($this->type == 'normal'){
|
||||
if($data['LEVEL'] == 0){
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->CELL(120, 10, $data['MACRO']['DISP_HOSTNAME']." -- ".$data['MACRO']['DISP_SERVICEDESC'], 0, 1);
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pdf->CELL(120, 5, $data['TIMERANGE']['title']." (".$data['TIMERANGE']['f_start']." - ".$data['TIMERANGE']['f_end'].")", 0, 1);
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}else{
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}
|
||||
}elseif($this->type == 'special'){
|
||||
if($header){
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->CELL(120, 10, $data['MACRO']['TITLE'], 0, 1);
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pdf->CELL(120, 5, $data['TIMERANGE']['title']." (".$data['TIMERANGE']['f_start']." - ".$data['TIMERANGE']['f_end'].")", 0, 1);
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}else{
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pdf->CELL(120, 5, $data['TIMERANGE']['title']." (".$data['TIMERANGE']['f_start']." - ".$data['TIMERANGE']['f_end'].")", 0, 1);
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}
|
||||
}
|
||||
$image = $this->rrdtool->doImage($data['RRD_CALL'],$out='PDF');
|
||||
$img = $this->rrdtool->saveImage($image);
|
||||
$Y = $pdf->GetY();
|
||||
$cell_height = ($img['height'] * 0.23);
|
||||
$cell_width = ($img['width'] * 0.23);
|
||||
$pdf->Image($img['file'], $this->pdf_margin_left, $Y, $cell_width, $cell_height, 'PNG');
|
||||
$pdf->CELL(120, $cell_height, '', 0, 1);
|
||||
unlink($img['file']);
|
||||
}
|
||||
$pdf->Output("pnp4nagios.pdf","I");
|
||||
|
||||
}
|
||||
|
||||
public function page($page){
|
||||
$this->start = $this->input->get('start');
|
||||
$this->end = $this->input->get('end');
|
||||
$this->view = "";
|
||||
|
||||
if(isset($_GET['view']) && $_GET['view'] != "" ){
|
||||
$this->view = pnp::clean($_GET['view']);
|
||||
}
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
$this->data->buildPageStruct($page,$this->view);
|
||||
// Define PDF background per url option
|
||||
if(isset($this->data->PAGE_DEF['background_pdf'])){
|
||||
if( is_readable( Kohana::config( 'core.pnp_etc_path')."/".$this->data->PAGE_DEF['background_pdf'] ) ){
|
||||
$this->bg = Kohana::config('core.pnp_etc_path')."/".$this->data->PAGE_DEF['background_pdf'];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* PDF Output
|
||||
*/
|
||||
$pdf = new PDF("P", "mm", $this->pdf_page_size);
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->SetAutoPageBreak('off');
|
||||
$pdf->SetMargins($this->pdf_margin_left,$this->pdf_margin_top,$this->pdf_margin_right);
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){
|
||||
$pdf->setSourceFile($this->bg);
|
||||
$tplIdx = $pdf->importPage(1,'/MediaBox');
|
||||
$pdf->useTemplate($tplIdx);
|
||||
}
|
||||
|
||||
$pdf->SetCreator('Created with PNP');
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
// Title
|
||||
foreach($this->data->STRUCT as $data){
|
||||
if ($pdf->GetY() > 200) {
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){$pdf->useTemplate($tplIdx);}
|
||||
}
|
||||
if($data['LEVEL'] == 0){
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->CELL(120, 10, $data['MACRO']['DISP_HOSTNAME']." -- ".$data['MACRO']['DISP_SERVICEDESC'], 0, 1);
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pdf->CELL(120, 5, $data['TIMERANGE']['title']." (".$data['TIMERANGE']['f_start']." - ".$data['TIMERANGE']['f_end'].")", 0, 1);
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}else{
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}
|
||||
$image = $this->rrdtool->doImage($data['RRD_CALL'],$out='PDF');
|
||||
$img = $this->rrdtool->saveImage($image);
|
||||
$Y = $pdf->GetY();
|
||||
$cell_height = ($img['height'] * 0.23);
|
||||
$cell_width = ($img['width'] * 0.23);
|
||||
$pdf->Image($img['file'], $this->pdf_margin_left, $Y, $cell_width, $cell_height, 'PNG');
|
||||
$pdf->CELL(120, $cell_height, '', 0, 1);
|
||||
unlink($img['file']);
|
||||
}
|
||||
$pdf->Output("pnp4nagios.pdf","I");
|
||||
}
|
||||
|
||||
public function basket(){
|
||||
$this->start = $this->input->get('start');
|
||||
$this->end = $this->input->get('end');
|
||||
$this->view = "";
|
||||
if(isset($_GET['view']) && $_GET['view'] != "" ){
|
||||
$this->view = pnp::clean($_GET['view']);
|
||||
}
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
$basket = $this->session->get("basket");
|
||||
if(is_array($basket) && sizeof($basket) > 0){
|
||||
$this->data->buildBasketStruct($basket,$this->view);
|
||||
}
|
||||
//echo Kohana::debug($this->data->STRUCT);
|
||||
/*
|
||||
* PDF Output
|
||||
*/
|
||||
$pdf = new PDF("P", "mm", $this->pdf_page_size);
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->SetAutoPageBreak('off');
|
||||
$pdf->SetMargins($this->pdf_margin_left,$this->pdf_margin_top,$this->pdf_margin_right);
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){
|
||||
$pdf->setSourceFile($this->config->conf['background_pdf']);
|
||||
$tplIdx = $pdf->importPage(1,'/MediaBox');
|
||||
$pdf->useTemplate($tplIdx);
|
||||
}
|
||||
|
||||
$pdf->SetCreator('Created with PNP');
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
// Title
|
||||
foreach($this->data->STRUCT as $data){
|
||||
if ($pdf->GetY() > 200) {
|
||||
$pdf->AddPage();
|
||||
if($this->use_bg){$pdf->useTemplate($tplIdx);}
|
||||
}
|
||||
if($data['LEVEL'] == 0){
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->CELL(120, 10, $data['MACRO']['DISP_HOSTNAME']." -- ".$data['MACRO']['DISP_SERVICEDESC'], 0, 1);
|
||||
$pdf->SetFont('Arial', '', 10);
|
||||
$pdf->CELL(120, 5, $data['TIMERANGE']['title']." (".$data['TIMERANGE']['f_start']." - ".$data['TIMERANGE']['f_end'].")", 0, 1);
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}else{
|
||||
$pdf->SetFont('Arial', '', 8);
|
||||
$pdf->CELL(120, 5, "Datasource ".$data["ds_name"], 0, 1);
|
||||
}
|
||||
$image = $this->rrdtool->doImage($data['RRD_CALL'],$out='PDF');
|
||||
$img = $this->rrdtool->saveImage($image);
|
||||
$Y = $pdf->GetY();
|
||||
$cell_height = ($img['height'] * 0.23);
|
||||
$cell_width = ($img['width'] * 0.23);
|
||||
$pdf->Image($img['file'], $this->pdf_margin_left, $Y, $cell_width, $cell_height, 'PNG');
|
||||
$pdf->CELL(120, $cell_height, '', 0, 1);
|
||||
unlink($img['file']);
|
||||
}
|
||||
$pdf->Output("pnp4nagios.pdf","I");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
+
|
||||
*
|
||||
*/
|
||||
require Kohana::find_file('vendor/fpdf', 'fpdf');
|
||||
require Kohana::find_file('vendor/fpdf', 'fpdi');
|
||||
class PDF extends FPDI {
|
||||
//Page header
|
||||
function Header() {
|
||||
//Arial bold 10
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
}
|
||||
|
||||
//Page footer
|
||||
function Footer() {
|
||||
//Position at 1.5 cm from bottom
|
||||
$this->SetY(-20);
|
||||
//Arial italic 8
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
//Page number
|
||||
$this->Cell(0, 10, $this->PageNo() . '/{nb}', 0, 0, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
41
share/pnp/application/controllers/popup.php
Normal file
41
share/pnp/application/controllers/popup.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Popup controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Popup_Controller extends System_Controller {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('popup');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if ( $this->view == "" ){
|
||||
$this->view = $this->config->conf['overview-range'];
|
||||
}
|
||||
|
||||
$this->imgwidth = pnp::clean($this->input->get('width',$this->config->conf['popup-width']));
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
if(isset($this->host) && isset($this->service)){
|
||||
$this->data->buildDataStruct($this->host,$this->service,$this->view,$this->source);
|
||||
$this->template->host = $this->host;
|
||||
$this->template->srv = $this->service;
|
||||
$this->template->view = $this->view;
|
||||
$this->template->source = $this->source;
|
||||
$this->template->end = $this->end;
|
||||
$this->template->start = $this->start;
|
||||
$this->template->imgwidth = $this->imgwidth;
|
||||
}else{
|
||||
url::redirect("/graph");
|
||||
}
|
||||
}
|
||||
}
|
||||
52
share/pnp/application/controllers/special.php
Normal file
52
share/pnp/application/controllers/special.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Graph controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Special_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('template');
|
||||
$this->template->graph = $this->add_view('graph');
|
||||
$this->templates = $this->data->getSpecialTemplates();
|
||||
$this->data->GRAPH_TYPE = 'special';
|
||||
if($this->tpl == ''){
|
||||
if($this->templates)
|
||||
$this->tpl = $this->templates[0];
|
||||
url::redirect('special?tpl='.$this->tpl, 302);
|
||||
}
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$this->url = "?tpl=".$this->tpl;
|
||||
$this->template->zoom_header = $this->add_view('zoom_header');
|
||||
$this->template->zoom_header->graph_width = ($this->config->conf['graph_width'] + 140);
|
||||
$this->template->zoom_header->graph_height = ($this->config->conf['graph_height'] + 230);
|
||||
$this->template->graph->graph_content = $this->add_view('graph_content_special');
|
||||
$this->template->graph->graph_content->graph_width = ($this->config->conf['graph_width'] + 85);
|
||||
$this->template->graph->graph_content->timerange_select = $this->add_view('timerange_select');
|
||||
$this->template->graph->header = $this->add_view('header');
|
||||
$this->template->graph->search_box = $this->add_view('search_box');
|
||||
$this->template->graph->service_box = $this->add_view('special_templates_box');
|
||||
#$this->template->graph->status_box = $this->add_view('status_box');
|
||||
#$this->template->graph->basket_box = $this->add_view('basket_box');
|
||||
$this->template->graph->widget_menu = $this->add_view('widget_menu');
|
||||
$this->template->graph->graph_content->widget_graph = $this->add_view('widget_graph');
|
||||
#print Kohana::debug($services);
|
||||
$this->data->buildDataStruct('__special',$this->tpl,$this->view);
|
||||
$this->template->graph->icon_box = $this->add_view('icon_box');
|
||||
$this->template->graph->icon_box->position = "special";
|
||||
$this->template->graph->logo_box = $this->add_view('logo_box');
|
||||
// Timerange Box Vars
|
||||
$this->template->graph->timerange_box = $this->add_view('timerange_box');
|
||||
$this->template->graph->timerange_box->timeranges = $this->data->TIMERANGE;
|
||||
$this->template->graph->header->title = $this->data->MACRO['TITLE'];
|
||||
//print Kohana::debug($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
21
share/pnp/application/controllers/start.php
Normal file
21
share/pnp/application/controllers/start.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Default controller.
|
||||
*
|
||||
* @package pnp4nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Start_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
url::redirect("graph", 302);
|
||||
}
|
||||
|
||||
}
|
||||
210
share/pnp/application/controllers/system.php
Normal file
210
share/pnp/application/controllers/system.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* system controller.
|
||||
*
|
||||
* @package pnp4nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class System_Controller extends Template_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->data = new Data_Model();
|
||||
$this->config = new Config_Model();
|
||||
$this->rrdtool = new Rrdtool_Model();
|
||||
$this->auth = new Auth_Model();
|
||||
#$this->system = new System_Model();
|
||||
|
||||
$this->config->read_config();
|
||||
Kohana::config_set('locale.language',$this->config->conf['lang']);
|
||||
// Check for mod_rewrite
|
||||
$this->check_mod_rewrite();
|
||||
|
||||
$this->start = pnp::clean($this->input->get('start',FALSE));
|
||||
$this->end = pnp::clean($this->input->get('end',FALSE));
|
||||
$this->theme = pnp::clean($this->input->get('theme',FALSE));
|
||||
$this->view = pnp::clean($this->input->get('view', ""));
|
||||
$this->host = pnp::clean($this->input->get('host',NULL));
|
||||
$this->service = pnp::clean($this->input->get('srv',NULL));
|
||||
$this->source = pnp::clean($this->input->get('source',0));
|
||||
$this->version = pnp::clean($this->input->get('version',NULL));
|
||||
$this->tpl = pnp::clean($this->input->get('tpl'));
|
||||
$this->controller = Router::$controller;
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
if(Router::$controller != "image" && Router::$controller != "image_special"){
|
||||
$this->session = Session::instance();
|
||||
|
||||
# Session withou theme info
|
||||
if($this->session->get("theme","new") == "new"){
|
||||
if($this->theme){
|
||||
# store $this->theme if available
|
||||
Kohana::config_set('core.theme',$this->theme);
|
||||
$this->session->set('theme', $this->theme );
|
||||
}else{
|
||||
# set $this->theme to default value
|
||||
$this->theme = $this->config->conf['ui-theme'];
|
||||
Kohana::config_set('core.theme',$this->theme);
|
||||
}
|
||||
# Sesion with theme info
|
||||
}else{
|
||||
if($this->theme && $this->theme != 'default'){
|
||||
# store $this->theme if available
|
||||
$this->session->set('theme', $this->theme );
|
||||
Kohana::config_set('core.theme',$this->theme);
|
||||
}elseif($this->theme == 'default'){
|
||||
# reset to default theme
|
||||
$this->theme = $this->config->conf['ui-theme'];
|
||||
$this->session->set('theme', $this->theme );
|
||||
Kohana::config_set('core.theme',$this->theme);
|
||||
}else{
|
||||
# set $this->theme with session infos
|
||||
$this->theme = $this->session->get('theme');
|
||||
Kohana::config_set('core.theme',$this->theme);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->start && $this->end ){
|
||||
if($this->session->get('timerange-reset',0) == 0){
|
||||
$this->session->set("start", $this->start);
|
||||
$this->session->set("end", $this->end);
|
||||
}else{
|
||||
$this->session->set('timerange-reset', 0);
|
||||
}
|
||||
}
|
||||
if($this->start && !$this->end){
|
||||
if($this->session->get('timerange-reset',0) == 0){
|
||||
$this->session->set("start", $this->start);
|
||||
$this->session->set("end", "");
|
||||
}else{
|
||||
$this->session->set('timerange-reset', 0);
|
||||
}
|
||||
}
|
||||
if($this->end && !$this->start){
|
||||
if($this->session->get('timerange-reset',0) == 0){
|
||||
$this->session->set("end", $this->end);
|
||||
$this->session->set("start", "");
|
||||
}else{
|
||||
$this->session->set('timerange-reset', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
// By defining a __call method, all pages routed to this controller
|
||||
// that result in 404 errors will be handled by this method, instead of
|
||||
// being displayed as "Page Not Found" errors.
|
||||
echo $this->_("The requested page doesn't exist") . " ($method)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle paths to current theme etc
|
||||
*
|
||||
*/
|
||||
public function add_view($view=false)
|
||||
{
|
||||
$view = trim($view);
|
||||
if (empty($view)) {
|
||||
return false;
|
||||
}
|
||||
if (!file_exists(APPPATH."/views/".$view.".php")) {
|
||||
return false;
|
||||
}
|
||||
#return new View($this->theme_path.$view);
|
||||
return new View($view);
|
||||
}
|
||||
|
||||
public function check_mod_rewrite(){
|
||||
if(!function_exists('apache_get_modules')){
|
||||
// Add index.php to every URL while not running withn apache mod_php
|
||||
Kohana::config_set('core.index_page','index.php');
|
||||
return TRUE;
|
||||
}
|
||||
if(!in_array('mod_rewrite', apache_get_modules())){
|
||||
// Add index.php to every URL while mod_rewrite is not available
|
||||
Kohana::config_set('core.index_page','index.php');
|
||||
}
|
||||
if ( $this->config->conf['use_url_rewriting'] == 0 ){
|
||||
Kohana::config_set('core.index_page','index.php');
|
||||
}
|
||||
}
|
||||
|
||||
public function isAuthorizedFor($auth) {
|
||||
$conf = $this->config->conf;
|
||||
if ($auth == "service_links") {
|
||||
|
||||
$users = explode(",", $conf['allowed_for_service_links']);
|
||||
if (in_array('EVERYONE', $users)) {
|
||||
return 1;
|
||||
}
|
||||
elseif (in_array('NONE', $users)) {
|
||||
return 0;
|
||||
}
|
||||
elseif (in_array($this->auth->REMOTE_USER, $users)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ($auth == "host_search") {
|
||||
$users = explode(",", $conf['allowed_for_host_search']);
|
||||
if (in_array('EVERYONE', $users)) {
|
||||
return 1;
|
||||
}
|
||||
elseif (in_array('NONE', $users)) {
|
||||
return 0;
|
||||
}
|
||||
elseif (in_array($this->auth->REMOTE_USER, $users)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ($auth == "host_overview") {
|
||||
$users = explode(",", $conf['allowed_for_host_overview']);
|
||||
if (in_array('EVERYONE', $users)) {
|
||||
return 1;
|
||||
}
|
||||
elseif (in_array('NONE', $users)) {
|
||||
return 0;
|
||||
}
|
||||
elseif (in_array($this->auth->REMOTE_USER, $users)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ($auth == "pages") {
|
||||
$users = explode(",", $conf['allowed_for_pages']);
|
||||
if (in_array('EVERYONE', $users)) {
|
||||
return 1;
|
||||
}
|
||||
elseif (in_array('NONE', $users)) {
|
||||
return 0;
|
||||
}
|
||||
elseif (in_array($this->auth->REMOTE_USER, $users)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
public function isMobileDevice (){
|
||||
if( $this->session->get('classic-ui',0) == 1){
|
||||
return FALSE;
|
||||
}
|
||||
if ( preg_match('/'.$this->config->conf['mobile_devices'].'/', $_SERVER['HTTP_USER_AGENT'] ) ){
|
||||
return TRUE;
|
||||
}else{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
48
share/pnp/application/controllers/xml.php
Normal file
48
share/pnp/application/controllers/xml.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Xml controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Jorg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Xml_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->config->read_config();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auto_render = FALSE;
|
||||
if($this->service == "" && $this->host == ""){
|
||||
url::redirect("graph", 302);
|
||||
}
|
||||
$this->data->readXML($this->host, $this->service);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){
|
||||
header('Content-Type: application/xml');
|
||||
print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
print "<NAGIOS>\n";
|
||||
print "<ERROR>not authorized</ERROR>\n";
|
||||
print "</NAGIOS>\n";
|
||||
exit;
|
||||
}else{
|
||||
$xmlfile = $this->config->conf['rrdbase'].$this->host."/".$this->service.".xml";
|
||||
if(is_readable($xmlfile)){
|
||||
$fh = fopen($xmlfile, 'r');
|
||||
header('Content-Type: application/xml');
|
||||
fpassthru($fh);
|
||||
fclose($fh);
|
||||
exit;
|
||||
}else{
|
||||
header('Content-Type: application/xml');
|
||||
print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
print "<NAGIOS>\n";
|
||||
print "<ERROR>file not found</ERROR>\n";
|
||||
print "</NAGIOS>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
74
share/pnp/application/controllers/xport.php
Normal file
74
share/pnp/application/controllers/xport.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Xport controller.
|
||||
*
|
||||
* @package pnp4nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Xport_Controller extends System_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Disable auto-rendering
|
||||
$this->auto_render = FALSE;
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
}
|
||||
|
||||
public function xml(){
|
||||
if(isset($this->host) && isset($this->service)){
|
||||
$this->data->buildXport($this->host,$this->service);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){
|
||||
header('Content-Type: application/xml');
|
||||
print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
print "<NAGIOS>\n";
|
||||
print "<ERROR>not authorized</ERROR>\n";
|
||||
print "</NAGIOS>\n";
|
||||
exit;
|
||||
}
|
||||
$data = $this->rrdtool->doXport($this->data->XPORT);
|
||||
header('Content-Type: application/xml');
|
||||
print $data;
|
||||
}else{
|
||||
throw new Kohana_Exception('error.xport-host-service');
|
||||
}
|
||||
}
|
||||
|
||||
public function json(){
|
||||
if(isset($this->host) && isset($this->service)){
|
||||
$this->data->buildXport($this->host,$this->service);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){
|
||||
header('Content-type: application/json');
|
||||
print json_encode("not authorized");
|
||||
exit;
|
||||
}
|
||||
$data = $this->rrdtool->doXport($this->data->XPORT);
|
||||
$json = json_encode(simplexml_load_string($data));
|
||||
header('Content-type: application/json');
|
||||
print $json;
|
||||
}else{
|
||||
throw new Kohana_Exception('error.xport-host-service');
|
||||
}
|
||||
}
|
||||
|
||||
public function csv(){
|
||||
if(isset($this->host) && isset($this->service)){
|
||||
$this->data->buildXport($this->host,$this->service);
|
||||
if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){
|
||||
header("Content-Type: text/plain; charset=UTF-8");
|
||||
print "not authorized";
|
||||
exit;
|
||||
}
|
||||
$data = $this->rrdtool->doXport($this->data->XPORT);
|
||||
$csv = $this->data->xml2csv($data);
|
||||
header("Content-Type: text/plain; charset=UTF-8");
|
||||
print $csv;
|
||||
}else{
|
||||
throw new Kohana_Exception('error.xport-host-service');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
80
share/pnp/application/controllers/zoom.php
Normal file
80
share/pnp/application/controllers/zoom.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
* Zoom controller.
|
||||
*
|
||||
* @package PNP4Nagios
|
||||
* @author Joerg Linge
|
||||
* @license GPL
|
||||
*/
|
||||
class Zoom_Controller extends System_Controller {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->template = $this->add_view('zoom');
|
||||
#$this->tpl = $this->input->get('tpl');
|
||||
$this->graph_width = $this->config->conf['zgraph_width'];
|
||||
$this->graph_height = $this->config->conf['zgraph_height'];
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
#$this->source = intval($this->input->get('source'));
|
||||
#$this->view = "";
|
||||
|
||||
#if(isset($_GET['view']) && $_GET['view'] != "" ){
|
||||
# $this->view = pnp::clean($_GET['view']);
|
||||
#}else{
|
||||
# $this->view = $this->config->conf['overview-range'];
|
||||
#}
|
||||
|
||||
#
|
||||
# Limit startto 2000/01/01
|
||||
#
|
||||
$start_limit = strtotime("2000/01/01");
|
||||
$this->start = abs((int)$this->start);
|
||||
if($this->start < $start_limit)
|
||||
$this->start = $start_limit;
|
||||
#
|
||||
# Limit end to now + one hour
|
||||
#
|
||||
$end_limit = time() + 3600;
|
||||
$this->end = abs((int)$this->end);
|
||||
if($this->end > $end_limit)
|
||||
$this->end = $end_limit;
|
||||
|
||||
$this->data->getTimeRange($this->start,$this->end,$this->view);
|
||||
|
||||
if(isset($this->tpl) && $this->tpl != 'undefined' ){
|
||||
if($this->start && $this->end ){
|
||||
$this->session->set("start", $this->start);
|
||||
$this->session->set("end", $this->end);
|
||||
}
|
||||
$this->template->tpl = $this->tpl;
|
||||
$this->template->view = $this->view;
|
||||
$this->template->source = $this->source;
|
||||
$this->template->end = $this->end;
|
||||
$this->template->start = $this->start;
|
||||
$this->url = "?tpl=".$this->tpl;
|
||||
$this->template->graph_height = $this->graph_height;
|
||||
$this->template->graph_width = $this->graph_width;
|
||||
}elseif(isset($this->host) && isset($this->service)){
|
||||
if($this->start && $this->end ){
|
||||
$this->session->set("start", $this->start);
|
||||
$this->session->set("end", $this->end);
|
||||
}
|
||||
$this->template->host = $this->host;
|
||||
$this->template->srv = $this->service;
|
||||
$this->template->view = $this->view;
|
||||
$this->template->source = $this->source;
|
||||
$this->template->end = $this->end;
|
||||
$this->template->start = $this->start;
|
||||
$this->url = "?host=".$this->host."&srv=".$this->service;
|
||||
$this->template->graph_height = $this->graph_height;
|
||||
$this->template->graph_width = $this->graph_width;
|
||||
}else{
|
||||
url::redirect("/graph");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user