1 | <?php |
||
21 | class PageController extends Controller { |
||
22 | |||
23 | private $userId; |
||
24 | private $cacheManager; |
||
25 | 1 | private $deviceMapper; |
|
26 | private $apiKeyMapper; |
||
27 | public function __construct($appName, IRequest $request, $userId, |
||
28 | 1 | CacheManager $cacheManager, |
|
29 | 1 | DeviceMapper $deviceMapper, |
|
30 | 1 | ApiKeyMapper $apiKeyMapper) { |
|
31 | 1 | parent::__construct($appName, $request); |
|
32 | 1 | $this -> userId = $userId; |
|
33 | $this -> cacheManager = $cacheManager; |
||
34 | $this -> deviceMapper = $deviceMapper; |
||
35 | $this -> apiKeyMapper = $apiKeyMapper; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * CAUTION: the @Stuff turn off security checks, for this page no admin is |
||
40 | * required and no CSRF check. If you don't know what CSRF is, read |
||
41 | * it up in the docs or you might create a security hole. This is |
||
42 | * basically the only required method to add this exemption, don't |
||
43 | * add it to any other method if you don't exactly know what it does |
||
44 | 1 | * |
|
45 | * @NoAdminRequired |
||
46 | 1 | * @NoCSRFRequired |
|
47 | 1 | */ |
|
48 | 1 | public function index() { |
|
49 | 1 | ||
50 | $params = array('user' => $this -> userId,'devices'=>$this->deviceMapper->findAll($this->userId)); |
||
51 | 1 | $response = new TemplateResponse('maps', 'main', $params); |
|
52 | if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
||
53 | 1 | $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
54 | // map tiles |
||
55 | 1 | $csp->addAllowedImageDomain('http://*.mqcdn.com'); |
|
56 | 1 | // marker icons |
|
57 | 1 | $csp->addAllowedImageDomain('https://api.tiles.mapbox.com'); |
|
58 | 1 | // inline images |
|
59 | $csp->addAllowedScriptDomain('data:'); |
||
60 | $tmpkey = $this->apiKeyMapper->findByUser($this->userId); |
||
61 | if($tmpkey->apiKey != null && strlen($tmpkey->apiKey) > 0) { |
||
62 | // mapzen geocoder |
||
63 | $csp->addAllowedConnectDomain('http://search.mapzen.com/v1/search?'); |
||
64 | $csp->addAllowedConnectDomain('http://search.mapzen.com/v1/reverse?'); |
||
65 | } else { |
||
66 | // nominatim geocoder |
||
67 | $csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/search?q=*'); |
||
68 | $csp->addAllowedScriptDomain('http://nominatim.openstreetmap.org/reverse'); |
||
69 | $csp->addAllowedConnectDomain('http://router.project-osrm.org'); |
||
70 | } |
||
71 | $response->setContentSecurityPolicy($csp); |
||
72 | } |
||
73 | return $response; |
||
74 | // templates/main.php |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get an layer |
||
79 | * @NoAdminRequired |
||
80 | * @NoCSRFRequired |
||
81 | */ |
||
82 | public function getlayer() { |
||
92 | |||
93 | /** |
||
94 | * Simply method that posts back the payload of the request |
||
95 | * @NoAdminRequired |
||
96 | * @NoCSRFRequired |
||
97 | */ |
||
98 | public function doProxy($echo) { |
||
99 | $url = ($this -> params('url')) ? $this -> params('url') : ''; |
||
100 | $allowedHosts = array('overpass.osm.rambler.ru', 'overpass-api.de', 'dev.virtualearth.net', 'router.project-osrm.org', 'nominatim.openstreetmap.org', 'maps.googleapis.com'); |
||
101 | $parseUrl = parse_url($url); |
||
102 | |||
103 | if (in_array($parseUrl['host'], $allowedHosts)) { |
||
104 | header('Content-Type: application/javascript'); |
||
105 | $split = explode('url=', $_SERVER['REQUEST_URI']); |
||
106 | echo $this -> getURL($split[1]); |
||
107 | } |
||
108 | die(); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Simply method that posts back the payload of the request |
||
113 | * @NoAdminRequired |
||
114 | * @NoCSRFRequired |
||
115 | */ |
||
116 | public function search() { |
||
117 | $cm = \OC::$server -> getContactsManager(); |
||
118 | $kw = $this -> params('search'); |
||
119 | $bbox = $this -> params('bbox'); |
||
120 | $response = array('contacts'=>array(),'nodes'=>array(),'addresses'=>array()); |
||
121 | |||
122 | $contacts = $cm -> search($kw, array('FN', 'ADR')); |
||
123 | foreach ($contacts as $r) { |
||
124 | $data = array(); |
||
|
|||
125 | $contact = $r; |
||
126 | for($i=0; $i<count($r['ADR']); $i++){ |
||
127 | $lookupAdr = implode(',', array_filter($r['ADR'][$i])); |
||
128 | $lookup = $this -> doAdresslookup($lookupAdr); |
||
129 | $contact ['location'][] = $lookup[0]; |
||
130 | } |
||
131 | array_push($response['contacts'],$contact); |
||
132 | } |
||
133 | $response['nodes'] = $this->bboxSearch($kw, $bbox); |
||
134 | $addresses = $this->doAdresslookup(urlencode($kw)); |
||
135 | foreach($addresses as $address){ |
||
136 | array_push($response['addresses'],$address); |
||
137 | if($address->osm_type === "node"){ |
||
138 | } |
||
139 | } |
||
140 | //$response['addresses'] = (array)($this->doAdresslookup($kw)); |
||
141 | |||
142 | return $response; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Simply method that posts back the payload of the request |
||
147 | * @NoAdminRequired |
||
148 | * @NoCSRFRequired |
||
149 | */ |
||
150 | public function geodecode(){ |
||
151 | $lat = $this->params('lat'); |
||
152 | $lng = $this->params('lng'); |
||
153 | $zoom = $this->params('zoom'); |
||
154 | |||
155 | $hash = md5($lat.','.$lng.'@'.$zoom); |
||
156 | |||
157 | $checkCache = $this -> checkGeoCache($hash); |
||
158 | if(!$checkCache){ |
||
159 | $url = 'http://nominatim.openstreetmap.org/reverse/?format=json&[email protected]&lat='.$lat.'&lng='. $lng.'&zoom=67108864'; |
||
160 | $response = $this->getURL($url,false); |
||
161 | if($response){ |
||
162 | $this -> cacheManager -> insert($hash, $response); |
||
163 | } |
||
164 | } else { |
||
165 | $response = $checkCache; |
||
166 | } |
||
167 | echo $response; |
||
168 | die(); |
||
169 | } |
||
170 | /** |
||
171 | * Simply method that posts back the payload of the request |
||
172 | * @NoAdminRequired |
||
173 | * @NoCSRFRequired |
||
174 | */ |
||
175 | public function adresslookup() { |
||
176 | // |
||
177 | $street = ($this -> params('street')) ? $this -> params('street') : ''; |
||
178 | $city = ($this -> params('city')) ? $this -> params('city') : ''; |
||
179 | $country = ($this -> params('country')) ? $this -> params('country') : ''; |
||
180 | |||
181 | $q = urlencode($street . ',' . $city . ',' . $country); |
||
182 | $r = (array) $this -> doAdresslookup($q); |
||
183 | echo json_encode($r[0]); |
||
184 | die(); |
||
185 | } |
||
186 | |||
187 | private function bboxSearch($q,$bbox){ |
||
194 | |||
195 | /** |
||
196 | * @param string $q |
||
197 | */ |
||
198 | private function doAdresslookup($q) { |
||
199 | |||
200 | $q = str_replace(" ", "+", $q); |
||
220 | |||
221 | /** |
||
222 | * @param string $hash |
||
223 | */ |
||
224 | private function checkGeoCache($hash) { |
||
227 | |||
228 | private function getURL($url, $userAgent = true) { |
||
250 | |||
251 | } |
||
252 |
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.