-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.php
332 lines (278 loc) · 10.9 KB
/
setup.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
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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2007-2024 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/ |
+-------------------------------------------------------------------------+
*/
include_once('audit_functions.php');
function plugin_audit_install() {
api_plugin_register_hook('audit', 'config_arrays', 'audit_config_arrays', 'setup.php');
api_plugin_register_hook('audit', 'config_settings', 'audit_config_settings', 'setup.php');
api_plugin_register_hook('audit', 'config_insert', 'audit_config_insert', 'setup.php');
api_plugin_register_hook('audit', 'poller_bottom', 'audit_poller_bottom', 'setup.php');
api_plugin_register_hook('audit', 'draw_navigation_text', 'audit_draw_navigation_text', 'setup.php');
api_plugin_register_hook('audit', 'utilities_array', 'audit_utilities_array', 'setup.php');
api_plugin_register_hook('audit', 'is_console_page', 'audit_is_console_page', 'setup.php');
/* hook for table replication */
api_plugin_register_hook('audit', 'replicate_out', 'audit_replicate_out', 'setup.php');
api_plugin_register_realm('audit', 'audit.php', __('View Cacti Audit Log', 'audit'), 1);
audit_setup_table();
}
function plugin_audit_uninstall() {
db_execute('DROP TABLE IF EXISTS audit_log');
return true;
}
function audit_is_console_page($url) {
if (strpos($url, 'audit.php') !== false) {
return true;
}
return false;
}
function plugin_audit_check_config() {
return true;
}
function plugin_audit_upgrade() {
return true;
}
function audit_check_upgrade() {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
include_once($config['library_path'] . '/functions.php');
$files = array('plugins.php', 'audit.php');
if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) {
return;
}
$info = plugin_audit_version();
$current = $info['version'];
$old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='audit'");
if ($current != $old) {
if (api_plugin_is_enabled('audit')) {
# may sound ridiculous, but enables new hooks
api_plugin_enable_hooks('audit');
db_execute('ALTER TABLE audit_log ADD COLUMN IF NOT EXISTS object_data LONGBLOB');
}
db_execute("UPDATE plugin_config
SET version='$current'
WHERE directory='audit'");
db_execute("UPDATE plugin_config SET
version='" . $info['version'] . "',
name='" . $info['longname'] . "',
author='" . $info['author'] . "',
webpage='" . $info['homepage'] . "'
WHERE directory='" . $info['name'] . "' ");
/* hook for table replication */
api_plugin_register_hook('audit', 'replicate_out', 'audit_replicate_out', 'setup.php', '1');
api_plugin_register_hook('audit', 'is_console_page', 'audit_is_console_page', 'setup.php', 1);
}
}
function audit_check_dependencies($data) {
$remote_poller_id = $data['remote_poller_id'];
$rcnn_id = $data['rcnn_id'];
$class = $data['class'];
if ($class == 'all') {
if (!db_table_exists('alert_log', false, $rcnn_id)) {
$create = db_fetch_cell('SHOW CREATE TABLE autid_log');
db_execute($create, false, $rcnn_id);
}
}
return $data;
}
function audit_replicate_out($data) {
$remote_poller_id = $data['remote_poller_id'];
$rcnn_id = $data['rcnn_id'];
$class = $data['class'];
cacti_log('INFO: Replicating for the Audit Plugin', false, 'REPLICATE');
if ($class == 'all') {
if (!db_table_exists('audit_log', false, $rcnn_id)) {
cacti_log('INFO: Audit Log table does not exist creating', false, 'REPLICATE');
$table = 'audit_log';
$create = db_fetch_row("SHOW CREATE TABLE $table");
if (isset($create["CREATE TABLE `$table`"]) || isset($create['Create Table'])) {
if (isset($create["CREATE TABLE `$table`"])) {
db_execute($create["CREATE TABLE `$table`"], true, $rcnn_id);
} else {
db_execute($create['Create Table'], true, $rcnn_id);
}
}
} else {
cacti_log('INFO: Audit Log table exists skipping', false, 'REPLICATE');
}
}
return $data;
}
function audit_poller_bottom() {
$last_check = read_config_option('audit_last_check');
$now = date('d');
if ($last_check != $now) {
$retention = read_config_option('audit_retention');
if ($retention > 0) {
db_execute('DELETE FROM audit_log WHERE event_time < FROM_UNIXTIME(' . (time() - ($retention * 86400)) . ')');
$rows = db_affected_rows();
cacti_log('NOTE: Purged ' . $rows . ' Audit Log Records from Cacti', false, 'POLLER');
}
}
set_config_option('audit_last_check', $now);
}
function audit_setup_table() {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
db_execute("CREATE TABLE IF NOT EXISTS `audit_log` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`page` varchar(40) DEFAULT NULL,
`user_id` int(10) unsigned DEFAULT NULL,
`action` varchar(20) DEFAULT NULL,
`ip_address` varchar(40) DEFAULT NULL,
`user_agent` varchar(256) DEFAULT NULL,
`event_time` timestamp DEFAULT CURRENT_TIMESTAMP,
`post` longblob,
`object_data` longblob,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `page` (`page`),
KEY `ip_address` (`ip_address`),
KEY `event_time` (`event_time`),
KEY `action` (`action`))
ENGINE=InnoDB
COMMENT='Audit Log for all GUI activities'");
return true;
}
function plugin_audit_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/audit/INFO', true);
return $info['info'];
}
function audit_log_valid_event() {
global $action;
$valid = false;
if (read_config_option('audit_enabled') == 'on') {
if (strpos($_SERVER['SCRIPT_NAME'], 'graph_view.php') !== false) {
$valid = false;
} elseif (strpos($_SERVER['SCRIPT_NAME'], 'user_admin.php') !== false &&
isset_request_var('action') && get_nfilter_request_var('action') == 'checkpass') {
$valid = false;
} elseif (strpos($_SERVER['SCRIPT_NAME'], 'plugins.php') !== false) {
if (isset_request_var('mode')) {
$valid = true;
$action = get_nfilter_request_var('mode');
}
} elseif (strpos($_SERVER['SCRIPT_NAME'], 'auth_profile.php') !== false) {
$valid = false;
} elseif (strpos($_SERVER['SCRIPT_NAME'], 'index.php') !== false) {
$valid = false;
} elseif (strpos($_SERVER['SCRIPT_NAME'], 'auth_changepassword.php') !== false) {
$valid = false;
} elseif (isset($_POST) && sizeof($_POST)) {
$valid = true;
} elseif (isset_request_var('purge_continue')) {
$valid = true;
$action = 'purge';
}
}
return $valid;
}
function audit_utilities_array() {
global $utilities;
if (version_compare(CACTI_VERSION, '1.3.0', '<')) {
if (api_plugin_user_realm_auth('audit.php')) {
$utilities[__('Technical Support', 'audit')] = array_merge(
$utilities[__('Technical Support', 'audit')],
array(
__('View Audit Log', 'audit') => array(
'link' => 'plugins/audit/audit.php',
'description' => __('Allows Administrators to view change activity on the Cacti server. Administrators can also export the audit log for analysis purposes.', 'audit')
)
)
);
}
}
}
function audit_config_arrays() {
global $menu, $messages, $audit_retentions, $utilities;
if (isset($_SESSION['audit_message']) && $_SESSION['audit_message'] != '') {
$messages['audit_message'] = array('message' => $_SESSION['audit_message'], 'type' => 'info');
}
$audit_retentions = array(
-1 => __('Indefinitely', 'audit'),
14 => __('%d Weeks', 2, 'audit'),
30 => __('%d Month', 1, 'audit'),
60 => __('%d Months', 2, 'audit'),
90 => __('%d Months', 3, 'audit'),
120 => __('%d Months', 4, 'audit'),
183 => __('%d Months', 6, 'audit'),
365 => __('%d Year', 1, 'audit'),
730 => __('%d Years', 2, 'audit'),
1095 => __('%d Years', 3, 'audit')
);
$menu[__('Utilities')]['plugins/audit/audit.php'] = __('Audit Log', 'audit');
if (function_exists('auth_augment_roles')) {
auth_augment_roles(__('System Administration'), array('audit.php'));
}
audit_check_upgrade();
}
function audit_config_settings() {
global $tabs, $settings, $item_rows, $audit_retentions;
$temp = array(
'audit_header' => array(
'friendly_name' => __('Audit Log Settings', 'audit'),
'method' => 'spacer',
),
'audit_enabled' => array(
'friendly_name' => __('Enable Audit Log', 'audit'),
'description' => __('Check this box, if you want the Audit Log to track GUI activities.', 'audit'),
'method' => 'checkbox',
'default' => 'on'
),
'audit_retention' => array(
'friendly_name' => __('Audit Log Retention', 'audit'),
'description' => __('How long do you wish Audit Log entries to be retained?', 'audit'),
'method' => 'drop_array',
'default' => '90',
'array' => $audit_retentions
),
'audit_log_external' => array(
'friendly_name' => __('External Audit Log', 'audit'),
'description' => __('Check this box, if you want the Audit Log to be written to an external file.', 'audit'),
'method' => 'checkbox',
'default' => 'off'
),
'audit_log_external_path' => array(
'friendly_name' => __('External Audit Log Log file Path', 'audit'),
'description' => __('Enter the path to the external audit log file.', 'audit'),
'method' => 'filepath',
'default' => '/var/www/html/cacti/log/audit.log',
'max_length' => '255'
),
);
$tabs['audit'] = __('Audit', 'audit');
if (isset($settings['audit'])) {
$settings['audit'] = array_merge($settings['audit'], $temp);
} else {
$settings['audit'] = $temp;
}
}
function audit_draw_navigation_text($nav) {
$nav['audit.php:'] = array(
'title' => __('Audit Event Log', 'audit'),
'mapping' => 'index.php:',
'url' => 'audit.php',
'level' => '1'
);
return $nav;
}