-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdatabase.php
More file actions
348 lines (292 loc) · 16.8 KB
/
Copy pathdatabase.php
File metadata and controls
348 lines (292 loc) · 16.8 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
declare(strict_types=1);
/* vim: ts=4
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group, Inc. |
| Copyright (C) 2004-2025 Petr Macek |
| |
| 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. |
+-------------------------------------------------------------------------+
| https://github.com/xmacan/ |
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
function intropage_drop_database() {
db_execute('UPDATE user_auth SET login_opts = 1 WHERE login_opts > 3');
db_execute("DELETE FROM settings WHERE name LIKE 'intropage_%'");
db_execute('DROP TABLE IF EXISTS plugin_intropage_panel_definition');
db_execute('DROP TABLE IF EXISTS plugin_intropage_panel_data');
db_execute('DROP TABLE IF EXISTS plugin_intropage_panel_dashboard');
db_execute('DROP TABLE IF EXISTS plugin_intropage_trends');
db_execute('DROP TABLE IF EXISTS plugin_intropage_user_auth');
db_execute('DROP TABLE IF EXISTS plugin_intropage_dashboard');
db_execute('DROP TABLE IF EXISTS plugin_intropage_user_group_auth');
}
function intropage_initialize_database() {
global $config;
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
if (!isset($_SESSION['sess_user_id'])) {
$user_id = read_config_option('admin_user');
if (empty($user_id)) {
$user_id = db_fetch_cell('SELECT id FROM user_auth ORDER BY id ASC LIMIT 1');
}
} else {
$user_id = $_SESSION['sess_user_id'];
}
$data = [];
$data['columns'][] = ['name' => 'cur_timestamp', 'type' => 'timestamp'];
$data['columns'][] = ['name' => 'name', 'type' => 'varchar(50)', 'NULL' => false, 'default' => '0'];
$data['columns'][] = ['name' => 'user_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'];
$data['columns'][] = ['name' => 'value', 'type' => 'varchar(250)', 'NULL' => true, 'default' => null];
$data['type'] = 'InnoDB';
$data['comment'] = 'Intropage trends';
api_plugin_db_table_create('intropage', 'plugin_intropage_trends', $data);
db_execute('ALTER TABLE plugin_intropage_trends
MODIFY COLUMN cur_timestamp TIMESTAMP default current_timestamp ON UPDATE current_timestamp');
$data = [];
$data['columns'][] = ['name' => 'panel_id', 'type' => 'varchar(50)', 'NULL' => false];
$data['columns'][] = ['name' => 'name', 'type' => 'varchar(30)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'level', 'type' => 'tinyint', 'unsigned' => true, 'default' => 0];
$data['columns'][] = ['name' => 'class', 'type' => 'varchar(30)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'priority', 'type' => 'tinyint', 'unsigned' => true, 'default' => 0];
$data['columns'][] = ['name' => 'alarm', 'type' => 'varchar(10)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'requires', 'type' => 'varchar(128)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'update_func', 'type' => 'varchar(30)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'details_func', 'type' => 'varchar(30)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'trends_func', 'type' => 'varchar(30)', 'NULL' => false, 'default' => ''];
$data['columns'][] = ['name' => 'refresh', 'type' => 'int(10)', 'unsigned' => true, 'default' => '3600'];
$data['columns'][] = ['name' => 'trefresh', 'type' => 'int(10)', 'unsigned' => true, 'default' => '3600'];
$data['columns'][] = ['name' => 'description', 'type' => 'varchar(200)', 'default' => '', 'NULL' => true];
$data['columns'][] = ['name' => 'height', 'type' => "enum('normal','double','triple')", 'default' => 'normal', 'NULL' => false];
$data['type'] = 'InnoDB';
$data['primary'] = 'panel_id';
$data['comment'] = 'Panels Definitions of panels in panel library';
api_plugin_db_table_create('intropage', 'plugin_intropage_panel_definition', $data);
$data = [];
$data['columns'][] = ['name' => 'panel_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'user_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'dashboard_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'priority', 'type' => 'int(11)', 'NULL' => false, 'default' => 0];
$data['type'] = 'InnoDB';
$data['primary'] = 'panel_id`, `user_id`, `dashboard_id';
$data['comment'] = 'panel x dashboard dependency';
api_plugin_db_table_create('intropage', 'plugin_intropage_panel_dashboard', $data);
$data = [];
$data['columns'][] = ['name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true];
$data['columns'][] = ['name' => 'panel_id', 'type' => 'varchar(50)', 'NULL' => false];
$data['columns'][] = ['name' => 'user_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'last_update', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP', 'NULL' => false];
$data['columns'][] = ['name' => 'last_trend_update', 'type' => 'timestamp', 'NULL' => false];
$data['columns'][] = ['name' => 'data', 'type' => 'text', 'NULL' => true];
$data['columns'][] = ['name' => 'priority', 'type' => 'int(3)', 'default' => '30', 'NULL' => false];
$data['columns'][] = ['name' => 'alarm', 'type' => "enum('red','green','yellow','grey')", 'default' => 'green', 'NULL' => false];
$data['columns'][] = ['name' => 'refresh_interval', 'type' => 'int(9)', 'default' => '3600', 'NULL' => false];
$data['columns'][] = ['name' => 'trend_interval', 'type' => 'int(9)', 'default' => '300', 'NULL' => false];
$data['columns'][] = ['name' => 'fav_graph_id', 'type' => 'int(11)', 'NULL' => true];
$data['columns'][] = ['name' => 'fav_graph_timespan', 'type' => 'int(2)', 'default' => '1', 'NULL' => false];
$data['columns'][] = ['name' => 'height', 'type' => "enum('normal','double','triple')", 'default' => 'normal', 'NULL' => false];
$data['type'] = 'InnoDB';
$data['primary'] = 'id';
$data['comment'] = 'panel data';
api_plugin_db_table_create('intropage', 'plugin_intropage_panel_data', $data);
$panels = initialize_panel_library();
update_registered_panels($panels);
foreach ($panels as $panel_id => $panel) {
if ($panel['level'] == 0) {
db_execute_prepared('INSERT INTO plugin_intropage_panel_data
(panel_id, user_id, priority, alarm, refresh_interval, trend_interval)
VALUES(?, "0", ?, ?, ?, ?)',
[$panel_id, $panel['priority'], $panel['alarm'], $panel['refresh'], $panel['trefresh']]);
} else {
db_execute_prepared('INSERT INTO plugin_intropage_panel_data
(panel_id, user_id, priority, alarm, refresh_interval, trend_interval)
VALUES(?, ?, ?, ?, ?, ?)',
[$panel_id, $user_id, $panel['priority'], $panel['alarm'], $panel['refresh'], $panel['trefresh']]);
}
}
$data = [];
$data['columns'][] = ['name' => 'user_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'login_opts', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '0'];
$data['columns'][] = ['name' => 'permissions', 'type' => 'blob', 'NULL' => false, 'default' => ''];
$data['type'] = 'InnoDB';
$data['primary'] = 'user_id';
$data['comment'] = 'authorization';
api_plugin_db_table_create('intropage', 'plugin_intropage_user_auth', $data);
$data = [];
$data['columns'][] = ['name' => 'user_group_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'login_opts', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '0'];
$data['columns'][] = ['name' => 'permissions', 'type' => 'blob', 'NULL' => false, 'default' => ''];
$data['type'] = 'InnoDB';
$data['primary'] = 'user_group_id';
$data['comment'] = 'authorization';
api_plugin_db_table_create('intropage', 'plugin_intropage_user_group_auth', $data);
$permissions = [];
foreach ($panels as $panel_id => $panel) {
$permissions[$panel_id] = 'on';
}
$permissions['favourite_graph'] = 'on';
db_execute_prepared('INSERT INTO plugin_intropage_user_auth
(user_id, permissions)
VALUES (?, ?)',
[$user_id, json_encode($permissions)]);
$data = [];
$data['columns'][] = ['name' => 'user_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'dashboard_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'name', 'type' => 'varchar(30)', 'NULL' => true];
$data['columns'][] = ['name' => 'shared', 'type' => 'int(1)', 'NULL' => false, 'default' => 0];
$data['type'] = 'InnoDB';
$data['comment'] = 'panel x dashboard name';
api_plugin_db_table_create('intropage', 'plugin_intropage_dashboard', $data);
db_execute('ALTER TABLE plugin_intropage_dashboard ADD PRIMARY KEY (user_id, dashboard_id)');
}
function intropage_upgrade_database() {
global $config;
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
// If action need to be done for upgrade, add it.
$info = parse_ini_file($config['base_path'] . '/plugins/intropage/INFO', true);
$info = $info['info'];
$current = $info['version'];
$oldv = db_fetch_cell('SELECT version FROM plugin_config WHERE directory = "intropage"');
if (!cacti_version_compare($oldv, $current, '=')) {
if (cacti_version_compare($oldv, '3.0.0', '<=')) {
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
if (db_column_exists('plugin_intropage_panel_definition', 'file')) {
db_execute('ALTER TABLE plugin_intropage_panel_definition
DROP COLUMN `file`,
DROP COLUMN `has_detail`,
CHANGE COLUMN refresh_interval refresh int(10) unsigned NOT NULL default "30",
ADD COLUMN name varchar(30) NOT NULL default "" AFTER panel_id,
ADD COLUMN level int(10) unsigned NOT NULL default "0" AFTER name,
ADD COLUMN alarm varchar(10) NOT NULL default "" AFTER priority,
ADD COLUMN requires varchar(128) NOT NULL default "" AFTER alarm,
ADD COLUMN update_func varchar(30) NOT NULL default "" AFTER requires,
ADD COLUMN details_func varchar(30) NOT NULL default "" AFTER update_func,
ADD COLUMN class varchar(30) NOT NULL default "" AFTER level,
ADD COLUMN trends_func varchar(30) NOT NULL default "" AFTER details_func');
}
if (!db_column_exists('plugin_intropage_user_auth', 'permissions')) {
db_execute('ALTER TABLE plugin_intropage_user_auth
ADD COLUMN permissions BLOB default "" AFTER login_opts');
$panels = initialize_panel_library();
$permissions = db_fetch_assoc('SELECT * FROM plugin_intropage_user_auth');
$permissions['favourite_graph'] = 'on';
if (cacti_sizeof($permissions)) {
foreach ($permissions as $p) {
$user = $p['user_id'];
$opts = $p['login_opts'];
unset($p['user_id']);
unset($p['login_opts']);
// Remove panels that are no longer published
foreach ($p as $panel_id => $data) {
if (!isset($panels[$panel_id])) {
unset($p[$panel_id]);
}
}
$perms = json_encode($p);
db_execute_prepared('UPDATE plugin_intropage_user_auth
SET permissions = ?
WHERE user_id = ?',
[$perms, $user]);
}
}
$columns = db_fetch_assoc('SHOW COLUMNS FROM plugin_intropage_user_auth');
foreach ($columns as $c) {
switch($c['Field']) {
case 'user_id':
case 'login_opts':
case 'permissions':
break;
default:
db_execute('ALTER TABLE plugin_intropage_user_auth DROP COLUMN ' . $c['Field']);
break;
}
}
}
db_execute('UPDATE plugin_intropage_panel_data
SET alarm = "grey" WHERE alarm = "gray"');
db_execute('ALTER TABLE plugin_intropage_panel_dashboard
ADD PRIMARY KEY (panel_id, user_id, dashboard_id)');
db_execute('ALTER TABLE plugin_intropage_panel_data
MODIFY COLUMN `alarm` enum("red","green","yellow","grey") COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT "green"');
}
if (cacti_version_compare($oldv, '3.0.3', '<=')) {
if (!db_column_exists('plugin_intropage_panel_data', 'trend_interval')) {
db_execute('ALTER TABLE plugin_intropage_panel_data
ADD COLUMN trend_interval INT(9) UNSIGNED NOT NULL default "300" AFTER refresh_interval');
}
if (!db_column_exists('plugin_intropage_panel_data', 'last_trend_update')) {
db_execute('ALTER TABLE plugin_intropage_panel_data
ADD COLUMN last_trend_update TIMESTAMP NOT NULL default CURRENT_TIMESTAMP AFTER last_update');
}
if (!db_column_exists('plugin_intropage_panel_definition', 'trefresh')) {
db_execute('ALTER TABLE plugin_intropage_panel_definition
ADD COLUMN trefresh INT(10) UNSIGNED default "3600" AFTER refresh');
}
}
if (cacti_version_compare($oldv, '4.0.1', '<=')) {
db_execute('ALTER TABLE plugin_intropage_panel_data
CHANGE last_update last_update timestamp NOT NULL default current_timestamp');
}
if (cacti_version_compare($oldv, '4.0.2', '<=')) {
db_execute("UPDATE plugin_intropage_panel_definition SET panel_id='ntp_dns', name='NTP/DNS check' WHERE panel_id='ntp'");
db_execute("UPDATE plugin_intropage_panel_data SET panel_id='ntp_dns' WHERE panel_id='ntp'");
db_execute("UPDATE plugin_intropage_user_auth set permissions=REPLACE(permissions,'ntp','ntp_dns')");
db_execute('ALTER TABLE plugin_intropage_dashboard ADD COLUMN shared INT(1) NOT NULL default "0"');
db_execute('DELETE FROM plugin_hooks WHERE FUNCTION = "intropage_config_form" AND name="intropage"');
}
if (cacti_version_compare($oldv, '4.0.3', '<=')) {
db_execute("UPDATE plugin_intropage_trends SET name='host_down' WHERE name='host'");
db_execute("UPDATE plugin_intropage_trends SET name='thold_trig' WHERE name='thold'");
db_execute("DELETE FROM plugin_intropage_panel_definition WHERE panel_id = 'trend'");
db_execute("DELETE FROM plugin_intropage_panel_data WHERE panel_id = 'trend'");
}
if (cacti_version_compare($oldv, '4.0.4', '<=')) {
$data = [];
$data['columns'][] = ['name' => 'user_group_id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'login_opts', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '0'];
$data['columns'][] = ['name' => 'permissions', 'type' => 'blob', 'NULL' => false, 'default' => ''];
$data['type'] = 'InnoDB';
$data['primary'] = 'user_group_id';
$data['comment'] = 'authorization';
api_plugin_db_table_create('intropage', 'plugin_intropage_user_group_auth', $data);
api_plugin_register_hook('intropage', 'user_group_admin_tab', 'intropage_user_group_admin_tab', 'include/settings.php', '1');
api_plugin_register_hook('intropage', 'user_group_admin_run_action', 'intropage_user_group_admin_run_action', 'includes/settings.php', '1');
api_plugin_register_hook('intropage', 'user_group_admin_save', 'intropage_user_group_admin_save', 'include/settings.php', '1');
api_plugin_register_hook('intropage', 'user_group_remove', 'intropage_user_group_remove', 'setup.php', '1');
}
if (cacti_version_compare($oldv, '4.0.5', '<=')) {
db_execute('ALTER TABLE plugin_intropage_panel_definition
ADD COLUMN `height` enum("normal","double","triple") NOT NULL DEFAULT "normal"');
db_execute('ALTER TABLE plugin_intropage_panel_data
ADD COLUMN `height` enum("normal","double","triple") NOT NULL DEFAULT "normal"');
}
// Set the new version
db_execute_prepared("UPDATE plugin_config
SET version = ?, author = ?, webpage = ?
WHERE directory = 'intropage'",
[
$info['version'],
$info['author'],
$info['homepage']
]
);
if (!db_column_exists('plugin_intropage_panel_dashboard', 'priority')) {
db_execute("ALTER TABLE plugin_intropage_panel_dashboard ADD COLUMN priority int(11) DEFAULT '0'");
}
$panels = initialize_panel_library();
api_plugin_register_hook('intropage', 'page_head', 'intropage_page_head', 'setup.php', 1);
}
}