/** * Returns array with subnets usage stats * * @return array */ function zb_FreeIpStats() { $result = array(); $allServices = array(); $allNets = array(); $nethostsUsed = array(); $servicesTmp = multinet_get_services(); $netsTmp = multinet_get_all_networks(); $neth_q = "SELECT COUNT(id) as count, netid from `nethosts` group by `netid`"; $nethTmp = simple_queryall($neth_q); if (!empty($nethTmp)) { foreach ($nethTmp as $io => $each) { $nethostsUsed[$each['netid']] = $each['count']; } } if (!empty($servicesTmp)) { foreach ($servicesTmp as $io => $each) { $allServices[$each['netid']] = $each['desc']; } } if (!empty($netsTmp)) { foreach ($netsTmp as $io => $each) { $totalIps = multinet_expand_network($each['startip'], $each['endip']); $allNets[$each['id']]['desc'] = $each['desc']; $allNets[$each['id']]['total'] = count($totalIps); //finding used hosts count if (isset($nethostsUsed[$each['id']])) { $allNets[$each['id']]['used'] = $nethostsUsed[$each['id']]; } else { $allNets[$each['id']]['used'] = 0; } //finding network associated service if (isset($allServices[$each['id']])) { $allNets[$each['id']]['service'] = $allServices[$each['id']]; } else { $allNets[$each['id']]['service'] = ''; } } } return $allNets; }
function zb_NetworkGetByIp($ip) { $allnets = multinet_get_all_networks(); $result = false; if (!empty($allnets)) { foreach ($allnets as $io => $eachnet) { $completenet = multinet_expand_network($eachnet['startip'], $eachnet['endip']); if (in_array($ip, $completenet, true)) { $result = $eachnet['id']; break; } else { $result = false; } } } return $result; }
/** * Returns NAS editing grid * * @param array $titles * @param array $keys * @param array $alldata * @param string $module * @param bool $delete * @param bool $edit * @param string $prefix * @return string */ function web_GridEditorNas($titles, $keys, $alldata, $module, $delete = true, $edit = true, $prefix = '') { // Получаем список сетей $networks = multinet_get_all_networks(); $cidrs = array(); if (!empty($networks)) { foreach ($networks as $network) { $cidrs[$network['id']] = $network['desc']; } } // Заголовок таблицы $cells = ''; foreach ($titles as $title) { $cells .= wf_TableCell(__($title)); } $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); // Содержимое таблицы if (!empty($alldata)) { foreach ($alldata as $data) { $cells = ''; $actions = ''; if ($delete) { $actions .= wf_JSAlert('?module=' . $module . '&' . $prefix . 'delete=' . $data['id'], web_delete_icon(), 'Removing this may lead to irreparable results'); } if ($edit) { $actions .= wf_Link('?module=' . $module . '&' . $prefix . 'edit=' . $data['id'], web_edit_icon()); } foreach ($keys as $key) { if (array_key_exists($key, $data)) { switch ($key) { case 'netid': $cells .= wf_TableCell($data[$key] . ': ' . $cidrs[$data[$key]]); break; case 'nastype': if ($data[$key] == 'mikrotik') { $actions .= wf_Link('?module=mikrotikextconf&nasid=' . $data['id'], web_icon_extended('MikroTik extended configuration')); } if ($data[$key] == 'radius') { $actions .= wf_Link('?module=freeradius&nasid=' . $data['id'], web_icon_freeradius('Set RADIUS-attributes')); } $cells .= wf_TableCell($data[$key]); break; default: $cells .= wf_TableCell($data[$key]); break; } } } $cells .= wf_TableCell($actions); $rows .= wf_TableRow($cells, 'row3'); } } // Результат - таблица $result = wf_TableBody($rows, '100%', 0, 'sortable'); // Отображаем результат return $result; }