1 | <?php |
||
2 | |||
3 | use App\Models\Device; |
||
4 | |||
5 | require_once 'includes/html/modal/device_maintenance.inc.php'; |
||
6 | |||
7 | $device_model = Device::find($device['device_id']); |
||
8 | |||
9 | if ($_POST['editing']) { |
||
10 | if (Auth::user()->hasGlobalAdmin()) { |
||
11 | if (isset($_POST['parent_id'])) { |
||
12 | $parents = array_diff((array) $_POST['parent_id'], ['0']); |
||
13 | // TODO avoid loops! |
||
14 | $device_model->parents()->sync($parents); |
||
15 | } |
||
16 | |||
17 | $override_sysLocation = (int) isset($_POST['override_sysLocation']); |
||
18 | $override_sysLocation_string = $_POST['sysLocation'] ?? null; |
||
19 | |||
20 | if ($override_sysLocation) { |
||
21 | $device_model->override_sysLocation = false; // allow override (will be set to actual value later) |
||
22 | $device_model->setLocation($override_sysLocation_string, true); |
||
23 | optional($device_model->location)->save(); |
||
24 | } elseif ($device_model->override_sysLocation) { |
||
25 | // no longer overridden, clear location |
||
26 | $device_model->location()->dissociate(); |
||
27 | } |
||
28 | |||
29 | $device_model->override_sysLocation = $override_sysLocation; |
||
30 | $device_model->purpose = $_POST['descr']; |
||
31 | $device_model->poller_group = $_POST['poller_group']; |
||
32 | $device_model->ignore = (int) isset($_POST['ignore']); |
||
33 | $device_model->disabled = (int) isset($_POST['disabled']); |
||
34 | $device_model->disable_notify = (int) isset($_POST['disable_notify']); |
||
35 | $device_model->type = $_POST['type']; |
||
36 | $device_model->overwrite_ip = $_POST['overwrite_ip']; |
||
37 | |||
38 | if ($device_model->isDirty('type')) { |
||
39 | set_dev_attrib($device, 'override_device_type', true); |
||
40 | } |
||
41 | |||
42 | if ($device_model->isDirty()) { |
||
43 | if ($device_model->save()) { |
||
44 | Toastr::success(__('Device record updated')); |
||
45 | } else { |
||
46 | Toastr::error(__('Device record update error')); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if (isset($_POST['hostname']) && $_POST['hostname'] !== '' && $_POST['hostname'] !== $device['hostname']) { |
||
51 | if (Auth::user()->hasGlobalAdmin()) { |
||
52 | $result = renamehost($device['device_id'], $_POST['hostname'], 'webui'); |
||
53 | if ($result == '') { |
||
54 | Toastr::success("Hostname updated from {$device['hostname']} to {$_POST['hostname']}"); |
||
55 | echo ' |
||
56 | <script> |
||
57 | var loc = window.location; |
||
58 | window.location.replace(loc.protocol + "//" + loc.host + loc.pathname + loc.search); |
||
59 | </script> |
||
60 | '; |
||
61 | } else { |
||
62 | Toastr::error($result . '. Does your web server have permission to modify the rrd files?'); |
||
63 | } |
||
64 | } else { |
||
65 | Toastr::error('Only administrative users may update the device hostname'); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | $override_sysContact_bool = $_POST['override_sysContact']; |
||
70 | if (isset($_POST['sysContact'])) { |
||
71 | $override_sysContact_string = $_POST['sysContact']; |
||
72 | } |
||
73 | |||
74 | if ($override_sysContact_bool) { |
||
75 | set_dev_attrib($device, 'override_sysContact_bool', '1'); |
||
76 | } else { |
||
77 | set_dev_attrib($device, 'override_sysContact_bool', '0'); |
||
78 | } |
||
79 | |||
80 | if (isset($override_sysContact_string)) { |
||
81 | set_dev_attrib($device, 'override_sysContact_string', $override_sysContact_string); |
||
82 | } |
||
83 | } else { |
||
84 | include 'includes/html/error-no-perm.inc.php'; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $override_sysContact_bool = get_dev_attrib($device, 'override_sysContact_bool'); |
||
89 | $override_sysContact_string = get_dev_attrib($device, 'override_sysContact_string'); |
||
90 | $disable_notify = get_dev_attrib($device, 'disable_notify'); |
||
91 | |||
92 | ?> |
||
93 | |||
94 | <h3> Device Settings </h3> |
||
95 | <div class="row"> |
||
96 | <!-- Bootstrap 3 doesn't support mediaqueries for text aligns (e.g. text-md-left), which makes these buttons stagger on sm or xs screens --> |
||
97 | <div class="col-md-2 col-md-offset-2"> |
||
98 | <form id="delete_host" name="delete_host" method="post" action="delhost/" role="form"> |
||
99 | <?php echo csrf_field() ?> |
||
100 | <input type="hidden" name="id" value="<?php echo $device['device_id']; ?>"> |
||
101 | <button type="submit" class="btn btn-danger" name="Submit"><i class="fa fa-trash"></i> Delete device</button> |
||
102 | </form> |
||
103 | </div> |
||
104 | <div class="col-md-2 text-center"> |
||
105 | <?php |
||
106 | if (\LibreNMS\Config::get('enable_clear_discovery') == 1 && ! $device['snmp_disable']) { |
||
107 | ?> |
||
108 | <button type="submit" id="rediscover" data-device_id="<?php echo $device['device_id']; ?>" class="btn btn-primary" name="rediscover" title="Schedule the device for immediate rediscovery by the poller"><i class="fa fa-retweet"></i> Rediscover device</button> |
||
109 | <?php |
||
110 | } |
||
111 | ?> |
||
112 | </div> |
||
113 | <div class="col-md-2 text-right"> |
||
114 | <button type="submit" id="reset_port_state" data-device_id="<?php echo $device['device_id']; ?>" class="btn btn-info" name="reset_ports" <button type="submit" id="reset_port_state" data-device_id="<?php echo $device['device_id']; ?>" class="btn btn-info" name="reset_ports" title="Reset interface speed, admin up/down, and link up/down history, clearing associated alarms"><i class="fa fa-recycle"></i> Reset Port State</button> |
||
115 | </div> |
||
116 | </div> |
||
117 | <br> |
||
118 | <form id="edit" name="edit" method="post" action="" role="form" class="form-horizontal"> |
||
119 | <?php echo csrf_field() ?> |
||
120 | <input type=hidden name="editing" value="yes"> |
||
121 | <div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Change the hostname used for name resolution" > |
||
122 | <label for="edit-hostname-input" class="col-sm-2 control-label" >Hostname:</label> |
||
123 | <div class="col-sm-6"> |
||
124 | <input type="text" id="edit-hostname-input" name="hostname" class="form-control" disabled value=<?php echo \LibreNMS\Util\Clean::html($device['hostname'], []); ?> /> |
||
125 | </div> |
||
126 | <div class="col-sm-2"> |
||
127 | <button name="hostname-edit-button" id="hostname-edit-button" class="btn btn-danger"> <i class="fa fa-pencil"></i> </button> |
||
128 | </div> |
||
129 | </div> |
||
130 | <div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Use this IP instead of resolved one for polling" > |
||
131 | <label for="edit-overwrite_ip-input" class="col-sm-2 control-label" >Overwrite IP:</label> |
||
132 | <div class="col-sm-6"> |
||
133 | <input type="text" id="edit-overwrite_up-input" name="overwrite_ip" class="form-control" value=<?php echo $device_model->overwrite_ip; ?>> |
||
134 | </div> |
||
135 | </div> |
||
136 | <div class="form-group"> |
||
137 | <label for="descr" class="col-sm-2 control-label">Description:</label> |
||
138 | <div class="col-sm-6"> |
||
139 | <textarea id="descr" name="descr" class="form-control"><?php echo \LibreNMS\Util\Clean::html($device_model->purpose, []); ?></textarea> |
||
140 | </div> |
||
141 | </div> |
||
142 | <div class="form-group"> |
||
143 | <label for="type" class="col-sm-2 control-label">Type:</label> |
||
144 | <div class="col-sm-6"> |
||
145 | <select id="type" name="type" class="form-control"> |
||
146 | <?php |
||
147 | $unknown = 1; |
||
148 | |||
149 | foreach (\LibreNMS\Config::get('device_types') as $type) { |
||
150 | echo ' <option value="' . $type['type'] . '"'; |
||
151 | if ($device_model->type == $type['type']) { |
||
152 | echo ' selected="1"'; |
||
153 | $unknown = 0; |
||
154 | } |
||
155 | echo ' >' . ucfirst($type['type']) . '</option>'; |
||
156 | } |
||
157 | if ($unknown) { |
||
158 | if (! is_null($device_model->type)) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
159 | $device_type = htmlspecialchars($device_model->type); |
||
160 | echo ' <option value="' . $device_type . '" selected="1" >' . ucfirst($device_type) . '</option>'; |
||
161 | } else { |
||
162 | echo ' <option value="other">Other</option>'; |
||
163 | } |
||
164 | } |
||
165 | ?> |
||
166 | </select> |
||
167 | </div> |
||
168 | </div> |
||
169 | <div class="form-group"> |
||
170 | <label for="sysLocation" class="col-sm-2 control-label">Override sysLocation:</label> |
||
171 | <div class="col-sm-6"> |
||
172 | <input onChange="edit.sysLocation.disabled=!edit.override_sysLocation.checked; edit.sysLocation.select()" type="checkbox" name="override_sysLocation" data-size="small" |
||
173 | <?php |
||
174 | if ($device_model->override_sysLocation) { |
||
175 | echo ' checked="1"'; |
||
176 | } |
||
177 | ?> /> |
||
178 | </div> |
||
179 | </div> |
||
180 | <div class="form-group" title="To set coordinates, include [latitude,longitude]"> |
||
181 | <div class="col-sm-2"></div> |
||
182 | <div class="col-sm-6"> |
||
183 | <input id="sysLocation" name="sysLocation" class="form-control" |
||
184 | <?php |
||
185 | if (! $device_model->override_sysLocation) { |
||
186 | echo ' disabled="1"'; |
||
187 | } |
||
188 | ?> value="<?php echo \LibreNMS\Util\Clean::html($device_model->location, []); ?>" /> |
||
189 | </div> |
||
190 | </div> |
||
191 | <div class="form-group"> |
||
192 | <label for="override_sysContact" class="col-sm-2 control-label">Override sysContact</label> |
||
193 | <div class="col-sm-6"> |
||
194 | <input onChange="edit.sysContact.disabled=!edit.override_sysContact.checked" type="checkbox" id="override_sysContact" name="override_sysContact" data-size="small" |
||
195 | <?php |
||
196 | if ($override_sysContact_bool) { |
||
197 | echo ' checked="1"'; |
||
198 | } |
||
199 | ?> |
||
200 | /> |
||
201 | </div> |
||
202 | </div> |
||
203 | <div class="form-group"> |
||
204 | <div class="col-sm-2"> |
||
205 | </div> |
||
206 | <div class="col-sm-6"> |
||
207 | <input id="sysContact" class="form-control" name="sysContact" size="32" |
||
208 | <?php |
||
209 | if (! $override_sysContact_bool) { |
||
210 | echo ' disabled="1"'; |
||
211 | } |
||
212 | ?> |
||
213 | value="<?php echo $override_sysContact_string; ?>" /> |
||
214 | </div> |
||
215 | </div> |
||
216 | <div class="form-group"> |
||
217 | <label for="parent_id" class="col-sm-2 control-label">This device depends on:</label> |
||
218 | <div class="col-sm-6"> |
||
219 | <select multiple name="parent_id[]" id="parent_id" class="form-control" style="width: 100%"> |
||
220 | <?php |
||
221 | $dev_parents = dbFetchColumn('SELECT device_id from devices WHERE device_id IN (SELECT dr.parent_device_id from devices as d, device_relationships as dr WHERE d.device_id = dr.child_device_id AND d.device_id = ?)', [$device['device_id']]); |
||
222 | if (! $dev_parents) { |
||
223 | $selected = 'selected="selected"'; |
||
224 | } else { |
||
225 | $selected = ''; |
||
226 | } |
||
227 | ?> |
||
228 | <option value="0" <?=$selected?>>None</option> |
||
229 | <?php |
||
230 | $available_devs = dbFetchRows('SELECT `device_id`,`hostname`,`sysName` FROM `devices` WHERE `device_id` <> ? ORDER BY `hostname` ASC', [$device['device_id']]); |
||
231 | foreach ($available_devs as $dev) { |
||
232 | if (in_array($dev['device_id'], $dev_parents)) { |
||
233 | $selected = 'selected="selected"'; |
||
234 | } else { |
||
235 | $selected = ''; |
||
236 | } |
||
237 | echo '<option value=' . $dev['device_id'] . ' ' . $selected . '>' . $dev['hostname'] . ' (' . $dev['sysName'] . ')</option>'; |
||
238 | } |
||
239 | ?> |
||
240 | </select> |
||
241 | </div> |
||
242 | </div> |
||
243 | <?php |
||
244 | if (\LibreNMS\Config::get('distributed_poller') === true) { |
||
245 | ?> |
||
246 | <div class="form-group"> |
||
247 | <label for="poller_group" class="col-sm-2 control-label">Poller Group</label> |
||
248 | <div class="col-sm-6"> |
||
249 | <select name="poller_group" id="poller_group" class="form-control input-sm"> |
||
250 | <option value="0">General<?=\LibreNMS\Config::get('distributed_poller_group') == 0 ? ' (default Poller)' : ''?></option> |
||
251 | <?php |
||
252 | foreach (dbFetchRows('SELECT `id`,`group_name` FROM `poller_groups` ORDER BY `group_name`') as $group) { |
||
253 | echo '<option value="' . $group['id'] . '"' . |
||
254 | ($device_model->poller_group == $group['id'] ? ' selected' : '') . '>' . $group['group_name']; |
||
255 | echo \LibreNMS\Config::get('distributed_poller_group') == $group['id'] ? ' (default Poller)' : ''; |
||
256 | echo '</option>'; |
||
257 | } ?> |
||
258 | </select> |
||
259 | </div> |
||
260 | </div> |
||
261 | <?php |
||
262 | }//endif |
||
263 | ?> |
||
264 | <div class="form-group"> |
||
265 | <label for="disabled" class="col-sm-2 control-label">Disable polling and alerting:</label> |
||
266 | <div class="col-sm-6"> |
||
267 | <input name="disabled" type="checkbox" id="disabled" value="1" data-size="small" |
||
268 | <?php |
||
269 | if ($device_model->disabled) { |
||
270 | echo 'checked=checked'; |
||
271 | } |
||
272 | ?> /> |
||
273 | </div> |
||
274 | </div> |
||
275 | <div class="form-group"> |
||
276 | <label for="maintenance" class="col-sm-2 control-label"></label> |
||
277 | <div class="col-sm-6"> |
||
278 | <button type="button" id="maintenance" data-device_id="<?php echo $device['device_id']; ?>" <?php echo \LibreNMS\Alert\AlertUtil::isMaintenance($device['device_id']) ? 'disabled class="btn btn-warning"' : 'class="btn btn-success"'?> name="maintenance"><i class="fa fa-wrench"></i> Maintenance Mode</button> |
||
279 | </div> |
||
280 | </div> |
||
281 | |||
282 | <div class="form-group"> |
||
283 | <label for="disable_notify" class="col-sm-2 control-label">Disable alerting:</label> |
||
284 | <div class="col-sm-6"> |
||
285 | <input id="disable_notify" type="checkbox" name="disable_notify" data-size="small" |
||
286 | <?php |
||
287 | if ($device_model->disable_notify) { |
||
288 | echo 'checked=checked'; |
||
289 | } |
||
290 | ?> /> |
||
291 | </div> |
||
292 | </div> |
||
293 | <div class="form-group"> |
||
294 | <label for="ignore" class="col-sm-2 control-label" title="Tag device to ignore alerts. Alert checks will still run. |
||
295 | However, ignore tag can be read in alert rules. |
||
296 | If `devices.ignore = 0` or `macros.device = 1` condition is is set and ignore alert tag is on, the alert rule won't match.">Ignore alert tag:</label> |
||
297 | <div class="col-sm-6"> |
||
298 | <input name="ignore" type="checkbox" id="ignore" value="1" data-size="small" |
||
299 | <?php |
||
300 | if ($device_model->ignore) { |
||
301 | echo 'checked=checked'; |
||
302 | } |
||
303 | ?> /> |
||
304 | </div> |
||
305 | </div> |
||
306 | <div class="row"> |
||
307 | <div class="col-md-1 col-md-offset-2"> |
||
308 | <button type="submit" name="Submit" class="btn btn-default"><i class="fa fa-check"></i> Save</button> |
||
309 | </div> |
||
310 | </div> |
||
311 | </form> |
||
312 | <br /> |
||
313 | <script> |
||
314 | $('[type="checkbox"]').bootstrapSwitch('offColor', 'danger'); |
||
315 | |||
316 | $("#maintenance").on("click", function() { |
||
317 | $("#device_maintenance_modal").modal('show'); |
||
318 | }); |
||
319 | $("#rediscover").on("click", function() { |
||
320 | var device_id = $(this).data("device_id"); |
||
321 | $.ajax({ |
||
322 | type: 'POST', |
||
323 | url: 'ajax_form.php', |
||
324 | data: { type: "rediscover-device", device_id: device_id }, |
||
325 | dataType: "json", |
||
326 | success: function(data){ |
||
327 | if(data['status'] == 'ok') { |
||
328 | toastr.success(data['message']); |
||
329 | } else { |
||
330 | toastr.error(data['message']); |
||
331 | } |
||
332 | }, |
||
333 | error:function(){ |
||
334 | toastr.error('An error occured setting this device to be rediscovered'); |
||
335 | } |
||
336 | }); |
||
337 | }); |
||
338 | $("#reset_port_state").on("click", function() { |
||
339 | var device_id = $(this).data("device_id"); |
||
340 | $.ajax({ |
||
341 | type: 'POST', |
||
342 | url: 'ajax_form.php', |
||
343 | data: { type: "reset-port-state", device_id: device_id }, |
||
344 | dataType: "json", |
||
345 | success: function(data){ |
||
346 | if(data['status'] == 'ok') { |
||
347 | toastr.success(data['message']); |
||
348 | } else { |
||
349 | toastr.error(data['message']); |
||
350 | } |
||
351 | }, |
||
352 | error:function(){ |
||
353 | toastr.error('An error occured while attempting to reset port state alarms'); |
||
354 | } |
||
355 | }); |
||
356 | }); |
||
357 | $('#hostname-edit-button').on("click", function(e) { |
||
358 | e.preventDefault(); |
||
359 | disabled_state = document.getElementById('edit-hostname-input').disabled; |
||
360 | if (disabled_state == true) { |
||
361 | document.getElementById('edit-hostname-input').disabled = false; |
||
362 | } else { |
||
363 | document.getElementById('edit-hostname-input').disabled = true; |
||
364 | } |
||
365 | }); |
||
366 | $('#sysLocation').on('keypress', function (e) { |
||
367 | if(e.keyCode === 13) { |
||
368 | e.preventDefault(); |
||
369 | $('#edit').trigger( "submit" ); |
||
370 | } |
||
371 | }); |
||
372 | $('#parent_id').select2({ |
||
373 | width: 'resolve' |
||
374 | }); |
||
375 | </script> |
||
376 | <?php |
||
377 | print_optionbar_start(); |
||
378 | [$sizeondisk, $numrrds] = foldersize(Rrd::dirFromHost($device['hostname'])); |
||
379 | echo 'Size on Disk: <b>' . \LibreNMS\Util\Number::formatBi($sizeondisk, 2, 3) . '</b> in <b>' . $numrrds . ' RRD files</b>.'; |
||
380 | echo ' | Last polled: <b>' . $device['last_polled'] . '</b>'; |
||
381 | if ($device['last_discovered']) { |
||
382 | echo ' | Last discovered: <b>' . $device['last_discovered'] . '</b>'; |
||
383 | } |
||
384 | print_optionbar_end(); |
||
385 | ?> |
||
386 |