1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\SiteController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\WritingController;
use App\Http\Controllers\LinkController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\AdminController;
use Illuminate\Http\Request;
Route::get('/', function () {
return view('home');
});
Route::get('/dq', [SiteController::class, 'duneQuote']);
Route::get('/f/{path}', function($path){
// Sanitize: strip directory traversal, only allow basename
$path = basename($path);
$storpath = storage_path('app/public/uploads/' . $path);
if (!file_exists($storpath)){
abort(404, 'File not found.');
}
$mime = Storage::mimeType('public/uploads/' . $path);
return response()->file($storpath, [
'Content-Type' => $mime,
'Content-Disposition' => 'inline; filename="'.$path.'"'
]);
});
Route::get('/mu/{path}', function($path){
// Sanitize: strip directory traversal, only allow basename
$path = basename($path);
$storpath = storage_path('app/public/band/' . $path);
if (!file_exists($storpath)){
abort(404, 'File not found.');
}
$mime = Storage::mimeType('public/band/' . $path);
return response()->file($storpath, [
'Content-Type' => $mime,
'Content-Disposition' => 'inline; filename="'.$path.'"'
]);
});
// Public read-only routes
Route::resource('w', WritingController::class)->only(['index', 'show']);
Route::resource('l', LinkController::class)->only(['index', 'show']);
Route::resource('f', \App\Http\Controllers\FileController::class)->only(['index', 'show']);
Route::get('/test', [SiteController::class, 'test']);
// Auth-protected routes
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
Route::get('/dashboard/stats', [DashboardController::class, 'statistics'])->name('dashboard.stats');
Route::resource('l', LinkController::class)->only(['create', 'store', 'edit', 'update', 'destroy']);
Route::resource('w', WritingController::class)->only(['create', 'store', 'edit', 'update', 'destroy']);
Route::resource('f', \App\Http\Controllers\FileController::class)->only(['create', 'store', 'edit', 'update', 'destroy']);
});
// Admin-only routes
Route::middleware(['auth', \App\Http\Middleware\Admin::class])->group(function () {
Route::get('/admin', [AdminController::class, 'index'])->name('admin');
Route::post('/l/import', [LinkController::class, 'import'])->name('l.import');
Route::get('/env', [SiteController::class, 'env']);
Route::get('/4', [SiteController::class, 'search4chan']);
});
// Session updates - auth required, whitelisted keys only
Route::post('/update-session', function(Request $req){
if ($req->input('key') && $req->input('value')){
$allowed = ['theme', 'locale', 'sidebar'];
if (!in_array($req->input('key'), $allowed)) {
abort(403, 'Session key not allowed.');
}
session()->put($req->input('key'), $req->input('value'));
return redirect()->back();
}
})->middleware('auth');
require __DIR__.'/auth.php';
Route::get('/toy/{v?}', function($v = null){
if (is_null($v)){
return view('toys.index');
}
// Only allow alphanumeric and hyphens
if (!preg_match('/^[a-zA-Z0-9\-]+$/', $v)) {
abort(404);
}
if (!view()->exists('toys.'.$v)) {
abort(404);
}
return view('toys.'.$v);
});
// Audio stream - requires auth to prevent abuse
Route::get('/stream/audio', function() {
$command = 'ffmpeg -re -i http://somafm.com/vaporwaves.pls -f mp3 -';
return response()->stream(function() use ($command) {
$handle = popen($command, 'r');
if ($handle) {
while (!feof($handle)) {
$chunk = fread($handle, 8192);
if ($chunk !== false) {
echo $chunk;
flush();
}
}
pclose($handle);
}
}, 200, [
'Content-Type' => 'audio/mpeg',
'Cache-Control' => 'no-cache',
'X-Accel-Buffering' => 'no'
]);
})->middleware('auth');
Route::get('/newtab', function() {
return view('newtab');
});
// Catch-all: only allow specific whitelisted views
Route::get('/{v}', function($v){
$allowed = ['notes', 'kyanite', 'marked', 'v'];
if (!in_array($v, $allowed)) {
abort(404);
}
return view($v);
})->where('v', '[a-zA-Z0-9\-]+');
|