Commit ab03d32f authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) move get_interface_info

parent 92a5f77a
......@@ -5066,3 +5066,246 @@ function get_failover_interface($interface, $family = "all") {
/* XXX: Really needed? */
return get_real_interface($interface, $family);
}
//returns interface information
function get_interface_info($ifdescr)
{
global $config;
$ifinfo = array();
if (empty($config['interfaces'][$ifdescr]))
return;
$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
$ifinfo['if'] = get_real_interface($ifdescr);
$chkif = $ifinfo['if'];
$ifinfotmp = pfSense_get_interface_addresses($chkif);
$ifinfo['status'] = $ifinfotmp['status'];
if (empty($ifinfo['status'])) {
$ifinfo['status'] = 'down';
}
$ifinfo['macaddr'] = $ifinfotmp['macaddr'];
$ifinfo['ipaddr'] = $ifinfotmp['ipaddr'];
$ifinfo['subnet'] = $ifinfotmp['subnet'];
$ifinfo['linklocal'] = get_interface_linklocal($ifdescr);
$ifinfo['ipaddrv6'] = get_interface_ipv6($ifdescr);
$ifinfo['subnetv6'] = get_interface_subnetv6($ifdescr);
if (isset($ifinfotmp['link0'])) {
$link0 = 'down';
}
$ifinfotmp = legacy_interface_stats($chkif);
$ifinfo['inerrs'] = $ifinfotmp['input errors'];
$ifinfo['outerrs'] = $ifinfotmp['output errors'];
$ifinfo['collisions'] = $ifinfotmp['collisions'];
/* Use pfctl for non wrapping 64 bit counters */
/* Pass */
exec("/sbin/pfctl -vvsI -i {$chkif}", $pfctlstats);
$pf_in4_pass = preg_split("/ +/ ", $pfctlstats[3]);
$pf_out4_pass = preg_split("/ +/", $pfctlstats[5]);
$pf_in6_pass = preg_split("/ +/ ", $pfctlstats[7]);
$pf_out6_pass = preg_split("/ +/", $pfctlstats[9]);
$in4_pass = $pf_in4_pass[5];
$out4_pass = $pf_out4_pass[5];
$in4_pass_packets = $pf_in4_pass[3];
$out4_pass_packets = $pf_out4_pass[3];
$in6_pass = $pf_in6_pass[5];
$out6_pass = $pf_out6_pass[5];
$in6_pass_packets = $pf_in6_pass[3];
$out6_pass_packets = $pf_out6_pass[3];
$ifinfo['inbytespass'] = $in4_pass + $in6_pass;
$ifinfo['outbytespass'] = $out4_pass + $out6_pass;
$ifinfo['inpktspass'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpktspass'] = $out4_pass_packets + $out6_pass_packets;
/* Block */
$pf_in4_block = preg_split("/ +/", $pfctlstats[4]);
$pf_out4_block = preg_split("/ +/", $pfctlstats[6]);
$pf_in6_block = preg_split("/ +/", $pfctlstats[8]);
$pf_out6_block = preg_split("/ +/", $pfctlstats[10]);
$in4_block = $pf_in4_block[5];
$out4_block = $pf_out4_block[5];
$in4_block_packets = $pf_in4_block[3];
$out4_block_packets = $pf_out4_block[3];
$in6_block = $pf_in6_block[5];
$out6_block = $pf_out6_block[5];
$in6_block_packets = $pf_in6_block[3];
$out6_block_packets = $pf_out6_block[3];
$ifinfo['inbytesblock'] = $in4_block + $in6_block;
$ifinfo['outbytesblock'] = $out4_block + $out6_block;
$ifinfo['inpktsblock'] = $in4_block_packets + $in6_block_packets;
$ifinfo['outpktsblock'] = $out4_block_packets + $out6_block_packets;
$ifinfo['inbytes'] = $in4_pass + $in6_pass;
$ifinfo['outbytes'] = $out4_pass + $out6_pass;
$ifinfo['inpkts'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpkts'] = $out4_pass_packets + $out6_pass_packets;
$ifconfiginfo = "";
$link_type = $config['interfaces'][$ifdescr]['ipaddr'];
switch ($link_type) {
/* DHCP? -> see if dhclient is up */
case "dhcp":
/* see if dhclient is up */
if (find_dhclient_process($ifinfo['if']) != 0)
$ifinfo['dhcplink'] = "up";
else
$ifinfo['dhcplink'] = "down";
break;
/* PPPoE/PPTP/L2TP interface? -> get status from virtual interface */
case "pppoe":
case "pptp":
case "l2tp":
if ($ifinfo['status'] == "up" && !isset($link0))
/* get PPPoE link status for dial on demand */
$ifinfo["{$link_type}link"] = "up";
else
$ifinfo["{$link_type}link"] = "down";
break;
/* PPP interface? -> get uptime for this session and cumulative uptime from the persistant log file in conf */
case "ppp":
if ($ifinfo['status'] == "up")
$ifinfo['ppplink'] = "up";
else
$ifinfo['ppplink'] = "down" ;
if (empty($ifinfo['status']))
$ifinfo['status'] = "down";
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
if ($config['interfaces'][$ifdescr]['if'] == $ppp['if'])
break;
}
}
$dev = $ppp['ports'];
if ($config['interfaces'][$ifdescr]['if'] != $ppp['if'] || empty($dev))
break;
if (!file_exists($dev)) {
$ifinfo['nodevice'] = 1;
$ifinfo['pppinfo'] = $dev . " " . gettext("device not present! Is the modem attached to the system?");
}
$usbmodemoutput = array();
exec("usbconfig", $usbmodemoutput);
$mondev = "/tmp/3gstats.{$ifdescr}";
if(file_exists($mondev)) {
$cellstats = file($mondev);
/* skip header */
$a_cellstats = explode(",", $cellstats[1]);
if(preg_match("/huawei/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = huawei_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = huawei_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = huawei_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = huawei_service_to_string(trim($a_cellstats[11]));
}
if(preg_match("/zte/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = zte_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = zte_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = zte_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = zte_service_to_string(trim($a_cellstats[11]));
}
$ifinfo['cell_upstream'] = $a_cellstats[4];
$ifinfo['cell_downstream'] = trim($a_cellstats[5]);
$ifinfo['cell_sent'] = $a_cellstats[6];
$ifinfo['cell_received'] = trim($a_cellstats[7]);
$ifinfo['cell_bwupstream'] = $a_cellstats[8];
$ifinfo['cell_bwdownstream'] = trim($a_cellstats[9]);
}
// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
if (isset($ppp['uptime']))
$ifinfo['ppp_uptime_accumulated'] = "(".get_ppp_uptime($ifinfo['if']).")";
break;
default:
break;
}
if (file_exists("/var/run/{$link_type}_{$ifdescr}.pid")) {
$sec = trim(`/usr/local/sbin/ppp-uptime.sh {$ifinfo['if']}`);
$ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec);
}
if ($ifinfo['status'] == "up") {
/* try to determine media with ifconfig */
unset($ifconfiginfo);
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
$wifconfiginfo = array();
if(is_interface_wireless($ifdescr)) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo);
array_shift($wifconfiginfo);
}
$matches = "";
foreach ($ifconfiginfo as $ici) {
/* don't list media/speed for wireless cards, as it always
displays 2 Mbps even though clients can connect at 11 Mbps */
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} else if (preg_match("/media: IEEE 802.11 Wireless Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
}
if (preg_match("/status: (.*)$/", $ici, $matches)) {
if ($matches[1] != "active")
$ifinfo['status'] = $matches[1];
if($ifinfo['status'] == gettext("running"))
$ifinfo['status'] = gettext("up");
}
if (preg_match("/channel (\S*)/", $ici, $matches)) {
$ifinfo['channel'] = $matches[1];
}
if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
if ($matches[1][0] == '"')
$ifinfo['ssid'] = substr($matches[1], 1, -1);
else
$ifinfo['ssid'] = $matches[1];
}
if (preg_match("/laggproto (.*)$/", $ici, $matches)) {
$ifinfo['laggproto'] = $matches[1];
}
if (preg_match("/laggport: (.*)$/", $ici, $matches)) {
$ifinfo['laggport'][] = $matches[1];
}
}
foreach($wifconfiginfo as $ici) {
$elements = preg_split("/[ ]+/i", $ici);
if ($elements[0] != "") {
$ifinfo['bssid'] = $elements[0];
}
if ($elements[3] != "") {
$ifinfo['rate'] = $elements[3];
}
if ($elements[4] != "") {
$ifinfo['rssi'] = $elements[4];
}
}
/* lookup the gateway */
if (interface_has_gateway($ifdescr)) {
$ifinfo['gateway'] = get_interface_gateway($ifdescr);
$ifinfo['gatewayv6'] = get_interface_gateway_v6($ifdescr);
}
}
$bridge = "";
$bridge = link_interface_to_bridge($ifdescr);
if($bridge) {
$bridge_text = `/sbin/ifconfig {$bridge}`;
if(stristr($bridge_text, "blocking") <> false) {
$ifinfo['bridge'] = "<b><font color='red'>" . gettext("blocking") . "</font></b> - " . gettext("check for ethernet loops");
$ifinfo['bridgeint'] = $bridge;
} else if(stristr($bridge_text, "learning") <> false) {
$ifinfo['bridge'] = gettext("learning");
$ifinfo['bridgeint'] = $bridge;
} else if(stristr($bridge_text, "forwarding") <> false) {
$ifinfo['bridge'] = gettext("forwarding");
$ifinfo['bridgeint'] = $bridge;
}
}
return $ifinfo;
}
......@@ -593,248 +593,6 @@ function get_ppp_uptime($port){
}
}
//returns interface information
function get_interface_info($ifdescr)
{
global $config;
$ifinfo = array();
if (empty($config['interfaces'][$ifdescr]))
return;
$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
$ifinfo['if'] = get_real_interface($ifdescr);
$chkif = $ifinfo['if'];
$ifinfotmp = pfSense_get_interface_addresses($chkif);
$ifinfo['status'] = $ifinfotmp['status'];
if (empty($ifinfo['status'])) {
$ifinfo['status'] = 'down';
}
$ifinfo['macaddr'] = $ifinfotmp['macaddr'];
$ifinfo['ipaddr'] = $ifinfotmp['ipaddr'];
$ifinfo['subnet'] = $ifinfotmp['subnet'];
$ifinfo['linklocal'] = get_interface_linklocal($ifdescr);
$ifinfo['ipaddrv6'] = get_interface_ipv6($ifdescr);
$ifinfo['subnetv6'] = get_interface_subnetv6($ifdescr);
if (isset($ifinfotmp['link0'])) {
$link0 = 'down';
}
$ifinfotmp = legacy_interface_stats($chkif);
$ifinfo['inerrs'] = $ifinfotmp['input errors'];
$ifinfo['outerrs'] = $ifinfotmp['output errors'];
$ifinfo['collisions'] = $ifinfotmp['collisions'];
/* Use pfctl for non wrapping 64 bit counters */
/* Pass */
exec("/sbin/pfctl -vvsI -i {$chkif}", $pfctlstats);
$pf_in4_pass = preg_split("/ +/ ", $pfctlstats[3]);
$pf_out4_pass = preg_split("/ +/", $pfctlstats[5]);
$pf_in6_pass = preg_split("/ +/ ", $pfctlstats[7]);
$pf_out6_pass = preg_split("/ +/", $pfctlstats[9]);
$in4_pass = $pf_in4_pass[5];
$out4_pass = $pf_out4_pass[5];
$in4_pass_packets = $pf_in4_pass[3];
$out4_pass_packets = $pf_out4_pass[3];
$in6_pass = $pf_in6_pass[5];
$out6_pass = $pf_out6_pass[5];
$in6_pass_packets = $pf_in6_pass[3];
$out6_pass_packets = $pf_out6_pass[3];
$ifinfo['inbytespass'] = $in4_pass + $in6_pass;
$ifinfo['outbytespass'] = $out4_pass + $out6_pass;
$ifinfo['inpktspass'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpktspass'] = $out4_pass_packets + $out6_pass_packets;
/* Block */
$pf_in4_block = preg_split("/ +/", $pfctlstats[4]);
$pf_out4_block = preg_split("/ +/", $pfctlstats[6]);
$pf_in6_block = preg_split("/ +/", $pfctlstats[8]);
$pf_out6_block = preg_split("/ +/", $pfctlstats[10]);
$in4_block = $pf_in4_block[5];
$out4_block = $pf_out4_block[5];
$in4_block_packets = $pf_in4_block[3];
$out4_block_packets = $pf_out4_block[3];
$in6_block = $pf_in6_block[5];
$out6_block = $pf_out6_block[5];
$in6_block_packets = $pf_in6_block[3];
$out6_block_packets = $pf_out6_block[3];
$ifinfo['inbytesblock'] = $in4_block + $in6_block;
$ifinfo['outbytesblock'] = $out4_block + $out6_block;
$ifinfo['inpktsblock'] = $in4_block_packets + $in6_block_packets;
$ifinfo['outpktsblock'] = $out4_block_packets + $out6_block_packets;
$ifinfo['inbytes'] = $in4_pass + $in6_pass;
$ifinfo['outbytes'] = $out4_pass + $out6_pass;
$ifinfo['inpkts'] = $in4_pass_packets + $in6_pass_packets;
$ifinfo['outpkts'] = $out4_pass_packets + $out6_pass_packets;
$ifconfiginfo = "";
$link_type = $config['interfaces'][$ifdescr]['ipaddr'];
switch ($link_type) {
/* DHCP? -> see if dhclient is up */
case "dhcp":
/* see if dhclient is up */
if (find_dhclient_process($ifinfo['if']) != 0)
$ifinfo['dhcplink'] = "up";
else
$ifinfo['dhcplink'] = "down";
break;
/* PPPoE/PPTP/L2TP interface? -> get status from virtual interface */
case "pppoe":
case "pptp":
case "l2tp":
if ($ifinfo['status'] == "up" && !isset($link0))
/* get PPPoE link status for dial on demand */
$ifinfo["{$link_type}link"] = "up";
else
$ifinfo["{$link_type}link"] = "down";
break;
/* PPP interface? -> get uptime for this session and cumulative uptime from the persistant log file in conf */
case "ppp":
if ($ifinfo['status'] == "up")
$ifinfo['ppplink'] = "up";
else
$ifinfo['ppplink'] = "down" ;
if (empty($ifinfo['status']))
$ifinfo['status'] = "down";
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
if ($config['interfaces'][$ifdescr]['if'] == $ppp['if'])
break;
}
}
$dev = $ppp['ports'];
if ($config['interfaces'][$ifdescr]['if'] != $ppp['if'] || empty($dev))
break;
if (!file_exists($dev)) {
$ifinfo['nodevice'] = 1;
$ifinfo['pppinfo'] = $dev . " " . gettext("device not present! Is the modem attached to the system?");
}
$usbmodemoutput = array();
exec("usbconfig", $usbmodemoutput);
$mondev = "/tmp/3gstats.{$ifdescr}";
if(file_exists($mondev)) {
$cellstats = file($mondev);
/* skip header */
$a_cellstats = explode(",", $cellstats[1]);
if(preg_match("/huawei/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = huawei_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = huawei_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = huawei_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = huawei_service_to_string(trim($a_cellstats[11]));
}
if(preg_match("/zte/i", implode("\n", $usbmodemoutput))) {
$ifinfo['cell_rssi'] = zte_rssi_to_string($a_cellstats[1]);
$ifinfo['cell_mode'] = zte_mode_to_string($a_cellstats[2], $a_cellstats[3]);
$ifinfo['cell_simstate'] = zte_simstate_to_string($a_cellstats[10]);
$ifinfo['cell_service'] = zte_service_to_string(trim($a_cellstats[11]));
}
$ifinfo['cell_upstream'] = $a_cellstats[4];
$ifinfo['cell_downstream'] = trim($a_cellstats[5]);
$ifinfo['cell_sent'] = $a_cellstats[6];
$ifinfo['cell_received'] = trim($a_cellstats[7]);
$ifinfo['cell_bwupstream'] = $a_cellstats[8];
$ifinfo['cell_bwdownstream'] = trim($a_cellstats[9]);
}
// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
if (isset($ppp['uptime']))
$ifinfo['ppp_uptime_accumulated'] = "(".get_ppp_uptime($ifinfo['if']).")";
break;
default:
break;
}
if (file_exists("/var/run/{$link_type}_{$ifdescr}.pid")) {
$sec = trim(`/usr/local/sbin/ppp-uptime.sh {$ifinfo['if']}`);
$ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec);
}
if ($ifinfo['status'] == "up") {
/* try to determine media with ifconfig */
unset($ifconfiginfo);
exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
$wifconfiginfo = array();
if(is_interface_wireless($ifdescr)) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo);
array_shift($wifconfiginfo);
}
$matches = "";
foreach ($ifconfiginfo as $ici) {
/* don't list media/speed for wireless cards, as it always
displays 2 Mbps even though clients can connect at 11 Mbps */
if (preg_match("/media: .*? \((.*?)\)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} else if (preg_match("/media: Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
} else if (preg_match("/media: IEEE 802.11 Wireless Ethernet (.*)/", $ici, $matches)) {
$ifinfo['media'] = $matches[1];
}
if (preg_match("/status: (.*)$/", $ici, $matches)) {
if ($matches[1] != "active")
$ifinfo['status'] = $matches[1];
if($ifinfo['status'] == gettext("running"))
$ifinfo['status'] = gettext("up");
}
if (preg_match("/channel (\S*)/", $ici, $matches)) {
$ifinfo['channel'] = $matches[1];
}
if (preg_match("/ssid (\".*?\"|\S*)/", $ici, $matches)) {
if ($matches[1][0] == '"')
$ifinfo['ssid'] = substr($matches[1], 1, -1);
else
$ifinfo['ssid'] = $matches[1];
}
if (preg_match("/laggproto (.*)$/", $ici, $matches)) {
$ifinfo['laggproto'] = $matches[1];
}
if (preg_match("/laggport: (.*)$/", $ici, $matches)) {
$ifinfo['laggport'][] = $matches[1];
}
}
foreach($wifconfiginfo as $ici) {
$elements = preg_split("/[ ]+/i", $ici);
if ($elements[0] != "") {
$ifinfo['bssid'] = $elements[0];
}
if ($elements[3] != "") {
$ifinfo['rate'] = $elements[3];
}
if ($elements[4] != "") {
$ifinfo['rssi'] = $elements[4];
}
}
/* lookup the gateway */
if (interface_has_gateway($ifdescr)) {
$ifinfo['gateway'] = get_interface_gateway($ifdescr);
$ifinfo['gatewayv6'] = get_interface_gateway_v6($ifdescr);
}
}
$bridge = "";
$bridge = link_interface_to_bridge($ifdescr);
if($bridge) {
$bridge_text = `/sbin/ifconfig {$bridge}`;
if(stristr($bridge_text, "blocking") <> false) {
$ifinfo['bridge'] = "<b><font color='red'>" . gettext("blocking") . "</font></b> - " . gettext("check for ethernet loops");
$ifinfo['bridgeint'] = $bridge;
} else if(stristr($bridge_text, "learning") <> false) {
$ifinfo['bridge'] = gettext("learning");
$ifinfo['bridgeint'] = $bridge;
} else if(stristr($bridge_text, "forwarding") <> false) {
$ifinfo['bridge'] = gettext("forwarding");
$ifinfo['bridgeint'] = $bridge;
}
}
return $ifinfo;
}
function add_hostname_to_watch($hostname) {
if(!is_dir("/var/db/dnscache")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment