| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-25 12:24:34 +00:00
										 |  |  | // FIXME - seems to be broken. IPs appear with leading zeroes.
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $ipsec_array = snmpwalk_cache_oid($device, 'cipSecTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB'); | 
					
						
							|  |  |  | $ike_array   = snmpwalk_cache_oid($device, 'cikeTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB'); | 
					
						
							| 
									
										
										
										
											2012-05-03 10:45:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $tunnels_db = dbFetchRows('SELECT * FROM `ipsec_tunnels` WHERE `device_id` = ?', array($device['device_id'])); | 
					
						
							| 
									
										
										
										
											2015-03-29 20:43:35 +01:00
										 |  |  | foreach ($tunnels_db as $tunnel) { | 
					
						
							|  |  |  |     if (empty($tunnel['peer_addr']) && empty($tunnel['local_addr'])) { | 
					
						
							|  |  |  |         dbDelete('ipsec_tunnels', '`tunnel_id` = ?', array($tunnel['tunnel_id'])); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-29 20:43:35 +01:00
										 |  |  |     $tunnels[$tunnel['peer_addr']] = $tunnel; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | foreach ($ipsec_array as $index => $tunnel) { | 
					
						
							|  |  |  |     $tunnel = array_merge($tunnel, $ike_array[$tunnel['cipSecTunIkeTunnelIndex']]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo "Tunnel $index (".$tunnel['cipSecTunIkeTunnelIndex'].")\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo 'Address '.$tunnel['cikeTunRemoteValue']."\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $address = $tunnel['cikeTunRemoteValue']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $oids = array( | 
					
						
							|  |  |  |         'cipSecTunInOctets', | 
					
						
							|  |  |  |         'cipSecTunInDecompOctets', | 
					
						
							|  |  |  |         'cipSecTunInPkts', | 
					
						
							|  |  |  |         'cipSecTunInDropPkts', | 
					
						
							|  |  |  |         'cipSecTunInReplayDropPkts', | 
					
						
							|  |  |  |         'cipSecTunInAuths', | 
					
						
							|  |  |  |         'cipSecTunInAuthFails', | 
					
						
							|  |  |  |         'cipSecTunInDecrypts', | 
					
						
							|  |  |  |         'cipSecTunInDecryptFails', | 
					
						
							|  |  |  |         'cipSecTunOutOctets', | 
					
						
							|  |  |  |         'cipSecTunOutUncompOctets', | 
					
						
							|  |  |  |         'cipSecTunOutPkts', | 
					
						
							|  |  |  |         'cipSecTunOutDropPkts', | 
					
						
							|  |  |  |         'cipSecTunOutAuths', | 
					
						
							|  |  |  |         'cipSecTunOutAuthFails', | 
					
						
							|  |  |  |         'cipSecTunOutEncrypts', | 
					
						
							|  |  |  |         'cipSecTunOutEncryptFails', | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $db_oids = array( | 
					
						
							|  |  |  |         'cipSecTunStatus'   => 'tunnel_status', | 
					
						
							|  |  |  |         'cikeTunLocalName'  => 'tunnel_name', | 
					
						
							|  |  |  |         'cikeTunLocalValue' => 'local_addr', | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!is_array($tunnels[$tunnel['cikeTunRemoteValue']]) && !empty($tunnel['cikeTunRemoteValue'])) { | 
					
						
							|  |  |  |         $tunnel_id = dbInsert(array('device_id' => $device['device_id'], 'peer_addr' => $tunnel['cikeTunRemoteValue'], 'local_addr' => $tunnel['cikeTunLocalValue'], 'tunnel_name' => $tunnel['cikeTunLocalName']), 'ipsec_tunnels'); | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     else { | 
					
						
							|  |  |  |         foreach ($db_oids as $db_oid => $db_value) { | 
					
						
							|  |  |  |             $db_update[$db_value] = $tunnel[$db_oid]; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         $updated = dbUpdate($db_update, 'ipsec_tunnels', '`tunnel_id` = ?', array($tunnels[$tunnel['cikeTunRemoteValue']]['tunnel_id'])); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     if (is_numeric($tunnel['cipSecTunHcInOctets']) && is_numeric($tunnel['cipSecTunHcInDecompOctets']) | 
					
						
							|  |  |  |         && is_numeric($tunnel['cipSecTunHcOutOctets']) && is_numeric($tunnel['cipSecTunHcOutUncompOctets']) | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         echo 'HC '; | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         $tunnel['cipSecTunInOctets']        = $tunnel['cipSecTunHcInOctets']; | 
					
						
							|  |  |  |         $tunnel['cipSecTunInDecompOctets']  = $tunnel['cipSecTunHcInDecompOctets']; | 
					
						
							|  |  |  |         $tunnel['cipSecTunOutOctets']       = $tunnel['cipSecTunHcOutOctets']; | 
					
						
							|  |  |  |         $tunnel['cipSecTunOutUncompOctets'] = $tunnel['cipSecTunHcOutUncompOctets']; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     $rrd_file = $config['rrd_dir'].'/'.$device['hostname'].'/ipsectunnel-'.$address.'.rrd'; | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     $rrd_create = $config['rrd_rra']; | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     foreach ($oids as $oid) { | 
					
						
							|  |  |  |         $oid_ds      = truncate(str_replace('cipSec', '', $oid), 19, ''); | 
					
						
							|  |  |  |         $rrd_create .= " DS:$oid_ds:COUNTER:600:U:1000000000"; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     $rrdupdate = 'N'; | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     foreach ($oids as $oid) { | 
					
						
							|  |  |  |         if (is_numeric($tunnel[$oid])) { | 
					
						
							|  |  |  |             $value = $tunnel[$oid]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $value = '0'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $rrdupdate .= ":$value"; | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     if (isset($tunnel['cikeTunRemoteValue'])) { | 
					
						
							|  |  |  |         if (!file_exists($rrd_file)) { | 
					
						
							|  |  |  |             rrdtool_create($rrd_file, $rrd_create); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         rrdtool_update($rrd_file, $rrdupdate); | 
					
						
							|  |  |  |         // $graphs['ipsec_tunnels'] = TRUE;
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }//end foreach
 | 
					
						
							| 
									
										
										
										
											2011-09-12 13:53:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:45:47 +01:00
										 |  |  | unset($rrd_file,$rrd_create,$rrdupdate,$oids, $data, $data_array, $oid, $tunnel); |