-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsyslog_dashboards.php
More file actions
747 lines (632 loc) · 23.5 KB
/
Copy pathsyslog_dashboards.php
File metadata and controls
747 lines (632 loc) · 23.5 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
<?php
chdir('../../');
include('./include/auth.php');
include_once('./plugins/syslog/functions.php');
include_once('./plugins/syslog/database.php');
include_once(__DIR__ . '/lib/syslog_dashboard.php');
// The page is part of the Syslog Administration realm. Accept the explicit
// realm lookup too so pre-existing installs work before realm repair runs.
if (!api_plugin_user_realm_auth('syslog_dashboards.php') && !api_plugin_user_realm_auth('syslog_alerts.php')) {
die(__('Permission denied.', 'syslog'));
}
syslog_connect();
set_default_action();
global $syslogdb_default;
$db = $syslogdb_default;
$error = '';
$edit = get_filter_request_var('edit', FILTER_VALIDATE_INT);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset_request_var('save_dashboard')) {
$id = get_filter_request_var('id', FILTER_VALIDATE_INT);
$name = trim((string) get_nfilter_request_var('name'));
$owner = trim((string) get_nfilter_request_var('owner'));
$edit = $id;
if ($id > 0 && $name !== '' && strlen($name) <= 128) {
$usernames = array_rekey(db_fetch_assoc('SELECT username FROM user_auth'), 'username', 'username');
if ($owner === '' || !isset($usernames[$owner])) {
$error = __('Select a valid owner.', 'syslog');
} else {
if (!syslog_db_execute_prepared("UPDATE $db.syslog_dashboards SET name = ?, `user` = ?, updated = ? WHERE id = ?", [$name, $owner, time(), $id])) {
$error = __('Unable to save the dashboard. Please try again.', 'syslog');
} else {
// Replace the user/group grants with the posted selections.
syslog_save_item_shares('dashboard', $id,
syslog_parse_share_ids('shared_users'),
syslog_parse_share_ids('shared_groups'));
}
}
} else {
$error = __('Enter a dashboard name between 1 and 128 characters.', 'syslog');
}
if ($error === '') {
header('Location: syslog_dashboards.php');
exit;
}
}
if ((isset_request_var('import') || isset_request_var('save_component_import')) && syslog_allow_edits()) {
set_request_var('action', 'import');
}
$row = $edit > 0 ? syslog_db_fetch_row_prepared("SELECT id, name, `user`, is_global, updated FROM $db.syslog_dashboards WHERE id = ?", [$edit]) : false;
if ($row && $error !== '') {
$row['name'] = $name;
}
switch (get_request_var('action')) {
case 'actions':
syslog_dashboard_actions();
exit;
case 'export':
syslog_dashboard_export();
exit;
case 'import':
if (isset_request_var('save_component_import')) {
syslog_dashboard_import();
} else {
top_header();
syslog_include_js();
syslog_dashboard_import_form();
bottom_footer();
}
exit;
case 'edit':
default:
top_header();
syslog_include_js();
if ($row) {
syslog_dashboard_edit($row, $error);
} else {
syslog_dashboards();
}
break;
}
?>
<script type='text/javascript'>
$(function() {
initSyslogTemplates();
<?php if ($row) { ?>
$('#shared_users').multiselect({
selectedList: 7,
noneSelectedText: '<?php print __esc('Share with users…', 'syslog'); ?>',
header: false,
height: 200,
menuWidth: 300
});
$('#shared_groups').multiselect({
selectedList: 7,
noneSelectedText: '<?php print __esc('Share with groups…', 'syslog'); ?>',
header: false,
height: 200,
menuWidth: 300
});
<?php } ?>
});
</script>
<?php
bottom_footer();
/**
* Render the dashboards list page.
*
* @return void
*/
function syslog_dashboards() {
global $db, $config;
// ================= input validation and session storage =================
$filters = [
'rows' => [
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
],
'page' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
],
'filter' => [
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
],
'sort_column' => [
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => ['options' => 'sanitize_search_string']
],
'sort_direction' => [
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => ['options' => 'sanitize_search_string']
]
];
validate_store_request_vars($filters, 'sess_syslogdb');
// ================= input validation =================
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} elseif (get_request_var('rows') == -2) {
$rows = 999999;
} else {
$rows = get_request_var('rows');
}
$sql_where = 'WHERE 1=1';
$sql_params = [];
if (get_request_var('filter') != '') {
$sql_where .= ' AND (d.name LIKE ? OR d.`user` LIKE ?)';
$filter = '%' . get_request_var('filter') . '%';
$sql_params = [$filter, $filter];
}
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
$dashboards = syslog_db_fetch_assoc_prepared("SELECT d.id, d.name, d.`user`, d.is_global, d.updated,
(SELECT COUNT(*) FROM $db.syslog_dashboard_panels p WHERE p.dashboard_id = d.id) AS panels
FROM $db.syslog_dashboards d
$sql_where
$sql_order
$sql_limit", $sql_params) ?: [];
$total_rows = syslog_db_fetch_cell_prepared("SELECT COUNT(*)
FROM $db.syslog_dashboards d
$sql_where", $sql_params);
$display_text = [
'name' => [__('Name', 'syslog'), 'ASC'],
'user' => [__('Owner', 'syslog'), 'ASC'],
'is_global' => [__('Shared', 'syslog'), 'ASC'],
'panels' => [__('Panels', 'syslog'), 'ASC'],
'updated' => [__('Updated', 'syslog'), 'ASC']
];
if (syslog_allow_edits()) {
$url = 'syslog_dashboards.php?action=edit';
} else {
$url = '';
}
$nav = html_nav_bar('syslog_dashboards.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text) + 1, __('Dashboards', 'syslog'), 'page', 'main');
html_start_box(__('Dashboards', 'syslog'), '100%', '', '3', 'center', $url);
syslog_dashboard_filter();
html_end_box();
syslog_dashboard_table($dashboards, $nav, $display_text);
}
/**
* Render the filter row for the dashboards list.
*
* @return void
*/
function syslog_dashboard_filter() {
global $config, $item_rows;
?>
<tr class='even'>
<td>
<form id='dashboards' action='syslog_dashboards.php' method='get'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search', 'syslog'); ?>
</td>
<td>
<input type='text' id='filter' size='25' value='<?php print html_escape_request_var('filter'); ?>'>
</td>
<td>
<?php print __('Rows', 'syslog'); ?>
</td>
<td>
<select id='rows' onChange='applyFilterDashboards()'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'syslog'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
print '<option value="' . $key . '"';
if (get_request_var('rows') == $key) {
print ' selected';
} print '>' . $value . "</option>\n";
}
}
?>
</select>
</td>
<td>
<span>
<input id='refresh' type='button' value='<?php print __esc('Go', 'syslog'); ?>'>
<input id='clear' type='button' value='<?php print __esc('Clear', 'syslog'); ?>'>
<?php if (syslog_allow_edits()) {?><input id='import' type='button' value='<?php print __esc('Import', 'syslog'); ?>'><?php } ?>
</span>
</td>
</tr>
</table>
<input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?>'>
</form>
<script type='text/javascript'>
initSyslogDashboards();
</script>
</td>
</tr>
<?php
}
/**
* Render the dashboards table.
*
* @param list<array<string, mixed>> $rows The dashboard rows to display.
* @param string $nav The navigation bar HTML to print above and below the table.
* @param array<string, array<int, string>> $display_text The sortable column display text.
*
* @return void
*/
function syslog_dashboard_table($rows, $nav = '', $display_text = []) {
global $db;
if (!cacti_sizeof($display_text)) {
$display_text = [
'name' => [__('Name', 'syslog'), 'ASC'],
'user' => [__('Owner', 'syslog'), 'ASC'],
'is_global' => [__('Shared', 'syslog'), 'ASC'],
'panels' => [__('Panels', 'syslog'), 'ASC'],
'updated' => [__('Updated', 'syslog'), 'ASC']
];
}
// Flag dashboards whose owner no longer exists so admins can clean up
// after deleting a Cacti user.
$usernames = [];
$known = db_fetch_assoc('SELECT username FROM user_auth');
if ($known) {
$usernames = array_rekey($known, 'username', 'username');
}
$actions = [1 => __('Delete', 'syslog'), 2 => __('Export', 'syslog')];
form_start('syslog_dashboards.php', 'chk');
if ($nav !== '') {
print $nav;
}
html_start_box('', '100%', '', '3', 'center', '');
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (cacti_sizeof($rows)) {
foreach ($rows as $dashboard) {
$id = (int) $dashboard['id'];
$owner = html_escape($dashboard['user']);
if (isset($usernames) && cacti_sizeof($usernames) && !isset($usernames[$dashboard['user']])) {
$owner .= ' (' . __('deleted user', 'syslog') . ')';
}
form_alternate_row('line' . $id, true);
print "<td><a class='linkEditMain' href='syslog_dashboards.php?edit=$id'>" . html_escape($dashboard['name']) . '</a></td>';
print '<td>' . $owner . '</td>';
print '<td>' . ($dashboard['is_global'] === 'on' ? __('Yes', 'syslog') : __('No', 'syslog')) . '</td>';
print '<td>' . (int) $dashboard['panels'] . '</td>';
print '<td>' . ((int) $dashboard['updated'] > 0 ? date('Y-m-d H:i:s', (int) $dashboard['updated']) : __('Never', 'syslog')) . '</td>';
form_checkbox_cell($dashboard['name'], $id);
form_end_row();
}
} else {
print "<tr><td colspan='6'><em>" . __('No dashboards yet. Users create them from the Dashboard tab of Syslog.', 'syslog') . '</em></td></tr>';
}
html_end_box(false);
if ($nav !== '') {
print $nav;
}
draw_actions_dropdown($actions);
// Bulk actions can return a JSON attachment; bypass Cacti's HTML AJAX handler.
form_end(false);
}
/**
* Run the bulk action requested for the selected dashboards.
*
* @return void
*/
function syslog_dashboard_actions() {
global $db;
$actions = [1 => __('Delete', 'syslog'), 2 => __('Export', 'syslog')];
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP,
['options' => ['regexp' => '/^([a-zA-Z0-9_]+)$/']]);
if (!isset($actions[get_request_var('drp_action')])) {
header('Location: syslog_dashboards.php');
exit;
}
// if we are to save this form, instead of display it
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false && get_request_var('drp_action') == '2') {
syslog_dashboard_export();
exit;
}
$action_map = ['1' => 'api_syslog_dashboard_remove'];
syslog_apply_selected_items_action($selected_items, (string) get_request_var('drp_action'), $action_map);
header('Location: syslog_dashboards.php');
exit;
}
top_header();
form_start('syslog_dashboards.php');
html_start_box($actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
// loop through each of the dashboards selected on the previous page and get more info about them
$dashboard_list = '';
$dashboard_array = [];
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
// ================= input validation =================
input_validate_input_number($matches[1]);
// ====================================================
$name = syslog_db_fetch_cell_prepared("SELECT name
FROM $db.syslog_dashboards
WHERE id = ?",
[$matches[1]]);
if ($name !== false && $name !== null) {
$dashboard_list .= '<li>' . html_escape($name) . '</li>';
$dashboard_array[] = $matches[1];
}
}
}
if (cacti_sizeof($dashboard_array)) {
if (get_request_var('drp_action') == '1') { // delete
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to Delete the following Dashboard(s) and all of their Panels.', 'syslog') . "</p>
<div class='itemlist'><ul>$dashboard_list</ul></div>
</td>
</tr>";
$title = __esc('Delete Dashboard(s)', 'syslog');
} elseif (get_request_var('drp_action') == '2') { // export
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to Export the following Dashboard(s).', 'syslog') . "</p>
<div class='itemlist'><ul>$dashboard_list</ul></div>
</td>
</tr>";
$title = __esc('Export Dashboard(s)', 'syslog');
}
$save_html = "<input type='button' value='" . __esc('Cancel', 'syslog') . "' onClick='cactiReturnTo()'> <input type='submit' class='export' value='" . __esc('Continue', 'syslog') . "' title='$title'>";
} else {
raise_message(40);
header('Location: syslog_dashboards.php');
exit;
}
print "<tr>
<td align='right' class='saveRow'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . serialize($dashboard_array) . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>
$save_html
</td>
</tr>";
html_end_box();
// Bulk actions can return a JSON attachment; bypass Cacti's HTML AJAX handler.
syslog_export_form_end(get_request_var('drp_action') == '2');
bottom_footer();
}
/**
* Remove a dashboard, its panels and its shares.
*
* @param int $id The id of the dashboard to remove.
*
* @return void
*/
function api_syslog_dashboard_remove($id) {
global $db;
// Panels first, then the dashboard itself.
syslog_db_execute_prepared("DELETE FROM $db.syslog_dashboard_panels WHERE dashboard_id = ?", [$id]);
syslog_db_execute_prepared("DELETE FROM $db.syslog_dashboards WHERE id = ?", [$id]);
syslog_db_execute_prepared("DELETE FROM $db.syslog_dashboards_perm WHERE dashboard_id = ?", [$id]);
}
/**
* Export the selected dashboards as a JSON attachment.
*
* @return void
*/
function syslog_dashboard_export() {
global $db;
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
$dashboards = [];
foreach ($selected_items as $id) {
if ($id <= 0) {
continue;
}
$dashboard = syslog_db_fetch_row_prepared("SELECT *
FROM $db.syslog_dashboards
WHERE id = ?",
[$id]);
if (!cacti_sizeof($dashboard)) {
continue;
}
unset($dashboard['id']);
$dashboard['panels'] = syslog_dashboard_panels($id);
foreach ($dashboard['panels'] as &$panel) {
unset($panel['id'], $panel['dashboard_id']);
}
$dashboard['shared_users'] = array_column(syslog_fetch_item_shares('dashboard', $id)['users'], 'id');
$dashboard['shared_groups'] = array_column(syslog_fetch_item_shares('dashboard', $id)['groups'], 'id');
$dashboards[] = $dashboard;
}
$output = syslog_rules_array2json('syslog_dashboards', $dashboards);
header('Content-type: application/json');
header('Content-Disposition: attachment; filename=syslog_dashboards_export.json');
print $output;
}
}
}
/**
* Import dashboards from the posted JSON payload.
*
* @return void
*/
function syslog_dashboard_import() {
global $db;
$import_data = syslog_get_import_xml_payload('syslog_dashboards.php');
$import_array = syslog_parse_rule_import($import_data, 'syslog_dashboards');
if ($import_array === false || !$import_array) {
raise_message('syslog_import_error', __('Import rejected: the file is empty, invalid, or contains a different type of Syslog object.', 'syslog'), MESSAGE_LEVEL_ERROR);
header('Location: syslog_dashboards.php');
return;
}
$imported = 0;
$updated = 0;
$failed = 0;
if ($import_array !== false && cacti_sizeof($import_array)) {
foreach ($import_array as $contents) {
if (!is_array($contents)) {
continue;
}
$save = [
'name' => $contents['name'] ?? '',
'user' => $contents['user'] ?? get_username($_SESSION['sess_user_id']),
'is_global' => $contents['is_global'] ?? '',
'date' => $contents['date'] ?? time(),
'updated' => $contents['updated'] ?? time(),
];
if (isset($contents['hash']) && $contents['hash'] !== '') {
$save['hash'] = $contents['hash'];
$found = syslog_db_fetch_cell_prepared("SELECT id
FROM $db.syslog_dashboards
WHERE hash = ?",
[$contents['hash']]);
if (!empty($found)) {
$save['id'] = $found;
} else {
$save['id'] = 0;
}
} else {
$save['hash'] = generate_hash();
$save['id'] = 0;
}
if ($save['name'] === '' || strlen($save['name']) > 128) {
$failed++;
continue;
}
$panels = $contents['panels'] ?? [];
$shared_users = $contents['shared_users'] ?? [];
$shared_groups = $contents['shared_groups'] ?? [];
unset($contents['panels'], $contents['shared_users'], $contents['shared_groups']);
foreach ($contents as $name => $value) {
if (syslog_db_column_exists('syslog_dashboards', $name) && !isset($save[$name])) {
$save[$name] = $value;
}
}
$id = syslog_sql_save($save, 'syslog_dashboards', 'id');
if (!$id) {
$failed++;
continue;
}
// An exported empty dashboard must also clear existing panels.
if (!syslog_db_execute_prepared("DELETE FROM $db.syslog_dashboard_panels WHERE dashboard_id = ?", [$id])) {
$failed++;
continue;
}
if (cacti_sizeof($panels)) {
foreach ($panels as $panel) {
if (!is_array($panel)) {
continue;
}
$panel_save = [
'dashboard_id' => $id,
'title' => $panel['title'] ?? '',
'expression' => $panel['expression'] ?? '',
'source' => $panel['source'] ?? 'syslog',
'removal' => $panel['removal'] ?? 1,
'kind' => $panel['kind'] ?? 'timeseries',
'chart' => $panel['chart'] ?? 'line',
'field' => $panel['field'] ?? 'host',
'interval' => $panel['interval'] ?? 'dashboard',
'timespan' => $panel['timespan'] ?? 'dashboard',
'top_n' => $panel['top_n'] ?? 10,
'width' => $panel['width'] ?? 1,
'height' => $panel['height'] ?? 0,
'position' => $panel['position'] ?? 0,
'date' => $panel['date'] ?? time(),
];
if (!syslog_db_execute_prepared("INSERT INTO $db.syslog_dashboard_panels
(dashboard_id, title, expression, source, removal, kind, chart, field,
`interval`, timespan, top_n, width, height, position, `date`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[
$panel_save['dashboard_id'], $panel_save['title'], $panel_save['expression'],
$panel_save['source'], $panel_save['removal'], $panel_save['kind'],
$panel_save['chart'], $panel_save['field'], $panel_save['interval'],
$panel_save['timespan'], $panel_save['top_n'], $panel_save['width'],
$panel_save['height'], $panel_save['position'], $panel_save['date'],
])) {
$failed++;
continue 2;
}
}
}
if (is_array($shared_users) || is_array($shared_groups)) {
syslog_save_item_shares('dashboard', $id, $shared_users, $shared_groups);
}
if ($save['id'] > 0) {
$updated++;
} else {
$imported++;
}
}
}
if ($imported || $updated) {
raise_message('syslog_info', __esc('NOTE: Imported %d and updated %d Dashboard(s).', $imported, $updated, 'syslog'), MESSAGE_LEVEL_INFO);
}
if ($failed) {
raise_message('syslog_error', __esc('ERROR: %d Dashboard(s) failed to import.', $failed, 'syslog'), MESSAGE_LEVEL_ERROR);
}
header('Location: syslog_dashboards.php');
}
/**
* Display the dashboard import form.
*
* @return void
*/
function syslog_dashboard_import_form() {
if (!syslog_allow_edits()) {
header('Location: syslog_dashboards.php');
exit;
}
$form_data = [
'import_file' => [
'friendly_name' => __('Import Dashboard from Local File', 'syslog'),
'description' => __('If the JSON file containing the Dashboard definition data is located on your local machine, select it here.', 'syslog'),
'method' => 'file'
],
'import_text' => [
'method' => 'textarea',
'friendly_name' => __('Import Dashboard from Text', 'syslog'),
'description' => __('If you have the JSON file containing the Dashboard definition data as text, you can paste it into this box to import it.', 'syslog'),
'value' => '',
'default' => '',
'textarea_rows' => '10',
'textarea_cols' => '80',
'class' => 'textAreaNotes'
]
];
print "<form method='post' action='syslog_dashboards.php' enctype='multipart/form-data'>";
html_start_box(__('Import Dashboard', 'syslog'), '100%', false, '3', 'center', '');
draw_edit_form(
[
'config' => ['no_form_tag' => true],
'fields' => $form_data
]
);
html_end_box();
form_hidden_box('save_component_import', '1', '');
form_save_button('', 'import', 'id', false);
}
/**
* Display the dashboard edit form.
*
* @param array<string, mixed> $row The dashboard row being edited.
* @param string $error The error message to display, if any.
*
* @return void
*/
function syslog_dashboard_edit($row, $error) {
// Cacti accounts and groups to grant this dashboard to, beyond its owner
// and the global share flag. The 'all' entry shares it with every
// signed-in user.
$usernames = array_rekey(db_fetch_assoc('SELECT username FROM user_auth ORDER BY username'), 'username', 'username');
$users = array_rekey(db_fetch_assoc('SELECT id, username FROM user_auth ORDER BY username'), 'id', 'username');
$groups = array_rekey(db_fetch_assoc('SELECT id, name FROM user_auth_group ORDER BY name'), 'id', 'name');
$shares = syslog_fetch_item_shares('dashboard', (int) $row['id']);
$users = ['all' => __('All Users', 'syslog')] + $users;
$groups = ['all' => __('All Groups', 'syslog')] + $groups;
form_start('syslog_dashboards.php', 'syslog_dashboard_form');
html_start_box(__('Edit Dashboard', 'syslog'), '100%', '', '3', 'center', '');
draw_edit_form(['config' => ['no_form_tag' => true], 'fields' => [
'name' => ['friendly_name' => __('Name', 'syslog'), 'method' => 'textbox', 'value' => $row['name'], 'max_length' => 128, 'size' => 60, 'description' => __('The name shown in the Dashboards select of the Syslog Dashboard tab.', 'syslog')],
'owner' => ['friendly_name' => __('Owner', 'syslog'), 'method' => 'drop_array', 'array' => $usernames, 'value' => $row['user'], 'description' => __('The account that owns this dashboard and can manage its panels.', 'syslog')],
'shared' => ['friendly_name' => __('Shared', 'syslog'), 'method' => 'static', 'value' => $row['is_global'] === 'on' ? __('Yes', 'syslog') : __('No', 'syslog')],
'shared_users' => ['friendly_name' => __('Shared With Users', 'syslog'), 'method' => 'drop_multi', 'array' => $users, 'value' => $shares['users'], 'description' => __('Users who can view this dashboard in addition to its owner and any global sharing. All Users shares it with everyone.', 'syslog')],
'shared_groups' => ['friendly_name' => __('Shared With Groups', 'syslog'), 'method' => 'drop_multi', 'array' => $groups, 'value' => $shares['groups'], 'description' => __('Groups who can view this dashboard in addition to its owner and any global sharing. All Groups shares it with everyone.', 'syslog')],
'id' => ['method' => 'hidden', 'value' => (int) $row['id']],
'save_dashboard' => ['method' => 'hidden', 'value' => '1']
]]);
html_end_box();
if ($error !== '') {
print "<p class='ui-state-error ui-corner-all' role='alert'>" . html_escape($error) . '</p>';
}
print "<p class='textInfo'>" . __('Renaming applies to every viewer of this dashboard. Panels are managed by their owners from the Syslog Dashboard tab.', 'syslog') . '</p>';
form_save_button('syslog_dashboards.php', '', 'edit', false);
}