Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions lib/WeatherMap.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function Recognise($targetstring) {
// itemtype and itemname may be used as part of the target (e.g. for TSV source line)
// function ReadData($targetstring, $configline, $itemtype, $itemname, $map) { return (array(-1,-1)); }
function ReadData($targetstring, &$map, &$item) {
return ([-1, -1]);
return ([-1, -1, 0]);
}

// pre-register a target + context, to allow a plugin to batch up queries to a slow database, or snmp for example
Expand Down Expand Up @@ -1608,19 +1608,21 @@ function DrawLegend_Vertical($image, $scalename = 'DEFAULT', $height = 400, $inv

$this->AllocateScaleColours($scale_im,$scale_ref);

if (!is_none($this->colours['DEFAULT']['KEYBG'])) {
if (!is_none($this->colours['DEFAULT']['KEYBG']) && isset($this->colours['DEFAULT']['KEYBG'][$scale_ref])) {
wimagefilledrectangle($scale_im, $box_left, $box_top, $box_right, $box_bottom,
$this->colours['DEFAULT']['KEYBG']['gdref1']);
$this->colours['DEFAULT']['KEYBG'][$scale_ref]);
}

if (!is_none($this->colours['DEFAULT']['KEYOUTLINE'])) {
if (!is_none($this->colours['DEFAULT']['KEYOUTLINE']) && isset($this->colours['DEFAULT']['KEYOUTLINE'][$scale_ref])) {
wimagerectangle($scale_im, $box_left, $box_top, $box_right, $box_bottom,
$this->colours['DEFAULT']['KEYOUTLINE']['gdref1']);
$this->colours['DEFAULT']['KEYOUTLINE'][$scale_ref]);
}

$this->myimagestring($scale_im, $font, $scale_left - $scalefactor, $scale_top - $tileheight , $title,
$this->colours['DEFAULT']['KEYTEXT']['gdref1']
);
if (isset($this->colours['DEFAULT']['KEYTEXT'][$scale_ref])) {
$this->myimagestring($scale_im, $font, $scale_left - $scalefactor, $scale_top - $tileheight , $title,
$this->colours['DEFAULT']['KEYTEXT'][$scale_ref]
);
}

$updown = 1;

Expand Down Expand Up @@ -1749,8 +1751,6 @@ function DrawLegend_Classic($image, $scalename = 'DEFAULT', $use_tags = false) {

$boxx = $x;
$boxy = $y;
Comment thread
somethingwithproof marked this conversation as resolved.
$boxx = 0;
$boxy = 0;

// allow for X11-style negative positioning
if ($boxx < 0) {
Expand All @@ -1774,20 +1774,22 @@ function DrawLegend_Classic($image, $scalename = 'DEFAULT', $use_tags = false) {
$this->AllocateScaleColours($scale_im,$scale_ref);

if (!is_none($this->colours['DEFAULT']['KEYBG'])) {
wimagefilledrectangle($scale_im, $boxx, $boxy, $boxx + $boxwidth, $boxy + $boxheight,
wimagefilledrectangle($scale_im, 0, 0, $boxwidth, $boxheight,
$this->colours['DEFAULT']['KEYBG'][$scale_ref]
);
}

if (!is_none($this->colours['DEFAULT']['KEYOUTLINE'])) {
wimagerectangle($scale_im, $boxx, $boxy, $boxx + $boxwidth, $boxy + $boxheight,
wimagerectangle($scale_im, 0, 0, $boxwidth, $boxheight,
$this->colours['DEFAULT']['KEYOUTLINE'][$scale_ref]
);
}

$this->myimagestring($scale_im, $font, $boxx + 4, $boxy + 4 + $tileheight, $title,
$this->colours['DEFAULT']['KEYTEXT'][$scale_ref]
);
if (isset($this->colours['DEFAULT']['KEYTEXT'][$scale_ref])) {
$this->myimagestring($scale_im, $font, 4, 4 + $tileheight, $title,
$this->colours['DEFAULT']['KEYTEXT'][$scale_ref]
);
}

$i = 1;

Expand All @@ -1800,8 +1802,8 @@ function DrawLegend_Classic($image, $scalename = 'DEFAULT', $use_tags = false) {

// debug("$i: drawing\n");
if (($hide_zero == 0) || $colour['key'] != '0_0') {
$y = $boxy + $tilespacing * $i + 8;
$x = $boxx + 6;
$y = $tilespacing * $i + 8;
$x = 6;

$fudgefactor = 0;

Expand Down Expand Up @@ -2143,7 +2145,7 @@ function ReadConfig($input, $is_include = false) {
// if it isn't, it's the filename
$lines = [];

if (strchr($input, "\n") != false || strchr($input, "\r") != false) {
if (strchr($input, "\n") !== false || strchr($input, "\r") !== false) {
wm_debug('ReadConfig Detected that this is a config fragment.');

// strip out any Windows line-endings that have gotten in here
Expand Down Expand Up @@ -3536,7 +3538,7 @@ function DrawMap($filename = '', $thumbnailfile = '', $thumbnailmax = 250, $with
if (file_exists($this->configfile)) {
$this->cachefile_version = crc32(file_get_contents($this->configfile));
} else {
wm_warn('Failed to find configuration file: ' . $this->configFile);
wm_warn('Failed to find configuration file: ' . $this->configfile);
}
}

Expand Down Expand Up @@ -4492,18 +4494,29 @@ function SeedCoverage() {
}

function LoadCoverage($file) {
// ToDo - Why the return?
return 0;
$i = 0;

$fd = fopen($file, 'r');
$real = realpath($file);
$base = defined('CACTI_PATH_BASE') ? realpath(CACTI_PATH_BASE) : realpath(dirname(dirname(__FILE__)));

if ($real === false || $base === false || strpos($real, $base . DIRECTORY_SEPARATOR) !== 0) {
return;
}

$fd = fopen($real, 'r');

if (is_resource($fd)) {
while (!feof($fd)) {
$line = fgets($fd,1024);
$line = fgets($fd, 1024);
$line = trim($line);

[$val,$key] = explode("\t",$line);
$parts = explode("\t", $line);

if (count($parts) < 2) {
continue;
}

[$val, $key] = $parts;

if ($key != '') {
$this->coverage[$key] = $val;
Expand All @@ -4521,7 +4534,15 @@ function LoadCoverage($file) {
function SaveCoverage($file) {
$i = 0;

$fd = fopen($file, 'w+');
$dir = realpath(dirname($file));
$base = defined('CACTI_PATH_BASE') ? realpath(CACTI_PATH_BASE) : realpath(dirname(dirname(__FILE__)));

if ($dir === false || $base === false || strpos($dir . DIRECTORY_SEPARATOR, $base . DIRECTORY_SEPARATOR) !== 0) {
return;
}

$safe = $dir . DIRECTORY_SEPARATOR . basename($file);
$fd = fopen($safe, 'w+');

foreach ($this->coverage as $key=>$val) {
fputs($fd, "$val\t$key\n");
Expand Down
12 changes: 6 additions & 6 deletions lib/WeatherMap.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ function mysprintf($format, $value, $kilo = 1000) {
wm_debug("KMGT formatting $value with $spec.");

$result = nice_scalar($value, $kilo, $places);
$output = preg_replace('/%' . $spec . 'k/', $format, $result);
$output = preg_replace_callback('/%' . preg_quote($spec, '/') . 'k/', function() use ($result) { return $result; }, $format);
} elseif (preg_match('/%(-*)(\d*)([Tt])/', $format, $matches)) {
$spec = $matches[3];
$precision = ($matches[2] == '' ? 10 : intval($matches[2]));
$joinchar = ' ';

if ($matches[1] == '-') {
$joinchar = ' ';
$joinchar = '-';
}

// special formatting for time_t (t) and SNMP TimeTicks (T)
Expand Down Expand Up @@ -414,15 +414,15 @@ function is_none($arr) {
}

function render_colour($col) {
if (($col[0] == -1) && ($col[1] == -1) && ($col[1] == -1)) {
if (($col[0] == -1) && ($col[1] == -1) && ($col[2] == -1)) {
return 'none';
}

if (($col[0] == -2) && ($col[1] == -2) && ($col[1] == -2)) {
if (($col[0] == -2) && ($col[1] == -2) && ($col[2] == -2)) {
return 'copy';
}

if (($col[0] == -3) && ($col[1] == -3) && ($col[1] == -3)) {
if (($col[0] == -3) && ($col[1] == -3) && ($col[2] == -3)) {
return 'contrast';
} else {
return sprintf('%d %d %d', $col[0], $col[1], $col[2]);
Expand Down Expand Up @@ -878,7 +878,7 @@ function calc_curve(&$in_xarray, &$in_yarray, $pointsperspan = 32) {
$yarray[$i], $xarray[$i + 1], $yarray[$i + 1], $xarray[$i + 2],
$yarray[$i + 2], $xarray[$i + 3], $yarray[$i + 3]);

Comment thread
somethingwithproof marked this conversation as resolved.
$curvepoints = $curvepoints + $newpoints;
$curvepoints = array_merge($curvepoints, array_slice($newpoints, 1));
}

return $curvepoints;
Expand Down
8 changes: 4 additions & 4 deletions lib/WeatherMapLink.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ function asJS() {
$js .= 'bw_out:' . js_escape($this->max_bandwidth_out_cfg) . ', ';

$js .= 'name:' . js_escape($this->name) . ', ';
$js .= 'overlibwidth:"' . $this->overlibheight . '", ';
$js .= 'overlibheight:"' . $this->overlibwidth . '", ';
$js .= 'overlibwidth:"' . $this->overlibwidth . '", ';
$js .= 'overlibheight:"' . $this->overlibheight . '", ';
$js .= 'overlibcaption:' . js_escape($this->overlibcaption[IN]) . ', ';

$js .= 'commentin:' . js_escape($this->comments[IN]) . ', ';
Expand Down Expand Up @@ -910,8 +910,8 @@ function asJSON($complete = true) {
$js .= '"bw_out":' . js_escape($this->max_bandwidth_out_cfg) . ', ';

$js .= '"name":' . js_escape($this->name) . ', ';
$js .= '"overlibwidth":"' . $this->overlibheight . '", ';
$js .= '"overlibheight":"' . $this->overlibwidth . '", ';
$js .= '"overlibwidth":"' . $this->overlibwidth . '", ';
$js .= '"overlibheight":"' . $this->overlibheight . '", ';
$js .= '"overlibcaption":' . js_escape($this->overlibcaption) . ', ';
}

Expand Down
8 changes: 4 additions & 4 deletions lib/WeatherMapNode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ function asJS() {
$js .= 'infourl:' . js_escape($this->infourl[IN]) . ', ';
$js .= 'overlibcaption:' . js_escape($this->overlibcaption[IN]) . ', ';
$js .= 'overliburl:' . js_escape(join(' ',$this->overliburl[IN])) . ', ';
$js .= 'overlibwidth:' . $this->overlibheight . ', ';
$js .= 'overlibheight:' . $this->overlibwidth . ', ';
$js .= 'overlibwidth:' . $this->overlibwidth . ', ';
$js .= 'overlibheight:' . $this->overlibheight . ', ';

if (preg_match('/^(none|nink|inpie|outpie|box|rbox|gauge|round)$/', $this->iconfile)) {
$js .= 'iconfile:' . js_escape('::' . $this->iconfile);
Expand Down Expand Up @@ -1011,8 +1011,8 @@ function asJSON($complete = true) {
$js .= '"overliburl":' . js_escape($this->overliburl) . ', ';
$js .= '"overlibcaption":' . js_escape($this->overlibcaption) . ', ';

$js .= '"overlibwidth":' . $this->overlibheight . ', ';
$js .= '"overlibheight":' . $this->overlibwidth . ', ';
$js .= '"overlibwidth":' . $this->overlibwidth . ', ';
$js .= '"overlibheight":' . $this->overlibheight . ', ';
$js .= '"iconfile":' . js_escape($this->iconfile) . ', ';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/editor.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ function handle_inheritance(&$map, &$inheritables) {
if ($inheritable[0] == 'node') {
$map->nodes['DEFAULT']->$fieldname = $new;

foreach ($map->nodes as $link_name => $node) {
foreach ($map->nodes as $node_name => $node) {
if ($node->name != ':: DEFAULT ::' && $old == $node->$fieldname) {
$map->nodes[$node->name]->$fieldname = $new;
}
Expand Down
4 changes: 2 additions & 2 deletions weathermap-cacti-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
// readfile_chunked($imagefile);
readfile($imagefile);

dir($orig_cwd);
chdir($orig_cwd);
} else {
// no permission to view this map
}
Expand Down Expand Up @@ -127,7 +127,7 @@
$map->ReadData();
$map->DrawMap('', '', 250, true, false);

dir($orig_cwd);
chdir($orig_cwd);
}
}
}
Expand Down