Location: PHPKode > projects > Network Managment / Inventory System > clearsite/include/aloe/cron/aloe_rarpwalk.php
#!/usr/bin/php
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2006-2008 Xinn.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 2          |
 | 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.                            |
 +-------------------------------------------------------------------------+
 | ClearSite/ALOE, A Long Overdue Enterprise network managment solution!   |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Xinn.org. See     |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://aloeusers.net                                                    |
 | http://clearsite.sourceforge.net                                        |
 | http://aloenms.net                                                      |
 | http://clear-site.net                                                   |
 | http://clear-site.info                                                  |
 | http://xinn.org/ClearSite.html                                          |
 +-------------------------------------------------------------------------+
*/
$configpath = str_replace(array("/aloe/cron/aloe_rarpwalk.php", "\aloe\cron\aloe_rarpwalk.php"), "", __FILE__) . "/config.php";
include_once($configpath);
include_once("$cs_base_path/include/aloe/aloe_config.php");
include_once("$base_path/lib/snmp.php");
include_once("$base_path/../db_config.php");

// Creates arrays with info for all devices with ARP tables in DB
$router_ip = array();
$router_community = array();
$arp_table_oid = array();
$snmpver = array();
mysql_connect("$DBhost:$DBport",$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$router_sqlquery = "SELECT t1.device_ip, t1.device_SNMP_Read, t1.pingable, t2.arp_table_oid, t2.snmpver FROM devices AS t1, device_type AS t2 WHERE t1.device_status = \"online\" and t1.device_type_ID = t2.device_type_ID AND t2.arp_table_oid != \"none\"";
$router_result = mysql_query($router_sqlquery)or die ("\nMySQL Error: " . mysql_error() . "\n\nQuery: " . $router_sqlquery . "\n\n");
while($row = mysql_fetch_assoc($router_result)) {
	if ($row["pingable"] == "Y") {
		if (php_ping($row["device_ip"])) {
			$router_ip[]        = $row["device_ip"];
			$router_community[] = $row["device_SNMP_Read"];
			$arp_table_oid []   = $row["arp_table_oid"];
			$snmpver[]          = $row["snmpver"];
		};
	} else {
		$router_ip[]        = $row["device_ip"];
		$router_community[] = $row["device_SNMP_Read"];
		$arp_table_oid []   = $row["arp_table_oid"];
		$snmpver[]          = $row["snmpver"];
	};
};
mysql_close();



// creates content of aloe_rarparray.php
$content = "
<?php
\$ip_mac_array = array();
";
foreach($router_ip as $key => $value) {
	$ip_mac_ufarray = aloe_walk($value, $router_community[$key], "arptable", $arp_table_oid[$key], $snmpver[$key]);
	foreach ($ip_mac_ufarray as $indexnum => $givenvalue) {
		$pos = strpos($indexnum, ".") + 1;
		$indexnum = substr($indexnum, $pos);
		$index_array = split("\.", $indexnum);
    $array_length = count($index_array);
    $xstart = $array_length - 4;
    if ($array_length != 4 and $array_length != 1) {
    	for ($x = $xstart; $x < $array_length; $x++) {
    		if ($x == $xstart) {
    			$indexnum = $index_array[$x];
    		} else {
    			$indexnum .= "." . $index_array[$x];
    		};
    	};
    };
    $temp_givenvalue_array = split("-", $givenvalue);
    foreach($temp_givenvalue_array as $tga) {
    	if (strlen($tga) == "1") {
    		$tga = "0$tga";
    	};
    	if(isset($newgivenvalue)) {
    		$newgivenvalue .= ":$tga";
    	} else {
    		$newgivenvalue = "$tga";
    	};
    };
		$content .= "\$ip_mac_array['$indexnum'] = \"$newgivenvalue\";
";
		unset($newgivenvalue);
	};
	unset($results);
};
$content .= "
?>";

// Writes aloe_rarparray.php which is used in aloe_dbwalk.php
$file_name = "$base_path/aloe_rarparray.php";
$handle = fopen($file_name, 'w');
fwrite($handle, $content);
fclose($handle);
unset($snmpver);
print "Router ARP tables walk completed!\n";
?>
Return current item: Network Managment / Inventory System