Location: PHPKode > projects > Network Managment / Inventory System > clearsite/include/admin/device_admin.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                                               |
 +-------------------------------------------------------------------------+
*/
$temp_config_path = substr(__FILE__, 0, -22) . "config.php";
include_once($temp_config_path);
include_once("$cs_base_path/include/aloe/aloe_config.php");

extract($_POST);
extract($_GET);

snmp_set_quick_print(1);
if (function_exists('snmp_set_oid_numeric_print')) {
  snmp_set_oid_numeric_print(1);
};

$link = mysql_connect("$DBhost:$DBport",$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName", $link) or die("Unable to select database $DBName");


if (!empty($dbfunc)) {
  if ($dbfunc == "add") {
    $sqlquery = "INSERT INTO devices SET device_IP=\"$device_IP\", device_FQDN=\"$device_FQDN\", device_name=\"$device_name\", device_serial=\"$device_serial\", device_asset_tag=\"$device_asset_tag\", device_model=\"$device_model\", device_SNMP_Read=\"$device_SNMP_Read\", device_type_ID=\"$device_type_ID\", device_OS=\"$device_OS\", location_ID=\"$location_ID\", snmpver=\"$snmpver\", template_ID=\"$template_ID\", device_status=\"online\", pingable=\"$pingable\", added_to_DB = NOW()";
    $result = mysql_query($sqlquery, $link) or die('Query failed: ' . mysql_error($link));
  } else if ($dbfunc == "edit") {
    $sqlquery = "UPDATE devices SET device_IP=\"$device_IP\", device_FQDN=\"$device_FQDN\", device_name=\"$device_name\", device_serial=\"$device_serial\", device_asset_tag=\"$device_asset_tag\", device_model=\"$device_model\", device_SNMP_Read=\"$device_SNMP_Read\", device_type_ID=\"$device_type_ID\", device_OS=\"$device_OS\", location_ID=\"$location_ID\", snmpver=\"$snmpver\", template_ID=\"$template_ID\", pingable=\"$pingable\", device_status=\"$device_status\" WHERE device_ID=\"$device_ID\"";
    $result = mysql_query($sqlquery, $link) or die('Query failed: ' . mysql_error($link));
    if ($device_status == "offline") {
      $sqlquery2 = "DELETE FROM interfaces WHERE device_ID=\"$device_ID\"";
      $result2 = mysql_query($sqlquery2, $link) or die('Query failed: ' . mysql_error($link));
    };
  } else if ($dbfunc == "delete") {
    $dt_query  = "SELECT t1.device_type_name FROM device_type AS t1, devices AS t2 WHERE t1.device_type_ID = t2.device_type_ID";
    $dt_result = mysql_query($dt_query);
    $dt_row    = mysql_fetch_assoc($dt_result);
    $identifiers = array("cpu_ID", "interface_ID");
    $tables      = array("cpus",   "interfaces");
    $ug_query    = array();
    if ($dt_row['device_type_name'] == "css") {
      $identifiers[] = "cr_ID";
      $identifiers[] = "owner_ID";
      $identifiers[] = "sv_ID";
      $tables[]      = "css_cr";
      $tables[]      = "css_owner";
      $tables[]      = "css_sv";
    } else if ($dt_row['device_type_name'] == "vpn concentrator") {
      $identifiers[] = "session_ID";
      $tables[]      = "vpn_sessions";
    } else if ($dt_row['device_type_name'] == "wap") {
      $identifiers[] = "client_ID";
      $tables[]      = "wap_clients";
    };
    for ($x=0; $x<count($tables); $x++) {
      $ug_query[] = "DELETE t1 FROM user_groups AS t1, $tables[$x] AS t2, devices AS t3 WHERE t1.interface_type=$identifiers[$x] and t2.$identifiers[$x]=t1.interface_ID and t2.device_ID=\"$device_ID\"";
    };
    foreach ($ug_query as $ug_delete) {
      $ug_result = mysql_query($ug_delete);
    };
    $sqlquery = "DELETE FROM devices WHERE device_ID=\"$device_ID\"";
    $result = mysql_query($sqlquery, $link) or die('Query failed: ' . mysql_error($link));
  };
};

if (!empty($act)) {
  if ($act == "add2") {
    $add_error = "";
    if (empty($device_IP) or empty($device_name) or empty($device_SNMP_Read)) {
      $add_error = "";
      $act = "add";
      if (empty($device_IP)) {
        $add_error .= "Device IP must be entered.<br />";
      };
      if (empty($device_name)) {
        $add_error .= "Device Name must be entered.<br />";
      };
      if (empty($device_SNMP_Read)) {
        $add_error .= "Community String must be entered.<br />";
      };
    } else {
      $device_IP = trim($device_IP);
      if (eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $device_IP)) {
        $device_ip_exists_query = "SELECT t1.device_name, t2.device_type_name FROM devices as t1, device_type as t2 WHERE t1.device_IP=\"$device_IP\" and t1.device_type_ID = t2.device_type_ID";
        $device_ip_exists_result = mysql_query($device_ip_exists_query, $link);
        $device_ip_exists_row = mysql_fetch_assoc($device_ip_exists_result);
        if (empty($device_ip_exists_row) or !empty($bypass)) {
          if (php_ping($device_IP)) {
            $pingable = "Y";
            $ping_results = "The deivce is pingable.";
          } else {
            $pingable = "N";
            $ping_results = "The deivce is not pingable.";
          };
          $device_FQDN = gethostbyaddr($device_IP);
          $sqlquery = "SELECT device_type_name, device_model_oid, device_os_oid, device_serial_oid, snmpver FROM device_type WHERE device_type_ID=\"$device_type_ID\"";
          $result = mysql_query($sqlquery, $link);
          $dev_row = mysql_fetch_assoc($result);
          if ($dev_row["device_os_oid"] != "none") {
            error_reporting(0);
            $device_os_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_os_oid]");
            if (substr($php_errormsg, 0, 16) == "No response from") {
              $act = "add";
              $add_error .= "Incorrect IP or Community String given.<br />";
              unset($php_errormsg);
            };
            error_reporting(E_ALL);
            if (!empty($device_os_results)) {
              if ($device_type_ID == "4") {
                if (strpos($device_os_results, "\n") > 0) {
                  $device_os_results_array = preg_split("/\n/", $device_os_results);
                  $device_os_results = $device_os_results_array[1];
                };
              } else if ($device_type_ID == "3" or $device_type_ID == "6") {
                if (strpos($device_os_results, "\n") > 0) {
                  $device_os_results_array = preg_split("/\n/", $device_os_results);
                  $device_os_results = $device_os_results_array[0] . $device_os_results_array[1];
                };
              };
            };
          } else {
            $device_os_results = "";
          };
          if ($dev_row["device_model_oid"] != "none") {
            error_reporting(0);
            $device_model_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_model_oid]");
            if (substr($php_errormsg, 0, 16) == "No response from") {
              $act = "add";
              $add_error .= "Incorrect IP or Community String given.<br />";
              unset($php_errormsg);
            };
            error_reporting(E_ALL);
            $device_model_results = substr($device_model_results, strpos($device_model_results, "\$") + 1, -2);
          } else {
            $device_model_results = "";
          };
          if ($dev_row["device_serial_oid"] != "none") {
            error_reporting(0);
            $device_serial_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_serial_oid]");
            if (substr($php_errormsg, 0, 24) == "This name does not exist") {
              $act = "add";
              $add_error .= "Incorrect Device Type chosen.<br />";
              unset($php_errormsg);
            };
            error_reporting(E_ALL);
            $device_serial_results = trim($device_serial_results, "\"");
            if ($device_serial_results == "No Such Instance currently exists at this OID") {
              $device_serial_results = "";
            };
          } else {
            $device_serial_results = "";
          };
        } else {
          $act = "add";
          $bypass = "yes";
          $add_error .= "IP already exists as $device_ip_exists_row[device_name] which is lsted as a $device_ip_exists_row[device_type_name].  Click continue to override this error.<br />";
        };
      } else {
        $act = "add";
        $add_error .= "Invalid IP given.<br />";
      };
    };
  };
};
      

if (empty($act)) {
  print "
         <fieldset class=\"site_admin\">
         <p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&act=add\"><img src=\"$ClearsiteBaseURL/images/add-devices.png\" class=\"admin_img\"></a></p>
         
         <div class=\"alt_six_even\">
         	<div class=\"six_cell_row\">
           <div class=\"cell_one\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&dev_oby=t1.device_name\">Device Name</a></p>
           </div>
           <div class=\"cell_two\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&dev_oby=t1.device_IP\">Device IP</a></p>
           </div>
           <div class=\"cell_three\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&dev_oby=t2.device_type_name\">Device Type</a></p>
           </div>
           <div class=\"cell_four\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&dev_oby=t1.device_status\">Status</a></p>
           </div>
           <div class=\"cell_five\">
           	<p>&nbsp;<p>
           </div>
           <div class=\"cell_six\">
           	<p>&nbsp;<p>
           </div>
           <div class=\"tbl_spacer\"></div>
           </div>
          </div>

  ";
  
  if (empty($dev_oby)) {
    $dev_oby = "device_name";
  };
  $dev_sqlquery = "SELECT t1.device_ID, t1.device_IP, t1.device_name, t2.device_type_name, t1.device_status FROM devices AS t1, device_type AS t2 WHERE t1.location_ID = \"$location_ID\" and t1.device_type_ID = t2.device_type_ID ORDER BY $dev_oby";
  $dev_result = mysql_query($dev_sqlquery, $link);
  $div_six_class = "bg02";
  while ($dev_row = mysql_fetch_array($dev_result)) {
    if ($div_six_class == "alt_six_odd"){
      $div_six_class = "alt_six_even";
    } else {
      $div_six_class = "alt_six_odd";
    };
    print "
    		<div class=\"$div_six_class\">
    			<div class=\"six_cell_row\">
           <div class=\"cell_one\">
           	<p>$dev_row[device_name]</p>
           </div>
           <div class=\"cell_two\">
           	<p>$dev_row[device_IP]</p>
           </div>
           <div class=\"cell_three\">
           	<p>$dev_row[device_type_name]</p>
           </div>
           <div class=\"cell_four\">
           	<p>$dev_row[device_status]</p>
           </div>
           <div class=\"cell_five\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&act=edit&device_ID=$dev_row[device_ID]\"><img src=\"$ClearsiteBaseURL/images/edit.png\" class=\"admin_img\"></a><p>
           </div>
           <div class=\"cell_six\">
           	<p><a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID&act=delete&device_ID=$dev_row[device_ID]\"><img src=\"$ClearsiteBaseURL/images/delete.png\" class=\"admin_img\"></a><p>
           </div>
           <div class=\"tbl_spacer\"></div>
           </div>
          </div>
      ";
  };
  print "
           </fieldset>
           <br />
  ";

} else if ($act == "add") {
  $added_to_DB = time();
  if (!empty($add_error)) {
    print "<font class=\"admin_error\">$add_error</font><p>
";
  };
  print "
         <fieldset class=\"site_details\">
         <form action=\"$ClearsiteBaseURL/include/admin/device_admin.php\" method=\"POST\" onsubmit=\"docClickLoader.submitInto(this, 'device_$location_ID', event)\">
          <input type=\"hidden\" name=\"act\" value=\"add2\">
  ";
  if (isset($bypass)) {
    print "<input type=\"hidden\" name=\"bypass\" value=\"yes\" />";
  };
  print "
          <label for=\"ip\">Device IP</label><input id=\"ip\" type=\"text\" name=\"device_IP\"";
  if (isset($device_IP)) {
    print " value=\"$device_IP\"";
  };
  print "><br />
          <label for=\"name\">Device Name</label><input id=\"name\" type=\"text\" name=\"device_name\"";
  if (isset($device_name)) {
    print " value=\"$device_name\"";
  };
  print "><br />
          <label for=\"community\">Community String</label><input id=\"community\" type=\"text\" name=\"device_SNMP_Read\"";
  if (isset($device_SNMP_Read)) {
    print " value=\"$device_SNMP_Read\"";
  };
  print "><br />
          <label for=\"type\">Device Type</label><select id=\"type\" name=\"device_type_ID\">
  ";
  $sqlquery = "SELECT device_type_ID, device_type_name FROM device_type ORDER BY device_type_name";
  $result = mysql_query($sqlquery, $link);
  while ($dev_row = mysql_fetch_array($result)) {
    print "
           <option value=\"$dev_row[device_type_ID]\"";
    if (isset($device_type_ID) and $device_type_ID == $dev_row["device_type_ID"]) {
      print " selected";
    };
    print ">$dev_row[device_type_name]</option>";
  };
  print "
          </select><br />
         <label for=\"location\">Location</label><select id=\"location\" name=\"location_ID\">
  ";
  $sqlquery = "SELECT t1.location_ID, t1.city, t1.state, t2.country_full FROM location AS t1, country_codes AS t2 WHERE t1.country_code = t2.country_code ORDER BY t1.city";
  $result = mysql_query($sqlquery, $link);
  while ($dev_row = mysql_fetch_assoc($result)) {
    print "
           <option value=\"$dev_row[location_ID]\"";
    if ($location_ID == $dev_row["location_ID"]) {
      print " selected";
    };
    print ">$dev_row[city], $dev_row[state], $dev_row[country_full]</option>";
  };
  print "
          </select><br />
         <p><input type=\"image\" name=\"Continue\" value=\"Continue\" src=\"$ClearsiteBaseURL/images/continue.png\" />&nbsp&nbsp&nbsp&nbsp&nbsp<a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
        </form>
        </fieldset>
  ";
} else if ($act == "add2") {
  print "
         <fieldset class=\"site_details\">
         <form action=\"$ClearsiteBaseURL/include/admin/device_admin.php\" method=\"POST\" onsubmit=\"docClickLoader.submitInto(this, 'device_$location_ID', event)\">
          <input type=\"hidden\" name=\"dbfunc\" value=\"add\">
          <input type=\"hidden\" name=\"device_IP\" value=\"$device_IP\">
          <label for=\"ip\">Device IP:</label>$device_IP<br>
          <label for=\"name\">Device Name:</label><input id=\"name\" type=\"text\" name=\"device_name\" value=\"$device_name\" size=\"32\"><br />
          <input type=\"hidden\" name=\"device_FQDN\" value=\"$device_FQDN\">
          <label for=\"fqdn\">Device FQDN:</label>$device_FQDN<br>
          <label for=\"serial\">Serial Number:</label><input id=\"serial\" type=\"text\" name=\"device_serial\" value=\"$device_serial_results\" size=\"32\"><br />
          <label for=\"asset\">Asset Tag Number:</label><input id=\"asset\" type=\"text\" name=\"device_asset_tag\" size=\"32\"><br />
          <label for=\"model\">Model:</label><input id=\"model\" type=\"text\" name=\"device_model\" value=\"$device_model_results\" size=\"16\"><br />
          <input type=\"hidden\" name=\"device_SNMP_Read\" value=\"$device_SNMP_Read\">
          <label for=\"community\">Community:</label>$device_SNMP_Read<br>
          <input type=\"hidden\" name=\"device_type_ID\" value=\"$device_type_ID\">
          <label for=\"type\">Device Type:</label>$dev_row[device_type_name]<br />
          <input type=\"hidden\" name=\"device_OS\" value=\"$device_os_results\">
          <label for=\"snmpv\">SNMP Version:</label><select id=\"snmpv\" name=\"snmpver\">
                          <option value=\"1\""; if ($dev_row["snmpver"] == "1") { print " selected"; }; print "> 1 </option>
                          <option value=\"2\""; if ($dev_row["snmpver"] == "2") { print " selected"; }; print "> 2 </option>
                        </select><br />
          <label for=\"os\">Device OS:</label>$device_os_results<br>
          <label for=\"template\">Walk Template:</label><select id=\"template\" name=\"template_ID\">
";
  $sqlquery2 = "SELECT template_ID, device_type_ID, template_name FROM snmp_template_list ORDER BY template_name";
  $result2 = mysql_query($sqlquery2, $link);
  while ($dev_row2 = mysql_fetch_assoc($result2)) {
    print "
           <option value=\"$dev_row2[template_ID]\""; 
    
    if ($device_type_ID != "4" and $device_type_ID != "8") {
      if ($device_type_ID == $dev_row2["device_type_ID"]) {
        print " selected";
      };
    } else {
      if ((strstr($device_os_results, "IOS") and $dev_row2["template_ID"] == 3 and $device_type_ID == "4") or (!strstr($device_os_results, "IOS") and $dev_row2["template_ID"] == 4 and $device_type_ID == "4") or (strstr($device_os_results, "IOS") and $dev_row2["template_ID"] == 9 and $device_type_ID == "8") or (!strstr($device_os_results, "IOS") and $dev_row2["template_ID"] == 10 and $device_type_ID == "8")) {
        print " selected";
      };
    };
    print ">$dev_row2[template_name]</option>
  ";
  };
  print "
          </select><br />
          <label for=\"ping_results\">$ping_results</label><br />
          <label for=\"pingable\">Pingable</label><select id=\"pingable\" name=\"pingable\">
                    <option value=\"Y\""; if ($pingable == "Y") { print " selected"; }; print "> Yes </option>
                    <option value=\"N\""; if ($pingable == "N") { print " selected"; }; print "> No </option>
          </select><br />
          <input type=\"hidden\" name=\"location_ID\" value=\"$location_ID\">
          <p><input type=\"image\" name=\"Add\" value=\"Add\" src=\"$ClearsiteBaseURL/images/add.png\">&nbsp&nbsp&nbsp&nbsp&nbsp<a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
         </form>
         </fieldset>
  ";
  
} else if ($act == "edit") {
  $sqlquery = "SELECT device_ID, device_IP, device_name, device_asset_tag, device_SNMP_Read, device_type_ID, location_ID, device_status FROM devices WHERE device_ID=\"$device_ID\"";
  $result = mysql_query($sqlquery, $link);
  $dev_row = mysql_fetch_assoc($result);
  print "
         <fieldset class=\"site_details\">
         <form action=\"$ClearsiteBaseURL/include/admin/device_admin.php\" method=\"POST\" onsubmit=\"docClickLoader.submitInto(this, 'device_$location_ID', event)\">
          <input type=\"hidden\" name=\"act\" value=\"edit2\">
          <input type=\"hidden\" name=\"device_ID\" value=\"$device_ID\">
          <label for=\"ip\">Device IP:</label><input id=\"ip\" type=\"text\" name=\"device_IP\" value=\"$dev_row[device_IP]\" size=\"15\"><br />
          <label for=\"name\">Device Name:</label><input id=\"name\" type=\"text\" name=\"device_name\" value=\"$dev_row[device_name]\" size=\"32\"><br />
          <label for=\"asset\">Asset Tag Number:</label><input id=\"asset\" type=\"text\" name=\"device_asset_tag\" value=\"$dev_row[device_asset_tag]\" size=\"32\"><br />
          <label for=\"community\">Community:</label><input id=\"community\" type=\"text\" name=\"device_SNMP_Read\" value=\"$dev_row[device_SNMP_Read]\" size=\"32\"><br />
          <label for=\"type\">Device Type:</label><select id=\"type\" name=\"device_type_ID\">
  ";
  $sqlquery2 = "SELECT device_type_ID, device_type_name FROM device_type ORDER BY device_type_name";
  $result2 = mysql_query($sqlquery2, $link);
  while ($dev_row2 = mysql_fetch_assoc($result2)) {
    print "
           <option value=\"$dev_row2[device_type_ID]\""; if ($dev_row2["device_type_ID"] == $dev_row["device_type_ID"]) { print " selected"; }; print ">$dev_row2[device_type_name]</option>";
  };
  print "
          </select><br />
          <label for=\"location\">Location:</label><select id=\"location\" name=\"location_ID\">
  ";
  $sqlquery3 = "SELECT t1.location_ID, t1.city, t1.state, t2.country_full FROM location AS t1, country_codes AS t2 WHERE t1.country_code = t2.country_code ORDER BY t1.city";
  $result3 = mysql_query($sqlquery3, $link);
  while ($dev_row3 = mysql_fetch_assoc($result3)) {
    print "
           <option value=\"$dev_row3[location_ID]\""; if ($dev_row3["location_ID"] == $dev_row["location_ID"]) { print " selected"; }; print ">$dev_row3[city], $dev_row3[state], $dev_row3[country_full]</option>";
  };
  print "
          </select><br />
          <p><input type=\"image\" name=\"Continue\" value=\"Continue\" src=\"$ClearsiteBaseURL/images/continue.png\" />&nbsp&nbsp&nbsp&nbsp&nbsp<a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
         </form>
         </fieldset>
  ";
} else if ($act == "edit2") {
  $sqlquery = "SELECT device_type_name, device_model_oid, device_os_oid, device_serial_oid FROM device_type WHERE device_type_ID=\"$device_type_ID\"";
  $result = mysql_query($sqlquery, $link);
  $dev_row = mysql_fetch_assoc($result);
  if ($dev_row["device_os_oid"] != "none" and snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_os_oid]")) {
    $device_os_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_os_oid]");
    if ($dev_row["device_type_name"] == "switch") {
      $device_os_results_array = preg_split("/\n/", $device_os_results);
      $device_os_results = $device_os_results_array[1];
    } else if ($dev_row["device_type_name"] == "router" or $dev_row["device_type_name"] == "switch (one U)") {
      $device_os_results_array = preg_split("/\n/", $device_os_results);
      $device_os_results = $device_os_results_array[0] . $device_os_results_array[1];
      $device_os_results = trim($device_os_results);
    };
  } else {
    $device_os_results = "";
  };
  if ($dev_row["device_model_oid"] != "none" and snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_model_oid]")) {
    $device_model_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_model_oid]");
    $device_model_results = substr($device_model_results, strpos($device_model_results, "\$") + 1, -2);
  } else {
    $device_model_results = "";
  };
  if ($dev_row["device_serial_oid"] != "none" and snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_serial_oid]")) {
    $device_serial_results = snmpget("$device_IP", "$device_SNMP_Read", "$dev_row[device_serial_oid]");
    $device_serial_results = trim($device_serial_results, "\"");
    if ($device_serial_results == "No Such Instance currently exists at this OID") {
      $device_serial_results = "";
    };
  } else {
    $device_serial_results = "";
  };
  $device_FQDN = gethostbyaddr($device_IP);
  $sqlquery2 = "SELECT device_FQDN, device_serial, device_model, device_OS, snmpver, device_status FROM devices WHERE device_ID=\"$device_ID\"";
  $result2 = mysql_query($sqlquery2, $link);
  $dev_row2 = mysql_fetch_assoc($result2);
  print "
         <fieldset class=\"site_details\">
         <form action=\"$ClearsiteBaseURL/include/admin/device_admin.php\" method=\"POST\" onsubmit=\"docClickLoader.submitInto(this, 'device_$location_ID', event)\">
          <input type=\"hidden\" name=\"dbfunc\" value=\"edit\">
          <input type=\"hidden\" name=\"device_ID\" value=\"$device_ID\">
          <input type=\"hidden\" name=\"device_IP\" value=\"$device_IP\">
          <label for=\"ip\">Device IP:</label>$device_IP<br>
          <label for=\"name\">Device Name:</label><input id=\"name\" type=\"text\" name=\"device_name\" value=\"$device_name\" size=\"32\"><br />
          <input type=\"hidden\" name=\"device_FQDN\" value=\"$device_FQDN\">
          <label for=\"fqdn\">Device FQDN:</label>$device_FQDN<br>";
  if ($device_FQDN != $dev_row2["device_FQDN"]) {
    print "<label for=\"ofqdn\">Old FQDN:</label>$dev_row2[device_FQDN]<br />";
  }; 
  print "
          <label for=\"serial\">Serial Number:</label><input id=\"serial\" type=\"text\" name=\"device_serial\" value=\"$dev_row2[device_serial]\" size=\"32\">"; if ($device_serial_results != $dev_row2["device_serial"]) { print " Value Pulled via SNMP: $device_serial_results"; }; print "<br />
          <label for=\"asset\">Asset Tag Number:</label><input id=\"asset\" type=\"text\" name=\"device_asset_tag\" value=\"$device_asset_tag\" size=\"32\"><br />
          <label for=\"model\">Model:</label><input id=\"model\" type=\"text\" name=\"device_model\" value=\"$device_model_results\" size=\"16\">"; if ($device_model_results != $dev_row2["device_model"]) { print " Old Value: $dev_row2[device_model]"; }; print "<br />
          <input type=\"hidden\" name=\"device_SNMP_Read\" value=\"$device_SNMP_Read\">
          <label for=\"community\">Community:</label>$device_SNMP_Read<br>
          <input type=\"hidden\" name=\"device_type_ID\" value=\"$device_type_ID\">
          <label for=\"type\">Device Type:</label>$dev_row[device_type_name]<br />
          <input type=\"hidden\" name=\"device_OS\" value=\"$device_os_results\">
          <label for=\"snmpv\">SNMP Version:</label><select id=\"snmpv\" name=\"snmpver\">
                          <option value=\"1\""; if ($dev_row2["snmpver"] == "1") { print " selected"; }; print "> 1 </option>
                          <option value=\"2\""; if ($dev_row2["snmpver"] == "2") { print " selected"; }; print "> 2 </option>
                        </select><br />
          <label for=\"os\">Device OS:</label>$device_os_results<br>";
  if ($device_os_results != $dev_row2["device_OS"]) {
    print "<label for=\"oos\">Old Value:</label>$dev_row2[device_OS]<br />";
  };
  print "
          <label for=\"template\">Walk Template:</label><select id=\"template\" name=\"template_ID\">
";
  $sqlquery3 = "SELECT template_ID, device_type_ID, template_name FROM snmp_template_list ORDER BY template_name";
  $result3 = mysql_query($sqlquery3, $link);
  while ($dev_row3 = mysql_fetch_assoc($result3)) {
    print "
           <option value=\"$dev_row3[template_ID]\""; 
    
    if ($device_type_ID != "4" and $device_type_ID != "8") {
      if ($device_type_ID == $dev_row3["device_type_ID"]) {
        print " selected";
      };
    } else {
      if ((strstr($device_os_results, "IOS") and $dev_row3["template_ID"] == 3 and $device_type_ID == "4") or (!strstr($device_os_results, "IOS") and $dev_row3["template_ID"] == 4 and $device_type_ID == "4") or (strstr($device_os_results, "IOS") and $dev_row3["template_ID"] == 9 and $device_type_ID == "8") or (!strstr($device_os_results, "IOS") and $dev_row3["template_ID"] == 10 and $device_type_ID == "8")) {
        print " selected";
      };
    };
    print ">$dev_row3[template_name]</option>
  ";
  };
  if (php_ping($device_IP)) {
    $pingable = "Y";
    $ping_results = "The deivce is pingable.";
  } else {
    $pingable = "N";
    $ping_results = "The deivce is not pingable.";
  };
  print "
          </select><br />
          <label for=\"ping_results\">$ping_results</label><br />
          <label for=\"pingable\">Pingable</label><select id=\"pingable\" name=\"pingable\">
                    <option value=\"Y\""; if ($pingable == "Y") { print " selected"; }; print "> Yes </option>
                    <option value=\"N\""; if ($pingable == "N") { print " selected"; }; print "> No </option>
          </select><br />
          <label for=\"status\">Device Status:</label><select id=\"status\" name=\"device_status\">
                          <option value=\"offline\""; if ($dev_row2["device_status"] == "offline") { print "selected"; }; print ">Not in Use</option>
                          <option value=\"online\""; if ($dev_row2["device_status"] == "online") { print "selected"; }; print ">Online</option>
                         </select><br />
                         
          <input type=\"hidden\" name=\"location_ID\" value=\"$location_ID\">
          <p><input type=\"image\" name=\"Submit\" value=\"Submit\" src=\"$ClearsiteBaseURL/images/submit.png\" />&nbsp&nbsp&nbsp&nbsp&nbsp<a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
         </form>
         </fieldset>
  ";
} else if ($act == "delete") {
  $sqlquery = "SELECT t1.device_IP, t1.device_FQDN, t1.device_name, t1.device_serial, t1.device_asset_tag, t1.device_model, t1.device_SNMP_Read, t2.device_type_name, t1.device_OS, t3.city, t3.state, t4.country_full, t1.device_status FROM devices AS t1, device_type AS t2, location AS t3, country_codes as t4 WHERE t1.device_ID = \"$device_ID\" AND t1.device_type_ID = t2.device_type_ID AND t1.location_ID = t3.location_ID AND t3.country_code = t4.country_code";
  $result = mysql_query($sqlquery, $link) or die('Query failed: ' . mysql_error($link));
  $dev_row = mysql_fetch_assoc($result);
  print "
         <fieldset class=\"site_details\">
         <label for=\"ip\">Device IP:</label>$dev_row[device_IP]<br />
         <label for=\"name\">Device Name:</label>$dev_row[device_name]<br />
         <label for=\"fqdn\">FQDN:</label>$dev_row[device_FQDN]<br />
         <label for=\"serial\">Device Serial:</label>$dev_row[device_serial]<br />
         <label for=\"asset\">Asset Tag:</label>$dev_row[device_asset_tag]<br />
         <label for=\"model\">Device Model:</label>$dev_row[device_model]<br />
         <label for=\"community\">Community:</label>$dev_row[device_SNMP_Read]<br />
         <label for=\"type\">Device Type:</label>$dev_row[device_type_name]<br />
         <label for=\"os\">Device OS:</label>$dev_row[device_OS]<br />
         <label for=\"location\">Location:</label>$dev_row[city], $dev_row[state], $dev_row[country_full]<br />
         <label for=\"status\">Device Status:</label>$dev_row[device_status]<br />
         <form action=\"$ClearsiteBaseURL/include/admin/device_admin.php\" method=\"POST\" onsubmit=\"docClickLoader.submitInto(this, 'device_$location_ID', event)\">
          <input type=\"hidden\" name=\"adpage\" value=\"device\">
          <input type=\"hidden\" name=\"dbfunc\" value=\"delete\">
          <input type=\"hidden\" name=\"device_name\" value=\"$dev_row[device_name]\">
          <input type=\"hidden\" name=\"device_ID\" value=\"$device_ID\">
          <input type=\"hidden\" name=\"location_ID\" value=\"$location_ID\">
          <p><input type=\"image\" name=\"Delete\" value=\"Delete\" src=\"$ClearsiteBaseURL/images/delete.png\" />&nbsp&nbsp&nbsp&nbsp&nbsp<a class=\"loadinto-device_$location_ID\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
         </form>
         </fieldset>
  ";
       
};

?>
Return current item: Network Managment / Inventory System