-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup_info2.php
178 lines (161 loc) · 7.22 KB
/
setup_info2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php declare(strict_types = 1);
/**
* setup_info2.php from The Kabal Invasion.
* The Kabal Invasion is a Free & Opensource (FOSS), web-based 4X space/strategy game.
*
* @copyright 2020 The Kabal Invasion development team, Ron Harwood, and the BNT development team
*
* @license GNU AGPL version 3.0 or (at your option) any later version.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once './common.php';
// Set headers
header('Content-type: text/html; charset=utf-8'); // Set character set to utf-8, and using HTML as our content type
header('Cache-Control: public'); // Tell the browser (and any caches) that this information can be stored in public caches.
header('Connection: Keep-Alive'); // Tell the browser to keep going until it gets all data, please.
header('Vary: Accept-Encoding, Accept-Language'); // Tell CDN's or proxies to keep a separate version of the page in various encodings - compressed or not, in english or french for example.
header('Keep-Alive: timeout=15, max=100'); // Ask for persistent HTTP connections (15sec), which give better per-client performance, but can be worse (for a server) for many.
// Set cookies for cookie test
setcookie('TestCookie', '', 0);
setcookie('TestCookie', 'Shuzbutt', time() + 3600, Tki\SetPaths::setGamepath(), $request->server->get('HTTP_HOST'));
// Database configuration.
$db_host = \Tki\SecureConfig::DB_HOST;
$db_port = \Tki\SecureConfig::DB_PORT;
$db_user = \Tki\SecureConfig::DB_USER;
$db_pwd = \Tki\SecureConfig::DB_PASS;
$db_type = \Tki\SecureConfig::DB_TYPE;
$db_name = \Tki\SecureConfig::DB_NAME;
$db_prefix = \Tki\SecureConfig::DB_TABLE_PREFIX;
// Database driven language entries
$langvars = Tki\Translate::load($pdo_db, $lang, array('common', 'footer',
'index', 'insignias', 'login', 'new', 'news',
'options', 'setup_info', 'universal'));
$variables = null;
$variables['lang'] = $lang;
$variables['link'] = 'https://github.com/thekabal/tki/';
$variables['admin_mail'] = $tkireg->admin_mail;
$variables['body_class'] = 'tki';
$variables['template'] = $tkireg->default_template; // Temporarily set the template to the default template until we have a user option
// Get the webserver version.
$sapi = php_sapi_name();
$serverType = '';
$serverVersion = '';
if($sapi === 'apache')
{
$serverType = $sapi;
$serverVersion = apache_get_version();
}
else
{
// This logic presumes nginx is being used.
$nameVersionPair = explode('/', $request->server->get('SERVER_SOFTWARE'));
$serverType = $nameVersionPair[0];
$serverVersion = array_pop($nameVersionPair);
}
$variables['selected_lang'] = null;
$variables['system'] = php_uname();
$variables['remote_addr'] = $request->server->get('REMOTE_ADDR');
$variables['server_addr'] = $request->server->get('HTTP_HOST') . ':' . $request->server->get('SERVER_PORT');
$variables['zend_version'] = zend_version();
$variables['php_version'] = PHP_VERSION;
$variables['php_sapi_name'] = php_sapi_name();
$variables['server_type'] = $serverType;
$variables['server_version'] = $serverVersion;
$variables['game_path'] = Tki\SetPaths::setGamepath();
$variables['db_type'] = $db_type;
$variables['db_name'] = $db_name;
$variables['db_prefix'] = $db_prefix;
$variables['admin_name'] = $tkireg->admin_name;
$variables['admin_email'] = str_replace('@', ' AT ', $tkireg->admin_mail);
$variables['release_version'] = $tkireg->release_version;
$variables['turns_per_tick'] = $tkireg->turns_per_tick;
$variables['sched_ticks'] = $tkireg->sched_ticks;
$variables['sched_turns'] = $tkireg->sched_turns;
$variables['sched_ports'] = $tkireg->sched_ports;
$variables['sched_planets'] = $tkireg->sched_planets;
$variables['sched_ibank'] = $tkireg->sched_ibank;
$variables['sched_ranking'] = $tkireg->sched_ranking;
$variables['sched_news'] = $tkireg->sched_news;
$variables['sched_degrade'] = $tkireg->sched_degrade;
$variables['sched_apocalypse'] = $tkireg->sched_apocalypse;
$variables['sched_thegovernor'] = $tkireg->sched_thegovernor;
$variables['hash'] = strtoupper((string) md5_file(__FILE__));
$variables['updated_on'] = date("l, F d, Y", (int) filemtime(basename(__FILE__)));
$variables['cookie_test'] = ($_COOKIE['TestCookie'] !== null);
$variables['dev_mode'] = file_exists('dev');
$variables['php_module_pdo'] = extension_loaded('pdo_mysql');
$variables['php_module_mysqli'] = extension_loaded('mysqli');
$variables['adodb_path_test'] = file_exists((string) realpath("vendor/adodb/adodb-php/adodb.inc.php"));
$variables['smarty_path_test'] = file_exists((string) realpath("vendor/smarty/smarty/libs/Smarty.class.php"));
$variables['title'] = $langvars['l_setup_info_title'];
// Test Smarty
$test_smarty = new Smarty();
$test_smarty->setCompileDir('templates/_compile/');
$test_smarty->setCacheDir('templates/_cache/');
$test_smarty->setConfigDir('templates/_configs/');
// Smarty outputs directly (yuck), so we output buffer it instead
ob_start();
$test_smarty->testInstall();
$variables['smarty_test_err'] = (string) ob_get_contents();
ob_end_clean();
if ((bool) strpos($variables['smarty_test_err'], 'FAILED'))
{
$variables['smarty_test'] = false;
}
else
{
$variables['smarty_test'] = true;
}
// Attempt to connect to the database via adodb
$test_db = new Tki\Db();
$variables['adodb_conn_err'] = "Error message";
$variables['adodb_conn_test'] = $test_db->initAdodb();
// Attempt to connect to the database via PDO
try
{
$test_pdo_db = new PDO("mysql:host=$db_host; dbname=$db_name; charset=utf8mb4", $db_user, $db_pwd);
$variables['pdo_conn_test'] = true;
$variables['pdo_server_ver'] = $test_pdo_db->getAttribute(constant("PDO::ATTR_SERVER_VERSION"));
}
catch (\PDOException $e)
{
$err_msg = "Unable to connect to the " . $db_type .
" Database.<br>\n Database Error: " .
$e->getMessage() . "<br>\n";
$variables['pdo_conn_test'] = false;
$variables['pdo_conn_err'] = $err_msg;
}
// Get environment variables
$id = 0;
ksort($_SERVER);
reset($_SERVER);
foreach ($_SERVER as $name => $value)
{
$array_var = explode(';', (string) $value);
$value = implode('; ', $array_var);
$variables['env_vars'][$id]['name'] = trim($name);
$variables['env_vars'][$id]['value'] = trim($value);
$id++;
}
// Properly format the database host/port
$variables['db_addr'] = $db_host;
$header = new Tki\Header();
$header->display($pdo_db, $lang, $template, $variables['title'], $variables['body_class']);
$template->addVariables('langvars', $langvars);
$template->addVariables('variables', $variables);
$template->display('templates/classic/setup_info.tpl');
$footer = new Tki\Footer();
$footer->display($pdo_db, $lang, $tkireg, $tkitimer, $template);