<?php
/*
* weathermap5rrd - index.php
* Copyright (C) 2008 Zdenek Styblik
*
* 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.
*
* Authors:
* Zdenek Styblik ~ 2007-2008
* Alexandre Fontelle ~ 2005-2006
* original file: linkgraph.php
*
*/
class linkgraph extends defaultLib
{
public $settings;
function __construct()
{
$this->settings = new StdClass;
$settings = $this->settings;
$settings->layout = "linkgraph.xsl";
$settings->xmlobject = new StdClass;
}
public function init()
{
$xml = $this->settings->xmlobject;
$path = $this->getPath();
if (isset($_GET['link']) && !empty($_GET['link']))
{
$linkname = urldecode($_GET['link']);
} else {
$xml->error = "Incorrect call to graph.php. Link variable is not defined";
return;
}
if (isset($_GET['config']) && !empty($_GET['config'])) {
$cfgfile = urldecode($_GET['config']);
} else {
$cfgfile = NULL;
}
if (isset($_GET['limit']) && $_GET['limit'] == 1) {
$limit = true;
} else {
$limit = false;
}
require_once "{$path}lib/configfile.php";
$configfile = new config_file($cfgfile);
if ($configfile->readConfig() != false)
{
$config = $configfile->getConfig();
$period = "6hours";
if (isset($config->links) && is_object($config->links))
{
$links = $config->links;
}
else
{
$xml->error = "no links were defined;";
return;
} /* not isset($config->links) */
if (isset($config->nodes) && is_object($config->nodes))
{
$nodes = $config->nodes;
}
else
{
$xml->error = "no nodes were defined;";
return;
} /* not isset($config->nodes) */
if (isset($_GET['period']) && !empty($_GET['period']))
$period = urldecode($_GET["period"]);
if (isset($_GET['type']) && !empty($_GET['type']))
$type = urldecode($_GET["type"]);
if (isset($links->{$linkname}))
{
$link = $links->{$linkname};
if (!isset($link->target) && (!isset($link->targetin) && !isset($link->targetout)))
$xml->error = "link target files not defined";
if (!isset($link->targetin))
$link->targetin = $link->target;
if (!isset($link->targetout))
$link->targetout = $link->target;
if (!isset($link->inpos) || !is_numeric($link->inpos))
$link->inpos = 1;
if (!isset($link->outpos) || !is_numeric($link->outpos))
$link->outpos = 2;
require_once "{$path}lib/rrd.php";
$rrdtools = new rrdtools();
if (($rrain = $rrdtools->get_rra_name($link->targetin, $link->inpos)) == NULL)
$xml->error = 'rrain failed;';
if (($rraout = $rrdtools->get_rra_name($link->targetout, $link->outpos)) == NULL)
$xml->error = 'rraout failed;';
if ($limit == false)
{
$xml->im[0] = new StdClass;
$xml->im[0]->name = "img0";
$xml->im[0]->link = "http://" . $this->getHostname() . dirname($_SERVER['PHP_SELF'])
. "/graph.php?link={$link->name}&from={$nodes->{$link->to}->name}&to="
. $nodes->{$link->from}->name . "&rrdin={$link->targetin}&rrdout="
. $link->targetout . "&inpos={$link->inpos}&outpos=" . $link->outpos
. "&unit={$link->unit}&period=1hour";
$xml->im[1] = new StdClass;
$xml->im[1]->name = "img1";
$xml->im[1]->link = "http://" . $this->getHostname() . dirname($_SERVER['PHP_SELF'])
. "/graph.php?link={$link->name}&from={$nodes->{$link->to}->name}&to="
. $nodes->{$link->from}->name . "&rrdin={$link->targetin}&rrdout="
. $link->targetout . "&inpos={$link->inpos}&outpos=" . $link->outpos
. "&unit={$link->unit}&period=1day";
$xml->im[2] = new StdClass;
$xml->im[2]->name = "img2";
$xml->im[2]->link = "http://" . $this->getHostname() . dirname($_SERVER['PHP_SELF'])
. "/graph.php?link={$link->name}&from={$nodes->{$link->to}->name}&to="
. $nodes->{$link->from}->name . "&rrdin={$link->targetin}&rrdout="
. $link->targetout . "&inpos={$link->inpos}&outpos=" . $link->outpos
. "&unit={$link->unit}&period=1week";
$xml->im[3] = new StdClass;
$xml->im[3]->name = "img3";
$xml->im[3]->link = "http://" . $this->getHostname() . dirname($_SERVER['PHP_SELF'])
. "/graph.php?link={$link->name}&from={$nodes->{$link->to}->name}&to="
. $nodes->{$link->from}->name . "&rrdin={$link->targetin}&rrdout="
. $link->targetout . "&inpos={$link->inpos}&outpos=" . $link->outpos
. "&unit={$link->unit}&period=1month";
}
else
{
$xml->im[0] = new StdClass;
$xml->im[0]->name = "img0";
$xml->im[0]->link = "http://". $this->getHostname() . dirname($_SERVER['PHP_SELF'])
. "/graph.php?link={$link->name}&from={$nodes->{$link->to}->name}&to="
. $nodes->{$link->from}->name . "&rrdin={$link->targetin}&rrdout="
. $link->targetout . "&inpos={$link->inpos}&outpos=" . $link->outpos
. "&unit={$link->unit}&period=1hour";
} /* not $limit */
}
else
{
$xml->error = 'link not set;';
} /* not isset($links->linkname) */
return 0;
}
else
{
$xml->error = "config file not found;";
return 0;
} /* not $configfile->readConfig() */
}
}
?>