| 
									
										
										
										
											2015-08-30 20:27:55 +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. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $status  = 'error'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $descr = mres($_POST['descr']); | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  | $device_id = mres($_POST['device_id']); | 
					
						
							| 
									
										
										
										
											2015-08-30 20:27:55 +00:00
										 |  |  | $ifName = mres($_POST['ifName']); | 
					
						
							|  |  |  | $port_id = mres($_POST['port_id']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  | logfile($descr . ','. $device_id . ','. $ifName. ','. $port_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 20:27:55 +00:00
										 |  |  | if (!empty($ifName) && is_numeric($port_id)) { | 
					
						
							|  |  |  |     // We have ifName and  port id so update ifAlias
 | 
					
						
							| 
									
										
										
										
											2015-08-30 13:50:44 -07:00
										 |  |  |     if (empty($descr)) { | 
					
						
							|  |  |  |         $descr = 'repoll'; | 
					
						
							|  |  |  |         // Set to repoll so we avoid using ifDescr on port poll
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  |     if (dbUpdate(array('ifAlias'=>$descr), 'ports', '`port_id`=?', array($port_id)) > 0) { | 
					
						
							| 
									
										
										
										
											2015-08-30 20:27:55 +00:00
										 |  |  |         $device = device_by_id_cache($device_id); | 
					
						
							| 
									
										
										
										
											2015-08-30 14:34:37 -07:00
										 |  |  |         if ($descr === 'repoll') { | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  |             del_dev_attrib($device, 'ifName'); | 
					
						
							| 
									
										
										
										
											2015-08-30 20:27:55 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  |             set_dev_attrib($device, 'ifName', $ifName); | 
					
						
							| 
									
										
										
										
											2015-08-30 20:27:55 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         $status = 'ok'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $status = 'na'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-30 13:47:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | $response = array( | 
					
						
							|  |  |  |     'status'        => $status, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | echo _json_encode($response); |