@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('firewall', function (Blueprint $table) { |
|
| 16 | + Schema::create('firewall', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | |
| 19 | 19 | $table->string('ip_address', 39)->unique()->index(); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | private function getNotifiableUsers() |
| 15 | 15 | { |
| 16 | - return collect(config('firewall.notifications.users.emails'))->map(function ($item) { |
|
| 16 | + return collect(config('firewall.notifications.users.emails'))->map(function($item) { |
|
| 17 | 17 | if (class_exists($class = config('firewall.notifications.users.model'))) { |
| 18 | 18 | $model = app($class); |
| 19 | 19 | |
@@ -55,21 +55,21 @@ |
||
| 55 | 55 | }) |
| 56 | 56 | ->attachment(function ($attachment) use ($item) { |
| 57 | 57 | $attachment->title($title = config('firewall.notifications.message.uri.title')) |
| 58 | - ->content($item['server']['REQUEST_URI']); |
|
| 58 | + ->content($item['server']['REQUEST_URI']); |
|
| 59 | 59 | }) |
| 60 | 60 | ->attachment(function ($attachment) use ($item) { |
| 61 | 61 | $attachment->title(config('firewall.notifications.message.user_agent.title')) |
| 62 | - ->content($item['userAgent']); |
|
| 62 | + ->content($item['userAgent']); |
|
| 63 | 63 | }) |
| 64 | 64 | ->attachment(function ($attachment) use ($item) { |
| 65 | 65 | $attachment->title(config('firewall.notifications.message.blacklisted.title')) |
| 66 | - ->content($item['isBlacklisted'] ? 'YES' : 'NO'); |
|
| 66 | + ->content($item['isBlacklisted'] ? 'YES' : 'NO'); |
|
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | 69 | if ($item['geoIp']) { |
| 70 | 70 | $message->attachment(function ($attachment) use ($item) { |
| 71 | 71 | $attachment->title(config('firewall.notifications.message.geolocation.title')) |
| 72 | - ->fields($this->makeGeolocation($item)); |
|
| 72 | + ->fields($this->makeGeolocation($item)); |
|
| 73 | 73 | }); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | config('firewall.notifications.from.icon_emoji') |
| 43 | 43 | ) |
| 44 | 44 | ->content($this->getMessage($item)) |
| 45 | - ->attachment(function ($attachment) use ($item) { |
|
| 45 | + ->attachment(function($attachment) use ($item) { |
|
| 46 | 46 | $attachment->title(config('firewall.notifications.message.request_count.title')) |
| 47 | 47 | ->content( |
| 48 | 48 | sprintf( |
@@ -53,21 +53,21 @@ discard block |
||
| 53 | 53 | ) |
| 54 | 54 | ); |
| 55 | 55 | }) |
| 56 | - ->attachment(function ($attachment) use ($item) { |
|
| 56 | + ->attachment(function($attachment) use ($item) { |
|
| 57 | 57 | $attachment->title($title = config('firewall.notifications.message.uri.title')) |
| 58 | 58 | ->content($item['server']['REQUEST_URI']); |
| 59 | 59 | }) |
| 60 | - ->attachment(function ($attachment) use ($item) { |
|
| 60 | + ->attachment(function($attachment) use ($item) { |
|
| 61 | 61 | $attachment->title(config('firewall.notifications.message.user_agent.title')) |
| 62 | 62 | ->content($item['userAgent']); |
| 63 | 63 | }) |
| 64 | - ->attachment(function ($attachment) use ($item) { |
|
| 64 | + ->attachment(function($attachment) use ($item) { |
|
| 65 | 65 | $attachment->title(config('firewall.notifications.message.blacklisted.title')) |
| 66 | 66 | ->content($item['isBlacklisted'] ? 'YES' : 'NO'); |
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | 69 | if ($item['geoIp']) { |
| 70 | - $message->attachment(function ($attachment) use ($item) { |
|
| 70 | + $message->attachment(function($attachment) use ($item) { |
|
| 71 | 71 | $attachment->title(config('firewall.notifications.message.geolocation.title')) |
| 72 | 72 | ->fields($this->makeGeolocation($item)); |
| 73 | 73 | }); |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | { |
| 51 | 51 | $country = $this->makeCountryFromString($country); |
| 52 | 52 | |
| 53 | - return $this->ipList()->all()->filter(function ($item) use ($country) { |
|
| 53 | + return $this->ipList()->all()->filter(function($item) use ($country) { |
|
| 54 | 54 | return $item['ip_address'] == $country || |
| 55 | 55 | $this->makeCountryFromString($this->getCountryFromIp($item['ip_address'])) == $country; |
| 56 | 56 | }); |
@@ -33,8 +33,8 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | public function addMessage($message) |
| 35 | 35 | { |
| 36 | - collect((array) $message)->each(function ($item) { |
|
| 37 | - collect($item)->flatten()->each(function ($flattened) { |
|
| 36 | + collect((array) $message)->each(function($item) { |
|
| 37 | + collect($item)->flatten()->each(function($flattened) { |
|
| 38 | 38 | $this->messageList->push($flattened); |
| 39 | 39 | }); |
| 40 | 40 | }); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | private function registerAttackBlocker() |
| 144 | 144 | { |
| 145 | - $this->app->singleton('firewall.attackBlocker', function () { |
|
| 145 | + $this->app->singleton('firewall.attackBlocker', function() { |
|
| 146 | 146 | return new AttackBlocker(); |
| 147 | 147 | }); |
| 148 | 148 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | private function registerCountriesRepository() |
| 154 | 154 | { |
| 155 | - $this->app->singleton('firewall.countries', function () { |
|
| 155 | + $this->app->singleton('firewall.countries', function() { |
|
| 156 | 156 | return new Countries(); |
| 157 | 157 | }); |
| 158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | private function registerBlacklistCommand() |
| 166 | 166 | { |
| 167 | - $this->app->singleton('firewall.blacklist.command', function () { |
|
| 167 | + $this->app->singleton('firewall.blacklist.command', function() { |
|
| 168 | 168 | return new BlacklistCommand(); |
| 169 | 169 | }); |
| 170 | 170 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | private function registerCache() |
| 180 | 180 | { |
| 181 | - $this->app->singleton('firewall.cache', function () { |
|
| 181 | + $this->app->singleton('firewall.cache', function() { |
|
| 182 | 182 | return new Cache(app('cache')); |
| 183 | 183 | }); |
| 184 | 184 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | private function registerClearCommand() |
| 192 | 192 | { |
| 193 | - $this->app->singleton('firewall.clear.command', function () { |
|
| 193 | + $this->app->singleton('firewall.clear.command', function() { |
|
| 194 | 194 | return new ClearCommand(); |
| 195 | 195 | }); |
| 196 | 196 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | private function registerDataRepository() |
| 206 | 206 | { |
| 207 | - $this->app->singleton('firewall.datarepository', function () { |
|
| 207 | + $this->app->singleton('firewall.datarepository', function() { |
|
| 208 | 208 | return new DataRepository(); |
| 209 | 209 | }); |
| 210 | 210 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | private function registerFileSystem() |
| 226 | 226 | { |
| 227 | - $this->app->singleton('firewall.filesystem', function () { |
|
| 227 | + $this->app->singleton('firewall.filesystem', function() { |
|
| 228 | 228 | return new Filesystem(); |
| 229 | 229 | }); |
| 230 | 230 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | private function registerFirewall() |
| 239 | 239 | { |
| 240 | - $this->app->singleton('firewall', function ($app) { |
|
| 240 | + $this->app->singleton('firewall', function($app) { |
|
| 241 | 241 | $app['firewall.loaded'] = true; |
| 242 | 242 | |
| 243 | 243 | $this->firewall = new Firewall( |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | private function registerIpAddress() |
| 258 | 258 | { |
| 259 | - $this->app->singleton('firewall.ipaddress', function () { |
|
| 259 | + $this->app->singleton('firewall.ipaddress', function() { |
|
| 260 | 260 | return new IpAddress(); |
| 261 | 261 | }); |
| 262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | private function registerIpList() |
| 269 | 269 | { |
| 270 | - $this->app->singleton('firewall.iplist', function () { |
|
| 270 | + $this->app->singleton('firewall.iplist', function() { |
|
| 271 | 271 | return new IpList($this->getFirewallModel()); |
| 272 | 272 | }); |
| 273 | 273 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | private function registerMessageRepository() |
| 280 | 280 | { |
| 281 | - $this->app->singleton('firewall.messages', function () { |
|
| 281 | + $this->app->singleton('firewall.messages', function() { |
|
| 282 | 282 | return new Message(); |
| 283 | 283 | }); |
| 284 | 284 | } |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | private function registerMiddleware() |
| 292 | 292 | { |
| 293 | - $this->app->singleton('firewall.middleware.blacklist', function () { |
|
| 293 | + $this->app->singleton('firewall.middleware.blacklist', function() { |
|
| 294 | 294 | return new FirewallBlacklist(new Blacklist()); |
| 295 | 295 | }); |
| 296 | 296 | |
| 297 | - $this->app->singleton('firewall.middleware.whitelist', function () { |
|
| 297 | + $this->app->singleton('firewall.middleware.whitelist', function() { |
|
| 298 | 298 | return new FirewallWhitelist(new Whitelist()); |
| 299 | 299 | }); |
| 300 | 300 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | private function registerGeoIp() |
| 308 | 308 | { |
| 309 | - $this->app->singleton('firewall.geoip', function () { |
|
| 309 | + $this->app->singleton('firewall.geoip', function() { |
|
| 310 | 310 | return new GeoIp($this->getConfig('geoip_database_path')); |
| 311 | 311 | }); |
| 312 | 312 | } |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | private function registerRemoveCommand() |
| 320 | 320 | { |
| 321 | - $this->app->singleton('firewall.remove.command', function () { |
|
| 321 | + $this->app->singleton('firewall.remove.command', function() { |
|
| 322 | 322 | return new RemoveCommand(); |
| 323 | 323 | }); |
| 324 | 324 | |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | private function registerReportCommand() |
| 334 | 334 | { |
| 335 | - $this->app->singleton('firewall.list.command', function () { |
|
| 335 | + $this->app->singleton('firewall.list.command', function() { |
|
| 336 | 336 | return new ReportCommand(); |
| 337 | 337 | }); |
| 338 | 338 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | private function registerUpdateGeoIpCommand() |
| 346 | 346 | { |
| 347 | - $this->app->singleton('firewall.updategeoip.command', function () { |
|
| 347 | + $this->app->singleton('firewall.updategeoip.command', function() { |
|
| 348 | 348 | return new UpdateGeoIpCommand(); |
| 349 | 349 | }); |
| 350 | 350 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | */ |
| 359 | 359 | private function registerWhitelistCommand() |
| 360 | 360 | { |
| 361 | - $this->app->singleton('firewall.whitelist.command', function () { |
|
| 361 | + $this->app->singleton('firewall.whitelist.command', function() { |
|
| 362 | 362 | return new WhitelistCommand(); |
| 363 | 363 | }); |
| 364 | 364 | |
@@ -5,8 +5,6 @@ |
||
| 5 | 5 | use Carbon\Carbon; |
| 6 | 6 | use PragmaRX\Firewall\Events\AttackDetected; |
| 7 | 7 | use PragmaRX\Firewall\Firewall; |
| 8 | -use PragmaRX\Firewall\Repositories\Cache\Cache; |
|
| 9 | -use PragmaRX\Support\Config; |
|
| 10 | 8 | |
| 11 | 9 | class AttackBlocker |
| 12 | 10 | { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * Check for attacks. |
| 233 | 233 | * |
| 234 | - * @param $ipAddress |
|
| 234 | + * @param null|string $ipAddress |
|
| 235 | 235 | * |
| 236 | 236 | * @return bool |
| 237 | 237 | */ |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | /** |
| 368 | 368 | * Make the cache key to record countries. |
| 369 | 369 | * |
| 370 | - * @param $ipAddress |
|
| 370 | + * @param string $ipAddress |
|
| 371 | 371 | * |
| 372 | 372 | * @return string|null |
| 373 | 373 | */ |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | protected function checkExpiration() |
| 121 | 121 | { |
| 122 | - $this->enabledItems->each(function ($index, $type) { |
|
| 122 | + $this->enabledItems->each(function($index, $type) { |
|
| 123 | 123 | if (($this->now()->diffInSeconds($this->record[$type]['lastRequestAt'])) <= ($this->getMaxSecondsForType($type))) { |
| 124 | 124 | return $this->record; |
| 125 | 125 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | protected function increment() |
| 209 | 209 | { |
| 210 | - $this->enabledItems->each(function ($index, $type) { |
|
| 210 | + $this->enabledItems->each(function($index, $type) { |
|
| 211 | 211 | $this->save($type, ['requestCount' => $this->record[$type]['requestCount'] + 1]); |
| 212 | 212 | }); |
| 213 | 213 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | protected function isAttack() |
| 221 | 221 | { |
| 222 | - return $this->enabledItems->filter(function ($index, $type) { |
|
| 222 | + return $this->enabledItems->filter(function($index, $type) { |
|
| 223 | 223 | if (!$this->isWhitelisted($type) && $this->record[$type]['requestCount'] > $this->getMaxRequestCountForType($type)) { |
| 224 | 224 | $this->takeAction($this->record[$type]); |
| 225 | 225 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | private function loadConfig() |
| 278 | 278 | { |
| 279 | - $this->enabledItems = collect($this->config()->get('attack_blocker.enabled'))->filter(function ($item) { |
|
| 279 | + $this->enabledItems = collect($this->config()->get('attack_blocker.enabled'))->filter(function($item) { |
|
| 280 | 280 | return $item === true; |
| 281 | 281 | }); |
| 282 | 282 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | protected function loadRecordItems() |
| 308 | 308 | { |
| 309 | - $this->enabledItems->each(function ($index, $type) { |
|
| 309 | + $this->enabledItems->each(function($index, $type) { |
|
| 310 | 310 | if (is_null($this->record[$type] = $this->cache()->get($key = $this->makeKeyForType($type, $this->ipAddress)))) { |
| 311 | 311 | $this->record[$type] = $this->getEmptyRecord($key, $type); |
| 312 | 312 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | if (!$record['wasNotified'] && $this->config()->get('notifications.enabled')) { |
| 460 | 460 | $this->save($record['type'], ['wasNotified' => true]); |
| 461 | 461 | |
| 462 | - collect($this->config()->get('notifications.channels'))->filter(function ($value, $channel) use ($record) { |
|
| 462 | + collect($this->config()->get('notifications.channels'))->filter(function($value, $channel) use ($record) { |
|
| 463 | 463 | event(new AttackDetected($record, $channel)); |
| 464 | 464 | }); |
| 465 | 465 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | /** |
| 131 | 131 | * Clear firewall table. |
| 132 | 132 | * |
| 133 | - * @return mixed |
|
| 133 | + * @return integer |
|
| 134 | 134 | */ |
| 135 | 135 | public function clear() |
| 136 | 136 | { |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | /** |
| 239 | 239 | * Get the list of all IP addresses stored. |
| 240 | 240 | * |
| 241 | - * @return mixed |
|
| 241 | + * @return \Illuminate\Support\Collection |
|
| 242 | 242 | */ |
| 243 | 243 | public function report() |
| 244 | 244 | { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @param $ip |
| 276 | 276 | * |
| 277 | - * @return bool|string |
|
| 277 | + * @return null|string |
|
| 278 | 278 | */ |
| 279 | 279 | public function whichList($ip) |
| 280 | 280 | { |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | /** |
| 324 | 324 | * Get a response to the attack. |
| 325 | 325 | * |
| 326 | - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse|null |
|
| 326 | + * @return null|\Illuminate\Http\Response |
|
| 327 | 327 | */ |
| 328 | 328 | public function responseToAttack() |
| 329 | 329 | { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * |
| 336 | 336 | * @param $ip |
| 337 | 337 | * |
| 338 | - * @return bool|string |
|
| 338 | + * @return string|null |
|
| 339 | 339 | */ |
| 340 | 340 | public function getCountryFromIp($ip) |
| 341 | 341 | { |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | /** |
| 358 | 358 | * Get the GeoIP instance. |
| 359 | 359 | * |
| 360 | - * @return object |
|
| 360 | + * @return \PragmaRX\Support\GeoIp\GeoIp |
|
| 361 | 361 | */ |
| 362 | 362 | public function getGeoIp() |
| 363 | 363 | { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Check if cache has key. |
| 49 | 49 | * |
| 50 | - * @param $key |
|
| 50 | + * @param string $key |
|
| 51 | 51 | * |
| 52 | 52 | * @return bool |
| 53 | 53 | */ |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Get a value from the cache. |
| 65 | 65 | * |
| 66 | - * @param $key |
|
| 66 | + * @param string|null $key |
|
| 67 | 67 | * |
| 68 | - * @return mixed|null |
|
| 68 | + * @return \Illuminate\Contracts\Cache\Repository|null |
|
| 69 | 69 | */ |
| 70 | 70 | public function get($key) |
| 71 | 71 | { |