1<?php 2 3/** 4 * Script to display IP address info 5 ***********************************************/ 6 7# get IP and subnet details (for subnet request) 8if(!isset($address)) { 9 $address = (array) $Addresses-> fetch_address(null, $_GET['subnetId']); 10 $subnet = (array) $Subnets->fetch_subnet(null, $address['subnetId']); 11} 12 13# fetch all custom fields 14$custom_fields = $Tools->fetch_custom_fields ('ipaddresses'); 15 16# set selected address fields array 17$selected_ip_fields = $settings->IPfilter; 18$selected_ip_fields = explode(";", $selected_ip_fields); //format to array 19$selected_ip_fields_size = in_array('state', $selected_ip_fields) ? (sizeof($selected_ip_fields)-1) : sizeof($selected_ip_fields); //set size of selected fields 20if($selected_ip_fields_size==1 && strlen($selected_ip_fields[0])==0) { $selected_ip_fields_size = 0; } //fix for 0 21 22 23# set ping statuses 24$statuses = explode(";", $settings->pingStatus); 25 26# checks 27if(sizeof($subnet)==0) { $Result->show("danger", _('Subnet does not exist'), true); } //subnet doesnt exist 28 29 # resolve dns name 30$DNS = new DNS ($Database); 31$resolve = $DNS->resolve_address($address['ip_addr'], $address['hostname'], false, $subnet['nameserverId']); 32 33# reformat empty fields 34$address = $Addresses->reformat_empty_array_fields($address, "<span class='text-muted'>/</span>"); 35 36#header 37print "<h4>"._('IP address details')."</h4><hr>"; 38 39# back 40if(@$temp_objects[$_GET['section']]->type=="subnets") { 41print "<a class='btn btn-default btn-sm btn-default' href='".create_link("temp_share",$_GET['section'])."'><i class='fa fa-chevron-left'></i> "._('Back to subnet')."</a>"; 42} 43 44# check if it exists, otherwise print error 45if(sizeof($address)>1) { 46 47 # table - details 48 print "<table class='ipaddress_subnet table table-noborder table-condensed' style='margin-top:10px;'>"; 49 50 # ip 51 print "<tr>"; 52 print " <th>"._('IP address')."</th>"; 53 print " <td><strong>$address[ip]</strong></td>"; 54 print "</tr>"; 55 56 # description 57 print "<tr>"; 58 print " <th>"._('Description')."</th>"; 59 print " <td>$address[description]</td>"; 60 print "</tr>"; 61 62 # hierarchy 63 print "<tr>"; 64 print " <th>"._('Hierarchy')."</th>"; 65 print " <td>"; 66 $Sections->print_breadcrumbs($Sections, $Subnets, array("page"=>"subnets", "section"=>$subnet['sectionId'], "subnetId"=>$subnet['id'], "ipaddrid"=>$address['id']), $Addresses); 67 print "</td>"; 68 print "</tr>"; 69 70 # subnet 71 print "<tr>"; 72 print " <th>"._('Subnet')."</th>"; 73 print " <td>$subnet[ip]/$subnet[mask] ($subnet[description])</td>"; 74 print "</tr>"; 75 76 # state 77 print "<tr>"; 78 print " <th>"._('IP status')."</th>"; 79 print " <td>"; 80 81 if ($address['state'] == "0") { $stateClass = _("Offline"); } 82 else if ($address['state'] == "2") { $stateClass = _("Reserved"); } 83 else if ($address['state'] == "3") { $stateClass = _("DHCP"); } 84 else { $stateClass = _("Online"); } 85 86 print $Addresses->address_type_index_to_type ($address['state']); 87 print $Addresses->address_type_format_tag ($address['state']); 88 89 print " </td>"; 90 print "</tr>"; 91 92 # hostname 93 print "<tr>"; 94 print " <th>"._('Hostname')."</th>"; 95 print " <td>$resolve[name]</td>"; 96 print "</tr>"; 97 98 # mac 99 if(in_array('owner', $selected_ip_fields)) { 100 print "<tr>"; 101 print " <th>"._('Owner')."</th>"; 102 print " <td>$address[owner]</td>"; 103 print "</tr>"; 104 } 105 106 # mac 107 if(in_array('mac', $selected_ip_fields)) { 108 print "<tr>"; 109 print " <th>"._('MAC address')."</th>"; 110 print " <td>$address[mac]</td>"; 111 print "</tr>"; 112 } 113 114 # note 115 if(in_array('note', $selected_ip_fields)) { 116 print "<tr>"; 117 print " <th>"._('Note')."</th>"; 118 print " <td>$address[note]</td>"; 119 print "</tr>"; 120 } 121 122 # switch 123 if(in_array('switch', $selected_ip_fields)) { 124 print "<tr>"; 125 print " <th>"._('Device')."</th>"; 126 if(strlen($address['switch'])>0) { 127 # get device 128 $device = $Tools->fetch_object("devices", "id", $address['switch']); 129 if($device!==false) { 130 $device = (array) $device; 131 $device = $Addresses->reformat_empty_array_fields($device, ""); 132 print " <td>".@$device['hostname']." ".@$device['description']."</td>"; 133 } 134 else { 135 print " <td><span class='text-muted'>/</span></td>"; 136 } 137 } else { 138 print " <td><span class='text-muted'>/</span></td>"; 139 } 140 print "</tr>"; 141 } 142 143 # port 144 if(in_array('port', $selected_ip_fields)) { 145 print "<tr>"; 146 print " <th>"._('Port')."</th>"; 147 print " <td>$address[port]</td>"; 148 print "</tr>"; 149 } 150 151 # last edited 152 print "<tr>"; 153 print " <th>"._('Last edited')."</th>"; 154 if(strlen($address['editDate'])>1) { 155 print " <td>$address[editDate]</td>"; 156 } else { 157 print " <td>"._('Never')."</td>"; 158 } 159 print "</tr>"; 160 161 162 # availability 163 print "<tr>"; 164 print " <td colspan='2'><hr></td>"; 165 print "</tr>"; 166 print "<tr>"; 167 168 # calculate 169 $tDiff = time() - strtotime($address['lastSeen']); 170 if($address['excludePing']==1) { $seen_status = ""; $seen_text = ""; } 171 elseif($tDiff < $statuses[0]) { $seen_status = "success"; $seen_text = _("Device is alive")."<br>"._("Last seen").": ".$address['lastSeen']; } 172 elseif($tDiff < $statuses[1]) { $seen_status = "warning"; $seen_text = _("Device warning")."<br>"._("Last seen").": ".$address['lastSeen']; } 173 elseif($tDiff > $statuses[1]) { $seen_status = "error"; $seen_text = _("Device is offline")."<br>"._("Last seen").": ".$address['lastSeen'];} 174 elseif($address['lastSeen'] == "0000-00-00 00:00:00") { $seen_status = "neutral"; $seen_text = _("Device is offline")."<br>"._("Last seen").": "._("Never");} 175 elseif($address['lastSeen'] == "1970-01-01 00:00:01") { $seen_status = "neutral"; $seen_text = _("Device is offline")."<br>"._("Last seen").": "._("Never");} 176 else { $seen_status = "neutral"; $seen_text = _("Device status unknown");} 177 178 print " <th>"._('Availability')."<br><span class='status status-ip status-$seen_status' style='pull-right'></span></th>"; 179 print " <td>"; 180 print "$seen_text"; 181 182 print " </td>"; 183 print "</tr>"; 184 185 # custom fields 186 if(sizeof($custom_fields) > 0) { 187 print "<tr>"; 188 print " <td colsapn='2'><hr></td>"; 189 print "</tr>"; 190 191 foreach($custom_fields as $key=>$field) { 192 if(strlen($address[$key])>0) { 193 $address[$key] = str_replace(array("\n", "\r\n"), "<br>",$address[$key]); 194 print "<tr>"; 195 print " <th>$key</th>"; 196 print " <td>"; 197 #booleans 198 if($field['type']=="tinyint(1)") { 199 if($address[$key] == 0) { print _("No"); } 200 elseif($address[$key] == 1) { print _("Yes"); } 201 } 202 else { 203 print $address[$key]; 204 } 205 print " </td>"; 206 print "</tr>"; 207 } 208 } 209 } 210 211 print "</tr>"; 212 print "</table>"; 213} 214# not exisitng 215else { 216 $Result->show("danger", _("IP address not existing in database")."!", true); 217}