Skip to content

Commit

Permalink
Appeal/Report System
Browse files Browse the repository at this point in the history
  • Loading branch information
hobsRKM committed Jun 15, 2024
1 parent 5718923 commit 94feb42
Show file tree
Hide file tree
Showing 24 changed files with 1,295 additions and 218 deletions.
10 changes: 10 additions & 0 deletions app/Helpers/CommonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Helpers;

use App\Models\Appeal\Appeal;
use App\Models\Report\Report;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -37,4 +39,12 @@ public static function steamProfile($resource) {
});
}
}

public static function appealCheck() {
return Appeal::where('status', 'pending')->count();
}

public static function reportCheck() {
return Report::count();
}
}
74 changes: 74 additions & 0 deletions app/Http/Controllers/Appeal/AppealController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers\Appeal;

use App\Http\Controllers\Controller;
use App\Mail\AppealApproved;
use App\Models\Appeal\Appeal;
use App\Models\SaBan;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class AppealController extends Controller
{
public function index()
{
$appeals = Appeal::all();
return view('appeals.create', compact('appeals'));
}

public function create()
{
return view('appeals.create');
}

public function store(Request $request)
{
$validated = $request->validate([
'ban_type' => 'required|string',
'steamid' => 'required_if:ban_type,Steam ID|nullable|string',
'ip' => 'required_if:ban_type,IP|nullable|ip',
'name' => 'required|string',
'reason' => 'required|string',
'email' => 'required|email',
]);
if(SaBan::where('player_steamid', $validated['steamid'])
->where('status', 'ACTIVE')
->exists()) {
$data = $request->only(['ban_type', 'steamid', 'ip', 'name', 'reason', 'email']);
$data['status'] = 'PENDING';
// Save the appeal
Appeal::create($data);

return redirect()->route('appeals.create')->with('success', 'Appeal submitted successfully.');
}
else {
return redirect()->route('appeals.create')->with('error', 'No active bans exists for this Steam ID or IP');
}
}

public function list()
{
$appeals = Appeal::orderBy('created_at', 'desc')->get();
return view('appeals.list', compact('appeals'));
}

public function view($id)
{
$appeal = Appeal::findOrFail($id);
return view('appeals.show', compact('appeal'));
}

public function updateStatus(Request $request, $id)
{
$request->validate([
'status' => 'required|in:APPROVED,REJECTED',
]);

$appeal = Appeal::findOrFail($id);
$appeal->status = $request->input('status');
$appeal->save();
Mail::to($appeal->email)->send(new AppealApproved($appeal));

return redirect()->route('appeals.list', $appeal->id)->with('success', 'Appeal status updated successfully.');
}
}
15 changes: 14 additions & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\SaMute;
use App\Models\SaServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;

class DashboardController extends Controller
Expand All @@ -21,10 +22,18 @@ public function check() {
public function home()
{
$updates = [];
$activeBans = null;
$activeMutes = null;
$totalBans = SaBan::count();
$totalServers = SaServer::count();
$totalMutes = SaMute::count();
$totalAdmins = SaAdmin::distinct('player_steamid')->count();
$totalActiveBans = SaBan::where('status', 'ACTIVE')->count();
$totalActiveMutes = SaMute::where('status', 'ACTIVE')->count();
if(auth()->check()){
$activeBans = SaBan::where('player_steamid', Auth::user()->steam_id)->where('status', 'ACTIVE')->count();
$activeMutes = SaMute::where('player_steamid', Auth::user()->steam_id)->where('status', 'ACTIVE')->count();
}
if(PermissionsHelper::isSuperAdmin()) {
$updates = $this->checkUpdates();
}
Expand All @@ -39,7 +48,11 @@ public function home()
'totalMutes',
'totalAdmins',
'updates',
'topPlayersData'
'topPlayersData',
'activeBans',
'activeMutes',
'totalActiveBans',
'totalActiveMutes'
)
);
}
Expand Down
57 changes: 57 additions & 0 deletions app/Http/Controllers/Report/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Controllers\Report;

use App\Http\Controllers\Controller;
use App\Models\Report\Report;
use App\Models\SaServer;
use Illuminate\Http\Request;

class ReportController extends Controller
{
public function create()
{
$servers = SaServer::all();
return view('reports.create', compact('servers'));
}

public function store(Request $request)
{
$request->validate([
'ban_type' => 'required|string',
'steamid' => 'required_if:ban_type,Steam ID|nullable|string',
'ip' => 'required_if:ban_type,IP|nullable|ip',
'nickname' => 'required|string',
'comments' => 'required|string',
'name' => 'required|string',
'email' => 'required|email',
'server_id' => 'required|integer',
'media_link' => 'nullable|url',
]);

$data = $request->only(['ban_type', 'steamid', 'ip', 'nickname', 'comments', 'name', 'email', 'server_id', 'media_link']);
Report::create($data);

return redirect()->route('reports.create')->with('success', 'Report submitted successfully.');
}

public function list()
{
$reports = Report::orderBy('created_at', 'desc')->get();
return view('reports.list', compact('reports'));
}

public function show($id)
{
$report = Report::findOrFail($id);
return view('reports.show', compact('report'));
}

public function destroy($id)
{
$report = Report::findOrFail($id);
$report->delete();

return redirect()->route('reports.list')->with('success', 'Report deleted successfully.');
}
}
18 changes: 16 additions & 2 deletions app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use App\Helpers\PermissionsHelper;
use App\Models\SaAdmin;
use App\Models\SaAdminsFlags;
use App\Models\SaBan;
use App\Models\SaServer;
use App\Models\ServerVisibilitySetting;
use App\Services\RconService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
Expand Down Expand Up @@ -56,7 +58,10 @@ public function getAllServerInfo(RconService $rcon)
$serverVisibilitySettings = ServerVisibilitySetting::pluck('is_visible', 'server_id')->toArray();

$formattedServers = [];

$loggedInPlayerSteam = null;
if(auth()->check()){
$loggedInPlayerSteam = Auth::user()?->steam_id;
}
foreach ($servers as $server) {
if (isset($serverVisibilitySettings[$server->id]) && !$serverVisibilitySettings[$server->id]) {
continue; // Skip hidden servers
Expand All @@ -67,9 +72,18 @@ public function getAllServerInfo(RconService $rcon)
try {
$serverDetails = $this->getServerDetails($serverIp, $serverPort);
if ($serverDetails) {
$banned = '';
if($loggedInPlayerSteam){
if(SaBan::where('player_steamid', $loggedInPlayerSteam)
->where('server_id', $server->id)
->where('status', 'ACTIVE')
->exists()) {
$banned = ' <span class="badge badge-light-danger mb-2 me-4">Banned</span>';
}
}
$formattedServer = [
'id' => $server->id,
'name' => $server->hostname,
'name' => $server->hostname.$banned,
'ip' => $serverIp,
'port' => $serverPort,
'players' => $serverDetails['players'] . "/" . $serverDetails['max_players'],
Expand Down
29 changes: 29 additions & 0 deletions app/Mail/AppealApproved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Mail;

use App\Models\Appeal\Appeal;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class AppealApproved extends Mailable
{
use Queueable, SerializesModels;

protected $appeal;

public function __construct(Appeal $appeal)
{
$this->appeal = $appeal;
}

public function build()
{
return $this->subject('Your Ban Appeal has been'." ".ucfirst($this->appeal->status))
->view('appeals.email.appeal_status')
->with([
'appeal' => $this->appeal,
]);
}
}
18 changes: 18 additions & 0 deletions app/Models/Appeal/Appeal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace App\Models\Appeal;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Appeal extends Model
{
use HasFactory;

protected $fillable = [
'ban_type',
'steamid',
'name',
'reason',
'email'
];
}
28 changes: 28 additions & 0 deletions app/Models/Report/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Models\Report;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Report extends Model
{
use HasFactory;

protected $fillable = [
'ban_type',
'steamid',
'ip',
'nickname',
'comments',
'name',
'email',
'server_id',
'media_link',
];

public function server()
{
return $this->belongsTo(\App\Models\SaServer::class);
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| Application Version
|--------------------------------------------------------------------------
*/
'version' => '3.4',
'version' => '3.5',
/*
|--------------------------------------------------------------------------
| Application Name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAppealsTable extends Migration
{
public function up()
{
Schema::create('appeals', function (Blueprint $table) {
$table->id();
$table->string('ban_type');
$table->string('steamid');
$table->string('name');
$table->text('reason');
$table->string('email');
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('appeals');
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('reports', function (Blueprint $table) {
$table->id();
$table->string('ban_type');
$table->string('steamid')->nullable();
$table->ipAddress('ip')->nullable();
$table->string('nickname');
$table->text('comments');
$table->string('name');
$table->string('email');
$table->unsignedBigInteger('server_id');
$table->string('media_link')->nullable();
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('reports');
}
};
Loading

0 comments on commit 94feb42

Please sign in to comment.