Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reindent php files

  • Loading branch information...
commit 035f3057f6a4cb44f17f657d6c17f6a9d358601c 1 parent 9c71cd1
@ymettier ymettier authored
Showing with 4,056 additions and 4,057 deletions.
  1. +1 −1  action.php
  2. +6 −6 etc/config.default.php
  3. +22 −22 etc/config.graph.php
  4. +1 −1  etc/config.sample.php
  5. +2,167 −2,167 etc/definitions.php
  6. +54 −54 export.php
  7. +149 −149 graph.php
  8. +221 −221 lib/class._database.php
  9. +39 −39 lib/class.folder_aggregator.php
  10. +37 −37 lib/class.folder_filling_manual.php
  11. +53 −53 lib/class.folder_filling_regex.php
  12. +30 −30 lib/class.folder_options.php
  13. +23 −23 lib/class.folder_status.php
  14. +15 −15 lib/class.load_meter.php
  15. +395 −395 lib/class.tree.php
  16. +15 −15 lib/class.vu_cpu_memory.php
  17. +51 −51 lib/common.php
  18. +633 −633 lib/functions.graph.php
  19. +5 −5 php/custom_view_default.php
  20. +15 −16 php/custom_view_folder.php
  21. +18 −18 php/folder_aggregator.php
  22. +9 −9 php/folder_filling_manual.php
  23. +12 −12 php/folder_filling_regex.php
  24. +9 −9 php/folder_options.php
  25. +2 −2 php/get_hosts.php
  26. +15 −15 php/json_actions.php
  27. +18 −18 php/json_node_datas.php
  28. +9 −9 php/json_tree.php
  29. +32 −32 php/top.php
View
2  action.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* Main dispatcher script
*
View
12 etc/config.default.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/*
*
* DO NOT MODIFY, create and use etc/config.php to overide configuration
@@ -6,11 +6,11 @@
*/
$db_config = array(
- "servername"=> "localhost",
- "username" => "root",
- "password" => "",
- "database" => "perfwatcher"
-);
+ "servername"=> "localhost",
+ "username" => "root",
+ "password" => "",
+ "database" => "perfwatcher"
+ );
$rrds_path = "/var/lib/collectd/rrd";
View
44 etc/config.graph.php
@@ -1,13 +1,13 @@
-<?php // vim:fenc=utf-8:filetype=php:ts=4
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* Configuration file for Collectd graph browser
*/
require 'etc/config.default.php';
// Array of paths when collectd's rrdtool plugin writes RRDs
if (!is_array($rrds_path)) {
- $config['datadirs'] = array($rrds_path);
+ $config['datadirs'] = array($rrds_path);
} else {
- $config['datadirs'] = $rrds_path;
+ $config['datadirs'] = $rrds_path;
}
// Width of graph to be generated by rrdgraph
$config['rrd_width'] = 600;
@@ -15,11 +15,11 @@
$config['rrd_height'] = 120;
// List of supported timespans (used for period drop-down list)
$config['timespan'] = array(
- array('name'=>'hour', 'label'=>'past hour', 'seconds'=>3600),
- array('name'=>'day', 'label'=>'past day', 'seconds'=>86400),
- array('name'=>'week', 'label'=>'past week', 'seconds'=>604800),
- array('name'=>'month', 'label'=>'past month', 'seconds'=>2678400),
- array('name'=>'year', 'label'=>'past year', 'seconds'=>31622400));
+ array('name'=>'hour', 'label'=>'past hour', 'seconds'=>3600),
+ array('name'=>'day', 'label'=>'past day', 'seconds'=>86400),
+ array('name'=>'week', 'label'=>'past week', 'seconds'=>604800),
+ array('name'=>'month', 'label'=>'past month', 'seconds'=>2678400),
+ array('name'=>'year', 'label'=>'past year', 'seconds'=>31622400));
// Interval at which values are collectd (currently ignored)
$config['rrd_interval'] = 10;
// Average rows/rra (currently ignored)
@@ -28,20 +28,20 @@
$config['rrd_opts'] = $rrdtool_options;
// Predefined set of colors for use by collectd_draw_rrd()
$config['rrd_colors'] = array(
- 'h_1'=>'F7B7B7', 'f_1'=>'FF0000', // Red
- 'h_2'=>'B7EFB7', 'f_2'=>'00E000', // Green
- 'h_3'=>'B7B7F7', 'f_3'=>'0000FF', // Blue
- 'h_4'=>'F3DFB7', 'f_4'=>'F0A000', // Yellow
- 'h_5'=>'B7DFF7', 'f_5'=>'00A0FF', // Cyan
- 'h_6'=>'DFB7F7', 'f_6'=>'A000FF', // Magenta
- 'h_7'=>'FFC782', 'f_7'=>'FF8C00', // Orange
- 'h_8'=>'DCFF96', 'f_8'=>'AAFF00', // Lime
- 'h_9'=>'83FFCD', 'f_9'=>'00FF99',
- 'h_10'=>'81D9FF', 'f_10'=>'00B2FF',
- 'h_11'=>'FF89F5', 'f_11'=>'FF00EA',
- 'h_12'=>'FF89AE', 'f_12'=>'FF0051',
- 'h_13'=>'BBBBBB', 'f_13'=>'555555',
- );
+ 'h_1'=>'F7B7B7', 'f_1'=>'FF0000', // Red
+ 'h_2'=>'B7EFB7', 'f_2'=>'00E000', // Green
+ 'h_3'=>'B7B7F7', 'f_3'=>'0000FF', // Blue
+ 'h_4'=>'F3DFB7', 'f_4'=>'F0A000', // Yellow
+ 'h_5'=>'B7DFF7', 'f_5'=>'00A0FF', // Cyan
+ 'h_6'=>'DFB7F7', 'f_6'=>'A000FF', // Magenta
+ 'h_7'=>'FFC782', 'f_7'=>'FF8C00', // Orange
+ 'h_8'=>'DCFF96', 'f_8'=>'AAFF00', // Lime
+ 'h_9'=>'83FFCD', 'f_9'=>'00FF99',
+ 'h_10'=>'81D9FF', 'f_10'=>'00B2FF',
+ 'h_11'=>'FF89F5', 'f_11'=>'FF00EA',
+ 'h_12'=>'FF89AE', 'f_12'=>'FF0051',
+ 'h_13'=>'BBBBBB', 'f_13'=>'555555',
+ );
/*
* URL to collectd's unix socket (unixsock plugin)
* enabled: 'unix:///var/run/collectd/collectd-unixsock'
View
2  etc/config.sample.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/*
*
* Copy me to config.php and edit me.
View
4,334 etc/definitions.php
2,167 additions, 2,167 deletions not shown
View
108 export.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
if (isset($_GET['type_instance']) && $_GET['type_instance'] == '_') { unset($_GET['type_instance']); }
if (isset($_GET['plugin_instance']) && $_GET['plugin_instance'] == '_') { unset($_GET['plugin_instance']); }
@@ -9,7 +9,7 @@
require 'lib/common.php';
-
+
$host = read_var('host', $_GET, null);
$plugin = read_var('plugin', $_GET, null);
$pinst = read_var('plugin_instance', $_GET, '');
@@ -27,37 +27,37 @@
$all_tinst = collectd_list_types($host, $plugin, $pinst, $type);
load_graph_definitions($logscale, $tinylegend);
if (isset($MetaGraphDefs[$type])) {
- if ($type == '_') {
- $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
- } else {
- $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $tinst, $opts);
- }
+ if ($type == '_') {
+ $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
+ } else {
+ $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $tinst, $opts);
+ }
} else {
- if (isset($GraphDefs[$type])) {
- $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
- } else {
- $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
- }
+ if (isset($GraphDefs[$type])) {
+ $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
+ } else {
+ $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
+ }
}
$prev_arg = $title = $vlabel = null;
$dss = array();
foreach($rrd_cmd as $arg) {
- if ($prev_arg == '-v') {
- $vlabel = $arg;
- } else if ($prev_arg == '-t') {
- $title = $arg;
- } else if (substr($arg, 0, 4) == 'DEF:') {
- list(,$d) = split('=', $arg);
- list($file, $ds,) = split(':', $d);
- if ($ds == 'value') {
- $tmp = split('/', $file);
- list(, $label) = split('-', substr($tmp[count($tmp)-1], 0, -4));
- } else { $label = $ds; }
- $dss[] = array('ds' => $ds, 'file' => $file, 'label' => $label);
- }
-
- $prev_arg = $arg;
+ if ($prev_arg == '-v') {
+ $vlabel = $arg;
+ } else if ($prev_arg == '-t') {
+ $title = $arg;
+ } else if (substr($arg, 0, 4) == 'DEF:') {
+ list(,$d) = split('=', $arg);
+ list($file, $ds,) = split(':', $d);
+ if ($ds == 'value') {
+ $tmp = split('/', $file);
+ list(, $label) = split('-', substr($tmp[count($tmp)-1], 0, -4));
+ } else { $label = $ds; }
+ $dss[] = array('ds' => $ds, 'file' => $file, 'label' => $label);
+ }
+
+ $prev_arg = $arg;
}
$rrd_cmd = array();
$rrd_cmd[] = '--step';
@@ -65,37 +65,37 @@
$rrd_cmd[] = '-s';
$rrd_cmd[] = $begin;
if ($end) {
- $rrd_cmd[] = '-e';
- $rrd_cmd[] = $end;
+ $rrd_cmd[] = '-e';
+ $rrd_cmd[] = $end;
}
if (isset($rrdcached) && file_exists($rrdcached)) {
- $rrd_cmd[] = "--daemon";
- $rrd_cmd[] = $rrdcached;
+ $rrd_cmd[] = "--daemon";
+ $rrd_cmd[] = $rrdcached;
}
foreach ($dss as $key => $ds) {
- $rrd_cmd[] = 'DEF:var'.$key.'='.$ds['file'].':'.$ds['ds'].':AVERAGE';
- $rrd_cmd[] = 'XPORT:var'.$key.':'.$ds['label'];
+ $rrd_cmd[] = 'DEF:var'.$key.'='.$ds['file'].':'.$ds['ds'].':AVERAGE';
+ $rrd_cmd[] = 'XPORT:var'.$key.':'.$ds['label'];
}
$out = rrd_xport($rrd_cmd);
/*
-Array
-(
- [start] => 1341226140
- [end] => 1341229740
- [step] => 60
- [data] => Array
- (
- [0] => Array
- (
- [legend] => tx
- [data] => Array
- (
- [1341226140] => 2435.9266666667
- [1341226200] => 2417.2925
-*/
+ Array
+ (
+ [start] => 1341226140
+ [end] => 1341229740
+ [step] => 60
+ [data] => Array
+ (
+ [0] => Array
+ (
+ [legend] => tx
+ [data] => Array
+ (
+ [1341226140] => 2435.9266666667
+ [1341226200] => 2417.2925
+ */
header("Pragma: public");
header("Expires: 0");
@@ -105,14 +105,14 @@
header("Content-Disposition: attachment; filename=\"graph.csv\";" );
echo "timestamp\tdate (y/m/d h:m:s)";
foreach ($out['data'] as $id => $data) {
- echo "\t".$data['legend'];
+ echo "\t".$data['legend'];
}
echo "\n";
foreach ($out['data'][0]['data'] as $time => $val) {
- echo $time."\t".date("Y/m/d H:i:s", $time);
- foreach ($out['data'] as $id => $data) {
- echo "\t".$data['data'][$time];
- }
- echo "\n";
+ echo $time."\t".date("Y/m/d H:i:s", $time);
+ foreach ($out['data'] as $id => $data) {
+ echo "\t".$data['data'][$time];
+ }
+ echo "\n";
}
?>
View
298 graph.php
@@ -1,4 +1,4 @@
-<?php // vim:fenc=utf-8:filetype=php:ts=4
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/*
* Copyright (C) 2009 Bruno Prémont <bonbons AT linux-vserver.org>
*
@@ -26,22 +26,22 @@
require 'lib/common.php';
function makeTextBlock($text, $fontfile, $fontsize, $width) {
- // TODO: handle explicit line-break!
- $words = explode(' ', $text);
- $lines = array($words[0]);
- $currentLine = 0;
+ // TODO: handle explicit line-break!
+ $words = explode(' ', $text);
+ $lines = array($words[0]);
+ $currentLine = 0;
array_shift($words);
- foreach ($words as $word) {
- $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word);
- if($lineSize[2] - $lineSize[0] < $width) {
- $lines[$currentLine] .= ' ' . $word;
- } else {
- $currentLine++;
- $lines[$currentLine] = $word;
- }
- }
- //error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines)));
- return implode("\n", $lines);
+ foreach ($words as $word) {
+ $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word);
+ if($lineSize[2] - $lineSize[0] < $width) {
+ $lines[$currentLine] .= ' ' . $word;
+ } else {
+ $currentLine++;
+ $lines[$currentLine] = $word;
+ }
+ }
+ //error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines)));
+ return implode("\n", $lines);
}
/**
@@ -52,131 +52,131 @@ function makeTextBlock($text, $fontfile, $fontsize, $width) {
* @msg Complete error message to display in place of graph content
*/
function error($code, $code_msg, $title, $msg) {
- global $config;
- header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
- header("Pragma: no-cache");
- header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
- header("Content-Type: image/png");
- $w = $config['rrd_width']+81+16;
- $h = $config['rrd_height']+79;
+ global $config;
+ header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
+ header("Pragma: no-cache");
+ header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
+ header("Content-Type: image/png");
+ $w = $config['rrd_width']+81+16;
+ $h = $config['rrd_height']+79;
- $png = imagecreate($w, $h);
-
- $c_bkgnd = imagecolorallocate($png, 255, 255, 255);
- if (isset($_GET['debug'])) {
- $c_fgnd = imagecolorallocate($png, 255, 255, 255);
- $c_blt = imagecolorallocate($png, 208, 208, 208);
- $c_brb = imagecolorallocate($png, 160, 160, 160);
- $c_grln = imagecolorallocate($png, 114, 114, 114);
- $c_grarr = imagecolorallocate($png, 128, 32, 32);
- $c_txt = imagecolorallocate($png, 0, 0, 0);
- $c_etxt = imagecolorallocate($png, 64, 0, 0);
- if (function_exists('imageantialias'))
- imageantialias($png, true);
- //imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd);
- imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
- imageline($png, 51, 30, 51, $h-43, $c_grln);
- imageline($png, 48, $h-46, $w-28, $h-46, $c_grln);
- imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr);
- imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr);
- // imageline($png, 0, 0, $w, 0, $c_blt);
- // imageline($png, 0, 1, $w, 1, $c_blt);
- // imageline($png, 0, 0, 0, $h, $c_blt);
- // imageline($png, 1, 0, 1, $h, $c_blt);
- // imageline($png, $w-1, 0, $w-1, $h, $c_brb);
- // imageline($png, $w-2, 1, $w-2, $h, $c_brb);
- // imageline($png, 1, $h-2, $w, $h-2, $c_brb);
- // imageline($png, 0, $h-1, $w, $h-1, $c_brb);
- imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
- imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
- if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
- // Detailled error message
- $fmt_msg = makeTextBlock($msg, $config['error_font'], 10, $w-86);
- $fmtbox = imagettfbbox(12, 0, $config['error_font'], $fmt_msg);
- imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $config['error_font'], $fmt_msg);
- } else {
- imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
- }
- }
- imagepng($png);
- imagedestroy($png);
+ $png = imagecreate($w, $h);
+
+ $c_bkgnd = imagecolorallocate($png, 255, 255, 255);
+ if (isset($_GET['debug'])) {
+ $c_fgnd = imagecolorallocate($png, 255, 255, 255);
+ $c_blt = imagecolorallocate($png, 208, 208, 208);
+ $c_brb = imagecolorallocate($png, 160, 160, 160);
+ $c_grln = imagecolorallocate($png, 114, 114, 114);
+ $c_grarr = imagecolorallocate($png, 128, 32, 32);
+ $c_txt = imagecolorallocate($png, 0, 0, 0);
+ $c_etxt = imagecolorallocate($png, 64, 0, 0);
+ if (function_exists('imageantialias'))
+ imageantialias($png, true);
+ //imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd);
+ imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
+ imageline($png, 51, 30, 51, $h-43, $c_grln);
+ imageline($png, 48, $h-46, $w-28, $h-46, $c_grln);
+ imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr);
+ imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr);
+ // imageline($png, 0, 0, $w, 0, $c_blt);
+ // imageline($png, 0, 1, $w, 1, $c_blt);
+ // imageline($png, 0, 0, 0, $h, $c_blt);
+ // imageline($png, 1, 0, 1, $h, $c_blt);
+ // imageline($png, $w-1, 0, $w-1, $h, $c_brb);
+ // imageline($png, $w-2, 1, $w-2, $h, $c_brb);
+ // imageline($png, 1, $h-2, $w, $h-2, $c_brb);
+ // imageline($png, 0, $h-1, $w, $h-1, $c_brb);
+ imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
+ imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
+ if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
+ // Detailled error message
+ $fmt_msg = makeTextBlock($msg, $config['error_font'], 10, $w-86);
+ $fmtbox = imagettfbbox(12, 0, $config['error_font'], $fmt_msg);
+ imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $config['error_font'], $fmt_msg);
+ } else {
+ imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
+ }
+ }
+ imagepng($png);
+ imagedestroy($png);
}
/**
* No RRD files found that could match request
*/
function error404($title, $msg) {
- return error(404, "Not found", $title, $msg);
+ return error(404, "Not found", $title, $msg);
}
/**
* Incomplete / invalid request
*/
function error400($title, $msg) {
- return error(400, "Bad request", $title, $msg);
+ return error(400, "Bad request", $title, $msg);
}
/**
* Incomplete / invalid request
*/
function error500($title, $msg) {
- return error(500, "Internal error", $title, $msg);
+ return error(500, "Internal error", $title, $msg);
}
// Process input arguments
$host = read_var('host', $_GET, null);
if (is_null($host))
- return error400("?/?-?/?", "Missing host name");
+ return error400("?/?-?/?", "Missing host name");
else if (!is_string($host))
- return error400("?/?-?/?", "Expecting exactly 1 host name");
+ return error400("?/?-?/?", "Expecting exactly 1 host name");
else if (strlen($host) == 0)
- return error400("?/?-?/?", "Host name may not be blank");
+ return error400("?/?-?/?", "Host name may not be blank");
-$plugin = read_var('plugin', $_GET, null);
+ $plugin = read_var('plugin', $_GET, null);
if (is_null($plugin))
- return error400($host.'/?-?/?', "Missing plugin name");
+ return error400($host.'/?-?/?', "Missing plugin name");
else if (!is_string($plugin))
- return error400($host.'/?-?/?', "Plugin name must be a string");
+ return error400($host.'/?-?/?', "Plugin name must be a string");
else if (strlen($plugin) == 0)
- return error400($host.'/?-?/?', "Plugin name may not be blank");
+ return error400($host.'/?-?/?', "Plugin name may not be blank");
-$pinst = read_var('plugin_instance', $_GET, '');
+ $pinst = read_var('plugin_instance', $_GET, '');
if (!is_string($pinst))
- return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string");
+ return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string");
-$type = read_var('type', $_GET, '');
+ $type = read_var('type', $_GET, '');
if (is_null($type))
- return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name");
+ return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name");
else if (!is_string($type))
- return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string");
+ return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string");
else if (strlen($type) == 0)
- return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank");
+ return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank");
-$tinst = read_var('type_instance', $_GET, '');
+ $tinst = read_var('type_instance', $_GET, '');
-$graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$type.(strlen($tinst) ? '-'.$tinst : '-*');
+ $graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$type.(strlen($tinst) ? '-'.$tinst : '-*');
-$timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']);
-$timespan_ok = false;
-foreach ($config['timespan'] as &$ts)
- if ($ts['name'] == $timespan)
- $timespan_ok = true;
+ $timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']);
+ $timespan_ok = false;
+ foreach ($config['timespan'] as &$ts)
+ if ($ts['name'] == $timespan)
+ $timespan_ok = true;
if (!$timespan_ok)
- return error400($graph_identifier, "Unknown timespan requested");
+ return error400($graph_identifier, "Unknown timespan requested");
-$begin = read_var('begin', $_GET, -86400);
-$end = read_var('end', $_GET, null);
+ $begin = read_var('begin', $_GET, -86400);
+ $end = read_var('end', $_GET, null);
-$xcenter = $begin < 0 ? $xcenter = time() + ($begin / 2) : $xcenter = $end - (($end - $begin) / 2);
-$xcenter = intval($xcenter);
+ $xcenter = $begin < 0 ? $xcenter = time() + ($begin / 2) : $xcenter = $end - (($end - $begin) / 2);
+ $xcenter = intval($xcenter);
-$xconfig = array();
+ $xconfig = array();
if(is_numeric($end) and $begin > 0 and $end - $begin > 2160000 and $end - $begin < 12960000)
{
- if($end - $begin < 12960000 - (86400*7))
- $xconfig = array('--x-grid', 'DAY:1:DAY:7:DAY:7:0:%d/%m');
- else
- $xconfig = array('--x-grid', 'DAY:1:DAY:7:DAY:14:0:%d/%m');
+ if($end - $begin < 12960000 - (86400*7))
+ $xconfig = array('--x-grid', 'DAY:1:DAY:7:DAY:7:0:%d/%m');
+ else
+ $xconfig = array('--x-grid', 'DAY:1:DAY:7:DAY:14:0:%d/%m');
}
$logscale = (boolean)read_var('logarithmic', $_GET, false);
@@ -186,76 +186,76 @@ function error500($title, $msg) {
// Check that at least 1 RRD exists for the specified request
$all_tinst = collectd_list_types($host, $plugin, $pinst, $type);
if (count($all_tinst) == 0)
- return error404($graph_identifier, "No rrd file found for graphing : $host, $plugin, $pinst, $type");
+ return error404($graph_identifier, "No rrd file found for graphing : $host, $plugin, $pinst, $type");
-// Now that we are read, do the bulk work
-load_graph_definitions($logscale, $tinylegend, $zero);
+ // Now that we are read, do the bulk work
+ load_graph_definitions($logscale, $tinylegend, $zero);
-$pinst = strlen($pinst) == 0 ? null : $pinst;
-$tinst = strlen($tinst) == 0 ? null : $tinst;
+ $pinst = strlen($pinst) == 0 ? null : $pinst;
+ $tinst = strlen($tinst) == 0 ? null : $tinst;
-$opts = array();
-$opts['timespan'] = $timespan;
+ $opts = array();
+ $opts['timespan'] = $timespan;
if ($logscale)
- $opts['logarithmic'] = 1;
+ $opts['logarithmic'] = 1;
if ($tinylegend)
- $opts['tinylegend'] = 1;
+ $opts['tinylegend'] = 1;
if ($zero)
- $opts['zero'] = 1;
+ $opts['zero'] = 1;
-$rrd_cmd = false;
-if (isset($MetaGraphDefs[$type])) {
- if ($type == '_') {
- $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
- } else {
- $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $tinst, $opts);
- }
-} else {
-// collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
- if (isset($GraphDefs[$type]))
- $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst, $opts);
- else
- $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst, $opts);
-}
+ $rrd_cmd = false;
+ if (isset($MetaGraphDefs[$type])) {
+ if ($type == '_') {
+ $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
+ } else {
+ $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $tinst, $opts);
+ }
+ } else {
+ // collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
+ if (isset($GraphDefs[$type]))
+ $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst, $opts);
+ else
+ $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst, $opts);
+ }
$rrd_cmd[] = 'VRULE:'.$GLOBALS['xcenter'].'#888888:'.date("Y/m/d H\\\\:i\\\\:s",$GLOBALS['xcenter']).'\l:dashes';
$rrd_cmd = array_merge($rrd_cmd,$xconfig);
$rrd_cmd[] = "-m";
$rrd_cmd[] = "1";
if (isset($rrdcached) && file_exists($rrdcached)) {
- $rrd_cmd[] = "--daemon";
- $rrd_cmd[] = $rrdcached;
+ $rrd_cmd[] = "--daemon";
+ $rrd_cmd[] = $rrdcached;
}
if (isset($_GET['debug'])) {
- header('Content-Type: text/plain; charset=utf-8');
- printf("Would have executed:\n%s\n", is_array($rrd_cmd) ? "'$rrdtool' 'graph' '-' '".implode("' '", $rrd_cmd )."'" : $rrd_cmd);
- return 0;
+ header('Content-Type: text/plain; charset=utf-8');
+ printf("Would have executed:\n%s\n", is_array($rrd_cmd) ? "'$rrdtool' 'graph' '-' '".implode("' '", $rrd_cmd )."'" : $rrd_cmd);
+ return 0;
} else if ($rrd_cmd) {
- if (!isset($_GET['download'])) {
- header('Content-Type: image/png');
- } else {
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private",false);
- header("Content-Type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"graph.png\";" );
- header("Content-Transfer-Encoding: binary");
- }
- header('Cache-Control: max-age=60');
- if (version_compare(phpversion("rrd"), '0.0.0', '>=')) {
- $tmpfile = tempnam('/dev/shm/','rrd-phpcollectd-');
- $ret = rrd_graph($tmpfile, $rrd_cmd);
- readfile($tmpfile);
- unlink($tmpfile);
- } else {
- $cmd = "'$rrdtool' 'graph' '-' '".implode("' '", $rrd_cmd )."'";
- echo `$cmd`;
- }
+ if (!isset($_GET['download'])) {
+ header('Content-Type: image/png');
+ } else {
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: private",false);
+ header("Content-Type: application/octet-stream");
+ header("Content-Disposition: attachment; filename=\"graph.png\";" );
+ header("Content-Transfer-Encoding: binary");
+ }
+ header('Cache-Control: max-age=60');
+ if (version_compare(phpversion("rrd"), '0.0.0', '>=')) {
+ $tmpfile = tempnam('/dev/shm/','rrd-phpcollectd-');
+ $ret = rrd_graph($tmpfile, $rrd_cmd);
+ readfile($tmpfile);
+ unlink($tmpfile);
+ } else {
+ $cmd = "'$rrdtool' 'graph' '-' '".implode("' '", $rrd_cmd )."'";
+ echo `$cmd`;
+ }
exit();
- if (!is_array($ret))
- return error500($graph_identifier, "RRD failed to generate the graph");
+ if (!is_array($ret))
+ return error500($graph_identifier, "RRD failed to generate the graph");
} else {
- return error500($graph_identifier, "Failed to tell RRD how to generate the graph");
+ return error500($graph_identifier, "Failed to tell RRD how to generate the graph");
}
?>
View
442 lib/class._database.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* Tree lib adapted from JStree http://www.jstree.com/
*
@@ -23,244 +23,244 @@
*/
class _database {
- private $link = false;
- private $sth = false;
- private $result = false;
- private $row = false;
+ private $link = false;
+ private $sth = false;
+ private $result = false;
+ private $row = false;
- public $settings = array(
- "dbtype" => "mysql",
- "servername"=> "localhost",
- "serverport"=> "3306",
- "username" => false,
- "password" => false,
- "database" => false,
- "persist" => false,
- "dieonerror"=> false,
- "show_error" => false,
- "error_file"=> true,
- "charset" => "utf8",
- );
+ public $settings = array(
+ "dbtype" => "mysql",
+ "servername"=> "localhost",
+ "serverport"=> "3306",
+ "username" => false,
+ "password" => false,
+ "database" => false,
+ "persist" => false,
+ "dieonerror"=> false,
+ "show_error" => false,
+ "error_file"=> true,
+ "charset" => "utf8",
+ );
- function __construct() {
- global $db_config;
- $this->settings = array_merge($this->settings, $db_config);
- if($this->settings["error_file"] === true) $this->settings["error_file"] = dirname(__FILE__)."/__mysql_errors.log";
- }
+ function __construct() {
+ global $db_config;
+ $this->settings = array_merge($this->settings, $db_config);
+ if($this->settings["error_file"] === true) $this->settings["error_file"] = dirname(__FILE__)."/__mysql_errors.log";
+ }
- function connect() {
- if (!$this->link) {
- $dsn = array(
- 'phptype' => $this->settings["dbtype"],
- 'username' => $this->settings["username"],
- 'password' => $this->settings["password"],
- 'hostspec' => $this->settings["servername"],
- 'port' => $this->settings["serverport"],
- 'database' => $this->settings["database"],
- );
- $options = array(
- 'debug' => 2,
- 'portability' => MDB2_PORTABILITY_ALL,
- 'persistent' => (($this->settings["persist"]) ? true : false),
- );
- $this->link =& MDB2::factory($dsn, $options);
- if(PEAR::isError($this->link)) {
- $this->error($this->link->getMessage());
- unset($this->link);
- }
- unset($this->sth);
- }
- /* if($this->link) mysql_query("SET NAMES 'utf8'"); */
+ function connect() {
+ if (!$this->link) {
+ $dsn = array(
+ 'phptype' => $this->settings["dbtype"],
+ 'username' => $this->settings["username"],
+ 'password' => $this->settings["password"],
+ 'hostspec' => $this->settings["servername"],
+ 'port' => $this->settings["serverport"],
+ 'database' => $this->settings["database"],
+ );
+ $options = array(
+ 'debug' => 2,
+ 'portability' => MDB2_PORTABILITY_ALL,
+ 'persistent' => (($this->settings["persist"]) ? true : false),
+ );
+ $this->link =& MDB2::factory($dsn, $options);
+ if(PEAR::isError($this->link)) {
+ $this->error($this->link->getMessage());
+ unset($this->link);
+ }
+ unset($this->sth);
+ }
+ /* if($this->link) mysql_query("SET NAMES 'utf8'"); */
- return ($this->link) ? true : false;
- }
+ return ($this->link) ? true : false;
+ }
- function query($sql) {
- if (!$this->link && !$this->connect()) $this->error("No connection");
- $this->result = $this->link->query($sql);
+ function query($sql) {
+ if (!$this->link && !$this->connect()) $this->error("No connection");
+ $this->result = $this->link->query($sql);
#debug# $this->log("QUERY : ".$sql);
- if(PEAR::isError($this->result)) {
- $this->error($this->result->getMessage(), "$sql");
- unset($this->result);
- return false;
- }
- return true;
- }
-
- function prepare($sql, $types = null, $result_types = null, $lobs = array()) {
- if (!$this->link && !$this->connect()) $this->error("No connection");
- if(isset($this->sth)) {
- $this->sth->free();
- if(PEAR::isError($this->sth)) {
- $this->error($this->sth->getMessage(), "$sql");
- unset($this->sth);
- return false;
- }
- }
- $this->sth = $this->link->prepare($sql, $types, $result_types, $lobs?$lobs:array());
- unset($this->result);
+ if(PEAR::isError($this->result)) {
+ $this->error($this->result->getMessage(), "$sql");
+ unset($this->result);
+ return false;
+ }
+ return true;
+ }
+
+ function prepare($sql, $types = null, $result_types = null, $lobs = array()) {
+ if (!$this->link && !$this->connect()) $this->error("No connection");
+ if(isset($this->sth)) {
+ $this->sth->free();
+ if(PEAR::isError($this->sth)) {
+ $this->error($this->sth->getMessage(), "$sql");
+ unset($this->sth);
+ return false;
+ }
+ }
+ $this->sth = $this->link->prepare($sql, $types, $result_types, $lobs?$lobs:array());
+ unset($this->result);
#debug# $this->log($sql);
- if(PEAR::isError($this->sth)) {
- $this->error($this->sth->getMessage(), "$sql");
- unset($this->sth);
- return false;
- }
- return true;
- }
-
- function execute($values = null, $result_class = true, $result_wrap_class = false) {
- if (!$this->link && !$this->connect()) $this->error("No connection");
- if(!isset($this->sth)) {
- $this->error("No prepared query");
- return false;
- }
- unset($this->result);
+ if(PEAR::isError($this->sth)) {
+ $this->error($this->sth->getMessage(), "$sql");
+ unset($this->sth);
+ return false;
+ }
+ return true;
+ }
+
+ function execute($values = null, $result_class = true, $result_wrap_class = false) {
+ if (!$this->link && !$this->connect()) $this->error("No connection");
+ if(!isset($this->sth)) {
+ $this->error("No prepared query");
+ return false;
+ }
+ unset($this->result);
#debug# $this->log("execute : ".serialize($values));
- $this->result = $this->sth->execute($values, $result_class, $result_wrap_class);
- if(PEAR::isError($this->result)) {
- $this->error($this->result->getMessage());
- unset($this->result);
- return false;
- }
- return true;
- }
-
- function free() {
- if (!$this->link && !$this->connect()) $this->error("No connection");
- if(!isset($this->sth)) {
- $this->error("No prepared query");
- return false;
- }
- $this->sth->free();
- if(PEAR::isError($this->sth)) {
- $this->error($this->sth->getMessage(), "$sql");
- unset($this->sth);
- return false;
- }
- unset($this->sth);
- return true;
- }
-
- function nextr($mode = "assoc") {
- if(!isset($this->result)) {
- $this->error("No query pending");
- return false;
- }
- unset($this->row);
- switch($mode) {
- case "assoc" : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ASSOC); break;
- case "num" : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ORDERED); break;
- default : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ASSOC); break;
- }
+ $this->result = $this->sth->execute($values, $result_class, $result_wrap_class);
+ if(PEAR::isError($this->result)) {
+ $this->error($this->result->getMessage());
+ unset($this->result);
+ return false;
+ }
+ return true;
+ }
+
+ function free() {
+ if (!$this->link && !$this->connect()) $this->error("No connection");
+ if(!isset($this->sth)) {
+ $this->error("No prepared query");
+ return false;
+ }
+ $this->sth->free();
+ if(PEAR::isError($this->sth)) {
+ $this->error($this->sth->getMessage(), "$sql");
+ unset($this->sth);
+ return false;
+ }
+ unset($this->sth);
+ return true;
+ }
+
+ function nextr($mode = "assoc") {
+ if(!isset($this->result)) {
+ $this->error("No query pending");
+ return false;
+ }
+ unset($this->row);
+ switch($mode) {
+ case "assoc" : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ASSOC); break;
+ case "num" : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ORDERED); break;
+ default : $this->row = $this->result->fetchRow(MDB2_FETCHMODE_ASSOC); break;
+ }
# $this->log("numrow/nextr : ".$this->result->numRows()." ".serialize($this->row));
- return ($this->row) ? true : false ;
- }
+ return ($this->row) ? true : false ;
+ }
- function get_row($mode = "assoc") {
- if(!$this->row) return false;
+ function get_row($mode = "assoc") {
+ if(!$this->row) return false;
- $return = array();
- switch($mode) {
- case "assoc":
- foreach($this->row as $k => $v) {
- if(!is_int($k)) $return[$k] = $v;
- }
- break;
- case "num":
- foreach($this->row as $k => $v) {
- if(is_int($k)) $return[$k] = $v;
- }
- break;
- default:
- $return = $this->row;
- break;
- }
- return array_map("stripslashes",$return);
- }
+ $return = array();
+ switch($mode) {
+ case "assoc":
+ foreach($this->row as $k => $v) {
+ if(!is_int($k)) $return[$k] = $v;
+ }
+ break;
+ case "num":
+ foreach($this->row as $k => $v) {
+ if(is_int($k)) $return[$k] = $v;
+ }
+ break;
+ default:
+ $return = $this->row;
+ break;
+ }
+ return array_map("stripslashes",$return);
+ }
- function get_all($mode = "assoc", $key = false) {
- if(!$this->result) {
- $this->error("No query pending");
- return false;
- }
- $return = array();
- while($this->nextr($mode)) {
- if($key !== false) $return[$this->f($key)] = $this->get_row($mode);
- else $return[] = $this->get_row($mode);
- }
- return $return;
- }
+ function get_all($mode = "assoc", $key = false) {
+ if(!$this->result) {
+ $this->error("No query pending");
+ return false;
+ }
+ $return = array();
+ while($this->nextr($mode)) {
+ if($key !== false) $return[$this->f($key)] = $this->get_row($mode);
+ else $return[] = $this->get_row($mode);
+ }
+ return $return;
+ }
- function f($index) {
- if(!$this->row) return false;
- return stripslashes($this->row[$index]);
- }
+ function f($index) {
+ if(!$this->row) return false;
+ return stripslashes($this->row[$index]);
+ }
-/* Unsupported */
-/* For developers, check if $this->result->seek() could fit */
-/*
- function go_to($row) {
- if(!$this->result) {
- $this->error("No query pending");
- return false;
- }
- if(!mysql_data_seek($this->result, $row)) $this->error();
- }
-*/
+ /* Unsupported */
+ /* For developers, check if $this->result->seek() could fit */
+ /*
+ function go_to($row) {
+ if(!$this->result) {
+ $this->error("No query pending");
+ return false;
+ }
+ if(!mysql_data_seek($this->result, $row)) $this->error();
+ }
+ */
- function nf() {
- if (($numb = $this->result->numRows()) === false) $this->error($this->result->getMessage());
+ function nf() {
+ if (($numb = $this->result->numRows()) === false) $this->error($this->result->getMessage());
#debug# $this->log("nf : ".$this->result->numRows()." / $numb");
- return $numb;
- }
- function af() {
- return $this->result->affectedRows();
- }
- function log($string="") {
- if(isset($this->settings["show_error"]) && $this->settings["show_error"]) echo $string;
- if($this->settings["error_file"] !== false) {
- $handle = @fopen($this->settings["error_file"], "a+");
- if($handle) {
- @fwrite($handle, "[".date("Y-m-d H:i:s")."] INFO : ".$string."\n");
- @fclose($handle);
- }
- }
- }
- function error($error, $string="") {
- if(isset($this->settings["show_error"]) && $this->settings["show_error"]) echo $error;
- if($this->settings["error_file"] !== false) {
- $handle = @fopen($this->settings["error_file"], "a+");
- if($handle) {
- @fwrite($handle, "[".date("Y-m-d H:i:s")."] ".$string." <".$error.">\n");
- @fclose($handle);
- }
- }
- if($this->settings["dieonerror"]) {
- if(isset($this->result)) $this->result->free();
- $this->link->disconnect();
- die();
- }
- }
- function insert_id($table = null, $field = null) {
- if(!$this->link) return false;
- if(isset($table) && isset($field)) $r = $this->link->lastInsertID($table,$field);
- else $r = $this->link->lastInsertID(); /* Not supported on all RDBMS */
+ return $numb;
+ }
+ function af() {
+ return $this->result->affectedRows();
+ }
+ function log($string="") {
+ if(isset($this->settings["show_error"]) && $this->settings["show_error"]) echo $string;
+ if($this->settings["error_file"] !== false) {
+ $handle = @fopen($this->settings["error_file"], "a+");
+ if($handle) {
+ @fwrite($handle, "[".date("Y-m-d H:i:s")."] INFO : ".$string."\n");
+ @fclose($handle);
+ }
+ }
+ }
+ function error($error, $string="") {
+ if(isset($this->settings["show_error"]) && $this->settings["show_error"]) echo $error;
+ if($this->settings["error_file"] !== false) {
+ $handle = @fopen($this->settings["error_file"], "a+");
+ if($handle) {
+ @fwrite($handle, "[".date("Y-m-d H:i:s")."] ".$string." <".$error.">\n");
+ @fclose($handle);
+ }
+ }
+ if($this->settings["dieonerror"]) {
+ if(isset($this->result)) $this->result->free();
+ $this->link->disconnect();
+ die();
+ }
+ }
+ function insert_id($table = null, $field = null) {
+ if(!$this->link) return false;
+ if(isset($table) && isset($field)) $r = $this->link->lastInsertID($table,$field);
+ else $r = $this->link->lastInsertID(); /* Not supported on all RDBMS */
#debug# $this->log("last id = $r");
- return($r);
- }
- function setLimit($limit, $offset=null) {
- if(!$this->link) return false;
- $this->link->setLimit($limit, $offset);
- }
- function escape($string){
- if(!$this->link) return addslashes($string);
- return $this->link->quote($string);
- }
+ return($r);
+ }
+ function setLimit($limit, $offset=null) {
+ if(!$this->link) return false;
+ $this->link->setLimit($limit, $offset);
+ }
+ function escape($string){
+ if(!$this->link) return addslashes($string);
+ return $this->link->quote($string);
+ }
- function destroy(){
- if (isset($this->result) && $this->result !== false) $this->result->free();
- if (isset($this->link)) $this->link->disconnect();
- }
+ function destroy(){
+ if (isset($this->result) && $this->result !== false) $this->result->free();
+ if (isset($this->link)) $this->link->disconnect();
+ }
}
View
78 lib/class.folder_aggregator.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,49 +21,49 @@
*/
class folder_aggregator {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- switch($this->datas['type']) {
- case 'folder':
- case 'drive':
- return true;
- break;
- default:
- return false;
- break;
- }
- }
+ function is_compatible() {
+ switch($this->datas['type']) {
+ case 'folder':
+ case 'drive':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
- function get_info() {
- global $folder_filling_plugins, $grouped_type;
- return array(
- 'title' => "Aggregated metrics from servers under this ".$this->datas['type'],
- 'content_url' => 'html/folder_aggregator.html',
- 'grouped_type' => $grouped_type
- );
- }
+ function get_info() {
+ global $folder_filling_plugins, $grouped_type;
+ return array(
+ 'title' => "Aggregated metrics from servers under this ".$this->datas['type'],
+ 'content_url' => 'html/folder_aggregator.html',
+ 'grouped_type' => $grouped_type
+ );
+ }
- function add_plugin($plugin, $cf) {
- global $jstree;
- $datas = $jstree->get_datas($this->datas['id']);
- if (!isset($datas['plugins'])) { $datas['plugins'] = array(); }
- if (!isset($datas['plugins'][$plugin[0].'-'.$cf])) {
- $datas['plugins'][$plugin[0].'-'.$cf] = true;
- $jstree->set_datas($this->datas['id'], $datas);
- }
- }
+ function add_plugin($plugin, $cf) {
+ global $jstree;
+ $datas = $jstree->get_datas($this->datas['id']);
+ if (!isset($datas['plugins'])) { $datas['plugins'] = array(); }
+ if (!isset($datas['plugins'][$plugin[0].'-'.$cf])) {
+ $datas['plugins'][$plugin[0].'-'.$cf] = true;
+ $jstree->set_datas($this->datas['id'], $datas);
+ }
+ }
- function del_plugin($plugin) {
- global $jstree;
- $datas = $jstree->get_datas($this->datas['id']);
- unset($datas['plugins'][$plugin]);
- $jstree->set_datas($this->datas['id'], $datas);
- }
+ function del_plugin($plugin) {
+ global $jstree;
+ $datas = $jstree->get_datas($this->datas['id']);
+ unset($datas['plugins'][$plugin]);
+ $jstree->set_datas($this->datas['id'], $datas);
+ }
}
?>
View
74 lib/class.folder_filling_manual.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,47 +21,47 @@
*/
class folder_filling_manual {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- switch($this->datas['type']) {
- case 'folder':
- case 'drive':
- return true;
- break;
- default:
- return false;
- break;
- }
- }
+ function is_compatible() {
+ switch($this->datas['type']) {
+ case 'folder':
+ case 'drive':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
- function get_info() {
- global $folder_filling_plugins;
- return array(
- 'title' => "Autofill this ".$this->datas['type']." using manual list",
- 'content_url' => 'html/folder_filling_manual.html'
- );
- }
-
- function get() {
- global $jstree;
- if (isset($this->datas['serverslist']) && isset($this->datas['serverslist']['manuallist'])) {
- return split("\n", trim($this->datas['serverslist']['manuallist']));
- } else { return array(); }
- }
+ function get_info() {
+ global $folder_filling_plugins;
+ return array(
+ 'title' => "Autofill this ".$this->datas['type']." using manual list",
+ 'content_url' => 'html/folder_filling_manual.html'
+ );
+ }
- function save ($list) {
- global $jstree, $id;
- $datas = $jstree->get_datas($this->datas['id']);
- if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
- $datas['serverslist']['manuallist'] = $list;
+ function get() {
+ global $jstree;
+ if (isset($this->datas['serverslist']) && isset($this->datas['serverslist']['manuallist'])) {
+ return split("\n", trim($this->datas['serverslist']['manuallist']));
+ } else { return array(); }
+ }
+
+ function save ($list) {
+ global $jstree, $id;
+ $datas = $jstree->get_datas($this->datas['id']);
+ if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
+ $datas['serverslist']['manuallist'] = $list;
$jstree->set_datas($id, $datas);
- return true;
- }
+ return true;
+ }
}
?>
View
106 lib/class.folder_filling_regex.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,64 +21,64 @@
*/
class folder_filling_regex {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- switch($this->datas['type']) {
- case 'folder':
- case 'drive':
- return true;
- break;
- default:
- return false;
- break;
- }
- }
+ function is_compatible() {
+ switch($this->datas['type']) {
+ case 'folder':
+ case 'drive':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
- function get_info() {
- global $folder_filling_plugins;
- return array(
- 'title' => "Autofill this ".$this->datas['type']." using regex",
- 'content_url' => 'html/folder_filling_regex.html'
- );
- }
+ function get_info() {
+ global $folder_filling_plugins;
+ return array(
+ 'title' => "Autofill this ".$this->datas['type']." using regex",
+ 'content_url' => 'html/folder_filling_regex.html'
+ );
+ }
- function test ($regex) {
- global $rrds_path, $jstree;
- return implode("\n", $this->get($regex));;
- }
+ function test ($regex) {
+ global $rrds_path, $jstree;
+ return implode("\n", $this->get($regex));;
+ }
- function get ($regex = null) {
- global $rrds_path, $jstree;
- if ($regex === null) {
- if (isset($this->datas['serverslist']) && isset($this->datas['serverslist']['servernameregex'])) {
- $regex = $this->datas['serverslist']['servernameregex'];
- }
- }
- $out = array();
- $dh = opendir($rrds_path);
- while ($hostdir = readdir($dh)) {
- if ($hostdir == '..' || $hostdir == '.' || $hostdir == '_csv') { continue; }
- if (substr($hostdir,0,11) != 'aggregator_' && @ereg($regex, $hostdir)) {
- $out[] = $hostdir;
- }
- }
- closedir($dh);
- return $out;
- }
+ function get ($regex = null) {
+ global $rrds_path, $jstree;
+ if ($regex === null) {
+ if (isset($this->datas['serverslist']) && isset($this->datas['serverslist']['servernameregex'])) {
+ $regex = $this->datas['serverslist']['servernameregex'];
+ }
+ }
+ $out = array();
+ $dh = opendir($rrds_path);
+ while ($hostdir = readdir($dh)) {
+ if ($hostdir == '..' || $hostdir == '.' || $hostdir == '_csv') { continue; }
+ if (substr($hostdir,0,11) != 'aggregator_' && @ereg($regex, $hostdir)) {
+ $out[] = $hostdir;
+ }
+ }
+ closedir($dh);
+ return $out;
+ }
- function save ($regex) {
- global $jstree, $id;
- $datas = $jstree->get_datas($this->datas['id']);
- if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
- $datas['serverslist']['servernameregex'] = $regex;
- $jstree->set_datas($id, $datas);
- return true;
- }
+ function save ($regex) {
+ global $jstree, $id;
+ $datas = $jstree->get_datas($this->datas['id']);
+ if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
+ $datas['serverslist']['servernameregex'] = $regex;
+ $jstree->set_datas($id, $datas);
+ return true;
+ }
}
?>
View
60 lib/class.folder_options.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,40 +21,40 @@
*/
class folder_options {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- switch($this->datas['type']) {
- case 'folder':
- case 'drive':
- return true;
- break;
- default:
- return false;
- break;
- }
- }
+ function is_compatible() {
+ switch($this->datas['type']) {
+ case 'folder':
+ case 'drive':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
- function get_info() {
- global $folder_filling_plugins;
- return array(
- 'title' => $this->datas['type']." options",
- 'content_url' => 'html/folder_options.html'
- );
- }
+ function get_info() {
+ global $folder_filling_plugins;
+ return array(
+ 'title' => $this->datas['type']." options",
+ 'content_url' => 'html/folder_options.html'
+ );
+ }
- function save ($list) {
- global $jstree, $id;
- $datas = $jstree->get_datas($this->datas['id']);
- if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
- $datas['serverslist']['manuallist'] = $list;
+ function save ($list) {
+ global $jstree, $id;
+ $datas = $jstree->get_datas($this->datas['id']);
+ if (!isset($datas['serverslist'])) { $datas['serverslist'] = array(); }
+ $datas['serverslist']['manuallist'] = $list;
$jstree->set_datas($id, $datas);
- return true;
- }
+ return true;
+ }
}
?>
View
46 lib/class.folder_status.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,31 +21,31 @@
*/
class folder_status {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- switch($this->datas['type']) {
- case 'folder':
- case 'drive':
- return true;
- break;
- default:
- return false;
- break;
- }
- }
+ function is_compatible() {
+ switch($this->datas['type']) {
+ case 'folder':
+ case 'drive':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ }
- function get_info() {
- global $folder_filling_plugins;
- return array(
- 'title' => ucfirst($this->datas['type'])." status",
- 'content_url' => 'html/folder_status.html'
- );
- }
+ function get_info() {
+ global $folder_filling_plugins;
+ return array(
+ 'title' => ucfirst($this->datas['type'])." status",
+ 'content_url' => 'html/folder_status.html'
+ );
+ }
}
?>
View
30 lib/class.load_meter.php
@@ -1,4 +1,4 @@
-<?php
+<?php # vim: set filetype=php fdm=marker sw=4 ts=4 tw=78 et :
/**
* PHP version 5
*
@@ -21,23 +21,23 @@
*/
class load_meter {
- private $datas = array();
+ private $datas = array();
- function __construct($datas) {
- $this->datas =& $datas;
- }
+ function __construct($datas) {
+ $this->datas =& $datas;
+ }
- function is_compatible() {
- return true;
- }
+ function is_compatible() {
+ return true;
+ }
- function get_info() {
- global $folder_filling_plugins;
- return array(
- 'title' => "Load Average",
- 'content_url' => 'html/load_meter.html'
- );
- }
+ function get_info() {
+ global $folder_filling_plugins;
+ return array(
+ 'title' => "Load Average",
+ 'content_url' => 'html/load_meter.html'
+ );
+ }
}
View
790 lib/class.tree.php
@@ -1,395 +1,395 @@
-<?php
-/**
- * Tree lib adapted from JStree http://www.jstree.com/
- *
- * PHP version 5
- *
- * LICENSE: 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 3 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, see <http://www.gnu.org/licenses/>.
- *
- * @category Monitoring
- * @author Cyril Feraudet <cyril@feraudet.com>
- * @copyright 2011 Cyril Feraudet
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- * @link http://www.perfwatcher.org/
- */
-
-class _tree_struct {
- // Structure table and fields
- protected $table = "";
- protected $fields = array(
- "id" => false,
- "parent_id" => false,
- "position" => false,
- );
-
- // Constructor
- function __construct($table = "tree", $fields = array()) {
- $this->table = $table;
- if(!count($fields)) {
- foreach($this->fields as $k => &$v) { $v = $k; }
- }
- else {
- foreach($fields as $key => $field) {
- switch($key) {
- case "id":
- case "parent_id":
- case "position":
- $this->fields[$key] = $field;
- break;
- }
- }
- }
- // Database
- $this->db = new _database;
- }
-
- function _get_node($id) {
- $this->db->prepare(
- "SELECT ".implode(", ", $this->fields)." FROM ".$this->table." WHERE ".$this->fields["id"]." = ?",
- array('integer')
- );
- $this->db->execute((int)$id);
- $this->db->nextr();
- $ret = $this->db->nf() === 0 ? false : $this->db->get_row("assoc");
- $this->db->free();
- return $ret;
- }
- function _get_children($id, $recursive = false, $path = "") {
- global $childrens_cache;
- if(is_array($childrens_cache) && isset($childrens_cache[$id.($recursive ? 'recursive' : 'notrecursive')])) {
- return $childrens_cache[$id];
- }
- $childrens = array();
- if($recursive) {
- $childrens = $this->_get_children($id, false, $path);
- foreach($childrens as $cid => $cdata) {
- if ( $cdata['type'] != 'default') {
- foreach($this->_get_children($cdata['id'], true, $cdata['_path_']) as $cid2 => $cdata2) {
- $childrens[$cdata2['type'] == 'default' ? $cdata2['title'] : 'aggregator_'.$cdata2['id']] = $cdata2;
- }
- }
- }
- } else {
- $datas = $this->get_datas($id);
- if (isset($datas['sort']) && $datas['sort'] == 1) { $sort = 'title'; } else { $sort = 'position'; }
- $this->db->prepare(
- "SELECT ".implode(", ", $this->fields)." FROM ".$this->table." WHERE ".$this->fields["parent_id"]." = ? ORDER BY ".$this->fields[$sort]." ASC",
- array('integer')
- );
- $this->db->execute((int)$id);
- while($this->db->nextr()) {
- $tmp = $this->db->get_row("assoc");
- $tmp["_path_"] = $path." -> ".$tmp['title'];
- $childrens[$tmp['type'] == 'default' ? $tmp['title'] : 'aggregator_'.$tmp['id']] = $tmp;
- }
- }
- $childrens_cache[$id] = $childrens;
- return $childrens;
- }
-
- function get_children_count($id) {
- $nbhosts = 0;
- $nbcontainer = 0;
- $childrens = $this->_get_children($id, true);
- foreach($childrens as $cid => $cdata) {
- if ($cdata['type'] == 'default') {
- $nbhosts++;
- } else {
- $nbcontainer++;
- }
- }
- return array($nbhosts, $nbcontainer);
- }
-
- function get_nodechildren_id($id) {
- $nodes = array();
- $childrens = $this->_get_children($id, true);
- foreach($childrens as $cid => $cdata) {
- if ($cdata['type'] == 'default') {
- $nodes[] = $cdata['id'];
- }
- }
- return $nodes;
- }
-
- function set_datas($id, $data) {
- $this->db->prepare("UPDATE ".$this->table." SET datas=? WHERE id = ?", array('text', 'integer'));
- $this->db->execute(array(serialize($data), (int)$id));
- }
-
- function get_datas($id) {
- $containers = array();
- $this->db->prepare("SELECT datas FROM ".$this->table." WHERE id = ?", array('integer'));
- $this->db->execute((int) $id);
- $this->db->nextr();
- $datas = $this->db->get_row("assoc");
- if(!$ret = unserialize($datas["datas"])) { $this->db->free(); return array(); }
- if(isset($ret['tabs']) && count($ret['tabs']) > 0) {
- //migrate from Alpha
- foreach($ret['tabs'] as $tabid => $tabdatas) {
- if (isset($tabdatas['selected_graph']) && is_array($tabdatas['selected_graph'])) {
- foreach($tabdatas['selected_graph'] as $pluginid => $plugindatas) {
- if(is_array($plugindatas)) { continue; }
- $ret['tabs'][$tabid]['selected_graph'][$pluginid] = split('\|', $plugindatas,4);
- }
- }
- }
- }
- $this->db->free();
- return $ret;
- }