1 | <?php |
||||
2 | |||||
3 | $no_refresh = true; |
||||
4 | |||||
5 | ?> |
||||
6 | <div class="row"> |
||||
7 | <div class="col-sm-12"> |
||||
8 | <span id="message"></span> |
||||
9 | </div> |
||||
10 | </div> |
||||
11 | <?php |
||||
12 | |||||
13 | require_once 'includes/html/modal/edit_alert_transport.inc.php'; |
||||
14 | require_once 'includes/html/modal/edit_transport_group.inc.php'; |
||||
15 | |||||
16 | if (Auth::user()->hasGlobalAdmin()) { |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
17 | echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-alert-transport'>Create alert transport</button>"; |
||||
18 | } |
||||
19 | ?> |
||||
20 | <br> |
||||
21 | <br> |
||||
22 | <div class="table-responsive"> |
||||
23 | <table class="table table-hover table-condensed"> |
||||
24 | <tr> |
||||
25 | <th>Transport Name</th> |
||||
26 | <th>Transport Type</th> |
||||
27 | <th>Default</th> |
||||
28 | <th>Details</th> |
||||
29 | <th style="width:136px;">Action</th> |
||||
30 | </tr> |
||||
31 | <?php |
||||
32 | |||||
33 | // Iterate through each alert transport |
||||
34 | $query = 'SELECT `transport_id` AS `id`, `transport_name` AS `name`, `transport_type` AS `type`, `is_default`, `transport_config` AS `config` FROM `alert_transports` order by `name`'; |
||||
35 | foreach (dbFetchRows($query) as $transport) { |
||||
36 | echo "<tr id=\"alert-transport-{$transport['id']}\">"; |
||||
37 | echo '<td>' . $transport['name'] . '</td>'; |
||||
38 | echo '<td>' . $transport['type'] . '</td>'; |
||||
39 | if ($transport['is_default'] == true) { |
||||
40 | echo '<td>Yes</td>'; |
||||
41 | } else { |
||||
42 | echo '<td>No</td>'; |
||||
43 | } |
||||
44 | |||||
45 | echo "<td class='col-sm-4'>"; |
||||
46 | |||||
47 | // Iterate through transport config template to display config details |
||||
48 | $class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport['type']); |
||||
49 | if (! method_exists($class, 'configTemplate')) { |
||||
50 | //skip |
||||
51 | continue; |
||||
52 | } |
||||
53 | $tmp = call_user_func($class . '::configTemplate'); |
||||
0 ignored issues
–
show
Are you sure
$class of type object can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
54 | $transport_config = json_decode($transport['config'], true); |
||||
55 | |||||
56 | foreach ($tmp['config'] as $item) { |
||||
57 | if ($item['type'] == 'oauth') { |
||||
58 | continue; |
||||
59 | } |
||||
60 | |||||
61 | $val = $transport_config[$item['name']]; |
||||
62 | if ($item['type'] == 'password') { |
||||
63 | $val = '<b>••••••••</b>'; |
||||
64 | } |
||||
65 | // Match value to key name for select inputs |
||||
66 | if ($item['type'] == 'select') { |
||||
67 | $val = array_search($val, $item['options']); |
||||
68 | } |
||||
69 | |||||
70 | echo '<i>' . $item['title'] . ': ' . $val . '<br/></i>'; |
||||
71 | } |
||||
72 | |||||
73 | echo '</td>'; |
||||
74 | echo '<td>'; |
||||
75 | |||||
76 | // Add action buttons for admin users only |
||||
77 | if (Auth::user()->hasGlobalAdmin()) { |
||||
78 | echo "<div class='btn-group btn-group-sm' role='group'>"; |
||||
79 | echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='" . $transport['id'] . "' name='edit-alert-rule' data-container='body' data-toggle='popover' data-content='Edit transport'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> "; |
||||
80 | echo "<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#delete-alert-transport' data-transport_id='" . $transport['id'] . "' name='delete-alert-transport' data-container='body' data-toggle='popover' data-content='Delete transport'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>"; |
||||
81 | echo "<button type='button' class='btn btn-warning btn-sm' data-transport_id='" . $transport['id'] . "' data-transport='{$transport['type']}' name='test-transport' id='test-transport' data-toggle='popover' data-content='Test transport'><i class='fa fa-lg fa-check' aria-hidden='true'></i></button> "; |
||||
82 | echo '</div>'; |
||||
83 | } |
||||
84 | echo '</td>'; |
||||
85 | echo "</tr>\r\n"; |
||||
86 | } |
||||
87 | ?> |
||||
88 | </table> |
||||
89 | </div> |
||||
90 | <br> |
||||
91 | <?php |
||||
92 | if (Auth::user()->hasGlobalAdmin()) { |
||||
93 | echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-transport-group'>Create transport group</button>"; |
||||
94 | } |
||||
95 | ?> |
||||
96 | |||||
97 | <br> |
||||
98 | <br> |
||||
99 | <div class="table-responsive"> |
||||
100 | <table class="table table-hover table-condensed"> |
||||
101 | <tr> |
||||
102 | <th>Transport Group</th> |
||||
103 | <th>Members</th> |
||||
104 | <th style="width:136px;">Action</th> |
||||
105 | </tr> |
||||
106 | <?php |
||||
107 | |||||
108 | //Iterate through alert groups |
||||
109 | $query = 'SELECT `transport_group_id` AS `id`, `transport_group_name` AS `name` FROM `alert_transport_groups` order by `name`'; |
||||
110 | foreach (dbFetchRows($query) as $group) { |
||||
111 | echo "<tr id=\"alert-transport-group-{$group['id']}\">"; |
||||
112 | echo '<td>' . $group['name'] . '</td>'; |
||||
113 | |||||
114 | //List out the members of each group |
||||
115 | $query = 'SELECT `transport_type`, `transport_name` FROM `transport_group_transport` AS `a` LEFT JOIN `alert_transports` AS `b` ON `a`.`transport_id`=`b`.`transport_id` WHERE `transport_group_id`=? order by `transport_name`'; |
||||
116 | $members = dbFetchRows($query, [$group['id']]); |
||||
117 | echo '<td>'; |
||||
118 | foreach ($members as $member) { |
||||
119 | echo '<i>' . ucfirst($member['transport_type']) . ': ' . $member['transport_name'] . '<br /></i>'; |
||||
120 | } |
||||
121 | echo '</td>'; |
||||
122 | echo '<td>'; |
||||
123 | if (Auth::user()->hasGlobalAdmin()) { |
||||
124 | echo "<div class='btn-group btn-group-sm' role='group'>"; |
||||
125 | echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#edit-transport-group' data-group_id='" . $group['id'] . "' data-container='body' data-toggle='popover' data-content='Edit transport group'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> "; |
||||
126 | echo "<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#delete-transport-group' data-group_id='" . $group['id'] . "' data-container='body' data-toggle='popover' data-content='Delete transport group'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>"; |
||||
127 | echo '</div>'; |
||||
128 | } |
||||
129 | echo '</td>'; |
||||
130 | echo '</tr>'; |
||||
131 | } |
||||
132 | ?> |
||||
133 | </table> |
||||
134 | </div> |
||||
135 | |||||
136 | <script> |
||||
137 | $("button#test-transport").on("click", function() { |
||||
138 | var $this = $(this); |
||||
139 | var transport_id = $this.data("transport_id"); |
||||
140 | var transport = $this.data("transport"); |
||||
141 | $.ajax({ |
||||
142 | type: 'POST', |
||||
143 | url: 'ajax_form.php', |
||||
144 | data: { type: "test-transport", transport_id: transport_id }, |
||||
145 | dataType: "json", |
||||
146 | success: function(data){ |
||||
147 | if (data.status === 'ok') { |
||||
148 | toastr.success('Test to ' + transport + ' ok'); |
||||
149 | } else { |
||||
150 | toastr.error('Test to ' + transport + ' failed<br />' + data.message); |
||||
151 | } |
||||
152 | }, |
||||
153 | error: function(){ |
||||
154 | toastr.error('Test to ' + transport + ' failed - general error'); |
||||
155 | } |
||||
156 | }); |
||||
157 | }); |
||||
158 | |||||
159 | $("[data-toggle='popover']").popover({ |
||||
160 | trigger: 'hover', |
||||
161 | placement: 'top' |
||||
162 | }); |
||||
163 | </script> |
||||
164 |