İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
$this->app->register(TelescopeServiceProvider::class);
|
||||
/*
|
||||
if ($this->app->isLocal()) {
|
||||
$this->app->register(TelescopeServiceProvider::class);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
Paginator::useBootstrap();
|
||||
|
||||
$this->protectDocumentFolders();
|
||||
|
||||
// Register Observers
|
||||
\App\Models\NaksCertificate::observe(\App\Observers\NaksCertificateObserver::class);
|
||||
\App\Models\NaksWelder::observe(\App\Observers\NaksWeldersObserver::class);
|
||||
\App\Models\NaksConsumable::observe(\App\Observers\NaksConsumablesObserver::class);
|
||||
\App\Models\RegisterOfExpert::observe(\App\Observers\RegisterOfExpertsObserver::class);
|
||||
\App\Models\WeldingEquipment::observe(\App\Observers\WeldingEquipmentObserver::class);
|
||||
|
||||
}
|
||||
|
||||
private function protectDocumentFolders()
|
||||
{
|
||||
$documentsPath = storage_path('documents');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class DatabaseServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
DB::beforeExecuting(function ($query, $bindings) {
|
||||
// Ensure query is a string before processing
|
||||
if (!is_string($query)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_contains(strtolower($query), 'delete from')) {
|
||||
try {
|
||||
// Extract table name
|
||||
preg_match('/delete from [`\']?(\w+)[`\']?/i', $query, $matches);
|
||||
if (!isset($matches[1])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tableName = $matches[1];
|
||||
|
||||
// Extract WHERE clause
|
||||
if (!preg_match('/where\s+(.+?)(?:order by|limit|$)/is', $query, $whereMatch)) {
|
||||
Log::warning('No WHERE clause found in DELETE query', [
|
||||
'table_name' => $tableName,
|
||||
'query' => $query
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$whereClause = trim($whereMatch[1]);
|
||||
|
||||
// Count placeholders in WHERE clause
|
||||
$placeholderCount = substr_count($whereClause, '?');
|
||||
|
||||
// Validate bindings count
|
||||
if (count($bindings) < $placeholderCount) {
|
||||
Log::error('Bindings count mismatch', [
|
||||
'table_name' => $tableName,
|
||||
'expected' => $placeholderCount,
|
||||
'received' => count($bindings),
|
||||
'query' => $query
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract only the bindings needed for WHERE clause
|
||||
$whereBindings = array_slice($bindings, 0, $placeholderCount);
|
||||
|
||||
// Build SELECT query with proper escaping
|
||||
$selectQuery = "SELECT * FROM `{$tableName}` WHERE {$whereClause}";
|
||||
|
||||
// Fetch records to be deleted
|
||||
$recordsToDelete = DB::select($selectQuery, $whereBindings);
|
||||
|
||||
if (empty($recordsToDelete)) {
|
||||
Log::debug('No records found to delete', [
|
||||
'table_name' => $tableName,
|
||||
'where_clause' => $whereClause,
|
||||
'bindings' => $whereBindings
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('Preparing to log records before deletion', [
|
||||
'table_name' => $tableName,
|
||||
'records_count' => count($recordsToDelete)
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Log each record before deletion
|
||||
foreach ($recordsToDelete as $record) {
|
||||
DB::table('deleted_records')->insert([
|
||||
'table_name' => $tableName,
|
||||
'record_id' => $record->id ?? null,
|
||||
'deleted_data' => json_encode($record),
|
||||
'deleted_by' => $user ? $user->id : null,
|
||||
'deleted_by_name' => $user ? $user->name : null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
Log::debug('Successfully logged records before deletion', [
|
||||
'table_name' => $tableName,
|
||||
'records_count' => count($recordsToDelete)
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to log records before deletion', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'query' => $query,
|
||||
'bindings' => $bindings
|
||||
]);
|
||||
// Don't throw exception - allow deletion to proceed
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/admin';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $namespace = 'App\\Http\\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Telescope\IncomingEntry;
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Laravel\Telescope\TelescopeApplicationServiceProvider;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
Telescope::night();
|
||||
|
||||
$this->hideSensitiveRequestDetails();
|
||||
|
||||
Telescope::filter(function (IncomingEntry $entry) {
|
||||
/*
|
||||
$accept = ['PUT', 'DELETE'];
|
||||
if ($entry->type === 'request') {
|
||||
return in_array($entry->content['method'], $accept);
|
||||
}
|
||||
|
||||
if ($entry->type === 'query') {
|
||||
// accept isteği sırasında yapılan sorguları loglamak için ilgili sorguları kontrol edin
|
||||
if(isset($entry->content['method'])) {
|
||||
return in_array($entry->content['method'], $accept);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
/*
|
||||
// if ($this->app->environment('production')) {
|
||||
return true;
|
||||
// }
|
||||
|
||||
return $entry->isReportableException() ||
|
||||
$entry->isFailedRequest() ||
|
||||
$entry->isFailedJob() ||
|
||||
$entry->isScheduledTask() ||
|
||||
$entry->hasMonitoredTag();
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent sensitive request details from being logged by Telescope.
|
||||
*/
|
||||
protected function hideSensitiveRequestDetails(): void
|
||||
{
|
||||
// if ($this->app->environment('production')) {
|
||||
return;
|
||||
// }
|
||||
|
||||
Telescope::hideRequestParameters(['_token']);
|
||||
|
||||
Telescope::hideRequestHeaders([
|
||||
'cookie',
|
||||
'x-csrf-token',
|
||||
'x-xsrf-token',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Telescope gate.
|
||||
*
|
||||
* This gate determines who can access Telescope in non-local environments.
|
||||
*/
|
||||
protected function gate(): void
|
||||
{
|
||||
|
||||
Gate::define('viewTelescope', function ($user) {
|
||||
return in_array($user->email, [
|
||||
'admin@pelinom.com',
|
||||
'stellar',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user