function macformat($mac, $escape=false) { global $DB; $res = str_replace('-', ':', $mac); // allow eg. format "::ab:3::12", only whole addresses if(preg_match('/^([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2})$/i', $mac, $arr)) { $res = ''; for($i=1; $i<=6; $i++) { if($i > 1) $res .= ':'; if(strlen($arr[$i]) == 1) $res .= '0'; if(strlen($arr[$i]) == 0) $res .= '00'; $res .= $arr[$i]; } } else // other formats eg. cisco xxxx.xxxx.xxxx or parts of addresses { $tmp = preg_replace('/[^0-9a-f]/i', '', $mac); if(strlen($tmp) == 12) // we've the whole address if(check_mac($tmp)) $res = $tmp; } if ($escape) $res = $DB->Escape("%$res%"); return $res; }
function macformat($mac) { $res = str_replace('-', ':', $mac); // allow eg. format "::ab:3::12", only whole addresses if (preg_match('/^([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2}):([0-9a-f]{0,2})$/i', $mac, $arr)) { $res = ''; for ($i = 1; $i <= 6; $i++) { if ($i > 1) { $res .= ':'; } if (strlen($arr[$i]) == 1) { $res .= '0'; } if (strlen($arr[$i]) == 0) { $res .= '00'; } $res .= $arr[$i]; } } else { $tmp = preg_replace('/[^0-9a-f]/i', '', $mac); if (strlen($tmp) == 12) { // we've the whole address if (check_mac($tmp)) { $res = $tmp; } } } return $res; }
$error['ipaddr_pub'] = trans('Specified IP address is in use!'); } elseif ($ip != $nodeedit['ipaddr_pub'] && $LMS->IsIPGateway($nodeedit['ipaddr_pub'])) { $error['ipaddr_pub'] = trans('Specified IP address is network gateway!'); } } else { $error['ipaddr_pub'] = trans('Specified IP address doesn\'t overlap with any network!'); } } else { $error['ipaddr_pub'] = trans('Incorrect IP address!'); } } else { $nodeedit['ipaddr_pub'] = '0.0.0.0'; } $macs = array(); foreach ($nodeedit['macs'] as $key => $value) { if (check_mac($value)) { if ($value != '00:00:00:00:00:00' && !ConfigHelper::checkConfig('phpui.allow_mac_sharing')) { if (($nodeid = $LMS->GetNodeIDByMAC($value)) != NULL && $nodeid != $nodeinfo['id']) { $error['mac' . $key] = trans('Specified MAC address is in use!'); } } $macs[] = $value; } elseif ($value != '') { $error['mac' . $key] = trans('Incorrect MAC address!'); } } if (empty($macs)) { $error['mac0'] = trans('MAC address is required!'); } $nodeedit['macs'] = $macs; if ($nodeedit['name'] == '') {
function GetMACs() { $result = array(); if ($this->CONFIG['phpui']['arp_table_backend'] != '') { exec($this->CONFIG['phpui']['arp_table_backend'], $result); foreach ($result as $arpline) { list($ip, $mac) = explode(' ', $arpline); $result['mac'][] = $mac; $result['ip'][] = $ip; $result['longip'][] = ip_long($ip); $result['nodename'][] = $this->GetNodeNameByMAC($mac); } } else { switch (PHP_OS) { case 'Linux': if (@is_readable('/proc/net/arp')) { $file = fopen('/proc/net/arp', 'r'); } else { break; } while (!feof($file)) { $line = fgets($file, 4096); $line = preg_replace('/[\\t ]+/', ' ', $line); if (preg_match('/[0-9]/', $line)) { // skip header line list($ip, $hwtype, $flags, $hwaddr, $mask, $device) = explode(' ', $line); if ($flags != '0x6' && $hwaddr != '00:00:00:00:00:00' && check_mac($hwaddr)) { $result['mac'][] = $hwaddr; $result['ip'][] = $ip; $result['longip'][] = ip_long($ip); $result['nodename'][] = $this->GetNodeNameByMAC($hwaddr); } } } fclose($file); break; default: exec('arp -an|grep -v incompl', $result); foreach ($result as $arpline) { list($fqdn, $ip, $at, $mac, $hwtype, $perm) = explode(' ', $arpline); $ip = str_replace('(', '', str_replace(')', '', $ip)); if ($perm != "PERM") { $result['mac'][] = $mac; $result['ip'][] = $ip; $result['longip'][] = ip_long($ip); $result['nodename'][] = $this->GetNodeNameByMAC($mac); } } break; } } return $result; }
$where = array(); if (!empty($type)) { $where[] = '(s.type & ' . intval($type) . ') > 0'; } $where[] = 's.start > ' . $datefrom . ' AND s.stop < ' . $dateto; if (!empty($filtertype)) { switch ($filtertype) { case 'ip': if (check_ip($filtervalue)) { $where[] = 's.ipaddr = ' . ip_long($filtervalue); } else { $filtervalue = ''; } break; case 'mac': if (check_mac($filtervalue)) { $where[] = 's.mac = \'' . $filtervalue . '\''; } else { $filtervalue = ''; } break; case 'customer': $where[] = '(c.name ?LIKE? ' . $DB->Escape("%{$filtervalue}%") . ' OR c.lastname ?LIKE? ' . $DB->Escape("%{$filtervalue}%") . ')'; break; case 'nodeid': if (intval($filtervalue)) { $where[] = 's.nodeid = ' . intval($filtervalue); } else { $filtervalue = ''; } break;