add client blacklist from DB

This commit is contained in:
Jay Sizzla
2022-09-07 08:45:10 +02:00
parent 480aad1bcf
commit 32c448e99b
11 changed files with 411 additions and 8 deletions
+2 -1
View File
@@ -146,6 +146,7 @@ class AnnounceController extends Controller
|| $request->header('want-digest'), new TrackerException(122));
$userAgent = $request->header('User-Agent');
$clientBlacklist = BlacklistClient::get();
// Should also block User-Agent strings that are too long. (For Database reasons)
\throw_if(\strlen((string) $userAgent) > 64, new TrackerException(123));
@@ -155,7 +156,7 @@ class AnnounceController extends Controller
(string) $userAgent), new TrackerException(121));
// Block Blacklisted Clients
\throw_if(\in_array($request->header('User-Agent'), \config('client-blacklist.clients')),
\throw_if(\in_array($request->header('User-Agent'), $clientBlacklist),
new TrackerException(128, [':ua' => $request->header('User-Agent')]));
}
+5 -4
View File
@@ -13,6 +13,7 @@
namespace App\Http\Controllers;
use App\Models\BlacklistCLient;
use App\Models\Group;
use App\Models\Internal;
use App\Models\Page;
@@ -63,13 +64,13 @@ class PageController extends Controller
}
/**
* Show Blacklist Page.
* Show Client-Blacklist Page.
*/
public function blacklist(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
public function clientblacklist(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$clients = \config('client-blacklist.clients', []);
$clients = BlacklistClient::get();
return \view('page.blacklist', ['clients' => $clients]);
return \view('page.blacklist.client', ['clients' => $clients]);
}
/**
@@ -0,0 +1,131 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers\Staff;
use App\Http\Controllers\Controller;
use App\Models\BlacklistClient;
use Carbon\Carbon;
use Illuminate\Http\Request;
/**
* @see \Tests\Feature\Http\Controllers\Staff\GroupControllerTest
*/
class BlacklistClientController extends Controller
{
/**
* Display All Blacklisted Groups.
*/
public function index(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = $request->user();
\abort_unless($user->group->is_modo, 403);
$clients = BlacklistClient::get()->sortBy('id');
return \view('Staff.blacklist.clients.index', ['clients' => $clients]);
}
/**
* Edit A group.
*/
public function edit(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$user = $request->user();
\abort_unless($user->group->is_modo, 403);
$date = Carbon::now();
$client = BlacklistClient::findOrFail($id);
return \view('Staff.blacklist.clients.edit', ['client' => $client]);
}
/**
* Save a group change.
*/
public function update(Request $request, int $id): \Illuminate\Http\RedirectResponse
{
$user = $request->user();
\abort_unless($user->group->is_modo, 403);
$client = BlacklistClient::findOrFail($id);
$client->name = $request->input('name');
$client->reason = $request->input('reason');
$v = \validator($client->toArray(), [
'name' => 'required',
'reason',
]);
if ($v->fails()) {
return \to_route('staff.blacklists.clients.index')
->withErrors($v->errors());
}
$client->save();
return \to_route('staff.blacklists.clients.index')
->withSuccess('Group Was Updated Successfully!');
}
/**
* Blacklist Add Form.
*/
public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
return \view('Staff.blacklist.clients.create');
}
/**
* Store A New Blacklisted Group.
*/
public function store(Request $request): \Illuminate\Http\RedirectResponse
{
$user = $request->user();
\abort_unless($user->group->is_admin, 403);
$client = new BlacklistClient();
$client->name = $request->input('name');
$client->reason = $request->input('reason');
$v = \validator($client->toArray(), [
'name' => 'required|unique:blacklist_clients',
'reason',
]);
if ($v->fails()) {
return \to_route('staff.blacklists.clients.index')
->withErrors($v->errors());
}
$client->save();
return \to_route('staff.blacklists.clients.index')
->withSuccess('New Internal Group added!');
}
/**
* Delete A Blacklisted Group.
*/
public function destroy(Request $request, int $id): \Illuminate\Http\RedirectResponse
{
$user = $request->user();
\abort_unless($user->group->is_admin, 403);
$client = BlacklistClient::findOrFail($id);
$client->delete();
return \to_route('staff.blacklists.clients.index')
->withSuccess('Group Has Been Removed.');
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BlacklistClient extends Model
{
/**
* The Attributes That Aren't Mass Assignable.
*
* @var array
*/
protected $guarded = [];
/**
* Indicates If The Model Should Be Timestamped.
*
* @var bool
*/
public $timestamps = true;
public $table = 'blacklist_clients';
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blacklist_clients', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->longText('reason')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('blacklist_clients');
}
};
@@ -0,0 +1,61 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff.dashboard.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ __('staff.staff-dashboard') }}</span>
</a>
</li>
<li class="active">
<a href="#" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Blacklists</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff.blacklists.releasegroups.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Clients</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff.blacklists.releasegroups.create') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ __('common.add') }} Blacklist</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>{{ __('common.add') }} Blacklisted Client</h2>
<div class="table-responsive">
<form role="form" method="POST" action="{{ route('staff.blacklists.clients.store') }}" enctype="multipart/form-data">
@csrf
<div class="table-responsive">
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr>
<th>{{ __('common.name') }}</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
<input type="text" class="form-control" name="name" placeholder="Transmission/2.93" required>
</label>
</td>
<td>
<label>
<input type="text" class="form-control" name="reason" placeholder="Security Vulnerabilities">
</label>
</td>
</tr>
</tbody>
</table>
</div>
<button type="submit" class="btn btn-default">{{ __('common.submit') }}</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,63 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff.dashboard.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ __('staff.staff-dashboard') }}</span>
</a>
</li>
<li class="active">
<a href="#" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Blacklists</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff.blacklists.clients.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Clients</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff.blacklists.clients.edit', ['name' => $client->name, 'id' => $client->id]) }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ $client->name }}</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>{{ $client->name }}</h2>
<div class="table-responsive">
<form role="form" method="POST"
action="{{ route('staff.blacklists.clients.update', ['name' => $client->name, 'id' => $client->id]) }}">
@csrf
<div class="table-responsive">
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr>
<th>{{ __('common.name') }}</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
<input type="text" name="name" value="{{ $client->name }}" class="form-control" required/>
</label>
</td>
<td>
<label>
<input type="text" name="reason" value="{{ $client->reason }}" class="form-control"/>
</label>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<button type="submit" class="btn btn-primary">{{ __('common.submit') }}</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,67 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff.dashboard.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ __('staff.staff-dashboard') }}</span>
</a>
</li>
<li class="active">
<a href="#" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Blacklists</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff.blacklists.clients.index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Clients</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>Blacklist Clients</h2>
<a href="{{ route('staff.blacklists.clients.create') }}" class="btn btn-primary">Add new blacklisted client</a><br><br>
<div class="table-responsive">
<table class="table table-condensed table-striped table-bordered table-hover" style="table-layout:fixed;">
<thead>
<tr>
<th width="5%">ID</th>
<th>{{ __('common.name') }}</th>
<th>Reason</th>
<th>Created at</th>
<th width="15%">{{ __('common.action') }}</th>
</tr>
</thead>
<tbody>
@foreach ($clients as $client)
<tr>
<td>
{{ $client->id }}
</td>
<td>
{{ $client->name }}
</td>
<td style="word-wrap:break-word;">
{{ $client->reason }}
</td>
<td>
{{ \Carbon\Carbon::parse($client->created_at)->format('Y-m-d')}}
</td>
<td>
<form action="{{ route('staff.blacklists.clients.destroy', ['id' => $client->id]) }}"
method="POST">
@csrf
@method('DELETE')
<a href="{{ route('staff.blacklists.clients.edit', ['id' => $client->id]) }}"
class="btn btn-warning">{{ __('common.edit') }}</a>
<button type="submit" class="btn btn-danger">{{ __('common.delete') }}</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
@@ -21,7 +21,7 @@
@foreach ($clients as $client)
<div class="col-xs-6 col-sm-4 col-md-3">
<div class="text-center black-item">
<h4>{{ $client }}</h4>
<h4>{{ $client->name }}</h4>
<span>{{ __('page.blacklist-btclient') }}</span>
<i class="fal fa-ban text-red black-icon"></i>
</div>
+1 -1
View File
@@ -50,7 +50,7 @@
<ul>
<li><a href="{{ route('staff') }}">{{ __('common.staff') }}</a></li>
<li><a href="{{ route('internal') }}">{{ __('common.internal') }}</a></li>
<li><a href="{{ route('blacklist') }}">{{ __('common.blacklist') }}</a></li>
<li><a href="{{ route('client_blacklist') }}">{{ __('common.blacklist') }}</a></li>
<li><a href="{{ route('about') }}">{{ __('common.about') }}</a></li>
</ul>
</div>
Executable → Regular
+13 -1
View File
@@ -129,7 +129,7 @@ Route::group(['middleware' => 'language'], function () {
Route::get('/', [App\Http\Controllers\PageController::class, 'index'])->name('pages.index');
Route::get('/staff', [App\Http\Controllers\PageController::class, 'staff'])->name('staff');
Route::get('/internal', [App\Http\Controllers\PageController::class, 'internal'])->name('internal');
Route::get('/blacklist', [App\Http\Controllers\PageController::class, 'blacklist'])->name('blacklist');
Route::get('/blacklist/clients', [App\Http\Controllers\PageController::class, 'clientblacklist'])->name('client_blacklist');
Route::get('/aboutus', [App\Http\Controllers\PageController::class, 'about'])->name('about');
Route::get('/{id}', [App\Http\Controllers\PageController::class, 'show'])->where('id', '[0-9]+')->name('pages.show');
});
@@ -799,6 +799,18 @@ Route::group(['middleware' => 'language'], function () {
});
});
// Blacklist System
Route::group(['prefix' => 'blacklists'], function () {
Route::name('staff.blacklists.clients.')->group(function () {
Route::get('/clients', [App\Http\Controllers\Staff\BlacklistClientController::class, 'index'])->name('index');
Route::get('/clients/create', [App\Http\Controllers\Staff\BlacklistClientController::class, 'create'])->name('create');
Route::post('/clients/store', [App\Http\Controllers\Staff\BlacklistClientController::class, 'store'])->name('store');
Route::get('/clients/{id}/edit', [App\Http\Controllers\Staff\BlacklistClientController::class, 'edit'])->name('edit');
Route::post('/clients/{id}/update', [App\Http\Controllers\Staff\BlacklistClientController::class, 'update'])->name('update');
Route::delete('/clients/{id}/destroy', [App\Http\Controllers\Staff\BlacklistClientController::class, 'destroy'])->name('destroy');
});
});
//Pages System
Route::group(['prefix' => 'pages'], function () {
Route::name('staff.pages.')->group(function () {