Pembatasan Browser Aplikasi #127
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Batasi akses web hanya untuk Google Chrome.
|
||||
*
|
||||
* Deteksi berdasarkan header User-Agent, jadi ini sekadar pembatas kenyamanan
|
||||
* (bukan pengaman): User-Agent bisa dipalsukan. Browser berbasis Chromium yang
|
||||
* menyamar sebagai Chrome (mis. Brave) tidak bisa dibedakan dan tetap lolos.
|
||||
*/
|
||||
class RequireChrome
|
||||
{
|
||||
/** Browser lain yang UA-nya juga memuat "Chrome/" atau "CriOS/". */
|
||||
private const BUKAN_CHROME = [
|
||||
'Edg/', 'EdgA/', 'EdgiOS/', 'OPR/', 'Opera', 'OPT/', 'SamsungBrowser',
|
||||
'Vivaldi', 'YaBrowser', 'UCBrowser', 'Firefox', 'FxiOS', 'DuckDuckGo',
|
||||
];
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! config('app.chrome_only') || $this->isChrome((string) $request->userAgent())) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Aplikasi ini hanya dapat diakses menggunakan browser Google Chrome.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
return response()->view('errors.browser-tidak-didukung', [], 403);
|
||||
}
|
||||
|
||||
private function isChrome(string $ua): bool
|
||||
{
|
||||
if (! str_contains($ua, 'Chrome/') && ! str_contains($ua, 'CriOS/')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::BUKAN_CHROME as $penanda) {
|
||||
if (str_contains($ua, $penanda)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Http\Middleware\CheckPermission;
|
||||
use App\Http\Middleware\EnsureBawahanPresensi;
|
||||
use App\Http\Middleware\RequireChrome;
|
||||
use App\Http\Middleware\SetPermissionsTeamId;
|
||||
use App\Http\Middleware\UntanSSO;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -31,7 +32,9 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
$middleware->trustProxies(at: '*');
|
||||
|
||||
// Add SetPermissionsTeamId middleware to web group
|
||||
$middleware->web(append: [
|
||||
$middleware->web(prepend: [
|
||||
RequireChrome::class,
|
||||
], append: [
|
||||
SetPermissionsTeamId::class,
|
||||
UntanSSO::class,
|
||||
]);
|
||||
|
||||
@@ -33,6 +33,9 @@ return [
|
||||
|
||||
'login_mode' => (int) env('LOGIN_MODE', 1),
|
||||
|
||||
// Batasi akses web hanya untuk Google Chrome (set CHROME_ONLY=false untuk menonaktifkan).
|
||||
'chrome_only' => (bool) env('CHROME_ONLY', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
@include('partials.cek-chrome')
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login | {{ config('app.name') }}</title>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
@include('partials.cek-chrome')
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Browser Tidak Didukung | {{ config('app.name') }}</title>
|
||||
<link rel="shortcut icon" href="{{ asset('assets/images/logo-untan.png') }}">
|
||||
<style>
|
||||
body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #fafbfe; font-family: "Inter", system-ui, sans-serif; color: #000; }
|
||||
.box { max-width: 440px; padding: 40px 32px; text-align: center; background: #fff; border: 1px solid #e3e6ec; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
|
||||
img { height: 56px; }
|
||||
h1 { font-size: 20px; margin: 16px 0 8px; }
|
||||
p { margin: 0 0 20px; font-size: 14px; color: #6c757d; line-height: 1.6; }
|
||||
a.btn { display: inline-block; padding: 10px 20px; border-radius: 8px; background: #1a73e8; color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<img src="{{ asset('assets/images/logo-untan.png') }}" alt="UNTAN">
|
||||
<h1>Browser Tidak Didukung</h1>
|
||||
<p>Aplikasi {{ config('app.name') }} hanya dapat diakses menggunakan browser <strong>Google Chrome</strong>. Silakan buka kembali halaman ini melalui Chrome.</p>
|
||||
<a class="btn" href="https://www.google.com/chrome/" target="_blank" rel="noopener">Unduh Google Chrome</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
@include('partials.cek-chrome')
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dashboard Statistik Jurnal — UNTAN</title>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
@include('partials.cek-chrome')
|
||||
@include('layouts.header')
|
||||
@yield('css')
|
||||
<style>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{{-- Alihkan ke halaman penolakan bila browser bukan Google Chrome.
|
||||
Server sudah mengecek User-Agent (RequireChrome); Brave memakai User-Agent Chrome,
|
||||
jadi hanya bisa dikenali dari sisi browser lewat navigator.brave. --}}
|
||||
@if (config('app.chrome_only'))
|
||||
<script>
|
||||
(function () {
|
||||
function bukanChrome() {
|
||||
location.replace(@json(route('browser.tidak-didukung')));
|
||||
}
|
||||
|
||||
function isChrome(ua) {
|
||||
if (ua.indexOf('Chrome/') === -1 && ua.indexOf('CriOS/') === -1) return false;
|
||||
return !/Edg\/|EdgA\/|EdgiOS\/|OPR\/|Opera|OPT\/|SamsungBrowser|Vivaldi|YaBrowser|UCBrowser|Firefox|FxiOS|DuckDuckGo/.test(ua);
|
||||
}
|
||||
|
||||
if (!isChrome(navigator.userAgent)) return bukanChrome();
|
||||
|
||||
if (navigator.brave && typeof navigator.brave.isBrave === 'function') {
|
||||
navigator.brave.isBrave().then(function (brave) {
|
||||
if (brave) bukanChrome();
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
@endif
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
@include('partials.cek-chrome')
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Verifikasi Presensi | {{ config('app.name') }}</title>
|
||||
|
||||
@@ -11,6 +11,10 @@ Route::get('/', function () {
|
||||
return redirect('login');
|
||||
});
|
||||
|
||||
// Halaman penolakan untuk browser selain Chrome (dipakai juga oleh pengecekan Brave di sisi klien)
|
||||
Route::get('/browser-tidak-didukung', fn () => response()->view('errors.browser-tidak-didukung', [], 403))
|
||||
->name('browser.tidak-didukung');
|
||||
|
||||
// Authentication Routes
|
||||
Route::get('/login', [LoginController::class, 'index'])->name('login');
|
||||
Route::get('/login/ariyutta', [LoginController::class, 'ariyutta'])->name('login.ariyutta');
|
||||
|
||||
Reference in New Issue
Block a user