| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org> | 
					
						
							|  |  |  |  * 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. | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Alert Templates | 
					
						
							|  |  |  |  * @author f0o <f0o@devilcode.org> | 
					
						
							|  |  |  |  * @copyright 2014 f0o, LibreNMS | 
					
						
							|  |  |  |  * @license GPL | 
					
						
							|  |  |  |  * @package LibreNMS | 
					
						
							|  |  |  |  * @subpackage Alerts | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-04-26 14:39:10 -07:00
										 |  |  | header('Content-type: text/plain'); | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | if (is_admin() === false) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |     die('ERROR: You need to be admin'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $ok = ''; | 
					
						
							|  |  |  | $error = ''; | 
					
						
							|  |  |  | $name = mres($_POST['name']); | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | if (!empty($name)) { | 
					
						
							|  |  |  |     if (is_numeric($_REQUEST['template_id']) && $_REQUEST['rule_id']) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         //Update the template/rule mapping
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         if (is_array($_REQUEST['rule_id'])) { | 
					
						
							|  |  |  |             $_REQUEST['rule_id'] = implode(",", $_REQUEST['rule_id']); | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         if (substr($_REQUEST['rule_id'], 0, 1) != ",") { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $_REQUEST['rule_id'] = ",".$_REQUEST['rule_id']; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         if (substr($_REQUEST['rule_id'], -1, 1) != ",") { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $_REQUEST['rule_id'] .= ","; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-11-16 04:06:46 +00:00
										 |  |  |         if (dbUpdate(array('rule_id' => mres($_REQUEST['rule_id']), 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id'])) >= 0) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $ok = "Updated template and rule id mapping"; | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $error ="Failed to update the template and rule id mapping"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |     } elseif ($_REQUEST['template'] && is_numeric($_REQUEST['template_id'])) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         //Update template-text
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-16 04:06:46 +00:00
										 |  |  |         if (dbUpdate(array('template' => $_REQUEST['template'], 'name' => $name, 'title' => $_REQUEST['title'], 'title_rec' => $_REQUEST['title_rec']), "alert_templates", "id = ?", array($_REQUEST['template_id'])) >= 0) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $ok = "Updated template"; | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $error = "Failed to update the template"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |     } elseif ($_REQUEST['template']) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         //Create new template
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         if (dbInsert(array('template' => $_REQUEST['template'], 'name' => $name, 'title' => $_REQUEST['title'], 'title_rec' => $_REQUEST['title_rec']), "alert_templates")) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |             $ok = "Alert template has been created."; | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-05-30 18:10:32 +01:00
										 |  |  |             $error = "Could not create alert template"; | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |         $error = "We could not work out what you wanted to do!"; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |     $error = "You haven't given your template a name, it feels sad :( - $name"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | if (!empty($ok)) { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |     die("$ok"); | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2014-11-30 17:49:52 +00:00
										 |  |  |     die("ERROR: $error"); | 
					
						
							|  |  |  | } |