|
43 | 43 | $endpoint = rtrim($endpoint, '/'); |
44 | 44 |
|
45 | 45 | if (!$apikey) { |
46 | | - logger($logfile, $apikey, null, 401); |
| 46 | + logger($logfile, ['req' => $requestCounter, 'proxyCode' => 401]); |
47 | 47 | apiResponse(401, ['error' => sprintf(APP_API_ERROR, 'no apikey provided')]); |
48 | 48 | } |
49 | 49 |
|
|
160 | 160 | $app = $starr->getStarrInterfaceNameFromId($proxiedApp['starrAppDetails']['starr']); |
161 | 161 |
|
162 | 162 | if (!$proxiedApp) { |
163 | | - logger($logfile, $apikey, $endpoint, 401); |
| 163 | + logger($logfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $endpoint, 'proxyCode' => 401]); |
164 | 164 | apiResponse(401, ['error' => sprintf(APP_API_ERROR, 'provided apikey is not valid or has no access')]); |
165 | 165 | } |
166 | 166 |
|
167 | 167 | $proxiedAppLogfile = str_replace('access.log', 'access_' . $proxiedApp['proxiedAppDetails']['name'] . '.log', $logfile); |
168 | 168 |
|
169 | | - logger($proxiedAppLogfile, '[req ' . $requestCounter . '] incoming request from apikey: ' . truncateMiddle($apikey, 20), null, 999); |
170 | | - logger($proxiedAppLogfile, '[req ' . $requestCounter . '] $starr->getAppFromProxiedKey: name=' . $proxiedApp['proxiedAppDetails']['name'] . ', id=' . $proxiedApp['proxiedAppDetails']['id'], null, 999); |
| 169 | + logger($proxiedAppLogfile, ['req' => $requestCounter, 'starr' => $proxiedApp['starrAppDetails']['name'], 'text' => 'apikey: ' . truncateMiddle($apikey, 20) . '; $starr->getAppFromProxiedKey: id=' . $proxiedApp['proxiedAppDetails']['id'] . '; app=' . $proxiedApp['proxiedAppDetails']['name']]); |
171 | 170 |
|
172 | 171 | if (!$endpoint && $_GET['backup']) { //--- Notifiarr corruption checking |
173 | 172 | $proxyBackup = $starr->downloadBackup($_GET['backup'], $proxiedApp['starrAppDetails']); |
|
186 | 185 | if ($isAllowed) { |
187 | 186 | $endpoint = $starrEndpoint; |
188 | 187 | } else { |
189 | | - logger($logfile, $apikey, $endpoint, 401); |
190 | | - logger($proxiedAppLogfile, $apikey, $endpoint, 401); |
| 188 | + logger($logfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $endpoint, 'proxyCode' => 401]); |
| 189 | + logger($proxiedAppLogfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $endpoint, 'proxyCode' => 401]); |
191 | 190 | $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], 401); |
192 | 191 |
|
193 | 192 | if ($proxyDb->isNotificationTriggerEnabled('blocked')) { |
|
204 | 203 | } |
205 | 204 |
|
206 | 205 | if (!$accessMethod = $starr->isAllowedEndpointMethod($proxiedApp['access'], $endpoint, $method)) { |
207 | | - logger($logfile, $apikey, $endpoint, 405); |
208 | | - logger($proxiedAppLogfile, $apikey, $endpoint, 405); |
| 206 | + logger($logfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $endpoint, 'proxyCode' => 405]); |
| 207 | + logger($proxiedAppLogfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $endpoint, 'proxyCode' => 405]); |
209 | 208 | $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], 405); |
210 | 209 |
|
211 | 210 | if ($proxyDb->isNotificationTriggerEnabled('blocked')) { |
|
225 | 224 | $starrUrl = $proxiedApp['starrAppDetails']['url'] . $originalEndpoint . ($variables ? '?' . http_build_query($variables) : ''); |
226 | 225 | $request = curl($starrUrl, ['X-Api-Key:' . $proxiedApp['starrAppDetails']['apikey']], $method, $json); |
227 | 226 |
|
228 | | - logger($logfile, $apikey, $endpoint, 200, $request['code']); |
229 | | - logger($proxiedAppLogfile, $apikey, $originalEndpoint, 200, $request['code'], $request); |
| 227 | + logger($logfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $originalEndpoint, 'proxyCode' => 200, 'starrCode' => $request['code']]); |
| 228 | + logger($proxiedAppLogfile, ['req' => $requestCounter, 'apikey' => $apikey, 'endpoint' => $originalEndpoint, 'proxyCode' => 200, 'starrCode' => $request['code'], 'starrRequest' => $request]); |
| 229 | + |
230 | 230 | $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], $request['code']); |
231 | 231 |
|
232 | 232 | if ($request['code'] <= 299 && str_contains($endpoint, 'mediacover')) { //-- OUTPUT THE REQUESTED IMAGE |
|
0 commit comments