diff --git a/app/Http/Controllers/DeviceController.php b/app/Http/Controllers/DeviceController.php index ffec1e6d01..087407936b 100644 --- a/app/Http/Controllers/DeviceController.php +++ b/app/Http/Controllers/DeviceController.php @@ -55,18 +55,20 @@ class DeviceController extends Controller 'capture' => \App\Http\Controllers\Device\Tabs\CaptureController::class, ]; - public function index(Request $request, $device_id, $current_tab = 'overview', $vars = '') + public function index(Request $request, $device, $current_tab = 'overview', $vars = '') { - $device_id = (int)str_replace('device=', '', $device_id); - $current_tab = str_replace('tab=', '', $current_tab); - $current_tab = array_key_exists($current_tab, $this->tabs) ? $current_tab : 'overview'; + $device = str_replace('device=', '', $device); + $device = is_numeric($device) ? DeviceCache::get($device) : DeviceCache::getByHostname($device); + $device_id = $device->device_id; DeviceCache::setPrimary($device_id); - $device = DeviceCache::getPrimary(); if (!$device->exists) { abort(404); } + $current_tab = str_replace('tab=', '', $current_tab); + $current_tab = array_key_exists($current_tab, $this->tabs) ? $current_tab : 'overview'; + if ($current_tab == 'port') { $vars = Url::parseLegacyPath($request->path()); $port = Port::findOrFail($vars->get('port')); diff --git a/routes/web.php b/routes/web.php index d6d06186f3..78468301f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,8 +34,8 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () { Route::get('authlog', 'UserController@authlog'); Route::get('overview', 'OverviewController@index')->name('overview'); Route::get('/', 'OverviewController@index'); - Route::match(['get', 'post'], 'device/{device_id}/{tab?}/{vars?}', 'DeviceController@index') - ->name('device')->where(['device_id' => '(device=)?[0-9]+', 'vars' => '.*']); + Route::match(['get', 'post'], 'device/{device}/{tab?}/{vars?}', 'DeviceController@index') + ->name('device')->where(['vars' => '.*']); // Maps Route::group(['prefix' => 'maps', 'namespace' => 'Maps'], function () {