forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathserver_data.php
213 lines (204 loc) · 5.88 KB
/
server_data.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* \file
* \brief Useful software data.
*
* Call: server_data.php
*
* PHP version 8.1.1
*
* @category User_Interface
* @package Lwt
* @author HugoFara <hugo.farajallah@protonmail.com>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/php/files/index.html
* @since 2.7.0
*/
namespace Lwt\Interface\Server\Data;
require_once 'inc/session_utility.php';
/**
* Return a lot of different server state variables.
*
* @return (false|float|string)[] {"db_prefix": string, "db_size": float, "server_soft": string[],
* "apache": string, "php": string, "mysql": string}
* Table prefix, database size, server software, apache version, PHP version, MySQL
* version
*
* @global string $tbpref Database table prefix
* @global string $dbname Database name
*
* @psalm-return array{db_name: string, db_prefix: string, db_size: float, server_soft: string, apache: string, php: false|string, mysql: string}
*/
function get_server_data_table(): array
{
global $tbpref, $dbname;
$dbaccess_format = convert_string_to_sqlsyntax($dbname);
$data_table = array();
$data_table["db_name"] = $dbname;
$data_table["db_prefix"] = $tbpref;
$temp_size = get_first_value(
"SELECT ROUND(SUM(data_length+index_length)/1024/1024, 1) AS value
FROM information_schema.TABLES
WHERE table_schema = $dbaccess_format
AND table_name IN (
'{$tbpref}archivedtexts', '{$tbpref}archtexttags',
'{$tbpref}feedlinks', '{$tbpref}languages',
'{$tbpref}newsfeeds', '{$tbpref}sentences', '{$tbpref}settings',
'{$tbpref}tags', '{$tbpref}tags2',
'{$tbpref}textitems2', '{$tbpref}texts', '{$tbpref}texttags',
'{$tbpref}words', '{$tbpref}wordtags'
)"
);
if ($temp_size === null) {
$data_table["db_size"] = 0.0;
} else {
$data_table["db_size"] = floatval($temp_size);
}
$data_table["server_soft"] = $_SERVER['SERVER_SOFTWARE'];
$data_table["apache"] = "Apache/?";
if (str_starts_with($data_table["server_soft"], "Apache/")) {
$temp_soft = explode(' ', $data_table["server_soft"]);
$data_table["apache"] = $temp_soft[0];
}
$data_table["php"] = phpversion();
$data_table["mysql"] = (string)get_first_value("SELECT VERSION() AS value");
return $data_table;
}
/**
* Display the main content for the page.
*
* @return void
*/
function display_content(): void
{
$data = get_server_data_table();
pagestart("Server Data", true);
?>
<h2>Server</h2>
<table>
<thead>
<tr>
<th>Data</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>LWT version</td>
<td><?php echo get_version_number(); ?></td>
</tr>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/Web_server" target="_blank">
Web Server
</a>
</td>
<td><i><?php echo $data["server_soft"]; ?></i></td>
</tr>
<tr>
<td>Server Software</td>
<td>
<a href="https://en.wikipedia.org/wiki/Apache_HTTP_Server"
target="_blank">
<?php echo $data["apache"]; ?>
</a>
</td>
</tr>
<tr>
<td>Server Location</td>
<td><i><?php echo $_SERVER['HTTP_HOST']; ?></i></td>
</tr>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/PHP" target="_blank">
PHP
</a> Version
</td>
<td><?php echo $data["php"]; ?></td>
</tr>
</tbody>
</table>
<h2>Database</h2>
<table>
<thead>
<tr>
<th>Data</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/Database" target="_blank">
Database
</a> name</td>
<td><i><?php echo $data["db_name"]; ?></i></td>
</tr>
<tr>
<td>Database prefix (surrounded by "")</td>
<td>"<?php echo $data["db_prefix"]; ?>"</td>
</tr>
<tr>
<td>Database Size</td>
<td><?php echo $data["db_size"]; ?> MB</td>
</tr>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/MySQL" target="_blank">
MySQL
</a> Version
</td>
<td><?php echo $data["mysql"]; ?></td>
</tr>
</tbody>
</table>
<h2>Client API</h2>
<table>
<thead>
<tr>
<th>Data</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/REST">
REST API
</a> Version
</td>
<td id="rest-api-version"><!-- JS inserts version here --></td>
</tr>
<tr>
<td>
<a href="https://en.wikipedia.org/wiki/REST">
REST API
</a> Release date
</td>
<td id="rest-api-release-date"><!-- JS acts here --></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function handle_api_version_answer(data) {
if ("error" in data) {
$("#rest-api-version").text(
"Error while getting data from the REST API!" +
"\nMessage: " + data.error
);
$("#rest-api-release-date").empty();
} else {
$("#rest-api-version").text(data.version);
$("#rest-api-release-date").text(data.release_date);
}
}
$.getJSON(
"api.php/v1/version",
{},
handle_api_version_answer
);
</script>
<?php
pageend();
}
display_content();