mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Allow device url by hostname (#11831)
* Allow device url by hostname /device/hostname /device/hostname/ports * slightly different code style without else ;)
This commit is contained in:
@@ -55,18 +55,20 @@ class DeviceController extends Controller
|
|||||||
'capture' => \App\Http\Controllers\Device\Tabs\CaptureController::class,
|
'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);
|
$device = str_replace('device=', '', $device);
|
||||||
$current_tab = str_replace('tab=', '', $current_tab);
|
$device = is_numeric($device) ? DeviceCache::get($device) : DeviceCache::getByHostname($device);
|
||||||
$current_tab = array_key_exists($current_tab, $this->tabs) ? $current_tab : 'overview';
|
$device_id = $device->device_id;
|
||||||
DeviceCache::setPrimary($device_id);
|
DeviceCache::setPrimary($device_id);
|
||||||
$device = DeviceCache::getPrimary();
|
|
||||||
|
|
||||||
if (!$device->exists) {
|
if (!$device->exists) {
|
||||||
abort(404);
|
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') {
|
if ($current_tab == 'port') {
|
||||||
$vars = Url::parseLegacyPath($request->path());
|
$vars = Url::parseLegacyPath($request->path());
|
||||||
$port = Port::findOrFail($vars->get('port'));
|
$port = Port::findOrFail($vars->get('port'));
|
||||||
|
@@ -34,8 +34,8 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () {
|
|||||||
Route::get('authlog', 'UserController@authlog');
|
Route::get('authlog', 'UserController@authlog');
|
||||||
Route::get('overview', 'OverviewController@index')->name('overview');
|
Route::get('overview', 'OverviewController@index')->name('overview');
|
||||||
Route::get('/', 'OverviewController@index');
|
Route::get('/', 'OverviewController@index');
|
||||||
Route::match(['get', 'post'], 'device/{device_id}/{tab?}/{vars?}', 'DeviceController@index')
|
Route::match(['get', 'post'], 'device/{device}/{tab?}/{vars?}', 'DeviceController@index')
|
||||||
->name('device')->where(['device_id' => '(device=)?[0-9]+', 'vars' => '.*']);
|
->name('device')->where(['vars' => '.*']);
|
||||||
|
|
||||||
// Maps
|
// Maps
|
||||||
Route::group(['prefix' => 'maps', 'namespace' => 'Maps'], function () {
|
Route::group(['prefix' => 'maps', 'namespace' => 'Maps'], function () {
|
||||||
|
Reference in New Issue
Block a user