librenms /
librenmsv2
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Api\Controllers; |
||
| 4 | |||
| 5 | use App\Models\Dashboard; |
||
| 6 | use App\Models\UsersWidgets; |
||
| 7 | use Dingo\Api\Routing\Helpers; |
||
| 8 | use Illuminate\Http\Request; |
||
| 9 | use Validator; |
||
| 10 | |||
| 11 | class DashboardController extends Controller |
||
| 12 | { |
||
| 13 | |||
| 14 | use Helpers; |
||
| 15 | |||
| 16 | 4 | public function __construct() |
|
| 17 | { |
||
| 18 | 4 | } |
|
| 19 | |||
| 20 | /** |
||
| 21 | * Display a listing of all authorized devices |
||
| 22 | * |
||
| 23 | * @return \Illuminate\Http\Response |
||
| 24 | */ |
||
| 25 | 4 | public function index(Request $request) |
|
| 26 | { |
||
| 27 | 4 | $dashboards = Dashboard::allAvailable($request->user())->get(); |
|
|
0 ignored issues
–
show
|
|||
| 28 | 4 | return $dashboards; |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Show the form for creating a new resource. |
||
| 33 | * |
||
| 34 | * @return \Illuminate\Http\Response|null |
||
| 35 | */ |
||
| 36 | public function create(Request $request) |
||
| 37 | { |
||
| 38 | // |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Store a newly created resource in storage. |
||
| 43 | * |
||
| 44 | * @param \Illuminate\Http\Request $request |
||
| 45 | * @return \Illuminate\Http\Response |
||
| 46 | */ |
||
| 47 | 1 | public function store(Request $request) |
|
| 48 | { |
||
| 49 | 1 | $validation = Validator::make($request->all(), [ |
|
| 50 | 1 | 'name' => 'required|max:255', |
|
| 51 | 'access' => 'required', |
||
| 52 | ]); |
||
| 53 | 1 | if ($validation->passes()) { |
|
| 54 | 1 | $dashboard = new Dashboard; |
|
| 55 | 1 | $dashboard->dashboard_name = $request->name; |
|
| 56 | 1 | $dashboard->access = $request->access; |
|
| 57 | 1 | if ($request->user()->dashboards()->save($dashboard)) { |
|
| 58 | 1 | if (is_numeric($request->copy_from)) { |
|
| 59 | $duplicate_widgets = Dashboard::find($request->copy_from)->widgets()->get(); |
||
| 60 | foreach ($duplicate_widgets as $tmp_widget) { |
||
| 61 | /** @var UsersWidgets $tmp_widget */ |
||
| 62 | $new_widget = $tmp_widget->replicate(); |
||
| 63 | $new_widget->user_id = $request->user()->user_id; |
||
| 64 | $new_widget->dashboard_id = $dashboard->dashboard_id; |
||
| 65 | unset($new_widget->user_widget_id); |
||
| 66 | $new_widget->save(); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | 1 | return $this->response->array(array('statusText' => 'OK', 'dashboard_id' => $dashboard->dashboard_id)); |
|
| 70 | } else { |
||
| 71 | return $this->response->errorInternal(); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | $errors = $validation->errors(); |
||
| 75 | return response()->json($errors, 422); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Display the specified resource. |
||
| 81 | * |
||
| 82 | * @param int $id |
||
| 83 | * @return \Illuminate\Http\Response |
||
|
0 ignored issues
–
show
|
|||
| 84 | */ |
||
| 85 | 3 | public function show(Request $request, $id) |
|
| 86 | { |
||
| 87 | 3 | $dashboard = Dashboard::find($id); |
|
| 88 | 3 | $widgets = $dashboard->widgets()->get(); |
|
| 89 | |||
| 90 | 3 | return array('dashboard' => $dashboard, 'widgets' => $widgets); |
|
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Show the form for editing the specified resource. |
||
| 95 | * |
||
| 96 | * @param int $id |
||
| 97 | * @return \Illuminate\Http\Response |
||
|
0 ignored issues
–
show
|
|||
| 98 | */ |
||
| 99 | public function edit($id) |
||
| 100 | { |
||
| 101 | // |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Update the specified resource in storage. |
||
| 106 | * |
||
| 107 | * @param \Illuminate\Http\Request $request |
||
| 108 | * @param int $id |
||
| 109 | * @return \Illuminate\Http\Response |
||
| 110 | */ |
||
| 111 | public function update(Request $request, $id) |
||
| 112 | { |
||
| 113 | $validation = Validator::make($request->all(), [ |
||
| 114 | 'name' => 'required|max:255', |
||
| 115 | 'access' => 'required', |
||
| 116 | ]); |
||
| 117 | if ($validation->passes()) { |
||
| 118 | $dashboard = Dashboard::find($id); |
||
| 119 | $dashboard->dashboard_name = $request->name; |
||
| 120 | $dashboard->access = $request->access; |
||
| 121 | if ($dashboard->save()) { |
||
| 122 | return $this->response->array(array('statusText' => 'OK')); |
||
| 123 | } else { |
||
| 124 | return $this->response->errorInternal(); |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $errors = $validation->errors(); |
||
| 128 | return response()->json($errors, 422); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Remove the specified resource from storage. |
||
| 134 | * |
||
| 135 | * @param int $id |
||
| 136 | * @return \Illuminate\Http\Response |
||
| 137 | */ |
||
| 138 | public function destroy(Request $request, $id) |
||
| 139 | { |
||
| 140 | if (Dashboard::where('user_id', $request->user()->user_id)->where('dashboard_id', $id)->delete()) { |
||
| 141 | if (UsersWidgets::where('dashboard_id', $id)->delete() >= 0) { |
||
| 142 | return $this->response->array(array('statusText' => 'OK')); |
||
| 143 | } else { |
||
| 144 | return $this->response->errorInternal(); |
||
| 145 | } |
||
| 146 | } else { |
||
| 147 | return $this->response->errorInternal(); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | public function clear($id) |
||
| 152 | { |
||
| 153 | if (Dashboard::find($id)->widgets()->delete() >= 0) { |
||
| 154 | return $this->response->array(array('statusText' => 'OK')); |
||
| 155 | } else { |
||
| 156 | return $this->response->errorInternal(); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: