1<?php
2/*
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004-2021 The Cacti Group                                 |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+
16 | Cacti: The Complete RRDtool-based Graphing Solution                     |
17 +-------------------------------------------------------------------------+
18 | This code is designed, written, and maintained by the Cacti Group. See  |
19 | about.php and/or the AUTHORS file for specific developer information.   |
20 +-------------------------------------------------------------------------+
21 | http://www.cacti.net/                                                   |
22 +-------------------------------------------------------------------------+
23*/
24
25/* since we'll have additional headers, tell php when to flush them */
26ob_start();
27
28// Prevnt redirect to /install/
29define('IN_CACTI_INSTALL', 1);
30chdir(__DIR__ . '/../');
31
32/* set the json variable for request validation handling */
33include_once('lib/functions.php');
34include_once('lib/html_utility.php');
35set_request_var('json', true);
36$auth_json = true;
37
38include('include/auth.php');
39include('install/functions.php');
40include('lib/installer.php');
41include('lib/utility.php');
42
43$debug = false;
44
45
46$initialData = array();
47/* ================= input validation ================= */
48get_nfilter_request_var('data', array());
49if (isset_request_var('data') && get_nfilter_request_var('data')) {
50	log_install_debug('json','Using supplied data');
51	$initialData = get_nfilter_request_var('data');
52	if (!is_array($initialData)) {
53		$initialData = array($initialData);
54	}
55}
56
57$json_level = log_install_level('json',POLLER_VERBOSITY_NONE);
58log_install_high('json','Start: ' . clean_up_lines(json_encode($initialData)));
59
60$initialData = array_merge(array('Runtime' => 'Web'), $initialData);
61if (isset($initialData['step']) && $initialData['step'] == Installer::STEP_TEST_REMOTE) {
62	$json = install_test_remote_database_connection();
63	$json_debug = $json;
64} else {
65	$installer = new Installer($initialData);
66	$json = json_encode($installer);
67
68	$json_debug = $json;
69	if ($json_level < POLLER_VERBOSITY_DEBUG) {
70		$installer->setRuntime('Json');
71		$json_debug = json_encode($installer);
72	}
73
74}
75log_install_high('json','  End: ' . clean_up_lines($json_debug) . PHP_EOL);
76header('Content-Type: application/json');
77header('Content-Length: ' . strlen($json));
78print $json;
79