diff --git a/html/ajax_search.php b/html/ajax_search.php
index d9d3925507..d6aa5fe2c6 100755
--- a/html/ajax_search.php
+++ b/html/ajax_search.php
@@ -29,7 +29,22 @@ if (isset($_REQUEST['search']))
{
$found = 0;
- if($_REQUEST['type'] == 'device') {
+ if( $_REQUEST['type'] == 'group' ) {
+ include_once('../includes/device-groups.inc.php');
+ foreach( dbFetchRows("SELECT name FROM device_groups WHERE name LIKE '%".$search."%'") as $group ) {
+ if( $_REQUEST['map'] ) {
+ $results[] = array('name'=>'g:'.$group['name']);
+ } else {
+ $results[] = array('name'=>$group['name']);
+ }
+ }
+ die(json_encode($results));
+ } elseif( $_REQUEST['type'] == 'alert-rules' ) {
+ foreach( dbFetchRows("SELECT name FROM alert_rules WHERE name LIKE '%".$search."%'") as $rules ) {
+ $results[] = array('name'=>$rules['name']);
+ }
+ die(json_encode($results));
+ } elseif($_REQUEST['type'] == 'device') {
// Device search
$results = dbFetchRows("SELECT * FROM `devices` WHERE `hostname` LIKE '%" . $search . "%' OR `location` LIKE '%" . $search . "%' ORDER BY hostname LIMIT 8");
diff --git a/html/forms/create-alert-item.inc.php b/html/forms/create-alert-item.inc.php
index 9efdef119d..7940fc4c28 100644
--- a/html/forms/create-alert-item.inc.php
+++ b/html/forms/create-alert-item.inc.php
@@ -55,6 +55,15 @@ if(empty($rule)) {
} else {
if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name),'alert_rules') ) {
$update_message = "Added Rule: $name: $rule";
+ if( is_array($_POST['maps']) ) {
+ foreach( $_POST['maps'] as $target ) {
+ $_POST['rule'] = $name;
+ $_POST['target'] = $target;
+ $_POST['map_id'] = '';
+ include('forms/create-map-item.inc.php');
+ unset($ret,$target,$raw,$rule,$msg,$map_id);
+ }
+ }
} else {
$update_message = "ERROR: Failed to add Rule: ".$rule."";
}
diff --git a/html/forms/create-device-group.inc.php b/html/forms/create-device-group.inc.php
new file mode 100644
index 0000000000..94c410c9e9
--- /dev/null
+++ b/html/forms/create-device-group.inc.php
@@ -0,0 +1,52 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+$pattern = $_POST['patterns'];
+$group_id = $_POST['group_id'];
+$name = mres($_POST['name']);
+$desc = mres($_POST['desc']);
+
+if( is_array($pattern) ) {
+ $pattern = implode(" ", $pattern);
+ $pattern = rtrim($pattern,'&&');
+ $pattern = rtrim($pattern,'||');
+} elseif( !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'].'"';
+ }
+}
+
+if(empty($pattern)) {
+ $update_message = "ERROR: No group was generated";
+} elseif(is_numeric($group_id) && $group_id > 0) {
+ if(dbUpdate(array('pattern' => $pattern,'name'=>$name,'desc'=>$desc), 'device_groups', 'id=?',array($group_id)) >= 0) {
+ $update_message = "Edited Group: $name: $pattern";
+ } else {
+ $update_message = "ERROR: Failed to edit Group: ".$pattern."";
+ }
+} else {
+ if( dbInsert(array('pattern'=>$pattern,'name'=>$name,'desc'=>$desc),'device_groups') ) {
+ $update_message = "Added Group: $name: $pattern";
+ } else {
+ $update_message = "ERROR: Failed to add Group: ".$pattern."";
+ }
+}
+echo $update_message;
diff --git a/html/forms/create-map-item.inc.php b/html/forms/create-map-item.inc.php
new file mode 100644
index 0000000000..d05f0f0dd7
--- /dev/null
+++ b/html/forms/create-map-item.inc.php
@@ -0,0 +1,59 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+$rule = mres($_POST['rule']);
+$target = mres($_POST['target']);
+$map_id = mres($_POST['map_id']);
+$ret = array();
+
+if( empty($rule) || empty($target) ) {
+ $ret[] = "ERROR: No map was generated";
+} else {
+ $raw = $rule;
+ $rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?',array($rule));
+ if( !is_numeric($target) && $target[0] != "g" ) {
+ array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
+ } else {
+ $raw = $target;
+ if( $target[0].$target[1] == "g:" ) {
+ $target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?',array(substr($target,2)));
+ } else {
+ $target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target));
+ }
+ if( !is_numeric($target) && $target[0] != "g" ) {
+ array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
+ } else {
+ if(is_numeric($map_id) && $map_id > 0) {
+ if(dbUpdate(array('rule' => $rule,'target'=>$target), 'alert_map', 'id=?',array($map_id)) >= 0) {
+ $ret[] = "Edited Map: ".$map_id.": ".$rule." = ".$target."";
+ } else {
+ array_unshift($ret,"ERROR: Failed to edit Map: ".$map_id.": ".$rule." = ".$target."");
+ }
+ } else {
+ if( dbInsert(array('rule'=>$rule,'target'=>$target),'alert_map') ) {
+ $ret[] = "Added Map: ".$rule." = ".$target."";
+ } else {
+ array_unshift($ret,"ERROR: Failed to add Map: ".$rule." = ".$target."");
+ }
+ }
+ }
+ }
+}
+foreach( $ret as $msg ) {
+ echo $msg." ";
+}
diff --git a/html/forms/delete-alert-map.inc.php b/html/forms/delete-alert-map.inc.php
new file mode 100644
index 0000000000..4136fe983b
--- /dev/null
+++ b/html/forms/delete-alert-map.inc.php
@@ -0,0 +1,31 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+if(!is_numeric($_POST['map_id'])) {
+ echo('ERROR: No map selected');
+ exit;
+} else {
+ if(dbDelete('alert_map', "`id` = ?", array($_POST['map_id']))) {
+ echo('Map has been deleted.');
+ exit;
+ } else {
+ echo('ERROR: Map has not been deleted.');
+ exit;
+ }
+}
+
diff --git a/html/forms/delete-device-group.inc.php b/html/forms/delete-device-group.inc.php
new file mode 100644
index 0000000000..a81f10d2f6
--- /dev/null
+++ b/html/forms/delete-device-group.inc.php
@@ -0,0 +1,31 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+if(!is_numeric($_POST['group_id'])) {
+ echo('ERROR: No group selected');
+ exit;
+} else {
+ if(dbDelete('device_groups', "`id` = ?", array($_POST['group_id']))) {
+ echo('group has been deleted.');
+ exit;
+ } else {
+ echo('ERROR: group has not been deleted.');
+ exit;
+ }
+}
+
diff --git a/html/forms/parse-alert-map.inc.php b/html/forms/parse-alert-map.inc.php
new file mode 100644
index 0000000000..393b1dc68b
--- /dev/null
+++ b/html/forms/parse-alert-map.inc.php
@@ -0,0 +1,30 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+$map_id = $_POST['map_id'];
+
+if(is_numeric($map_id) && $map_id > 0) {
+ $map = dbFetchRow("SELECT alert_rules.name,alert_map.target FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id && alert_map.id = ?",array($map_id));
+ if( $map['target'][0] == "g" ) {
+ $map['target'] = 'g:'.dbFetchCell("SELECT name FROM device_groups WHERE id = ?",array(substr($map['target'],1)));
+ } else {
+ $map['target'] = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?",array($map['target']));
+ }
+ $output = array('rule'=>$map['name'],'target'=>$map['target']);
+ echo _json_encode($output);
+}
diff --git a/html/forms/parse-device-group.inc.php b/html/forms/parse-device-group.inc.php
new file mode 100644
index 0000000000..7009459f26
--- /dev/null
+++ b/html/forms/parse-device-group.inc.php
@@ -0,0 +1,28 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+$group_id = $_POST['group_id'];
+
+if(is_numeric($group_id) && $group_id > 0) {
+ $group = dbFetchRow("SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1",array($group_id));
+ $group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@]+[&&\|\|]+)/',$group['pattern'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ $count = count($group_split) - 1;
+ $group_split[$count] = $group_split[$count].' &&';
+ $output = array('name'=>$group['name'],'desc'=>$group['desc'],'pattern'=>$group_split);
+ echo _json_encode($output);
+}
diff --git a/html/includes/modal/delete_alert_map.inc.php b/html/includes/modal/delete_alert_map.inc.php
new file mode 100644
index 0000000000..2656fd4cbe
--- /dev/null
+++ b/html/includes/modal/delete_alert_map.inc.php
@@ -0,0 +1,70 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+?>
+
+
+
+
+
+
+
Confirm Delete
+
+
+
If you would like to remove the alert map then please click Delete.
+
+
+
+
+
+
+
diff --git a/html/includes/modal/delete_device_group.inc.php b/html/includes/modal/delete_device_group.inc.php
new file mode 100644
index 0000000000..105442935d
--- /dev/null
+++ b/html/includes/modal/delete_device_group.inc.php
@@ -0,0 +1,70 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() === false) {
+ die('ERROR: You need to be admin');
+}
+
+?>
+
+
+
+
+
+
+
Confirm Delete
+
+
+
If you would like to remove the device group then please click Delete.
+
+
+
+
+
+
+
diff --git a/html/includes/modal/new_alert_map.inc.php b/html/includes/modal/new_alert_map.inc.php
new file mode 100644
index 0000000000..09b0795ca5
--- /dev/null
+++ b/html/includes/modal/new_alert_map.inc.php
@@ -0,0 +1,127 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() !== false) {
+
+?>
+
+
',
+ template: '{{name}}',
+ valueKey:"name",
+ engine: Hogan
+ }
+]);
$('#and, #or').click('', function(e) {
e.preventDefault();
diff --git a/html/includes/modal/new_device_group.inc.php b/html/includes/modal/new_device_group.inc.php
new file mode 100644
index 0000000000..8e8814541f
--- /dev/null
+++ b/html/includes/modal/new_device_group.inc.php
@@ -0,0 +1,189 @@
+
+ *
+ * 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.
+ */
+
+if(is_admin() !== false) {
+
+?>
+
+