1 | <?php |
||
20 | class PageController extends Controller { |
||
21 | |||
22 | private $userId; |
||
23 | private $cacheManager; |
||
24 | private $deviceMapper; |
||
25 | 1 | public function __construct($appName, IRequest $request, $userId, |
|
33 | |||
34 | /** |
||
35 | * CAUTION: the @Stuff turn off security checks, for this page no admin is |
||
36 | * required and no CSRF check. If you don't know what CSRF is, read |
||
37 | * it up in the docs or you might create a security hole. This is |
||
38 | * basically the only required method to add this exemption, don't |
||
39 | * add it to any other method if you don't exactly know what it does |
||
40 | * |
||
41 | * @NoAdminRequired |
||
42 | * @NoCSRFRequired |
||
43 | */ |
||
44 | 1 | public function index() { |
|
45 | |||
46 | 1 | $params = array('user' => $this -> userId,'devices'=>$this->deviceMapper->findAll($this->userId)); |
|
47 | 1 | $response = new TemplateResponse('maps', 'main', $params); |
|
48 | 1 | if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
|
49 | 1 | $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
50 | // map tiles |
||
51 | 1 | $csp->addAllowedImageDomain('http://*.mqcdn.com'); |
|
52 | // marker icons |
||
53 | 1 | $csp->addAllowedImageDomain('https://api.tiles.mapbox.com'); |
|
54 | // inline images |
||
55 | 1 | $csp->addAllowedScriptDomain('data:'); |
|
56 | // nominatim geocoder |
||
57 | 1 | $csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/search?q=*'); |
|
58 | 1 | $csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/reverse'); |
|
59 | 1 | $csp->addAllowedConnectDomain('http://router.project-osrm.org'); |
|
60 | 1 | $response->setContentSecurityPolicy($csp); |
|
61 | } |
||
62 | 1 | return $response; |
|
63 | // templates/main.php |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get an layer |
||
68 | * @NoAdminRequired |
||
69 | * @NoCSRFRequired |
||
70 | */ |
||
71 | public function getlayer() { |
||
72 | $layer = ($this -> params('layer')) ? $this -> params('layer') : null; |
||
73 | if ($layer === "contacts") { |
||
74 | if (\OCP\App::isEnabled('contacts')) { |
||
75 | |||
76 | } else { |
||
77 | OCP\Util::writeLog('maps', "App contacts missing for Maps", \OCP\Util::WARN); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Simply method that posts back the payload of the request |
||
84 | * @NoAdminRequired |
||
85 | * @NoCSRFRequired |
||
86 | */ |
||
87 | public function doProxy($echo) { |
||
88 | $url = ($this -> params('url')) ? $this -> params('url') : ''; |
||
89 | $allowedHosts = array('overpass.osm.rambler.ru', 'overpass-api.de', 'dev.virtualearth.net', 'router.project-osrm.org', 'nominatim.openstreetmap.org', 'maps.googleapis.com'); |
||
90 | $parseUrl = parse_url($url); |
||
91 | |||
92 | if (in_array($parseUrl['host'], $allowedHosts)) { |
||
93 | header('Content-Type: application/javascript'); |
||
94 | $split = explode('url=', $_SERVER['REQUEST_URI']); |
||
95 | echo $this -> getURL($split[1]); |
||
96 | } |
||
97 | die(); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Simply method that posts back the payload of the request |
||
102 | * @NoAdminRequired |
||
103 | * @NoCSRFRequired |
||
104 | */ |
||
105 | public function search() { |
||
106 | $cm = \OC::$server -> getContactsManager(); |
||
107 | $kw = $this -> params('search'); |
||
108 | $bbox = $this -> params('bbox'); |
||
109 | $response = array('contacts'=>array(),'nodes'=>array(),'addresses'=>array()); |
||
110 | |||
111 | $contacts = $cm -> search($kw, array('FN', 'ADR')); |
||
112 | foreach ($contacts as $r) { |
||
113 | $data = array(); |
||
|
|||
114 | $contact = $r; |
||
115 | for($i=0; $i<count($r['ADR']); $i++){ |
||
116 | $lookupAdr = implode(',', array_filter($r['ADR'][$i])); |
||
117 | $lookup = $this -> doAdresslookup($lookupAdr); |
||
118 | $contact ['location'][] = $lookup[0]; |
||
119 | } |
||
120 | array_push($response['contacts'],$contact); |
||
121 | } |
||
122 | $response['nodes'] = $this->bboxSearch($kw, $bbox); |
||
123 | $addresses = $this->doAdresslookup(urlencode($kw)); |
||
124 | foreach($addresses as $address){ |
||
125 | array_push($response['addresses'],$address); |
||
126 | if($address->osm_type === "node"){ |
||
127 | } |
||
128 | } |
||
129 | //$response['addresses'] = (array)($this->doAdresslookup($kw)); |
||
130 | |||
131 | return $response; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Simply method that posts back the payload of the request |
||
136 | * @NoAdminRequired |
||
137 | * @NoCSRFRequired |
||
138 | */ |
||
139 | public function geodecode(){ |
||
140 | $lat = $this->params('lat'); |
||
141 | $lng = $this->params('lng'); |
||
142 | $zoom = $this->params('zoom'); |
||
143 | |||
144 | $hash = md5($lat.','.$lng.'@'.$zoom); |
||
145 | |||
146 | $checkCache = $this -> checkGeoCache($hash); |
||
147 | if(!$checkCache){ |
||
148 | $url = 'http://nominatim.openstreetmap.org/reverse/?format=json&[email protected]&lat='.$lat.'&lng='. $lng.'&zoom=67108864'; |
||
149 | $response = $this->getURL($url,false); |
||
150 | if($response){ |
||
151 | $this -> cacheManager -> insert($hash, $response); |
||
152 | } |
||
153 | } else { |
||
154 | $response = $checkCache; |
||
155 | } |
||
156 | echo $response; |
||
157 | die(); |
||
158 | } |
||
159 | /** |
||
160 | * Simply method that posts back the payload of the request |
||
161 | * @NoAdminRequired |
||
162 | * @NoCSRFRequired |
||
163 | */ |
||
164 | public function adresslookup() { |
||
175 | |||
176 | private function bboxSearch($q,$bbox){ |
||
183 | |||
184 | /** |
||
185 | * @param string $q |
||
186 | */ |
||
187 | private function doAdresslookup($q) { |
||
188 | |||
189 | $q = str_replace(" ", "+", $q); |
||
190 | $geohash = md5($q); |
||
191 | $checkCache = $this -> checkGeoCache($geohash); |
||
192 | if (!$checkCache) { |
||
193 | //$apiUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address='. str_replace(' ','+',$q) .'&key=AIzaSyAIHAIBv_uPKZgoxQt0ingc1gWsdAhG7So'; |
||
194 | //$apiUrl = 'http://nominatim.openstreetmap.org/search?format=json&street='. $street . '&city='.$city.'&country='.$country.'&limit=1'; |
||
195 | $apiUrl = 'http://nominatim.openstreetmap.org/search?format=json&q=' . $q; |
||
196 | $r = $this -> getURL($apiUrl, false); |
||
197 | $s = (array)json_decode($r); |
||
198 | |||
199 | $r -> apiUrl = $apiUrl; |
||
200 | $r = $s; |
||
201 | $this -> cacheManager -> insert($geohash, $s); |
||
202 | } else { |
||
203 | $checkCache -> cachedResult = true; |
||
204 | $r = $checkCache; |
||
205 | } |
||
206 | return $r; |
||
207 | |||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @param string $hash |
||
212 | */ |
||
213 | private function checkGeoCache($hash) { |
||
216 | |||
217 | private function getURL($url, $userAgent = true) { |
||
218 | $ch = curl_init(); |
||
219 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
||
220 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
221 | curl_setopt($ch, CURLOPT_TIMEOUT, 900); |
||
222 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
239 | |||
240 | } |
||
241 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.