| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |  * Copyright (C) 2015 Daniel Preussker <f0o@devilcode.org> | 
					
						
							| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  * */ | 
					
						
							| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Merge config function
 | 
					
						
							|  |  |  |  * @author f0o <f0o@devilcode.org> | 
					
						
							|  |  |  |  * @copyright 2015 f0o, LibreNMS | 
					
						
							|  |  |  |  * @license GPL | 
					
						
							|  |  |  |  * @package LibreNMS | 
					
						
							|  |  |  |  * @subpackage Config | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  | function mergecnf($obj) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     $pointer = array(); | 
					
						
							|  |  |  |     $val     = $obj['config_value']; | 
					
						
							|  |  |  |     $obj     = $obj['config_name']; | 
					
						
							|  |  |  |     $obj     = explode('.', $obj, 2); | 
					
						
							|  |  |  |     if (!isset($obj[1])) { | 
					
						
							|  |  |  |         if (filter_var($val, FILTER_VALIDATE_INT)) { | 
					
						
							|  |  |  |             $val = (int) $val; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (filter_var($val, FILTER_VALIDATE_FLOAT)) { | 
					
						
							|  |  |  |             $val = (float) $val; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) { | 
					
						
							|  |  |  |             $val = filter_var($val, FILTER_VALIDATE_BOOLEAN); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($obj[0])) { | 
					
						
							|  |  |  |             return array($obj[0] => $val); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             return array($val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     else { | 
					
						
							|  |  |  |         $pointer[$obj[0]] = mergecnf(array('config_name' => $obj[1], 'config_value' => $val)); | 
					
						
							| 
									
										
										
										
											2015-06-09 14:05:22 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return $pointer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }//end mergecnf()
 |