forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Define Port Groups * . * . * . * API Calls * . * . * . * minor changes * . * update forms * remove link * . * change column settings * change migration * change update position * db migration fix * . * . * . * add missing doc reference * update test data * update test data * update test data * . * . * . * . * . * . * . * . * port group association in seperate table * . * . * show all found groups on port * select multiple Portgroups per Port * change on migration file * change query to eloquent * Code changes * move port group menu to ports main menu * port group update to eloquent * . * . * update to new setting way * add missing merge parameter * Use select2 and port some things to Laravel some fixes, hopefully no new added bugs * schema * don't use on update restrict unfortunately * remove unused import and revert changes Co-authored-by: Tony Murray <[email protected]>
- Loading branch information
1 parent
ecb87d9
commit 4b9e480
Showing
28 changed files
with
872 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/* | ||
* PortController.php | ||
* | ||
* -Description- | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package LibreNMS | ||
* @link http://librenms.org | ||
* @copyright 2021 Tony Murray | ||
* @author Tony Murray <[email protected]> | ||
*/ | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Port; | ||
|
||
class PortController extends Controller | ||
{ | ||
public function update(\Illuminate\Http\Request $request, Port $port) | ||
{ | ||
$this->validate($request, [ | ||
'groups.*' => 'int', | ||
]); | ||
|
||
$updated = false; | ||
$message = ''; | ||
|
||
if ($request->has('groups')) { | ||
$changes = $port->groups()->sync($request->get('groups')); | ||
$groups_updated = array_sum(array_map(function ($group_ids) { | ||
return count($group_ids); | ||
}, $changes)); | ||
|
||
if ($groups_updated > 0) { | ||
$message .= trans('port.groups.updated', ['port' => $port->getLabel()]); | ||
$updated = true; | ||
} | ||
} | ||
|
||
return $updated | ||
? response(['message' => $message]) | ||
: response(['message' => trans('port.groups.none', ['port' => $port->getLabel()])], 400); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\PortGroup; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\Rule; | ||
use Toastr; | ||
|
||
class PortGroupController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
return view('port-group.index', [ | ||
'port_groups' => PortGroup::orderBy('name')->get(), | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
return view('port-group.create', [ | ||
'port_group' => new PortGroup(), | ||
]); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'name' => 'required|string|unique:port_groups', | ||
]); | ||
|
||
$portGroup = PortGroup::make($request->only(['name', 'desc'])); | ||
$portGroup->save(); | ||
|
||
Toastr::success(__('Port Group :name created', ['name' => $portGroup->name])); | ||
|
||
return redirect()->route('port-groups.index'); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\Models\PortGroup $portGroup | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(PortGroup $portGroup) | ||
{ | ||
return view('port-group.edit', [ | ||
'port_group' => $portGroup, | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Models\PortGroup $portGroup | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, PortGroup $portGroup) | ||
{ | ||
$this->validate($request, [ | ||
'name' => [ | ||
'required', | ||
'string', | ||
'max:255', | ||
Rule::unique('port_groups', 'name')->where(function ($query) use ($portGroup) { | ||
$query->where('id', '!=', $portGroup->id); | ||
}), | ||
], | ||
'desc' => 'string|max:255', | ||
]); | ||
|
||
$portGroup->fill($request->only(['name', 'desc'])); | ||
|
||
if ($portGroup->save()) { | ||
Toastr::success(__('Port Group :name updated', ['name' => $portGroup->name])); | ||
} else { | ||
Toastr::error(__('Failed to save')); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
return redirect()->route('port-groups.index'); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Models\PortGroup $portGroup | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(PortGroup $portGroup) | ||
{ | ||
$portGroup->delete(); | ||
|
||
$msg = __('Port Group :name deleted', ['name' => $portGroup->name]); | ||
|
||
return response($msg, 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* PortGroupController.php | ||
* | ||
* -Description- | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @link http://librenms.org | ||
* @copyright 2020 Thomas Berberich | ||
* @author Thomas Berberich <[email protected]> | ||
*/ | ||
|
||
namespace App\Http\Controllers\Select; | ||
|
||
use App\Models\PortGroup; | ||
|
||
class PortGroupController extends SelectController | ||
{ | ||
protected function searchFields($request) | ||
{ | ||
return ['name']; | ||
} | ||
|
||
protected function baseQuery($request) | ||
{ | ||
return PortGroup::hasAccess($request->user())->select(['id', 'name']); | ||
} | ||
|
||
public function formatItem($port_group) | ||
{ | ||
return [ | ||
'id' => $port_group->id, | ||
'text' => $port_group->name, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/* | ||
* EditPortsController.php | ||
* | ||
* -Description- | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package LibreNMS | ||
* @link http://librenms.org | ||
* @copyright 2021 Tony Murray | ||
* @author Tony Murray <[email protected]> | ||
*/ | ||
|
||
namespace App\Http\Controllers\Table; | ||
|
||
class EditPortsController extends TableController | ||
{ | ||
public function rules() | ||
{ | ||
return [ | ||
'device_id' => 'required|int', | ||
'device_group' => 'nullable|int', | ||
'eventtype' => 'nullable|string', | ||
]; | ||
} | ||
|
||
public function searchFields($request) | ||
{ | ||
return ['ifName', 'ifAlias', 'ifDescr']; | ||
} | ||
|
||
protected function sortFields($request) | ||
{ | ||
return ['ifIndex', 'ifName', 'ifAdminStatus', 'ifOperStatus', 'ifSpeed', 'ifAlias']; | ||
} | ||
|
||
protected function baseQuery($request) | ||
{ | ||
return \App\Models\Port::where('device_id', $request->get('device_id')) | ||
->with('groups'); | ||
} | ||
|
||
/** | ||
* @param \App\Models\Port $port | ||
* @return array | ||
*/ | ||
public function formatItem($port) | ||
{ | ||
$is_port_bad = $port->ifAdminStatus != 'down' && $port->ifOperStatus != 'up'; | ||
$do_we_care = ($port->ignore || $port->disabled) ? false : $is_port_bad; | ||
$out_of_sync = $do_we_care ? "class='red'" : ''; | ||
$tune = $port->device->getAttrib('ifName_tune:' . $port->ifName) == 'true' ? 'checked' : ''; | ||
|
||
$port_group_options = ''; | ||
foreach ($port->groups as $group) { | ||
/** @var \App\Models\PortGroup $group */ | ||
$port_group_options .= '<option value="' . $group->id . '" selected>' . $group->name . '</option>'; | ||
} | ||
|
||
return [ | ||
'ifIndex' => $port->ifIndex, | ||
'ifName' => $port->getLabel(), | ||
'ifAdminStatus' => $port->ifAdminStatus, | ||
'ifOperStatus' => '<span id="operstatus_' . $port->port_id . '" ' . $out_of_sync . '>' . $port->ifOperStatus . '</span>', | ||
'disabled' => '<input type="checkbox" class="disable-check" data-size="small" name="disabled_' . $port->port_id . '"' . ($port->disabled ? 'checked' : '') . '> | ||
<input type="hidden" name="olddis_' . $port->port_id . '" value="' . ($port->disabled ? 1 : 0) . '"">', | ||
'ignore' => '<input type="checkbox" class="ignore-check" data-size="small" name="ignore_' . $port->port_id . '"' . ($port->ignore ? 'checked' : '') . '> | ||
<input type="hidden" name="oldign_' . $port->port_id . '" value="' . ($port->ignore ? 1 : 0) . '"">', | ||
'port_tune' => '<input type="checkbox" name="override_config" data-attrib="ifName_tune:' . $port->ifName . '" data-device_id="' . $port->device_id . '" data-size="small" ' . $tune . '>', | ||
'ifAlias' => '<div class="form-group"><input class="form-control input-sm" name="if-alias" data-device_id="' . $port->device_id . '" data-port_id="' . $port->port_id . '" data-ifName="' . $port->ifName . '" value="' . $port->ifAlias . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>', | ||
'ifSpeed' => '<div class="form-group has-feedback"><input type="text" pattern="[0-9]*" inputmode="numeric" class="form-control input-sm" name="if-speed" data-device_id="' . $port->device_id . '" data-port_id="' . $port->port_id . '" data-ifName="' . $port->ifName . '" value="' . $port->ifSpeed . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>', | ||
'portGroup' => '<div class="form-group has-feedback"><select class="input-sm port_group_select" name="port_group_' . $port->port_id . '[]" data-port_id="' . $port->port_id . '" multiple>' . $port_group_options . '</select></div>', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.