@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('ip_lists', function (Blueprint $table) { |
|
| 16 | + Schema::create('ip_lists', function(Blueprint $table) { |
|
| 17 | 17 | $table->bigIncrements('id'); |
| 18 | 18 | $table->string('group'); |
| 19 | 19 | $table->string('definition'); |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use HayriCan\IpChecker\Contracts\IpCheckerInterface; |
| 6 | 6 | |
| 7 | -class DBDriver implements IpCheckerInterface{ |
|
| 7 | +class DBDriver implements IpCheckerInterface { |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Model for saving logs |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function getIpArray() |
| 26 | 26 | { |
| 27 | - foreach ($this->model->all() as $record){ |
|
| 28 | - array_push($this->ipList,$record->ip); |
|
| 27 | + foreach ($this->model->all() as $record) { |
|
| 28 | + array_push($this->ipList, $record->ip); |
|
| 29 | 29 | } |
| 30 | 30 | $ipList = $this->ipList ?? []; |
| 31 | 31 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | public function saveIp($array) |
| 48 | 48 | { |
| 49 | 49 | $result = IpList::create($array); |
| 50 | - if (!$result){ |
|
| 50 | + if (!$result) { |
|
| 51 | 51 | return false; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | public function deleteIp($ipAddress) |
| 62 | 62 | { |
| 63 | 63 | $response = false; |
| 64 | - $ipList = IpList::where('ip',$ipAddress)->first(); |
|
| 65 | - if ($ipList){ |
|
| 66 | - IpList::where('id',$ipList->id)->delete(); |
|
| 64 | + $ipList = IpList::where('ip', $ipAddress)->first(); |
|
| 65 | + if ($ipList) { |
|
| 66 | + IpList::where('id', $ipList->id)->delete(); |
|
| 67 | 67 | $response = true; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function saveIp($array) |
| 77 | 77 | { |
| 78 | - $array['created_at']=Carbon::now()->toDateTimeString(); |
|
| 78 | + $array['created_at'] = Carbon::now()->toDateTimeString(); |
|
| 79 | 79 | $filename = $this->getFilename(); |
| 80 | 80 | |
| 81 | 81 | $contents = implode(";", $array); |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | if (!is_dir($file)) { |
| 101 | 101 | $lines = file($this->path.DIRECTORY_SEPARATOR.$file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
| 102 | 102 | foreach ($lines as $line) { |
| 103 | - if (strpos($line, $ipAddress)){ |
|
| 103 | + if (strpos($line, $ipAddress)) { |
|
| 104 | 104 | $contents = file_get_contents($this->path.DIRECTORY_SEPARATOR.$file); |
| 105 | - $contents = str_replace($line,'',$contents); |
|
| 106 | - file_put_contents($this->path.DIRECTORY_SEPARATOR.$file,$contents); |
|
| 105 | + $contents = str_replace($line, '', $contents); |
|
| 106 | + file_put_contents($this->path.DIRECTORY_SEPARATOR.$file, $contents); |
|
| 107 | 107 | return true; |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param array $data |
| 123 | 123 | * @return IpList |
| 124 | 124 | */ |
| 125 | - public function mapArrayToModel(array $data){ |
|
| 125 | + public function mapArrayToModel(array $data) { |
|
| 126 | 126 | $model = new IpList(); |
| 127 | 127 | $model->group = $data[0]; |
| 128 | 128 | $model->definition = $data[1]; |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | public function getFilename() |
| 140 | 140 | { |
| 141 | 141 | $filename = 'iplist.php'; |
| 142 | - if (config('ipchecker.filename')){ |
|
| 142 | + if (config('ipchecker.filename')) { |
|
| 143 | 143 | $filename = config('ipchecker.filename'); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | * @link https://github.com/HayriCan/laravel-ip-checker |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -Route::group(['prefix'=>config('ipchecker.settings.route_prefix')], function () { |
|
| 11 | +Route::group(['prefix'=>config('ipchecker.settings.route_prefix')], function() { |
|
| 12 | 12 | Route::get('/iplists', 'HayriCan\IpChecker\Http\Controllers\IpCheckerController@index')->name('iplist.index'); |
| 13 | 13 | Route::post('/ip-add', 'HayriCan\IpChecker\Http\Controllers\IpCheckerController@add')->name('iplist.add'); |
| 14 | 14 | Route::delete('/ip-delete', 'HayriCan\IpChecker\Http\Controllers\IpCheckerController@delete')->name('iplist.delete'); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function register() |
| 29 | 29 | { |
| 30 | 30 | $this->mergeConfigFrom( |
| 31 | - __DIR__ . '/../config/ipchecker.php', 'ipchecker' |
|
| 31 | + __DIR__.'/../config/ipchecker.php', 'ipchecker' |
|
| 32 | 32 | ); |
| 33 | 33 | $this->bindServices(); |
| 34 | 34 | } |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | $this->loadConfig(); |
| 38 | 38 | $this->loadRoutes(); |
| 39 | 39 | $this->loadViews(); |
| 40 | - if (config('ipchecker.driver') === 'db'){ |
|
| 40 | + if (config('ipchecker.driver') === 'db') { |
|
| 41 | 41 | $this->loadMigrations(); |
| 42 | 42 | } |
| 43 | 43 | $this->loadTranslation(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function bindServices(){ |
|
| 46 | + public function bindServices() { |
|
| 47 | 47 | $driver = config('ipchecker.driver'); |
| 48 | 48 | switch ($driver) { |
| 49 | 49 | case 'file': |
@@ -56,36 +56,36 @@ discard block |
||
| 56 | 56 | throw new Exception("Unsupported Driver"); |
| 57 | 57 | break; |
| 58 | 58 | } |
| 59 | - $this->app->singleton(IpCheckerInterface::class,$instance); |
|
| 59 | + $this->app->singleton(IpCheckerInterface::class, $instance); |
|
| 60 | 60 | |
| 61 | - $this->app->singleton('ipchecker', function ($app) use ($instance){ |
|
| 61 | + $this->app->singleton('ipchecker', function($app) use ($instance){ |
|
| 62 | 62 | return new IpChecker($app->make($instance)); |
| 63 | 63 | }); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function loadConfig(){ |
|
| 66 | + public function loadConfig() { |
|
| 67 | 67 | $this->publishes([ |
| 68 | - __DIR__ . '/../config/ipchecker.php' => config_path('ipchecker.php') |
|
| 68 | + __DIR__.'/../config/ipchecker.php' => config_path('ipchecker.php') |
|
| 69 | 69 | ], 'ipchecker'); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function loadRoutes(){ |
|
| 73 | - $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); |
|
| 72 | + public function loadRoutes() { |
|
| 73 | + $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public function loadViews(){ |
|
| 77 | - $this->loadViewsFrom(__DIR__ . '/../resources/views', 'ipchecker'); |
|
| 76 | + public function loadViews() { |
|
| 77 | + $this->loadViewsFrom(__DIR__.'/../resources/views', 'ipchecker'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function loadMigrations(){ |
|
| 81 | - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
| 80 | + public function loadMigrations() { |
|
| 81 | + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - public function loadTranslation(){ |
|
| 85 | - $this->loadTranslationsFrom(__DIR__ . '/lang', 'ipchecker'); |
|
| 84 | + public function loadTranslation() { |
|
| 85 | + $this->loadTranslationsFrom(__DIR__.'/lang', 'ipchecker'); |
|
| 86 | 86 | |
| 87 | 87 | $this->publishes([ |
| 88 | - __DIR__ . '/lang' => resource_path('lang/vendor/ipchecker'), |
|
| 88 | + __DIR__.'/lang' => resource_path('lang/vendor/ipchecker'), |
|
| 89 | 89 | ], 'ipchecker'); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
| 10 | 10 | * @link https://github.com/HayriCan/laravel-ip-checker |
| 11 | 11 | */ |
| 12 | -interface IpCheckerInterface{ |
|
| 12 | +interface IpCheckerInterface { |
|
| 13 | 13 | |
| 14 | 14 | public function getIpArray(); |
| 15 | 15 | /** |
@@ -35,17 +35,17 @@ |
||
| 35 | 35 | $code = trans('ipchecker::messages.denied_access.code'); |
| 36 | 36 | $message = trans('ipchecker::messages.denied_access.message'); |
| 37 | 37 | |
| 38 | - if (in_array(config('ipchecker.api_middleware'),$request->route()->gatherMiddleware())){ |
|
| 38 | + if (in_array(config('ipchecker.api_middleware'), $request->route()->gatherMiddleware())) { |
|
| 39 | 39 | $return_array = [ |
| 40 | 40 | 'success'=>false, |
| 41 | 41 | 'code'=>$code, |
| 42 | 42 | 'message'=>$message, |
| 43 | 43 | ]; |
| 44 | 44 | |
| 45 | - return response()->json($return_array,200,[],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); |
|
| 45 | + return response()->json($return_array, 200, [], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return response()->view('ipchecker::error',compact('message','code')); |
|
| 48 | + return response()->view('ipchecker::error', compact('message', 'code')); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return $next($request); |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | $this->middleware(['web']); |
| 29 | 29 | if (config('ipchecker.settings.auth')) { |
| 30 | - if (!empty(config('ipchecker.settings.admin_id'))){ |
|
| 31 | - if (!in_array(Auth::id(),config('ipchecker.settings.admin_id'))){ |
|
| 30 | + if (!empty(config('ipchecker.settings.admin_id'))) { |
|
| 31 | + if (!in_array(Auth::id(), config('ipchecker.settings.admin_id'))) { |
|
| 32 | 32 | return abort(404); |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | - $this->middleware(['web','auth']); |
|
| 35 | + $this->middleware(['web', 'auth']); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $iplist = $ipchecker->getIpList(); |
| 48 | 48 | |
| 49 | - if(count($iplist)>0){ |
|
| 49 | + if (count($iplist)>0) { |
|
| 50 | 50 | $iplist = $iplist->sortByDesc('created_at'); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - return view('ipchecker::index',compact('iplist')); |
|
| 53 | + return view('ipchecker::index', compact('iplist')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param IpCheckerInterface $ipchecker |
| 59 | 59 | * @return \Illuminate\Http\RedirectResponse |
| 60 | 60 | */ |
| 61 | - public function add(Request $request,IpCheckerInterface $ipchecker) |
|
| 61 | + public function add(Request $request, IpCheckerInterface $ipchecker) |
|
| 62 | 62 | { |
| 63 | 63 | $request_data = $request->all(); |
| 64 | 64 | $request_validation = array( |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | return redirect()->back()->withErrors($validator->errors()); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if (!in_array($request->input('ip'),$ipchecker->getIpArray())){ |
|
| 74 | + if (!in_array($request->input('ip'), $ipchecker->getIpArray())) { |
|
| 75 | 75 | $ipchecker->saveIp(array( |
| 76 | 76 | 'group'=>$request->input('group'), |
| 77 | 77 | 'definition'=>$request->input('definition'), |
| 78 | 78 | 'ip'=>$request->input('ip'), |
| 79 | 79 | )); |
| 80 | 80 | |
| 81 | - return redirect()->back()->with('success',trans('ipchecker::messages.ip_success')); |
|
| 81 | + return redirect()->back()->with('success', trans('ipchecker::messages.ip_success')); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return redirect()->back()->with('error',trans('ipchecker::messages.ip_error')); |
|
| 84 | + return redirect()->back()->with('error', trans('ipchecker::messages.ip_error')); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * @param IpCheckerInterface $ipchecker |
| 90 | 90 | * @return \Illuminate\Http\RedirectResponse |
| 91 | 91 | */ |
| 92 | - public function delete(Request $request,IpCheckerInterface $ipchecker) |
|
| 92 | + public function delete(Request $request, IpCheckerInterface $ipchecker) |
|
| 93 | 93 | { |
| 94 | 94 | $ipchecker->deleteIp($request->input('ipAddress')); |
| 95 | 95 | |
| 96 | - return redirect()->back()->with('info',trans('ipchecker::messages.ip_delete')); |
|
| 96 | + return redirect()->back()->with('info', trans('ipchecker::messages.ip_delete')); |
|
| 97 | 97 | } |
| 98 | 98 | } |