librenms-librenms/html/includes/forms/create-device-group.inc.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2015-04-03 18:22:29 +00:00
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
2015-07-13 20:10:26 +02:00
if (is_admin() === false) {
2015-04-03 18:22:29 +00:00
die('ERROR: You need to be admin');
}
require_once '../includes/device-groups.inc.php';
2015-07-13 20:10:26 +02:00
$pattern = $_POST['patterns'];
2015-04-03 18:22:29 +00:00
$group_id = $_POST['group_id'];
2015-07-13 20:10:26 +02:00
$name = mres($_POST['name']);
$desc = mres($_POST['desc']);
2015-04-03 18:22:29 +00:00
2015-07-13 20:10:26 +02:00
if (is_array($pattern)) {
$pattern = implode(' ', $pattern);
}
else if (!empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value'])) {
$pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' ';
if (is_numeric($_POST['value'])) {
$pattern .= $_POST['value'];
}
else {
$pattern .= '"'.$_POST['value'].'"';
}
2015-04-03 18:22:29 +00:00
}
2015-07-13 20:10:26 +02:00
if (empty($pattern)) {
$update_message = 'ERROR: No group was generated';
}
else if (is_numeric($group_id) && $group_id > 0) {
if (EditDeviceGroup($group_id, $name, $desc, $pattern)) {
2015-07-13 20:10:26 +02:00
$update_message = "Edited Group: <i>$name: $pattern</i>";
2015-04-03 18:22:29 +00:00
}
2015-07-13 20:10:26 +02:00
else {
$update_message = 'ERROR: Failed to edit Group: <i>'.$pattern.'</i>';
}
}
else {
if (AddDeviceGroup($name, $desc, $pattern)) {
2015-04-03 18:22:29 +00:00
$update_message = "Added Group: <i>$name: $pattern</i>";
2015-07-13 20:10:26 +02:00
}
else {
$update_message = 'ERROR: Failed to add Group: <i>'.$pattern.'</i>';
2015-04-03 18:22:29 +00:00
}
}
2015-07-13 20:10:26 +02:00
2015-04-03 18:22:29 +00:00
echo $update_message;