@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | @else |
| 50 | 50 | <div class="label label-default">UNKNOWN</div> |
| 51 | 51 | @endif') |
| 52 | - ->editColumn('rule.name', function ($alert) { |
|
| 52 | + ->editColumn('rule.name', function($alert) { |
|
| 53 | 53 | return '<a href="'.url("alerting/rules/".$alert->rule_id).'">'.$alert->rule->name.'</a>'; |
| 54 | 54 | }) |
| 55 | - ->editColumn('device.hostname', function ($alert) { |
|
| 55 | + ->editColumn('device.hostname', function($alert) { |
|
| 56 | 56 | $hostname = is_null($alert->device) ? trans('devices.text.deleted') : $alert->device->hostname; |
| 57 | 57 | return '<a href="'.url("devices/".$alert->device_id).'">'.$hostname.'</a>'; |
| 58 | 58 | }) |
| 59 | - ->addColumn('actions', function ($alert) { |
|
| 59 | + ->addColumn('actions', function($alert) { |
|
| 60 | 60 | if ($alert->state == 2) { |
| 61 | 61 | $btn = "btn-danger"; |
| 62 | 62 | $icon = "volume-off"; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | return '<a id="alerts-ack" data-id="'.$alert->id.'" data-state="'.$alert->state.'" class="btn btn-xs '.$btn.'"><i class="fa fa-'.$icon.' fa-fw"></i></a>'; |
| 68 | 68 | }) |
| 69 | - ->editColumn('rule.severity', function ($alert) { |
|
| 69 | + ->editColumn('rule.severity', function($alert) { |
|
| 70 | 70 | return $alert->rule->severity; |
| 71 | 71 | }) |
| 72 | 72 | ->make(true); |
@@ -60,7 +60,8 @@ |
||
| 60 | 60 | if ($alert->state == 2) { |
| 61 | 61 | $btn = "btn-danger"; |
| 62 | 62 | $icon = "volume-off"; |
| 63 | - } else { |
|
| 63 | + } |
|
| 64 | + else { |
|
| 64 | 65 | $btn = "btn-success"; |
| 65 | 66 | $icon = "volume-up"; |
| 66 | 67 | } |
@@ -38,14 +38,14 @@ |
||
| 38 | 38 | { |
| 39 | 39 | return $this->datatables |
| 40 | 40 | ->eloquent($this->query()) |
| 41 | - ->editColumn('name', function ($group) { |
|
| 41 | + ->editColumn('name', function($group) { |
|
| 42 | 42 | return '<a href="'.url('devices/group='.$group->id).'">'.$group->name.'</a>'; |
| 43 | 43 | }) |
| 44 | - ->editColumn('count', function ($group) { |
|
| 44 | + ->editColumn('count', function($group) { |
|
| 45 | 45 | return '<span data-toggle="tooltip" title="'.$group->deviceCount.' '.trans('nav.devices.devices').'" class="badge bg-aqua"> |
| 46 | 46 | <i class="fa fa-server"></i> '.$group->deviceCount.'</span>'; |
| 47 | 47 | }) |
| 48 | - ->addColumn('actions', function ($group) { |
|
| 48 | + ->addColumn('actions', function($group) { |
|
| 49 | 49 | $edit = '<button type="button" class="btn btn-xs btn-primary showModal" data-toggle="modal" data-target="#generalModal" data-href="'. |
| 50 | 50 | route('device-groups.edit', ['group_id' => $group->id]). |
| 51 | 51 | '"><i class="fa fa-edit fa-lg fa-fw"></i><span class="hidden-xs"> '.trans('button.edit').'</span></button> '; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * Store a newly created resource in storage. |
| 58 | 58 | * |
| 59 | 59 | * @param \Illuminate\Http\Request $request |
| 60 | - * @return \Illuminate\Http\Response |
|
| 60 | + * @return \Illuminate\Http\JsonResponse |
|
| 61 | 61 | */ |
| 62 | 62 | public function store(DeviceGroupRequest $request) |
| 63 | 63 | { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * Display the specified resource. |
| 71 | 71 | * |
| 72 | 72 | * @param int $id |
| 73 | - * @return \Illuminate\Http\Response |
|
| 73 | + * @return \Illuminate\Http\RedirectResponse |
|
| 74 | 74 | */ |
| 75 | 75 | public function show($id) |
| 76 | 76 | { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @param \Illuminate\Http\Request $request |
| 96 | 96 | * @param int $id |
| 97 | - * @return \Illuminate\Http\Response |
|
| 97 | + * @return \Illuminate\Http\JsonResponse |
|
| 98 | 98 | */ |
| 99 | 99 | public function update(DeviceGroupRequest $request, $id) |
| 100 | 100 | { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param \Illuminate\Http\Request $request |
| 112 | 112 | * @param int $id |
| 113 | - * @return \Illuminate\Http\Response |
|
| 113 | + * @return \Illuminate\Http\JsonResponse |
|
| 114 | 114 | * @throws \Exception |
| 115 | 115 | */ |
| 116 | 116 | public function destroy(AdminOnlyRequest $request, $id) |
@@ -118,7 +118,8 @@ |
||
| 118 | 118 | $group = DeviceGroup::find($id); |
| 119 | 119 | if ($group && $group->delete()) { |
| 120 | 120 | return response()->json(['message' => trans('devices.groups.deleted', ['name' => $group->name])]); |
| 121 | - } else { |
|
| 121 | + } |
|
| 122 | + else { |
|
| 122 | 123 | return response()->json(['message' => trans('devices.groups.deletefailed', ['name' => $group ? $group->name : ""])], 422); |
| 123 | 124 | } |
| 124 | 125 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Store a newly created resource in storage. |
| 44 | 44 | * |
| 45 | 45 | * @param CreateUserRequest $request |
| 46 | - * @return \Illuminate\Http\Response |
|
| 46 | + * @return \Illuminate\Http\JsonResponse |
|
| 47 | 47 | */ |
| 48 | 48 | public function store(CreateUserRequest $request) |
| 49 | 49 | { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * Remove the specified resource from storage. |
| 120 | 120 | * |
| 121 | 121 | * @param int $user_id |
| 122 | - * @return \Illuminate\Http\Response |
|
| 122 | + * @return \Illuminate\Http\JsonResponse |
|
| 123 | 123 | */ |
| 124 | 124 | public function destroy(DeleteUserRequest $request, $user_id) |
| 125 | 125 | { |
@@ -108,7 +108,8 @@ |
||
| 108 | 108 | $user->update($request->all()); |
| 109 | 109 | if ($request->input('update') == 'password') { |
| 110 | 110 | $message = trans('user.text.pwdupdated'); |
| 111 | - } else { |
|
| 111 | + } |
|
| 112 | + else { |
|
| 112 | 113 | $message = trans('user.text.updated', ['username' => $user->username]); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -207,7 +207,7 @@ |
||
| 207 | 207 | * Convert a v1 device group pattern to sql that can be ingested by jQuery-QueryBuilder |
| 208 | 208 | * |
| 209 | 209 | * @param $pattern |
| 210 | - * @return array |
|
| 210 | + * @return string |
|
| 211 | 211 | */ |
| 212 | 212 | private function convertV1Pattern($pattern) |
| 213 | 213 | { |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | foreach (Settings::get('alert.macros.group', []) as $macro => $value) { |
| 175 | - $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 175 | + $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex |
|
| 176 | 176 | if (!str_contains($macro, ' ')) { |
| 177 | 177 | $pattern = str_replace('macros.'.$macro, '('.$value.')', $pattern); |
| 178 | 178 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $sql = $this->pattern; |
| 299 | 299 | |
| 300 | 300 | // fill in parameters |
| 301 | - foreach ((array)$this->params as $value) { |
|
| 301 | + foreach ((array) $this->params as $value) { |
|
| 302 | 302 | if (!is_numeric($value) && !starts_with($value, "'")) { |
| 303 | 303 | $value = "'".$value."'"; |
| 304 | 304 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | $related = $this->getRelation('deviceCountRelation')->first(); |
| 324 | 324 | |
| 325 | 325 | // then return the count directly |
| 326 | - return ($related) ? (int)$related->count : 0; |
|
| 326 | + return ($related) ? (int) $related->count : 0; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -126,7 +126,8 @@ discard block |
||
| 126 | 126 | // can't build sql |
| 127 | 127 | return []; |
| 128 | 128 | } |
| 129 | - } else { |
|
| 129 | + } |
|
| 130 | + else { |
|
| 130 | 131 | $params = $this->params; |
| 131 | 132 | } |
| 132 | 133 | } |
@@ -137,7 +138,8 @@ discard block |
||
| 137 | 138 | $query = null; |
| 138 | 139 | if (count($tables) == 1) { |
| 139 | 140 | $query = DB::table($tables[0])->select('device_id')->distinct(); |
| 140 | - } else { |
|
| 141 | + } |
|
| 142 | + else { |
|
| 141 | 143 | $query = DB::table('devices')->select('devices.device_id')->distinct(); |
| 142 | 144 | |
| 143 | 145 | foreach ($tables as $table) { |
@@ -153,7 +155,8 @@ discard block |
||
| 153 | 155 | // match the device ids |
| 154 | 156 | if (is_null($params)) { |
| 155 | 157 | return $query->whereRaw($statement)->pluck('device_id')->toArray(); |
| 156 | - } else { |
|
| 158 | + } |
|
| 159 | + else { |
|
| 157 | 160 | return $query->whereRaw($statement, $params)->pluck('device_id')->toArray(); |
| 158 | 161 | } |
| 159 | 162 | } |
@@ -181,7 +184,8 @@ discard block |
||
| 181 | 184 | if (str_contains($pattern, 'macros.')) { |
| 182 | 185 | if (++$x < 30) { |
| 183 | 186 | $pattern = self::applyGroupMacros($pattern, $x); |
| 184 | - } else { |
|
| 187 | + } |
|
| 188 | + else { |
|
| 185 | 189 | return false; |
| 186 | 190 | } |
| 187 | 191 | } |
@@ -225,7 +229,8 @@ discard block |
||
| 225 | 229 | if (starts_with($cur, '%')) { |
| 226 | 230 | // table and column or macro |
| 227 | 231 | $out .= substr($cur, 1).' '; |
| 228 | - } elseif (substr($cur, -1) == '~') { |
|
| 232 | + } |
|
| 233 | + elseif (substr($cur, -1) == '~') { |
|
| 229 | 234 | // like operator |
| 230 | 235 | $content = $parts[++$i]; // grab the content so we can format it |
| 231 | 236 | |
@@ -235,14 +240,18 @@ discard block |
||
| 235 | 240 | } |
| 236 | 241 | |
| 237 | 242 | $out .= "LIKE('".$this->convertRegexToLike($content)."') "; |
| 238 | - } elseif ($cur == '&&') { |
|
| 243 | + } |
|
| 244 | + elseif ($cur == '&&') { |
|
| 239 | 245 | $out .= 'AND '; |
| 240 | - } elseif ($cur == '||') { |
|
| 246 | + } |
|
| 247 | + elseif ($cur == '||') { |
|
| 241 | 248 | $out .= 'OR '; |
| 242 | - } elseif (in_array($cur, $ops)) { |
|
| 249 | + } |
|
| 250 | + elseif (in_array($cur, $ops)) { |
|
| 243 | 251 | // pass-through operators |
| 244 | 252 | $out .= $cur.' '; |
| 245 | - } else { |
|
| 253 | + } |
|
| 254 | + else { |
|
| 246 | 255 | // user supplied input |
| 247 | 256 | $out .= "'".trim($cur, '"\'')."' "; // TODO: remove trim, only needed with invalid input |
| 248 | 257 | } |
@@ -273,7 +282,8 @@ discard block |
||
| 273 | 282 | // add ends appropriately |
| 274 | 283 | if ($startAnchor && !$endAnchor) { |
| 275 | 284 | $pattern .= '%'; |
| 276 | - } elseif (!$startAnchor && $endAnchor) { |
|
| 285 | + } |
|
| 286 | + elseif (!$startAnchor && $endAnchor) { |
|
| 277 | 287 | $pattern = '%'.$pattern; |
| 278 | 288 | } |
| 279 | 289 | |
@@ -38,33 +38,33 @@ |
||
| 38 | 38 | { |
| 39 | 39 | return $this->datatables |
| 40 | 40 | ->eloquent($this->query()) |
| 41 | - ->editColumn('status_reason', function ($device) { |
|
| 41 | + ->editColumn('status_reason', function($device) { |
|
| 42 | 42 | if ($device->status == 0) { |
| 43 | 43 | return '<span data-toggle="tooltip" title="down" class="device-status label label-danger">'.$device->status_reason.'</span>'; |
| 44 | 44 | } else { |
| 45 | 45 | return '<span data-toggle="tooltip" title="up" class="device-status label label-success">up</span>'; |
| 46 | 46 | } |
| 47 | 47 | }) |
| 48 | - ->editColumn('vendor', function ($device) { |
|
| 48 | + ->editColumn('vendor', function($device) { |
|
| 49 | 49 | return '<img src="'.$device->icon.'" alt="'.$device->os.'">'; |
| 50 | 50 | }) |
| 51 | - ->editColumn('hostname', function ($device) { |
|
| 51 | + ->editColumn('hostname', function($device) { |
|
| 52 | 52 | $hostname = is_null($device) ? trans('devices.text.deleted') : $device->hostname; |
| 53 | 53 | return '<a href="'.url("devices/".$device->device_id).'">'.$hostname.'</a>'; |
| 54 | 54 | }) |
| 55 | - ->editColumn('resources', function ($device) { |
|
| 55 | + ->editColumn('resources', function($device) { |
|
| 56 | 56 | $ports = $device->ports()->count(); |
| 57 | 57 | $sensors = $device->sensors()->count(); |
| 58 | 58 | return '<span data-toggle="tooltip" title="'.$ports.' Ports" class="badge bg-light-blue"><i class="fa fa-link"></i> '.$ports.'</span><br /> |
| 59 | 59 | <span data-toggle="tooltip" title="'.$sensors.' Sensors" class="badge bg-light-blue"><i class="fa fa-dashboard"></i> '.$sensors.'</span>'; |
| 60 | 60 | }) |
| 61 | - ->editColumn('hardware', function ($device) { |
|
| 61 | + ->editColumn('hardware', function($device) { |
|
| 62 | 62 | return $device->hardware.'<br />'.$device->features; |
| 63 | 63 | }) |
| 64 | - ->editColumn('os', function ($device) { |
|
| 64 | + ->editColumn('os', function($device) { |
|
| 65 | 65 | return ucfirst($device->os).'<br />'.$device->version; |
| 66 | 66 | }) |
| 67 | - ->editColumn('location', function ($device) { |
|
| 67 | + ->editColumn('location', function($device) { |
|
| 68 | 68 | return $device->formatUptime($device->uptime).'<br />'.$device->location; |
| 69 | 69 | }) |
| 70 | 70 | ->make(true); |
@@ -41,7 +41,8 @@ |
||
| 41 | 41 | ->editColumn('status_reason', function ($device) { |
| 42 | 42 | if ($device->status == 0) { |
| 43 | 43 | return '<span data-toggle="tooltip" title="down" class="device-status label label-danger">'.$device->status_reason.'</span>'; |
| 44 | - } else { |
|
| 44 | + } |
|
| 45 | + else { |
|
| 45 | 46 | return '<span data-toggle="tooltip" title="up" class="device-status label label-success">up</span>'; |
| 46 | 47 | } |
| 47 | 48 | }) |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | { |
| 41 | 41 | return $this->datatables |
| 42 | 42 | ->eloquent($this->query()) |
| 43 | - ->editColumn('hostname', function ($data) { |
|
| 43 | + ->editColumn('hostname', function($data) { |
|
| 44 | 44 | $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; |
| 45 | 45 | return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; |
| 46 | 46 | }) |
| 47 | - ->editColumn('ifName', function ($data) { |
|
| 47 | + ->editColumn('ifName', function($data) { |
|
| 48 | 48 | $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; |
| 49 | 49 | return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; |
| 50 | 50 | }) |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | { |
| 41 | 41 | return $this->datatables |
| 42 | 42 | ->eloquent($this->query()) |
| 43 | - ->editColumn('hostname', function ($data) { |
|
| 43 | + ->editColumn('hostname', function($data) { |
|
| 44 | 44 | $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; |
| 45 | 45 | return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; |
| 46 | 46 | }) |
| 47 | - ->editColumn('ifName', function ($data) { |
|
| 47 | + ->editColumn('ifName', function($data) { |
|
| 48 | 48 | $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; |
| 49 | 49 | return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; |
| 50 | 50 | }) |
@@ -19,7 +19,8 @@ |
||
| 19 | 19 | if (!Auth::guard($guard)->user()->isAdmin()) { |
| 20 | 20 | if ($request->ajax() || $request->wantsJson()) { |
| 21 | 21 | return response(trans('general.text.unauthorized'), 401); |
| 22 | - } else { |
|
| 22 | + } |
|
| 23 | + else { |
|
| 23 | 24 | //FIXME: Errors not working |
| 24 | 25 | return redirect('/')->withErrors(['msg', trans('general.text.unauthorized')]); |
| 25 | 26 | } |