Skip to content

Commit 55bbf27

Browse files
committed
Changed NAT info from popup to popover
1 parent a8ee90d commit 55bbf27

File tree

5 files changed

+192
-6
lines changed

5 files changed

+192
-6
lines changed

app/subnets/addresses/print-address-table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@
344344
print $Addresses->address_type_format_tag($addresses[$n]->state);
345345

346346
# set subnet nat
347-
if(isset($all_nats_per_object['subnets'][$subnet['id']]) || isset($all_nats_per_object['ipaddresses'][$addresses[$n]->id])) { print " <a href='".create_link("subnets", $subnet['sectionId'], $subnet['id'], "address-details", $addresses[$n]->id, "nat")."' class='btn btn-xs btn-info fa fa-exchange' style='font-size:11px;margin-top:-3px;padding:1px 3px;' rel='tooltip' title='"._('Address is Natted')."'></i>"; }
348-
347+
$Addresses->print_nat_link($all_nats, $all_nats_per_object, $subnet, $addresses[$n]);
349348

350349
print $dns_records2."</td>";
351350

app/subnets/subnet-details/subnet-details.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<?php if(@array_key_exists($subnet['id'], $all_nats_per_object['subnets'])) { ?>
118118
<tr>
119119
<th><?php print _('NAT'); ?></th>
120-
<td><a href='<?php print create_link("subnets", $subnet['sectionId'], $subnet['id'], "nat") ?>'><i class='btn btn-xs btn-info fa fa-exchange'></i> <?php print _("Subnet is natted"); ?></a></td>
120+
<td><?php $Addresses->print_nat_link($all_nats, $all_nats_per_object, $subnet, false, "subnet"); ?> <?php print _("Subnet is natted"); ?></a></td>
121121
</tr>
122122
<?php } ?>
123123

css/1.2/bootstrap/bootstrap-custom.css

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
src: local('Source Sans Pro Light'), local('SourceSansPro-Light'), url("../fonts/source_sans_pro/SourceSansPro-Light.woff2") format('woff2');
1111
}
1212

13-
14-
1513
/* @general ---------- */
1614
body {
1715
font-size: 13px;
@@ -105,7 +103,6 @@ table td.stats-badge {
105103
border-radius: 3px;
106104
}
107105

108-
109106
hr {
110107
margin: 5px;
111108
margin-left: 0px;
@@ -2606,4 +2603,16 @@ ul.dropdown-menu li a {
26062603
.navbar ul li.first-item i {
26072604
color: white;
26082605
margin-right: 2px;
2606+
}
2607+
2608+
2609+
2610+
.table.ipaddresses tbody tr:hover td table.popover_table tbody td {
2611+
background: white !important;
2612+
}
2613+
table.popover_table {
2614+
margin: 0px;
2615+
}
2616+
table.popover_table td {
2617+
border: none !important;
26092618
}

functions/classes/class.Addresses.php

+176
Original file line numberDiff line numberDiff line change
@@ -1850,4 +1850,180 @@ public function reformat_number ($number) {
18501850
}
18511851
return $number;
18521852
}
1853+
1854+
1855+
1856+
1857+
1858+
1859+
1860+
1861+
1862+
1863+
/**
1864+
* @nat methods
1865+
* -------------------------------
1866+
*/
1867+
/**
1868+
* Prints nat link
1869+
*
1870+
* @access public
1871+
* @param array $all_nats
1872+
* @param array $all_nats_per_object
1873+
* @param object $subnet
1874+
* @param object $address
1875+
* @param mixed $address
1876+
* @return void
1877+
*/
1878+
public function print_nat_link ($all_nats, $all_nats_per_object, $subnet, $address, $type="ipaddress") {
1879+
// cast
1880+
$subnet = (object) $subnet;
1881+
$address = (object) $address;
1882+
1883+
// cnt
1884+
$html = array();
1885+
$html[] = '<table class="popover_table">';
1886+
1887+
$cnt = 0;
1888+
1889+
// subnets
1890+
if(isset($all_nats_per_object['subnets'][$subnet->id])) {
1891+
foreach ($all_nats_per_object['subnets'][$subnet->id] as $nat) {
1892+
// set object
1893+
$n = $all_nats[$nat];
1894+
// print
1895+
$html[] = str_replace("'", "\"", $this->print_nat_link_line ($n, false, "subnets", $subnet->id));
1896+
}
1897+
$cnt++;
1898+
}
1899+
1900+
// addresses
1901+
if(isset($all_nats_per_object['ipaddresses'][$address->id])) {
1902+
foreach ($all_nats_per_object['ipaddresses'][$address->id] as $nat) {
1903+
// set object
1904+
$n = $all_nats[$nat];
1905+
// print
1906+
$html[] = str_replace("'", "\"", $this->print_nat_link_line ($n, false, "ipaddresses", $address->id));
1907+
$cnt++;
1908+
}
1909+
}
1910+
1911+
// print if some
1912+
if ($cnt>0) {
1913+
$html[] = "</table>";
1914+
if($type=="subnet") {
1915+
print " <a href='".create_link("subnets",$subnet->sectionId, $subnet->id, "nat")."' class='btn btn-xs btn-default show_popover fa fa-exchange' style='font-size:11px;margin-top:-3px;padding:1px 3px;' data-toggle='popover' title='"._('Object is Natted')."' data-trigger='hover' data-html='true' data-content='".implode("\n", $html)."'></a>";
1916+
}
1917+
else {
1918+
print " <a href='".create_link("subnets",$subnet->sectionId, $subnet->id, "address-details", $address->id, "nat")."' class='btn btn-xs btn-default show_popover fa fa-exchange' style='font-size:11px;margin-top:-3px;padding:1px 3px;' data-toggle='popover' title='"._('Object is Natted')."' data-trigger='hover' data-html='true' data-content='".implode("\n", $html)."'></a>";
1919+
}
1920+
}
1921+
}
1922+
1923+
/**
1924+
* Prints single NAT for display in devices, subnets, addresses.
1925+
*
1926+
* @access public
1927+
* @param mixed $n
1928+
* @param bool|int $nat_id (default: false)
1929+
* @param bool|mixed $object_type (default: false)
1930+
* @param bool $object_id (default: false)
1931+
* @return void
1932+
*/
1933+
public function print_nat_link_line ($n, $nat_id = false, $object_type = false, $object_id=false) {
1934+
// cast to object to be sure if array provided
1935+
$n = (object) $n;
1936+
1937+
// translate json to array, links etc
1938+
$sources = $this->translate_nat_objects_for_popup ($n->src, $nat_id, false, $object_type, $object_id);
1939+
$destinations = $this->translate_nat_objects_for_popup ($n->dst, $nat_id, false, $object_type, $object_id);
1940+
1941+
// no src/dst
1942+
if ($sources===false)
1943+
$sources = array("<span class='badge badge1 badge5 alert-danger'>"._("None")."</span>");
1944+
if ($destinations===false)
1945+
$destinations = array("<span class='badge badge1 badge5 alert-danger'>"._("None")."</span>");
1946+
1947+
1948+
// icon
1949+
$icon = $n->type=="static" ? "fa-arrows-h" : "fa-long-arrow-right";
1950+
1951+
// to html
1952+
$html = array();
1953+
$html[] = "<tr>";
1954+
$html[] = "<td colspan='3'>";
1955+
$html[] = "<strong>$n->name</strong> <span class='badge badge1 badge5'>".ucwords($n->type)."</span>";
1956+
$html[] = "</td>";
1957+
$html[] = "</tr>";
1958+
1959+
// append ports
1960+
if(($n->type=="static" || $n->type=="destination") && (strlen($n->src_port)>0 && strlen($n->dst_port)>0)) {
1961+
$sources = implode("<br>", $sources)." /".$n->src_port;
1962+
$destinations = implode("<br>", $destinations)." /".$n->dst_port;
1963+
}
1964+
else {
1965+
$sources = implode("<br>", $sources);
1966+
$destinations = implode("<br>", $destinations);
1967+
}
1968+
1969+
$html[] = "<tr>";
1970+
$html[] = "<td>$sources</td>";
1971+
$html[] = "<td><i class='fa $icon'></i></td>";
1972+
$html[] = "<td>$destinations</td>";
1973+
$html[] = "</tr>";
1974+
$html[] = "<tr><td colspan='3' style='padding-top:20px;'></td></tr>";
1975+
1976+
$html[] = "<tr>";
1977+
$html[] = "<td colspan='3'><hr></td>";
1978+
$html[] = "</tr>";
1979+
1980+
// return
1981+
return implode("\n", $html);
1982+
}
1983+
1984+
/**
1985+
* Translates NAT objects to be shown on page
1986+
*
1987+
* @access public
1988+
* @param json $json_objects
1989+
* @param int|bool $nat_id (default: false)
1990+
* @param bool $json_objects (default: false)
1991+
* @param bool $object_type (default: false) - to bold it (ipaddresses / subnets)
1992+
* @param int|bool object_id (default: false) - to bold it
1993+
* @return void
1994+
*/
1995+
public function translate_nat_objects_for_popup ($json_objects, $nat_id = false, $admin = false, $object_type = false, $object_id=false) {
1996+
// to array "subnets"=>array(1,2,3)
1997+
$objects = json_decode($json_objects, true);
1998+
// init out array
1999+
$out = array();
2000+
// check
2001+
if(is_array($objects)) {
2002+
if(sizeof($objects)>0) {
2003+
foreach ($objects as $ot=>$ids) {
2004+
if (sizeof($ids)>0) {
2005+
foreach ($ids as $id) {
2006+
// fetch
2007+
$item = $this->fetch_object($ot, "id", $id);
2008+
if($item!==false) {
2009+
// bold
2010+
$bold = $item->id==$object_id && $ot==$object_type ? "<span class='strong'>" : "<span>";
2011+
// subnets
2012+
if ($ot=="subnets") {
2013+
$out[] = "$bold".$this->transform_address($item->subnet, "dotted")."/".$item->mask."</span></span>";
2014+
}
2015+
// addresses
2016+
else {
2017+
$out[] = "$bold".$this->transform_address($item->ip_addr, "dotted")."</span>";
2018+
}
2019+
}
2020+
}
2021+
}
2022+
}
2023+
}
2024+
}
2025+
// result
2026+
return sizeof($out)>0 ? $out : false;
2027+
}
2028+
18532029
}

js/1.2/magic.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ $(document).on("submit", ".searchFormClass", function() {
2424
return false;
2525
});
2626

27+
$('.show_popover').popover();
28+
2729

2830
/* this functions opens popup */
2931
/* -------------------------- */

0 commit comments

Comments
 (0)