Files
librenms-librenms/html/pages/device/edit/device.inc.php

273 lines
11 KiB
PHP
Raw Normal View History

<?php
2015-07-13 20:10:26 +02:00
if ($_POST['editing']) {
if ($_SESSION['userlevel'] > "7") {
$updated = 0;
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
if (isset($_POST['parent_id'])) {
$parent_id = $_POST['parent_id'];
$res = dbDelete('device_relationships', '`child_device_id` = ?', array($device['device_id']));
if (!in_array('0', $pr)) {
foreach ($parent_id as $pr) {
dbInsert(array('parent_device_id' => $pr, 'child_device_id' => $device['device_id']), 'device_relationships');
}
}
}
2015-07-13 20:10:26 +02:00
$override_sysLocation_bool = mres($_POST['override_sysLocation']);
if (isset($_POST['sysLocation'])) {
$override_sysLocation_string = $_POST['sysLocation'];
2015-07-13 20:10:26 +02:00
}
if ($device['override_sysLocation'] != $override_sysLocation_bool || $device['location'] != $override_sysLocation_string) {
$updated = 1;
}
2015-07-13 20:10:26 +02:00
if ($override_sysLocation_bool) {
$override_sysLocation = 1;
} else {
$override_sysLocation = 0;
2015-07-13 20:10:26 +02:00
}
dbUpdate(array('override_sysLocation'=>$override_sysLocation), 'devices', '`device_id`=?', array($device['device_id']));
2015-07-13 20:10:26 +02:00
if (isset($override_sysLocation_string)) {
dbUpdate(array('location'=>$override_sysLocation_string), 'devices', '`device_id`=?', array($device['device_id']));
}
if ($device['type'] != $vars['type']) {
$param['type'] = $vars['type'];
$update_type = true;
}
2015-07-13 20:10:26 +02:00
#FIXME needs more sanity checking! and better feedback
$param['purpose'] = $vars['descr'];
$param['ignore'] = set_numeric($vars['ignore']);
$param['disabled'] = set_numeric($vars['disabled']);
2015-07-13 20:10:26 +02:00
$rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id']));
2015-07-13 20:10:26 +02:00
if ($rows_updated > 0 || $updated) {
if ($update_type === true) {
set_dev_attrib($device, 'override_device_type', true);
}
2015-07-13 20:10:26 +02:00
$update_message = "Device record updated.";
$updated = 1;
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
} elseif ($rows_updated == 0) {
2015-07-13 20:10:26 +02:00
$update_message = "Device record unchanged. No update necessary.";
$updated = -1;
} else {
2015-07-13 20:10:26 +02:00
$update_message = "Device record update error.";
}
if (isset($_POST['hostname']) && $_POST['hostname'] !== '' && $_POST['hostname'] !== $device['hostname']) {
if (is_admin()) {
$result = renamehost($device['device_id'], $_POST['hostname'], 'webui');
if ($result == "") {
print_message("Hostname updated from {$device['hostname']} to {$_POST['hostname']}");
echo '
<script>
var loc = window.location;
window.location.replace(loc.protocol + "//" + loc.host + loc.pathname + loc.search);
</script>
';
} else {
print_error($result . ". Does your web server have permission to modify the rrd files?");
}
} else {
print_error('Only administrative users may update the device hostname');
}
}
} else {
2015-07-13 20:10:26 +02:00
include 'includes/error-no-perm.inc.php';
}
}
$descr = $device['purpose'];
$override_sysLocation = $device['override_sysLocation'];
$override_sysLocation_string = $device['location'];
2015-07-13 20:10:26 +02:00
if ($updated && $update_message) {
print_message($update_message);
} elseif ($update_message) {
2015-07-13 20:10:26 +02:00
print_error($update_message);
}
?>
2016-01-10 19:01:59 +05:30
<h3> Device Settings </h3>
<div class="row">
<div class="col-md-1 col-md-offset-2">
<form id="delete_host" name="delete_host" method="post" action="delhost/" role="form">
<input type="hidden" name="id" value="<?php echo($device['device_id']); ?>">
2015-09-15 01:41:39 +05:30
<button type="submit" class="btn btn-danger" name="Submit"><i class="fa fa-trash"></i> Delete device</button>
</form>
</div>
<div class="col-md-1 col-md-offset-2">
2015-09-15 01:41:39 +05:30
<?php
if ($config['enable_clear_discovery'] == 1 && !$device['snmp_disable']) {
2015-09-15 01:41:39 +05:30
?>
<button type="submit" id="rediscover" data-device_id="<?php echo($device['device_id']); ?>" class="btn btn-primary" name="rediscover"><i class="fa fa-retweet"></i> Rediscover device</button>
<?php
}
?>
</div>
</div>
<br>
2014-06-16 23:06:04 +01:00
<form id="edit" name="edit" method="post" action="" role="form" class="form-horizontal">
<input type=hidden name="editing" value="yes">
<div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Change the hostname used for name resolution" >
<label for="edit-hostname-input" class="col-sm-2 control-label" >Hostname:</label>
<div class="col-sm-6">
<input type="text" id="edit-hostname-input" name="hostname" class="form-control" disabled value=<?php echo(display($device['hostname'])); ?> />
</div>
<div class="col-sm-2">
<button name="hostname-edit-button" id="hostname-edit-button" class="btn btn-danger"> <i class="fa fa-pencil"></i> </button>
</div>
</div>
<div class="form-group">
<label for="descr" class="col-sm-2 control-label">Description:</label>
<div class="col-sm-6">
<textarea id="descr" name="descr" class="form-control"><?php echo(display($device['purpose'])); ?></textarea>
</div>
2014-06-16 23:06:04 +01:00
</div>
<div class="form-group">
<label for="type" class="col-sm-2 control-label">Type:</label>
<div class="col-sm-6">
<select id="type" name="type" class="form-control">
<?php
$unknown = 1;
foreach ($config['device_types'] as $type) {
echo(' <option value="'.$type['type'].'"');
if ($device['type'] == $type['type']) {
echo(' selected="1"');
$unknown = 0;
}
echo(' >' . ucfirst($type['type']) . '</option>');
}
if ($unknown) {
echo(' <option value="other">Other</option>');
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="sysLocation" class="col-sm-2 control-label">Override sysLocation:</label>
<div class="col-sm-6">
<input onclick="edit.sysLocation.disabled=!edit.override_sysLocation.checked" type="checkbox" name="override_sysLocation"
<?php
if ($override_sysLocation) {
echo(' checked="1"');
}
?> />
</div>
2014-06-16 23:06:04 +01:00
</div>
<div class="form-group">
<div class="col-sm-2"></div>
<div class="col-sm-6">
<input id="sysLocation" name="sysLocation" class="form-control"
<?php
if (!$override_sysLocation) {
echo(' disabled="1"');
}
?> value="<?php echo($override_sysLocation_string); ?>" />
</div>
2014-06-16 23:06:04 +01:00
</div>
<div class="form-group">
<label for="parent_id" class="col-sm-2 control-label">This device depends on:</label>
<div class="col-sm-6">
<select multiple name="parent_id[]" id="parent_id" class="form-control">
<?php
$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 = ?)', array($device['device_id']));
if (!$dev_parents) {
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
$selected = 'selected="selected"';
} else {
$selected = '';
}
?>
<option value="0" <?=$selected?>>None</option>
<?php
$available_devs = dbFetchRows('SELECT `device_id`,`hostname`,`sysName` FROM `devices` WHERE `device_id` <> ? ORDER BY `hostname` ASC', array($device['device_id']));
foreach ($available_devs as $dev) {
if (in_array($dev['device_id'], $dev_parents)) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option value=". $dev['device_id']. " " . $selected . ">" . $dev['hostname'] . " (" . $dev['sysName'] .")</option>";
}
?>
</select>
</div>
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
</div>
<div class="form-group">
<label for="disabled" class="col-sm-2 control-label">Disable:</label>
<div class="col-sm-6">
<input name="disabled" type="checkbox" id="disabled" value="1"
<?php
if ($device["disabled"]) {
echo("checked=checked");
}
?> />
</div>
2014-06-16 23:06:04 +01:00
</div>
<div class="form-group">
<label for="ignore" class="col-sm-2 control-label">Ignore</label>
<div class="col-sm-6">
<input name="ignore" type="checkbox" id="ignore" value="1"
<?php
if ($device['ignore']) {
echo("checked=checked");
}
?> />
</div>
</div>
<div class="row">
<div class="col-md-1 col-md-offset-2">
<button type="submit" name="Submit" class="btn btn-default"><i class="fa fa-check"></i> Save</button>
</div>
2014-06-16 23:06:04 +01:00
</div>
</form>
<br />
<script>
$("#rediscover").click(function() {
var device_id = $(this).data("device_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "rediscover-device", device_id: device_id },
dataType: "json",
success: function(data){
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
},
error:function(){
toastr.error('An error occured setting this device to be rediscovered');
}
});
});
$('#hostname-edit-button').click(function(e) {
e.preventDefault();
disabled_state = document.getElementById('edit-hostname-input').disabled;
if (disabled_state == true) {
document.getElementById('edit-hostname-input').disabled = false;
} else {
document.getElementById('edit-hostname-input').disabled = true;
}
});
feature: Added support for Host dependencies (#7332) * First draft of the modals and the config interfaces * GUI part done * Backend code and db schema addition * Documentation added, fixed alerting bug * Fix typos * Do not try to push an older db_schame.yaml * Small db fix * More db fixes * Travis CI fixes * missed a line in the travis error * Fixed dependency clearing bug, Manage Host dependencies button now shows current selections * Removed unnecessary index * Correct faulty query * Fixed sql query as requested, and renamed sql file * Added requested changes * Removed debug code * Renamed sql file * More fixes as requested * Trying to fix db_schema.yaml * adding laf's diff * Corrected a small bug * Try to resolve scrutinizer issue * Main page bootgrid ajax modifications * Also corrected travis ci errors * Added select2 for pull downs, removed a redundant debug output. Changed parent_id to text * Add missing class in the device settings page * Fix bug where a link wasn't added after save * Better parent down detection * Add missing comma * Behold the multi-parent code * Added lookup table * Ready for testing * Trying to fix documentation conflicts * Fix copy paste errors, and possible sql injection * indentation problems * Modified db_schema.yaml as well * Typos, typos * This should correct alerts * Try to fix travis ci error * Fix the typo in index.php * Changed to Tony's query * function explanation text changed * Updated db_schema.yaml * Trying to make automated tests happy * Changes as requested * Added acknowledgment for select2 * Added laf's patch * dbBulkInsert when adding parents
2017-12-20 17:17:52 +03:00
$('#parent_id').select2({
width: 'resolve',
tags: true,
});
</script>
<?php
print_optionbar_start();
list($sizeondisk, $numrrds) = foldersize(get_rrd_dir($device['hostname']));
echo("Size on Disk: <b>" . formatStorage($sizeondisk) . "</b> in <b>" . $numrrds . " RRD files</b>.");
print_optionbar_end();
?>