-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrouter-devtypes.php
More file actions
391 lines (329 loc) · 14.6 KB
/
Copy pathrouter-devtypes.php
File metadata and controls
391 lines (329 loc) · 14.6 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
declare(strict_types = 1);
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 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/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
require_once('./include/auth.php');
require_once(__DIR__ . '/includes/functions.php');
set_default_action();
set_request_var('tab', 'devtypes');
switch (get_request_var('action')) {
case 'actions':
actions_devicetypes();
break;
case 'save':
save_devicetypes();
break;
case 'edit':
general_header();
display_tabs();
edit_devicetypes();
bottom_footer();
break;
default:
general_header();
display_tabs();
show_devicetypes();
bottom_footer();
break;
}
/**
* Handles the bulk-actions form for the Device Types list (currently
* only delete). On first display, renders the confirmation dialog
* listing the selected device types; once confirmed, deletes each
* selected device type. Invoked from this file's dispatcher when the
* request's 'action' is 'actions'.
*
* @return void Either redirects back to the list after deleting, or
* prints the confirmation dialog and returns nothing.
*
* @global array $rc_devtype_actions Map of bulk-action ids to their
* display labels, used for the
* confirmation dialog title.
* @global array $config Cacti global configuration array
* (declared but not directly used
* here).
*/
function actions_devicetypes() {
global $rc_devtype_actions, $config;
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') {
for ($i = 0; $i < cacti_count($selected_items); $i++) {
db_execute_prepared('DELETE FROM plugin_routerconfigs_devicetypes
WHERE id = ?',
[$selected_items[$i]]);
}
}
}
header('Location: router-devtypes.php?header=false');
exit;
}
// setup some variables
$devtype_list = '';
$devtype_array = [];
// loop through each of the devices selected on the previous page and get more info about them
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
// ================= input validation =================
input_validate_input_number($matches[1]);
// ====================================================
$devtype_list .= '<li>' . html_escape(db_fetch_cell_prepared('SELECT name FROM plugin_routerconfigs_devicetypes WHERE id = ?', [(int) $matches[1]])) . '</li>';
$devtype_array[] = $matches[1];
}
}
if (read_config_option('routerconfigs_presentation') == 'console') {
top_header();
} else {
general_header();
}
form_start('router-devtypes.php');
$drp_action = (int) get_nfilter_request_var('drp_action');
if ($drp_action > 0 && array_key_exists($drp_action, $rc_devtype_actions)) {
html_start_box($rc_devtype_actions[$drp_action], '60%', false, 3, 'center', '');
} else {
html_start_box('', '60%', false, 3, 'center', '');
}
if (cacti_sizeof($devtype_array)) {
if ($drp_action == RCONFIG_DEVTYPE_DELETE) { // Delete
print "<tr>
<td colspan='2' class='textArea'>
<p>" . __('When you click \'Continue\', the following device(s) will be deleted.', 'routerconfigs') . "</p>
<ul>$devtype_list</ul>
</td>
</tr>";
}
$save_html = "<input type='button' value='" . __esc('Cancel', 'routerconfigs') . "' onClick='cactiReturnTo()'> <input type='submit' value='" . __esc('Continue', 'routerconfigs') . "' title='" . __esc('Delete Device(s)', 'routerconfigs') . "'>";
} else {
print "<tr><td class='even'><span class='textError'>You must select at least one device for this function.</span></td></tr>\n";
$save_html = "<input type='button' value='Return' onClick='cactiReturnTo()'>";
}
print "<tr>
<td class='saveRow'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . serialize($devtype_array) . "'>
<input type='hidden' name='drp_action' value='" . html_escape(get_request_var('drp_action')) . "'>
$save_html
</td>
</tr>";
html_end_box();
form_end();
bottom_footer();
}
/**
* Validates and saves a single router device type's configuration
* (connection type, prompt patterns, config-file/TFTP settings, confirm/
* force-confirm behavior, timeouts). Invoked from this file's dispatcher
* when the request's 'action' is 'save'.
*
* @return void Redirects back to the edit form for this device type;
* does not return a value.
*/
function save_devicetypes() {
// ================= input validation =================
get_filter_request_var('id');
// ====================================================
if (isset_request_var('id')) {
$save['id'] = get_request_var('id');
} else {
$save['id'] = '';
}
$save['name'] = get_nfilter_request_var('name');
$save['promptuser'] = get_nfilter_request_var('promptuser');
$save['promptpass'] = get_nfilter_request_var('promptpass');
$save['connecttype'] = get_nfilter_request_var('connecttype');
$save['configfile'] = get_nfilter_request_var('configfile');
$save['copytftp'] = get_nfilter_request_var('copytftp');
$save['version'] = get_nfilter_request_var('version');
$save['promptconfirm'] = get_nfilter_request_var('promptconfirm');
$save['confirm'] = get_nfilter_request_var('confirm');
$save['forceconfirm'] = get_nfilter_request_var('forceconfirm');
$save['checkendinconfig'] = get_nfilter_request_var('checkendinconfig');
$save['timeout'] = get_nfilter_request_var('timeout');
$save['sleep'] = get_nfilter_request_var('sleep');
$save['anykey'] = get_nfilter_request_var('anykey');
$save['elevated'] = get_nfilter_request_var('elevated');
if (!is_error_message()) {
$id = sql_save($save, 'plugin_routerconfigs_devicetypes', 'id');
if ($id) {
raise_message(1);
} else {
raise_message(2);
}
}
header('Location: router-devtypes.php?action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
exit;
}
/**
* Renders the add/edit form for a single router device type,
* pre-populating its fields when editing an existing device type.
* Invoked from this file's dispatcher when the request's 'action' is
* 'edit'.
*
* @return void Outputs the edit form HTML directly.
*
* @global array $config Cacti global configuration
* array (declared but not
* directly used here).
* @global mixed $form_id Reserved/declared for parity
* with other functions in this
* file; not used directly here.
* @global array $rc_devtype_edit_fields The edit form's field
* definitions, filled in here
* with the device type's current
* values.
*/
function edit_devicetypes() {
global $config, $form_id, $rc_devtype_edit_fields;
// ================= input validation =================
get_filter_request_var('id');
// ====================================================
$devicetype = [];
if (!isempty_request_var('id')) {
$devicetype = db_fetch_row_prepared('SELECT *
FROM plugin_routerconfigs_devicetypes
WHERE id = ?',
[get_request_var('id')]);
$devicetype = is_array($devicetype) ? $devicetype : [];
if (!isset($devicetype['id'])) {
header('Location: router-devtypes.php?header=false');
exit;
}
$header_label = __('Query [edit: %s]', $devicetype['name'], 'routerconfigs');
} else {
$header_label = __('Query [new]', 'routerconfigs');
}
form_start('router-devtypes.php', 'chk');
html_start_box($header_label, '100%', false, 3, 'center', '');
draw_edit_form(
[
'config' => ['no_form_tag' => true],
'fields' => inject_form_variables($rc_devtype_edit_fields, $devicetype)
]
);
html_end_box();
form_save_button('router-devtypes.php');
}
/**
* Renders the main Device Types list page: a paginated table of
* configured router device types with their connection/prompt settings.
* Invoked from this file's dispatcher for the default (no 'action')
* request.
*
* @return void Outputs the list page HTML directly.
*
* @global mixed $host Reserved/declared for parity with
* other functions in this file; not
* used directly here.
* @global mixed $username Reserved/declared for parity with
* other functions in this file; not
* used directly here.
* @global mixed $password Reserved/declared for parity with
* other functions in this file; not
* used directly here.
* @global mixed $command Reserved/declared for parity with
* other functions in this file; not
* used directly here.
* @global array $config Cacti global configuration array
* (declared but not directly used
* here).
* @global array $rc_devtype_actions Map of bulk-action ids to their
* display labels, used to populate
* the actions dropdown.
* @global mixed $acc Reserved/declared for parity with
* other functions in this file; not
* used directly here.
* @global mixed $form_id Reserved/declared for parity with
* other functions in this file; not
* used directly here.
*/
function show_devicetypes() {
global $host, $username, $password, $command;
global $config, $rc_devtype_actions, $acc, $form_id;
// ================= input validation =================
get_filter_request_var('account');
get_filter_request_var('page');
// ====================================================
$account = '';
if (isset_request_var('account')) {
$account = get_request_var('account');
}
load_current_session_value('page', 'sess_routerconfigs_devtypes_current_page', '1');
$num_rows = 30;
$result = db_fetch_assoc_prepared('SELECT *
FROM plugin_routerconfigs_devicetypes
ORDER BY id
LIMIT ' . ($num_rows * ((int) get_request_var('page') - 1)) . ', ' . $num_rows,
[]);
if ($account != '') {
$total_rows = db_fetch_cell_prepared('SELECT COUNT(*)
FROM plugin_routerconfigs_devicetypes
WHERE account = ?',
[(int) $account]);
} else {
$total_rows = db_fetch_cell_prepared('SELECT COUNT(*)
FROM plugin_routerconfigs_devicetypes', []);
}
$nav = html_nav_bar('router-devtypes.php', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, 11, __('Device Types', 'routerconfigs'), 'page', 'main');
form_start('router-devtypes.php', 'chk');
html_start_box(__('View Router Device Types', 'routerconfigs'), '100%', false, 4, 'center', 'router-devtypes.php?action=edit');
print $nav;
html_header_checkbox(
[
__('ID', 'routerconfigs'),
__('Name', 'routerconfigs'),
__('Type', 'routerconfigs'),
__('User Prompt', 'routerconfigs'),
__('Pass Prompt', 'routerconfigs'),
__('Copy TFTP', 'routerconfigs'),
__('Version', 'routerconfigs'),
__('Confirm', 'routerconfigs'),
__('Force Confirm', 'routerconfigs'),
__('Confirm Prompt', 'routerconfigs'),
__('Check End In Config', 'routerconfigs')
]
);
if (cacti_sizeof($result)) {
foreach ($result as $row) {
form_alternate_row('line' . $row['id'], false);
form_selectable_cell($row['id'], $row['id']);
form_selectable_cell('<a class="linkEditMain" href="' . html_escape('router-devtypes.php?&action=edit&id=' . $row['id']) . '">' . html_escape($row['name']) . '</a>', $row['id']);
form_selectable_cell(html_escape($row['connecttype']), $row['id']);
form_selectable_cell(html_escape($row['promptuser']), $row['id']);
form_selectable_cell(html_escape($row['promptpass']), $row['id']);
form_selectable_cell(html_escape($row['copytftp']), $row['id']);
form_selectable_cell(html_escape($row['version']), $row['id']);
form_selectable_cell(($row['confirm'] == 'y' ? '<span class="deviceUp">' . __('Yes', 'routerconfigs') . '</span>' : '<span class="deviceDown">' . __('No', 'routerconfigs') . '</span>'), $row['id']);
form_selectable_cell(($row['forceconfirm'] == 'on' ? '<span class="deviceUp">' . __('Yes', 'routerconfigs') . '</span>' : '<span class="deviceDown">' . __('No', 'routerconfigs') . '</span>'), $row['id']);
form_selectable_cell(html_escape($row['promptconfirm']), $row['id']);
form_selectable_cell(($row['checkendinconfig'] == 'on' ? '<span class="deviceUp">' . __('Yes', 'routerconfigs') . '</span>' : '<span class="deviceDown">' . __('No', 'routerconfigs') . '</span>'), $row['id']);
form_checkbox_cell($row['name'], $row['id']);
form_end_row();
}
} else {
print "<tr class='even'><td colspan='11'>" . __('No Router Device Types Found', 'routerconfigs') . "</td></tr>\n";
}
html_end_box(false);
draw_actions_dropdown($rc_devtype_actions);
}