Skip to content

Commit bc020f0

Browse files
committed
add blocker package
1 parent 19cfb30 commit bc020f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2492
-111
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ LARAVEL_LOGGER_FONT_AWESOME_CDN_URL=https://maxcdn.bootstrapcdn.com/font-awesome
110110
LARAVEL_LOGGER_BOOTSTRAP_CSS_CDN_ENABLED=false
111111
LARAVEL_LOGGER_BOOTSTRAP_CSS_CDN_URL=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css
112112

113+
LARAVEL_BLOCKER_USER_MODEL='App\Models\User'
114+
LARAVEL_BLOCKER_AUTH_ENABLED=true
115+
LARAVEL_BLOCKER_ROLES_ENABLED=true
116+
LARAVEL_BLOCKER_FLASH_MESSAGES_ENABLED=false
117+
LARAVEL_BLOCKER_JQUERY_CDN_ENABLED=false
118+
LARAVEL_BLOCKER_BLADE_PLACEMENT_CSS='template_linked_css'
119+
LARAVEL_BLOCKER_BLADE_PLACEMENT_JS='footer_scripts'
120+
LARAVEL_BLOCKER_USE_TYPES_SEED_PUBLISHED=true
121+
LARAVEL_BLOCKER_USE_ITEMS_SEED_PUBLISHED=true
122+
113123
// NOTE: YOU CAN REMOVE THE KEY CALL IN app.blade.php IF YOU GET A POP UP AND DO NOT WANT TO SETUP A KEY FOR DEV
114124
# Google Maps API v3 Key - https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key
115125
GOOGLEMAPS_API_STATUS=true

.env.travis

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ LARAVEL_LOGGER_FONT_AWESOME_CDN_URL=https://maxcdn.bootstrapcdn.com/font-awesome
110110
LARAVEL_LOGGER_BOOTSTRAP_CSS_CDN_ENABLED=false
111111
LARAVEL_LOGGER_BOOTSTRAP_CSS_CDN_URL=https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css
112112

113+
LARAVEL_BLOCKER_USER_MODEL=App\Models\User
114+
LARAVEL_BLOCKER_AUTH_ENABLED=true
115+
LARAVEL_BLOCKER_ROLES_ENABLED=true
116+
LARAVEL_BLOCKER_FLASH_MESSAGES_ENABLED=false
117+
LARAVEL_BLOCKER_JQUERY_CDN_ENABLED=false
118+
LARAVEL_BLOCKER_BLADE_PLACEMENT_CSS='template_linked_css'
119+
LARAVEL_BLOCKER_BLADE_PLACEMENT_JS='footer_scripts'
120+
LARAVEL_BLOCKER_USE_TYPES_SEED_PUBLISHED=true
121+
LARAVEL_BLOCKER_USE_ITEMS_SEED_PUBLISHED=true
122+
113123
// NOTE: YOU CAN REMOVE THE KEY CALL IN app.blade.php IF YOU GET A POP UP AND DO NOT WANT TO SETUP A KEY FOR DEV
114124
# Google Maps API v3 Key - https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key
115125
GOOGLEMAPS_API_STATUS=true

README.md

Lines changed: 180 additions & 97 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"google/recaptcha": "^1.1",
1414
"intervention/image": "^2.4",
1515
"jaybizzle/laravel-crawler-detect": "1.*",
16+
"jeremykenedy/laravel-blocker": "^1.0",
1617
"jeremykenedy/laravel-exception-notifier": "^1.1",
1718
"jeremykenedy/laravel-https": "^1.1",
1819
"jeremykenedy/laravel-logger": "^2.0",

config/laravelblocker.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Laravel Blocker Core Setting
8+
|--------------------------------------------------------------------------
9+
*/
10+
'laravelBlockerEnabled' => env('LARAVEL_BLOCKER_ENABLED', true),
11+
12+
/*
13+
|--------------------------------------------------------------------------
14+
| Laravel Blocker Database Settings
15+
|--------------------------------------------------------------------------
16+
*/
17+
'blockerDatabaseConnection' => env('LARAVEL_BLOCKER_DATABASE_CONNECTION', 'mysql'),
18+
'blockerDatabaseTable' => env('LARAVEL_BLOCKER_DATABASE_TABLE', 'laravel_blocker'),
19+
'blockerTypeDatabaseTable' => env('LARAVEL_BLOCKER_TYPE_DATABASE_TABLE', 'laravel_blocker_types'),
20+
'seedDefaultBlockedTypes' => env('LARAVEL_BLOCKER_SEED_DEFAULT_TYPES', true),
21+
'seedDefaultBlockedItems' => env('LARAVEL_BLOCKER_SEED_DEFAULT_ITEMS', true),
22+
'seedPublishedBlockedTypes' => env('LARAVEL_BLOCKER_TYPES_SEED_PUBLISHED', true),
23+
'seedPublishedBlockedItems' => env('LARAVEL_BLOCKER_ITEMS_SEED_PUBLISHED', true),
24+
'useSeededBlockedTypes' => env('LARAVEL_BLOCKER_USE_TYPES_SEED_PUBLISHED', false),
25+
'useSeededBlockedItems' => env('LARAVEL_BLOCKER_USE_ITEMS_SEED_PUBLISHED', false),
26+
27+
/*
28+
|--------------------------------------------------------------------------
29+
| Laravel Default User Model
30+
|--------------------------------------------------------------------------
31+
*/
32+
'defaultUserModel' => env('LARAVEL_BLOCKER_USER_MODEL', 'App\User'),
33+
34+
/*
35+
|--------------------------------------------------------------------------
36+
| Laravel Blocker Front End Settings
37+
|--------------------------------------------------------------------------
38+
*/
39+
// The parent blade file
40+
'laravelBlockerBladeExtended' => env('LARAVEL_BLOCKER_BLADE_EXTENDED', 'layouts.app'),
41+
42+
// Titles placement extend
43+
'laravelBlockerTitleExtended' => env('LARAVEL_BLOCKER_TITLE_EXTENDED', 'template_title'),
44+
45+
// Switch Between bootstrap 3 `panel` and bootstrap 4 `card` classes
46+
'blockerBootstapVersion' => env('LARAVEL_BLOCKER_BOOTSTRAP_VERSION', '4'),
47+
48+
// Additional Card classes for styling -
49+
// See: https://getbootstrap.com/docs/4.0/components/card/#background-and-color
50+
// Example classes: 'text-white bg-primary mb-3'
51+
'blockerBootstrapCardClasses' => env('LARAVEL_BLOCKER_CARD_CLASSES', ''),
52+
53+
// Blade Extension Placement
54+
'blockerBladePlacement' => env('LARAVEL_BLOCKER_BLADE_PLACEMENT', 'yield'),
55+
'blockerBladePlacementCss' => env('LARAVEL_BLOCKER_BLADE_PLACEMENT_CSS', 'inline_template_linked_css'),
56+
'blockerBladePlacementJs' => env('LARAVEL_BLOCKER_BLADE_PLACEMENT_JS', 'inline_footer_scripts'),
57+
58+
// jQuery
59+
'enablejQueryCDN' => env('LARAVEL_BLOCKER_JQUERY_CDN_ENABLED', true),
60+
'JQueryCDN' => env('LARAVEL_BLOCKER_JQUERY_CDN_URL', 'https://code.jquery.com/jquery-3.3.1.min.js'),
61+
62+
// Font Awesome
63+
'blockerEnableFontAwesomeCDN' => env('LARAVEL_BLOCKER_FONT_AWESOME_CDN_ENABLED', true),
64+
'blockerFontAwesomeCDN' => env('LARAVEL_BLOCKER_FONT_AWESOME_CDN_URL', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'),
65+
66+
// Bootstrap Tooltips
67+
'tooltipsEnabled' => env('LARAVEL_BLOCKER_TOOLTIPS_ENABLED', true),
68+
69+
// jQuery IP Mask
70+
'jQueryIpMaskEnabled' => env('LARAVEL_BLOCKER_JQUERY_IP_MASK_ENABLED', true),
71+
'jQueryIpMaskCDN' => env('LARAVEL_BLOCKER_JQUERY_IP_MASK_CDN', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js'),
72+
73+
// Flash Messaging
74+
'blockerFlashMessagesEnabled' => env('LARAVEL_BLOCKER_FLASH_MESSAGES_ENABLED', true),
75+
76+
// Enable Search Blocked - Uses jQuery Ajax
77+
'enableSearchBlocked' => env('LARAVEL_BLOCKER_SEARCH_ENABLED', true),
78+
79+
/*
80+
|--------------------------------------------------------------------------
81+
| Laravel Blocker Auth & Roles Settings
82+
|--------------------------------------------------------------------------
83+
*/
84+
// Enable `auth` middleware
85+
'authEnabled' => env('LARAVEL_BLOCKER_AUTH_ENABLED', true),
86+
87+
// Enable Optional Roles Middleware
88+
'rolesEnabled' => env('LARAVEL_BLOCKER_ROLES_ENABLED', false),
89+
90+
// Optional Roles Middleware
91+
'rolesMiddlware' => env('LARAVEL_BLOCKER_ROLES_MIDDLWARE', ['activated', 'role:admin', 'activity', 'twostep']), // Override in place here
92+
93+
/*
94+
|--------------------------------------------------------------------------
95+
| Laravel Blocker Pagination Settings
96+
|--------------------------------------------------------------------------
97+
*/
98+
'blockerPaginationEnabled' => env('LARAVEL_BLOCKER_PAGINATION_ENABLED', false),
99+
'blockerPaginationPerPage' => env('LARAVEL_BLOCKER_PAGINATION_PER_PAGE', 25),
100+
101+
/*
102+
|--------------------------------------------------------------------------
103+
| Laravel Blocker Databales Settings - Not recommended with pagination.
104+
|--------------------------------------------------------------------------
105+
*/
106+
'blockerDatatables' => env('LARAVEL_BLOCKER_DATATABLES_ENABLED', false),
107+
'enabledDatatablesJs' => env('LARAVEL_BLOCKER_DATATABLES_JS_ENABLED', false),
108+
'datatablesJsStartCount' => env('LARAVEL_BLOCKER_DATATABLES_JS_START_COUNT', 25),
109+
'datatablesCssCDN' => env('LARAVEL_BLOCKER_DATATABLES_CSS_CDN', 'https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css'),
110+
'datatablesJsCDN' => env('LARAVEL_BLOCKER_DATATABLES_JS_CDN', 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'),
111+
'datatablesJsPresetCDN' => env('LARAVEL_BLOCKER_DATATABLES_JS_PRESET_CDN', 'https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js'),
112+
113+
/*
114+
|--------------------------------------------------------------------------
115+
| Laravel Blocker Actions Options
116+
|--------------------------------------------------------------------------
117+
*/
118+
'blockerDefaultAction' => env('LARAVEL_BLOCKER_DEFAULT_ACTION', 'abort'), //'abort', 'view' ,'redirect'
119+
'blockerDefaultActionAbortType' => env('LARAVEL_BLOCKER_DEFAULT_ACTION_ABORT_TYPE', '403'),
120+
'blockerDefaultActionView' => env('LARAVEL_BLOCKER_DEFAULT_ACTION_VIEW', 'welcome'),
121+
'blockerDefaultActionRedirect' => env('LARAVEL_BLOCKER_DEFAULT_ACTION_REDIRECT', '/'), // Internal or external
122+
];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use jeremykenedy\LaravelBlocker\App\Models\BlockedType;
7+
8+
class CreateLaravelBlockerTypesTable extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*
13+
* @return void
14+
*/
15+
public function up()
16+
{
17+
$blocked = new BlockedType();
18+
$connection = $blocked->getConnectionName();
19+
$table = $blocked->getTableName();
20+
$tableCheck = Schema::connection($connection)->hasTable($table);
21+
22+
if (!$tableCheck) {
23+
Schema::connection($connection)->create($table, function (Blueprint $table) {
24+
$table->increments('id');
25+
$table->string('slug')->unique();
26+
$table->string('name');
27+
$table->timestamps();
28+
$table->softDeletes();
29+
});
30+
}
31+
}
32+
33+
/**
34+
* Reverse the migrations.
35+
*
36+
* @return void
37+
*/
38+
public function down()
39+
{
40+
$blockedType = new BlockedType();
41+
$connection = $blockedType->getConnectionName();
42+
$table = $blockedType->getTableName();
43+
44+
Schema::connection($connection)->dropIfExists($table);
45+
}
46+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem;
7+
use jeremykenedy\LaravelBlocker\App\Models\BlockedType;
8+
9+
class CreateLaravelBlockerTable extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up()
17+
{
18+
$blocked = new BlockedItem();
19+
$connection = $blocked->getConnectionName();
20+
$table = $blocked->getTableName();
21+
$tableCheck = Schema::connection($connection)->hasTable($table);
22+
23+
if (!$tableCheck) {
24+
Schema::connection($connection)->create($table, function (Blueprint $table) {
25+
$blockedType = new BlockedType();
26+
$connectionType = $blockedType->getConnectionName();
27+
$tableTypeName = $blockedType->getTableName();
28+
$table->increments('id');
29+
$table->integer('typeId')->unsigned()->index();
30+
$table->foreign('typeId')->references('id')->on($tableTypeName)->onDelete('cascade');
31+
$table->string('value')->unique();
32+
$table->longText('note')->nullable();
33+
$table->integer('userId')->unsigned()->index()->nullable();
34+
// $table->foreign('userId')->references('id')->on('users')->onDelete('cascade');
35+
$table->timestamps();
36+
$table->softDeletes();
37+
});
38+
}
39+
}
40+
41+
/**
42+
* Reverse the migrations.
43+
*
44+
* @return void
45+
*/
46+
public function down()
47+
{
48+
$blocked = new BlockedItem();
49+
$connection = $blocked->getConnectionName();
50+
$table = $blocked->getTableName();
51+
52+
Schema::connection($connection)->dropIfExists($table);
53+
}
54+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Database\Seeds;
4+
5+
use Illuminate\Database\Seeder;
6+
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem;
7+
use jeremykenedy\LaravelBlocker\App\Models\BlockedType;
8+
9+
class BlockedItemsTableSeeder extends Seeder
10+
{
11+
/**
12+
* Run the database seeds.
13+
*
14+
* @return void
15+
*/
16+
public function run()
17+
{
18+
/*
19+
* Blocked Types
20+
*
21+
*/
22+
$BlockedItems = [
23+
[
24+
'type' => 'domain',
25+
'value' => 'test.com',
26+
'note' => 'Block all domains/emails @test.com',
27+
],
28+
[
29+
'type' => 'domain',
30+
'value' => 'test.ca',
31+
'note' => 'Block all domains/emails @test.ca',
32+
],
33+
[
34+
'type' => 'domain',
35+
'value' => 'fake.com',
36+
'note' => 'Block all domains/emails @fake.com',
37+
],
38+
[
39+
'type' => 'domain',
40+
'value' => 'example.com',
41+
'note' => 'Block all domains/emails @example.com',
42+
],
43+
[
44+
'type' => 'domain',
45+
'value' => 'mailinator.com',
46+
'note' => 'Block all domains/emails @mailinator.com',
47+
],
48+
];
49+
50+
/*
51+
* Add Blocked Items
52+
*
53+
*/
54+
if (config('laravelblocker.seedPublishedBlockedItems')) {
55+
foreach ($BlockedItems as $BlockedItem) {
56+
$blockType = BlockedType::where('slug', $BlockedItem['type'])->first();
57+
$newBlockedItem = BlockedItem::where('typeId', '=', $blockType->id)
58+
->where('value', '=', $BlockedItem['value'])
59+
->withTrashed()
60+
->first();
61+
if ($newBlockedItem === null) {
62+
$newBlockedItem = BlockedItem::create([
63+
'typeId' => $blockType->id,
64+
'value' => $BlockedItem['value'],
65+
'note' => $BlockedItem['note'],
66+
]);
67+
}
68+
}
69+
}
70+
echo "\e[32mSeeding:\e[0m BlockedItemsTableSeeder\r\n";
71+
}
72+
}

0 commit comments

Comments
 (0)