/**
  * @param array $params
  * @param array $select
  * @param null|int  $limit
  * @param null|string  $order
  * @return array
  */
 public function getNetsByParams($params, $select = array('*'), $limit = null, $order = null)
 {
     $SQLselect = $this->buildSelect($select);
     $SQLwhere = array();
     $pdoParams = array();
     foreach ($params as $p => $pv) {
         switch ($p) {
             case 'coords':
                 $pdoParams[':latStart'] = $pv->getLatStart();
                 $SQLwhere[] = 'latitude > :latStart';
                 $pdoParams[':latEnd'] = $pv->getLatEnd();
                 $SQLwhere[] = 'latitude < :latEnd';
                 $pdoParams[':lonStart'] = $pv->getLonStart();
                 $SQLwhere[] = 'longitude > :lonStart';
                 $pdoParams[':lonEnd'] = $pv->getLonEnd();
                 $SQLwhere[] = 'longitude < :lonEnd';
                 break;
             case 'ssid':
                 $pdoParams[':ssid'] = '%' . $pv . '%';
                 $SQLwhere[] = 'ssid LIKE :ssid';
                 break;
             case 'mac':
                 $pdoParams[':mac'] = '%' . MyUtils::macSeparator2Colon($pv) . '%';
                 $SQLwhere[] = 'mac LIKE :mac';
                 break;
             default:
                 $pdoParams[":" . $p] = $pv;
                 $SQLwhere[] = $p . " = :{$p}";
         }
     }
     $where = implode(' AND ', $SQLwhere);
     $sql = "SELECT " . $SQLselect . " FROM " . self::TABLE . " WHERE " . $where;
     if ($order) {
         $sql .= " ORDER BY " . $order;
     }
     if ($limit) {
         $sql .= " LIMIT " . intval($limit);
     }
     $sth = $this->pdo->prepare($sql);
     foreach ($pdoParams as $p => $v) {
         $sth->bindValue($p, $v);
     }
     $sth->execute();
     $data = $sth->fetchAll(\PDO::FETCH_ASSOC);
     return $data;
 }
Esempio n. 2
0
 /**
  * @param Model\Coords|null $coords
  * @param string	$mode
  * @param array	$array
  * @return array
  */
 protected function getParamsArray(Model\Coords $coords = null, $mode = self::MODE_ALL, $array)
 {
     if ($coords == null) {
         $coords = new Model\Coords($array["lat1"], $array["lat2"], $array["lon1"], $array["lon2"]);
     }
     $params = array("coords" => $coords);
     // podle nastaveneho modu rozhodnout
     switch ($mode) {
         case WifiPresenter::MODE_SEARCH:
             $ssidmac = isset($array["ssidmac"]) ? $ssidmac = $array["ssidmac"] : null;
             if ($ssidmac) {
                 if (Model\MyUtils::isMacAddress($ssidmac)) {
                     $params['mac'] = urldecode($ssidmac);
                 } else {
                     $params['ssid'] = $ssidmac;
                 }
             }
             $channel = isset($array['channel']) ? $array['channel'] : null;
             if ($channel != null && $channel != "") {
                 $params['channel'] = intval($channel);
             }
             $security = isset($array['security']) ? $array['security'] : null;
             if ($security != null && $security != '') {
                 $params['sec'] = intval($security);
             }
             $source = isset($array['source']) ? $array['source'] : null;
             if ($source != null && $source != "") {
                 $params['id_source'] = intval($source);
             }
             break;
         case WifiPresenter::MODE_ONE:
             $params['ssid'] = isset($array["ssid"]) ? $array["ssid"] : "";
             break;
         default:
             break;
     }
     return $params;
 }
Esempio n. 3
0
 /**
  * @param Nette\Http\IRequest $request
  * @param null|float                $click_lat
  * @param null|float                $click_lon
  * @return Nette\Database\Table\Selection
  */
 public function getClickQueryByMode(Nette\Http\IRequest $request, $click_lat = null, $click_lon = null)
 {
     if (!$click_lat && !$click_lon) {
         $click_lat = doubleval($request->getQuery("click_lat"));
         $click_lon = doubleval($request->getQuery("click_lon"));
     }
     $mapCoords = new Coords($request->getQuery("map_lat1"), $request->getQuery("map_lat2"), $request->getQuery("map_lon1"), $request->getQuery("map_lon2"));
     $lat1 = doubleval($click_lat) - self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLat();
     $lat2 = doubleval($click_lat) + self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLat();
     $lon1 = doubleval($click_lon) - self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLon();
     $lon2 = doubleval($click_lon) + self::CLICK_POINT_CIRCLE_RADIUS * $mapCoords->getDeltaLon();
     $requestCoords = new Coords($lat1, $lat2, $lon1, $lon2);
     switch ($request->getQuery("mode")) {
         case WifiPresenter::MODE_SEARCH:
             $params = array();
             if ($request->getQuery("ssidmac")) {
                 if (MyUtils::isMacAddress($request->getQuery("ssidmac"))) {
                     $params['mac'] = urldecode($request->getQuery("ssidmac"));
                 } else {
                     $params["ssid"] = $request->getQuery("ssidmac");
                 }
             }
             if ($request->getQuery("channel") != null && $request->getQuery("channel") != "") {
                 $params['channel'] = intval($request->getQuery("channel"));
             }
             if ($request->getQuery("security") != null && $request->getQuery("security") != "") {
                 $params['sec'] = intval($request->getQuery("security"));
             }
             if ($request->getQuery("source") != null && $request->getQuery("source") != "") {
                 $params['id_source'] = intval($request->getQuery("source"));
             }
             $sql = $this->getSearchQuery($requestCoords, $params);
             break;
         case WifiPresenter::MODE_ONE:
             $params['ssid'] = $request->getQuery('ssid');
             $sql = $this->getSearchQuery($requestCoords, $params);
             break;
         default:
             $sql = $this->getNetsRangeQuery($requestCoords);
     }
     $sql->select("*,SQRT(POW(latitude-?,2)+POW(longitude-?,2)) AS distance ", doubleval($click_lat), doubleval($click_lon));
     $sql->order("distance");
     return $sql;
 }
Esempio n. 4
0
 /**
  * @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;
 }
Esempio n. 5
0
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * change Wi-Fi object to associative array
  *
  * @param Wifi $wifi
  * @return array
  */
 private function prepareArrayForDB(Wifi $wifi)
 {
     $wifi->synchronizeSecurity();
     $array = array("id_source" => $wifi->getSource(), "date_added" => date("Y-m-d"), "mac" => MyUtils::macSeparator2Colon($wifi->getMac()), "ssid" => $wifi->getSsid(), "sec" => $wifi->getSec(), "latitude" => $wifi->getLatitude(), "longitude" => $wifi->getLongitude(), "altitude" => $wifi->getAltitude(), "comment" => $wifi->getComment(), "name" => $wifi->getName(), "type" => $wifi->getType(), "freenet" => $wifi->getFreenet(), "paynet" => $wifi->getPaynet(), "firsttime" => $wifi->getFirsttime(), "lasttime" => $wifi->getLasttime(), "flags" => $wifi->getFlags(), "wep" => $wifi->getWep(), "lastupdt" => $wifi->getLastupdt(), "channel" => $wifi->getChannel(), "bcninterval" => $wifi->getBcninterval(), "qos" => $wifi->getQos(), "accuracy" => $wifi->getAccuracy(), "calculated" => $wifi->getCalculated());
     return $array;
 }
Esempio n. 7
0
 /**
  * CRON -> run every 1 HOUR (?)
  * get one use created DownloadRequest, divide it by wifi density and add calculated records to wigle download queue
  *
  * @throws \Nette\Application\AbortException
  */
 public function renderProcessWigleRequest()
 {
     MyUtils::setIni(1200, '256M');
     $req = $this->downloadRequest->getEldestDownloadRequest(Service\WigleDownload::ID_SOURCE);
     if ($req) {
         $coords = new Coords($req->lat_start, $req->lat_end, $req->lon_start, $req->lon_end);
         $this->downloadQueue->generateLatLngDownloadArray($coords);
         $total_count = count($this->downloadQueue->getGeneratedCoords());
         $this->downloadQueue->save($req->id);
         $this->downloadRequest->setProcessed($req, $total_count);
     }
     $this->terminate();
 }
Esempio n. 8
0
 /**
  * accuracy page
  */
 public function renderAccuracy()
 {
     if ($this->getHttpRequest()->getQuery("mac") != "" && $this->getHttpRequest()->getQuery("r_latitude") != "" && $this->getHttpRequest()->getQuery("r_longitude") != "" && MyUtils::isMacAddress($this->getHttpRequest()->getQuery("mac"))) {
         $mac = MyUtils::macSeparator2Colon($this->getHttpRequest()->getQuery("mac"));
         $tableData = $this->wifiManager->getDistanceFromOriginalGPS($mac, doubleval($this->getHttpRequest()->getQuery("r_latitude")), doubleval($this->getHttpRequest()->getQuery("r_longitude")));
         $data = array();
         foreach ($tableData as $td) {
             $coords = new Coords($td["latitude"], $this->getHttpRequest()->getQuery("r_latitude"), $td["longitude"], $this->getHttpRequest()->getQuery("r_longitude"));
             $inM = $coords->getDistanceInMetres();
             $arr = $td;
             $arr["inM"] = $inM;
             $data[] = $arr;
         }
         usort($data, "self::Sort");
         $chWigleMin = PHP_INT_MAX;
         $chWigleMax = 0;
         $chWigleTotal = 0;
         $chGoogleMin = PHP_INT_MAX;
         $chGoogleMax = 0;
         $chGoogleTotal = 0;
         $chWigleAvg = 0;
         $wigleCount = 0;
         $wifileaksCount = 0;
         $wifileaksTotal = 0;
         $googleCount = 0;
         foreach ($data as $d) {
             if ($d["id_source"] == WifileaksDownload::ID_SOURCE) {
                 $wifileaksCount++;
                 $wifileaksTotal += $d["inM"];
             }
             if ($d["id_source"] == WigleDownload::ID_SOURCE) {
                 $wigleCount++;
                 if ($chWigleMin > $d["inM"]) {
                     $chWigleMin = $d["inM"];
                 }
                 if ($chWigleMax < $d["inM"]) {
                     $chWigleMax = $d["inM"];
                 }
                 $chWigleTotal += $d["inM"];
                 if ($d["calculated"] == 1) {
                     $chWigleAvg = $d["inM"];
                 }
             }
             if ($d["id_source"] == GoogleDownload::ID_SOURCE) {
                 $googleCount++;
                 if ($chGoogleMin > $d["inM"]) {
                     $chGoogleMin = $d["inM"];
                 }
                 if ($chGoogleMax < $d["inM"]) {
                     $chGoogleMax = $d["inM"];
                 }
                 $chGoogleTotal += $d["inM"];
             }
         }
         if ($chWigleAvg == 0) {
             $chWigleAvg = $chWigleTotal / $wigleCount;
         }
         $chGoogleAvg = $chGoogleTotal / $googleCount;
         $chWifileaks = $wifileaksTotal / $wifileaksCount;
         $this->template->chWifileaks = $chWifileaks;
         $this->template->chWigleMin = $chWigleMin;
         $this->template->chWigleMax = $chWigleMax;
         $this->template->chWigleAvg = $chWigleAvg;
         $this->template->chGoogleMin = $chGoogleMin;
         $this->template->chGoogleMax = $chGoogleMax;
         $this->template->chGoogleAvg = $chGoogleAvg;
         $this->template->table = $data;
     }
 }