diff --git a/html/.htaccess b/html/.htaccess index b128dcd77b..4cc1bdaf94 100644 --- a/html/.htaccess +++ b/html/.htaccess @@ -43,5 +43,7 @@ RewriteRule ^device/([0-9]+) ?page=device&id=$1 RewriteRule ^([a-z|0-9\-]+)/$ ?page=$1 +RewriteRule ^([a-z|0-9]+)/(.+)/(.+)/(.+)/$ ?page=$1&opta=$2&optb=$3&optc=$4 +RewriteRule ^([a-z|0-9]+)/(.+)/(.+)/$ ?page=$1&opta=$2&optb=$3 RewriteRule ^([a-z|0-9]+)/(.+)/$ ?page=$1&opta=$2 diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index cc476545df..40484ece90 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -13,6 +13,37 @@ function permissions_cache($user_id) { return $permissions; } +function interfacepermitted($interface_id, $device_id = NULL) +{ + global $_SESSION; global $permissions; + if(!$device_id) { $device_id = mysql_result(mysql_query("SELECT `device_id` from ports WHERE interface_id = '".$interface_id."'"),0); } + if ($_SESSION['userlevel'] >= "5") { + $allowed = TRUE; + } elseif ( devicepermitted($device_id)) { + $allowed = TRUE; + } elseif ( $permissions['port'][$interface_id]) { + $allowed = TRUE; + } else { + $allowed = FALSE; + } + return $allowed; +} + +function devicepermitted($device_id) +{ + global $_SESSION; global $permissions; + if ($_SESSION['userlevel'] >= "5") { + $allowed = true; + } elseif ( $permissions['device'][$device_id] ) { + $allowed = true; + } else { + $allowed = false; + } + return $allowed; + +} + + function print_graph_tag ($args) { echo generate_graph_tag ($args); diff --git a/html/index.php b/html/index.php index 3f6e3df8cd..0dbaa6a599 100755 --- a/html/index.php +++ b/html/index.php @@ -18,6 +18,7 @@ if($debug) { include("includes/functions.inc.php"); include("includes/authenticate.inc.php"); if($_SESSION['authenticated']) { + # Load permissions used my devicepermitted() and interfacepermitted() $permissions = permissions_cache($_SESSION['user_id']); } diff --git a/html/pages/ports.php b/html/pages/ports.php index aefb0c403f..ac4f986850 100644 --- a/html/pages/ports.php +++ b/html/pages/ports.php @@ -1,162 +1,10 @@ - - - - - - - - - - - - -
- - - - - - - - - - Deleted > - - -
- - - - - = '5') { -# $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ORDER BY D.hostname, I.ifDescr"; -#} else { -# $sql = "SELECT * FROM `ports` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr"; -#} +#print_r($_GET); +$file = $config['install_dir'] . "/html/pages/ports/" . safename($_GET['opta']) . ".inc.php"; -if($_GET['opta'] == "down" || $_GET['type'] == "down" || $_POST['state'] == "down") { - $where .= "AND I.ifAdminStatus = 'up' AND I.ifOperStatus = 'down' AND I.ignore = '0'"; -} elseif ($_GET['opta'] == "admindown" || $_GET['type'] == "admindown" || $_POST['state'] == "admindown") { - $where .= "AND I.ifAdminStatus = 'down'"; -} elseif ($_GET['opta'] == "errors" || $_GET['type'] == "errors" || $_POST['state'] == "errors") { - $where .= "AND ( I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0' )"; -} elseif ($_GET['type'] == "up" || $_POST['state'] == "up") { - $where .= "AND I.ifOperStatus = 'up'"; -} elseif ($_GET['opta'] == "ignored" || $_GET['type'] == "ignored" || $_POST['state'] == "ignored") { - $where .= "AND I.ignore = '1'"; -} elseif ($_GET['type'] == "l2vlan" || $_POST['state'] == "l2vlan") { - $where .= " AND I.ifType = 'l2vlan'"; -} elseif ($_GET['type'] == "ethernet" || $_POST['state'] == "ethernet") { - $where .= " AND I.ifType = 'ethernetCsmacd'"; -} elseif ($_GET['type'] == "loopback" || $_POST['state'] == "loopback") { - $where .= " AND I.ifType = 'softwareLoopback'"; -} elseif ($_GET['typee'] == "sonet" || $_POST['state'] == "sonet") { - $where .= " AND I.ifType = 'sonet'"; -} elseif ($_POST['state'] == "propvirtual") { - $where .= " AND I.ifType = 'propVirtual'"; -} elseif ($_POST['state'] == "ppp") { - $where .= " AND I.ifType = 'ppp'"; -} - - - -if($_POST['device_id']) { $where .= " AND I.device_id = '".$_POST['device_id']."'"; } -if($_POST['ifType']) { $where .= " AND I.ifType = '".$_POST['ifType']."'"; } -if($_POST['ifSpeed']) { $where .= " AND I.ifSpeed = '".$_POST['ifSpeed']."'"; } -if($_POST['ifAlias']) { $where .= " AND I.ifAlias LIKE '%".$_POST['ifAlias']."%'"; } -if($_POST['deleted'] || $_GET['type'] == "deleted") { $where .= " AND I.deleted = '1'"; } - -$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where ORDER BY D.hostname, I.ifIndex"; - -$query = mysql_query($sql); - -echo(""); - -$row = 1; - -while($interface = mysql_fetch_array($query)) { - - if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - - $speed = humanspeed($interface['ifSpeed']); - $type = humanmedia($interface['ifType']); - - if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { - $error_img = generateiflink($interface,"Interface Errors",errors); - } else { $error_img = ""; } - - if( interfacepermitted($interface['interface_id']) ) - { - echo(" - - - - - - - \n"); - - $row++; - - } - -} - -echo("
DeviceInterfaceSpeedMediaDescription
" . generatedevicelink($interface) . "" . generateiflink($interface, makeshortif(fixifname($interface['ifDescr']))) . " $error_img$speed$type" . $interface['ifAlias'] . "
"); +if(is_file($file)) { include($file); } else { include("ports/default.inc.php"); } ?> - diff --git a/html/pages/ports/default.inc.php b/html/pages/ports/default.inc.php new file mode 100644 index 0000000000..185a9980ea --- /dev/null +++ b/html/pages/ports/default.inc.php @@ -0,0 +1,163 @@ + + + + + + + + + + + + +
+ + + + + + + + + + Deleted > + + +
+ + + + + += '5') { +# $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ORDER BY D.hostname, I.ifDescr"; +#} else { +# $sql = "SELECT * FROM `ports` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr"; +#} + + +if($_GET['opta'] == "down" || $_GET['type'] == "down" || $_POST['state'] == "down") { + $where .= "AND I.ifAdminStatus = 'up' AND I.ifOperStatus = 'down' AND I.ignore = '0'"; +} elseif ($_GET['opta'] == "admindown" || $_GET['type'] == "admindown" || $_POST['state'] == "admindown") { + $where .= "AND I.ifAdminStatus = 'down'"; +} elseif ($_GET['opta'] == "errors" || $_GET['type'] == "errors" || $_POST['state'] == "errors") { + $where .= "AND ( I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0' )"; +} elseif ($_GET['type'] == "up" || $_POST['state'] == "up") { + $where .= "AND I.ifOperStatus = 'up'"; +} elseif ($_GET['opta'] == "ignored" || $_GET['type'] == "ignored" || $_POST['state'] == "ignored") { + $where .= "AND I.ignore = '1'"; +} elseif ($_GET['type'] == "l2vlan" || $_POST['state'] == "l2vlan") { + $where .= " AND I.ifType = 'l2vlan'"; +} elseif ($_GET['type'] == "ethernet" || $_POST['state'] == "ethernet") { + $where .= " AND I.ifType = 'ethernetCsmacd'"; +} elseif ($_GET['type'] == "loopback" || $_POST['state'] == "loopback") { + $where .= " AND I.ifType = 'softwareLoopback'"; +} elseif ($_GET['typee'] == "sonet" || $_POST['state'] == "sonet") { + $where .= " AND I.ifType = 'sonet'"; +} elseif ($_POST['state'] == "propvirtual") { + $where .= " AND I.ifType = 'propVirtual'"; +} elseif ($_POST['state'] == "ppp") { + $where .= " AND I.ifType = 'ppp'"; +} + + + +if($_POST['device_id']) { $where .= " AND I.device_id = '".$_POST['device_id']."'"; } +if($_POST['ifType']) { $where .= " AND I.ifType = '".$_POST['ifType']."'"; } +if($_POST['ifSpeed']) { $where .= " AND I.ifSpeed = '".$_POST['ifSpeed']."'"; } +if($_POST['ifAlias']) { $where .= " AND I.ifAlias LIKE '%".$_POST['ifAlias']."%'"; } +if($_POST['deleted'] || $_GET['type'] == "deleted") { $where .= " AND I.deleted = '1'"; } + +$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where ORDER BY D.hostname, I.ifIndex"; + +$query = mysql_query($sql); + +echo(""); + +$row = 1; + +while($interface = mysql_fetch_array($query)) { + + if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + $speed = humanspeed($interface['ifSpeed']); + $type = humanmedia($interface['ifType']); + + if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { + $error_img = generateiflink($interface,"Interface Errors",errors); + } else { $error_img = ""; } + + if( interfacepermitted($interface['interface_id'], $interface['device_id']) ) + { + $interface = ifLabel($interface, $device); + echo(" + + + + + + + \n"); + + $row++; + + } + +} + +echo("
DeviceInterfaceSpeedMediaDescription
" . generatedevicelink($interface) . "" . generateiflink($interface) . " $error_img$speed$type" . $interface['ifAlias'] . "
"); + + +?> + diff --git a/html/pages/ports/deleted.inc.php b/html/pages/ports/deleted.inc.php new file mode 100644 index 0000000000..bc16671fde --- /dev/null +++ b/html/pages/ports/deleted.inc.php @@ -0,0 +1,48 @@ +Deleted ".generatedevicelink($interface)." - ".generateiflink($interface).""); } + } + } +} elseif($_GET['optb'] == "purge" && $_GET['optc']) { + $interface = mysql_fetch_assoc(mysql_query("SELECT * from `ports` AS P, `devices` AS D WHERE `interface_id` = '".mres($_GET['optc'])."' AND D.device_id = P.device_id")); + if(interfacepermitted($interface['interface_id'], $interface['device_id'])) + mysql_query("DELETE FROM `ports` WHERE `interface_id` = '".mres($_GET['optc'])."' AND `deleted` = '1'"); + if(mysql_affected_rows()) { echo("
Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."
"); } +} + + + +$i_deleted = 1; + + +echo(""); +echo(""); + +$sql = "SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id"; +$query = mysql_query($sql); +while($interface = mysql_fetch_assoc($query)) { + $interface = ifLabel($interface, $interface); + if(interfacepermitted($interface['interface_id'], $interface['device_id'])){ + if(is_integer($i_deleted/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + + $i_deleted++; + } +} + +echo("
Purge All
".generatedevicelink($interface)."".generateiflink($interface)." Purge
"); + + +?> diff --git a/includes/functions.php b/includes/functions.php index e7d1098d27..e37b47916b 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -139,36 +139,6 @@ function billpermitted($bill_id) return $allowed; } - -function interfacepermitted($interface_id) -{ - global $_SESSION; - if ($_SESSION['userlevel'] >= "5") { - $allowed = TRUE; - } elseif ( devicepermitted(mysql_result(mysql_query("SELECT `device_id` FROM `ports` WHERE `interface_id` = '$interface_id'"),0))) { - $allowed = TRUE; - } elseif ( @mysql_result(mysql_query("SELECT `interface_id` FROM `ports_perms` WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `interface_id` = $interface_id"), 0)) { - $allowed = TRUE; - } else { - $allowed = FALSE; - } - return $allowed; -} - -function devicepermitted($device_id) -{ - global $_SESSION; - if ($_SESSION['userlevel'] >= "5") { - $allowed = true; - } elseif ( @mysql_result(mysql_query("SELECT * FROM devices_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `device_id` = $device_id"), 0) > '0' ) { - $allowed = true; - } else { - $allowed = false; - } - return $allowed; - -} - function formatRates($rate) { $rate = format_si($rate) . "bps"; return $rate; diff --git a/includes/rewrites.php b/includes/rewrites.php index b4debe0f8a..95100007c8 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -23,6 +23,11 @@ function ifLabel ($interface, $device = NULL) { $interface['label'] = $interface['ifDescr']; if(isset($config['appendifindex'][$os])) { $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; } } + + if($device['os'] == "speedtouch") { + list($interface['label']) = explode("thomson", $interface['label']); + } + return $interface; }