librenms-librenms/html/includes/forms/save-host-dependency.inc.php

61 lines
2.4 KiB
PHP
Raw Normal View History

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
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Aldemir Akpinar <https://github.com/aldemira/>
*
* 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 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
use LibreNMS\Authentication\Auth;
if (!Auth::user()->hasGlobalAdmin()) {
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
$status = array('status' => 1, 'message' => 'You need to be admin');
} else {
foreach ($_POST['parent_ids'] as $parent) {
if (!is_numeric($parent)) {
$status = array('status' => 1, 'message' => 'Parent ID must be an integer!');
break;
}
}
if (count($_POST['parent_ids']) > 1 && in_array('0', $_POST['parent_ids'])) {
$status = array('status' => 1, 'message' => 'Multiple parents cannot contain None-Parent!');
}
// A bit of an effort to reuse this code with dependency editing and the dependency wizard (editing multiple hosts at the same time)
$device_arr = array();
foreach ($_POST['device_ids'] as $dev) {
if (!is_numeric($dev)) {
$status = array('status' => 1, 'message' => 'Device ID must be an integer!');
break;
} elseif (in_array($dev, $_POST['parent_ids'])) {
$status = array('status' => 1, 'message' => 'A device cannot depend itself');
break;
}
$insert = array();
foreach ($_POST['parent_ids'] as $parent) {
if (is_numeric($parent) && $parent != 0) {
$insert[] = array('parent_device_id' => $parent, 'child_device_id' => $dev);
} elseif ($parent == 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
// In case we receive a mixed array with $parent = 0 (which shouldn't happen)
// Empty the insert array so we remove any previous dependency so 'None' takes precedence
$insert = array();
break;
}
}
dbDelete('device_relationships', '`child_device_id` = ?', array($dev));
if (!empty($insert)) {
dbBulkInsert($insert, 'device_relationships');
}
$status = array('status' => 0, 'message' => 'Device dependencies have been saved');
}
}
header('Content-Type: application/json');
echo _json_encode($status);