/** * Returns simple MAC address selector * * @global object $ubillingConfig * @param string $name * @return string */ function zb_NewMacSelect($name = 'newmac') { global $ubillingConfig; $billing_config = $ubillingConfig->getBilling(); $alter_conf = $ubillingConfig->getAlter(); $sudo = $billing_config['SUDO']; $cat = $billing_config['CAT']; $grep = $billing_config['GREP']; $tail = $billing_config['TAIL']; $leases = $alter_conf['NMLEASES']; $leasesmark = $alter_conf['NMLEASEMARK']; $command = $sudo . ' ' . $cat . ' ' . $leases . ' | ' . $grep . ' "' . $leasesmark . '" | ' . $tail . ' -n 200'; $rawdata = shell_exec($command); $allUsedMacs = zb_getAllUsedMac(); $resultArr = array(); if (!empty($rawdata)) { $cleardata = exploderows($rawdata); foreach ($cleardata as $eachline) { preg_match('/[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}/i', $eachline, $matches); if (!empty($matches[0])) { $nmarr[] = $matches[0]; $unique_nmarr = array_unique($nmarr); } } if (!empty($unique_nmarr)) { foreach ($unique_nmarr as $newmac) { if (zb_checkMacFree($newmac, $allUsedMacs)) { $resultArr[$newmac] = $newmac; } } } } $result = wf_Selector($name, $resultArr, '', '', false); return $result; }
function zb_NewMacShow() { global $ubillingConfig; $billing_config = $ubillingConfig->getBilling(); $alter_config = $ubillingConfig->getAlter(); $allarp = array(); $sudo = $billing_config['SUDO']; $cat = $billing_config['CAT']; $grep = $billing_config['GREP']; $tail = $billing_config['TAIL']; $alter_conf = parse_ini_file(CONFIG_PATH . 'alter.ini'); $leases = $alter_conf['NMLEASES']; $leasemark = $alter_conf['NMLEASEMARK']; $command = $sudo . ' ' . $cat . ' ' . $leases . ' | ' . $grep . ' "' . $leasemark . '" | ' . $tail . ' -n 200'; $rawdata = shell_exec($command); $allusedMacs = zb_getAllUsedMac(); $result = ''; //fdb cache preprocessing $fdbData_raw = rcms_scandir('./exports/', '*_fdb'); if (!empty($fdbData_raw)) { $fdbArr = sn_SnmpParseFdbCacheArray($fdbData_raw); $fdbColumn = true; } else { $fdbArr = array(); $fdbColumn = false; } $cells = wf_TableCell(__('MAC')); if (!empty($fdbColumn)) { $cells .= wf_TableCell(__('Switch')); } if ($alter_config['MACVEN_ENABLED']) { $cells .= wf_TableCell(__('Manufacturer')); } $rows = wf_TableRow($cells, 'row1'); if (!empty($rawdata)) { $cleardata = exploderows($rawdata); foreach ($cleardata as $eachline) { preg_match('/[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}/i', $eachline, $matches); if (!empty($matches)) { $allarp[] = $matches[0]; } } $un_arr = array_unique($allarp); if (!empty($un_arr)) { if ($alter_config['MACVEN_ENABLED']) { //adding ajax loader $result .= wf_AjaxLoader(); } foreach ($un_arr as $io => $eachmac) { if (zb_checkMacFree($eachmac, $allusedMacs)) { $cells = wf_TableCell(@$eachmac); if (!empty($fdbColumn)) { $cells .= wf_TableCell(sn_SnmpParseFdbExtract(@$fdbArr[$eachmac])); } if ($alter_config['MACVEN_ENABLED']) { $containerName = 'NMRSMCNT_' . zb_rand_string(8); $lookupVendorLink = wf_AjaxLink('?module=macvendor&mac=' . @$eachmac . '&raw=true', wf_img('skins/macven.gif', __('Device vendor')), $containerName, false, ''); $lookupVendorLink .= wf_tag('span', false, '', 'id="' . $containerName . '"') . '' . wf_tag('span', true); $cells .= wf_TableCell($lookupVendorLink, '350'); } $rows .= wf_TableRow($cells, 'row3'); } } } } $result .= wf_TableBody($rows, '100%', '0', 'sortable'); return $result; }
<?php if (cfr('MAC')) { $altercfg = $ubillingConfig->getAlter(); $newmac_report = $altercfg['NMREP_INMACCHG']; $newmacselector = $altercfg['SIMPLENEWMACSELECTOR']; if (isset($_GET['username'])) { $login = vf($_GET['username']); // change mac if need if (isset($_POST['newmac'])) { $mac = trim($_POST['newmac']); $allUsedMacs = zb_getAllUsedMac(); //check mac for free if (zb_checkMacFree($mac, $allUsedMacs)) { //validate mac format if (check_mac_format($mac)) { $ip = zb_UserGetIP($login); $old_mac = zb_MultinetGetMAC($ip); multinet_change_mac($ip, $mac); log_register("MAC CHANGE (" . $login . ") " . $ip . " FROM " . $old_mac . " ON " . $mac); multinet_rebuild_all_handlers(); // need reset after mac change $billing->resetuser($login); log_register("RESET User (" . $login . ")"); if (isset($altercfg['MACCHGDOUBLEKILL'])) { if ($altercfg['MACCHGDOUBLEKILL']) { $billing->resetuser($login); log_register("RESET User (" . $login . ") DOUBLEKILL"); } } } else {