/** * parse one line and create Wifi object * @param string $line * @return Wifi */ private function parseLine($line) { $wifi = new Wifi(); $array = explode("\t", $line); $wifi->setMac($array[0]); $wifi->setSsid($array[1]); $wifi->setSec(intval($array[2])); $wifi->setLatitude(doubleval($array[3])); $wifi->setLongitude(doubleval($array[4])); $wifi->setAltitude(doubleval($array[5])); $wifi->setSource(self::ID_SOURCE); return $wifi; }
/** * @param int $limit * @param int $from * @return \App\Model\Wifi[] */ public function getAllNets($limit = null, $from = null) { $q = $this->database->table('wifi'); if ($limit) { $q->where('id > ?', $from)->limit(intval($limit)); } $w = $q->fetchAll(); return Wifi::createWifiArrayFromDBRowArray($w); }
/** * @param array $line * @return Wifi */ public function parseLine($line) { $wifi = new Wifi(); $wifi->setMac(MyUtils::macSeparator2Colon($line['netid'])); $wifi->setSsid($line['ssid'] ? $line['ssid'] : ""); $wifi->setComment(trim($line['comment'])); $wifi->setName(trim($line['name'])); $wifi->setType($line['type']); $wifi->setFreenet($line['freenet']); $wifi->setPaynet($line['paynet']); $wifi->setFirsttime(new DateTime($line['firsttime'])); $wifi->setLasttime(new DateTime($line['lasttime'])); $wifi->setFlags($line['flags']); $wifi->setWep($line['wep']); $wifi->setLatitude((double) $line['trilat']); $wifi->setLongitude((double) $line['trilong']); $wifi->setLastupdt($line['lastupdt']); $wifi->setChannel((int) $line['channel']); $wifi->setBcninterval($line['bcninterval']); $wifi->setQos((int) $line['qos']); $wifi->setSource(self::ID_SOURCE); return $wifi; }
/** * render one image for overlay * * @param string $mode * @param float $lat1 * @param float $lat2 * @param float $lon1 * @param float $lon2 */ public function renderImage($mode, $lat1, $lat2, $lon1, $lon2) { header("Content-type: image/png"); MyUtils::setIni(180, '1024M'); $request = $this->getHttpRequest(); $zoom = $request->getQuery("zoom"); $this->overlayRenderer = new OverlayRenderer($zoom); // not allowed mode -> set do default mode if (!$this->allowedMode($mode)) { $mode = self::DEFAULT_MODE; } // zoom is too small if ($zoom < self::MIN_OVERLAY_ZOOM) { echo MyUtils::image2string($this->overlayRenderer->drawNone()); exit; } // increase coords range, due to future crop $coords = new Coords($lat1, $lat2, $lon1, $lon2); $coords->increaseLatLngRange(self::INCREASE_LATLNG_RANGE_ABOUT); // params for image creation $params = array(); switch ($mode) { case self::MODE_SEARCH: $ssidmac = $request->getQuery("ssidmac"); if ($ssidmac) { if (MyUtils::isMacAddress($ssidmac)) { $params['mac'] = urldecode($ssidmac); } else { $params['ssid'] = $ssidmac; } } $channel = $request->getQuery('channel'); if ($channel != null && $channel != "") { $params['channel'] = intval($channel); } $security = $request->getQuery('security'); if ($security != null && $security != '') { $params['sec'] = intval($security); } $source = $request->getQuery('source'); if ($source != null && $source != "") { $params['id_source'] = intval($source); } break; case self::MODE_HIGHLIGHT: $by = $request->getQuery("by"); if (in_array($by, self::$MODE_HIGHLIGHT_ALLOWED_BY)) { $params['by'] = $by; $val = $request->getQuery("val"); $params['val'] = $val; } break; case self::MODE_ONE: $ssidmac = $this->getHttpRequest()->getQuery('ssid'); if (MyUtils::isMacAddress($ssidmac)) { $params['mac'] = urldecode($ssidmac); } else { $params['ssid'] = $ssidmac; } break; default: break; } // generating cache key $key = MyUtils::generateCacheKey($mode, $coords, $zoom, $params); // try to find in cache if (self::CACHE_ON && $mode != self::MODE_CALCULATED) { $img = $this->cache->load($key); if ($img != null) { echo $img; return; } } // get data and generate tile of overlay switch ($mode) { case self::MODE_SEARCH: $params['coords'] = $coords; $nets = $this->oWifiManager->getNetsByParams($params, array('ssid,mac,latitude,longitude,id_source')); $img = $this->overlayRenderer->drawModeAll($coords, $nets); break; case self::MODE_HIGHLIGHT: if (!empty($params)) { $params['coords'] = $coords; $params[$params['by']] = $params['val']; unset($params['by']); unset($params['val']); $highlightedIds = $this->oWifiManager->getNetsByParams($params, array('id')); $allNets = $this->oWifiManager->getNetsByParams(array('coords' => $params['coords']), array('id,ssid,mac,latitude,longitude,id_source')); $img = $this->overlayRenderer->drawModeHighlight($coords, $allNets, $highlightedIds); } else { $nets = $this->wifiManager->getAllNetsInLatLngRange($coords, array('latitude', 'longitude', 'ssid', 'mac', 'id_source'), true); $img = $this->overlayRenderer->drawModeAll($coords, $nets); } break; case self::MODE_ONE: $nets = $this->wifiManager->getNetsModeSearch($coords, $params); $img = $this->overlayRenderer->drawModeOne($coords, $nets); break; case self::MODE_CALCULATED: $net = $this->wifiManager->getWifiById($this->getHttpRequest()->getQuery('a')); $lat = $net->getLatitude(); $lon = $net->getLongitude(); $lat1 = doubleval($lat) - 0.003; $lat2 = doubleval($lat) + 0.003; $lon1 = doubleval($lon) - 0.003 / 2; $lon2 = doubleval($lon) + 0.003 / 2; $coordsNew = new Coords($lat1, $lat2, $lon1, $lon2); $nets = $this->wifiManager->getNetsModeSearch($coordsNew, array('mac' => $net->getMac())); $nets2 = $this->wifiManager->getNetsModeSearch($coords, array('mac' => $net->getMac())); $latt = 0; $lont = 0; foreach ($nets as $net) { $latt += $net->getLatitude(); $lont += $net->getLongitude(); } $lat_avg = $latt / (double) count($nets); $lon_avg = $lont / (double) count($nets); $net = new Wifi(); $net->setLatitude($lat_avg); $net->setLongitude($lon_avg); $img = $this->overlayRenderer->drawCalculated($coords, $nets2, $net); break; default: $nets = $this->wifiManager->getAllNetsInLatLngRange($coords, array('latitude', 'longitude', 'ssid', 'mac', 'id_source'), true); $img = $this->overlayRenderer->drawModeAll($coords, $nets); break; } $image = MyUtils::image2string($img); $img = null; // save generated image to cache if (self::CACHE_ON && $mode != self::MODE_CALCULATED) { $this->cache->save($key, $image, array(Cache::EXPIRE => time() + self::$cacheExpire[$zoom])); } echo $image; return; }
/** * only save without preparation (already have right sec) * * @param Wifi $w */ public function save(Wifi $w) { try { $this->database->table('wifi')->insert($w->toArray()); } catch (\PDOException $e) { $this->logger->addLog(new Log(Log::TYPE_ERROR, 'WIFI INSERT', 'nepodarilo se ulozit bod do tabulky wifi, zprava:' . $e->getMessage())); } }
/** * @param Coords $coords * @param Wifi[] $nets * @param Wifi $net * @return resource */ public function drawCalculated(Coords $coords, $nets, Wifi $net) { $this->createImage(self::IMAGE_BIGGER, self::IMAGE_BIGGER); $op = $this->getConversionRatio($coords); foreach ($nets as $w) { $xy = $this->latLngToPx($w->getLatitude(), $w->getLongitude(), $coords->getLatStart(), $coords->getLonStart(), $op->onepxlat, $op->onepxlon); $this->drawOneNet($xy->getX(), $xy->getY(), 16, 16, array('ssid' => $w->getSsid(), 'mac' => $w->getMac()), $this->imgcolors['one_net'], self::IMG_TYPE_ELLIPSE); } if ($net->getLatitude() < $coords->getLatEnd() && $net->getLatitude() > $coords->getLatStart() && $net->getLongitude() < $coords->getLonEnd() && $net->getLongitude() > $coords->getLonStart()) { $xy = $this->latLngToPx($net->getLatitude(), $net->getLongitude(), $coords->getLatStart(), $coords->getLonStart(), $op->onepxlat, $op->onepxlon); $this->drawOneNet($xy->getX(), $xy->getY(), 16, 16, array('ssid' => $net->getSsid(), 'mac' => $net->getMac()), $this->imgcolors[1], self::IMG_TYPE_ELLIPSE, false); } $this->cropImage(); return $this->img; }