Cacti / plugin_weathermap

Weathermap for Cacti 1.x
MIT License
77 stars 26 forks source link

`weathermap_repair_maps()` destroys maps instead of repairing them #126

Closed Jay2k1 closed 2 months ago

Jay2k1 commented 7 months ago

https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L100-L263

This function is being called whenever you open the weathermap map list (console > management > weathermaps). Back in the day, background and icon images were stored in the images subfolder of the plugin. At some point, it was decided to put them into the subfolders images/backgrounds/ and images/objects/. The only purpose of this function is to migrate old configs by moving the images into their new subfolders and update the paths in the config. However, it destroys them in the process:

For each weathermap config file, it reads the config and loops over all lines.

For each line of the current config,

Finally, if ($changes), it overwrites the config file with the contents of the $outcontents array. However, because only lines containing BACKGROUND and ICON have been looked at, all other lines of the config haven't been added to the $outcontents array, so they get lost. The config is reduced to only containing BACKGROUND and ICON lines, effectively destroying that weathermap.


Additionally, there's a copy-paste error, $objfile should be $bgfile here: https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L176


Also, before renaming (moving) the background image, it tries to check if the new file name $new is writeable, but this cannot be true if the file does not exist. https://github.com/Cacti/plugin_weathermap/blob/3c6e0e94a954e66a24ba0e81d17b419553575eaf/lib/poller-common.php#L162

TheWitness commented 7 months ago

How about a pull request on this please?

TheWitness commented 7 months ago

@Jay2k1 , Pull request?