@@ -23,8 +23,8 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function addMessage($message) |
| 25 | 25 | { |
| 26 | - collect((array) $message)->each(function ($item) { |
|
| 27 | - collect($item)->flatten()->each(function ($flattened) { |
|
| 26 | + collect((array) $message)->each(function($item) { |
|
| 27 | + collect($item)->flatten()->each(function($flattened) { |
|
| 28 | 28 | $this->messages->push($flattened); |
| 29 | 29 | }); |
| 30 | 30 | }); |
@@ -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(); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function checkExpiration() |
| 138 | 138 | { |
| 139 | - $this->enabledItems->each(function ($index, $type) { |
|
| 139 | + $this->enabledItems->each(function($index, $type) { |
|
| 140 | 140 | if (($this->record[$type]['lastRequestAt']->diffInSeconds(Carbon::now())) <= ($this->getMaxSecondsForType($type))) { |
| 141 | 141 | return $this->record; |
| 142 | 142 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | protected function increment() |
| 253 | 253 | { |
| 254 | - $this->enabledItems->each(function ($index, $type) { |
|
| 254 | + $this->enabledItems->each(function($index, $type) { |
|
| 255 | 255 | $this->save($type, ['requestCount' => $this->record[$type]['requestCount'] + 1]); |
| 256 | 256 | }); |
| 257 | 257 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | protected function isAttack() |
| 265 | 265 | { |
| 266 | - return $this->enabledItems->filter(function ($index, $type) { |
|
| 266 | + return $this->enabledItems->filter(function($index, $type) { |
|
| 267 | 267 | if (!$this->isWhitelisted($type) && $isAttack = $this->record[$type]['requestCount'] > $this->getMaxRequestCountForType($type)) { |
| 268 | 268 | // $this->takeAction($this->record[$type]); |
| 269 | 269 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | private function loadConfig() |
| 318 | 318 | { |
| 319 | - $this->enabledItems = collect($this->config->get('attack_blocker.enabled'))->filter(function ($item) { |
|
| 319 | + $this->enabledItems = collect($this->config->get('attack_blocker.enabled'))->filter(function($item) { |
|
| 320 | 320 | return $item === true; |
| 321 | 321 | }); |
| 322 | 322 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | protected function loadRecordItems() |
| 346 | 346 | { |
| 347 | - $this->enabledItems->each(function ($index, $type) { |
|
| 347 | + $this->enabledItems->each(function($index, $type) { |
|
| 348 | 348 | if (is_null($this->record[$type] = $this->cache->get($key = $this->makeKeyForType($type, $this->ipAddress)))) { |
| 349 | 349 | $this->record[$type] = $this->getEmptyRecord($key, $type); |
| 350 | 350 | } |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | if (!$record['wasNotified'] && $this->config->get('notifications.enabled')) { |
| 481 | 481 | $this->save($record['type'], ['wasNotified' => true]); |
| 482 | 482 | |
| 483 | - collect($this->config->get('notifications.channels'))->filter(function ($value, $channel) use ($record) { |
|
| 483 | + collect($this->config->get('notifications.channels'))->filter(function($value, $channel) use ($record) { |
|
| 484 | 484 | try { |
| 485 | 485 | event(new AttackDetected($record, $channel)); |
| 486 | 486 | } catch (\Exception $exception) { |
@@ -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 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | private function registerAttackBlocker() |
| 136 | 136 | { |
| 137 | - $this->app->singleton('firewall.attackBlocker', function ($app) { |
|
| 137 | + $this->app->singleton('firewall.attackBlocker', function($app) { |
|
| 138 | 138 | return new AttackBlocker( |
| 139 | 139 | $app['firewall.config'], |
| 140 | 140 | $app['firewall.cache'] |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | private function registerBlacklistCommand() |
| 151 | 151 | { |
| 152 | - $this->app->singleton('firewall.blacklist.command', function ($app) { |
|
| 152 | + $this->app->singleton('firewall.blacklist.command', function($app) { |
|
| 153 | 153 | return new BlacklistCommand(); |
| 154 | 154 | }); |
| 155 | 155 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | private function registerCache() |
| 165 | 165 | { |
| 166 | - $this->app->singleton('firewall.cache', function ($app) { |
|
| 166 | + $this->app->singleton('firewall.cache', function($app) { |
|
| 167 | 167 | return new CacheManager($app); |
| 168 | 168 | }); |
| 169 | 169 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | private function registerClearCommand() |
| 177 | 177 | { |
| 178 | - $this->app->singleton('firewall.clear.command', function ($app) { |
|
| 178 | + $this->app->singleton('firewall.clear.command', function($app) { |
|
| 179 | 179 | return new ClearCommand(); |
| 180 | 180 | }); |
| 181 | 181 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | private function registerDataRepository() |
| 191 | 191 | { |
| 192 | - $this->app->singleton('firewall.dataRepository', function ($app) { |
|
| 192 | + $this->app->singleton('firewall.dataRepository', function($app) { |
|
| 193 | 193 | return new DataRepository( |
| 194 | 194 | $this->getFirewallModel(), |
| 195 | 195 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | private function registerFileSystem() |
| 223 | 223 | { |
| 224 | - $this->app->singleton('firewall.fileSystem', function ($app) { |
|
| 224 | + $this->app->singleton('firewall.fileSystem', function($app) { |
|
| 225 | 225 | return new Filesystem(); |
| 226 | 226 | }); |
| 227 | 227 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | private function registerFirewall() |
| 236 | 236 | { |
| 237 | - $this->app->singleton('firewall', function ($app) { |
|
| 237 | + $this->app->singleton('firewall', function($app) { |
|
| 238 | 238 | $app['firewall.loaded'] = true; |
| 239 | 239 | |
| 240 | 240 | $this->firewall = new Firewall( |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | private function registerMessageRepository() |
| 261 | 261 | { |
| 262 | - $this->app->singleton('firewall.message', function ($app) { |
|
| 262 | + $this->app->singleton('firewall.message', function($app) { |
|
| 263 | 263 | return new Message(); |
| 264 | 264 | }); |
| 265 | 265 | } |
@@ -271,11 +271,11 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | private function registerMiddleware() |
| 273 | 273 | { |
| 274 | - $this->app->singleton('firewall.middleware.blacklist', function ($app) { |
|
| 274 | + $this->app->singleton('firewall.middleware.blacklist', function($app) { |
|
| 275 | 275 | return new FirewallBlacklist(new Blacklist()); |
| 276 | 276 | }); |
| 277 | 277 | |
| 278 | - $this->app->singleton('firewall.middleware.whitelist', function ($app) { |
|
| 278 | + $this->app->singleton('firewall.middleware.whitelist', function($app) { |
|
| 279 | 279 | return new FirewallWhitelist(new Whitelist()); |
| 280 | 280 | }); |
| 281 | 281 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | private function registerGeoIp() |
| 289 | 289 | { |
| 290 | - $this->app->singleton('firewall.geoip', function () { |
|
| 290 | + $this->app->singleton('firewall.geoip', function() { |
|
| 291 | 291 | return new GeoIp($this->getConfig('geoip_database_path')); |
| 292 | 292 | }); |
| 293 | 293 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | private function registerRemoveCommand() |
| 301 | 301 | { |
| 302 | - $this->app->singleton('firewall.remove.command', function ($app) { |
|
| 302 | + $this->app->singleton('firewall.remove.command', function($app) { |
|
| 303 | 303 | return new RemoveCommand(); |
| 304 | 304 | }); |
| 305 | 305 | |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | private function registerReportCommand() |
| 315 | 315 | { |
| 316 | - $this->app->singleton('firewall.list.command', function ($app) { |
|
| 316 | + $this->app->singleton('firewall.list.command', function($app) { |
|
| 317 | 317 | return new ReportCommand(); |
| 318 | 318 | }); |
| 319 | 319 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | private function registerUpdateGeoIpCommand() |
| 327 | 327 | { |
| 328 | - $this->app->singleton('firewall.updategeoip.command', function ($app) { |
|
| 328 | + $this->app->singleton('firewall.updategeoip.command', function($app) { |
|
| 329 | 329 | return new UpdateGeoIpCommand(); |
| 330 | 330 | }); |
| 331 | 331 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | private function registerWhitelistCommand() |
| 341 | 341 | { |
| 342 | - $this->app->singleton('firewall.whitelist.command', function ($app) { |
|
| 342 | + $this->app->singleton('firewall.whitelist.command', function($app) { |
|
| 343 | 343 | return new WhitelistCommand(); |
| 344 | 344 | }); |
| 345 | 345 | |
@@ -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 | }); |
@@ -240,8 +240,7 @@ discard block |
||
| 240 | 240 | public function addToProperList($whitelist, $ip) |
| 241 | 241 | { |
| 242 | 242 | $this->config->get('use_database') ? |
| 243 | - $this->addToDatabaseList($whitelist, $ip) : |
|
| 244 | - $this->addToArrayList($whitelist, $ip); |
|
| 243 | + $this->addToDatabaseList($whitelist, $ip) : $this->addToArrayList($whitelist, $ip); |
|
| 245 | 244 | } |
| 246 | 245 | |
| 247 | 246 | /** |
@@ -254,8 +253,7 @@ discard block |
||
| 254 | 253 | public function delete($ipAddress) |
| 255 | 254 | { |
| 256 | 255 | $this->config->get('use_database') ? |
| 257 | - $this->removeFromDatabaseList($ipAddress) : |
|
| 258 | - $this->removeFromArrayList($ipAddress); |
|
| 256 | + $this->removeFromDatabaseList($ipAddress) : $this->removeFromArrayList($ipAddress); |
|
| 259 | 257 | } |
| 260 | 258 | |
| 261 | 259 | /** |
@@ -364,7 +362,7 @@ discard block |
||
| 364 | 362 | { |
| 365 | 363 | $country = $this->makeCountryFromString($country); |
| 366 | 364 | |
| 367 | - return $this->all()->filter(function ($item) use ($country) { |
|
| 365 | + return $this->all()->filter(function($item) use ($country) { |
|
| 368 | 366 | return $item['ip_address'] == $country || |
| 369 | 367 | $this->makeCountryFromString($this->getCountryFromIp($item['ip_address'])) == $country; |
| 370 | 368 | }); |
@@ -430,13 +428,13 @@ discard block |
||
| 430 | 428 | private function getNonDatabaseIps() |
| 431 | 429 | { |
| 432 | 430 | return array_merge_recursive( |
| 433 | - array_map(function ($ip) { |
|
| 431 | + array_map(function($ip) { |
|
| 434 | 432 | $ip['whitelisted'] = true; |
| 435 | 433 | |
| 436 | 434 | return $ip; |
| 437 | 435 | }, $this->formatIpArray($this->config->get('whitelist'))), |
| 438 | 436 | |
| 439 | - array_map(function ($ip) { |
|
| 437 | + array_map(function($ip) { |
|
| 440 | 438 | $ip['whitelisted'] = false; |
| 441 | 439 | |
| 442 | 440 | return $ip; |
@@ -555,7 +553,7 @@ discard block |
||
| 555 | 553 | */ |
| 556 | 554 | private function formatIpArray($list) |
| 557 | 555 | { |
| 558 | - return array_map(function ($ip) { |
|
| 556 | + return array_map(function($ip) { |
|
| 559 | 557 | return ['ip_address' => $ip]; |
| 560 | 558 | }, $this->makeArrayOfIps($list)); |
| 561 | 559 | } |