Location: PHPKode > projects > Network Managment / Inventory System > clearsite/include/aloe/aloe_menu_tree.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                                          |
 +-------------------------------------------------------------------------+
*/

include_once("../config.php");
include_once("$cs_base_path/include/aloe/aloe_config.php");

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

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

$weekagotimestamp = date('Y-m-d H:i:s', strtotime("-8 days"));
$tenminagotimestamp = date('Y-m-d H:i:s', strtotime("-11 minutes"));
$blade = array();
if ($menu_desc == "main") {
  $device_type_array = array();
  $device_type_query = "SELECT device_type_ID, device_type_name FROM device_type ORDER BY device_type_name";
  $device_type_result = mysql_query($device_type_query);
  while ($device_type_row = mysql_fetch_assoc($device_type_result)) {
    $device_type_array[$device_type_row["device_type_ID"]] = $device_type_row["device_type_name"];
  };
  foreach ($device_type_array as $dtype_ID => $dtype_name) {
    $device_list_query = "SELECT device_ID, device_name FROM devices WHERE device_type_ID=\"$dtype_ID\" and location_ID=\"$location_ID\"";
    $device_list_results = mysql_query($device_list_query);
    if (mysql_affected_rows() > 0) {
      print "<b><a class=\"toggleinto-$dtype_name-main-list\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=device_name&device_type_ID=$dtype_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />$dtype_name</a></b><br />
             <div id=\"$dtype_name-main-list\" style=\"display: none\"></div>
             <p>
";
    };
  };
} else if ($menu_desc == "device_name") {

  $device_list_query = "SELECT device_ID, device_name FROM devices WHERE device_type_ID=\"$device_type_ID\" and location_ID=\"$location_ID\" ORDER BY device_name";
  $device_list_results = mysql_query($device_list_query);
  while ($device_list_row = mysql_fetch_assoc($device_list_results)) {
    print "<span class=\"indent1\"><a class=\"toggleinto-$device_list_row[device_name]-details\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=device_details&device_ID=$device_list_row[device_ID]\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />$device_list_row[device_name]</a></b></span><br />
           <div id=\"$device_list_row[device_name]-details\" style=\"display: none\"></div>
";
  };
} else if ($menu_desc == "device_details") {
  $device_type_query = "SELECT t1.device_type_name FROM device_type AS t1, devices AS t2 WHERE t2.device_ID = \"$device_ID\" AND t2.device_type_ID = t1.device_type_ID";
  $device_type_result = mysql_query($device_type_query);
  $device_type_row = mysql_fetch_assoc($device_type_result);
  if ($device_type_row["device_type_name"] == "css") {
    print "<span class=\"indent2\"><a class=\"toggleinto-$device_ID-content\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=css_cr&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Content Rules</a></b></span><br />
           <div id =\"$device_ID-content\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-interface\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Interfaces</a></b></span><br />
           <div id =\"$device_ID-interface\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-owner\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=css_owner&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Owners</a></b></span><br />
           <div id =\"$device_ID-owner\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-service\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=css_sv&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Services</a></b></span><br />
           <div id =\"$device_ID-service\" style=\"display: none\"></div>
";
  } else if ($device_type_row["device_type_name"] == "wap") {
    print "<span class=\"indent2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"loadinto-targetArea\" href=\"$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=wap_stats&device_ID=$device_ID\">Stats</a></span><br />
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-interface\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Interfaces</a></b></span><br />
           <div id =\"$device_ID-interface\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-users\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=wap_clients&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Current Users</a></b></span><br />
           <div id =\"$device_ID-users\" style=\"display: none\"></div>
";
  } else if ($device_type_row["device_type_name"] == "vpn concentrator") {
    print "<span class=\"indent2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"loadinto-targetArea\" href=\"$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=vpn_stats&device_ID=$device_ID\">Stats</a></span><br />
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-interface\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Interfaces</a></b></span><br />
           <div id =\"$device_ID-interface\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-users\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=vpn_sessions&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Current Sessions</a></b></span><br />
           <div id =\"$device_ID-users\" style=\"display: none\"></div>
";
  } else if (substr($device_type_row["device_type_name"], 0, 6) == "switch") {
    print "<span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
";
    $switch_blade_query = "SELECT ifname FROM interfaces WHERE device_ID=\"$device_ID\" and record_updated > \"$weekagotimestamp\" ORDER BY ifname";
    $switch_blade_results = mysql_query($switch_blade_query);
    while ($switch_blade_row = mysql_fetch_assoc($switch_blade_results)) {
      $temp_blade = substr($switch_blade_row["ifname"], 0, strpos($switch_blade_row["ifname"], '-'));
      if(empty($temp_blade) or $temp_blade == "0") {
        $temp_blade = substr($switch_blade_row["ifname"], 0, 2);
        //portchannles will be showed as blade po
      } else if (!empty($temp_blade) and $temp_blade != "0") {
        $addtoblade = array_search($temp_blade, $blade);
        if (strlen($addtoblade) < 1) {
          $blade[] = $temp_blade;
          print "<span class=\"indent2\"><a class=\"toggleinto-$device_ID-$temp_blade\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID&temp_blade=$temp_blade\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Blade $temp_blade</a></span><br />
                 <div id=\"$device_ID-$temp_blade\" style=\"display: none\"></div>
";
        };
      };
    };
  } else if ($device_type_row["device_type_name"] == "hp_procurve_switch" || $device_type_row['device_type_name'] == "dd-wrt wap") {
    print "<span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-interface\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Interfaces</a></b></span><br />
           <div id =\"$device_ID-interface\" style=\"display: none\"></div>
";
  } else {
    print "<span class=\"indent2\"><a class=\"toggleinto-$device_ID-cpu\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=cpus&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />CPUs</a></b></span><br />
           <div id =\"$device_ID-cpu\" style=\"display: none\"></div>
           <span class=\"indent2\"><a class=\"toggleinto-$device_ID-interface\" href=\"$ClearsiteBaseURL/include/aloe/aloe_menu_tree.php?location_ID=$location_ID&menu_desc=detail_link&table_search=interfaces&device_ID=$device_ID\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" />Interfaces</a></b></span><br />
           <div id =\"$device_ID-interface\" style=\"display: none\"></div>
";
  };
} else if ($menu_desc == "detail_link") {
  $device_type_query = "SELECT t1.device_type_name FROM device_type AS t1, devices AS t2 WHERE t2.device_ID = \"$device_ID\" and t2.device_type_ID = t1.device_type_ID";
  $device_type_result = mysql_query($device_type_query);
  $device_type_row = mysql_fetch_assoc($device_type_result);
  if ($table_search == "interfaces") {
    $ID_type = "interface_ID";
    if (substr($device_type_row["device_type_name"], 0, 6) == "switch") {
      $select = "interface_ID, ifname";
      $where = " and ifname LIKE \"$temp_blade%\" and ifoperstatus = \"up\"";
      $oby = "ifname";
      $timeframe = $weekagotimestamp;
    } else if ($device_type_row["device_type_name"] == "css" or $device_type_row["device_type_name"] == "pix" or $device_type_row["device_type_name"] == "vpn concentrator") {
      $select = "interface_ID, ifdescr";
      $where = " and ifoperstatus = \"up\"";
      $oby = "ifdescr";
      $timeframe = $weekagotimestamp;
    } else if ($device_type_row['device_type_name'] == "dd-wrt wap") {
      $select = "interface_ID, ifindex";
      $where = " and ifoperstatus = \"up\"";
      $oby = "ifindex";
      $timeframe = $weekagotimestamp;
    } else {
      $select = "interface_ID, ifname";
      $where = " and ifoperstatus = \"up\"";
      $oby = "ifname";
      $timeframe = $weekagotimestamp;
    };
  } else if ($table_search == "cpus") {
    $select = "cpu_ID, cpu_name";
    $where = "";
    $oby = "cpu_name";
    $ID_type = "cpu_ID";
    $timeframe = $weekagotimestamp;
  } else if ($table_search == "css_cr") {
    $select = "cr_ID, cr_name";
    $where = "";
    $oby = "cr_name";
    $ID_type = "cr_ID";
    $timeframe = $weekagotimestamp;
  } else if ($table_search == "css_owner") {
    $select = "owner_ID, owner_name";
    $where = "";
    $oby = "owner_name";
    $ID_type = "owner_ID";
    $timeframe = $weekagotimestamp;
  } else if ($table_search == "css_sv") {
    $select = "sv_ID, sv_name";
    $where = "";
    $oby = "sv_name";
    $ID_type = "sv_ID";
    $timeframe = $weekagotimestamp;
  } else if ($table_search == "wap_clients") {
    $select = "client_ID, client_name";
    $where = "";
    $oby = "client_name";
    $ID_type = "client_ID";
    $timeframe = $tenminagotimestamp;
  } else if ($table_search == "vpn_sessions") {
    $select = "session_ID, username";
    $where = "";
    $oby = "username";
    $ID_type = "session_ID";
    $timeframe = $tenminagotimestamp;
  };
  $detail_query = "SELECT $select FROM $table_search WHERE device_ID=\"$device_ID\" and record_updated > \"$timeframe\"$where ORDER BY $oby";
  $detail_results = mysql_query($detail_query);
  while ($detail_row = mysql_fetch_array($detail_results)) {
    $detail_ID   = $detail_row[0];
    if (empty($detail_row[1]) and $table_search == "cpus") {
      $detail_name = "CPU 1";
    } else {
      // Remove "PIX-Firewall-" from the begining of PIX interfaces, just to save space in drop down menu
      if (substr($detail_row[1], 0, 13) == "PIX-Firewall-") {
        $detail_row[1] = substr($detail_row[1], 13);
      };
      $detail_name = $detail_row[1];
    };
    if (substr($device_type_row["device_type_name"], 0, 6) == "switch" or $device_type_row["device_type_name"] == "router" or $device_type_row["device_type_name"] == "vpn concentrator") {
      $detail_name_view = str_replace("-", "/", $detail_name);
    } else {
      $detail_name_view = $detail_name;
    };
    print "<span class=\"indent3\"><a class=\"loadinto-targetArea\" href=\"$ClearsiteBaseURL/include/aloe/aloe_details.php?$ID_type=$detail_ID&interface_type=$table_search\">$detail_name_view</a></span><br />
";
  };
};

mysql_close();

?>
Return current item: Network Managment / Inventory System