-
Notifications
You must be signed in to change notification settings - Fork 18
refactor: centralize XML import payload loading #280
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | 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/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| $root = dirname(__DIR__, 2); | ||
|
|
||
| $functions = file_get_contents($root . '/functions.php'); | ||
| if ($functions === false) { | ||
| fwrite(STDERR, "Failed to load functions.php\n"); | ||
| exit(1); | ||
| } | ||
|
Comment on lines
+1
to
+31
|
||
|
|
||
| if (strpos($functions, 'function syslog_get_import_xml_payload(') === false) { | ||
| fwrite(STDERR, "Shared import payload loader helper is missing.\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| if (strpos($functions, "trim(get_nfilter_request_var('import_text')) != ''") === false) { | ||
| fwrite(STDERR, "Shared import payload loader is missing trimmed text handling.\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| $targets = array( | ||
| $root . '/syslog_alerts.php', | ||
| $root . '/syslog_reports.php', | ||
| $root . '/syslog_removal.php' | ||
| ); | ||
|
|
||
| foreach ($targets as $target) { | ||
| $content = file_get_contents($target); | ||
|
|
||
| if ($content === false) { | ||
| fwrite(STDERR, "Failed to load $target\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| if (strpos($content, 'syslog_get_import_xml_payload(') === false) { | ||
| fwrite(STDERR, "Shared import payload loader is not used in $target\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| if (strpos($content, "\$_FILES['import_file']['tmp_name']") !== false) { | ||
| fwrite(STDERR, "Legacy per-file upload payload loading remains in $target\n"); | ||
| exit(1); | ||
| } | ||
| } | ||
|
|
||
| echo "issue277_import_payload_loader_test passed\n"; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upload-path payload loader does not handle file read failures (e.g., fopen()/filesize()/fread() can return false), which can trigger PHP warnings and pass non-string data to xml2array(). Consider checking the upload error status, reading in binary mode, and falling back to the existing redirect behavior when the file cannot be read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — both fopen() and fread() return values checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed -- fopen and fread failures are now checked and logged before proceeding.