|
3 | 3 | namespace Pterodactyl\Http\Controllers\Admin; |
4 | 4 |
|
5 | 5 | use Ramsey\Uuid\Uuid; |
| 6 | +use Illuminate\Support\Str; |
6 | 7 | use Illuminate\Http\Request; |
7 | 8 | use Pterodactyl\Models\Nest; |
8 | 9 | use Pterodactyl\Models\Mount; |
@@ -101,28 +102,21 @@ public function view($id) |
101 | 102 | */ |
102 | 103 | public function create(MountFormRequest $request) |
103 | 104 | { |
104 | | - /** @var \Pterodactyl\Models\Mount $mount */ |
105 | 105 | $model = (new Mount())->fill($request->validated()); |
106 | 106 | $model->forceFill(['uuid' => Uuid::uuid4()->toString()]); |
107 | 107 |
|
108 | | - if (str_starts_with($model->source, '/etc/pterodactyl')) { |
109 | | - $this->alert->danger('Invalid source path: "/etc/pterodactyl" cannot be used as a source path.')->flash(); |
110 | | - return redirect()->route('admin.mounts'); |
| 108 | + foreach (Mount::$invalidSourcePaths as $path) { |
| 109 | + if (Str::startsWith($model->source, $path)) { |
| 110 | + $this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash(); |
| 111 | + return redirect()->route('admin.mounts'); |
| 112 | + } |
111 | 113 | } |
112 | 114 |
|
113 | | - if (str_starts_with($model->source, '/var/lib/pterodactyl/volumes')) { |
114 | | - $this->alert->danger('Invalid source path: "/var/lib/pterodactyl/volumes" cannot be used as a source path.')->flash(); |
115 | | - return redirect()->route('admin.mounts'); |
116 | | - } |
117 | | - |
118 | | - if (str_starts_with($model->source, '/srv/daemon-data')) { |
119 | | - $this->alert->danger('Invalid source path: "/srv/daemon-data" cannot be used as a source path.')->flash(); |
120 | | - return redirect()->route('admin.mounts'); |
121 | | - } |
122 | | - |
123 | | - if (str_starts_with($model->target, '/home/container')) { |
124 | | - $this->alert->danger('Invalid target path: "/home/container" cannot be used as a target path.')->flash(); |
125 | | - return redirect()->route('admin.mounts'); |
| 115 | + foreach (Mount::$invalidTargetPaths as $path) { |
| 116 | + if (Str::startsWith($model->target, $path)) { |
| 117 | + $this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash(); |
| 118 | + return redirect()->route('admin.mounts'); |
| 119 | + } |
126 | 120 | } |
127 | 121 |
|
128 | 122 | $model->saveOrFail(); |
@@ -150,24 +144,18 @@ public function update(MountFormRequest $request, Mount $mount) |
150 | 144 |
|
151 | 145 | $mount->forceFill($request->validated()); |
152 | 146 |
|
153 | | - if (str_starts_with($mount->source, '/etc/pterodactyl')) { |
154 | | - $this->alert->danger('Invalid source path: "/etc/pterodactyl" cannot be used as a source path.')->flash(); |
155 | | - return redirect()->route('admin.mounts.view', $mount->id); |
156 | | - } |
157 | | - |
158 | | - if (str_starts_with($mount->source, '/var/lib/pterodactyl/volumes')) { |
159 | | - $this->alert->danger('Invalid source path: "/var/lib/pterodactyl/volumes" cannot be used as a source path.')->flash(); |
160 | | - return redirect()->route('admin.mounts.view', $mount->id); |
161 | | - } |
162 | | - |
163 | | - if (str_starts_with($mount->source, '/srv/daemon-data')) { |
164 | | - $this->alert->danger('Invalid source path: "/srv/daemon-data" cannot be used as a source path.')->flash(); |
165 | | - return redirect()->route('admin.mounts.view', $mount->id); |
| 147 | + foreach (Mount::$invalidSourcePaths as $path) { |
| 148 | + if (Str::startsWith($mount->source, $path)) { |
| 149 | + $this->alert->danger('"' . $path . '" cannot be used as a source path.')->flash(); |
| 150 | + return redirect()->route('admin.mounts.view', $mount->id); |
| 151 | + } |
166 | 152 | } |
167 | 153 |
|
168 | | - if (str_starts_with($mount->target, '/home/container')) { |
169 | | - $this->alert->danger('Invalid target path: "/home/container" cannot be used as a target path.')->flash(); |
170 | | - return redirect()->route('admin.mounts.view', $mount->id); |
| 154 | + foreach (Mount::$invalidTargetPaths as $path) { |
| 155 | + if (Str::startsWith($mount->target, $path)) { |
| 156 | + $this->alert->danger('"' . $path . '" cannot be used as a target path.')->flash(); |
| 157 | + return redirect()->route('admin.mounts.view', $mount->id); |
| 158 | + } |
171 | 159 | } |
172 | 160 |
|
173 | 161 | $mount->save(); |
|
0 commit comments