Repository navigation
Allow setting a map title when creating configuration files #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d79e1fe
Set optional map titles when creating configuration files
alcatron 80809d7
Refine touched formatting and verify saved options
alcatron b2b797f
Reference PR 297 in the plugin changelog
alcatron ffbf971
Give feature regression files distinct names for independent merging
alcatron 0a2c127
Retain the real entry-point directory in the title creation fixture
alcatron e2d812d
Sanitize creation titles consistently with the editor (PR #297)
alcatron 49479ed
Escape translated map title form fields
alcatron 3c9c492
Preserve map titles for normalized empty overrides
alcatron 305ef72
Merge develop and resolve changelog conflicts
alcatron 52dae3f
Merge develop after thumbnail default update
alcatron dcc5584
Reject titles exceeding the config reader line limit
alcatron 8996745
Merge develop after detailed graph default update
alcatron dc5fec4
Merge develop after Map Style controls update
alcatron ab76056
Merge develop after new map preset update
alcatron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group, Howard Jones | | ||
| | | | ||
| | 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. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| require dirname(__DIR__) . '/bootstrap-unit.php'; | ||
| $plugin = dirname(__DIR__,2); | ||
| chdir($plugin); | ||
| require $plugin . '/setup.php'; | ||
| require $plugin . '/lib/WeatherMap.class.php'; | ||
|
|
||
| if (!function_exists('cacti_count')) { | ||
| function cacti_count($value) { | ||
| return is_countable($value) ? count($value) : 0; | ||
| } | ||
| } | ||
|
|
||
| if (!function_exists('clean_up_name')) { | ||
| function clean_up_name($value) { | ||
| return preg_replace('/[^A-Za-z0-9_\-.]/','_',$value); | ||
| } | ||
| } | ||
|
|
||
| if (!defined('MESSAGE_LEVEL_INFO')) { | ||
| define('MESSAGE_LEVEL_INFO',0); | ||
| } | ||
| function wm_engine_assert($value,$message) { | ||
| if (!$value) { | ||
| throw new RuntimeException($message); | ||
| } | ||
| } | ||
| $directory = sys_get_temp_dir() . '/wm-engine-' . bin2hex(random_bytes(8)); | ||
| mkdir($directory); | ||
|
|
||
| try { | ||
| $source = file_get_contents($plugin . '/weathermap-cacti-plugin-mgmt.php'); | ||
| $start = strpos($source,'function newMap('); | ||
| eval(str_replace('__DIR__', var_export($plugin, true), substr($source, $start))); | ||
| $weathermap_confdir = $directory; | ||
| newMap('new.conf','',"My <network> & 'title'\nTITLE injected"); | ||
| $saved = new WeatherMap(); | ||
| $saved->ReadConfig($directory . '/new.conf'); | ||
| wm_engine_assert($saved->title === 'My <network> & 'title' TITLE injected','title round trip and line-break normalization'); | ||
| $map = new WeatherMap(); | ||
| $map->width = 910; | ||
| $map->title = 'Source title'; | ||
| $map->WriteConfig($directory . '/source.conf'); | ||
| $before = file_get_contents($directory . '/source.conf'); | ||
| newMap('copy.conf','source.conf',''); | ||
| $copy = new WeatherMap(); | ||
| $copy->ReadConfig($directory . '/copy.conf'); | ||
| wm_engine_assert($copy->title === 'Source title' && $copy->width == 910,'blank title retains source'); | ||
| foreach (["\x01", "\x7f", " \r\n\x02 ", null, []] as $index => $empty_title) { | ||
| $filename = 'empty-' . $index . '.conf'; | ||
| newMap($filename, 'source.conf', $empty_title); | ||
| $empty_copy = new WeatherMap(); | ||
| $empty_copy->ReadConfig($directory . '/' . $filename); | ||
| wm_engine_assert($empty_copy->title === 'Source title' && $empty_copy->width == 910, 'normalized empty override preserves source title and layout'); | ||
| } | ||
| newMap('blank-control.conf', '', "\x01"); | ||
| $blank = new WeatherMap(); | ||
| $blank->ReadConfig($directory . '/blank-control.conf'); | ||
| $defaults = new WeatherMap(); | ||
| wm_engine_assert($blank->title === $defaults->title, 'normalized empty title preserves a new map default'); | ||
| newMap('mixed.conf', 'source.conf', " \x01New\x7ftitle "); | ||
| $mixed = new WeatherMap(); | ||
| $mixed->ReadConfig($directory . '/mixed.conf'); | ||
| wm_engine_assert($mixed->title === 'New title', 'mixed control characters normalize before applying a real override'); | ||
| newMap('renamed.conf','source.conf','New <title> & copy'); | ||
| $renamed = new WeatherMap(); | ||
| $renamed->ReadConfig($directory . '/renamed.conf'); | ||
| wm_engine_assert($renamed->title === 'New <title> & copy' && $renamed->width == 910,'override title preserves layout'); | ||
| wm_engine_assert(file_get_contents($directory . '/source.conf') === $before,'source unchanged'); | ||
|
|
||
| foreach ([str_repeat('T', 4088), str_repeat('é', 2044)] as $index => $boundary_title) { | ||
| newMap('boundary-' . $index . '.conf', '', $boundary_title); | ||
| $boundary = new WeatherMap(); | ||
| $boundary->ReadConfig($directory . '/boundary-' . $index . '.conf'); | ||
| wm_engine_assert($boundary->title === $boundary_title, 'maximum byte-length title round-trips intact'); | ||
| } | ||
| $include = $directory . '/injected.conf'; | ||
| file_put_contents($include, "WIDTH 9999\n"); | ||
| foreach ([str_repeat('T', 4089), str_repeat('é', 2045), str_repeat('&', 818), str_repeat('T', 4089) . 'INCLUDE ' . $include] as $index => $oversized_title) { | ||
| foreach (['', 'source.conf'] as $source_map) { | ||
| $filename = 'oversized-' . $index . '-' . ($source_map === '' ? 'blank' : 'copy') . '.conf'; | ||
| newMap($filename, $source_map, $oversized_title); | ||
| wm_engine_assert(!file_exists($directory . '/' . $filename), 'oversized title cannot create a config or inject directives'); | ||
| } | ||
| } | ||
| wm_engine_assert(file_get_contents($directory . '/source.conf') === $before, 'oversized copied-map override leaves its source untouched'); | ||
|
|
||
| print "PASS\n"; | ||
| } finally { | ||
| foreach (glob($directory . '/*') as $file) { | ||
| unlink($file); | ||
| }rmdir($directory); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group, Howard Jones | | ||
| | | | ||
| | 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. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| it('PersistsAndRendersTheNewMapOptionsUsingTheRealEngine', function () { | ||
| $lines = []; | ||
| exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg(dirname(__DIR__) . '/Support/NewMapTitleEngineRegression.php') . ' 2>&1',$lines,$status); | ||
| expect($status)->toBe(0)->and(implode("\n",$lines))->toBe('PASS'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group, Howard Jones | | ||
| | | | ||
| | 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. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| it('EscapesTranslatedTitleFieldsInTheActualCreateForm', function () { | ||
| $source = file_get_contents(dirname(__DIR__, 2) . '/weathermap-cacti-plugin-mgmt.php'); | ||
| $start = strpos($source, "<td><label for='newtitle'>"); | ||
| $end = strpos($source, '</td>', strpos($source, "<input id='newtitle'", $start)) + strlen('</td>'); | ||
| $fragment = substr($source, $start, $end - $start); | ||
| $payload = "Title' autofocus onfocus='alert(1) <script>"; | ||
| // Substitute translated output before the escape helper executes. | ||
| $fragment = str_replace(["'Map Title'", "'Optional map title'"], var_export($payload, true), $fragment); | ||
| ob_start(); | ||
| eval('?>' . $fragment); | ||
| $html = ob_get_clean(); | ||
| expect($html)->toContain(''', '<script>')->not->toContain("placeholder='Title' autofocus", '<script>'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.