Files
cacti/install/step_json.php
Thomas Vincent 06c32ab13f fix(installer): preserve upgrade state and propagate failures (#8266)
* fix(installer): preserve upgrade state and propagate failures

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs(changelog): record installer recovery fixes for #8266

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(security): refresh installer sink inventories

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(installer): retain merge precedence for browser parameters

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(installer): defer debug settings until the process lock is held

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(installer): enforce table conversion failures and postconditions

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(installer): refresh SQL audit baseline after clause refactor

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-11 17:08:12 -04:00

108 lines
3.6 KiB
PHP

<?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/ |
+-------------------------------------------------------------------------+
*/
// since we'll have additional headers, tell php when to flush them
ob_start();
// Prevent redirect to /install/
define('IN_CACTI_INSTALL', 1);
chdir(__DIR__ . '/../');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
header('Allow: POST');
header('Content-Type: application/json');
print json_encode(['error' => 'Method not allowed']);
exit;
}
// set the json variable for request validation handling
include_once('lib/functions.php');
include_once('lib/html_utility.php');
srv('json', true);
$auth_json = true;
include_once('include/auth.php');
include_once('install/functions.php');
include_once('lib/installer.php');
include_once('lib/utility.php');
srv('json', true);
$auth_json = true;
$debug = false;
$initialData = [];
// ================= input validation =================
gnrv('data', []);
if (isrv('data') && gnrv('data')) {
log_install_debug('json','Using supplied data');
$initialData = gnrv('data');
if (!is_array($initialData)) {
$initialData = [$initialData];
}
}
$json_level = log_install_level('json',POLLER_VERBOSITY_NONE);
log_install_high('json','Start: ' . clean_up_lines(json_encode($initialData)));
$initialData = array_merge($initialData, ['Runtime' => 'Web']);
if (isset($initialData['step']) && $initialData['step'] == Installer::STEP_TEST_REMOTE) {
$json = install_test_remote_database_connection();
$json_debug = $json;
} else {
$installer = new Installer($initialData);
$json = json_encode($installer);
$json_debug = $json;
if ($json_level < POLLER_VERBOSITY_DEBUG) {
$installer->setRuntime('Json');
$json_debug = json_encode($installer);
}
}
$response = json_decode((string) $json, true);
if (is_array($response)) {
$response['csrfMagicToken'] = csrf_get_tokens();
$encoded_response = json_encode($response);
if ($encoded_response !== false) {
$json = $encoded_response;
}
}
log_install_high('json',' End: ' . clean_up_lines($json_debug) . PHP_EOL);
header('Content-Type: application/json');
header('Cache-Control: no-store');
header('X-Content-Type-Options: nosniff');
header('Content-Length: ' . strlen((string) $json));
print $json;