@@ -1850,4 +1850,180 @@ public function reformat_number ($number) {
1850
1850
}
1851
1851
return $ number ;
1852
1852
}
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
+
1853
2029
}
0 commit comments