From 3f0ad0360ed7d669f7b4dabf7769d52e73bf349b Mon Sep 17 00:00:00 2001 From: crcro Date: Sun, 24 Dec 2017 21:58:59 +0200 Subject: [PATCH] webui: Ports table refresh (#7827) * initial release * removed duplicate div tag * deleted ports reworks * more header optimizations, added status entries * more header optimizations, added status entries * added purge all, testing needed, try once again to fix overflowing filtering bar * fix purge all, another try to break option bar in two for longer inputs * fix indentation --- html/includes/print-menubar.php | 2 +- html/includes/table/ports.inc.php | 38 ++- html/pages/deleted-ports.inc.php | 37 --- html/pages/ports.inc.php | 474 ++++++++++++++++-------------- html/pages/ports/list.inc.php | 68 +++-- 5 files changed, 339 insertions(+), 280 deletions(-) delete mode 100644 html/pages/deleted-ports.inc.php diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 9249c045bb..a98664a442 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -346,7 +346,7 @@ foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`delete Deleted ('.$deleted_ports.')'); + echo('
  • Deleted ('.$deleted_ports.')
  • '); } ?> diff --git a/html/includes/table/ports.inc.php b/html/includes/table/ports.inc.php index 9f7a58dfa5..33392c5d31 100644 --- a/html/includes/table/ports.inc.php +++ b/html/includes/table/ports.inc.php @@ -141,21 +141,47 @@ foreach (dbFetchRows($query, $param) as $port) { $device = device_by_id_cache($port['device_id']); $port = cleanPort($port, $device); + switch ($port['ifOperStatus']) { + case 'up': + $status = ' '; + break; + case 'down': + switch ($port['ifAdminStatus']) { + case 'up': + $status = ' '; + break; + case 'down': + $status = ' '; + break; + } + break; + } + // FIXME what actions should we have? $actions = '
    '; - $actions .= '
    '; - if ($_SESSION['userlevel'] >= '7') { + if ($_POST['deleted'] !== 'yes') { $actions .= '
    '; + $actions .= generate_device_url($device, array('tab' => 'alerts')); + $actions .= '" title="View alerts">
    '; + + if ($_SESSION['userlevel'] >= '7') { + $actions .= '
    '; + } + } + + if ($_POST['deleted'] === 'yes') { + if (port_permitted($port['port_id'], $device['device_id'])) { + $actions .= '
    '; + } } $actions .= '
    '; $response[] = array( + 'status' => $status, 'device' => generate_device_link($device), 'port' => generate_port_link($port), 'ifLastChange' => ceil($port['secondsIfLastChange']), diff --git a/html/pages/deleted-ports.inc.php b/html/pages/deleted-ports.inc.php deleted file mode 100644 index 86a7cf105e..0000000000 --- a/html/pages/deleted-ports.inc.php +++ /dev/null @@ -1,37 +0,0 @@ -Deleted '.generate_device_link($interface).' - '.generate_port_link($interface).''; - } - } -} elseif ($vars['purge']) { - $interface = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge'])); - $interface = cleanPort($interface); - if (port_permitted($interface['port_id'], $interface['device_id'])) { - delete_port($interface['port_id']); - } - - echo '
    Deleted '.generate_device_link($interface).' - '.generate_port_link($interface).'
    '; -} - -echo ''; -echo ""; - -foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id", array()) as $interface) { - $interface = cleanPort($interface, $interface); - if (port_permitted($interface['port_id'], $interface['device_id'])) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ""; - } -} - -echo '
    DevicePort Purge All
    '.generate_device_link($interface).''.generate_port_link($interface).' Purge
    '; diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index 83b376eedc..b6a52405a6 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -1,4 +1,17 @@ Lists » '); +$displayLists = ''; +$displayLists .= 'Ports lists » '; $menu_options = array('basic' => 'Basic', 'detail' => 'Detail'); $sep = ""; foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == "list_".$option) { - echo(""); + $displayLists .= $sep; + if ($vars['format'] == "list_" . $option) { + $displayLists .= ''; } - echo('' . $text . ''); - if ($vars['format'] == "list_".$option) { - echo(""); + $displayLists .= '' . $text . ''; + if ($vars['format'] == "list_" . $option) { + $displayLists .= ''; } $sep = " | "; } -?> - - | - -Graphs » - -Graphs »'; $menu_options = array('bits' => 'Bits', 'upkts' => 'Unicast Packets', @@ -41,235 +47,250 @@ $menu_options = array('bits' => 'Bits', $sep = ""; foreach ($menu_options as $option => $text) { - echo($sep); - if ($vars['format'] == 'graph_'.$option) { - echo(''); + $displayLists .= $sep; + if ($vars['format'] == 'graph_' . $option) { + $displayLists .= ''; } - echo('' . $text . ''); - if ($vars['format'] == 'graph_'.$option) { - echo(""); + $displayLists .= '' . $text . ''; + if ($vars['format'] == 'graph_' . $option) { + $displayLists .= ''; } $sep = " | "; } -echo('
    '); -?> +$displayLists .= '
    '; +$displayLists .= 'Export CSV | Update URL'; - Export CSV | - Update URL | - - '')).'">Search'); + $displayLists .= 'Search'; } else { - echo('Search'); + $displayLists .= 'Search'; } -echo(" | "); +$displayLists .= ' | '; if (isset($vars['bare']) && $vars['bare'] == "yes") { - echo('Header'); + $displayLists .= 'Header'; } else { - echo('Header'); + $displayLists .= 'Header'; } -echo('
    '); +$displayLists .= ' | '; +$displayLists .= 'Bulk actions »'; -print_optionbar_end(); -print_optionbar_start(); +$displayLists .= ' Purge all deleted'; + +$displayLists .= '
    '; if ((isset($vars['searchbar']) && $vars['searchbar'] != "hide") || !isset($vars['searchbar'])) { -?> -
    -
    - - placeholder="Hostname"/> -
    -
    - - - -
    -
    - - "; + $output .= ""; + $output .= ""; + $output .= ""; + $output .= ""; + $output .= " "; + + $output .= " -
    -
    - placeholder="Port Description"/> - "; + $output .= ""; + + if (is_admin() === true || is_read() === true) { + $sql = "SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`"; + } else { + $sql = "SELECT `ifType` FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` GROUP BY `ifType` ORDER BY `ifType`"; + $param[] = array($_SESSION['user_id'], $_SESSION['user_id']); + } + + foreach (dbFetchRows($sql, $param) as $data) { + if ($data['ifType']) { + if ($data['ifType'] == $vars['ifType']) { + $dataselected = "selected"; + } else { + $dataselected = ""; + } + $output .= ""; } - echo(">".$location.""); } -} - ?> - -
    -
    - - > - - > - - > -
    - - Reset -
    - "; + $output .= " "; + $output .= ""; + $output .= "
    "; + + if (strlen($vars['ifAlias'])) { + $ifaliasvalue = "value='" . $vars['ifAlias'] . "'"; + } + + $output .= "
    "; + + $output .= ""; + $output .= "
    "; + + $output .= " "; + $output .= " "; + + if ($vars['ignore']) { + $ignorecheck = "checked"; + } else { + $ignorecheck = ""; + } + + if ($vars['disabled']) { + $disabledcheck = "checked"; + } else { + $disabledcheck = ""; + } + + if ($vars['deleted']) { + $deletedcheck = "checked"; + } else { + $deletedcheck = ""; + } + + $output .= " "; + $output .= " "; + $output .= " "; + $output .= " "; + $output .= " "; + $output .= " "; + + $output .= " "; + $output .= " 'ports', 'section' => $vars['section'], 'bare' => $vars['bare'])) . "' title='Reset critera to default.'>Reset"; + + $output .= "
    "; + + $output .= ""; + $output .= ""; +} $param = array(); @@ -292,11 +313,11 @@ foreach ($vars as $var => $value) { switch ($var) { case 'hostname': $where .= " AND D.hostname LIKE ?"; - $param[] = "%".$value."%"; + $param[] = "%" . $value . "%"; break; case 'location': $where .= " AND D.location LIKE ?"; - $param[] = "%".$value."%"; + $param[] = "%" . $value . "%"; break; case 'device_id': $where .= " AND D.device_id = ?"; @@ -333,7 +354,7 @@ foreach ($vars as $var => $value) { case 'ifAlias': case 'port_descr_type': $where .= " AND I.$var LIKE ?"; - $param[] = "%".$value."%"; + $param[] = "%" . $value . "%"; break; case 'errors': if ($value == 1) { @@ -354,6 +375,23 @@ foreach ($vars as $var => $value) { $param[] = "down"; } break; + case 'purge': + if ($vars['purge'] === 'all') { + $interfaces = dbFetchRows('SELECT * from `ports` AS P, `devices` AS D WHERE `deleted` = 1 AND D.device_id = P.device_id'); + foreach ($interfaces as $interface) { + $interface = cleanPort($interface); + if (port_permitted($interface['port_id'], $interface['device_id'])) { + delete_port($interface['port_id']); + } + } + } else { + $interface = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge'])); + $interface = cleanPort($interface); + if (port_permitted($interface['port_id'], $interface['device_id'])) { + delete_port($interface['port_id']); + } + } + break; } } } @@ -362,7 +400,7 @@ if ($ignore_filter == 0 && $disabled_filter == 0) { $where .= " AND `I`.`ignore` = 0 AND `I`.`disabled` = 0 AND `I`.`deleted` = 0"; } -$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort; +$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id " . $where . " " . $query_sort; $row = 1; @@ -409,8 +447,6 @@ switch ($vars['sort']) { $ports = array_sort($ports, 'hostname', SORT_ASC); } -if (file_exists('pages/ports/'.$format.'.inc.php')) { - require 'pages/ports/'.$format.'.inc.php'; +if (file_exists('pages/ports/' . $format . '.inc.php')) { + require 'pages/ports/' . $format . '.inc.php'; } - -?> diff --git a/html/pages/ports/list.inc.php b/html/pages/ports/list.inc.php index 68edc51287..cec59446b9 100644 --- a/html/pages/ports/list.inc.php +++ b/html/pages/ports/list.inc.php @@ -1,4 +1,18 @@
    +
    + +
    - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
    Device>PortStatus ChangedConnectedSpeedMTUDownUpPackets InPackets Out>Errors InErrors OutMediaDescriptionActions
    Device>PortStatus ChangedConnectedSpeedMTUDown + Up + + Packets In + + Packets Out + >Errors In + Errors Out + MediaDescriptionActions
    @@ -88,4 +120,6 @@ var grid = $("#ports").bootgrid({ url: "ajax_table.php" }); +$(".actionBar").append(""); +