Example #1
0
/**
 * Returns full map marks for builds with filled GEO field
 * 
 * @return string
 */
function um_MapDrawBuilds()
{
    $ym_conf = rcms_parse_ini_file(CONFIG_PATH . "ymaps.ini");
    $query = "SELECT * from `build` WHERE `geo` != '' ";
    $allbuilds = simple_queryall($query);
    $allstreets = zb_AddressGetStreetAllData();
    $streetData = array();
    $cacheDir = 'exports/';
    $cacheTime = 10;
    $cacheTime = time() - $cacheTime * 60;
    //street id => streetname
    if (!empty($allstreets)) {
        foreach ($allstreets as $ia => $eachstreet) {
            $streetData[$eachstreet['id']] = $eachstreet['streetname'];
        }
    }
    //get apts in all builds aggregated with users logins
    $aptData = array();
    $allapts_q = "SELECT `buildid`,`apt`,`login` from `apt` JOIN `address` ON `apt`.`id`=`address`.`aptid`";
    $allapts = simple_queryall($allapts_q);
    if (!empty($allapts)) {
        $aptData = $allapts;
    }
    //get all user ips
    $alluserips = zb_UserGetAllIPs();
    //form alive ips array
    $aliveIps = array();
    if (file_exists("exports/nmaphostscan")) {
        $nmapData = file_get_contents("exports/nmaphostscan");
        $nmapData = explodeRows($nmapData);
        if (!empty($nmapData)) {
            foreach ($nmapData as $ic => $eachnmaphost) {
                $zhost = zb_ExtractIpAddress($eachnmaphost);
                if ($zhost) {
                    $aliveIps[$zhost] = $zhost;
                }
            }
        }
    }
    $result = '';
    if (!empty($allbuilds)) {
        foreach ($allbuilds as $io => $each) {
            $geo = mysql_real_escape_string($each['geo']);
            @($streetname = $streetData[$each['streetid']]);
            $title = wf_Link("?module=builds&action=editbuild&streetid=" . $each['streetid'] . "&buildid=" . $each['id'], $streetname . ' ' . $each['buildnum'], false);
            $content = '';
            $cells = wf_TableCell(__('apt.'));
            $cells .= wf_TableCell(__('User'));
            $cells .= wf_TableCell(__('Status'));
            $rows = wf_tag('tr', false, '', 'bgcolor=#DCDCDC') . $cells . wf_tag('tr', true);
            $iconlabel = '';
            $footer = '';
            $aliveUsers = 0;
            $usersCount = 0;
            if (!empty($aptData)) {
                //build users data caching
                $cacheName = $cacheDir . $each['id'] . '.inbuildusers';
                if (file_exists($cacheName)) {
                    $updateCache = false;
                    if (filemtime($cacheName) > $cacheTime) {
                        $updateCache = false;
                    } else {
                        $updateCache = true;
                    }
                } else {
                    $updateCache = true;
                }
                if (!$updateCache) {
                    $cachePrev = file_get_contents($cacheName);
                    $cachePrev = unserialize($cachePrev);
                    $rows = $cachePrev['rows'];
                    $usersCount = $cachePrev['userscount'];
                    $aliveUsers = $cachePrev['aliveusers'];
                } else {
                    foreach ($aptData as $ib => $eachapt) {
                        if ($eachapt['buildid'] == $each['id']) {
                            if (isset($alluserips[$eachapt['login']])) {
                                $userIp = $alluserips[$eachapt['login']];
                                $usersCount++;
                                if (isset($aliveIps[$userIp])) {
                                    $aliveFlag = web_bool_led(true);
                                    $aliveUsers++;
                                } else {
                                    $aliveFlag = web_bool_led(false);
                                }
                                $cells = wf_TableCell($eachapt['apt']);
                                $cells .= wf_TableCell(wf_Link('?module=userprofile&username='******'login'], $userIp, false));
                                $cells .= wf_TableCell($aliveFlag);
                                $rows .= wf_TableRow($cells);
                            }
                        }
                    }
                    $cacheStore = array();
                    $cacheStore['rows'] = $rows;
                    $cacheStore['userscount'] = $usersCount;
                    $cacheStore['aliveusers'] = $aliveUsers;
                    $cacheStore = serialize($cacheStore);
                    file_put_contents($cacheName, $cacheStore);
                }
            }
            $footer = __('Active') . ' ' . $aliveUsers . '/' . $usersCount;
            $icon = um_MapBuildIcon($usersCount);
            $content = json_encode(wf_TableBody($rows, '', 0));
            $title = json_encode($title);
            $content = str_replace('"', '', $content);
            $content = str_replace("'", '', $content);
            $content = str_replace("\n", '', $content);
            $title = str_replace('"', '', $title);
            $title = str_replace("'", '', $title);
            $title = str_replace("\n", '', $title);
            $result .= sm_MapAddMark($geo, $title, $content, $footer, $icon, $iconlabel, true);
        }
    }
    return $result;
}
Example #2
0
 /**
  * Returns JSON for actual ARP table
  * 
  * @return string
  */
 public function ajaxReplyArp()
 {
     $result = '';
     $command = 'arp -a';
     $raw = shell_exec($command);
     $jsonAAData = array();
     if (!empty($raw)) {
         $allUserAddress = zb_AddressGetFulladdresslistCached();
         $allUserIps = zb_UserGetAllIPs();
         $allUserIps = array_flip($allUserIps);
         $allSwitchesIps = $this->getAllSwitchesIps();
         $raw = explodeRows($raw);
         if (!empty($raw)) {
             foreach ($raw as $io => $each) {
                 if (!empty($each)) {
                     $ip = zb_ExtractIpAddress($each);
                     $mac = zb_ExtractMacAddress($each);
                     $hostType = $this->getHostLink($allUserIps, $allUserAddress, $allSwitchesIps, $ip);
                     $jsonItem = array();
                     $jsonItem[] = $ip;
                     $jsonItem[] = $mac;
                     $jsonItem[] = $hostType;
                     $jsonAAData[] = $jsonItem;
                 }
             }
         }
     }
     $result = array("aaData" => $jsonAAData);
     return json_encode($result);
 }
Example #3
0
         //writing to cache
         $savePrev = serialize($curTraff);
         file_put_contents('exports/prevtraff', $savePrev);
     }
 }
 //saving scan data
 file_put_contents('exports/nmaphostscan', $fullScanResult);
 //postprocessing DN data
 if ($alterconf['DN_FULLHOSTSCAN']) {
     $activeIps = array();
     if (file_exists("exports/nmaphostscan")) {
         $nmapData = file_get_contents("exports/nmaphostscan");
         $nmapData = explodeRows($nmapData);
         if (!empty($nmapData)) {
             foreach ($nmapData as $ic => $eachnmaphost) {
                 $zhost = zb_ExtractIpAddress($eachnmaphost);
                 if ($zhost) {
                     $activeIps[$zhost] = $zhost;
                 }
             }
         }
     }
     if (!empty($activeIps)) {
         if (file_exists(DATA_PATH . "dn")) {
             //directory clanup
             $oldDnData = rcms_scandir(DATA_PATH . "dn/");
             if (!empty($oldDnData)) {
                 foreach ($oldDnData as $deleteFile) {
                     unlink(DATA_PATH . "dn/" . $deleteFile);
                 }
             }