From f7fd63dff9ac7cdb99984f158b7d7fea4d0630e7 Mon Sep 17 00:00:00 2001
From: Charles Morgan <sir3lit@gmail.com>
Date: Sun, 11 Oct 2020 18:38:09 -0400
Subject: [PATCH 1/3] Remove trailing slash if one is present

Closes https://github.com/pterodactyl/panel/issues/2386
---
 resources/scripts/routers/AuthenticationRouter.tsx | 3 ++-
 resources/scripts/routers/DashboardRouter.tsx      | 3 ++-
 resources/scripts/routers/ServerRouter.tsx         | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/resources/scripts/routers/AuthenticationRouter.tsx b/resources/scripts/routers/AuthenticationRouter.tsx
index 57d1422ca..baa662a85 100644
--- a/resources/scripts/routers/AuthenticationRouter.tsx
+++ b/resources/scripts/routers/AuthenticationRouter.tsx
@@ -1,6 +1,6 @@
 import React, { useEffect } from 'react';
 import ReactGA from 'react-ga';
-import { Route, RouteComponentProps, Switch } from 'react-router-dom';
+import { Route, RouteComponentProps, Switch, Redirect } from 'react-router-dom';
 import LoginContainer from '@/components/auth/LoginContainer';
 import ForgotPasswordContainer from '@/components/auth/ForgotPasswordContainer';
 import ResetPasswordContainer from '@/components/auth/ResetPasswordContainer';
@@ -15,6 +15,7 @@ export default ({ location, history, match }: RouteComponentProps) => {
     return (
         <div className={'pt-8 xl:pt-32'}>
             <Switch location={location}>
+                <Redirect from="/:url*(/+)" to={location.pathname.slice(0, -1)} />
                 <Route path={`${match.path}/login`} component={LoginContainer} exact/>
                 <Route path={`${match.path}/login/checkpoint`} component={LoginCheckpointContainer}/>
                 <Route path={`${match.path}/password`} component={ForgotPasswordContainer} exact/>
diff --git a/resources/scripts/routers/DashboardRouter.tsx b/resources/scripts/routers/DashboardRouter.tsx
index 7a895a7e4..f68bda865 100644
--- a/resources/scripts/routers/DashboardRouter.tsx
+++ b/resources/scripts/routers/DashboardRouter.tsx
@@ -1,6 +1,6 @@
 import React, { useEffect } from 'react';
 import ReactGA from 'react-ga';
-import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
+import { NavLink, Route, RouteComponentProps, Switch, Redirect } from 'react-router-dom';
 import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
 import NavigationBar from '@/components/NavigationBar';
 import DashboardContainer from '@/components/dashboard/DashboardContainer';
@@ -27,6 +27,7 @@ export default ({ location }: RouteComponentProps) => {
             }
             <TransitionRouter>
                 <Switch location={location}>
+                    <Redirect from="/:url*(/+)" to={location.pathname.slice(0, -1)} />
                     <Route path={'/'} component={DashboardContainer} exact />
                     <Route path={'/account'} component={AccountOverviewContainer} exact/>
                     <Route path={'/account/api'} component={AccountApiContainer} exact/>
diff --git a/resources/scripts/routers/ServerRouter.tsx b/resources/scripts/routers/ServerRouter.tsx
index a90ff652b..e35113dca 100644
--- a/resources/scripts/routers/ServerRouter.tsx
+++ b/resources/scripts/routers/ServerRouter.tsx
@@ -1,6 +1,6 @@
 import React, { useEffect, useState } from 'react';
 import ReactGA from 'react-ga';
-import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
+import { NavLink, Route, RouteComponentProps, Switch, Redirect } from 'react-router-dom';
 import NavigationBar from '@/components/NavigationBar';
 import ServerConsole from '@/components/server/ServerConsole';
 import TransitionRouter from '@/TransitionRouter';
@@ -123,6 +123,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
                         <>
                             <TransitionRouter>
                                 <Switch location={location}>
+                                    <Redirect from="/:url*(/+)" to={location.pathname.slice(0, -1)} />
                                     <Route path={`${match.path}`} component={ServerConsole} exact/>
                                     <Route
                                         path={`${match.path}/files`}

From abd60ee6f85773cfb865e1005e38f71cacea15cd Mon Sep 17 00:00:00 2001
From: Matthew Penner <me@matthewp.io>
Date: Mon, 12 Oct 2020 11:11:40 -0600
Subject: [PATCH 2/3] Fix 500 error when mounting a mount and fix the actual
 mount being deleted instead of the relation

---
 .../Controllers/Admin/ServersController.php   | 20 ++++++++++---------
 app/Models/MountServer.php                    |  5 +++++
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php
index 5555f6581..9dcafb033 100644
--- a/app/Http/Controllers/Admin/ServersController.php
+++ b/app/Http/Controllers/Admin/ServersController.php
@@ -14,6 +14,7 @@ use Illuminate\Http\Request;
 use Pterodactyl\Models\User;
 use Pterodactyl\Models\Mount;
 use Pterodactyl\Models\Server;
+use Pterodactyl\Models\MountServer;
 use Prologue\Alerts\AlertsMessageBag;
 use GuzzleHttp\Exception\RequestException;
 use Pterodactyl\Exceptions\DisplayException;
@@ -419,17 +420,21 @@ class ServersController extends Controller
      *
      * @param Server $server
      * @param \Pterodactyl\Models\Mount $mount
-     * @return \Illuminate\Http\RedirectResponse
      *
-     * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
-     * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
+     * @return \Illuminate\Http\RedirectResponse
+     * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException|\Throwable
      */
     public function addMount(Server $server, Mount $mount)
     {
-        $server->mounts()->updateOrCreate([
+        /*$server->mounts()->updateOrCreate([
             'mount_id' => $mount->id,
             'server_id' => $server->id,
-        ]);
+        ]);*/
+
+        $mountServer = new MountServer;
+        $mountServer->mount_id = $mount->id;
+        $mountServer->server_id = $server->id;
+        $mountServer->saveOrFail();
 
         $data = $this->serverConfigurationStructureService->handle($server);
 
@@ -458,10 +463,7 @@ class ServersController extends Controller
      */
     public function deleteMount(Server $server, Mount $mount)
     {
-        $server->mounts()
-            ->where('mount_id', $mount->id)
-            ->where('server_id', $server->id)
-            ->delete();
+        MountServer::where('mount_id', $mount->id)->where('server_id', $server->id)->delete();
 
         $data = $this->serverConfigurationStructureService->handle($server);
 
diff --git a/app/Models/MountServer.php b/app/Models/MountServer.php
index 3999b0c8e..21bf8fe2d 100644
--- a/app/Models/MountServer.php
+++ b/app/Models/MountServer.php
@@ -11,6 +11,11 @@ class MountServer extends Model
      */
     protected $table = 'mount_server';
 
+    /**
+     * @var bool
+     */
+    public $timestamps = false;
+
     /**
      * @var null
      */

From 3ef3c2a461b887eabecf9f1de701bb079b09a292 Mon Sep 17 00:00:00 2001
From: Matthew Penner <me@matthewp.io>
Date: Mon, 12 Oct 2020 11:12:23 -0600
Subject: [PATCH 3/3] Remove commented code

---
 app/Http/Controllers/Admin/ServersController.php | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php
index 9dcafb033..324e7c3b0 100644
--- a/app/Http/Controllers/Admin/ServersController.php
+++ b/app/Http/Controllers/Admin/ServersController.php
@@ -426,11 +426,6 @@ class ServersController extends Controller
      */
     public function addMount(Server $server, Mount $mount)
     {
-        /*$server->mounts()->updateOrCreate([
-            'mount_id' => $mount->id,
-            'server_id' => $server->id,
-        ]);*/
-
         $mountServer = new MountServer;
         $mountServer->mount_id = $mount->id;
         $mountServer->server_id = $server->id;